Skip to content

Commit

Permalink
Fix: support FormData object on fetch body (#3417)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bholmesdev authored May 20, 2022
1 parent d296eb6 commit 4de53ec
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
6 changes: 6 additions & 0 deletions .changeset/serious-vans-smell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@astrojs/webapi': minor
'astro': patch
---

Fix: support FormData object on fetch body
4 changes: 3 additions & 1 deletion packages/webapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
],
"bugs": "https://github.com/withastro/astro/issues",
"homepage": "https://github.com/withastro/astro/tree/main/packages/webapi#readme",
"dependencies": {
"node-fetch": "^3.2.4"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-inject": "^4.0.4",
Expand All @@ -65,7 +68,6 @@
"formdata-polyfill": "^4.0.10",
"magic-string": "^0.25.9",
"mocha": "^9.2.2",
"node-fetch": "^3.2.4",
"rollup": "^2.74.1",
"rollup-plugin-terser": "^7.0.2",
"tslib": "^2.4.0",
Expand Down
1 change: 1 addition & 0 deletions packages/webapi/run/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ async function build() {
inputOptions: {
input: 'src/polyfill.ts',
plugins: plugins,
external: ['node-fetch'],
onwarn(warning, warn) {
if (warning.code !== 'UNRESOLVED_IMPORT') warn(warning)
},
Expand Down
13 changes: 4 additions & 9 deletions packages/webapi/src/lib/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import {
Headers,
Request,
Response,
} from 'node-fetch/src/index.js'
} from 'node-fetch'
import type { RequestInit } from 'node-fetch'
import Stream from 'node:stream'
import * as _ from './utils'

export { Headers, Request, Response }

export const fetch = {
fetch(
resource: string | URL | Request,
resource: string | Request,
init?: Partial<FetchInit>
): Promise<Response> {
const resourceURL = new URL(
Expand Down Expand Up @@ -62,13 +63,7 @@ export const fetch = {
type USVString = {} & string

interface FetchInit {
body:
| Blob
| BufferSource
| FormData
| URLSearchParams
| ReadableStream
| USVString
body: RequestInit['body']
cache:
| 'default'
| 'no-store'
Expand Down
16 changes: 5 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4de53ec

Please sign in to comment.