-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: swap node-fetch for undici (#4)
node-fetch does not use browser streams which makes using it in typed environments very hard since the methods on node streams are different from those on browser streams. undici is a node implementation of fetch that supports browser streams and is probably the closest thing we'll ever see to fetch in node core, so swap node-fetch for undici. BREAKING CHANGE: only browser streams are returned, requires node 16+
- Loading branch information
1 parent
2fc76e7
commit c744c71
Showing
6 changed files
with
59 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** @type {import('aegir').Options["build"]["config"]} */ | ||
const esbuild = { | ||
plugins: [ | ||
{ | ||
name: 'node built ins', | ||
setup (build) { | ||
build.onResolve({ filter: /^undici$/ }, () => { | ||
return { path: require.resolve('./scripts/undici') } | ||
}) | ||
} | ||
} | ||
] | ||
} | ||
|
||
/** @type {import('aegir').PartialOptions} */ | ||
module.exports = { | ||
build: { | ||
config: esbuild | ||
}, | ||
test: { | ||
browser: { | ||
config: { | ||
buildConfig: esbuild | ||
} | ||
} | ||
} | ||
} |
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
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
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,2 @@ | ||
|
||
module.exports = {} |
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 |
---|---|---|
@@ -1,17 +1,18 @@ | ||
'use strict' | ||
|
||
// @ts-expect-error globalThis.fetch is defined according to the env types but it's not in node | ||
if (globalThis.fetch && globalThis.Headers && globalThis.Request && globalThis.Response) { | ||
module.exports = { | ||
default: globalThis.fetch, | ||
fetch: globalThis.fetch, | ||
Headers: globalThis.Headers, | ||
Request: globalThis.Request, | ||
Response: globalThis.Response | ||
} | ||
} else { | ||
module.exports = { | ||
default: require('node-fetch').default, | ||
Headers: require('node-fetch').Headers, | ||
Request: require('node-fetch').Request, | ||
Response: require('node-fetch').Response | ||
fetch: require('undici').fetch, | ||
Headers: require('undici').Headers, | ||
Request: require('undici').Request, | ||
Response: require('undici').Response | ||
} | ||
} |
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