Skip to content

Commit dcb856f

Browse files
authored
rename __fetch_polyfill to installFetch (#4111)
* rename __fetch_polyfill to installFetch * update adapters * tidy up changesets * fix types
1 parent 7acbcc1 commit dcb856f

File tree

10 files changed

+29
-21
lines changed

10 files changed

+29
-21
lines changed

.changeset/slow-dots-know.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': patch
3+
---
4+
5+
[breaking] Rename `__fetch_polyfill` to `installFetch`, remove fetch exports

.changeset/tricky-bees-yell.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@sveltejs/adapter-netlify': patch
3+
'@sveltejs/adapter-node': patch
4+
'@sveltejs/adapter-vercel': patch
5+
---
6+
7+
Rename `__fetch_polyfill` to `installFetch`
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import { __fetch_polyfill } from '@sveltejs/kit/install-fetch';
2-
__fetch_polyfill();
1+
import { installFetch } from '@sveltejs/kit/install-fetch';
2+
installFetch();

packages/adapter-node/src/shims.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import { __fetch_polyfill } from '@sveltejs/kit/install-fetch';
2-
__fetch_polyfill();
1+
import { installFetch } from '@sveltejs/kit/install-fetch';
2+
installFetch();
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
import { __fetch_polyfill } from '@sveltejs/kit/install-fetch';
2-
__fetch_polyfill();
1+
import { installFetch } from '@sveltejs/kit/install-fetch';
2+
installFetch();

packages/kit/src/core/adapt/prerender/prerender.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { readFileSync, writeFileSync } from 'fs';
22
import { dirname, join, resolve as resolve_path } from 'path';
33
import { pathToFileURL, URL } from 'url';
44
import { mkdirp } from '../../../utils/filesystem.js';
5-
import { __fetch_polyfill } from '../../../install-fetch.js';
5+
import { installFetch } from '../../../install-fetch.js';
66
import { SVELTE_KIT } from '../../constants.js';
77
import { is_root_relative, normalize_path, resolve } from '../../../utils/url.js';
88
import { queue } from './queue.js';
@@ -63,7 +63,7 @@ export async function prerender({ cwd, out, log, config, build_data, fallback, a
6363
return prerendered;
6464
}
6565

66-
__fetch_polyfill();
66+
installFetch();
6767

6868
const server_root = resolve_path(cwd, `${SVELTE_KIT}/output`);
6969

packages/kit/src/core/dev/plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path';
33
import { URL } from 'url';
44
import colors from 'kleur';
55
import sirv from 'sirv';
6-
import { __fetch_polyfill } from '../../install-fetch.js';
6+
import { installFetch } from '../../install-fetch.js';
77
import { create_app } from '../create_app/index.js';
88
import create_manifest_data from '../create_manifest_data/index.js';
99
import { getRequest, setResponse } from '../../node.js';
@@ -36,7 +36,7 @@ export async function create_plugin(config, cwd) {
3636
name: 'vite-plugin-svelte-kit',
3737

3838
configureServer(vite) {
39-
__fetch_polyfill();
39+
installFetch();
4040

4141
/** @type {import('types').SSRManifest} */
4242
let manifest;

packages/kit/src/core/preview/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { join, resolve } from 'path';
55
import sirv from 'sirv';
66
import { pathToFileURL } from 'url';
77
import { getRequest, setResponse } from '../../node.js';
8-
import { __fetch_polyfill } from '../../install-fetch.js';
8+
import { installFetch } from '../../install-fetch.js';
99
import { SVELTE_KIT, SVELTE_KIT_ASSETS } from '../constants.js';
1010

1111
/** @param {string} dir */
@@ -31,7 +31,7 @@ export async function preview({
3131
https: use_https = false,
3232
cwd = process.cwd()
3333
}) {
34-
__fetch_polyfill();
34+
installFetch();
3535

3636
const index_file = resolve(cwd, `${SVELTE_KIT}/output/server/index.js`);
3737
const manifest_file = resolve(cwd, `${SVELTE_KIT}/output/server/manifest.js`);

packages/kit/src/install-fetch.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fetch, { Response, Request, Headers } from 'node-fetch';
22

33
// exported for dev/preview and node environments
4-
export function __fetch_polyfill() {
4+
export function installFetch() {
55
Object.defineProperties(globalThis, {
66
fetch: {
77
enumerable: true,
@@ -25,6 +25,3 @@ export function __fetch_polyfill() {
2525
}
2626
});
2727
}
28-
29-
// exported for esbuild shims in adapters
30-
export { fetch, Response, Request, Headers };

packages/kit/types/ambient.d.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,10 @@ declare module '@sveltejs/kit/hooks' {
281281
* A polyfill for `fetch` and its related interfaces, used by adapters for environments that don't provide a native implementation.
282282
*/
283283
declare module '@sveltejs/kit/install-fetch' {
284-
import fetch, { Headers, Request, Response } from 'node-fetch';
285-
286-
export function __fetch_polyfill(): void;
287-
288-
export { fetch, Headers, Request, Response };
284+
/**
285+
* Make `fetch`, `Headers`, `Request` and `Response` available as globals, via `node-fetch`
286+
*/
287+
export function installFetch(): void;
289288
}
290289

291290
/**

0 commit comments

Comments
 (0)