-
Notifications
You must be signed in to change notification settings - Fork 124
fix: patch undici File support on Node.js < 20 #588
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
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Warning Rate limit exceeded@akitaSummer has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 45 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (10)
WalkthroughA blank line was added in Changes
Sequence Diagram(s)sequenceDiagram
participant App
participant patchForNode16
participant globalThis
participant StringPrototype
App->>patchForNode16: Call patchForNode16()
patchForNode16->>globalThis: Check if File exists
alt File missing
patchForNode16->>globalThis: Assign File polyfill
end
patchForNode16->>StringPrototype: Check for toWellFormed and isWellFormed
alt Methods missing
patchForNode16->>StringPrototype: Add toWellFormed and isWellFormed polyfills
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Possibly related PRs
Suggested labels
Poem
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Summary of Changes
Hello @akitaSummer, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
I've implemented a fix primarily focused on enhancing compatibility for undici and other web-standard APIs in older Node.js environments. This involves ensuring that the File global object is available and polyfilling modern String.prototype methods like toWellFormed and isWellFormed. The goal is to provide a more robust and consistent environment for applications relying on these features, especially when running on Node.js versions prior to 20.
Highlights
- Ensuring
globalThis.Fileavailability forundicicompatibility: I've added a check within thepatchForNode16function to ensure thatglobalThis.Fileis defined. If it's missing, I assign theFileclass imported fromnode:bufferto it. This change is specifically aimed at resolving compatibility issues withundiciwhen running on Node.js versions older than 20, as indicated by the linkedundiciGitHub issue. - Polyfilling
String.prototype.toWellFormedandString.prototype.isWellFormed: I've also included polyfills forString.prototype.toWellFormedandString.prototype.isWellFormedwithin thepatchForNode16function. These polyfills usetoUSVStringfromnode:utilto provide the functionality of these modern string methods, which are useful for handling well-formed Unicode strings.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request adds polyfills for File, String.prototype.toWellFormed, and String.prototype.isWellFormed to improve compatibility with different Node.js versions and undici library versions. The changes are generally good, but I've suggested a refactoring for the string prototype polyfills to improve code clarity, fix inconsistent indentation, and reduce the number of @ts-ignore suppressions.
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
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/index.ts(1 hunks)src/utils.ts(2 hunks)
🧰 Additional context used
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 20)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 18)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 24)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (macos-latest, 20)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (macos-latest, 18)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (windows-latest, 24)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 16)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (windows-latest, 20)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (macos-latest, 22)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 22)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (windows-latest, 18)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (macos-latest, 16)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (windows-latest, 22)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (macos-latest, 24)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Check: Node.js / Test (windows-latest, 16)
src/utils.ts
[failure] 251-251:
Expected indentation of 4 spaces but found 6
[failure] 250-250:
Expected indentation of 6 spaces but found 10
[failure] 249-249:
Expected indentation of 6 spaces but found 10
[failure] 248-248:
Expected indentation of 6 spaces but found 10
[failure] 247-247:
Unexpected space before function parentheses
[failure] 247-247:
String prototype is read only, properties should not be added
[failure] 247-247:
Expected indentation of 4 spaces but found 6
[failure] 246-246:
Expected indentation of 4 spaces but found 6
[failure] 245-245:
Expected indentation of 4 spaces but found 6
[failure] 241-241:
Trailing spaces not allowed
🪛 GitHub Actions: CI
src/utils.ts
[error] 241-241: ESLint: Trailing spaces not allowed (no-trailing-spaces)
🔇 Additional comments (2)
src/utils.ts (1)
5-6: LGTM!The imports are correctly added for the new polyfills.
src/index.ts (1)
4-4: LGTM!Good formatting improvement for readability.
66c0920 to
89fbcb3
Compare
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: 1
♻️ Duplicate comments (1)
src/utils.ts (1)
235-240: Useglobal.Filefor consistency.This inconsistency was already identified in past reviews - the polyfill should use
global.Fileinstead ofglobalThis.Fileto maintain consistency with other polyfills in this function.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.eslintrc(1 hunks)src/index.ts(1 hunks)src/utils.ts(2 hunks)test/options.stream.test.ts(1 hunks)
✅ Files skipped from review due to trivial changes (3)
- src/index.ts
- .eslintrc
- test/options.stream.test.ts
🧰 Additional context used
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 22)
src/utils.ts
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 18)
src/utils.ts
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
🪛 GitHub Check: Node.js / Test (macos-latest, 24)
src/utils.ts
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 16)
src/utils.ts
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
🪛 GitHub Check: Node.js / Test (macos-latest, 20)
src/utils.ts
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 24)
src/utils.ts
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
🪛 GitHub Check: Node.js / Test (macos-latest, 18)
src/utils.ts
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
🪛 GitHub Check: Node.js / Test (ubuntu-latest, 20)
src/utils.ts
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
🪛 GitHub Check: Node.js / Test (macos-latest, 16)
src/utils.ts
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
[warning] 259-259:
String prototype is read only, properties should not be added
[warning] 247-247:
String prototype is read only, properties should not be added
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Node.js / Test (windows-latest, 22)
- GitHub Check: Node.js / Test (macos-latest, 22)
- GitHub Check: Node.js / Test (windows-latest, 24)
- GitHub Check: Node.js / Test (windows-latest, 16)
- GitHub Check: Node.js / Test (windows-latest, 18)
- GitHub Check: Node.js / Test (windows-latest, 20)
🔇 Additional comments (1)
src/utils.ts (1)
5-6: LGTM!The new imports for
FileandtoUSVStringare correct and necessary for the polyfills being implemented.
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #588 +/- ##
==========================================
- Coverage 95.67% 95.27% -0.40%
==========================================
Files 11 11
Lines 1364 1377 +13
Branches 313 316 +3
==========================================
+ Hits 1305 1312 +7
- Misses 55 61 +6
Partials 4 4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
27be7cc to
c85bef5
Compare
[skip ci] ## <small>4.8.1 (2025-08-06)</small> * chore: add GIT_TOKEN ([baabae9](baabae9)) * chore: use npm trusted publisher (#589) ([8f2ed13](8f2ed13)), closes [#589](#589) * chore(deps): update dependency cross-env to v10 (#584) ([ad4405a](ad4405a)), closes [#584](#584) * chore(deps): update dependency selfsigned to v3 (#582) ([9e62fb1](9e62fb1)), closes [#582](#582) * fix: patch undici File support on Node.js < 20 (#588) ([0e5ad19](0e5ad19)), closes [#588](#588)
|
🎉 This PR is included in version 4.8.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
|
这样全局的 patch 可能会额外的带来一些不兼容性,revert 一下吧。低版本应该用 urllib3。 |
OK |
Summary by CodeRabbit
New Features
Style
Bug Fixes
Chores