diff options
Diffstat (limited to 'packages/astro/src/core/polyfill.ts')
-rw-r--r-- | packages/astro/src/core/polyfill.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/packages/astro/src/core/polyfill.ts b/packages/astro/src/core/polyfill.ts new file mode 100644 index 000000000..7b0280fb7 --- /dev/null +++ b/packages/astro/src/core/polyfill.ts @@ -0,0 +1,22 @@ +import buffer from 'node:buffer'; +import crypto from 'node:crypto'; + +/** + * Astro aims to compatible with web standards as much as possible. + * This function adds two objects that are globally-available on most javascript runtimes but not on node 18. + */ +export function apply() { + // Remove when Node 18 is dropped for Node 20 + if (!globalThis.crypto) { + Object.defineProperty(globalThis, 'crypto', { + value: crypto.webcrypto, + }); + } + + // Remove when Node 18 is dropped for Node 20 + if (!globalThis.File) { + Object.defineProperty(globalThis, 'File', { + value: buffer.File, + }); + } +} |