diff options
author | 2023-08-18 18:23:51 +0200 | |
---|---|---|
committer | 2023-08-18 18:23:51 +0200 | |
commit | db39206cbb85b034859ac416179f141184bb2bff (patch) | |
tree | 105b4d3901be4ae9e478f4d780dd8edb7124153a | |
parent | e5c13881f188f7e67595e3b2c32940b603cc388c (diff) | |
download | astro-db39206cbb85b034859ac416179f141184bb2bff.tar.gz astro-db39206cbb85b034859ac416179f141184bb2bff.tar.zst astro-db39206cbb85b034859ac416179f141184bb2bff.zip |
fix: polyfill File using undici instead of node:buffer (#8139)
* fix: polyfill File using undici instead of node:buffer
* chore: changeset
-rw-r--r-- | .changeset/angry-dogs-shake.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/polyfill.ts | 12 |
2 files changed, 9 insertions, 8 deletions
diff --git a/.changeset/angry-dogs-shake.md b/.changeset/angry-dogs-shake.md new file mode 100644 index 000000000..979fcf0f4 --- /dev/null +++ b/.changeset/angry-dogs-shake.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Use `undici` for File changeset for Node 16 compatibility diff --git a/packages/astro/src/core/polyfill.ts b/packages/astro/src/core/polyfill.ts index 9c0a3b1a2..053570cc2 100644 --- a/packages/astro/src/core/polyfill.ts +++ b/packages/astro/src/core/polyfill.ts @@ -1,4 +1,3 @@ -import { File } from 'node:buffer'; import crypto from 'node:crypto'; import { ByteLengthQueuingStrategy, @@ -14,13 +13,13 @@ import { WritableStreamDefaultController, WritableStreamDefaultWriter, } 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 // 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 -// 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; export function apply() { @@ -38,7 +37,7 @@ export function apply() { WritableStream, WritableStreamDefaultController, WritableStreamDefaultWriter, - undiciFile, + File, FormData, Headers, Request, @@ -54,10 +53,7 @@ export function apply() { configurable: true, enumerable: true, writable: true, - value: - neededPolyfills[ - (polyfillName === 'undiciFile' ? 'File' : polyfillName) as keyof typeof neededPolyfills - ], + value: neededPolyfills[polyfillName as keyof typeof neededPolyfills], }); } } |