fix: polyfill File using undici instead of node:buffer (#8139)
* fix: polyfill File using undici instead of node:buffer * chore: changeset
This commit is contained in:
parent
e5c13881f1
commit
db39206cbb
2 changed files with 9 additions and 8 deletions
5
.changeset/angry-dogs-shake.md
Normal file
5
.changeset/angry-dogs-shake.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Use `undici` for File changeset for Node 16 compatibility
|
|
@ -1,4 +1,3 @@
|
||||||
import { File } from 'node:buffer';
|
|
||||||
import crypto from 'node:crypto';
|
import crypto from 'node:crypto';
|
||||||
import {
|
import {
|
||||||
ByteLengthQueuingStrategy,
|
ByteLengthQueuingStrategy,
|
||||||
|
@ -14,13 +13,13 @@ import {
|
||||||
WritableStreamDefaultController,
|
WritableStreamDefaultController,
|
||||||
WritableStreamDefaultWriter,
|
WritableStreamDefaultWriter,
|
||||||
} from 'node:stream/web';
|
} from 'node:stream/web';
|
||||||
import { FormData, Headers, Request, Response, fetch, File as undiciFile } from 'undici';
|
import { File, FormData, Headers, Request, Response, fetch } from 'undici';
|
||||||
|
|
||||||
// NOTE: This file does not intend to polyfill everything that exists, its main goal is to make life easier
|
// NOTE: This file does not intend to polyfill everything that exists, its main goal is to make life easier
|
||||||
// for users deploying to runtime that do support these features. In the future, we hope for this file to disappear.
|
// for users deploying to runtime that do support these features. In the future, we hope for this file to disappear.
|
||||||
|
|
||||||
// HACK (2023-08-18) Stackblitz does not support Node 18 yet, so we'll fake Node 16 support for some time until it's supported
|
// HACK (2023-08-18) Stackblitz does not support Node 18 yet, so we'll fake Node 16 support for some time until it's supported
|
||||||
// TODO: Remove when Node 18 is supported on Stackblitz
|
// TODO: Remove when Node 18 is supported on Stackblitz. File should get imported from `node:buffer` instead of `undici` once this is removed
|
||||||
const isStackblitz = process.env.SHELL === '/bin/jsh' && process.versions.webcontainer != null;
|
const isStackblitz = process.env.SHELL === '/bin/jsh' && process.versions.webcontainer != null;
|
||||||
|
|
||||||
export function apply() {
|
export function apply() {
|
||||||
|
@ -38,7 +37,7 @@ export function apply() {
|
||||||
WritableStream,
|
WritableStream,
|
||||||
WritableStreamDefaultController,
|
WritableStreamDefaultController,
|
||||||
WritableStreamDefaultWriter,
|
WritableStreamDefaultWriter,
|
||||||
undiciFile,
|
File,
|
||||||
FormData,
|
FormData,
|
||||||
Headers,
|
Headers,
|
||||||
Request,
|
Request,
|
||||||
|
@ -54,10 +53,7 @@ export function apply() {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
enumerable: true,
|
enumerable: true,
|
||||||
writable: true,
|
writable: true,
|
||||||
value:
|
value: neededPolyfills[polyfillName as keyof typeof neededPolyfills],
|
||||||
neededPolyfills[
|
|
||||||
(polyfillName === 'undiciFile' ? 'File' : polyfillName) as keyof typeof neededPolyfills
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue