summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.changeset/clever-years-appear.md5
-rw-r--r--packages/astro/package.json1
-rw-r--r--packages/astro/src/core/build/index.ts4
-rw-r--r--packages/astro/src/core/create-vite.ts2
-rw-r--r--packages/astro/src/core/dev/index.ts4
-rw-r--r--yarn.lock5
6 files changed, 19 insertions, 2 deletions
diff --git a/.changeset/clever-years-appear.md b/.changeset/clever-years-appear.md
new file mode 100644
index 000000000..275faecf8
--- /dev/null
+++ b/.changeset/clever-years-appear.md
@@ -0,0 +1,5 @@
+---
+'astro': minor
+---
+
+Replaced `fetch` walk-n-replace with globalThis polyfill
diff --git a/packages/astro/package.json b/packages/astro/package.json
index 4617c0a6b..2e8698df5 100644
--- a/packages/astro/package.json
+++ b/packages/astro/package.json
@@ -64,6 +64,7 @@
"@astrojs/renderer-react": "0.3.1",
"@astrojs/renderer-svelte": "0.2.2",
"@astrojs/renderer-vue": "0.2.1",
+ "@astropub/webapi": "^0.4.0",
"@babel/core": "^7.15.8",
"@babel/traverse": "^7.15.4",
"@proload/core": "^0.2.1",
diff --git a/packages/astro/src/core/build/index.ts b/packages/astro/src/core/build/index.ts
index 1842afc22..a47d1aaba 100644
--- a/packages/astro/src/core/build/index.ts
+++ b/packages/astro/src/core/build/index.ts
@@ -7,6 +7,7 @@ import { rollupPluginAstroBuildHTML } from '../../vite-plugin-build-html/index.j
import { rollupPluginAstroBuildCSS } from '../../vite-plugin-build-css/index.js';
import fs from 'fs';
import * as colors from 'kleur/colors';
+import { polyfill } from '@astropub/webapi';
import { performance } from 'perf_hooks';
import vite, { ViteDevServer } from '../vite.js';
import { fileURLToPath } from 'url';
@@ -25,6 +26,9 @@ export interface BuildOptions {
/** `astro build` */
export default async function build(config: AstroConfig, options: BuildOptions = { logging: defaultLogOptions }): Promise<void> {
+ // polyfill WebAPIs to globalThis for Node v12, Node v14, and Node v16
+ polyfill(globalThis);
+
const builder = new AstroBuilder(config, options);
await builder.build();
}
diff --git a/packages/astro/src/core/create-vite.ts b/packages/astro/src/core/create-vite.ts
index 485300f7a..2001afc54 100644
--- a/packages/astro/src/core/create-vite.ts
+++ b/packages/astro/src/core/create-vite.ts
@@ -10,7 +10,6 @@ import astroPostprocessVitePlugin from '../vite-plugin-astro-postprocess/index.j
import configAliasVitePlugin from '../vite-plugin-config-alias/index.js';
import markdownVitePlugin from '../vite-plugin-markdown/index.js';
import jsxVitePlugin from '../vite-plugin-jsx/index.js';
-import fetchVitePlugin from '../vite-plugin-fetch/index.js';
import { resolveDependency } from './util.js';
// Some packages are just external, and that’s the way it goes.
@@ -55,7 +54,6 @@ export async function createVite(inlineConfig: ViteConfigWithSSR, { astroConfig,
markdownVitePlugin({ config: astroConfig, devServer }),
jsxVitePlugin({ config: astroConfig, logging }),
astroPostprocessVitePlugin({ config: astroConfig, devServer }),
- fetchVitePlugin(),
],
publicDir: fileURLToPath(astroConfig.public),
root: fileURLToPath(astroConfig.projectRoot),
diff --git a/packages/astro/src/core/dev/index.ts b/packages/astro/src/core/dev/index.ts
index c2f2bca94..3fcda0114 100644
--- a/packages/astro/src/core/dev/index.ts
+++ b/packages/astro/src/core/dev/index.ts
@@ -9,6 +9,7 @@ import { fileURLToPath } from 'url';
import { promisify } from 'util';
import connect from 'connect';
import mime from 'mime';
+import { polyfill } from '@astropub/webapi';
import { performance } from 'perf_hooks';
import stripAnsi from 'strip-ansi';
import vite from '../vite.js';
@@ -35,6 +36,9 @@ export interface DevServer {
/** `astro dev` */
export default async function dev(config: AstroConfig, options: DevOptions = { logging: defaultLogOptions }): Promise<DevServer> {
+ // polyfill WebAPIs to globalThis for Node v12, Node v14, and Node v16
+ polyfill(globalThis);
+
// start dev server
const server = new AstroDevServer(config, options);
await server.start();
diff --git a/yarn.lock b/yarn.lock
index de0e86074..d92281fd3 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -140,6 +140,11 @@
vscode-languageserver-types "^3.16.0"
vscode-uri "^3.0.2"
+"@astropub/webapi@^0.4.0":
+ version "0.4.0"
+ resolved "https://registry.yarnpkg.com/@astropub/webapi/-/webapi-0.4.0.tgz#ce03357e562758fe8ac9b461fec4206a888c8e56"
+ integrity sha512-KpHOH9WsIJk2E3Z/suAZri3a6I9GrkZnmm+BHAZp4OBAXUUyNTIid9mIC8tiiHNbY2A6OLbBvfteuD+BYQfcrw==
+
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.16.0":
version "7.16.0"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.16.0.tgz#0dfc80309beec8411e65e706461c408b0bb9b431"