Skip to content

Commit 4de53ec

Browse files
authored
Fix: support FormData object on fetch body (#3417)
* refactor: make node-fetch external in rollup build * deps: make node-fetch standard dep * refactor: switch to node-fetch pkg ref in fetch.ts * chore: changeset * chore: bump webapi to minor change
1 parent d296eb6 commit 4de53ec

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

.changeset/serious-vans-smell.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@astrojs/webapi': minor
3+
'astro': patch
4+
---
5+
6+
Fix: support FormData object on fetch body

packages/webapi/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
],
5050
"bugs": "https://github.com/withastro/astro/issues",
5151
"homepage": "https://github.com/withastro/astro/tree/main/packages/webapi#readme",
52+
"dependencies": {
53+
"node-fetch": "^3.2.4"
54+
},
5255
"devDependencies": {
5356
"@rollup/plugin-alias": "^3.1.9",
5457
"@rollup/plugin-inject": "^4.0.4",
@@ -65,7 +68,6 @@
6568
"formdata-polyfill": "^4.0.10",
6669
"magic-string": "^0.25.9",
6770
"mocha": "^9.2.2",
68-
"node-fetch": "^3.2.4",
6971
"rollup": "^2.74.1",
7072
"rollup-plugin-terser": "^7.0.2",
7173
"tslib": "^2.4.0",

packages/webapi/run/build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ async function build() {
178178
inputOptions: {
179179
input: 'src/polyfill.ts',
180180
plugins: plugins,
181+
external: ['node-fetch'],
181182
onwarn(warning, warn) {
182183
if (warning.code !== 'UNRESOLVED_IMPORT') warn(warning)
183184
},

packages/webapi/src/lib/fetch.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import {
33
Headers,
44
Request,
55
Response,
6-
} from 'node-fetch/src/index.js'
6+
} from 'node-fetch'
7+
import type { RequestInit } from 'node-fetch'
78
import Stream from 'node:stream'
89
import * as _ from './utils'
910

1011
export { Headers, Request, Response }
1112

1213
export const fetch = {
1314
fetch(
14-
resource: string | URL | Request,
15+
resource: string | Request,
1516
init?: Partial<FetchInit>
1617
): Promise<Response> {
1718
const resourceURL = new URL(
@@ -62,13 +63,7 @@ export const fetch = {
6263
type USVString = {} & string
6364

6465
interface FetchInit {
65-
body:
66-
| Blob
67-
| BufferSource
68-
| FormData
69-
| URLSearchParams
70-
| ReadableStream
71-
| USVString
66+
body: RequestInit['body']
7267
cache:
7368
| 'default'
7469
| 'no-store'

pnpm-lock.yaml

Lines changed: 5 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)