@sveltejs/kit 3.0.0-next.7 → 3.0.0-next.9
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 +6 -3
- package/src/core/config/index.js +1 -2
- package/src/core/config/options.js +5 -2
- package/src/core/env.js +1 -0
- package/src/core/sync/create_manifest_data/index.js +1 -1
- package/src/core/sync/sync.js +0 -2
- package/src/core/sync/write_client_manifest.js +0 -7
- package/src/core/sync/write_non_ambient.js +2 -2
- package/src/core/sync/write_server.js +0 -3
- package/src/core/sync/write_tsconfig.js +14 -4
- package/src/core/sync/write_tsconfig_test/package.json +7 -0
- package/src/core/sync/write_types/index.js +17 -14
- package/src/core/utils.js +2 -2
- package/src/exports/hooks/sequence.js +3 -2
- package/src/exports/index.js +1 -1
- package/src/exports/node/index.js +4 -8
- package/src/exports/public.d.ts +22 -23
- package/src/exports/vite/dev/index.js +4 -7
- package/src/exports/vite/index.js +110 -59
- package/src/exports/vite/preview/index.js +13 -14
- package/src/exports/vite/utils.js +14 -14
- package/src/runtime/app/env/internal.js +4 -4
- package/src/runtime/app/environment/index.js +3 -3
- package/src/runtime/app/forms.js +2 -2
- package/src/runtime/app/paths/internal/client.js +4 -2
- package/src/runtime/app/paths/internal/server.js +2 -23
- package/src/runtime/app/paths/server.js +2 -2
- package/src/runtime/app/server/remote/prerender.js +1 -2
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client-entry.js +3 -0
- package/src/runtime/client/client.js +217 -172
- package/src/runtime/client/entry.js +24 -3
- package/src/runtime/client/payload.js +17 -0
- package/src/runtime/client/remote-functions/form.svelte.js +6 -6
- package/src/runtime/client/state.svelte.js +0 -1
- package/src/runtime/client/types.d.ts +2 -6
- package/src/runtime/components/root.svelte +66 -0
- package/src/runtime/env/dynamic/private.js +7 -0
- package/src/runtime/env/dynamic/public.js +7 -0
- package/src/runtime/env/static/private.js +6 -0
- package/src/runtime/env/static/public.js +6 -0
- package/src/runtime/form-utils.js +1 -4
- package/src/runtime/server/cookie.js +51 -23
- package/src/runtime/server/csrf.js +1 -1
- package/src/runtime/server/data/index.js +8 -12
- package/src/runtime/server/page/index.js +7 -14
- package/src/runtime/server/page/render.js +71 -78
- package/src/runtime/server/remote.js +2 -1
- package/src/runtime/server/respond.js +1 -1
- package/src/runtime/server/utils.js +28 -5
- package/src/runtime/types.d.ts +8 -0
- package/src/types/global-private.d.ts +10 -17
- package/src/types/internal.d.ts +25 -26
- package/src/utils/import.js +6 -1
- package/src/utils/imports.js +83 -0
- package/src/utils/routing.js +6 -6
- package/src/version.js +1 -1
- package/types/index.d.ts +34 -285
- package/types/index.d.ts.map +3 -26
- package/src/core/sync/write_root.js +0 -127
- package/src/types/synthetic/$lib.md +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.9",
|
|
4
4
|
"description": "SvelteKit is the fastest way to build Svelte apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
35
35
|
"@types/connect": "^3.4.38",
|
|
36
36
|
"@types/node": "^22.19.19",
|
|
37
|
-
"dts-buddy": "^0.8.
|
|
37
|
+
"dts-buddy": "^0.8.2",
|
|
38
38
|
"jsdom": "^29.1.1",
|
|
39
39
|
"rolldown": "^1.1.2",
|
|
40
40
|
"svelte": "^5.56.3",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@opentelemetry/api": "^1.0.0",
|
|
49
49
|
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
50
|
-
"svelte": "^5.
|
|
50
|
+
"svelte": "^5.56.4",
|
|
51
51
|
"typescript": "^6.0.0",
|
|
52
52
|
"vite": "^8.0.12"
|
|
53
53
|
},
|
|
@@ -72,14 +72,17 @@
|
|
|
72
72
|
],
|
|
73
73
|
"imports": {
|
|
74
74
|
"#app/paths": {
|
|
75
|
+
"workerd": "./src/runtime/app/paths/server.js",
|
|
75
76
|
"browser": "./src/runtime/app/paths/client.js",
|
|
76
77
|
"default": "./src/runtime/app/paths/server.js"
|
|
77
78
|
},
|
|
78
79
|
"#app/env/public": {
|
|
80
|
+
"workerd": "./src/runtime/app/env/public/server.js",
|
|
79
81
|
"browser": "./src/runtime/app/env/public/client.js",
|
|
80
82
|
"default": "./src/runtime/app/env/public/server.js"
|
|
81
83
|
},
|
|
82
84
|
"#internal": {
|
|
85
|
+
"workerd": "./src/exports/internal/server/index.js",
|
|
83
86
|
"browser": "./src/exports/internal/client.js",
|
|
84
87
|
"default": "./src/exports/internal/server/index.js"
|
|
85
88
|
}
|
package/src/core/config/index.js
CHANGED
|
@@ -161,7 +161,7 @@ export function process_config(config, cwd) {
|
|
|
161
161
|
config.kit.files.hooks.client = path.resolve(cwd, config.kit.files.hooks.client);
|
|
162
162
|
config.kit.files.hooks.server = path.resolve(cwd, config.kit.files.hooks.server);
|
|
163
163
|
config.kit.files.hooks.universal = path.resolve(cwd, config.kit.files.hooks.universal);
|
|
164
|
-
} else {
|
|
164
|
+
} else if (key !== 'lib' /* TODO remove when we remove the `lib` option altogether */) {
|
|
165
165
|
// @ts-expect-error
|
|
166
166
|
config.kit.files[key] = path.resolve(cwd, config.kit.files[key]);
|
|
167
167
|
}
|
|
@@ -191,7 +191,6 @@ export function validate_config(config) {
|
|
|
191
191
|
files.hooks.client ??= path.join(files.src, 'hooks.client');
|
|
192
192
|
files.hooks.server ??= path.join(files.src, 'hooks.server');
|
|
193
193
|
files.hooks.universal ??= path.join(files.src, 'hooks');
|
|
194
|
-
files.lib ??= path.join(files.src, 'lib');
|
|
195
194
|
files.params ??= path.join(files.src, 'params');
|
|
196
195
|
files.routes ??= path.join(files.src, 'routes');
|
|
197
196
|
files.serviceWorker ??= path.join(files.src, 'service-worker');
|
|
@@ -129,7 +129,7 @@ export const validate_kit_options = object({
|
|
|
129
129
|
),
|
|
130
130
|
remoteFunctions: boolean(false),
|
|
131
131
|
forkPreloads: boolean(false),
|
|
132
|
-
handleRenderingErrors:
|
|
132
|
+
handleRenderingErrors: removed()
|
|
133
133
|
}),
|
|
134
134
|
|
|
135
135
|
files: object({
|
|
@@ -140,7 +140,10 @@ export const validate_kit_options = object({
|
|
|
140
140
|
server: string(null),
|
|
141
141
|
universal: string(null)
|
|
142
142
|
}),
|
|
143
|
-
lib:
|
|
143
|
+
lib: removed(
|
|
144
|
+
(keypath) =>
|
|
145
|
+
`\`${keypath}\` has been removed. Use #lib instead of $lib: https://svelte.dev/docs/kit/$lib`
|
|
146
|
+
),
|
|
144
147
|
params: string(null),
|
|
145
148
|
routes: string(null),
|
|
146
149
|
serviceWorker: string(null),
|
package/src/core/env.js
CHANGED
|
@@ -38,6 +38,7 @@ export async function load_explicit_env(kit, file, root, mode) {
|
|
|
38
38
|
logLevel: 'silent',
|
|
39
39
|
mode,
|
|
40
40
|
define: {
|
|
41
|
+
__SVELTEKIT_PAYLOAD__: 'undefined', // coming in through static import in env/internal.js but will end up unused
|
|
41
42
|
__SVELTEKIT_APP_VERSION__: JSON.stringify(kit.version.name) // needed by $app/env
|
|
42
43
|
},
|
|
43
44
|
resolve: {
|
|
@@ -142,7 +142,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
142
142
|
throw new Error(`Route ${id} should be renamed to ${id.replace(/#/g, '[x+23]')}`);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
if (/\[
|
|
145
|
+
if (/\[\.\.\.[\w-]+\]\/\[\[/.test(id)) {
|
|
146
146
|
throw new Error(
|
|
147
147
|
`Invalid route ${id} — an [[optional]] route segment cannot follow a [...rest] route segment`
|
|
148
148
|
);
|
package/src/core/sync/sync.js
CHANGED
|
@@ -2,7 +2,6 @@ import path from 'node:path';
|
|
|
2
2
|
import process from 'node:process';
|
|
3
3
|
import create_manifest_data from './create_manifest_data/index.js';
|
|
4
4
|
import { write_client_manifest } from './write_client_manifest.js';
|
|
5
|
-
import { write_root } from './write_root.js';
|
|
6
5
|
import { write_tsconfig } from './write_tsconfig.js';
|
|
7
6
|
import { write_types, write_all_types } from './write_types/index.js';
|
|
8
7
|
import { write_ambient } from './write_ambient.js';
|
|
@@ -37,7 +36,6 @@ export function create(config, root) {
|
|
|
37
36
|
|
|
38
37
|
write_client_manifest(config.kit, manifest_data, `${output}/client`);
|
|
39
38
|
write_server(config, output, root);
|
|
40
|
-
write_root(manifest_data, config, output);
|
|
41
39
|
write_all_types(config, manifest_data, root);
|
|
42
40
|
write_non_ambient(config.kit, manifest_data);
|
|
43
41
|
|
|
@@ -139,11 +139,6 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
|
|
|
139
139
|
write_if_changed(
|
|
140
140
|
`${output}/app.js`,
|
|
141
141
|
dedent`
|
|
142
|
-
// in dev, this makes Vite inject its client as this module's first dependency,
|
|
143
|
-
// so that global constant replacements are installed before any other module
|
|
144
|
-
// (including user hooks) evaluates. In build it's inert.
|
|
145
|
-
import.meta.hot;
|
|
146
|
-
|
|
147
142
|
${
|
|
148
143
|
client_hooks_file
|
|
149
144
|
? `import * as client_hooks from '${relative_path(output, client_hooks_file)}';`
|
|
@@ -181,8 +176,6 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
|
|
|
181
176
|
|
|
182
177
|
export const decode = (type, value) => decoders[type](value);
|
|
183
178
|
|
|
184
|
-
export { default as root } from '../root.js';
|
|
185
|
-
|
|
186
179
|
export const get_error_template = () => import('../shared/error-template.js').then(m => m.default);
|
|
187
180
|
`
|
|
188
181
|
);
|
|
@@ -209,7 +209,7 @@ function generate_app_types(manifest_data, config) {
|
|
|
209
209
|
if (route.params.length > 0) {
|
|
210
210
|
const params = route.params.map((p) => {
|
|
211
211
|
const type = get_matcher_type(p.matcher);
|
|
212
|
-
return `${p.name}${p.optional ? '?:' : ':'} ${type}${p.optional ? ' | undefined' : ''}`;
|
|
212
|
+
return `${/^\w+$/.test(p.name) ? p.name : `'${p.name}'`}${p.optional ? '?:' : ':'} ${type}${p.optional ? ' | undefined' : ''}`;
|
|
213
213
|
});
|
|
214
214
|
const route_type = `${s(route.id)}: { ${params.join('; ')} }`;
|
|
215
215
|
|
|
@@ -230,7 +230,7 @@ function generate_app_types(manifest_data, config) {
|
|
|
230
230
|
const params = Array.from(layout_params)
|
|
231
231
|
.map(([name, { optional, matchers }]) => {
|
|
232
232
|
const type = get_matchers_type(matchers);
|
|
233
|
-
return `${name}${optional ? '?:' : ':'} ${type}${optional ? ' | undefined' : ''}`;
|
|
233
|
+
return `${/^\w+$/.test(name) ? name : `'${name}'`}${optional ? '?:' : ':'} ${type}${optional ? ' | undefined' : ''}`;
|
|
234
234
|
})
|
|
235
235
|
.join('; ');
|
|
236
236
|
|
|
@@ -24,7 +24,6 @@ const server_template = ({
|
|
|
24
24
|
has_service_worker,
|
|
25
25
|
template
|
|
26
26
|
}) => `
|
|
27
|
-
import root from '../root.js';
|
|
28
27
|
import { set_building, set_prerendering } from '$app/env/internal';
|
|
29
28
|
import { set_assets } from '$app/paths/internal/server';
|
|
30
29
|
import { set_manifest, set_read_implementation } from '__sveltekit/server';
|
|
@@ -40,10 +39,8 @@ export const options = {
|
|
|
40
39
|
hooks: null, // added lazily, via \`get_hooks\`
|
|
41
40
|
link_header_preload: ${s(config.kit.output.linkHeaderPreload)},
|
|
42
41
|
paths_origin: ${s(config.kit.paths.origin)},
|
|
43
|
-
root,
|
|
44
42
|
service_worker: ${has_service_worker},
|
|
45
43
|
service_worker_options: ${config.kit.serviceWorker.register ? s(config.kit.serviceWorker.options) : 'null'},
|
|
46
|
-
server_error_boundaries: ${s(!!config.kit.experimental.handleRenderingErrors)},
|
|
47
44
|
templates: {
|
|
48
45
|
app: ({ head, body, assets, nonce, env }) => ${s(template)
|
|
49
46
|
.replace('%sveltekit.head%', '" + head + "')
|
|
@@ -2,6 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { styleText } from 'node:util';
|
|
4
4
|
import { posixify } from '../../utils/os.js';
|
|
5
|
+
import { read_package_imports, normalize_import_value } from '../../utils/imports.js';
|
|
5
6
|
import { write_if_changed } from './utils.js';
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -65,7 +66,7 @@ export function get_tsconfig(kit, cwd) {
|
|
|
65
66
|
config_relative('vite.config.js'),
|
|
66
67
|
config_relative('vite.config.ts')
|
|
67
68
|
]);
|
|
68
|
-
const src_includes = [kit.files.routes, kit.files.
|
|
69
|
+
const src_includes = [kit.files.routes, kit.files.src].filter((dir) => {
|
|
69
70
|
const relative = path.relative(kit.files.src, dir);
|
|
70
71
|
return !relative || relative.startsWith('..');
|
|
71
72
|
});
|
|
@@ -198,7 +199,7 @@ const alias_regex = /^(.+?)(\/\*)?$/;
|
|
|
198
199
|
const value_regex = /^(.*?)((\/\*)|(\.\w+))?$/;
|
|
199
200
|
|
|
200
201
|
/**
|
|
201
|
-
* Generates tsconfig path aliases from kit's aliases.
|
|
202
|
+
* Generates tsconfig path aliases from kit's aliases and the package.json `imports` field.
|
|
202
203
|
* Related to vite alias creation.
|
|
203
204
|
*
|
|
204
205
|
* @param {import('types').ValidatedKitConfig} config
|
|
@@ -215,8 +216,17 @@ function get_tsconfig_paths(config, cwd) {
|
|
|
215
216
|
};
|
|
216
217
|
|
|
217
218
|
const alias = { ...config.alias };
|
|
218
|
-
|
|
219
|
-
|
|
219
|
+
|
|
220
|
+
// Add all `#`-prefixed imports from package.json as path aliases
|
|
221
|
+
const imports = read_package_imports(cwd);
|
|
222
|
+
if (imports) {
|
|
223
|
+
for (const [key, raw_value] of Object.entries(imports)) {
|
|
224
|
+
if (!key.startsWith('#')) continue;
|
|
225
|
+
const value = normalize_import_value(raw_value);
|
|
226
|
+
if (value) {
|
|
227
|
+
alias[key] = value;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
220
230
|
}
|
|
221
231
|
|
|
222
232
|
/** @type {Record<string, string[]>} */
|
|
@@ -231,7 +231,9 @@ function update_types(config, routes, route, root, to_delete = new Set()) {
|
|
|
231
231
|
'type OptionalUnion<U extends Record<string, any>, A extends keyof U = U extends U ? keyof U : never> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;',
|
|
232
232
|
|
|
233
233
|
// Re-export `Snapshot` from @sveltejs/kit — in future we could use this to infer <T> from the return type of `snapshot.capture`
|
|
234
|
-
'export type Snapshot<T = any> = Kit.Snapshot<T>;'
|
|
234
|
+
'export type Snapshot<T = any> = Kit.Snapshot<T>;',
|
|
235
|
+
|
|
236
|
+
'export type ErrorProps = { error: App.Error };'
|
|
235
237
|
);
|
|
236
238
|
}
|
|
237
239
|
|
|
@@ -263,15 +265,8 @@ function update_types(config, routes, route, root, to_delete = new Set()) {
|
|
|
263
265
|
|
|
264
266
|
if (route.leaf.server) {
|
|
265
267
|
exports.push(
|
|
266
|
-
'export type Action<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Action<RouteParams, OutputData, RouteId>'
|
|
267
|
-
|
|
268
|
-
exports.push(
|
|
269
|
-
'export type Actions<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Actions<RouteParams, OutputData, RouteId>'
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
if (route.leaf.server) {
|
|
274
|
-
exports.push(
|
|
268
|
+
'export type Action<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Action<RouteParams, OutputData, RouteId>',
|
|
269
|
+
'export type Actions<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Actions<RouteParams, OutputData, RouteId>',
|
|
275
270
|
'export type PageProps = { params: RouteParams; data: PageData; form: ActionData }'
|
|
276
271
|
);
|
|
277
272
|
} else {
|
|
@@ -612,7 +607,7 @@ function generate_params_type(params, outdir, config) {
|
|
|
612
607
|
return `{ ${params
|
|
613
608
|
.map(
|
|
614
609
|
(param) =>
|
|
615
|
-
`${param.name}${param.optional ? '?' : ''}: ${
|
|
610
|
+
`${/^\w+$/.test(param.name) ? param.name : `'${param.name}'`}${param.optional ? '?' : ''}: ${
|
|
616
611
|
param.matcher
|
|
617
612
|
? `import('@sveltejs/kit').MatcherParam<(typeof import('${params_import}').params)[${JSON.stringify(param.matcher)}]>`
|
|
618
613
|
: 'string'
|
|
@@ -643,6 +638,16 @@ export function tweak_types(content, is_server) {
|
|
|
643
638
|
const code = new MagicString(content);
|
|
644
639
|
|
|
645
640
|
const exports = new Map();
|
|
641
|
+
/** @param {import('typescript').BindingName} name */
|
|
642
|
+
function add_export(name) {
|
|
643
|
+
if (ts.isIdentifier(name)) {
|
|
644
|
+
if (names.has(name.text)) exports.set(name.text, name.text);
|
|
645
|
+
} else {
|
|
646
|
+
for (const element of name.elements) {
|
|
647
|
+
if (ts.isBindingElement(element)) add_export(element.name);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
646
651
|
|
|
647
652
|
ast.forEachChild((node) => {
|
|
648
653
|
if (
|
|
@@ -669,9 +674,7 @@ export function tweak_types(content, is_server) {
|
|
|
669
674
|
|
|
670
675
|
if (ts.isVariableStatement(node)) {
|
|
671
676
|
node.declarationList.declarations.forEach((declaration) => {
|
|
672
|
-
|
|
673
|
-
exports.set(declaration.name.text, declaration.name.text);
|
|
674
|
-
}
|
|
677
|
+
add_export(declaration.name);
|
|
675
678
|
});
|
|
676
679
|
}
|
|
677
680
|
}
|
package/src/core/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ import { noop } from '../utils/functions.js';
|
|
|
7
7
|
import { posixify } from '../utils/os.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Resolved path of the `runtime` directory
|
|
10
|
+
* Resolved path of the `runtime` directory posix-ified
|
|
11
11
|
*
|
|
12
12
|
* TODO Windows issue:
|
|
13
13
|
* Vite or sth else somehow sets the driver letter inconsistently to lower or upper case depending on the run environment.
|
|
@@ -25,7 +25,7 @@ export const runtime_directory = posixify(fileURLToPath(new URL('../runtime', im
|
|
|
25
25
|
*/
|
|
26
26
|
export function get_runtime_base(root) {
|
|
27
27
|
return runtime_directory.startsWith(root)
|
|
28
|
-
? `/${path.relative(root, runtime_directory)}`
|
|
28
|
+
? `/${posixify(path.relative(root, runtime_directory))}`
|
|
29
29
|
: to_fs(runtime_directory);
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/** @import { Handle, RequestEvent, ResolveOptions } from '@sveltejs/kit' */
|
|
2
|
-
/** @import { MaybePromise } from 'types' */
|
|
3
2
|
import {
|
|
4
3
|
merge_tracing,
|
|
5
4
|
get_request_store,
|
|
@@ -74,6 +73,8 @@ import {
|
|
|
74
73
|
* first post-processing
|
|
75
74
|
* ```
|
|
76
75
|
*
|
|
76
|
+
* Calling `resolve` invokes the next handler in the sequence (or SvelteKit itself, if it is the last one). To pass data between handlers, use `event.locals`.
|
|
77
|
+
*
|
|
77
78
|
* @param {...Handle} handlers The chain of `handle` functions
|
|
78
79
|
* @returns {Handle}
|
|
79
80
|
*/
|
|
@@ -89,7 +90,7 @@ export function sequence(...handlers) {
|
|
|
89
90
|
* @param {number} i
|
|
90
91
|
* @param {RequestEvent} event
|
|
91
92
|
* @param {ResolveOptions | undefined} parent_options
|
|
92
|
-
* @returns {
|
|
93
|
+
* @returns {Promise<Response>}
|
|
93
94
|
*/
|
|
94
95
|
function apply_handle(i, event, parent_options) {
|
|
95
96
|
const handle = handlers[i];
|
package/src/exports/index.js
CHANGED
|
@@ -234,7 +234,7 @@ export function isActionFailure(e) {
|
|
|
234
234
|
* ```ts
|
|
235
235
|
* import { invalid } from '@sveltejs/kit';
|
|
236
236
|
* import { form } from '$app/server';
|
|
237
|
-
* import { tryLogin } from '
|
|
237
|
+
* import { tryLogin } from '#lib/server/auth';
|
|
238
238
|
* import * as v from 'valibot';
|
|
239
239
|
*
|
|
240
240
|
* export const login = form(
|
|
@@ -119,11 +119,9 @@ function get_raw_body(req, body_size_limit) {
|
|
|
119
119
|
* base: string;
|
|
120
120
|
* bodySizeLimit?: number;
|
|
121
121
|
* }} options
|
|
122
|
-
* @returns {
|
|
122
|
+
* @returns {Request}
|
|
123
123
|
*/
|
|
124
|
-
|
|
125
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
126
|
-
export async function getRequest({ request, base, bodySizeLimit }) {
|
|
124
|
+
export function getRequest({ request, base, bodySizeLimit }) {
|
|
127
125
|
let headers = /** @type {Record<string, string>} */ (request.headers);
|
|
128
126
|
if (request.httpVersionMajor >= 2) {
|
|
129
127
|
// the Request constructor rejects headers with ':' in the name
|
|
@@ -205,11 +203,9 @@ function drain_request(res) {
|
|
|
205
203
|
/**
|
|
206
204
|
* @param {import('http').ServerResponse} res
|
|
207
205
|
* @param {Response} response
|
|
208
|
-
* @returns {
|
|
206
|
+
* @returns {void}
|
|
209
207
|
*/
|
|
210
|
-
|
|
211
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
212
|
-
export async function setResponse(res, response) {
|
|
208
|
+
export function setResponse(res, response) {
|
|
213
209
|
res.once('finish', () => drain_request(res));
|
|
214
210
|
res.once('close', () => drain_request(res));
|
|
215
211
|
|
package/src/exports/public.d.ts
CHANGED
|
@@ -157,7 +157,8 @@ export interface Builder {
|
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
159
|
* Generate a server-side manifest to initialise the SvelteKit [server](https://svelte.dev/docs/kit/@sveltejs-kit#Server) with.
|
|
160
|
-
* @param opts
|
|
160
|
+
* @param opts
|
|
161
|
+
* @param opts.relativePath A relative path to the base directory of the server build output
|
|
161
162
|
*/
|
|
162
163
|
generateManifest: (opts: { relativePath: string; routes?: RouteDefinition[] }) => string;
|
|
163
164
|
|
|
@@ -434,8 +435,6 @@ export interface KitConfig {
|
|
|
434
435
|
*
|
|
435
436
|
* > [!NOTE] When `mode` is `'auto'`, SvelteKit will use nonces for dynamically rendered pages and hashes for prerendered pages. Using nonces with prerendered pages is insecure and therefore forbidden.
|
|
436
437
|
*
|
|
437
|
-
* > [!NOTE] Note that most [Svelte transitions](https://svelte.dev/tutorial/svelte/transition) work by creating an inline `<style>` element. If you use these in your app, you must either leave the `style-src` directive unspecified or add `unsafe-inline`.
|
|
438
|
-
*
|
|
439
438
|
* If this level of configuration is insufficient and you have more dynamic requirements, you can use the [`handle` hook](https://svelte.dev/docs/kit/hooks#Server-hooks-handle) to roll your own CSP.
|
|
440
439
|
*/
|
|
441
440
|
csp?: {
|
|
@@ -509,15 +508,6 @@ export interface KitConfig {
|
|
|
509
508
|
* @default false
|
|
510
509
|
*/
|
|
511
510
|
forkPreloads?: boolean;
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* Whether to enable the experimental handling of rendering errors.
|
|
515
|
-
* When enabled, `<svelte:boundary>` is used to wrap components at each level
|
|
516
|
-
* where there's an `+error.svelte`, rendering the error page if the component fails.
|
|
517
|
-
* In addition, error boundaries also work on the server and the error object goes through `handleError`.
|
|
518
|
-
* @default false
|
|
519
|
-
*/
|
|
520
|
-
handleRenderingErrors?: boolean;
|
|
521
511
|
};
|
|
522
512
|
/**
|
|
523
513
|
* Where to find various files within your project.
|
|
@@ -558,12 +548,6 @@ export interface KitConfig {
|
|
|
558
548
|
*/
|
|
559
549
|
universal?: string;
|
|
560
550
|
};
|
|
561
|
-
/**
|
|
562
|
-
* Your app's internal library, accessible throughout the codebase as `$lib`.
|
|
563
|
-
* @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
|
|
564
|
-
* @default "src/lib"
|
|
565
|
-
*/
|
|
566
|
-
lib?: string;
|
|
567
551
|
/**
|
|
568
552
|
* A directory containing [parameter matchers](https://svelte.dev/docs/kit/advanced-routing#Matching).
|
|
569
553
|
* @deprecated this feature is still supported, but it's generally recommended to use [monorepos](https://levelup.video/tutorials/monorepos-with-pnpm) instead
|
|
@@ -970,7 +954,7 @@ export interface KitConfig {
|
|
|
970
954
|
*/
|
|
971
955
|
export type Handle = (input: {
|
|
972
956
|
event: RequestEvent;
|
|
973
|
-
resolve: (event: RequestEvent, opts?: ResolveOptions) =>
|
|
957
|
+
resolve: (event: RequestEvent, opts?: ResolveOptions) => Promise<Response>;
|
|
974
958
|
}) => MaybePromise<Response>;
|
|
975
959
|
|
|
976
960
|
/**
|
|
@@ -1439,7 +1423,7 @@ export interface Page<
|
|
|
1439
1423
|
/**
|
|
1440
1424
|
* The URL of the current page.
|
|
1441
1425
|
*/
|
|
1442
|
-
url:
|
|
1426
|
+
url: ReadonlyURL & { readonly pathname: ResolvedPathname | (string & {}) };
|
|
1443
1427
|
/**
|
|
1444
1428
|
* The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
1445
1429
|
*/
|
|
@@ -1742,7 +1726,9 @@ export interface ResolveOptions {
|
|
|
1742
1726
|
*/
|
|
1743
1727
|
filterSerializedResponseHeaders?: (name: string, value: string) => boolean;
|
|
1744
1728
|
/**
|
|
1745
|
-
* Determines
|
|
1729
|
+
* Determines which files should be preloaded. Files are preloaded via `<link>` tags added to the
|
|
1730
|
+
* `<head>` tag; if `output.linkHeaderPreload` is enabled, dynamically rendered pages use the
|
|
1731
|
+
* [`Link` response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) instead.
|
|
1746
1732
|
* By default, `js` and `css` files will be preloaded.
|
|
1747
1733
|
* @param input the type of the file and its path
|
|
1748
1734
|
*/
|
|
@@ -1777,19 +1763,24 @@ export interface ServerInitOptions {
|
|
|
1777
1763
|
read?: (file: string) => MaybePromise<ReadableStream | null>;
|
|
1778
1764
|
}
|
|
1779
1765
|
|
|
1766
|
+
/**
|
|
1767
|
+
* Information required to instantiate a new `Server` instance.
|
|
1768
|
+
*/
|
|
1780
1769
|
export interface SSRManifest {
|
|
1770
|
+
/** The directory where SvelteKit keeps its stuff, including static assets (such as JS and CSS) and internally-used routes. */
|
|
1781
1771
|
appDir: string;
|
|
1772
|
+
/** The `base` and `appDir` settings combined without a leading slash. */
|
|
1782
1773
|
appPath: string;
|
|
1783
1774
|
/** Static files from `config.files.assets` and the service worker (if any). */
|
|
1784
1775
|
assets: Set<string>;
|
|
1785
1776
|
mimeTypes: Record<string, string>;
|
|
1786
1777
|
|
|
1787
|
-
/** private fields */
|
|
1778
|
+
/** @internal private fields */
|
|
1788
1779
|
_: {
|
|
1789
1780
|
client: BuildData['client'];
|
|
1790
1781
|
nodes: SSRNodeLoader[];
|
|
1791
1782
|
/** hashed filename -> import to that file */
|
|
1792
|
-
remotes: Record<string, () => Promise<any>>;
|
|
1783
|
+
remotes: Record<string, () => Promise<{ default: Record<string, any> }>>;
|
|
1793
1784
|
routes: SSRRoute[];
|
|
1794
1785
|
prerendered_routes: Set<string>;
|
|
1795
1786
|
matchers: () => Promise<Record<string, ParamMatcher>>;
|
|
@@ -1980,6 +1971,14 @@ export interface Snapshot<T = any> {
|
|
|
1980
1971
|
restore: (snapshot: T) => void;
|
|
1981
1972
|
}
|
|
1982
1973
|
|
|
1974
|
+
export type ReadonlyURLSearchParams = Omit<URLSearchParams, 'set' | 'append' | 'delete' | 'sort'>;
|
|
1975
|
+
|
|
1976
|
+
export type ReadonlyURL = Readonly<
|
|
1977
|
+
Omit<URL, 'searchParams'> & {
|
|
1978
|
+
searchParams: ReadonlyURLSearchParams;
|
|
1979
|
+
}
|
|
1980
|
+
>;
|
|
1981
|
+
|
|
1983
1982
|
// If T is unknown or has an index signature, the types below will recurse indefinitely and create giant unions that TS can't handle
|
|
1984
1983
|
type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
|
|
1985
1984
|
|
|
@@ -407,10 +407,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes, root) {
|
|
|
407
407
|
dev: true,
|
|
408
408
|
etag: true,
|
|
409
409
|
maxAge: 0,
|
|
410
|
-
extensions: []
|
|
411
|
-
setHeaders: (res) => {
|
|
412
|
-
res.setHeader('access-control-allow-origin', '*');
|
|
413
|
-
}
|
|
410
|
+
extensions: []
|
|
414
411
|
});
|
|
415
412
|
|
|
416
413
|
vite.middlewares.use((req, res, next) => {
|
|
@@ -528,7 +525,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes, root) {
|
|
|
528
525
|
read: (file) => createReadableStream(from_fs(file))
|
|
529
526
|
});
|
|
530
527
|
|
|
531
|
-
const request =
|
|
528
|
+
const request = getRequest({
|
|
532
529
|
base,
|
|
533
530
|
request: req
|
|
534
531
|
});
|
|
@@ -579,10 +576,10 @@ export async function dev(vite, vite_config, svelte_config, get_remotes, root) {
|
|
|
579
576
|
if (rendered.status === 404) {
|
|
580
577
|
// @ts-expect-error
|
|
581
578
|
serve_static_middleware.handle(req, res, () => {
|
|
582
|
-
|
|
579
|
+
setResponse(res, rendered);
|
|
583
580
|
});
|
|
584
581
|
} else {
|
|
585
|
-
|
|
582
|
+
setResponse(res, rendered);
|
|
586
583
|
}
|
|
587
584
|
} catch (e) {
|
|
588
585
|
const error = coalesce_to_error(e);
|