mirror of
https://github.com/withastro/astro.git
synced 2025-02-17 22:44:24 -05:00
Replace fetch
walk-n-replace with polyfill (#2206)
* Replace fetch replacer with genuine polyfill * chore(lint): Prettier fix * changeset Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
fb25b7573c
commit
91173fe938
6 changed files with 19 additions and 2 deletions
5
.changeset/clever-years-appear.md
Normal file
5
.changeset/clever-years-appear.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Replaced `fetch` walk-n-replace with globalThis polyfill
|
|
@ -64,6 +64,7 @@
|
||||||
"@astrojs/renderer-react": "0.3.1",
|
"@astrojs/renderer-react": "0.3.1",
|
||||||
"@astrojs/renderer-svelte": "0.2.2",
|
"@astrojs/renderer-svelte": "0.2.2",
|
||||||
"@astrojs/renderer-vue": "0.2.1",
|
"@astrojs/renderer-vue": "0.2.1",
|
||||||
|
"@astropub/webapi": "^0.4.0",
|
||||||
"@babel/core": "^7.15.8",
|
"@babel/core": "^7.15.8",
|
||||||
"@babel/traverse": "^7.15.4",
|
"@babel/traverse": "^7.15.4",
|
||||||
"@proload/core": "^0.2.1",
|
"@proload/core": "^0.2.1",
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { rollupPluginAstroBuildHTML } from '../../vite-plugin-build-html/index.j
|
||||||
import { rollupPluginAstroBuildCSS } from '../../vite-plugin-build-css/index.js';
|
import { rollupPluginAstroBuildCSS } from '../../vite-plugin-build-css/index.js';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import * as colors from 'kleur/colors';
|
import * as colors from 'kleur/colors';
|
||||||
|
import { polyfill } from '@astropub/webapi';
|
||||||
import { performance } from 'perf_hooks';
|
import { performance } from 'perf_hooks';
|
||||||
import vite, { ViteDevServer } from '../vite.js';
|
import vite, { ViteDevServer } from '../vite.js';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
|
@ -25,6 +26,9 @@ export interface BuildOptions {
|
||||||
|
|
||||||
/** `astro build` */
|
/** `astro build` */
|
||||||
export default async function build(config: AstroConfig, options: BuildOptions = { logging: defaultLogOptions }): Promise<void> {
|
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);
|
const builder = new AstroBuilder(config, options);
|
||||||
await builder.build();
|
await builder.build();
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import astroPostprocessVitePlugin from '../vite-plugin-astro-postprocess/index.j
|
||||||
import configAliasVitePlugin from '../vite-plugin-config-alias/index.js';
|
import configAliasVitePlugin from '../vite-plugin-config-alias/index.js';
|
||||||
import markdownVitePlugin from '../vite-plugin-markdown/index.js';
|
import markdownVitePlugin from '../vite-plugin-markdown/index.js';
|
||||||
import jsxVitePlugin from '../vite-plugin-jsx/index.js';
|
import jsxVitePlugin from '../vite-plugin-jsx/index.js';
|
||||||
import fetchVitePlugin from '../vite-plugin-fetch/index.js';
|
|
||||||
import { resolveDependency } from './util.js';
|
import { resolveDependency } from './util.js';
|
||||||
|
|
||||||
// Some packages are just external, and that’s the way it goes.
|
// 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 }),
|
markdownVitePlugin({ config: astroConfig, devServer }),
|
||||||
jsxVitePlugin({ config: astroConfig, logging }),
|
jsxVitePlugin({ config: astroConfig, logging }),
|
||||||
astroPostprocessVitePlugin({ config: astroConfig, devServer }),
|
astroPostprocessVitePlugin({ config: astroConfig, devServer }),
|
||||||
fetchVitePlugin(),
|
|
||||||
],
|
],
|
||||||
publicDir: fileURLToPath(astroConfig.public),
|
publicDir: fileURLToPath(astroConfig.public),
|
||||||
root: fileURLToPath(astroConfig.projectRoot),
|
root: fileURLToPath(astroConfig.projectRoot),
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { fileURLToPath } from 'url';
|
||||||
import { promisify } from 'util';
|
import { promisify } from 'util';
|
||||||
import connect from 'connect';
|
import connect from 'connect';
|
||||||
import mime from 'mime';
|
import mime from 'mime';
|
||||||
|
import { polyfill } from '@astropub/webapi';
|
||||||
import { performance } from 'perf_hooks';
|
import { performance } from 'perf_hooks';
|
||||||
import stripAnsi from 'strip-ansi';
|
import stripAnsi from 'strip-ansi';
|
||||||
import vite from '../vite.js';
|
import vite from '../vite.js';
|
||||||
|
@ -35,6 +36,9 @@ export interface DevServer {
|
||||||
|
|
||||||
/** `astro dev` */
|
/** `astro dev` */
|
||||||
export default async function dev(config: AstroConfig, options: DevOptions = { logging: defaultLogOptions }): Promise<DevServer> {
|
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
|
// start dev server
|
||||||
const server = new AstroDevServer(config, options);
|
const server = new AstroDevServer(config, options);
|
||||||
await server.start();
|
await server.start();
|
||||||
|
|
|
@ -140,6 +140,11 @@
|
||||||
vscode-languageserver-types "^3.16.0"
|
vscode-languageserver-types "^3.16.0"
|
||||||
vscode-uri "^3.0.2"
|
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":
|
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.10.4", "@babel/code-frame@^7.16.0":
|
||||||
version "7.16.0"
|
version "7.16.0"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.16.0.tgz#0dfc80309beec8411e65e706461c408b0bb9b431"
|
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.16.0.tgz#0dfc80309beec8411e65e706461c408b0bb9b431"
|
||||||
|
|
Loading…
Add table
Reference in a new issue