diff --git a/.changeset/slow-dots-know.md b/.changeset/slow-dots-know.md new file mode 100644 index 000000000000..48c8661f6f1a --- /dev/null +++ b/.changeset/slow-dots-know.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[breaking] Rename `__fetch_polyfill` to `installFetch`, remove fetch exports diff --git a/.changeset/tricky-bees-yell.md b/.changeset/tricky-bees-yell.md new file mode 100644 index 000000000000..12e2b954c80c --- /dev/null +++ b/.changeset/tricky-bees-yell.md @@ -0,0 +1,7 @@ +--- +'@sveltejs/adapter-netlify': patch +'@sveltejs/adapter-node': patch +'@sveltejs/adapter-vercel': patch +--- + +Rename `__fetch_polyfill` to `installFetch` diff --git a/packages/adapter-netlify/src/shims.js b/packages/adapter-netlify/src/shims.js index 0f5610df98c1..8d2fe00acd85 100644 --- a/packages/adapter-netlify/src/shims.js +++ b/packages/adapter-netlify/src/shims.js @@ -1,2 +1,2 @@ -import { __fetch_polyfill } from '@sveltejs/kit/install-fetch'; -__fetch_polyfill(); +import { installFetch } from '@sveltejs/kit/install-fetch'; +installFetch(); diff --git a/packages/adapter-node/src/shims.js b/packages/adapter-node/src/shims.js index 0f5610df98c1..8d2fe00acd85 100644 --- a/packages/adapter-node/src/shims.js +++ b/packages/adapter-node/src/shims.js @@ -1,2 +1,2 @@ -import { __fetch_polyfill } from '@sveltejs/kit/install-fetch'; -__fetch_polyfill(); +import { installFetch } from '@sveltejs/kit/install-fetch'; +installFetch(); diff --git a/packages/adapter-vercel/files/shims.js b/packages/adapter-vercel/files/shims.js index 0f5610df98c1..8d2fe00acd85 100644 --- a/packages/adapter-vercel/files/shims.js +++ b/packages/adapter-vercel/files/shims.js @@ -1,2 +1,2 @@ -import { __fetch_polyfill } from '@sveltejs/kit/install-fetch'; -__fetch_polyfill(); +import { installFetch } from '@sveltejs/kit/install-fetch'; +installFetch(); diff --git a/packages/kit/src/core/adapt/prerender/prerender.js b/packages/kit/src/core/adapt/prerender/prerender.js index b950afeda76b..74ea0e1f4178 100644 --- a/packages/kit/src/core/adapt/prerender/prerender.js +++ b/packages/kit/src/core/adapt/prerender/prerender.js @@ -2,7 +2,7 @@ import { readFileSync, writeFileSync } from 'fs'; import { dirname, join, resolve as resolve_path } from 'path'; import { pathToFileURL, URL } from 'url'; import { mkdirp } from '../../../utils/filesystem.js'; -import { __fetch_polyfill } from '../../../install-fetch.js'; +import { installFetch } from '../../../install-fetch.js'; import { SVELTE_KIT } from '../../constants.js'; import { is_root_relative, normalize_path, resolve } from '../../../utils/url.js'; import { queue } from './queue.js'; @@ -63,7 +63,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a return prerendered; } - __fetch_polyfill(); + installFetch(); const server_root = resolve_path(cwd, `${SVELTE_KIT}/output`); diff --git a/packages/kit/src/core/dev/plugin.js b/packages/kit/src/core/dev/plugin.js index 8e173b6cde65..9c23b328007d 100644 --- a/packages/kit/src/core/dev/plugin.js +++ b/packages/kit/src/core/dev/plugin.js @@ -3,7 +3,7 @@ import path from 'path'; import { URL } from 'url'; import colors from 'kleur'; import sirv from 'sirv'; -import { __fetch_polyfill } from '../../install-fetch.js'; +import { installFetch } from '../../install-fetch.js'; import { create_app } from '../create_app/index.js'; import create_manifest_data from '../create_manifest_data/index.js'; import { getRequest, setResponse } from '../../node.js'; @@ -36,7 +36,7 @@ export async function create_plugin(config, cwd) { name: 'vite-plugin-svelte-kit', configureServer(vite) { - __fetch_polyfill(); + installFetch(); /** @type {import('types').SSRManifest} */ let manifest; diff --git a/packages/kit/src/core/preview/index.js b/packages/kit/src/core/preview/index.js index 577775919e8a..11ec3dd66828 100644 --- a/packages/kit/src/core/preview/index.js +++ b/packages/kit/src/core/preview/index.js @@ -5,7 +5,7 @@ import { join, resolve } from 'path'; import sirv from 'sirv'; import { pathToFileURL } from 'url'; import { getRequest, setResponse } from '../../node.js'; -import { __fetch_polyfill } from '../../install-fetch.js'; +import { installFetch } from '../../install-fetch.js'; import { SVELTE_KIT, SVELTE_KIT_ASSETS } from '../constants.js'; /** @param {string} dir */ @@ -31,7 +31,7 @@ export async function preview({ https: use_https = false, cwd = process.cwd() }) { - __fetch_polyfill(); + installFetch(); const index_file = resolve(cwd, `${SVELTE_KIT}/output/server/index.js`); const manifest_file = resolve(cwd, `${SVELTE_KIT}/output/server/manifest.js`); diff --git a/packages/kit/src/install-fetch.js b/packages/kit/src/install-fetch.js index 96a0e8c27464..2e75d62ec560 100644 --- a/packages/kit/src/install-fetch.js +++ b/packages/kit/src/install-fetch.js @@ -1,7 +1,7 @@ import fetch, { Response, Request, Headers } from 'node-fetch'; // exported for dev/preview and node environments -export function __fetch_polyfill() { +export function installFetch() { Object.defineProperties(globalThis, { fetch: { enumerable: true, @@ -25,6 +25,3 @@ export function __fetch_polyfill() { } }); } - -// exported for esbuild shims in adapters -export { fetch, Response, Request, Headers }; diff --git a/packages/kit/types/ambient.d.ts b/packages/kit/types/ambient.d.ts index 1e39b179aabe..885c960f313b 100644 --- a/packages/kit/types/ambient.d.ts +++ b/packages/kit/types/ambient.d.ts @@ -281,11 +281,10 @@ declare module '@sveltejs/kit/hooks' { * A polyfill for `fetch` and its related interfaces, used by adapters for environments that don't provide a native implementation. */ declare module '@sveltejs/kit/install-fetch' { - import fetch, { Headers, Request, Response } from 'node-fetch'; - - export function __fetch_polyfill(): void; - - export { fetch, Headers, Request, Response }; + /** + * Make `fetch`, `Headers`, `Request` and `Response` available as globals, via `node-fetch` + */ + export function installFetch(): void; } /**