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 1 commit
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
Next Next commit
rename __fetch_polyfill to installFetch
  • Loading branch information
Rich-Harris committed Feb 24, 2022
commit 7e97734cd86523ed4a3b5e2a2f087078cf3f0a5e
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
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 };
2 changes: 1 addition & 1 deletion packages/kit/types/ambient.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ declare module '@sveltejs/kit/hooks' {
declare module '@sveltejs/kit/install-fetch' {
import fetch, { Headers, Request, Response } from 'node-fetch';

export function __fetch_polyfill(): void;
export function installFetch(): void;

export { fetch, Headers, Request, Response };
}
Expand Down