-
Notifications
You must be signed in to change notification settings - Fork 736
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
chore: replace node-fetch
with undici
#348
Conversation
🦋 Changeset detectedLatest commit: be2c20d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
6b4a5e6
to
1ac3642
Compare
node-fetch
with undici
node-fetch
with undici
I get a little nervous with reviews like this because pages doesn't have test coverage. @GregBrimble I don't expect anything to break by upping |
@@ -12,7 +12,13 @@ | |||
"jsx": "react", | |||
"resolveJsonModule": true, | |||
"incremental": true, | |||
"strictNullChecks": true | |||
"strictNullChecks": true, | |||
"skipLibCheck": true |
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 assume this will be the controversial part of this PR, so I'm calling it out right now. Have I misunderstood how this flag works, and does it make our codebase worse?
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.
1ac3642
to
870d1b2
Compare
There are several reasons to replace `node-fetch` with `undici`: - `undici`'s `fetch()` implementation is set to become node's standard `fetch()` implementation, which means we can just remove the dependency in the future (or optionally load it depending on which version of node is being used) - `node-fetch` pollutes the global type space with a number of standard types - we already bundle `undici` via `miniflare`/pages, so this means our bundle size could ostensibly become smaller. This replaces `node-fetch` with `undici`. - All instances of `import fetch from "node-fetch"` are replaced with `import {fetch} from "undici"` - `undici` also comes with spec compliant forms of `FormData` and `File`, so we could also remove `formdata-node` in `form_data.ts` - All the global types that were injected by `node-fetch` are now imported from `undici` (as well as some mistaken ones from `node:url`) - NOTE: this also turns on `skipLibCheck` in `tsconfig.json`. Some dependencies oddly depend on browser globals like `Request`, `Response` (like `@miniflare/core`, `jest-fetch-mock`, etc), which now fail because `node-fetch` isn't injecting those globals anymore. So we enable `skipLibCheck` to bypass them. (I'd thought `skipLibCheck` completely ignores 'third party' types, but that's not true - it still uses the module graph to scan types. So we're still typesafe. We should enable `strict` sometime to avoid `any`s, but that's for later.) - The bundle size isn't smaller because we're bundling 2 different versions of `undici`, but we'll fix that by separately upping the version of `undici` that miniflare bundles.
870d1b2
to
be2c20d
Compare
There are several reasons to replace
node-fetch
withundici
:undici
'sfetch()
implementation is set to become node's standardfetch()
implementation, which means we can just remove the dependency in the future (or optionally load it depending on which version of node is being used)node-fetch
pollutes the global type space with a number of standard typesundici
viaminiflare
/pages, so this means our bundle size could ostensibly become smaller.This replaces
node-fetch
withundici
.import fetch from "node-fetch"
are replaced withimport {fetch} from "undici"
undici
also comes with spec compliant forms ofFormData
andFile
, so we could also removeformdata-node
inform_data.ts
node-fetch
are now imported fromundici
(as well as some mistaken ones fromnode:url
)skipLibCheck
intsconfig.json
. Some dependencies oddly depend on browser globals likeRequest
,Response
(like@miniflare/core
,jest-fetch-mock
, etc), which now fail becausenode-fetch
isn't injecting those globals anymore. So we enableskipLibCheck
to bypass them. (I'd thoughtskipLibCheck
completely ignores 'third party' types, but that's not true - it still uses the module graph to scan types. So we're still typesafe. We should enablestrict
sometime to avoidany
s, but that's for later.)undici
, but we'll fix that by separately upping the version ofundici
that miniflare bundles.