From 0abd1d3e42cf7bf5efb8c41f37e011b933fb0629 Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Fri, 3 Mar 2023 14:47:24 +0100 Subject: [PATCH] Use undici's FormData for polyfilling (#6413) * fix(webapi): Use undici's FormData instead of a polyfill * chore: changeset --- .changeset/cool-bags-mix.md | 5 +++++ packages/webapi/LICENSE | 2 -- packages/webapi/README.md | 2 -- packages/webapi/mod.d.ts | 24 ++++++++++++------------ packages/webapi/package.json | 1 - packages/webapi/src/ponyfill.ts | 11 +++++------ pnpm-lock.yaml | 5 +++-- 7 files changed, 25 insertions(+), 25 deletions(-) create mode 100644 .changeset/cool-bags-mix.md diff --git a/.changeset/cool-bags-mix.md b/.changeset/cool-bags-mix.md new file mode 100644 index 000000000..616d7f0a6 --- /dev/null +++ b/.changeset/cool-bags-mix.md @@ -0,0 +1,5 @@ +--- +'@astrojs/webapi': patch +--- + +Use undici's FormData instead of a polyfill diff --git a/packages/webapi/LICENSE b/packages/webapi/LICENSE index bb084e8bd..d513f83db 100644 --- a/packages/webapi/LICENSE +++ b/packages/webapi/LICENSE @@ -25,5 +25,3 @@ THE SOFTWARE. Code from [@astrocommunity/webapi](https://www.npmjs.com/@astrocommunity/webapi) is licensed under the CC0-1.0 License. Code from [event-target-shim](https://www.npmjs.com/package/event-target-shim) is licensed under the MIT License (MIT), Copyright Toru Nagashima. - -Code from [formdata-polyfill](https://www.npmjs.com/package/formdata-polyfill) is licensed under the MIT License (MIT), Copyright Jimmy Wärting. diff --git a/packages/webapi/README.md b/packages/webapi/README.md index aadc6db8d..4a0d9b5c9 100644 --- a/packages/webapi/README.md +++ b/packages/webapi/README.md @@ -155,5 +155,3 @@ polyfill(globalThis, { Thank you to Jon Neal for his work on the original [webapi](https://github.com/astro-community/webapi) project that this package is forked from. Licensed under the CC0-1.0 License. Code from [event-target-shim](https://www.npmjs.com/package/event-target-shim) is licensed under the MIT License (MIT), Copyright Toru Nagashima. - -Code from [formdata-polyfill](https://www.npmjs.com/package/formdata-polyfill) is licensed under the MIT License (MIT), Copyright Jimmy Wärting. diff --git a/packages/webapi/mod.d.ts b/packages/webapi/mod.d.ts index 00be1f274..ecc902364 100644 --- a/packages/webapi/mod.d.ts +++ b/packages/webapi/mod.d.ts @@ -1,13 +1,13 @@ // organize-imports-ignore -export { pathToPosix } from './lib/utils'; -export { alert, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js'; -export declare const polyfill: { - (target: any, options?: PolyfillOptions): any; - internals(target: any, name: string): any; -}; -interface PolyfillOptions { - exclude?: string | string[]; - override?: Record; -} \ No newline at end of file +export { pathToPosix } from './lib/utils'; +export { alert, ByteLengthQueuingStrategy, cancelAnimationFrame, cancelIdleCallback, CanvasRenderingContext2D, CharacterData, clearTimeout, Comment, CountQueuingStrategy, CSSStyleSheet, CustomElementRegistry, CustomEvent, Document, DocumentFragment, DOMException, Element, Event, EventTarget, fetch, File, FormData, Headers, HTMLBodyElement, HTMLCanvasElement, HTMLDivElement, HTMLDocument, HTMLElement, HTMLHeadElement, HTMLHtmlElement, HTMLImageElement, HTMLSpanElement, HTMLStyleElement, HTMLTemplateElement, HTMLUnknownElement, Image, ImageData, IntersectionObserver, MediaQueryList, MutationObserver, Node, NodeFilter, NodeIterator, OffscreenCanvas, ReadableByteStreamController, ReadableStream, ReadableStreamBYOBReader, ReadableStreamBYOBRequest, ReadableStreamDefaultController, ReadableStreamDefaultReader, Request, requestAnimationFrame, requestIdleCallback, ResizeObserver, Response, setTimeout, ShadowRoot, structuredClone, StyleSheet, Text, TransformStream, TreeWalker, URLPattern, Window, WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, } from './mod.js'; +export declare const polyfill: { + (target: any, options?: PolyfillOptions): any; + internals(target: any, name: string): any; +}; +interface PolyfillOptions { + exclude?: string | string[]; + override?: Record; +} \ No newline at end of file diff --git a/packages/webapi/package.json b/packages/webapi/package.json index 61e808eab..cf68eb783 100644 --- a/packages/webapi/package.json +++ b/packages/webapi/package.json @@ -63,7 +63,6 @@ "@ungap/structured-clone": "^0.3.4", "chai": "^4.3.6", "event-target-shim": "^6.0.2", - "formdata-polyfill": "^4.0.10", "magic-string": "^0.27.0", "mocha": "^9.2.2", "rollup": "^2.79.1", diff --git a/packages/webapi/src/ponyfill.ts b/packages/webapi/src/ponyfill.ts index 25c880fda..368f7ee5b 100644 --- a/packages/webapi/src/ponyfill.ts +++ b/packages/webapi/src/ponyfill.ts @@ -1,6 +1,5 @@ // @ts-check -import { Event, EventTarget } from 'event-target-shim' -import { FormData } from 'formdata-polyfill/esm.min.js' +import { Event, EventTarget } from 'event-target-shim' // Look into removing when Node 18 is dropped for Node 20 import { ByteLengthQueuingStrategy, CountQueuingStrategy, @@ -14,18 +13,18 @@ import { WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, -} from 'node:stream/web' -import { fetch, File, Headers, Request, Response } from 'undici' +} from 'node:stream/web' // Remove when Node 16 is dropped for Node 18. +import { fetch, File, FormData, Headers, Request, Response } from 'undici' // Remove when Node 16 is dropped for Node 18. import { URLPattern } from 'urlpattern-polyfill' import { cancelAnimationFrame, requestAnimationFrame, } from './lib/AnimationFrame' import { CharacterData, Comment, Text } from './lib/CharacterData' -import { CustomEvent } from './lib/CustomEvent' +import { CustomEvent } from './lib/CustomEvent' // Look into removing when Node 18 is dropped for Node 20 import { DOMException } from './lib/DOMException' import { cancelIdleCallback, requestIdleCallback } from './lib/IdleCallback' -import structuredClone from './lib/structuredClone' +import structuredClone from './lib/structuredClone' // Remove when Node 16 is dropped for Node 18. import { clearTimeout, setTimeout } from './lib/Timeout' import { TreeWalker } from './lib/TreeWalker' diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b548db06a..e6fbaa05d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -3694,7 +3694,6 @@ importers: '@ungap/structured-clone': ^0.3.4 chai: ^4.3.6 event-target-shim: ^6.0.2 - formdata-polyfill: ^4.0.10 magic-string: ^0.27.0 mocha: ^9.2.2 rollup: ^2.79.1 @@ -3715,7 +3714,6 @@ importers: '@ungap/structured-clone': 0.3.4 chai: 4.3.7 event-target-shim: 6.0.2 - formdata-polyfill: 4.0.10 magic-string: 0.27.0 mocha: 9.2.2 rollup: 2.79.1 @@ -10032,6 +10030,7 @@ packages: dependencies: node-domexception: 1.0.0 web-streams-polyfill: 3.2.1 + dev: false /file-entry-cache/6.0.1: resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==} @@ -10144,6 +10143,7 @@ packages: engines: {node: '>=12.20.0'} dependencies: fetch-blob: 3.2.0 + dev: false /fraction.js/4.2.0: resolution: {integrity: sha512-MhLuK+2gUcnZe8ZHlaaINnQLl0xRIGRfcGk2yl8xoQAfHrSsL3rYu6FCmBdkdbhc9EPlwyGHewaRsvwRMJtAlA==} @@ -12380,6 +12380,7 @@ packages: /node-domexception/1.0.0: resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==} engines: {node: '>=10.5.0'} + dev: false /node-fetch-native/1.0.1: resolution: {integrity: sha512-VzW+TAk2wE4X9maiKMlT+GsPU4OMmR1U9CrHSmd3DFLn2IcZ9VJ6M6BBugGfYUnPCLSYxXdZy17M0BEJyhUTwg==}