@sveltejs/kit 1.25.0 → 1.25.2
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 +4 -4
- package/src/core/adapt/builder.js +4 -1
- package/src/exports/vite/dev/index.js +13 -9
- package/src/exports/vite/graph_analysis/index.js +12 -4
- package/src/exports/vite/index.js +11 -15
- package/src/exports/vite/utils.js +2 -0
- package/src/runtime/client/client.js +7 -3
- package/src/runtime/server/page/respond_with_error.js +5 -0
- package/src/runtime/server/respond.js +8 -0
- package/src/runtime/server/utils.js +1 -9
- package/src/runtime/shared-server.js +3 -3
- package/src/types/internal.d.ts +1 -1
- package/src/utils/routing.js +10 -0
- package/src/version.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.25.
|
|
3
|
+
"version": "1.25.2",
|
|
4
4
|
"description": "The fastest way to build Svelte apps",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"set-cookie-parser": "^2.6.0",
|
|
24
24
|
"sirv": "^2.0.2",
|
|
25
25
|
"tiny-glob": "^0.2.9",
|
|
26
|
-
"undici": "~5.
|
|
26
|
+
"undici": "~5.25.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@playwright/test": "1.30.0",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"svelte": "^4.0.5",
|
|
39
39
|
"svelte-preprocess": "^5.0.4",
|
|
40
40
|
"typescript": "^4.9.4",
|
|
41
|
-
"vite": "^4.4.
|
|
42
|
-
"vitest": "^0.34.
|
|
41
|
+
"vite": "^4.4.9",
|
|
42
|
+
"vitest": "^0.34.5"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"svelte": "^3.54.0 || ^4.0.0-next.0",
|
|
@@ -181,7 +181,10 @@ export function create_builder({
|
|
|
181
181
|
},
|
|
182
182
|
|
|
183
183
|
writeClient(dest) {
|
|
184
|
-
return copy(`${config.kit.outDir}/output/client`, dest
|
|
184
|
+
return copy(`${config.kit.outDir}/output/client`, dest, {
|
|
185
|
+
// avoid making vite build artefacts public
|
|
186
|
+
filter: (basename) => basename !== '.vite'
|
|
187
|
+
});
|
|
185
188
|
},
|
|
186
189
|
|
|
187
190
|
writePrerendered(dest) {
|
|
@@ -54,11 +54,14 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
54
54
|
/** @param {string} url */
|
|
55
55
|
async function loud_ssr_load_module(url) {
|
|
56
56
|
try {
|
|
57
|
-
return await vite.ssrLoadModule(url);
|
|
57
|
+
return await vite.ssrLoadModule(url, { fixStacktrace: true });
|
|
58
58
|
} catch (/** @type {any} */ err) {
|
|
59
59
|
const msg = buildErrorMessage(err, [colors.red(`Internal server error: ${err.message}`)]);
|
|
60
60
|
|
|
61
|
-
vite.config.logger.
|
|
61
|
+
if (!vite.config.logger.hasErrorLogged(err)) {
|
|
62
|
+
vite.config.logger.error(msg, { error: err });
|
|
63
|
+
}
|
|
64
|
+
|
|
62
65
|
vite.ws.send({
|
|
63
66
|
type: 'error',
|
|
64
67
|
err: {
|
|
@@ -233,7 +236,7 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
233
236
|
for (const key in manifest_data.matchers) {
|
|
234
237
|
const file = manifest_data.matchers[key];
|
|
235
238
|
const url = path.resolve(cwd, file);
|
|
236
|
-
const module = await vite.ssrLoadModule(url);
|
|
239
|
+
const module = await vite.ssrLoadModule(url, { fixStacktrace: true });
|
|
237
240
|
|
|
238
241
|
if (module.match) {
|
|
239
242
|
matchers[key] = module.match;
|
|
@@ -248,9 +251,10 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
248
251
|
};
|
|
249
252
|
}
|
|
250
253
|
|
|
251
|
-
/** @param {
|
|
252
|
-
function fix_stack_trace(
|
|
253
|
-
|
|
254
|
+
/** @param {Error} error */
|
|
255
|
+
function fix_stack_trace(error) {
|
|
256
|
+
vite.ssrFixStacktrace(error);
|
|
257
|
+
return error.stack;
|
|
254
258
|
}
|
|
255
259
|
|
|
256
260
|
await update_manifest();
|
|
@@ -393,7 +397,7 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
393
397
|
} catch (e) {
|
|
394
398
|
const error = coalesce_to_error(e);
|
|
395
399
|
res.statusCode = 500;
|
|
396
|
-
res.end(fix_stack_trace(
|
|
400
|
+
res.end(fix_stack_trace(error));
|
|
397
401
|
}
|
|
398
402
|
});
|
|
399
403
|
|
|
@@ -454,7 +458,7 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
454
458
|
|
|
455
459
|
// we have to import `Server` before calling `set_assets`
|
|
456
460
|
const { Server } = /** @type {import('types').ServerModule} */ (
|
|
457
|
-
await vite.ssrLoadModule(`${runtime_base}/server/index.js
|
|
461
|
+
await vite.ssrLoadModule(`${runtime_base}/server/index.js`, { fixStacktrace: true })
|
|
458
462
|
);
|
|
459
463
|
|
|
460
464
|
const { set_fix_stack_trace } = await vite.ssrLoadModule(
|
|
@@ -523,7 +527,7 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
523
527
|
} catch (e) {
|
|
524
528
|
const error = coalesce_to_error(e);
|
|
525
529
|
res.statusCode = 500;
|
|
526
|
-
res.end(fix_stack_trace(
|
|
530
|
+
res.end(fix_stack_trace(error));
|
|
527
531
|
}
|
|
528
532
|
});
|
|
529
533
|
};
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { posixify } from '../../../utils/filesystem.js';
|
|
3
|
+
import { strip_virtual_prefix } from '../utils.js';
|
|
3
4
|
|
|
4
|
-
const ILLEGAL_IMPORTS = new Set([
|
|
5
|
+
const ILLEGAL_IMPORTS = new Set([
|
|
6
|
+
'\0virtual:$env/dynamic/private',
|
|
7
|
+
'\0virtual:$env/static/private'
|
|
8
|
+
]);
|
|
5
9
|
const ILLEGAL_MODULE_NAME_PATTERN = /.*\.server\..+/;
|
|
6
10
|
|
|
7
11
|
/**
|
|
@@ -51,10 +55,14 @@ export function module_guard(context, { cwd, lib }) {
|
|
|
51
55
|
chain.map(({ id, dynamic }, i) => {
|
|
52
56
|
id = normalize_id(id, lib, cwd);
|
|
53
57
|
|
|
54
|
-
return `${' '.repeat(i * 2)}- ${id} ${
|
|
55
|
-
|
|
58
|
+
return `${' '.repeat(i * 2)}- ${strip_virtual_prefix(id)} ${
|
|
59
|
+
dynamic ? 'dynamically imports' : 'imports'
|
|
60
|
+
}\n`;
|
|
61
|
+
}) + `${' '.repeat(chain.length)}- ${strip_virtual_prefix(id)}`;
|
|
56
62
|
|
|
57
|
-
const message = `Cannot import ${
|
|
63
|
+
const message = `Cannot import ${strip_virtual_prefix(
|
|
64
|
+
id
|
|
65
|
+
)} into client-side code:\n${pyramid}`;
|
|
58
66
|
|
|
59
67
|
throw new Error(message);
|
|
60
68
|
}
|
|
@@ -18,7 +18,7 @@ import { assets_base, find_deps } from './build/utils.js';
|
|
|
18
18
|
import { dev } from './dev/index.js';
|
|
19
19
|
import { is_illegal, module_guard, normalize_id } from './graph_analysis/index.js';
|
|
20
20
|
import { preview } from './preview/index.js';
|
|
21
|
-
import { get_config_aliases, get_env } from './utils.js';
|
|
21
|
+
import { get_config_aliases, get_env, strip_virtual_prefix } from './utils.js';
|
|
22
22
|
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';
|
|
@@ -336,7 +336,7 @@ function kit({ svelte_config }) {
|
|
|
336
336
|
async resolveId(id) {
|
|
337
337
|
// treat $env/static/[public|private] as virtual
|
|
338
338
|
if (id.startsWith('$env/') || id.startsWith('__sveltekit/') || id === '$service-worker') {
|
|
339
|
-
return `\
|
|
339
|
+
return `\0virtual:${id}`;
|
|
340
340
|
}
|
|
341
341
|
},
|
|
342
342
|
|
|
@@ -358,24 +358,24 @@ function kit({ svelte_config }) {
|
|
|
358
358
|
})
|
|
359
359
|
) {
|
|
360
360
|
const relative = normalize_id(id, normalized_lib, normalized_cwd);
|
|
361
|
-
throw new Error(`Cannot import ${relative} into client-side code`);
|
|
361
|
+
throw new Error(`Cannot import ${strip_virtual_prefix(relative)} into client-side code`);
|
|
362
362
|
}
|
|
363
363
|
}
|
|
364
364
|
|
|
365
365
|
switch (id) {
|
|
366
|
-
case '\
|
|
366
|
+
case '\0virtual:$env/static/private':
|
|
367
367
|
return create_static_module('$env/static/private', env.private);
|
|
368
368
|
|
|
369
|
-
case '\
|
|
369
|
+
case '\0virtual:$env/static/public':
|
|
370
370
|
return create_static_module('$env/static/public', env.public);
|
|
371
371
|
|
|
372
|
-
case '\
|
|
372
|
+
case '\0virtual:$env/dynamic/private':
|
|
373
373
|
return create_dynamic_module(
|
|
374
374
|
'private',
|
|
375
375
|
vite_config_env.command === 'serve' ? env.private : undefined
|
|
376
376
|
);
|
|
377
377
|
|
|
378
|
-
case '\
|
|
378
|
+
case '\0virtual:$env/dynamic/public':
|
|
379
379
|
// populate `$env/dynamic/public` from `window`
|
|
380
380
|
if (browser) {
|
|
381
381
|
return `export const env = ${global}.env;`;
|
|
@@ -386,12 +386,12 @@ function kit({ svelte_config }) {
|
|
|
386
386
|
vite_config_env.command === 'serve' ? env.public : undefined
|
|
387
387
|
);
|
|
388
388
|
|
|
389
|
-
case '\
|
|
389
|
+
case '\0virtual:$service-worker':
|
|
390
390
|
return create_service_worker_module(svelte_config);
|
|
391
391
|
|
|
392
392
|
// for internal use only. it's published as $app/paths externally
|
|
393
393
|
// we use this alias so that we won't collide with user aliases
|
|
394
|
-
case '\
|
|
394
|
+
case '\0virtual:__sveltekit/paths': {
|
|
395
395
|
const { assets, base } = svelte_config.kit.paths;
|
|
396
396
|
|
|
397
397
|
// use the values defined in `global`, but fall back to hard-coded values
|
|
@@ -429,7 +429,7 @@ function kit({ svelte_config }) {
|
|
|
429
429
|
`;
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
-
case '\
|
|
432
|
+
case '\0virtual:__sveltekit/environment': {
|
|
433
433
|
const { version } = svelte_config.kit;
|
|
434
434
|
|
|
435
435
|
return dedent`
|
|
@@ -555,7 +555,7 @@ function kit({ svelte_config }) {
|
|
|
555
555
|
cssCodeSplit: true,
|
|
556
556
|
cssMinify: initial_config.build?.minify == null ? true : !!initial_config.build.minify,
|
|
557
557
|
// don't use the default name to avoid collisions with 'static/manifest.json'
|
|
558
|
-
manifest: 'vite
|
|
558
|
+
manifest: '.vite/manifest.json', // TODO: remove this after bumping peer dep to vite 5
|
|
559
559
|
outDir: `${out}/${ssr ? 'server' : 'client'}`,
|
|
560
560
|
rollupOptions: {
|
|
561
561
|
input,
|
|
@@ -805,10 +805,6 @@ function kit({ svelte_config }) {
|
|
|
805
805
|
.cyan('npm run preview')} to preview your production build locally.`
|
|
806
806
|
);
|
|
807
807
|
|
|
808
|
-
// avoid making the manifest available to users
|
|
809
|
-
fs.unlinkSync(`${out}/client/${vite_config.build.manifest}`);
|
|
810
|
-
fs.unlinkSync(`${out}/server/${vite_config.build.manifest}`);
|
|
811
|
-
|
|
812
808
|
if (kit.adapter) {
|
|
813
809
|
const { adapt } = await import('../../core/adapt/index.js');
|
|
814
810
|
await adapt(svelte_config, build_data, metadata, prerendered, prerender_map, log);
|
|
@@ -1662,16 +1662,19 @@ export function create_client(app, target) {
|
|
|
1662
1662
|
});
|
|
1663
1663
|
|
|
1664
1664
|
addEventListener('popstate', async (event) => {
|
|
1665
|
+
token = {};
|
|
1665
1666
|
if (event.state?.[INDEX_KEY]) {
|
|
1666
1667
|
// if a popstate-driven navigation is cancelled, we need to counteract it
|
|
1667
1668
|
// with history.go, which means we end up back here, hence this check
|
|
1668
1669
|
if (event.state[INDEX_KEY] === current_history_index) return;
|
|
1669
1670
|
|
|
1670
1671
|
const scroll = scroll_positions[event.state[INDEX_KEY]];
|
|
1672
|
+
const url = new URL(location.href);
|
|
1671
1673
|
|
|
1672
1674
|
// if the only change is the hash, we don't need to do anything...
|
|
1673
1675
|
if (current.url.href.split('#')[0] === location.href.split('#')[0]) {
|
|
1674
|
-
// ...except handle scroll
|
|
1676
|
+
// ...except update our internal URL tracking and handle scroll
|
|
1677
|
+
update_url(url);
|
|
1675
1678
|
scroll_positions[current_history_index] = scroll_state();
|
|
1676
1679
|
current_history_index = event.state[INDEX_KEY];
|
|
1677
1680
|
scrollTo(scroll.x, scroll.y);
|
|
@@ -1681,7 +1684,7 @@ export function create_client(app, target) {
|
|
|
1681
1684
|
const delta = event.state[INDEX_KEY] - current_history_index;
|
|
1682
1685
|
|
|
1683
1686
|
await navigate({
|
|
1684
|
-
url
|
|
1687
|
+
url,
|
|
1685
1688
|
scroll,
|
|
1686
1689
|
keepfocus: false,
|
|
1687
1690
|
redirect_chain: [],
|
|
@@ -1693,7 +1696,8 @@ export function create_client(app, target) {
|
|
|
1693
1696
|
history.go(-delta);
|
|
1694
1697
|
},
|
|
1695
1698
|
type: 'popstate',
|
|
1696
|
-
delta
|
|
1699
|
+
delta,
|
|
1700
|
+
nav_token: token
|
|
1697
1701
|
});
|
|
1698
1702
|
} else {
|
|
1699
1703
|
// since popstate event is also emitted when an anchor referencing the same
|
|
@@ -28,6 +28,11 @@ export async function respond_with_error({
|
|
|
28
28
|
error,
|
|
29
29
|
resolve_opts
|
|
30
30
|
}) {
|
|
31
|
+
// reroute to the fallback page to prevent an infinite chain of requests.
|
|
32
|
+
if (event.request.headers.get('x-sveltekit-error')) {
|
|
33
|
+
return static_error_page(options, status, /** @type {Error} */ (error).message);
|
|
34
|
+
}
|
|
35
|
+
|
|
31
36
|
/** @type {import('./types').Fetched[]} */
|
|
32
37
|
const fetched = [];
|
|
33
38
|
|
|
@@ -457,6 +457,14 @@ export async function respond(request, options, manifest, state) {
|
|
|
457
457
|
return response;
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
+
if (state.error && event.isSubRequest) {
|
|
461
|
+
return await fetch(request, {
|
|
462
|
+
headers: {
|
|
463
|
+
'x-sveltekit-error': 'true'
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
|
|
460
468
|
if (state.error) {
|
|
461
469
|
return text('Internal Server Error', {
|
|
462
470
|
status: 500
|
|
@@ -99,15 +99,7 @@ export async function handle_error_and_jsonify(event, options, error) {
|
|
|
99
99
|
return error.body;
|
|
100
100
|
} else {
|
|
101
101
|
if (__SVELTEKIT_DEV__ && typeof error == 'object') {
|
|
102
|
-
|
|
103
|
-
get: (target, property) => {
|
|
104
|
-
if (property === 'stack') {
|
|
105
|
-
return fix_stack_trace(target.stack);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return Reflect.get(target, property, target);
|
|
109
|
-
}
|
|
110
|
-
});
|
|
102
|
+
fix_stack_trace(error);
|
|
111
103
|
}
|
|
112
104
|
|
|
113
105
|
return (
|
|
@@ -4,8 +4,8 @@ export let private_env = {};
|
|
|
4
4
|
/** @type {Record<string, string>} */
|
|
5
5
|
export let public_env = {};
|
|
6
6
|
|
|
7
|
-
/** @param {
|
|
8
|
-
export let fix_stack_trace = (
|
|
7
|
+
/** @param {any} error */
|
|
8
|
+
export let fix_stack_trace = (error) => error?.stack;
|
|
9
9
|
|
|
10
10
|
/** @type {(environment: Record<string, string>) => void} */
|
|
11
11
|
export function set_private_env(environment) {
|
|
@@ -17,7 +17,7 @@ export function set_public_env(environment) {
|
|
|
17
17
|
public_env = environment;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
/** @param {(
|
|
20
|
+
/** @param {(error: Error) => string} value */
|
|
21
21
|
export function set_fix_stack_trace(value) {
|
|
22
22
|
fix_stack_trace = value;
|
|
23
23
|
}
|
package/src/types/internal.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export interface ServerInternalModule {
|
|
|
32
32
|
set_private_env(environment: Record<string, string>): void;
|
|
33
33
|
set_public_env(environment: Record<string, string>): void;
|
|
34
34
|
set_version(version: string): void;
|
|
35
|
-
set_fix_stack_trace(fix_stack_trace: (
|
|
35
|
+
set_fix_stack_trace(fix_stack_trace: (error: unknown) => string): void;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export interface Asset {
|
package/src/utils/routing.js
CHANGED
|
@@ -136,6 +136,7 @@ export function exec(match, params, matchers) {
|
|
|
136
136
|
const result = {};
|
|
137
137
|
|
|
138
138
|
const values = match.slice(1);
|
|
139
|
+
const values_needing_match = values.filter((value) => value !== undefined);
|
|
139
140
|
|
|
140
141
|
let buffered = 0;
|
|
141
142
|
|
|
@@ -170,6 +171,15 @@ export function exec(match, params, matchers) {
|
|
|
170
171
|
if (next_param && !next_param.rest && next_param.optional && next_value && param.chained) {
|
|
171
172
|
buffered = 0;
|
|
172
173
|
}
|
|
174
|
+
|
|
175
|
+
// There are no more params and no more values, but all non-empty values have been matched
|
|
176
|
+
if (
|
|
177
|
+
!next_param &&
|
|
178
|
+
!next_value &&
|
|
179
|
+
Object.keys(result).length === values_needing_match.length
|
|
180
|
+
) {
|
|
181
|
+
buffered = 0;
|
|
182
|
+
}
|
|
173
183
|
continue;
|
|
174
184
|
}
|
|
175
185
|
|
package/src/version.js
CHANGED