From a764264d29648e31e3d0908343da9e0454ef8e88 Mon Sep 17 00:00:00 2001 From: Jonathan Neal Date: Tue, 25 Jan 2022 11:37:06 -0500 Subject: [PATCH] Remove `node-fetch` (#2462) * remove node-fetch * use webapi polyfill like astro --- packages/astro/package.json | 1 - .../fixtures/fetch/src/components/AlreadyImported.astro | 4 ---- packages/astro/test/test-utils.js | 7 ++++++- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/astro/package.json b/packages/astro/package.json index 067e30813..07e88ddaf 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -86,7 +86,6 @@ "magic-string": "^0.25.7", "mime": "^3.0.0", "morphdom": "^2.6.1", - "node-fetch": "^3.0.0", "parse5": "^6.0.1", "path-to-regexp": "^6.2.0", "postcss": "^8.3.8", diff --git a/packages/astro/test/fixtures/fetch/src/components/AlreadyImported.astro b/packages/astro/test/fixtures/fetch/src/components/AlreadyImported.astro index 486eeacaa..40dd58012 100644 --- a/packages/astro/test/fixtures/fetch/src/components/AlreadyImported.astro +++ b/packages/astro/test/fixtures/fetch/src/components/AlreadyImported.astro @@ -1,5 +1 @@ ---- -import fetch from 'node-fetch' ---- - {typeof fetch} diff --git a/packages/astro/test/test-utils.js b/packages/astro/test/test-utils.js index 18c83d506..88b46908d 100644 --- a/packages/astro/test/test-utils.js +++ b/packages/astro/test/test-utils.js @@ -1,5 +1,5 @@ import { execa } from 'execa'; -import fetch from 'node-fetch'; +import { polyfill } from '@astropub/webapi'; import fs from 'fs'; import { fileURLToPath } from 'url'; import { loadConfig } from '../dist/core/config.js'; @@ -8,6 +8,11 @@ import build from '../dist/core/build/index.js'; import preview from '../dist/core/preview/index.js'; import os from 'os'; +// polyfill WebAPIs to globalThis for Node v12, Node v14, and Node v16 +polyfill(globalThis, { + exclude: 'window document', +}); + /** * @typedef {import('node-fetch').Response} Response * @typedef {import('../src/core/dev/index').DevServer} DevServer