diff --git a/packages/api/.gitignore b/packages/api/.gitignore index b8fe8bdb..2e0d94a6 100644 --- a/packages/api/.gitignore +++ b/packages/api/.gitignore @@ -2,3 +2,4 @@ coverage/ dist/ node_modules/ +legacy-require-handler.d.cts diff --git a/packages/api/legacy-require-handler.cjs b/packages/api/legacy-require-handler.cjs new file mode 100644 index 00000000..174d0319 --- /dev/null +++ b/packages/api/legacy-require-handler.cjs @@ -0,0 +1,29 @@ +// @ts-check +/* eslint-disable import/no-commonjs */ + +/** + * In `api` v6, this package was a JS library used JavaScript Proxies to dynamically generate SDKs at runtime. + * This functionality has been sunset in `api` v7 to focus on its CLI, which builds strongly-typed SDKs. + * This file is here to throw errors for users that attempt to use the legacy library. + * + * + * @param {unknown} input + */ +module.exports = function legacyHandler(input) { + let identifier = 'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.0/petstore.json'; + + if (typeof input === 'string') { + identifier = input; + } + + throw new Error(`Oops! You're attempting to use a legacy usage pattern that no longer exists. + +You can read more about this in our docs: TKTK + +\`api\` can now generate strongly-typed SDKs that work in pretty much every JS runtime! + +Try running this command to get started: + +npx api@latest install ${identifier} +`); +}; diff --git a/packages/api/package.json b/packages/api/package.json index f97b0093..cd4eb837 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -6,17 +6,20 @@ "bin": { "api": "bin/api.js" }, + "main": "legacy-require-handler.cjs", "scripts": { "attw": "attw --pack --format table-flipped", "build": "tsc", - "build:versionedfiles": "NODE_OPTIONS=--no-warnings node --loader ts-node/esm bin/buildVersionedFiles.ts", + "build:legacy-handler": "tsc legacy-require-handler.cjs --checkJs --declaration --emitDeclarationOnly", + "build:versioned-files": "NODE_OPTIONS=--no-warnings node --loader ts-node/esm bin/buildVersionedFiles.ts", "debug:bin": "NODE_OPTIONS=--no-warnings node --loader ts-node/esm src/bin.ts", "lint:types": "tsc --noEmit", - "prebuild": "rm -rf dist/ && npm run build:versionedfiles", + "prebuild": "rm -rf dist/ && npm run build:versioned-files", + "postbuild": "npm run build:legacy-handler", "prepack": "npm run build", "test": "vitest run --coverage", "test:smoke": "vitest --config=vitest-smoketest.config.ts", - "version": "npm run build:versionedfiles && git add schema.json src/packageInfo.ts" + "version": "npm run build:versioned-files && git add schema.json src/packageInfo.ts" }, "repository": { "type": "git", @@ -34,6 +37,7 @@ }, "files": [ "dist", + "legacy-require-handler.**", "schema.json" ], "keywords": [