@sveltejs/kit 1.0.0-next.581 → 1.0.0-next.583
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 +2 -2
- package/src/core/prerender/prerender.js +5 -3
- package/src/exports/vite/build/utils.js +65 -23
- package/src/exports/vite/dev/index.js +33 -16
- package/src/exports/vite/index.js +80 -28
- package/src/exports/vite/utils.js +6 -2
- package/src/runtime/app/forms.js +1 -0
- package/src/runtime/client/client.js +1 -1
- package/types/ambient.d.ts +16 -2
- package/types/index.d.ts +2 -3
- package/types/private.d.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.583",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"marked": "^4.2.3",
|
|
36
36
|
"rollup": "^3.7.0",
|
|
37
37
|
"svelte": "^3.54.0",
|
|
38
|
-
"svelte-preprocess": "^
|
|
38
|
+
"svelte-preprocess": "^5.0.0",
|
|
39
39
|
"typescript": "^4.9.3",
|
|
40
40
|
"uvu": "^0.5.6",
|
|
41
41
|
"vite": "^4.0.0"
|
|
@@ -22,11 +22,12 @@ const [, , client_out_dir, manifest_path, results_path, verbose, env] = process.
|
|
|
22
22
|
prerender();
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* @template T
|
|
25
|
+
* @template {{message: string}} T
|
|
26
|
+
* @template {Omit<T, 'message'>} K
|
|
26
27
|
* @param {import('types').Logger} log
|
|
27
28
|
* @param {'fail' | 'warn' | 'ignore' | ((details: T) => void)} input
|
|
28
|
-
* @param {(details:
|
|
29
|
-
* @returns {(details:
|
|
29
|
+
* @param {(details: K) => string} format
|
|
30
|
+
* @returns {(details: K) => void}
|
|
30
31
|
*/
|
|
31
32
|
function normalise_error_handler(log, input, format) {
|
|
32
33
|
switch (input) {
|
|
@@ -41,6 +42,7 @@ function normalise_error_handler(log, input, format) {
|
|
|
41
42
|
case 'ignore':
|
|
42
43
|
return () => {};
|
|
43
44
|
default:
|
|
45
|
+
// @ts-expect-error TS thinks T might be of a different kind, but it's not
|
|
44
46
|
return (details) => input({ ...details, message: format(details) });
|
|
45
47
|
}
|
|
46
48
|
}
|
|
@@ -108,39 +108,22 @@ export function resolve_symlinks(manifest, file) {
|
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
/**
|
|
111
|
-
*
|
|
111
|
+
* Partial Vite configuration that we use by default for setting up the build.
|
|
112
|
+
* Can be used in a non-SvelteKit Vite server and build process such as Storybook.
|
|
112
113
|
* @param {{
|
|
113
114
|
* config: import('types').ValidatedConfig;
|
|
114
|
-
* input: Record<string, string>;
|
|
115
115
|
* ssr: boolean;
|
|
116
|
-
* outDir: string;
|
|
117
116
|
* }} options
|
|
118
117
|
* @return {import('vite').UserConfig}
|
|
119
118
|
*/
|
|
120
|
-
export function
|
|
119
|
+
export function get_build_setup_config({ config, ssr }) {
|
|
121
120
|
const prefix = `${config.kit.appDir}/immutable`;
|
|
122
121
|
|
|
123
122
|
return {
|
|
124
|
-
appType: 'custom',
|
|
125
|
-
base: ssr ? assets_base(config.kit) : './',
|
|
126
123
|
build: {
|
|
127
|
-
cssCodeSplit: true,
|
|
128
124
|
// don't use the default name to avoid collisions with 'static/manifest.json'
|
|
129
125
|
manifest: 'vite-manifest.json',
|
|
130
|
-
|
|
131
|
-
rollupOptions: {
|
|
132
|
-
input,
|
|
133
|
-
output: {
|
|
134
|
-
format: 'esm',
|
|
135
|
-
entryFileNames: ssr ? '[name].js' : `${prefix}/[name]-[hash].js`,
|
|
136
|
-
chunkFileNames: ssr ? 'chunks/[name].js' : `${prefix}/chunks/[name]-[hash].js`,
|
|
137
|
-
assetFileNames: `${prefix}/assets/[name]-[hash][extname]`,
|
|
138
|
-
hoistTransitiveImports: false
|
|
139
|
-
},
|
|
140
|
-
preserveEntrySignatures: 'strict'
|
|
141
|
-
},
|
|
142
|
-
ssr,
|
|
143
|
-
target: ssr ? 'node14.8' : undefined
|
|
126
|
+
ssr
|
|
144
127
|
},
|
|
145
128
|
define: {
|
|
146
129
|
__SVELTEKIT_ADAPTER_NAME__: JSON.stringify(config.kit.adapter?.name),
|
|
@@ -148,7 +131,6 @@ export function get_default_build_config({ config, input, ssr, outDir }) {
|
|
|
148
131
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(config.kit.version.pollInterval),
|
|
149
132
|
__SVELTEKIT_EMBEDDED__: config.kit.embedded ? 'true' : 'false'
|
|
150
133
|
},
|
|
151
|
-
publicDir: ssr ? false : config.kit.files.assets,
|
|
152
134
|
resolve: {
|
|
153
135
|
alias: [...get_app_aliases(config.kit), ...get_config_aliases(config.kit)]
|
|
154
136
|
},
|
|
@@ -156,7 +138,16 @@ export function get_default_build_config({ config, input, ssr, outDir }) {
|
|
|
156
138
|
exclude: ['@sveltejs/kit']
|
|
157
139
|
},
|
|
158
140
|
ssr: {
|
|
159
|
-
noExternal: [
|
|
141
|
+
noExternal: [
|
|
142
|
+
// TODO document why this is necessary
|
|
143
|
+
'@sveltejs/kit',
|
|
144
|
+
// This ensures that esm-env is inlined into the server output with the
|
|
145
|
+
// export conditions resolved correctly through Vite. This prevents adapters
|
|
146
|
+
// that bundle later on to resolve the export conditions incorrectly
|
|
147
|
+
// and for example include browser-only code in the server output
|
|
148
|
+
// because they for example use esbuild.build with `platform: 'browser'`
|
|
149
|
+
'esm-env'
|
|
150
|
+
]
|
|
160
151
|
},
|
|
161
152
|
worker: {
|
|
162
153
|
rollupOptions: {
|
|
@@ -170,6 +161,57 @@ export function get_default_build_config({ config, input, ssr, outDir }) {
|
|
|
170
161
|
};
|
|
171
162
|
}
|
|
172
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Partial Vite configuration that we use by default for setting up the build.
|
|
166
|
+
* Cannot be used in a non-SvelteKit Vite server and build process such as Storybook.
|
|
167
|
+
* @param {{
|
|
168
|
+
* config: import('types').ValidatedConfig;
|
|
169
|
+
* input: Record<string, string>;
|
|
170
|
+
* ssr: boolean;
|
|
171
|
+
* outDir: string;
|
|
172
|
+
* }} options
|
|
173
|
+
* @return {import('vite').UserConfig}
|
|
174
|
+
*/
|
|
175
|
+
export function get_build_compile_config({ config, input, ssr, outDir }) {
|
|
176
|
+
const prefix = `${config.kit.appDir}/immutable`;
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
appType: 'custom',
|
|
180
|
+
base: ssr ? assets_base(config.kit) : './',
|
|
181
|
+
build: {
|
|
182
|
+
cssCodeSplit: true,
|
|
183
|
+
outDir,
|
|
184
|
+
rollupOptions: {
|
|
185
|
+
input,
|
|
186
|
+
output: {
|
|
187
|
+
format: 'esm',
|
|
188
|
+
entryFileNames: ssr ? '[name].js' : `${prefix}/[name]-[hash].js`,
|
|
189
|
+
chunkFileNames: ssr ? 'chunks/[name].js' : `${prefix}/chunks/[name]-[hash].js`,
|
|
190
|
+
assetFileNames: `${prefix}/assets/[name]-[hash][extname]`,
|
|
191
|
+
hoistTransitiveImports: false
|
|
192
|
+
},
|
|
193
|
+
preserveEntrySignatures: 'strict'
|
|
194
|
+
},
|
|
195
|
+
target: ssr ? 'node16.14' : undefined
|
|
196
|
+
},
|
|
197
|
+
publicDir: ssr ? false : config.kit.files.assets
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* The Vite configuration that we use by default for building.
|
|
203
|
+
* @param {{
|
|
204
|
+
* config: import('types').ValidatedConfig;
|
|
205
|
+
* input: Record<string, string>;
|
|
206
|
+
* ssr: boolean;
|
|
207
|
+
* outDir: string;
|
|
208
|
+
* }} options
|
|
209
|
+
* @return {import('vite').UserConfig}
|
|
210
|
+
*/
|
|
211
|
+
export function get_default_build_config(options) {
|
|
212
|
+
return vite.mergeConfig(get_build_setup_config(options), get_build_compile_config(options));
|
|
213
|
+
}
|
|
214
|
+
|
|
173
215
|
/**
|
|
174
216
|
* @param {import('types').ValidatedKitConfig} config
|
|
175
217
|
* @returns {string}
|
|
@@ -11,7 +11,7 @@ import { posixify, resolve_entry, to_fs } from '../../../utils/filesystem.js';
|
|
|
11
11
|
import { load_error_page, load_template } from '../../../core/config/index.js';
|
|
12
12
|
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
|
|
13
13
|
import * as sync from '../../../core/sync/sync.js';
|
|
14
|
-
import { get_mime_lookup,
|
|
14
|
+
import { get_mime_lookup, runtime_prefix } from '../../../core/utils.js';
|
|
15
15
|
import { compact } from '../../../utils/array.js';
|
|
16
16
|
import { not_found } from '../utils.js';
|
|
17
17
|
|
|
@@ -49,7 +49,22 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
async function update_manifest() {
|
|
52
|
-
|
|
52
|
+
try {
|
|
53
|
+
({ manifest_data } = await sync.create(svelte_config));
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error(colors.bold().red('Failed to update manifest'));
|
|
56
|
+
console.error(error);
|
|
57
|
+
vite.ws.send({
|
|
58
|
+
type: 'error',
|
|
59
|
+
err: {
|
|
60
|
+
message: `Failed to udpate manifest: ${
|
|
61
|
+
/** @type {Error} */ (error)?.message ?? 'Unknown error'
|
|
62
|
+
}`,
|
|
63
|
+
stack: /** @type {Error} */ (error)?.stack ?? ''
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
53
68
|
|
|
54
69
|
manifest = {
|
|
55
70
|
appDir: svelte_config.kit.appDir,
|
|
@@ -221,13 +236,16 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
221
236
|
}, 100);
|
|
222
237
|
};
|
|
223
238
|
|
|
239
|
+
// flag to skip watchers if server is already restarting
|
|
240
|
+
let restarting = false;
|
|
241
|
+
|
|
224
242
|
// Debounce add/unlink events because in case of folder deletion or moves
|
|
225
243
|
// they fire in rapid succession, causing needless invocations.
|
|
226
244
|
watch('add', () => debounce(update_manifest));
|
|
227
245
|
watch('unlink', () => debounce(update_manifest));
|
|
228
246
|
watch('change', (file) => {
|
|
229
247
|
// Don't run for a single file if the whole manifest is about to get updated
|
|
230
|
-
if (timeout) return;
|
|
248
|
+
if (timeout || restarting) return;
|
|
231
249
|
|
|
232
250
|
sync.update(svelte_config, manifest_data, file);
|
|
233
251
|
});
|
|
@@ -238,12 +256,23 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
238
256
|
// send the vite client a full-reload event without path being set
|
|
239
257
|
if (appTemplate !== 'index.html') {
|
|
240
258
|
vite.watcher.on('change', (file) => {
|
|
241
|
-
if (file === appTemplate) {
|
|
259
|
+
if (file === appTemplate && !restarting) {
|
|
242
260
|
vite.ws.send({ type: 'full-reload' });
|
|
243
261
|
}
|
|
244
262
|
});
|
|
245
263
|
}
|
|
246
264
|
|
|
265
|
+
// changing the svelte config requires restarting the dev server
|
|
266
|
+
// the config is only read on start and passed on to vite-plugin-svelte
|
|
267
|
+
// which needs up-to-date values to operate correctly
|
|
268
|
+
vite.watcher.on('change', (file) => {
|
|
269
|
+
if (path.basename(file) === 'svelte.config.js') {
|
|
270
|
+
console.log(`svelte config changed, restarting vite dev-server. changed file: ${file}`);
|
|
271
|
+
restarting = true;
|
|
272
|
+
vite.restart();
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
247
276
|
const assets = svelte_config.kit.paths.assets ? SVELTE_KIT_ASSETS : svelte_config.kit.paths.base;
|
|
248
277
|
const asset_server = sirv(svelte_config.kit.files.assets, {
|
|
249
278
|
dev: true,
|
|
@@ -284,11 +313,6 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
284
313
|
}
|
|
285
314
|
});
|
|
286
315
|
|
|
287
|
-
// set `import { version } from '$app/environment'`
|
|
288
|
-
(await vite.ssrLoadModule(`${runtime_prefix}/env.js`)).set_version(
|
|
289
|
-
svelte_config.kit.version.name
|
|
290
|
-
);
|
|
291
|
-
|
|
292
316
|
return () => {
|
|
293
317
|
const serve_static_middleware = vite.middlewares.stack.find(
|
|
294
318
|
(middleware) =>
|
|
@@ -408,13 +432,6 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
408
432
|
`/${posixify(path.relative(cwd, `${svelte_config.kit.outDir}/generated/root.svelte`))}`
|
|
409
433
|
);
|
|
410
434
|
|
|
411
|
-
const paths = await vite.ssrLoadModule(`${runtime_base}/paths.js`);
|
|
412
|
-
|
|
413
|
-
paths.set_paths({
|
|
414
|
-
base: svelte_config.kit.paths.base,
|
|
415
|
-
assets
|
|
416
|
-
});
|
|
417
|
-
|
|
418
435
|
let request;
|
|
419
436
|
|
|
420
437
|
try {
|
|
@@ -1,24 +1,27 @@
|
|
|
1
1
|
import { fork } from 'node:child_process';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
|
-
import
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
5
6
|
import { svelte } from '@sveltejs/vite-plugin-svelte';
|
|
7
|
+
import colors from 'kleur';
|
|
6
8
|
import * as vite from 'vite';
|
|
9
|
+
|
|
7
10
|
import { mkdirp, posixify, resolve_entry, rimraf } from '../../utils/filesystem.js';
|
|
11
|
+
import { SVELTE_KIT_ASSETS } from '../../constants.js';
|
|
12
|
+
import { create_static_module, create_dynamic_module } from '../../core/env.js';
|
|
8
13
|
import * as sync from '../../core/sync/sync.js';
|
|
14
|
+
import { create_assets } from '../../core/sync/create_manifest_data/index.js';
|
|
15
|
+
import { runtime_base, runtime_directory, runtime_prefix, logger } from '../../core/utils.js';
|
|
16
|
+
import { load_config } from '../../core/config/index.js';
|
|
17
|
+
import { generate_manifest } from '../../core/generate_manifest/index.js';
|
|
9
18
|
import { build_server } from './build/build_server.js';
|
|
10
19
|
import { build_service_worker } from './build/build_service_worker.js';
|
|
11
|
-
import {
|
|
20
|
+
import { find_deps, get_build_setup_config, get_build_compile_config } from './build/utils.js';
|
|
12
21
|
import { dev } from './dev/index.js';
|
|
13
|
-
import {
|
|
14
|
-
import { runtime_directory, logger } from '../../core/utils.js';
|
|
15
|
-
import { find_deps, get_default_build_config } from './build/utils.js';
|
|
22
|
+
import { is_illegal, module_guard, normalize_id } from './graph_analysis/index.js';
|
|
16
23
|
import { preview } from './preview/index.js';
|
|
17
24
|
import { get_config_aliases, get_app_aliases, get_env } from './utils.js';
|
|
18
|
-
import { fileURLToPath } from 'node:url';
|
|
19
|
-
import { create_static_module, create_dynamic_module } from '../../core/env.js';
|
|
20
|
-
import { is_illegal, module_guard, normalize_id } from './graph_analysis/index.js';
|
|
21
|
-
import { create_assets } from '../../core/sync/create_manifest_data/index.js';
|
|
22
25
|
|
|
23
26
|
export { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
|
24
27
|
|
|
@@ -168,7 +171,7 @@ function kit({ svelte_config }) {
|
|
|
168
171
|
}
|
|
169
172
|
});
|
|
170
173
|
|
|
171
|
-
return
|
|
174
|
+
return get_build_compile_config({
|
|
172
175
|
config: svelte_config,
|
|
173
176
|
input,
|
|
174
177
|
ssr: false,
|
|
@@ -200,8 +203,8 @@ function kit({ svelte_config }) {
|
|
|
200
203
|
check_vite_version();
|
|
201
204
|
|
|
202
205
|
/** @type {import('vite').Plugin} */
|
|
203
|
-
const
|
|
204
|
-
name: 'vite-plugin-sveltekit-
|
|
206
|
+
const plugin_setup = {
|
|
207
|
+
name: 'vite-plugin-sveltekit-setup',
|
|
205
208
|
|
|
206
209
|
/**
|
|
207
210
|
* Build the SvelteKit-provided Vite config to be merged with the user's vite.config.js file.
|
|
@@ -226,7 +229,7 @@ function kit({ svelte_config }) {
|
|
|
226
229
|
if (is_build) {
|
|
227
230
|
manifest_data = (await sync.all(svelte_config, config_env.mode)).manifest_data;
|
|
228
231
|
|
|
229
|
-
const new_config =
|
|
232
|
+
const new_config = get_build_setup_config({ config: svelte_config, ssr: false });
|
|
230
233
|
|
|
231
234
|
const warning = warn_overridden_config(config, new_config);
|
|
232
235
|
if (warning) console.error(warning + '\n');
|
|
@@ -252,20 +255,10 @@ function kit({ svelte_config }) {
|
|
|
252
255
|
// dev and preview config can be shared
|
|
253
256
|
/** @type {import('vite').UserConfig} */
|
|
254
257
|
const result = {
|
|
255
|
-
appType: 'custom',
|
|
256
|
-
base: './',
|
|
257
|
-
build: {
|
|
258
|
-
rollupOptions: {
|
|
259
|
-
// Vite dependency crawler needs an explicit JS entry point
|
|
260
|
-
// eventhough server otherwise works without it
|
|
261
|
-
input: `${runtime_directory}/client/start.js`
|
|
262
|
-
}
|
|
263
|
-
},
|
|
264
258
|
define: {
|
|
265
259
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
|
|
266
260
|
__SVELTEKIT_EMBEDDED__: svelte_config.kit.embedded ? 'true' : 'false'
|
|
267
261
|
},
|
|
268
|
-
publicDir: svelte_config.kit.files.assets,
|
|
269
262
|
resolve: {
|
|
270
263
|
alias: [...get_app_aliases(svelte_config.kit), ...get_config_aliases(svelte_config.kit)]
|
|
271
264
|
},
|
|
@@ -554,12 +547,68 @@ function kit({ svelte_config }) {
|
|
|
554
547
|
fs.unlinkSync(`${paths.output_dir}/client/${vite_config.build.manifest}`);
|
|
555
548
|
fs.unlinkSync(`${paths.output_dir}/server/${vite_config.build.manifest}`);
|
|
556
549
|
}
|
|
550
|
+
},
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* @see https://vitejs.dev/guide/api-plugin.html#configureserver
|
|
554
|
+
*/
|
|
555
|
+
async configureServer(vite) {
|
|
556
|
+
// set `import { version } from '$app/environment'`
|
|
557
|
+
(await vite.ssrLoadModule(`${runtime_prefix}/env.js`)).set_version(
|
|
558
|
+
svelte_config.kit.version.name
|
|
559
|
+
);
|
|
560
|
+
|
|
561
|
+
// set `import { base, assets } from '$app/paths'`
|
|
562
|
+
const { base, assets } = svelte_config.kit.paths;
|
|
563
|
+
|
|
564
|
+
(await vite.ssrLoadModule(`${runtime_base}/paths.js`)).set_paths({
|
|
565
|
+
base,
|
|
566
|
+
assets: assets ? SVELTE_KIT_ASSETS : base
|
|
567
|
+
});
|
|
557
568
|
}
|
|
558
569
|
};
|
|
559
570
|
|
|
560
571
|
/** @type {import('vite').Plugin} */
|
|
561
|
-
const
|
|
562
|
-
name: 'vite-plugin-sveltekit-
|
|
572
|
+
const plugin_compile = {
|
|
573
|
+
name: 'vite-plugin-sveltekit-compile',
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* Build the SvelteKit-provided Vite config to be merged with the user's vite.config.js file.
|
|
577
|
+
* @see https://vitejs.dev/guide/api-plugin.html#config
|
|
578
|
+
*/
|
|
579
|
+
async config(config, config_env) {
|
|
580
|
+
// The config is created in build_server for SSR mode and passed inline
|
|
581
|
+
if (config.build?.ssr) return;
|
|
582
|
+
|
|
583
|
+
if (config_env.command === 'build') {
|
|
584
|
+
const new_config = vite_client_build_config();
|
|
585
|
+
|
|
586
|
+
const warning = warn_overridden_config(config, new_config);
|
|
587
|
+
if (warning) console.error(warning + '\n');
|
|
588
|
+
|
|
589
|
+
return new_config;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// dev and preview config can be shared
|
|
593
|
+
/** @type {import('vite').UserConfig} */
|
|
594
|
+
const result = {
|
|
595
|
+
appType: 'custom',
|
|
596
|
+
base: svelte_config.kit.paths.base,
|
|
597
|
+
build: {
|
|
598
|
+
rollupOptions: {
|
|
599
|
+
// Vite dependency crawler needs an explicit JS entry point
|
|
600
|
+
// eventhough server otherwise works without it
|
|
601
|
+
input: `${runtime_directory}/client/start.js`
|
|
602
|
+
}
|
|
603
|
+
},
|
|
604
|
+
publicDir: svelte_config.kit.files.assets
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
const warning = warn_overridden_config(config, result);
|
|
608
|
+
if (warning) console.error(warning);
|
|
609
|
+
|
|
610
|
+
return result;
|
|
611
|
+
},
|
|
563
612
|
|
|
564
613
|
/**
|
|
565
614
|
* Adds the SvelteKit middleware to do SSR in dev mode.
|
|
@@ -578,7 +627,7 @@ function kit({ svelte_config }) {
|
|
|
578
627
|
}
|
|
579
628
|
};
|
|
580
629
|
|
|
581
|
-
return [
|
|
630
|
+
return [plugin_setup, plugin_compile];
|
|
582
631
|
}
|
|
583
632
|
|
|
584
633
|
function check_vite_version() {
|
|
@@ -634,8 +683,12 @@ function warn_overridden_config(config, resolved_config) {
|
|
|
634
683
|
* @param {string[]} out used locally to compute the return value
|
|
635
684
|
*/
|
|
636
685
|
function find_overridden_config(config, resolved_config, enforced_config, path, out) {
|
|
686
|
+
if (config == null || resolved_config == null) {
|
|
687
|
+
return out;
|
|
688
|
+
}
|
|
689
|
+
|
|
637
690
|
for (const key in enforced_config) {
|
|
638
|
-
if (typeof config === 'object' &&
|
|
691
|
+
if (typeof config === 'object' && key in config && key in resolved_config) {
|
|
639
692
|
const enforced = enforced_config[key];
|
|
640
693
|
|
|
641
694
|
if (enforced === true) {
|
|
@@ -647,7 +700,6 @@ function find_overridden_config(config, resolved_config, enforced_config, path,
|
|
|
647
700
|
}
|
|
648
701
|
}
|
|
649
702
|
}
|
|
650
|
-
|
|
651
703
|
return out;
|
|
652
704
|
}
|
|
653
705
|
|
|
@@ -173,8 +173,12 @@ export function not_found(req, res, base) {
|
|
|
173
173
|
|
|
174
174
|
if (type === 'text/html') {
|
|
175
175
|
res.setHeader('Content-Type', 'text/html');
|
|
176
|
-
res.end(
|
|
176
|
+
res.end(
|
|
177
|
+
`The server is configured with a public base URL of /path-base - did you mean to visit <a href="${prefixed}">${prefixed}</a> instead?`
|
|
178
|
+
);
|
|
177
179
|
} else {
|
|
178
|
-
res.end(
|
|
180
|
+
res.end(
|
|
181
|
+
`The server is configured with a public base URL of /path-base - did you mean to visit ${prefixed} instead?`
|
|
182
|
+
);
|
|
179
183
|
}
|
|
180
184
|
}
|
package/src/runtime/app/forms.js
CHANGED
|
@@ -107,6 +107,7 @@ export function enhance(form, submit = () => {}) {
|
|
|
107
107
|
});
|
|
108
108
|
|
|
109
109
|
result = deserialize(await response.text());
|
|
110
|
+
if (result.type === 'error') result.status = response.status;
|
|
110
111
|
} catch (error) {
|
|
111
112
|
if (/** @type {any} */ (error)?.name === 'AbortError') return;
|
|
112
113
|
result = { type: 'error', error };
|
|
@@ -1387,7 +1387,7 @@ export function create_client({ target, base }) {
|
|
|
1387
1387
|
url,
|
|
1388
1388
|
params: current.params,
|
|
1389
1389
|
branch: branch.slice(0, error_load.idx).concat(error_load.node),
|
|
1390
|
-
status:
|
|
1390
|
+
status: result.status ?? 500,
|
|
1391
1391
|
error: result.error,
|
|
1392
1392
|
route
|
|
1393
1393
|
});
|
package/types/ambient.d.ts
CHANGED
|
@@ -160,8 +160,17 @@ declare module '$app/forms' {
|
|
|
160
160
|
* Usage:
|
|
161
161
|
*
|
|
162
162
|
* ```js
|
|
163
|
-
*
|
|
164
|
-
*
|
|
163
|
+
* import { deserialize } from '$app/forms';
|
|
164
|
+
*
|
|
165
|
+
* async function handleSubmit(event) {
|
|
166
|
+
* const response = await fetch('/form?/action', {
|
|
167
|
+
* method: 'POST',
|
|
168
|
+
* body: new FormData(event.target)
|
|
169
|
+
* });
|
|
170
|
+
*
|
|
171
|
+
* const result = deserialize(await response.text());
|
|
172
|
+
* // ...
|
|
173
|
+
* }
|
|
165
174
|
* ```
|
|
166
175
|
*/
|
|
167
176
|
export function deserialize<
|
|
@@ -220,6 +229,8 @@ declare module '$app/navigation' {
|
|
|
220
229
|
*
|
|
221
230
|
* ```ts
|
|
222
231
|
* // Example: Match '/path' regardless of the query parameters
|
|
232
|
+
* import { invalidate } from '$app/navigation';
|
|
233
|
+
*
|
|
223
234
|
* invalidate((url) => url.pathname === '/path');
|
|
224
235
|
* ```
|
|
225
236
|
* @param url The invalidated URL
|
|
@@ -356,6 +367,7 @@ declare module '@sveltejs/kit/hooks' {
|
|
|
356
367
|
* /// file: src/hooks.server.js
|
|
357
368
|
* import { sequence } from '@sveltejs/kit/hooks';
|
|
358
369
|
*
|
|
370
|
+
* /// type: import('@sveltejs/kit').Handle
|
|
359
371
|
* async function first({ event, resolve }) {
|
|
360
372
|
* console.log('first pre-processing');
|
|
361
373
|
* const result = await resolve(event, {
|
|
@@ -369,6 +381,7 @@ declare module '@sveltejs/kit/hooks' {
|
|
|
369
381
|
* return result;
|
|
370
382
|
* }
|
|
371
383
|
*
|
|
384
|
+
* /// type: import('@sveltejs/kit').Handle
|
|
372
385
|
* async function second({ event, resolve }) {
|
|
373
386
|
* console.log('second pre-processing');
|
|
374
387
|
* const result = await resolve(event, {
|
|
@@ -434,4 +447,5 @@ declare module '@sveltejs/kit/vite' {
|
|
|
434
447
|
* Returns the SvelteKit Vite plugins.
|
|
435
448
|
*/
|
|
436
449
|
export function sveltekit(): Promise<Plugin[]>;
|
|
450
|
+
export { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
|
|
437
451
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -464,8 +464,7 @@ export interface KitConfig {
|
|
|
464
464
|
* }
|
|
465
465
|
*
|
|
466
466
|
* // otherwise fail the build
|
|
467
|
-
*
|
|
468
|
-
* }
|
|
467
|
+
* throw new Error(message);
|
|
469
468
|
* }
|
|
470
469
|
* }
|
|
471
470
|
* }
|
|
@@ -1075,7 +1074,7 @@ export type ActionResult<
|
|
|
1075
1074
|
| { type: 'success'; status: number; data?: Success }
|
|
1076
1075
|
| { type: 'failure'; status: number; data?: Invalid }
|
|
1077
1076
|
| { type: 'redirect'; status: number; location: string }
|
|
1078
|
-
| { type: 'error'; error: any };
|
|
1077
|
+
| { type: 'error'; status?: number; error: any };
|
|
1079
1078
|
|
|
1080
1079
|
/**
|
|
1081
1080
|
* Creates an `HttpError` object with an HTTP status code and an optional message.
|
package/types/private.d.ts
CHANGED
|
@@ -192,11 +192,12 @@ export interface PrerenderHttpErrorHandler {
|
|
|
192
192
|
path: string;
|
|
193
193
|
referrer: string | null;
|
|
194
194
|
referenceType: 'linked' | 'fetched';
|
|
195
|
+
message: string;
|
|
195
196
|
}): void;
|
|
196
197
|
}
|
|
197
198
|
|
|
198
199
|
export interface PrerenderMissingIdHandler {
|
|
199
|
-
(details: { path: string; id: string; referrers: string[] }): void;
|
|
200
|
+
(details: { path: string; id: string; referrers: string[]; message: string }): void;
|
|
200
201
|
}
|
|
201
202
|
|
|
202
203
|
export type PrerenderHttpErrorHandlerValue = 'fail' | 'warn' | 'ignore' | PrerenderHttpErrorHandler;
|