-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: support use on Node.js 16 #550
Conversation
WalkthroughThe changes involve modifications to two files: Changes
Possibly related PRs
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (2)
src/utils.ts (2)
212-225
: Consider adding Node.js version checkThe patch function should verify it's running on Node.js 16 to avoid potential conflicts with existing globals in other versions.
export function patchForNode16() { + // Only patch if running on Node.js 16 + if (process.version.startsWith('v16.')) { if (typeof global.ReadableStream === 'undefined') { // @ts-expect-error global.ReadableStream = ReadableStream; } if (typeof global.Blob === 'undefined') { // @ts-expect-error global.Blob = Blob; } if (typeof global.DOMException === 'undefined') { // @ts-expect-error global.DOMException = getDOMExceptionClass(); } + } }🧰 Tools
🪛 eslint
[error] 214-214: Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.
(@typescript-eslint/ban-ts-comment)
[error] 218-218: Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.
(@typescript-eslint/ban-ts-comment)
[error] 222-222: Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.
(@typescript-eslint/ban-ts-comment)
🪛 GitHub Check: Node.js / Test (windows-latest, 23)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (windows-latest, 22)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (windows-latest, 20)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (windows-latest, 18.19.0)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (windows-latest, 18)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (ubuntu-latest, 23)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (ubuntu-latest, 22)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (ubuntu-latest, 20)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (ubuntu-latest, 18.19.0)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (ubuntu-latest, 18)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (macos-latest, 23)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (macos-latest, 22)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (macos-latest, 18.19.0)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (macos-latest, 18)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (macos-latest, 20)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
228-235
: Improve error handling in getDOMExceptionClassThe function relies on
atob()
being available and throwing a DOMException. Consider adding a fallback mechanism.function getDOMExceptionClass() { try { - // @ts-ignore + // @ts-expect-error atob(0); } catch (err: any) { return err.constructor; } + // Fallback if atob doesn't throw or isn't available + return class DOMException extends Error { + constructor(message: string, name = 'Error') { + super(message); + this.name = name; + } + }; }🧰 Tools
🪛 eslint
[error] 230-230: Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.
(@typescript-eslint/ban-ts-comment)
🪛 GitHub Check: Node.js / Test (windows-latest, 23)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (windows-latest, 22)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (windows-latest, 20)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (windows-latest, 18.19.0)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (windows-latest, 18)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (ubuntu-latest, 23)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (ubuntu-latest, 22)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (ubuntu-latest, 20)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (ubuntu-latest, 18.19.0)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (ubuntu-latest, 18)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (macos-latest, 23)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (macos-latest, 22)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (macos-latest, 18.19.0)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (macos-latest, 18)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free🪛 GitHub Check: Node.js / Test (macos-latest, 20)
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
src/index.ts
(1 hunks)src/utils.ts
(2 hunks)
🧰 Additional context used
🪛 eslint
src/utils.ts
[error] 214-214: Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.
(@typescript-eslint/ban-ts-comment)
[error] 218-218: Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.
(@typescript-eslint/ban-ts-comment)
[error] 222-222: Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.
(@typescript-eslint/ban-ts-comment)
[error] 230-230: Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.
(@typescript-eslint/ban-ts-comment)
🪛 GitHub Check: Node.js / Test (windows-latest, 23)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (windows-latest, 22)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (windows-latest, 20)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (windows-latest, 18.19.0)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (windows-latest, 18)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 23)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 22)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 20)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 18.19.0)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 18)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (macos-latest, 23)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (macos-latest, 22)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (macos-latest, 18.19.0)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (macos-latest, 18)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (macos-latest, 20)
src/utils.ts
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 230-230:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🔇 Additional comments (1)
src/utils.ts (1)
4-5
: LGTM! Proper usage of built-in Node.js modules
Good use of the node:
protocol prefix for importing built-in modules.
src/utils.ts
Outdated
export function patchForNode16() { | ||
if (typeof global.ReadableStream === 'undefined') { | ||
// @ts-ignore | ||
global.ReadableStream = ReadableStream; | ||
} | ||
if (typeof global.Blob === 'undefined') { | ||
// @ts-ignore | ||
global.Blob = Blob; | ||
} | ||
if (typeof global.DOMException === 'undefined') { | ||
// @ts-ignore | ||
global.DOMException = getDOMExceptionClass(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Replace @ts-ignore with @ts-expect-error
The static analysis tools correctly flag the usage of @ts-ignore. Using @ts-expect-error is preferred as it will error if the type error is fixed, preventing stale suppressions.
- // @ts-ignore
+ // @ts-expect-error
global.ReadableStream = ReadableStream;
- // @ts-ignore
+ // @ts-expect-error
global.Blob = Blob;
- // @ts-ignore
+ // @ts-expect-error
global.DOMException = getDOMExceptionClass();
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export function patchForNode16() { | |
if (typeof global.ReadableStream === 'undefined') { | |
// @ts-ignore | |
global.ReadableStream = ReadableStream; | |
} | |
if (typeof global.Blob === 'undefined') { | |
// @ts-ignore | |
global.Blob = Blob; | |
} | |
if (typeof global.DOMException === 'undefined') { | |
// @ts-ignore | |
global.DOMException = getDOMExceptionClass(); | |
} | |
} | |
export function patchForNode16() { | |
if (typeof global.ReadableStream === 'undefined') { | |
// @ts-expect-error | |
global.ReadableStream = ReadableStream; | |
} | |
if (typeof global.Blob === 'undefined') { | |
// @ts-expect-error | |
global.Blob = Blob; | |
} | |
if (typeof global.DOMException === 'undefined') { | |
// @ts-expect-error | |
global.DOMException = getDOMExceptionClass(); | |
} | |
} |
🧰 Tools
🪛 eslint
[error] 214-214: Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.
(@typescript-eslint/ban-ts-comment)
[error] 218-218: Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.
(@typescript-eslint/ban-ts-comment)
[error] 222-222: Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.
(@typescript-eslint/ban-ts-comment)
🪛 GitHub Check: Node.js / Test (windows-latest, 23)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (windows-latest, 22)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (windows-latest, 20)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (windows-latest, 18.19.0)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (windows-latest, 18)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 23)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 22)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 20)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 18.19.0)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 18)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (macos-latest, 23)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (macos-latest, 22)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (macos-latest, 18.19.0)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (macos-latest, 18)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
🪛 GitHub Check: Node.js / Test (macos-latest, 20)
[failure] 214-214:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 218-218:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
[failure] 222-222:
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #550 +/- ##
==========================================
- Coverage 94.42% 93.50% -0.93%
==========================================
Files 10 10
Lines 1255 1277 +22
Branches 285 289 +4
==========================================
+ Hits 1185 1194 +9
- Misses 66 79 +13
Partials 4 4 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (1)
src/utils.ts (1)
231-239
: Improve error handling and documentationWhile the implementation cleverly uses
atob
to get theDOMException
class, consider these improvements:
- Add JSDoc to explain the implementation strategy
- Add error handling for environments where
atob
might not be available+ /** + * Gets the native DOMException class by triggering an error with atob. + * This approach is based on the node-domexception library. + * @see https://github.com/jimmywarting/node-domexception + * @returns The DOMException class + * @throws If atob is not available + */ function getDOMExceptionClass() { + if (typeof atob !== 'function') { + throw new Error('atob is required to get DOMException class'); + } try { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore atob(0); } catch (err: any) { return err.constructor; } + // This should never happen as atob(0) should always throw + throw new Error('Failed to get DOMException class'); }🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 231-232: src/utils.ts#L231-L232
Added lines #L231 - L232 were not covered by tests
[warning] 235-239: src/utils.ts#L235-L239
Added lines #L235 - L239 were not covered by tests
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
src/utils.ts
(2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
src/utils.ts
[warning] 216-217: src/utils.ts#L216-L217
Added lines #L216 - L217 were not covered by tests
[warning] 221-222: src/utils.ts#L221-L222
Added lines #L221 - L222 were not covered by tests
[warning] 226-227: src/utils.ts#L226-L227
Added lines #L226 - L227 were not covered by tests
[warning] 231-232: src/utils.ts#L231-L232
Added lines #L231 - L232 were not covered by tests
[warning] 235-239: src/utils.ts#L235-L239
Added lines #L235 - L239 were not covered by tests
🔇 Additional comments (3)
src/utils.ts (3)
4-5
: LGTM! Imports are correctly specified.
The imports use the recommended node:
protocol prefix and import from official Node.js modules.
214-226
: Replace @ts-ignore with @ts-expect-error
The static analysis tools correctly flag the usage of @ts-ignore.
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 216-217: src/utils.ts#L216-L217
Added lines #L216 - L217 were not covered by tests
[warning] 221-222: src/utils.ts#L221-L222
Added lines #L221 - L222 were not covered by tests
212-228
: Verify the impact of global modifications
The function modifies the global scope which could have unintended side effects.
✅ Verification successful
Let me gather more context about the usage of this function and Node.js version handling.
Based on the gathered information, I can now provide a final response:
Global modifications are safely scoped to Node.js 16 compatibility
The patchForNode16()
function is a controlled polyfill that only adds missing Web API globals when they're undefined. This is safe because:
- The package explicitly requires Node.js >= 18.19.0 in package.json
- The polyfills are only applied when the globals don't exist (defensive checks)
- These modifications only occur once at initialization (imported and called once in index.ts)
- No other files modify these globals, preventing conflicts
- The polyfills are standard Web APIs needed for compatibility
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for other global modifications and potential conflicts
# Search for other global.ReadableStream assignments
rg -l "global\.ReadableStream\s*=" --type ts
# Search for other global.Blob assignments
rg -l "global\.Blob\s*=" --type ts
# Search for other global.DOMException assignments
rg -l "global\.DOMException\s*=" --type ts
# Look for potential version checks or Node.js version specific code
rg "process\.version" --type ts
Length of output: 547
Script:
#!/bin/bash
# Check where patchForNode16 is used and how it's related to version checks
rg "patchForNode16" -B 2 -A 2 --type ts
# Check package.json for Node.js version requirements
cat package.json | jq '.engines'
# Look for any test cases or documentation about Node.js compatibility
fd README.md --exec cat {}
Length of output: 16425
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 216-217: src/utils.ts#L216-L217
Added lines #L216 - L217 were not covered by tests
[warning] 221-222: src/utils.ts#L221-L222
Added lines #L221 - L222 were not covered by tests
[warning] 226-227: src/utils.ts#L226-L227
Added lines #L226 - L227 were not covered by tests
export function patchForNode16() { | ||
if (typeof global.ReadableStream === 'undefined') { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
global.ReadableStream = ReadableStream; | ||
} | ||
if (typeof global.Blob === 'undefined') { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
global.Blob = Blob; | ||
} | ||
if (typeof global.DOMException === 'undefined') { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
global.DOMException = getDOMExceptionClass(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add test coverage for Node.js 16 compatibility patches
The new patchForNode16
function lacks test coverage. Please add tests to verify:
- Polyfills are correctly applied when globals are undefined
- Existing globals are preserved when already defined
Would you like me to help create test cases for this function?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 216-217: src/utils.ts#L216-L217
Added lines #L216 - L217 were not covered by tests
[warning] 221-222: src/utils.ts#L221-L222
Added lines #L221 - L222 were not covered by tests
[warning] 226-227: src/utils.ts#L226-L227
Added lines #L226 - L227 were not covered by tests
function getDOMExceptionClass() { | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
atob(0); | ||
} catch (err: any) { | ||
return err.constructor; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add test coverage for DOMException class retrieval
The getDOMExceptionClass
function lacks test coverage. Please add tests to verify:
- The function returns the correct DOMException class
- Error handling for environments without atob
Would you like me to help create test cases for this function?
🧰 Tools
🪛 GitHub Check: codecov/patch
[warning] 231-232: src/utils.ts#L231-L232
Added lines #L231 - L232 were not covered by tests
[warning] 235-239: src/utils.ts#L235-L239
Added lines #L235 - L239 were not covered by tests
[skip ci] ## [4.5.1](v4.5.0...v4.5.1) (2024-12-02) ### Bug Fixes * support use on Node.js 16 ([#550](#550)) ([78e1336](78e1336))
Summary by CodeRabbit
New Features
ReadableStream
,Blob
, andDOMException
to support newer features.Bug Fixes
Documentation