@sveltejs/kit 3.0.0-next.6 → 3.0.0-next.7
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 +7 -2
- package/src/core/adapt/builder.js +11 -39
- package/src/core/config/index.js +76 -71
- package/src/core/config/options.js +280 -285
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +85 -1
- package/src/core/generate_manifest/index.js +12 -15
- package/src/core/sync/create_manifest_data/index.js +6 -44
- package/src/core/sync/write_client_manifest.js +7 -14
- package/src/core/sync/write_non_ambient.js +10 -7
- package/src/core/sync/write_root.js +9 -30
- package/src/core/sync/write_server.js +0 -1
- package/src/core/sync/write_types/index.js +11 -10
- package/src/exports/index.js +3 -3
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/index.js +1 -91
- package/src/exports/internal/{event.js → server/event.js} +1 -2
- package/src/exports/internal/server/index.js +33 -0
- package/src/exports/internal/shared.js +89 -0
- package/src/exports/node/index.js +1 -1
- package/src/exports/params.js +63 -0
- package/src/exports/public.d.ts +82 -32
- package/src/exports/url.js +84 -0
- package/src/exports/vite/dev/index.js +28 -17
- package/src/exports/vite/index.js +217 -156
- package/src/exports/vite/preview/index.js +1 -1
- package/src/exports/vite/utils.js +3 -5
- package/src/runtime/app/paths/client.js +3 -7
- package/src/runtime/app/paths/server.js +1 -1
- package/src/runtime/app/server/remote/query.js +6 -12
- package/src/runtime/app/state/client.js +1 -2
- package/src/runtime/app/stores.js +13 -76
- package/src/runtime/client/client.js +26 -79
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/form.svelte.js +5 -24
- package/src/runtime/client/remote-functions/prerender.svelte.js +10 -3
- package/src/runtime/client/remote-functions/query/instance.svelte.js +18 -9
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +16 -6
- package/src/runtime/client/remote-functions/shared.svelte.js +1 -2
- package/src/runtime/client/state.svelte.js +66 -49
- package/src/runtime/client/types.d.ts +1 -1
- package/src/runtime/client/utils.js +0 -96
- package/src/runtime/form-utils.js +15 -2
- package/src/runtime/server/index.js +1 -1
- package/src/runtime/server/page/load_data.js +1 -1
- package/src/runtime/server/page/render.js +15 -24
- package/src/runtime/server/page/server_routing.js +13 -9
- package/src/runtime/server/remote.js +21 -12
- package/src/runtime/server/respond.js +11 -8
- package/src/runtime/telemetry/otel.js +1 -1
- package/src/types/ambient.d.ts +5 -1
- package/src/types/global-private.d.ts +1 -1
- package/src/types/internal.d.ts +9 -10
- package/src/utils/error.js +1 -1
- package/src/utils/mime.js +9 -0
- package/src/utils/params.js +66 -0
- package/src/utils/routing.js +84 -38
- package/src/utils/streaming.js +14 -4
- package/src/utils/url.js +0 -79
- package/src/version.js +1 -1
- package/types/index.d.ts +98 -87
- package/types/index.d.ts.map +10 -7
- package/src/exports/internal/server.js +0 -22
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
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.7",
|
|
4
4
|
"description": "SvelteKit is the fastest way to build Svelte apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"svelte": "^5.56.3",
|
|
41
41
|
"svelte-preprocess": "^6.0.5",
|
|
42
42
|
"typescript": "~6.0.3",
|
|
43
|
+
"valibot": "^1.2.0",
|
|
43
44
|
"vite": "^8.0.16",
|
|
44
45
|
"vitest": "^4.1.9"
|
|
45
46
|
},
|
|
@@ -77,6 +78,10 @@
|
|
|
77
78
|
"#app/env/public": {
|
|
78
79
|
"browser": "./src/runtime/app/env/public/client.js",
|
|
79
80
|
"default": "./src/runtime/app/env/public/server.js"
|
|
81
|
+
},
|
|
82
|
+
"#internal": {
|
|
83
|
+
"browser": "./src/exports/internal/client.js",
|
|
84
|
+
"default": "./src/exports/internal/server/index.js"
|
|
80
85
|
}
|
|
81
86
|
},
|
|
82
87
|
"exports": {
|
|
@@ -98,7 +103,7 @@
|
|
|
98
103
|
},
|
|
99
104
|
"./internal/server": {
|
|
100
105
|
"types": "./types/index.d.ts",
|
|
101
|
-
"import": "./src/exports/internal/server.js"
|
|
106
|
+
"import": "./src/exports/internal/server/index.js"
|
|
102
107
|
},
|
|
103
108
|
"./node": {
|
|
104
109
|
"types": "./types/index.d.ts",
|
|
@@ -18,7 +18,7 @@ import generate_fallback from '../postbuild/fallback.js';
|
|
|
18
18
|
import { write } from '../sync/utils.js';
|
|
19
19
|
import { list_files } from '../utils.js';
|
|
20
20
|
import { find_server_assets } from '../generate_manifest/find_server_assets.js';
|
|
21
|
-
import {
|
|
21
|
+
import { create_exported_declarations } from '../env.js';
|
|
22
22
|
import { handle_issues, validate } from '../../exports/internal/env.js';
|
|
23
23
|
|
|
24
24
|
const pipe = promisify(pipeline);
|
|
@@ -305,53 +305,25 @@ async function compress_file(file, format = 'gz') {
|
|
|
305
305
|
* - Imports `exports` from the entrypoint (dynamically, if `tla` is true)
|
|
306
306
|
* - Re-exports `exports` from the entrypoint
|
|
307
307
|
*
|
|
308
|
-
* `default` receives special treatment: It will be imported as `default` and exported with `export default`.
|
|
309
|
-
*
|
|
310
308
|
* @param {{ instrumentation: string; start: string; exports: string[] }} opts
|
|
311
309
|
* @returns {string}
|
|
312
310
|
*/
|
|
313
311
|
function create_instrumentation_facade({ instrumentation, start, exports }) {
|
|
314
312
|
const import_instrumentation = `import './${instrumentation}';`;
|
|
315
313
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
* you can do evil things like `export { c as class }`.
|
|
322
|
-
* in order to import these, you need to alias them, and then un-alias them when re-exporting
|
|
323
|
-
* this map will allow us to generate the following:
|
|
324
|
-
* import { class as _1 } from 'entrypoint';
|
|
325
|
-
* export { _1 as class };
|
|
326
|
-
*/
|
|
327
|
-
let alias = `_${alias_index++}`;
|
|
328
|
-
while (exports.includes(alias)) {
|
|
329
|
-
alias = `_${alias_index++}`;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
aliases.set(name, alias);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
const import_statements = [];
|
|
336
|
-
const export_statements = [];
|
|
337
|
-
|
|
338
|
-
for (const name of exports) {
|
|
339
|
-
const alias = aliases.get(name);
|
|
340
|
-
if (alias) {
|
|
341
|
-
import_statements.push(`${name}: ${alias}`);
|
|
342
|
-
export_statements.push(`${alias} as ${name}`);
|
|
343
|
-
} else {
|
|
344
|
-
import_statements.push(`${name}`);
|
|
345
|
-
export_statements.push(`${name}`);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
314
|
+
const { namespace, declarations, reexports } = create_exported_declarations(
|
|
315
|
+
exports,
|
|
316
|
+
(name, ns) => `${ns}.${name}`,
|
|
317
|
+
'__mod'
|
|
318
|
+
);
|
|
348
319
|
|
|
349
|
-
const
|
|
350
|
-
`const
|
|
351
|
-
|
|
320
|
+
const parts = [
|
|
321
|
+
`const ${namespace} = await import('./${start}');`,
|
|
322
|
+
declarations.join('\n'),
|
|
323
|
+
reexports.length > 0 ? `export { ${reexports.join(', ')} };` : ''
|
|
352
324
|
]
|
|
353
325
|
.filter(Boolean)
|
|
354
326
|
.join('\n');
|
|
355
327
|
|
|
356
|
-
return `${import_instrumentation}\n${
|
|
328
|
+
return `${import_instrumentation}\n${parts}`;
|
|
357
329
|
}
|
package/src/core/config/index.js
CHANGED
|
@@ -6,7 +6,12 @@ import fs from 'node:fs';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import process from 'node:process';
|
|
8
8
|
import * as url from 'node:url';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
validate_kit_options,
|
|
11
|
+
kit_options,
|
|
12
|
+
kit_experimental_options,
|
|
13
|
+
validate_svelte_options
|
|
14
|
+
} from './options.js';
|
|
10
15
|
import { resolve_entry } from '../../utils/filesystem.js';
|
|
11
16
|
import { import_peer } from '../../utils/import.js';
|
|
12
17
|
|
|
@@ -128,99 +133,99 @@ export async function load_vite_config(config) {
|
|
|
128
133
|
*/
|
|
129
134
|
export function extract_svelte_config(vite_config) {
|
|
130
135
|
const plugin = vite_config.plugins.find((p) => p.name === 'vite-plugin-sveltekit-setup');
|
|
131
|
-
return plugin?.api.options ?? process_config({});
|
|
136
|
+
return plugin?.api.options ?? process_config(validate_config({}), vite_config.root);
|
|
132
137
|
}
|
|
133
138
|
|
|
134
139
|
/**
|
|
135
|
-
* @param {
|
|
140
|
+
* @param {ValidatedConfig} config
|
|
141
|
+
* @param {string} cwd
|
|
136
142
|
* @returns {ValidatedConfig}
|
|
137
143
|
*/
|
|
138
|
-
export function process_config(config,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
validated.kit.files.hooks.universal = path.resolve(
|
|
150
|
-
cwd,
|
|
151
|
-
validated.kit.files.hooks.universal
|
|
152
|
-
);
|
|
153
|
-
} else {
|
|
154
|
-
// @ts-expect-error
|
|
155
|
-
validated.kit.files[key] = path.resolve(cwd, validated.kit.files[key]);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
144
|
+
export function process_config(config, cwd) {
|
|
145
|
+
if (
|
|
146
|
+
config.kit.csp?.directives?.['require-trusted-types-for']?.includes('script') &&
|
|
147
|
+
config.kit.serviceWorker.register &&
|
|
148
|
+
resolve_entry(path.resolve(cwd, config.kit.files.serviceWorker)) &&
|
|
149
|
+
!config.kit.csp?.directives?.['trusted-types']?.includes('sveltekit-trusted-url')
|
|
150
|
+
) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
"The `csp.directives['trusted-types']` option must include 'sveltekit-trusted-url' when `serviceWorker.register` is true"
|
|
153
|
+
);
|
|
154
|
+
}
|
|
158
155
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const error = /** @type {Error} */ (e);
|
|
156
|
+
config.kit.outDir = path.resolve(cwd, config.kit.outDir);
|
|
157
|
+
config.kit.env.dir = path.resolve(cwd, config.kit.env.dir);
|
|
162
158
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
for (const key in config.kit.files) {
|
|
160
|
+
if (key === 'hooks') {
|
|
161
|
+
config.kit.files.hooks.client = path.resolve(cwd, config.kit.files.hooks.client);
|
|
162
|
+
config.kit.files.hooks.server = path.resolve(cwd, config.kit.files.hooks.server);
|
|
163
|
+
config.kit.files.hooks.universal = path.resolve(cwd, config.kit.files.hooks.universal);
|
|
164
|
+
} else {
|
|
165
|
+
// @ts-expect-error
|
|
166
|
+
config.kit.files[key] = path.resolve(cwd, config.kit.files[key]);
|
|
167
|
+
}
|
|
166
168
|
}
|
|
169
|
+
|
|
170
|
+
return config;
|
|
167
171
|
}
|
|
168
172
|
|
|
169
173
|
/**
|
|
170
174
|
* @param {Config} config
|
|
171
|
-
* @param {string} [cwd]
|
|
172
175
|
* @returns {ValidatedConfig}
|
|
173
176
|
*/
|
|
174
|
-
export function validate_config(config
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
'The SvelteKit options from the Vite config must be an object. See https://svelte.dev/docs/kit/configuration'
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/** @type {ValidatedConfig} */
|
|
182
|
-
const validated = options(config, 'config');
|
|
183
|
-
const files = validated.kit.files;
|
|
184
|
-
|
|
185
|
-
files.hooks.client ??= path.join(files.src, 'hooks.client');
|
|
186
|
-
files.hooks.server ??= path.join(files.src, 'hooks.server');
|
|
187
|
-
files.hooks.universal ??= path.join(files.src, 'hooks');
|
|
188
|
-
files.lib ??= path.join(files.src, 'lib');
|
|
189
|
-
files.params ??= path.join(files.src, 'params');
|
|
190
|
-
files.routes ??= path.join(files.src, 'routes');
|
|
191
|
-
files.serviceWorker ??= path.join(files.src, 'service-worker');
|
|
192
|
-
files.appTemplate ??= path.join(files.src, 'app.html');
|
|
193
|
-
files.errorTemplate ??= path.join(files.src, 'error.html');
|
|
194
|
-
|
|
195
|
-
if (validated.kit.router.resolution === 'server') {
|
|
196
|
-
if (validated.kit.router.type === 'hash') {
|
|
197
|
-
throw new Error(
|
|
198
|
-
"The `router.resolution` option cannot be 'server' if `router.type` is 'hash'"
|
|
199
|
-
);
|
|
200
|
-
}
|
|
201
|
-
if (validated.kit.output.bundleStrategy !== 'split') {
|
|
177
|
+
export function validate_config(config) {
|
|
178
|
+
try {
|
|
179
|
+
if (typeof config !== 'object') {
|
|
202
180
|
throw new Error(
|
|
203
|
-
|
|
181
|
+
'The SvelteKit options from the Vite config must be an object. See https://svelte.dev/docs/kit/configuration'
|
|
204
182
|
);
|
|
205
183
|
}
|
|
206
|
-
}
|
|
207
184
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
185
|
+
const validated = /** @type {ValidatedConfig} */ ({
|
|
186
|
+
...validate_svelte_options(config, 'config'),
|
|
187
|
+
kit: validate_kit_options(config.kit, 'config')
|
|
188
|
+
});
|
|
189
|
+
const files = validated.kit.files;
|
|
190
|
+
|
|
191
|
+
files.hooks.client ??= path.join(files.src, 'hooks.client');
|
|
192
|
+
files.hooks.server ??= path.join(files.src, 'hooks.server');
|
|
193
|
+
files.hooks.universal ??= path.join(files.src, 'hooks');
|
|
194
|
+
files.lib ??= path.join(files.src, 'lib');
|
|
195
|
+
files.params ??= path.join(files.src, 'params');
|
|
196
|
+
files.routes ??= path.join(files.src, 'routes');
|
|
197
|
+
files.serviceWorker ??= path.join(files.src, 'service-worker');
|
|
198
|
+
files.appTemplate ??= path.join(files.src, 'app.html');
|
|
199
|
+
files.errorTemplate ??= path.join(files.src, 'error.html');
|
|
200
|
+
|
|
201
|
+
if (validated.kit.router.resolution === 'server') {
|
|
202
|
+
if (validated.kit.router.type === 'hash') {
|
|
203
|
+
throw new Error(
|
|
204
|
+
"The `router.resolution` option cannot be 'server' if `router.type` is 'hash'"
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
if (validated.kit.output.bundleStrategy !== 'split') {
|
|
208
|
+
throw new Error(
|
|
209
|
+
"The `router.resolution` option cannot be 'server' if `output.bundleStrategy` is 'inline' or 'single'"
|
|
210
|
+
);
|
|
211
|
+
}
|
|
213
212
|
}
|
|
213
|
+
|
|
214
214
|
if (
|
|
215
|
-
validated.kit.
|
|
216
|
-
|
|
217
|
-
!validated.kit.csp?.directives?.['trusted-types']?.includes('sveltekit-trusted-url')
|
|
215
|
+
validated.kit.csp?.directives?.['require-trusted-types-for']?.includes('script') &&
|
|
216
|
+
!validated.kit.csp?.directives?.['trusted-types']?.includes('svelte-trusted-html')
|
|
218
217
|
) {
|
|
219
218
|
throw new Error(
|
|
220
|
-
"The `csp.directives['trusted-types']` option must include '
|
|
219
|
+
"The `csp.directives['trusted-types']` option must include 'svelte-trusted-html'"
|
|
221
220
|
);
|
|
222
221
|
}
|
|
223
|
-
}
|
|
224
222
|
|
|
225
|
-
|
|
223
|
+
return validated;
|
|
224
|
+
} catch (e) {
|
|
225
|
+
const error = /** @type {Error} */ (e);
|
|
226
|
+
|
|
227
|
+
// redact the stack trace — it's not helpful to users
|
|
228
|
+
error.stack = `Error loading SvelteKit options from Vite config: ${error.message}\n`;
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
226
231
|
}
|