@sveltejs/kit 2.62.0 → 3.0.0-next.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 +28 -22
- package/src/cli.js +49 -20
- package/src/core/adapt/builder.js +38 -69
- package/src/core/adapt/index.js +11 -6
- package/src/core/config/index.js +12 -82
- package/src/core/config/options.js +36 -45
- package/src/core/env.js +240 -60
- package/src/core/generate_manifest/find_server_assets.js +3 -2
- package/src/core/generate_manifest/index.js +11 -3
- package/src/core/postbuild/analyse.js +20 -16
- package/src/core/postbuild/fallback.js +0 -3
- package/src/core/postbuild/prerender.js +19 -17
- package/src/core/postbuild/queue.js +3 -4
- package/src/core/sync/create_manifest_data/index.js +16 -18
- package/src/core/sync/sync.js +44 -23
- package/src/core/sync/utils.js +0 -15
- package/src/core/sync/write_ambient.js +5 -50
- package/src/core/sync/write_client_manifest.js +8 -9
- package/src/core/sync/write_env.js +36 -0
- package/src/core/sync/write_non_ambient.js +7 -7
- package/src/core/sync/write_root.js +41 -89
- package/src/core/sync/write_server.js +18 -24
- package/src/core/sync/write_tsconfig.js +29 -24
- package/src/core/sync/write_types/index.js +31 -25
- package/src/core/utils.js +14 -11
- package/src/exports/hooks/index.js +13 -0
- package/src/exports/index.js +8 -21
- package/src/exports/internal/env.js +71 -0
- package/src/exports/internal/types.d.ts +3 -0
- package/src/exports/node/index.js +8 -13
- package/src/exports/public.d.ts +68 -69
- package/src/exports/vite/build/build_server.js +14 -11
- package/src/exports/vite/build/remote.js +6 -7
- package/src/exports/vite/build/utils.js +7 -5
- package/src/exports/vite/dev/index.js +32 -33
- package/src/exports/vite/index.js +1015 -711
- package/src/exports/vite/module_ids.js +10 -6
- package/src/exports/vite/options.js +17 -0
- package/src/exports/vite/preview/index.js +3 -5
- package/src/exports/vite/static_analysis/index.js +11 -5
- package/src/exports/vite/utils.js +11 -41
- package/src/runtime/app/env/index.js +2 -0
- package/src/runtime/app/env/internal.js +14 -0
- package/src/runtime/app/env/private.js +1 -0
- package/src/runtime/app/env/public/client.js +1 -0
- package/src/runtime/app/env/public/index.js +1 -0
- package/src/runtime/app/env/public/server.js +1 -0
- package/src/runtime/app/env/standard-schema.d.ts +0 -0
- package/src/runtime/app/server/index.js +4 -2
- package/src/runtime/app/server/remote/form.js +0 -51
- package/src/runtime/app/server/remote/query.js +1 -8
- package/src/runtime/app/server/remote/shared.js +4 -3
- package/src/runtime/app/state/client.js +1 -12
- package/src/runtime/client/client.js +1 -1
- package/src/runtime/client/constants.js +0 -1
- package/src/runtime/client/remote-functions/form.svelte.js +0 -31
- package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
- package/src/runtime/client/remote-functions/query/index.js +2 -2
- package/src/runtime/client/remote-functions/query/instance.svelte.js +1 -2
- package/src/runtime/client/remote-functions/query-batch.svelte.js +2 -2
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +5 -8
- package/src/runtime/client/utils.js +9 -11
- package/src/runtime/components/{svelte-5/layout.svelte → layout.svelte} +1 -1
- package/src/runtime/form-utils.js +4 -41
- package/src/runtime/server/cookie.js +21 -37
- package/src/runtime/server/env_module.js +12 -4
- package/src/runtime/server/fetch.js +6 -10
- package/src/runtime/server/index.js +5 -9
- package/src/runtime/server/page/render.js +33 -37
- package/src/runtime/server/page/types.d.ts +4 -2
- package/src/runtime/server/respond.js +3 -3
- package/src/runtime/server/utils.js +2 -4
- package/src/runtime/shared-server.js +0 -22
- package/src/runtime/shared.js +0 -15
- package/src/types/ambient-private.d.ts +25 -9
- package/src/types/global-private.d.ts +6 -0
- package/src/types/internal.d.ts +4 -8
- package/src/utils/css.js +3 -19
- package/src/utils/filesystem.js +1 -30
- package/src/utils/http.js +0 -21
- package/src/utils/import.js +8 -7
- package/src/utils/os.js +7 -0
- package/src/utils/path.js +23 -0
- package/src/utils/shared-iterator.js +3 -0
- package/src/utils/streaming.js +2 -4
- package/src/utils/url.js +1 -1
- package/src/utils/vite.js +28 -0
- package/src/version.js +1 -1
- package/types/index.d.ts +85 -109
- package/types/index.d.ts.map +5 -6
- package/src/exports/vite/build/build_service_worker.js +0 -149
- package/src/runtime/app/environment/index.js +0 -2
- package/src/runtime/components/svelte-4/error.svelte +0 -6
- package/src/runtime/components/svelte-4/layout.svelte +0 -1
- package/src/runtime/env/dynamic/private.js +0 -1
- package/src/runtime/env/dynamic/public.js +0 -1
- package/src/types/synthetic/$env+dynamic+private.md +0 -43
- package/src/types/synthetic/$env+dynamic+public.md +0 -46
- package/src/types/synthetic/$env+static+private.md +0 -31
- package/src/types/synthetic/$env+static+public.md +0 -31
- package/src/utils/env.js +0 -13
- package/src/utils/promise.js +0 -29
- /package/src/runtime/app/{environment → env}/types.d.ts +0 -0
- /package/src/runtime/components/{svelte-5/error.svelte → error.svelte} +0 -0
|
@@ -7,9 +7,10 @@ import { normalizePath } from 'vite';
|
|
|
7
7
|
* @param {import('vite').Manifest} manifest
|
|
8
8
|
* @param {string} entry
|
|
9
9
|
* @param {boolean} add_dynamic_css
|
|
10
|
+
* @param {string} root
|
|
10
11
|
* @returns {import('types').AssetDependencies}
|
|
11
12
|
*/
|
|
12
|
-
export function find_deps(manifest, entry, add_dynamic_css) {
|
|
13
|
+
export function find_deps(manifest, entry, add_dynamic_css, root) {
|
|
13
14
|
/** @type {Set<string>} */
|
|
14
15
|
const seen = new Set();
|
|
15
16
|
|
|
@@ -35,7 +36,7 @@ export function find_deps(manifest, entry, add_dynamic_css) {
|
|
|
35
36
|
if (seen.has(current)) return;
|
|
36
37
|
seen.add(current);
|
|
37
38
|
|
|
38
|
-
const { chunk } = resolve_symlinks(manifest, current);
|
|
39
|
+
const { chunk } = resolve_symlinks(manifest, current, root);
|
|
39
40
|
|
|
40
41
|
if (add_js) imports.add(chunk.file);
|
|
41
42
|
|
|
@@ -81,7 +82,7 @@ export function find_deps(manifest, entry, add_dynamic_css) {
|
|
|
81
82
|
}
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
const { chunk, file } = resolve_symlinks(manifest, entry);
|
|
85
|
+
const { chunk, file } = resolve_symlinks(manifest, entry, root);
|
|
85
86
|
|
|
86
87
|
traverse(file, true, entry, 0);
|
|
87
88
|
|
|
@@ -101,10 +102,11 @@ export function find_deps(manifest, entry, add_dynamic_css) {
|
|
|
101
102
|
/**
|
|
102
103
|
* @param {import('vite').Manifest} manifest
|
|
103
104
|
* @param {string} file
|
|
105
|
+
* @param {string} root
|
|
104
106
|
*/
|
|
105
|
-
export function resolve_symlinks(manifest, file) {
|
|
107
|
+
export function resolve_symlinks(manifest, file, root) {
|
|
106
108
|
while (!manifest[file]) {
|
|
107
|
-
const next = normalizePath(path.relative(
|
|
109
|
+
const next = normalizePath(path.relative(root, fs.realpathSync(file)));
|
|
108
110
|
if (next === file) throw new Error(`Could not find file "${file}" in Vite manifest`);
|
|
109
111
|
file = next;
|
|
110
112
|
}
|
|
@@ -2,27 +2,26 @@
|
|
|
2
2
|
/** @import { PrerenderOption, UniversalNode } from 'types' */
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import process from 'node:process';
|
|
6
5
|
import { URL } from 'node:url';
|
|
7
6
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
8
|
-
import
|
|
7
|
+
import { styleText } from 'node:util';
|
|
9
8
|
import sirv from 'sirv';
|
|
10
9
|
import { isCSSRequest, loadEnv, buildErrorMessage } from 'vite';
|
|
11
10
|
import { createReadableStream, getRequest, setResponse } from '../../../exports/node/index.js';
|
|
12
|
-
import { installPolyfills } from '../../../exports/node/polyfills.js';
|
|
13
11
|
import { coalesce_to_error } from '../../../utils/error.js';
|
|
14
|
-
import {
|
|
12
|
+
import { resolve_entry } from '../../../utils/filesystem.js';
|
|
13
|
+
import { from_fs, to_fs } from '../../../utils/vite.js';
|
|
14
|
+
import { posixify } from '../../../utils/os.js';
|
|
15
15
|
import { load_error_page } from '../../../core/config/index.js';
|
|
16
16
|
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
|
|
17
17
|
import * as sync from '../../../core/sync/sync.js';
|
|
18
|
-
import { get_mime_lookup,
|
|
18
|
+
import { get_mime_lookup, get_runtime_base } from '../../../core/utils.js';
|
|
19
19
|
import { compact } from '../../../utils/array.js';
|
|
20
20
|
import { is_chrome_devtools_request, not_found } from '../utils.js';
|
|
21
21
|
import { SCHEME } from '../../../utils/url.js';
|
|
22
22
|
import { check_feature } from '../../../utils/features.js';
|
|
23
23
|
import { escape_html } from '../../../utils/escape.js';
|
|
24
24
|
|
|
25
|
-
const cwd = process.cwd();
|
|
26
25
|
// vite-specifc queries that we should skip handling for css urls
|
|
27
26
|
const vite_css_query_regex = /(?:\?|&)(?:raw|url|inline)(?:&|$)/;
|
|
28
27
|
|
|
@@ -31,11 +30,11 @@ const vite_css_query_regex = /(?:\?|&)(?:raw|url|inline)(?:&|$)/;
|
|
|
31
30
|
* @param {import('vite').ResolvedConfig} vite_config
|
|
32
31
|
* @param {import('types').ValidatedConfig} svelte_config
|
|
33
32
|
* @param {() => Array<{ hash: string, file: string }>} get_remotes
|
|
33
|
+
* @param {string} root The project root directory
|
|
34
|
+
* @param {import('@sveltejs/kit').Adapter | undefined} adapter
|
|
34
35
|
* @return {Promise<Promise<() => void>>}
|
|
35
36
|
*/
|
|
36
|
-
export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
37
|
-
installPolyfills();
|
|
38
|
-
|
|
37
|
+
export async function dev(vite, vite_config, svelte_config, get_remotes, root, adapter) {
|
|
39
38
|
/** @type {AsyncLocalStorage<{ event: RequestEvent, config: any, prerender: PrerenderOption }>} */
|
|
40
39
|
const async_local_storage = new AsyncLocalStorage();
|
|
41
40
|
|
|
@@ -43,12 +42,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
43
42
|
const context = async_local_storage.getStore();
|
|
44
43
|
if (!context || context.prerender === true) return;
|
|
45
44
|
|
|
46
|
-
check_feature(
|
|
47
|
-
/** @type {string} */ (context.event.route.id),
|
|
48
|
-
context.config,
|
|
49
|
-
label,
|
|
50
|
-
svelte_config.kit.adapter
|
|
51
|
-
);
|
|
45
|
+
check_feature(/** @type {string} */ (context.event.route.id), context.config, label, adapter);
|
|
52
46
|
};
|
|
53
47
|
|
|
54
48
|
const fetch = globalThis.fetch;
|
|
@@ -62,7 +56,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
62
56
|
return fetch(info, init);
|
|
63
57
|
};
|
|
64
58
|
|
|
65
|
-
sync.init(svelte_config,
|
|
59
|
+
sync.init(svelte_config, root);
|
|
66
60
|
|
|
67
61
|
/** @type {import('types').ManifestData} */
|
|
68
62
|
let manifest_data;
|
|
@@ -76,9 +70,10 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
76
70
|
async function loud_ssr_load_module(url) {
|
|
77
71
|
try {
|
|
78
72
|
return await vite.ssrLoadModule(url, { fixStacktrace: true });
|
|
79
|
-
} catch (/** @type {
|
|
80
|
-
const
|
|
81
|
-
|
|
73
|
+
} catch (/** @type {any} */ err) {
|
|
74
|
+
const msg = buildErrorMessage(err, [
|
|
75
|
+
styleText('red', `Internal server error: ${err.message}`)
|
|
76
|
+
]);
|
|
82
77
|
|
|
83
78
|
if (!vite.config.logger.hasErrorLogged(err)) {
|
|
84
79
|
vite.config.logger.error(msg, { error: err });
|
|
@@ -113,7 +108,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
113
108
|
|
|
114
109
|
function update_manifest() {
|
|
115
110
|
try {
|
|
116
|
-
({ manifest_data } = sync.create(svelte_config));
|
|
111
|
+
({ manifest_data } = sync.create(svelte_config, root));
|
|
117
112
|
|
|
118
113
|
if (manifest_error) {
|
|
119
114
|
manifest_error = null;
|
|
@@ -122,7 +117,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
122
117
|
} catch (error) {
|
|
123
118
|
manifest_error = /** @type {Error} */ (error);
|
|
124
119
|
|
|
125
|
-
console.error(
|
|
120
|
+
console.error(styleText(['bold', 'red'], manifest_error.message));
|
|
126
121
|
vite.ws.send({
|
|
127
122
|
type: 'error',
|
|
128
123
|
err: {
|
|
@@ -141,7 +136,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
141
136
|
mimeTypes: get_mime_lookup(manifest_data),
|
|
142
137
|
_: {
|
|
143
138
|
client: {
|
|
144
|
-
start: `${
|
|
139
|
+
start: `${get_runtime_base(root)}/client/entry.js`,
|
|
145
140
|
app: `${to_fs(svelte_config.kit.outDir)}/generated/client/app.js`,
|
|
146
141
|
imports: [],
|
|
147
142
|
stylesheets: [],
|
|
@@ -284,7 +279,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
284
279
|
page: route.page,
|
|
285
280
|
endpoint: endpoint
|
|
286
281
|
? async () => {
|
|
287
|
-
const url = path.resolve(
|
|
282
|
+
const url = path.resolve(root, endpoint.file);
|
|
288
283
|
return await loud_ssr_load_module(url);
|
|
289
284
|
}
|
|
290
285
|
: null,
|
|
@@ -298,7 +293,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
298
293
|
|
|
299
294
|
for (const key in manifest_data.matchers) {
|
|
300
295
|
const file = manifest_data.matchers[key];
|
|
301
|
-
const url = path.resolve(
|
|
296
|
+
const url = path.resolve(root, file);
|
|
302
297
|
const module = await vite.ssrLoadModule(url, { fixStacktrace: true });
|
|
303
298
|
|
|
304
299
|
if (module.match) {
|
|
@@ -322,7 +317,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
322
317
|
// ssrFixStacktrace can fail on StackBlitz web containers and we don't know why
|
|
323
318
|
// by ignoring it the line numbers are wrong, but at least we can show the error
|
|
324
319
|
}
|
|
325
|
-
return error.stack;
|
|
320
|
+
return error.stack?.replaceAll('\0', ''); // remove null bytes from e.g. virtual module IDs, or the response will fail
|
|
326
321
|
}
|
|
327
322
|
|
|
328
323
|
update_manifest();
|
|
@@ -368,7 +363,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
368
363
|
// Don't run for a single file if the whole manifest is about to get updated
|
|
369
364
|
// Unless it's a file where the trailing slash page option might have changed
|
|
370
365
|
if (timeout || restarting || !/\+(page|layout|server).*$/.test(file)) return;
|
|
371
|
-
sync.update(svelte_config, manifest_data, file);
|
|
366
|
+
sync.update(svelte_config, manifest_data, file, root);
|
|
372
367
|
});
|
|
373
368
|
|
|
374
369
|
const { appTemplate, errorTemplate, serviceWorker, hooks } = svelte_config.kit.files;
|
|
@@ -391,7 +386,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
391
386
|
file.startsWith(serviceWorker) ||
|
|
392
387
|
file.startsWith(hooks.server)
|
|
393
388
|
) {
|
|
394
|
-
sync.server(svelte_config);
|
|
389
|
+
sync.server(svelte_config, root);
|
|
395
390
|
}
|
|
396
391
|
});
|
|
397
392
|
|
|
@@ -441,7 +436,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
441
436
|
});
|
|
442
437
|
|
|
443
438
|
const env = loadEnv(vite_config.mode, svelte_config.kit.env.dir, '');
|
|
444
|
-
const emulator = await
|
|
439
|
+
const emulator = await adapter?.emulate?.();
|
|
445
440
|
|
|
446
441
|
return () => {
|
|
447
442
|
const serve_static_middleware = vite.middlewares.stack.find(
|
|
@@ -463,7 +458,9 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
463
458
|
}`;
|
|
464
459
|
|
|
465
460
|
const decoded = decodeURI(new URL(base + req.url).pathname);
|
|
466
|
-
const file = posixify(
|
|
461
|
+
const file = posixify(
|
|
462
|
+
path.resolve(root, decoded.slice(svelte_config.kit.paths.base.length + 1))
|
|
463
|
+
);
|
|
467
464
|
const is_file = fs.existsSync(file) && !fs.statSync(file).isDirectory();
|
|
468
465
|
const allowed =
|
|
469
466
|
!vite_config.server.fs.strict ||
|
|
@@ -510,11 +507,13 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
510
507
|
|
|
511
508
|
// we have to import `Server` before calling `set_assets`
|
|
512
509
|
const { Server } = /** @type {import('types').ServerModule} */ (
|
|
513
|
-
await vite.ssrLoadModule(`${
|
|
510
|
+
await vite.ssrLoadModule(`${get_runtime_base(root)}/server/index.js`, {
|
|
511
|
+
fixStacktrace: true
|
|
512
|
+
})
|
|
514
513
|
);
|
|
515
514
|
|
|
516
515
|
const { set_fix_stack_trace } = await vite.ssrLoadModule(
|
|
517
|
-
`${
|
|
516
|
+
`${get_runtime_base(root)}/shared-server.js`
|
|
518
517
|
);
|
|
519
518
|
set_fix_stack_trace(fix_stack_trace);
|
|
520
519
|
|
|
@@ -534,7 +533,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
534
533
|
});
|
|
535
534
|
|
|
536
535
|
if (manifest_error) {
|
|
537
|
-
console.error(
|
|
536
|
+
console.error(styleText(['bold', 'red'], manifest_error.message));
|
|
538
537
|
|
|
539
538
|
const error_page = load_error_page(svelte_config);
|
|
540
539
|
|
|
@@ -587,7 +586,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
|
|
|
587
586
|
} catch (e) {
|
|
588
587
|
const error = coalesce_to_error(e);
|
|
589
588
|
res.statusCode = 500;
|
|
590
|
-
res.end(fix_stack_trace(error));
|
|
589
|
+
res.end(fix_stack_trace(error) || error.message); // handle `stackless` errors
|
|
591
590
|
}
|
|
592
591
|
});
|
|
593
592
|
};
|