Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename __fetch_polyfill to installFetch #4111

Merged
merged 4 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slow-dots-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[breaking] Rename `__fetch_polyfill` to `installFetch`, remove fetch exports
7 changes: 7 additions & 0 deletions .changeset/tricky-bees-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@sveltejs/adapter-netlify': patch
'@sveltejs/adapter-node': patch
'@sveltejs/adapter-vercel': patch
---

Rename `__fetch_polyfill` to `installFetch`
4 changes: 2 additions & 2 deletions packages/adapter-netlify/src/shims.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { __fetch_polyfill } from '@sveltejs/kit/install-fetch';
__fetch_polyfill();
import { installFetch } from '@sveltejs/kit/install-fetch';
installFetch();
4 changes: 2 additions & 2 deletions packages/adapter-node/src/shims.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { __fetch_polyfill } from '@sveltejs/kit/install-fetch';
__fetch_polyfill();
import { installFetch } from '@sveltejs/kit/install-fetch';
installFetch();
4 changes: 2 additions & 2 deletions packages/adapter-vercel/files/shims.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { __fetch_polyfill } from '@sveltejs/kit/install-fetch';
__fetch_polyfill();
import { installFetch } from '@sveltejs/kit/install-fetch';
installFetch();
4 changes: 2 additions & 2 deletions packages/kit/src/core/adapt/prerender/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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`);

Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/core/dev/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/core/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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`);
Expand Down
5 changes: 1 addition & 4 deletions packages/kit/src/install-fetch.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -25,6 +25,3 @@ export function __fetch_polyfill() {
}
});
}

// exported for esbuild shims in adapters
export { fetch, Response, Request, Headers };
9 changes: 4 additions & 5 deletions packages/kit/types/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down