Skip to content

Commit

Permalink
fix: polyfill File using undici instead of node:buffer (#8139)
Browse files Browse the repository at this point in the history
* fix: polyfill File using undici instead of node:buffer

* chore: changeset
  • Loading branch information
Princesseuh committed Aug 18, 2023
1 parent e5c1388 commit db39206
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-dogs-shake.md
@@ -0,0 +1,5 @@
---
'astro': patch
---

Use `undici` for File changeset for Node 16 compatibility
12 changes: 4 additions & 8 deletions packages/astro/src/core/polyfill.ts
@@ -1,4 +1,3 @@
import { File } from 'node:buffer';
import crypto from 'node:crypto';
import {
ByteLengthQueuingStrategy,
Expand All @@ -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() {
Expand All @@ -38,7 +37,7 @@ export function apply() {
WritableStream,
WritableStreamDefaultController,
WritableStreamDefaultWriter,
undiciFile,
File,
FormData,
Headers,
Request,
Expand All @@ -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],
});
}
}
Expand Down

0 comments on commit db39206

Please sign in to comment.