Skip to content

Commit a715763

Browse files
committed
merge version-2
2 parents 174343e + e0f97c8 commit a715763

File tree

28 files changed

+139
-188
lines changed

28 files changed

+139
-188
lines changed

.changeset/rotten-penguins-hope.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/adapter-node': major
3+
---
4+
5+
breaking: remove polyfill option. fetch APIs will now always come from the platform being used. File and crypto APIs will be polyfilled if not available

.changeset/thick-suits-help.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sveltejs/kit': major
3+
---
4+
5+
breaking: require Node 18.13 or newer

.github/workflows/ci.yml

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- uses: pnpm/[email protected]
2727
- uses: actions/setup-node@v4
2828
with:
29-
node-version: '16.x'
29+
node-version: '18.x'
3030
cache: pnpm
3131
- run: pnpm install --frozen-lockfile
3232
- run: pnpm run lint
@@ -39,9 +39,6 @@ jobs:
3939
fail-fast: false
4040
matrix:
4141
include:
42-
- node-version: 16
43-
os: ubuntu-latest
44-
e2e-browser: 'chromium'
4542
- node-version: 18
4643
os: ubuntu-latest
4744
e2e-browser: 'chromium'
@@ -79,27 +76,27 @@ jobs:
7976
fail-fast: false
8077
matrix:
8178
include:
82-
- node-version: 16
79+
- node-version: 18
8380
os: windows-2019 # slowness reported on newer versions https://github.com/actions/runner-images/issues/5166
8481
e2e-browser: 'chromium'
8582
mode: 'dev'
86-
- node-version: 16
83+
- node-version: 18
8784
os: ubuntu-latest
8885
e2e-browser: 'firefox'
8986
mode: 'dev'
90-
- node-version: 16
87+
- node-version: 18
9188
os: macOS-latest
9289
e2e-browser: 'webkit'
9390
mode: 'dev'
94-
- node-version: 16
91+
- node-version: 18
9592
os: windows-2019 # slowness reported on newer versions https://github.com/actions/runner-images/issues/5166
9693
e2e-browser: 'chromium'
9794
mode: 'build'
98-
- node-version: 16
95+
- node-version: 18
9996
os: ubuntu-latest
10097
e2e-browser: 'firefox'
10198
mode: 'build'
102-
- node-version: 16
99+
- node-version: 18
103100
os: macOS-latest
104101
e2e-browser: 'webkit'
105102
mode: 'build'
@@ -134,7 +131,7 @@ jobs:
134131
- uses: pnpm/[email protected]
135132
- uses: actions/setup-node@v4
136133
with:
137-
node-version: 16
134+
node-version: 18
138135
cache: pnpm
139136
- run: pnpm install --frozen-lockfile
140137
- run: cd packages/kit && pnpm prepublishOnly

