@sveltejs/kit 1.0.0-next.583 → 1.0.0-next.585
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
CHANGED
package/src/core/config/index.js
CHANGED
|
@@ -43,7 +43,14 @@ export function load_template(cwd, config) {
|
|
|
43
43
|
* @param {import('types').ValidatedConfig} config
|
|
44
44
|
*/
|
|
45
45
|
export function load_error_page(config) {
|
|
46
|
-
|
|
46
|
+
let { errorTemplate } = config.kit.files;
|
|
47
|
+
|
|
48
|
+
// Don't do this inside resolving the config, because that would mean
|
|
49
|
+
// adding/removing error.html isn't detected and would require a restart.
|
|
50
|
+
if (!fs.existsSync(config.kit.files.errorTemplate)) {
|
|
51
|
+
errorTemplate = url.fileURLToPath(new URL('./default-error.html', import.meta.url));
|
|
52
|
+
}
|
|
53
|
+
|
|
47
54
|
return fs.readFileSync(errorTemplate, 'utf-8');
|
|
48
55
|
}
|
|
49
56
|
|
|
@@ -86,12 +93,6 @@ function process_config(config, { cwd = process.cwd() } = {}) {
|
|
|
86
93
|
}
|
|
87
94
|
}
|
|
88
95
|
|
|
89
|
-
if (!fs.existsSync(validated.kit.files.errorTemplate)) {
|
|
90
|
-
validated.kit.files.errorTemplate = url.fileURLToPath(
|
|
91
|
-
new URL('./default-error.html', import.meta.url)
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
96
|
return validated;
|
|
96
97
|
}
|
|
97
98
|
|
|
@@ -117,8 +117,6 @@ export function resolve_symlinks(manifest, file) {
|
|
|
117
117
|
* @return {import('vite').UserConfig}
|
|
118
118
|
*/
|
|
119
119
|
export function get_build_setup_config({ config, ssr }) {
|
|
120
|
-
const prefix = `${config.kit.appDir}/immutable`;
|
|
121
|
-
|
|
122
120
|
return {
|
|
123
121
|
build: {
|
|
124
122
|
// don't use the default name to avoid collisions with 'static/manifest.json'
|
|
@@ -148,15 +146,6 @@ export function get_build_setup_config({ config, ssr }) {
|
|
|
148
146
|
// because they for example use esbuild.build with `platform: 'browser'`
|
|
149
147
|
'esm-env'
|
|
150
148
|
]
|
|
151
|
-
},
|
|
152
|
-
worker: {
|
|
153
|
-
rollupOptions: {
|
|
154
|
-
output: {
|
|
155
|
-
entryFileNames: `${prefix}/workers/[name]-[hash].js`,
|
|
156
|
-
chunkFileNames: `${prefix}/workers/chunks/[name]-[hash].js`,
|
|
157
|
-
hoistTransitiveImports: false
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
149
|
}
|
|
161
150
|
};
|
|
162
151
|
}
|
|
@@ -194,7 +183,16 @@ export function get_build_compile_config({ config, input, ssr, outDir }) {
|
|
|
194
183
|
},
|
|
195
184
|
target: ssr ? 'node16.14' : undefined
|
|
196
185
|
},
|
|
197
|
-
publicDir: ssr ? false : config.kit.files.assets
|
|
186
|
+
publicDir: ssr ? false : config.kit.files.assets,
|
|
187
|
+
worker: {
|
|
188
|
+
rollupOptions: {
|
|
189
|
+
output: {
|
|
190
|
+
entryFileNames: `${prefix}/workers/[name]-[hash].js`,
|
|
191
|
+
chunkFileNames: `${prefix}/workers/chunks/[name]-[hash].js`,
|
|
192
|
+
hoistTransitiveImports: false
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
198
196
|
};
|
|
199
197
|
}
|
|
200
198
|
|
|
@@ -36,6 +36,9 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
36
36
|
/** @type {import('types').SSRManifest} */
|
|
37
37
|
let manifest;
|
|
38
38
|
|
|
39
|
+
/** @type {Error | null} */
|
|
40
|
+
let manifest_error = null;
|
|
41
|
+
|
|
39
42
|
/** @param {string} id */
|
|
40
43
|
async function resolve(id) {
|
|
41
44
|
const url = id.startsWith('..') ? `/@fs${path.posix.resolve(id)}` : `/${id}`;
|
|
@@ -51,18 +54,24 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
51
54
|
async function update_manifest() {
|
|
52
55
|
try {
|
|
53
56
|
({ manifest_data } = await sync.create(svelte_config));
|
|
57
|
+
|
|
58
|
+
if (manifest_error) {
|
|
59
|
+
manifest_error = null;
|
|
60
|
+
vite.ws.send({ type: 'full-reload' });
|
|
61
|
+
}
|
|
54
62
|
} catch (error) {
|
|
55
|
-
|
|
63
|
+
manifest_error = /** @type {Error} */ (error);
|
|
64
|
+
|
|
65
|
+
console.error(colors.bold().red('Invalid routes'));
|
|
56
66
|
console.error(error);
|
|
57
67
|
vite.ws.send({
|
|
58
68
|
type: 'error',
|
|
59
69
|
err: {
|
|
60
|
-
message:
|
|
61
|
-
|
|
62
|
-
}`,
|
|
63
|
-
stack: /** @type {Error} */ (error)?.stack ?? ''
|
|
70
|
+
message: manifest_error.message ?? 'Invalid routes',
|
|
71
|
+
stack: ''
|
|
64
72
|
}
|
|
65
73
|
});
|
|
74
|
+
|
|
66
75
|
return;
|
|
67
76
|
}
|
|
68
77
|
|
|
@@ -447,6 +456,27 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
447
456
|
const template = load_template(cwd, svelte_config);
|
|
448
457
|
const error_page = load_error_page(svelte_config);
|
|
449
458
|
|
|
459
|
+
/** @param {{ status: number; message: string }} opts */
|
|
460
|
+
const error_template = ({ status, message }) => {
|
|
461
|
+
return error_page
|
|
462
|
+
.replace(/%sveltekit\.status%/g, String(status))
|
|
463
|
+
.replace(/%sveltekit\.error\.message%/g, message);
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
if (manifest_error) {
|
|
467
|
+
console.error(colors.bold().red('Invalid routes'));
|
|
468
|
+
console.error(manifest_error);
|
|
469
|
+
|
|
470
|
+
res.writeHead(500, {
|
|
471
|
+
'Content-Type': 'text/html; charset=utf-8'
|
|
472
|
+
});
|
|
473
|
+
res.end(
|
|
474
|
+
error_template({ status: 500, message: manifest_error.message ?? 'Invalid routes' })
|
|
475
|
+
);
|
|
476
|
+
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
|
|
450
480
|
const rendered = await respond(
|
|
451
481
|
request,
|
|
452
482
|
{
|
|
@@ -501,11 +531,7 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
501
531
|
);
|
|
502
532
|
},
|
|
503
533
|
app_template_contains_nonce: template.includes('%sveltekit.nonce%'),
|
|
504
|
-
error_template
|
|
505
|
-
return error_page
|
|
506
|
-
.replace(/%sveltekit\.status%/g, String(status))
|
|
507
|
-
.replace(/%sveltekit\.error\.message%/g, message);
|
|
508
|
-
},
|
|
534
|
+
error_template,
|
|
509
535
|
service_worker:
|
|
510
536
|
svelte_config.kit.serviceWorker.register &&
|
|
511
537
|
!!resolve_entry(svelte_config.kit.files.serviceWorker),
|
|
@@ -354,9 +354,7 @@ function kit({ svelte_config }) {
|
|
|
354
354
|
* Clears the output directories.
|
|
355
355
|
*/
|
|
356
356
|
buildStart() {
|
|
357
|
-
if (vite_config.build.ssr)
|
|
358
|
-
return;
|
|
359
|
-
}
|
|
357
|
+
if (vite_config.build.ssr) return;
|
|
360
358
|
|
|
361
359
|
// Reset for new build. Goes here because `build --watch` calls buildStart but not config
|
|
362
360
|
completed_build = false;
|
|
@@ -371,6 +369,16 @@ function kit({ svelte_config }) {
|
|
|
371
369
|
}
|
|
372
370
|
},
|
|
373
371
|
|
|
372
|
+
generateBundle() {
|
|
373
|
+
if (vite_config.build.ssr) return;
|
|
374
|
+
|
|
375
|
+
this.emitFile({
|
|
376
|
+
type: 'asset',
|
|
377
|
+
fileName: `${svelte_config.kit.appDir}/version.json`,
|
|
378
|
+
source: JSON.stringify({ version: svelte_config.kit.version.name })
|
|
379
|
+
});
|
|
380
|
+
},
|
|
381
|
+
|
|
374
382
|
/**
|
|
375
383
|
* Vite builds a single bundle. We need three bundles: client, server, and service worker.
|
|
376
384
|
* The user's package.json scripts will invoke the Vite CLI to execute the client build. We
|
|
@@ -379,9 +387,7 @@ function kit({ svelte_config }) {
|
|
|
379
387
|
writeBundle: {
|
|
380
388
|
sequential: true,
|
|
381
389
|
async handler(_options, bundle) {
|
|
382
|
-
if (vite_config.build.ssr)
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
390
|
+
if (vite_config.build.ssr) return;
|
|
385
391
|
|
|
386
392
|
const guard = module_guard(this, {
|
|
387
393
|
cwd: vite.normalizePath(process.cwd()),
|
|
@@ -401,11 +407,6 @@ function kit({ svelte_config }) {
|
|
|
401
407
|
verbose
|
|
402
408
|
});
|
|
403
409
|
|
|
404
|
-
fs.writeFileSync(
|
|
405
|
-
`${paths.client_out_dir}/${svelte_config.kit.appDir}/version.json`,
|
|
406
|
-
JSON.stringify({ version: svelte_config.kit.version.name })
|
|
407
|
-
);
|
|
408
|
-
|
|
409
410
|
const { assets, chunks } = collect_output(bundle);
|
|
410
411
|
log.info(
|
|
411
412
|
`Client build completed. Wrote ${chunks.length} chunks and ${assets.length} assets`
|
|
@@ -3,14 +3,4 @@
|
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
5
|
<h1>{$page.status}</h1>
|
|
6
|
-
|
|
7
|
-
<pre>{$page.error.message}</pre>
|
|
8
|
-
|
|
9
|
-
<!-- TODO figure out what to do with frames/stacktraces in prod -->
|
|
10
|
-
<!-- frame is populated by Svelte in its CompileError and is a Rollup/Vite convention -->
|
|
11
|
-
{#if $page.error.frame}
|
|
12
|
-
<pre>{$page.error.frame}</pre>
|
|
13
|
-
{/if}
|
|
14
|
-
{#if $page.error.stack}
|
|
15
|
-
<pre>{$page.error.stack}</pre>
|
|
16
|
-
{/if}
|
|
6
|
+
<p>{$page.error?.message}</p>
|