-
Notifications
You must be signed in to change notification settings - Fork 60
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
BREAKING CHANGE: remove node-fetch
in favor of global
#580
Conversation
You can also add this to
That way it doesnt require any changes to the existing code, and it will not be a breaking change anymore. |
node-fetch
in favor of globalnode-fetch
in favor of global
Can you fix the tests for Node 14 and 16? |
I think adding a simple patch like so will work: (async function () {
if (parseInt(process.versions.node.split(".")[0]) <= 18) {
// @ts-expect-error
globalThis.fetch = await import("node-fetch");
}
})(); |
@wolfy1339 I think that way bundlers will still include node-fetch, because they cannot evaluate the if-expression during bundling. With the solution I suggested I reduced the size of my app that requires octokit significantly. |
The patch shouldn't go in any production code, just for the test files. |
Okay, sorry I misunderstood. But I still think nodefetch-native would be an easier solution. It uses the native fetch when available (node 18+) and uses nodefetch 3.0 as a fallback for lower versions. This would allow request.js to transition to native fetch without breaking anything for older versions. I am using request.js with it without any problems. |
@wolfy1339 I used a similar solution but with I confirmed the tests are now passing on node 16 and 18. |
node-fetch
in favor of globalnode-fetch
in favor of global
Even with As |
I didn't notice anything about timeouts, all I can say is that I didn't notice any change in behaviour when using |
We are using |
I would remove the dependency on A custom Node 16 is the last version that doesn't have it built in, and it will be out of maintenance mode in September. After that all current JavaScript runtime environments have the global fetch method. It might make sense to remove support for both Node 14 & Node 16 at this point, and while doing that also remove the dependency on node-fetch |
We'll need to remove the |
There is a similar solution for timeout using AbortSignal.timeout(opts.timeout) Although if the consumer provides their own fetch then they can provider their own options too, so we can remove the options now that I think about it. Let me know how to proceed. |
Since this is going to be a breaking change, let's just remove that option from our code altogether |
note that this will also be a breaking change for all the packages that depend on |
test/request.test.ts
Outdated
@@ -447,7 +451,7 @@ x//0u+zd/R/QRUzLOw4N72/Hu+UG6MNt5iDZFCtapRaKt6OvSBwy8w== | |||
}); | |||
|
|||
it("passes node-fetch options to fetch only", () => { |
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.
Remove timeout
parameter tests
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.
Removed it from the tests in ea7c2ab
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.
These tests don't really seem useful now. Could you remove them
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.
Sounds good! Removed in 3cfc7c8
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.
I would recommend we also remove the request.timeout
option while at it. We already recommend options.request.signal
today
Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
Looks like I have some merge conflicts now. Do you prefer |
Either way is fine. We squash and merge anyways in the end. |
Merge is easier to keep track of new changes for reviewers. |
@wolfy1339 @gr2m I fixed the merge conflicts and addressed the remaining comments, thanks! |
There are some linting issues left to fix. |
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.
Great work, just some lint errors left:
https://github.com/octokit/request.js/actions/runs/5039405053/jobs/9038110405?pr=580#step:5:7
running npm run lint:fix
should do the trick
Wow this is a big day for Octokit's cross plattform support. Thank you all for making this a reality ❤️ |
🎉 This PR is included in version 7.0.0-beta.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
* ci: stop testing against NodeJS v14, v16 (#581) BREAKING CHANGE: Drop support for NodeJS v14, v16 * feat: remove `node-fetch` in favor of global (#580) BREAKING CHANGE: remove `node-fetch` in favor of global * docs: update ToC for README.md * fix(deps): update dependency @octokit/request-error to v4 (#587) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix: bump `@octokit/request-error` * fix(deps): bump `@octokit/types` * fix(build): bump Octokit deps * tests: adapt for `@octokit/endpoint` v8 * fix(deps): upgrade to `@octokit/endpoint` v8 stable --------- Co-authored-by: Steven <steven@ceriously.com> Co-authored-by: prettier-toc-me[bot] <56236715+prettier-toc-me[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Keegan Campbell <me@kfcampbell.com>
node-fetch
and add end-to-end test to catch breaking changes #432Behavior
Before the change?
Previously you could run this on Node.js 14 and 16 without manually polyfilling
fetch
.After the change?
With this PR it will work in Node.js 18, browsers, and any JS runtime that provides
fetch
. If you want to run in Node.js 14 or 16, you can polyfillglobalThis.fetch
or pass in the request options.Other information
This improves compatibility with many runtimes because
node-fetch
is not the same as the standardfetch
global.Additional info
Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!
Type: Breaking change
label)If
Yes
, what's the impact:If you want to run in Node.js 14 or 16, you must polyfill
globalThis.fetch
or pass in the request options.Pull request type
Please add the corresponding label for change this PR introduces:
Type: Feature