@sveltejs/kit 1.7.2 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/src/core/env.js +6 -10
- package/src/core/generate_manifest/index.js +1 -1
- package/src/core/sync/write_ambient.js +6 -5
- package/src/core/sync/write_client_manifest.js +3 -2
- package/src/core/sync/write_server.js +6 -4
- package/src/exports/vite/build/utils.js +1 -0
- package/src/exports/vite/dev/index.js +15 -9
- package/src/exports/vite/index.js +67 -35
- package/src/internal.d.ts +7 -0
- package/src/runtime/app/environment.js +1 -1
- package/src/runtime/client/client.js +118 -62
- package/src/runtime/client/parse.js +2 -5
- package/src/runtime/client/start.js +5 -16
- package/src/runtime/client/types.d.ts +37 -1
- package/src/runtime/client/utils.js +1 -1
- package/src/runtime/env/dynamic/private.js +1 -1
- package/src/runtime/env/dynamic/public.js +1 -1
- package/src/runtime/server/data/index.js +118 -18
- package/src/runtime/server/index.js +1 -1
- package/src/runtime/server/page/index.js +16 -11
- package/src/runtime/server/page/load_data.js +56 -6
- package/src/runtime/server/page/render.js +253 -153
- package/src/runtime/server/page/types.d.ts +2 -2
- package/src/runtime/server/utils.js +12 -21
- package/src/runtime/{shared.js → shared-server.js} +0 -13
- package/src/utils/streaming.js +44 -0
- package/types/index.d.ts +5 -7
- package/types/internal.d.ts +49 -17
- package/src/runtime/client/ambient.d.ts +0 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"@sveltejs/vite-plugin-svelte": "^2.0.0",
|
|
14
14
|
"@types/cookie": "^0.5.1",
|
|
15
15
|
"cookie": "^0.5.0",
|
|
16
|
-
"devalue": "^4.
|
|
16
|
+
"devalue": "^4.3.0",
|
|
17
17
|
"esm-env": "^1.0.0",
|
|
18
18
|
"kleur": "^4.1.5",
|
|
19
19
|
"magic-string": "^0.29.0",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"set-cookie-parser": "^2.5.1",
|
|
23
23
|
"sirv": "^2.0.2",
|
|
24
24
|
"tiny-glob": "^0.2.9",
|
|
25
|
-
"undici": "5.
|
|
25
|
+
"undici": "5.20.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@playwright/test": "^1.29.2",
|
package/src/core/env.js
CHANGED
|
@@ -3,11 +3,6 @@ import { runtime_base } from './utils.js';
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {'public' | 'private'} EnvType
|
|
6
|
-
* @typedef {{
|
|
7
|
-
* public: Record<string, string>;
|
|
8
|
-
* private: Record<string, string>;
|
|
9
|
-
* prefix: string;
|
|
10
|
-
* }} EnvData
|
|
11
6
|
*/
|
|
12
7
|
|
|
13
8
|
/**
|
|
@@ -44,12 +39,12 @@ export function create_dynamic_module(type, dev_values) {
|
|
|
44
39
|
);
|
|
45
40
|
return `export const env = {\n${keys.join(',\n')}\n}`;
|
|
46
41
|
}
|
|
47
|
-
return `export { ${type}_env as env } from '${runtime_base}/shared.js';`;
|
|
42
|
+
return `export { ${type}_env as env } from '${runtime_base}/shared-server.js';`;
|
|
48
43
|
}
|
|
49
44
|
|
|
50
45
|
/**
|
|
51
46
|
* @param {EnvType} id
|
|
52
|
-
* @param {
|
|
47
|
+
* @param {import('types').Env} env
|
|
53
48
|
* @returns {string}
|
|
54
49
|
*/
|
|
55
50
|
export function create_static_types(id, env) {
|
|
@@ -63,15 +58,16 @@ export function create_static_types(id, env) {
|
|
|
63
58
|
|
|
64
59
|
/**
|
|
65
60
|
* @param {EnvType} id
|
|
66
|
-
* @param {
|
|
61
|
+
* @param {import('types').Env} env
|
|
62
|
+
* @param {string} prefix
|
|
67
63
|
* @returns {string}
|
|
68
64
|
*/
|
|
69
|
-
export function create_dynamic_types(id, env) {
|
|
65
|
+
export function create_dynamic_types(id, env, prefix) {
|
|
70
66
|
const properties = Object.keys(env[id])
|
|
71
67
|
.filter((k) => valid_identifier.test(k))
|
|
72
68
|
.map((k) => `\t\t${k}: string;`);
|
|
73
69
|
|
|
74
|
-
const prefixed = `[key: \`${
|
|
70
|
+
const prefixed = `[key: \`${prefix}\${string}\`]`;
|
|
75
71
|
|
|
76
72
|
if (id === 'private') {
|
|
77
73
|
properties.push(`\t\t${prefixed}: undefined;`);
|
|
@@ -86,7 +86,7 @@ export function generate_manifest({ build_data, relative_path, routes }) {
|
|
|
86
86
|
assets: new Set(${s(assets)}),
|
|
87
87
|
mimeTypes: ${s(get_mime_lookup(build_data.manifest_data))},
|
|
88
88
|
_: {
|
|
89
|
-
|
|
89
|
+
client: ${s(build_data.client)},
|
|
90
90
|
nodes: [
|
|
91
91
|
${(node_paths).map(loader).join(',\n\t\t\t\t')}
|
|
92
92
|
],
|
|
@@ -21,9 +21,10 @@ function read_description(filename) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* @param {import('
|
|
24
|
+
* @param {import('types').Env} env
|
|
25
|
+
* @param {string} prefix
|
|
25
26
|
*/
|
|
26
|
-
const template = (env) => `
|
|
27
|
+
const template = (env, prefix) => `
|
|
27
28
|
${GENERATED_COMMENT}
|
|
28
29
|
|
|
29
30
|
/// <reference types="@sveltejs/kit" />
|
|
@@ -35,10 +36,10 @@ ${read_description('$env+static+public.md')}
|
|
|
35
36
|
${create_static_types('public', env)}
|
|
36
37
|
|
|
37
38
|
${read_description('$env+dynamic+private.md')}
|
|
38
|
-
${create_dynamic_types('private', env)}
|
|
39
|
+
${create_dynamic_types('private', env, prefix)}
|
|
39
40
|
|
|
40
41
|
${read_description('$env+dynamic+public.md')}
|
|
41
|
-
${create_dynamic_types('public', env)}
|
|
42
|
+
${create_dynamic_types('public', env, prefix)}
|
|
42
43
|
`;
|
|
43
44
|
|
|
44
45
|
/**
|
|
@@ -53,6 +54,6 @@ export function write_ambient(config, mode) {
|
|
|
53
54
|
|
|
54
55
|
write_if_changed(
|
|
55
56
|
path.join(config.outDir, 'ambient.d.ts'),
|
|
56
|
-
template(
|
|
57
|
+
template(env, config.env.publicPrefix)
|
|
57
58
|
);
|
|
58
59
|
}
|
|
@@ -106,9 +106,8 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
|
|
|
106
106
|
|
|
107
107
|
const hooks_file = resolve_entry(kit.files.hooks.client);
|
|
108
108
|
|
|
109
|
-
// String representation of __CLIENT__/manifest.js
|
|
110
109
|
write_if_changed(
|
|
111
|
-
`${output}/
|
|
110
|
+
`${output}/app.js`,
|
|
112
111
|
trim(`
|
|
113
112
|
${hooks_file ? `import * as client_hooks from '${relative_path(output, hooks_file)}';` : ''}
|
|
114
113
|
|
|
@@ -125,6 +124,8 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
|
|
|
125
124
|
hooks_file ? 'client_hooks.handleError || ' : ''
|
|
126
125
|
}(({ error }) => { console.error(error) }),
|
|
127
126
|
};
|
|
127
|
+
|
|
128
|
+
export { default as root } from '../root.svelte';
|
|
128
129
|
`)
|
|
129
130
|
);
|
|
130
131
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
+
import { hash } from '../../runtime/hash.js';
|
|
3
4
|
import { posixify, resolve_entry } from '../../utils/filesystem.js';
|
|
4
5
|
import { s } from '../../utils/misc.js';
|
|
5
6
|
import { load_error_page, load_template } from '../config/index.js';
|
|
@@ -25,11 +26,11 @@ const server_template = ({
|
|
|
25
26
|
error_page
|
|
26
27
|
}) => `
|
|
27
28
|
import root from '../root.svelte';
|
|
28
|
-
import {
|
|
29
|
-
|
|
30
|
-
set_version(${s(config.kit.version.name)});
|
|
29
|
+
import { set_building } from '__sveltekit/environment';
|
|
30
|
+
import { set_assets, set_private_env, set_public_env } from '${runtime_directory}/shared-server.js';
|
|
31
31
|
|
|
32
32
|
export const options = {
|
|
33
|
+
app_template_contains_nonce: ${template.includes('%sveltekit.nonce%')},
|
|
33
34
|
csp: ${s(config.kit.csp)},
|
|
34
35
|
csrf_check_origin: ${s(config.kit.csrf.checkOrigin)},
|
|
35
36
|
embedded: ${config.kit.embedded},
|
|
@@ -50,7 +51,8 @@ export const options = {
|
|
|
50
51
|
error: ({ status, message }) => ${s(error_page)
|
|
51
52
|
.replace(/%sveltekit\.status%/g, '" + status + "')
|
|
52
53
|
.replace(/%sveltekit\.error\.message%/g, '" + message + "')}
|
|
53
|
-
}
|
|
54
|
+
},
|
|
55
|
+
version_hash: ${s(hash(config.kit.version.name))}
|
|
54
56
|
};
|
|
55
57
|
|
|
56
58
|
export function get_hooks() {
|
|
@@ -6,6 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
* @param {import('vite').Manifest} manifest
|
|
7
7
|
* @param {string} entry
|
|
8
8
|
* @param {boolean} add_dynamic_css
|
|
9
|
+
* @returns {import('types').AssetDependencies}
|
|
9
10
|
*/
|
|
10
11
|
export function find_deps(manifest, entry, add_dynamic_css) {
|
|
11
12
|
/** @type {Set<string>} */
|
|
@@ -105,11 +105,19 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
105
105
|
assets: new Set(manifest_data.assets.map((asset) => asset.file)),
|
|
106
106
|
mimeTypes: get_mime_lookup(manifest_data),
|
|
107
107
|
_: {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
client: {
|
|
109
|
+
start: {
|
|
110
|
+
file: `${runtime_base}/client/start.js`,
|
|
111
|
+
imports: [],
|
|
112
|
+
stylesheets: [],
|
|
113
|
+
fonts: []
|
|
114
|
+
},
|
|
115
|
+
app: {
|
|
116
|
+
file: `${svelte_config.kit.outDir}/generated/client/app.js`,
|
|
117
|
+
imports: [],
|
|
118
|
+
stylesheets: [],
|
|
119
|
+
fonts: []
|
|
120
|
+
}
|
|
113
121
|
},
|
|
114
122
|
nodes: manifest_data.nodes.map((node, index) => {
|
|
115
123
|
return async () => {
|
|
@@ -443,15 +451,13 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
443
451
|
await vite.ssrLoadModule(`${runtime_base}/server/index.js`)
|
|
444
452
|
);
|
|
445
453
|
|
|
446
|
-
const { set_assets,
|
|
454
|
+
const { set_assets, set_fix_stack_trace } =
|
|
447
455
|
/** @type {import('types').ServerInternalModule} */ (
|
|
448
|
-
await vite.ssrLoadModule(`${runtime_base}/shared.js`)
|
|
456
|
+
await vite.ssrLoadModule(`${runtime_base}/shared-server.js`)
|
|
449
457
|
);
|
|
450
458
|
|
|
451
459
|
set_assets(assets);
|
|
452
460
|
|
|
453
|
-
set_version(svelte_config.kit.version.name);
|
|
454
|
-
|
|
455
461
|
set_fix_stack_trace(fix_stack_trace);
|
|
456
462
|
|
|
457
463
|
const server = new Server(manifest);
|
|
@@ -23,6 +23,7 @@ import { write_client_manifest } from '../../core/sync/write_client_manifest.js'
|
|
|
23
23
|
import prerender from '../../core/postbuild/prerender.js';
|
|
24
24
|
import analyse from '../../core/postbuild/analyse.js';
|
|
25
25
|
import { s } from '../../utils/misc.js';
|
|
26
|
+
import { hash } from '../../runtime/hash.js';
|
|
26
27
|
|
|
27
28
|
export { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
|
28
29
|
|
|
@@ -164,6 +165,8 @@ function kit({ svelte_config }) {
|
|
|
164
165
|
const { kit } = svelte_config;
|
|
165
166
|
const out = `${kit.outDir}/output`;
|
|
166
167
|
|
|
168
|
+
const version_hash = hash(kit.version.name);
|
|
169
|
+
|
|
167
170
|
/** @type {import('vite').ResolvedConfig} */
|
|
168
171
|
let vite_config;
|
|
169
172
|
|
|
@@ -220,12 +223,7 @@ function kit({ svelte_config }) {
|
|
|
220
223
|
const new_config = {
|
|
221
224
|
resolve: {
|
|
222
225
|
alias: [
|
|
223
|
-
{
|
|
224
|
-
find: '__CLIENT__',
|
|
225
|
-
replacement: `${generated}/${is_build ? 'client-optimized' : 'client'}`
|
|
226
|
-
},
|
|
227
226
|
{ find: '__SERVER__', replacement: `${generated}/server` },
|
|
228
|
-
{ find: '__GENERATED__', replacement: generated },
|
|
229
227
|
{ find: '$app', replacement: `${runtime_directory}/app` },
|
|
230
228
|
...get_config_aliases(kit)
|
|
231
229
|
]
|
|
@@ -324,12 +322,15 @@ function kit({ svelte_config }) {
|
|
|
324
322
|
|
|
325
323
|
async resolveId(id) {
|
|
326
324
|
// treat $env/static/[public|private] as virtual
|
|
327
|
-
if (id.startsWith('$env/') || id
|
|
325
|
+
if (id.startsWith('$env/') || id.startsWith('__sveltekit/') || id === '$service-worker') {
|
|
328
326
|
return `\0${id}`;
|
|
329
327
|
}
|
|
330
328
|
},
|
|
331
329
|
|
|
332
330
|
async load(id, options) {
|
|
331
|
+
const browser = !options?.ssr;
|
|
332
|
+
const global = `__sveltekit_${version_hash}`;
|
|
333
|
+
|
|
333
334
|
if (options?.ssr === false && process.env.TEST !== 'true') {
|
|
334
335
|
const normalized_cwd = vite.normalizePath(cwd);
|
|
335
336
|
const normalized_lib = vite.normalizePath(kit.files.lib);
|
|
@@ -356,16 +357,28 @@ function kit({ svelte_config }) {
|
|
|
356
357
|
vite_config_env.command === 'serve' ? env.private : undefined
|
|
357
358
|
);
|
|
358
359
|
case '\0$env/dynamic/public':
|
|
360
|
+
// populate `$env/dynamic/public` from `window`
|
|
361
|
+
if (browser) {
|
|
362
|
+
return `export const env = ${global}.env;`;
|
|
363
|
+
}
|
|
364
|
+
|
|
359
365
|
return create_dynamic_module(
|
|
360
366
|
'public',
|
|
361
367
|
vite_config_env.command === 'serve' ? env.public : undefined
|
|
362
368
|
);
|
|
363
369
|
case '\0$service-worker':
|
|
364
370
|
return create_service_worker_module(svelte_config);
|
|
371
|
+
|
|
365
372
|
// for internal use only. it's published as $app/paths externally
|
|
366
373
|
// we use this alias so that we won't collide with user aliases
|
|
367
374
|
case '\0__sveltekit/paths':
|
|
368
375
|
const { assets, base } = svelte_config.kit.paths;
|
|
376
|
+
|
|
377
|
+
if (browser) {
|
|
378
|
+
return `export const base = ${s(base)};
|
|
379
|
+
export const assets = ${global}.assets;`;
|
|
380
|
+
}
|
|
381
|
+
|
|
369
382
|
return `export const base = ${s(base)};
|
|
370
383
|
export let assets = ${assets ? s(assets) : 'base'};
|
|
371
384
|
|
|
@@ -373,6 +386,15 @@ export let assets = ${assets ? s(assets) : 'base'};
|
|
|
373
386
|
export function set_assets(path) {
|
|
374
387
|
assets = path;
|
|
375
388
|
}`;
|
|
389
|
+
|
|
390
|
+
case '\0__sveltekit/environment':
|
|
391
|
+
const { version } = svelte_config.kit;
|
|
392
|
+
return `export const version = ${s(version.name)};
|
|
393
|
+
export let building = false;
|
|
394
|
+
|
|
395
|
+
export function set_building() {
|
|
396
|
+
building = true;
|
|
397
|
+
}`;
|
|
376
398
|
}
|
|
377
399
|
}
|
|
378
400
|
};
|
|
@@ -460,30 +482,29 @@ export function set_assets(path) {
|
|
|
460
482
|
input[name] = path.resolve(file);
|
|
461
483
|
});
|
|
462
484
|
} else {
|
|
463
|
-
|
|
464
|
-
input
|
|
485
|
+
input['entry/start'] = `${runtime_directory}/client/start.js`;
|
|
486
|
+
input['entry/app'] = `${kit.outDir}/generated/client-optimized/app.js`;
|
|
465
487
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
488
|
+
/**
|
|
489
|
+
* @param {string | undefined} file
|
|
490
|
+
*/
|
|
491
|
+
function add_input(file) {
|
|
492
|
+
if (!file) return;
|
|
470
493
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
: posixify(path.join('pages', relative));
|
|
474
|
-
input[`components/${name}`] = resolved;
|
|
475
|
-
}
|
|
494
|
+
const resolved = path.resolve(file);
|
|
495
|
+
const relative = decodeURIComponent(path.relative(kit.files.routes, resolved));
|
|
476
496
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
497
|
+
const name = relative.startsWith('..')
|
|
498
|
+
? path.basename(file).replace(/^\+/, '')
|
|
499
|
+
: relative.replace(/(\\|\/)\+/g, '-').replace(/[\\/]/g, '-');
|
|
480
500
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
501
|
+
input[`entry/${name}`] = resolved;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
for (const node of manifest_data.nodes) {
|
|
505
|
+
add_input(node.component);
|
|
506
|
+
add_input(node.universal);
|
|
507
|
+
}
|
|
487
508
|
}
|
|
488
509
|
|
|
489
510
|
new_config = {
|
|
@@ -495,9 +516,13 @@ export function set_assets(path) {
|
|
|
495
516
|
input,
|
|
496
517
|
output: {
|
|
497
518
|
format: 'esm',
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
519
|
+
// we use .mjs for client-side modules, because this signals to Chrome (when it
|
|
520
|
+
// reads the <link rel="preload">) that it should parse the file as a module
|
|
521
|
+
// rather than as a script, preventing a double parse. Ideally we'd just use
|
|
522
|
+
// modulepreload, but Safari prevents that
|
|
523
|
+
entryFileNames: ssr ? '[name].js' : `${prefix}/[name].[hash].mjs`,
|
|
524
|
+
chunkFileNames: ssr ? 'chunks/[name].js' : `${prefix}/chunks/[name].[hash].mjs`,
|
|
525
|
+
assetFileNames: `${prefix}/assets/[name].[hash][extname]`,
|
|
501
526
|
hoistTransitiveImports: false
|
|
502
527
|
},
|
|
503
528
|
preserveEntrySignatures: 'strict'
|
|
@@ -601,7 +626,7 @@ export function set_assets(path) {
|
|
|
601
626
|
app_path: `${kit.paths.base.slice(1)}${kit.paths.base ? '/' : ''}${kit.appDir}`,
|
|
602
627
|
manifest_data,
|
|
603
628
|
service_worker: !!service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
|
|
604
|
-
|
|
629
|
+
client: null,
|
|
605
630
|
server_manifest
|
|
606
631
|
};
|
|
607
632
|
|
|
@@ -658,11 +683,18 @@ export function set_assets(path) {
|
|
|
658
683
|
/** @type {import('vite').Manifest} */
|
|
659
684
|
const client_manifest = JSON.parse(read(`${out}/client/${vite_config.build.manifest}`));
|
|
660
685
|
|
|
661
|
-
build_data.
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
686
|
+
build_data.client = {
|
|
687
|
+
start: find_deps(
|
|
688
|
+
client_manifest,
|
|
689
|
+
posixify(path.relative('.', `${runtime_directory}/client/start.js`)),
|
|
690
|
+
false
|
|
691
|
+
),
|
|
692
|
+
app: find_deps(
|
|
693
|
+
client_manifest,
|
|
694
|
+
posixify(path.relative('.', `${kit.outDir}/generated/client-optimized/app.js`)),
|
|
695
|
+
false
|
|
696
|
+
)
|
|
697
|
+
};
|
|
666
698
|
|
|
667
699
|
const css = output.filter(
|
|
668
700
|
/** @type {(value: any) => value is import('rollup').OutputAsset} */
|
package/src/internal.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/** Internal version of $app/environment */
|
|
2
|
+
declare module '__sveltekit/environment' {
|
|
3
|
+
export const building: boolean;
|
|
4
|
+
export const version: string;
|
|
5
|
+
export function set_building(): void;
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
/** Internal version of $app/paths */
|
|
2
9
|
declare module '__sveltekit/paths' {
|
|
3
10
|
export const base: `/${string}`;
|