documentation/docs/25-build-and-deploy/40-adapter-node.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ export default {
131131
// default options are shown
132132
out: 'build',
133133
precompress: false,
134-
envPrefix: '',
135-
polyfill: true
134+
envPrefix: ''
136135
})
137136
}
138137
};
@@ -161,12 +160,6 @@ MY_CUSTOM_ORIGIN=https://my.site \
161160
node build
162161
```
163162

164-
### polyfill
165-
166-
Controls whether your build will load polyfills for missing modules. It defaults to `true`, and should only be disabled when using Node 18.11 or greater.
167-
168-
Note: to use Node's built-in `crypto` global with Node 18 you will need to use the `--experimental-global-webcrypto` flag. This flag is not required with Node 20.
169-
170163
## Custom server
171164

172165
The adapter creates two files in your build directory — `index.js` and `handler.js`. Running `index.js` — e.g. `node build`, if you use the default build directory — will start a server on the configured port.

packages/adapter-auto/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"devDependencies": {
3333
"@sveltejs/kit": "workspace:^",
3434
"@sveltejs/vite-plugin-svelte": "^3.0.0",
35-
"@types/node": "^16.18.6",
35+
"@types/node": "^18.19.1",
3636
"typescript": "^5.3.2"
3737
},
3838
"dependencies": {

packages/adapter-cloudflare-workers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"devDependencies": {
3838
"@cloudflare/kv-asset-handler": "^0.3.0",
39-
"@types/node": "^16.18.6",
39+
"@types/node": "^18.19.1",
4040
"typescript": "^5.3.2"
4141
},
4242
"peerDependencies": {

packages/adapter-cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"worktop": "0.8.0-next.15"
3838
},
3939
"devDependencies": {
40-
"@types/node": "^16.18.6",
40+
"@types/node": "^18.19.1",
4141
"@types/ws": "^8.5.3",
4242
"typescript": "^5.3.2"
4343
},

packages/adapter-netlify/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"@rollup/plugin-node-resolve": "^15.2.3",
4545
"@sveltejs/kit": "workspace:^",
4646
"@sveltejs/vite-plugin-svelte": "^3.0.0",
47-
"@types/node": "^16.18.6",
47+
"@types/node": "^18.19.1",
4848
"@types/set-cookie-parser": "^2.4.2",
4949
"rollup": "^4.2.0",
5050
"typescript": "^5.3.2",

packages/adapter-node/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ interface AdapterOptions {
99
out?: string;
1010
precompress?: boolean;
1111
envPrefix?: string;
12-
polyfill?: boolean;
1312
}
1413

1514
export default function plugin(options?: AdapterOptions): Adapter;

packages/adapter-node/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const files = fileURLToPath(new URL('./files', import.meta.url).href);
99

1010
/** @type {import('./index.js').default} */
1111
export default function (opts = {}) {
12-
const { out = 'build', precompress, envPrefix = '', polyfill = true } = opts;
12+
const { out = 'build', precompress, envPrefix = '' } = opts;
1313

1414
return {
1515
name: '@sveltejs/adapter-node',
@@ -86,11 +86,6 @@ export default function (opts = {}) {
8686
ENV_PREFIX: JSON.stringify(envPrefix)
8787
}
8888
});
89-
90-
// If polyfills aren't wanted then clear the file
91-
if (!polyfill) {
92-
writeFileSync(`${out}/shims.js`, '', 'utf-8');
93-
}
9489
}
9590
};
9691
}

packages/adapter-node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"@polka/url": "^1.0.0-next.24",
3737
"@sveltejs/kit": "workspace:^",
3838
"@sveltejs/vite-plugin-svelte": "^3.0.0",
39-
"@types/node": "^16.18.6",
39+
"@types/node": "^18.19.1",
4040
"c8": "^8.0.0",
4141
"polka": "^1.0.0-next.24",
4242
"sirv": "^2.0.3",

packages/adapter-static/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@playwright/test": "1.30.0",
3434
"@sveltejs/kit": "workspace:^",
3535
"@sveltejs/vite-plugin-svelte": "^3.0.0",
36-
"@types/node": "^16.18.6",
36+
"@types/node": "^18.19.1",
3737
"sirv": "^2.0.3",
3838
"svelte": "^4.2.7",
3939
"typescript": "^5.3.2",

packages/adapter-vercel/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"devDependencies": {
3838
"@sveltejs/kit": "workspace:^",
3939
"@sveltejs/vite-plugin-svelte": "^3.0.0",
40-
"@types/node": "^16.18.6",
40+
"@types/node": "^18.19.1",
4141
"typescript": "^5.3.2",
4242
"vitest": "^0.34.5"
4343
},

packages/enhanced-img/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"devDependencies": {
3434
"@types/estree": "^1.0.2",
35-
"@types/node": "^16.18.6",
35+
"@types/node": "^18.19.1",
3636
"estree-walker": "^3.0.3",
3737
"rollup": "^4.2.0",
3838
"svelte": "^4.2.7",

packages/kit/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
"sade": "^1.8.1",
2222
"set-cookie-parser": "^2.6.0",
2323
"sirv": "^2.0.2",
24-
"tiny-glob": "^0.2.9",
25-
"undici": "~5.26.2"
24+
"tiny-glob": "^0.2.9"
2625
},
2726
"devDependencies": {
2827
"@playwright/test": "1.30.0",
2928
"@sveltejs/vite-plugin-svelte": "^3.0.0",
3029
"@types/connect": "^3.4.35",
31-
"@types/node": "^16.18.6",
30+
"@types/node": "^18.19.1",
3231
"@types/sade": "^1.7.4",
3332
"@types/set-cookie-parser": "^2.4.2",
3433
"dts-buddy": "^0.4.1",
@@ -96,6 +95,6 @@
9695
},
9796
"types": "types/index.d.ts",
9897
"engines": {
99-
"node": "^16.14 || >=18"
98+
"node": ">=18.13"
10099
}
101100
}

packages/kit/src/core/postbuild/analyse.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
} from '../../utils/exports.js';
1111
import { load_config } from '../config/index.js';
1212
import { forked } from '../../utils/fork.js';
13-
import { should_polyfill } from '../../utils/platform.js';
1413
import { installPolyfills } from '../../exports/node/polyfills.js';
1514
import { resolvePath } from '../../exports/index.js';
1615
import { ENDPOINT_METHODS } from '../../constants.js';
@@ -36,9 +35,7 @@ async function analyse({ manifest_path, env }) {
3635
/** @type {import('types').ServerInternalModule} */
3736
const internal = await import(pathToFileURL(`${server_root}/server/internal.js`).href);
3837

39-
if (should_polyfill) {
40-
installPolyfills();
41-
}
38+
installPolyfills();
4239

4340
// configure `import { building } from '$app/environment'` —
4441
// essential we do this before analysing the code

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { dirname, join } from 'node:path';
33
import { pathToFileURL } from 'node:url';
44
import { installPolyfills } from '../../exports/node/polyfills.js';
55
import { mkdirp, posixify, walk } from '../../utils/filesystem.js';
6-
import { should_polyfill } from '../../utils/platform.js';
76
import { decode_uri, is_root_relative, resolve } from '../../utils/url.js';
87
import { escape_html_attr } from '../../utils/escape.js';
98
import { logger } from '../utils.js';
@@ -94,9 +93,7 @@ async function prerender({ out, manifest_path, metadata, verbose, env }) {
9493
/** @type {import('types').Logger} */
9594
const log = logger({ verbose });
9695

97-
if (should_polyfill) {
98-
installPolyfills();
99-
}
96+
installPolyfills();
10097

10198
/** @type {Map<string, string>} */
10299
const saved = new Map();

packages/kit/src/exports/node/polyfills.js

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,25 @@
1-
import { ReadableStream, TransformStream, WritableStream } from 'node:stream/web';
21
import buffer from 'node:buffer';
32
import { webcrypto as crypto } from 'node:crypto';
4-
import { fetch, Response, Request, Headers, FormData, File as UndiciFile } from 'undici';
53

64
// `buffer.File` was added in Node 18.13.0 while the `File` global was added in Node 20.0.0
7-
const File = /** @type {import('node:buffer') & { File?: File}} */ (buffer).File ?? UndiciFile;
5+
const File = /** @type {import('node:buffer') & { File?: File}} */ (buffer).File;
86

97
/** @type {Record<string, any>} */
10-
const globals_post_node_18_11 = {
8+
const globals = {
119
crypto,
1210
File
1311
};
1412

15-
/** @type {Record<string, any>} */
16-
// TODO: remove this once we only support Node 18.11+ (the version multipart/form-data was added)
17-
const globals_pre_node_18_11 = {
18-
crypto,
19-
fetch,
20-
Response,
21-
Request,
22-
Headers,
23-
ReadableStream,
24-
TransformStream,
25-
WritableStream,
26-
FormData,
27-
File
28-
};
29-
3013
// exported for dev/preview and node environments
3114
/**
3215
* Make various web APIs available as globals:
3316
* - `crypto`
34-
* - `fetch` (only in node < 18.11)
35-
* - `Headers` (only in node < 18.11)
36-
* - `Request` (only in node < 18.11)
37-
* - `Response` (only in node < 18.11)
17+
* - `File`
3818
*/
3919
export function installPolyfills() {
40-
// Be defensive (we don't know in which environments this is called) and always apply if something goes wrong
41-
let globals = globals_pre_node_18_11;
42-
try {
43-
const version = process.versions.node.split('.').map((n) => parseInt(n, 10));
44-
if ((version[0] === 18 && version[1] >= 11) || version[0] > 18) {
45-
globals = globals_post_node_18_11;
46-
}
47-
} catch (e) {
48-
// ignore
49-
}
50-
5120
for (const name in globals) {
21+
if (name in globalThis) continue;
22+
5223
Object.defineProperty(globalThis, name, {
5324
enumerable: true,
5425
configurable: true,

packages/kit/src/exports/vite/dev/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { getRequest, setResponse } from '../../../exports/node/index.js';
88
import { installPolyfills } from '../../../exports/node/polyfills.js';
99
import { coalesce_to_error } from '../../../utils/error.js';
1010
import { posixify, resolve_entry, to_fs } from '../../../utils/filesystem.js';
11-
import { should_polyfill } from '../../../utils/platform.js';
1211
import { load_error_page } from '../../../core/config/index.js';
1312
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
1413
import * as sync from '../../../core/sync/sync.js';
@@ -26,9 +25,7 @@ const cwd = process.cwd();
2625
* @return {Promise<Promise<() => void>>}
2726
*/
2827
export async function dev(vite, vite_config, svelte_config) {
29-
if (should_polyfill) {
30-
installPolyfills();
31-
}
28+
installPolyfills();
3229

3330
const fetch = globalThis.fetch;
3431
globalThis.fetch = (info, init) => {

packages/kit/src/exports/vite/preview/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { loadEnv, normalizePath } from 'vite';
77
import { getRequest, setResponse } from '../../../exports/node/index.js';
88
import { installPolyfills } from '../../../exports/node/polyfills.js';
99
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
10-
import { should_polyfill } from '../../../utils/platform.js';
1110

1211
/** @typedef {import('http').IncomingMessage} Req */
1312
/** @typedef {import('http').ServerResponse} Res */
@@ -19,9 +18,7 @@ import { should_polyfill } from '../../../utils/platform.js';
1918
* @param {import('types').ValidatedConfig} svelte_config
2019
*/
2120
export async function preview(vite, vite_config, svelte_config) {
22-
if (should_polyfill) {
23-
installPolyfills();
24-
}
21+
installPolyfills();
2522

2623
const { paths } = svelte_config.kit;
2724
const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;

packages/kit/src/runtime/server/page/csp.spec.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ import { webcrypto } from 'node:crypto';
22
import { assert, beforeAll, test } from 'vitest';
33
import { Csp } from './csp.js';
44

5-
// @ts-expect-error
6-
globalThis.crypto = webcrypto;
5+
// TODO: remove after bumping peer dependency to require Node 20
6+
if (!globalThis.crypto) {
7+
// @ts-expect-error
8+
globalThis.crypto = webcrypto;
9+
}
710

811
beforeAll(() => {
912
// @ts-expect-error

packages/kit/src/utils/platform.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/kit/test/apps/basics/test/server.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect } from '@playwright/test';
22
import { test } from '../../../utils.js';
3-
import { fetch } from 'undici';
43
import { createHash, randomBytes } from 'node:crypto';
54

65
/** @typedef {import('@playwright/test').Response} Response */

packages/migrate/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"typescript": "^5.3.2"
3434
},
3535
"devDependencies": {
36-
"@types/node": "^16.18.6",
36+
"@types/node": "^18.19.1",
3737
"@types/prompts": "^2.4.1",
3838
"@types/semver": "^7.5.0",
3939
"prettier": "^3.1.0",

packages/package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"svelte2tsx": "~0.6.19"
1919
},
2020
"devDependencies": {
21-
"@types/node": "^16.18.6",
21+
"@types/node": "^18.19.1",
2222
"@types/semver": "^7.5.0",
2323
"svelte": "^4.2.7",
2424
"svelte-preprocess": "^5.1.1",

0 commit comments

Comments
 (0)