-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: throw error for legacy dynamic
require
users (#794)
* feat: throw error for legacy dynamic `require` users * chore: whitespace * fix: add to files array * refactor: only use input if it's a string * chore: consistent script naming * refactor: gitignore declaration file, add to postbuild * chore: add @ts-check directive
- Loading branch information
1 parent
7a8b0e2
commit 1c66a59
Showing
3 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
coverage/ | ||
dist/ | ||
node_modules/ | ||
legacy-require-handler.d.cts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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} | ||
`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters