@sveltejs/kit 3.0.0-next.1 → 3.0.0-next.10
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 +33 -21
- package/src/core/adapt/builder.js +29 -43
- package/src/core/adapt/index.js +1 -4
- package/src/core/config/index.js +132 -71
- package/src/core/config/options.js +294 -244
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +121 -5
- package/src/core/generate_manifest/index.js +12 -15
- package/src/core/postbuild/analyse.js +7 -19
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/prerender.js +42 -23
- package/src/core/sync/create_manifest_data/index.js +53 -50
- package/src/core/sync/sync.js +0 -2
- package/src/core/sync/write_client_manifest.js +8 -15
- package/src/core/sync/write_env.js +2 -1
- package/src/core/sync/write_non_ambient.js +12 -9
- package/src/core/sync/write_server.js +13 -14
- package/src/core/sync/write_tsconfig.js +16 -8
- package/src/core/sync/write_tsconfig_test/package.json +7 -0
- package/src/core/sync/write_types/index.js +28 -24
- package/src/core/utils.js +2 -2
- package/src/exports/env/index.js +12 -0
- package/src/exports/hooks/index.js +3 -9
- package/src/exports/hooks/sequence.js +3 -2
- package/src/exports/index.js +35 -13
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +2 -2
- package/src/exports/internal/index.js +1 -90
- 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 +62 -15
- package/src/exports/params.js +63 -0
- package/src/exports/public.d.ts +323 -170
- package/src/exports/url.js +86 -0
- package/src/exports/vite/build/build_server.js +53 -59
- package/src/exports/vite/build/remote.js +18 -11
- package/src/exports/vite/build/utils.js +0 -8
- package/src/exports/vite/dev/index.js +42 -44
- package/src/exports/vite/index.js +810 -593
- package/src/exports/vite/preview/index.js +29 -22
- package/src/exports/vite/static_analysis/index.js +2 -4
- package/src/exports/vite/static_analysis/types.d.ts +14 -0
- package/src/exports/vite/utils.js +21 -36
- package/src/runtime/app/env/internal.js +4 -4
- package/src/runtime/app/env/types.d.ts +1 -1
- package/src/runtime/app/environment/index.js +3 -3
- package/src/runtime/app/forms.js +24 -7
- package/src/runtime/app/paths/client.js +4 -10
- 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/public.d.ts +0 -28
- package/src/runtime/app/paths/server.js +9 -5
- package/src/runtime/app/server/remote/command.js +0 -3
- package/src/runtime/app/server/remote/form.js +27 -15
- package/src/runtime/app/server/remote/prerender.js +29 -36
- package/src/runtime/app/server/remote/query.js +101 -99
- package/src/runtime/app/server/remote/requested.js +22 -14
- package/src/runtime/app/server/remote/shared.js +30 -26
- package/src/runtime/app/state/client.js +1 -2
- package/src/runtime/app/stores.js +13 -76
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client-entry.js +3 -0
- package/src/runtime/client/client.js +411 -318
- package/src/runtime/client/entry.js +24 -3
- package/src/runtime/client/fetcher.js +3 -2
- package/src/runtime/client/ndjson.js +6 -33
- package/src/runtime/client/payload.js +17 -0
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/command.svelte.js +7 -32
- package/src/runtime/client/remote-functions/form.svelte.js +183 -112
- package/src/runtime/client/remote-functions/prerender.svelte.js +29 -8
- package/src/runtime/client/remote-functions/query/index.js +7 -14
- package/src/runtime/client/remote-functions/query/instance.svelte.js +63 -18
- package/src/runtime/client/remote-functions/query/proxy.js +3 -3
- package/src/runtime/client/remote-functions/query-batch.svelte.js +60 -68
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +60 -18
- package/src/runtime/client/remote-functions/query-live/iterator.js +36 -55
- package/src/runtime/client/remote-functions/shared.svelte.js +88 -62
- package/src/runtime/client/sse.js +32 -0
- package/src/runtime/client/state.svelte.js +65 -49
- package/src/runtime/client/stream.js +38 -0
- package/src/runtime/client/types.d.ts +11 -7
- package/src/runtime/client/utils.js +0 -96
- 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 +100 -22
- package/src/runtime/server/cookie.js +69 -52
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +14 -18
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/index.js +2 -2
- package/src/runtime/server/page/actions.js +41 -26
- package/src/runtime/server/page/index.js +9 -15
- package/src/runtime/server/page/load_data.js +1 -1
- package/src/runtime/server/page/render.js +112 -187
- package/src/runtime/server/page/respond_with_error.js +7 -8
- package/src/runtime/server/page/server_routing.js +27 -18
- package/src/runtime/server/remote.js +355 -216
- package/src/runtime/server/respond.js +97 -61
- package/src/runtime/server/utils.js +32 -9
- package/src/runtime/shared.js +83 -13
- package/src/runtime/telemetry/otel.js +1 -1
- package/src/runtime/types.d.ts +8 -0
- package/src/types/ambient.d.ts +10 -5
- package/src/types/global-private.d.ts +15 -22
- package/src/types/internal.d.ts +89 -74
- package/src/types/private.d.ts +33 -1
- package/src/utils/error.js +24 -4
- package/src/utils/import.js +6 -1
- package/src/utils/imports.js +83 -0
- package/src/utils/mime.js +9 -0
- package/src/utils/params.js +66 -0
- package/src/utils/routing.js +90 -44
- package/src/utils/shared-iterator.js +5 -0
- package/src/utils/streaming.js +14 -4
- package/src/utils/url.js +20 -2
- package/src/version.js +1 -1
- package/types/index.d.ts +467 -537
- package/types/index.d.ts.map +22 -39
- package/src/core/sync/write_root.js +0 -148
- package/src/exports/internal/server.js +0 -22
- package/src/types/synthetic/$lib.md +0 -5
- /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.10",
|
|
4
4
|
"description": "SvelteKit is the fastest way to build Svelte apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -18,37 +18,38 @@
|
|
|
18
18
|
"homepage": "https://svelte.dev",
|
|
19
19
|
"type": "module",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@standard-schema/spec": "^1.
|
|
22
|
-
"@sveltejs/acorn-typescript": "^1.0.
|
|
23
|
-
"acorn": "^8.
|
|
24
|
-
"cookie": "^
|
|
21
|
+
"@standard-schema/spec": "^1.1.0",
|
|
22
|
+
"@sveltejs/acorn-typescript": "^1.0.10",
|
|
23
|
+
"acorn": "^8.17.0",
|
|
24
|
+
"cookie": "^2.0.0",
|
|
25
25
|
"devalue": "^5.8.1",
|
|
26
26
|
"esm-env": "^1.2.2",
|
|
27
|
-
"magic-string": "^0.30.
|
|
27
|
+
"magic-string": "^0.30.21",
|
|
28
28
|
"mrmime": "^2.0.0",
|
|
29
|
-
"sirv": "^3.0.
|
|
29
|
+
"sirv": "^3.0.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@opentelemetry/api": "^1.
|
|
33
|
-
"@playwright/test": "^1.
|
|
32
|
+
"@opentelemetry/api": "^1.9.0",
|
|
33
|
+
"@playwright/test": "^1.61.1",
|
|
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.3",
|
|
38
38
|
"jsdom": "^29.1.1",
|
|
39
|
-
"rolldown": "^1.
|
|
40
|
-
"svelte": "^5.
|
|
39
|
+
"rolldown": "^1.2.0",
|
|
40
|
+
"svelte": "^5.56.3",
|
|
41
41
|
"svelte-preprocess": "^6.0.5",
|
|
42
|
-
"typescript": "~6.0.
|
|
43
|
-
"
|
|
44
|
-
"
|
|
42
|
+
"typescript": "~6.0.3",
|
|
43
|
+
"valibot": "^1.2.0",
|
|
44
|
+
"vite": "^8.1.5",
|
|
45
|
+
"vitest": "^4.1.10"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
|
-
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
48
48
|
"@opentelemetry/api": "^1.0.0",
|
|
49
|
-
"svelte": "^
|
|
49
|
+
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
50
|
+
"svelte": "^5.56.4",
|
|
50
51
|
"typescript": "^6.0.0",
|
|
51
|
-
"vite": "^8.0.
|
|
52
|
+
"vite": "^8.0.12"
|
|
52
53
|
},
|
|
53
54
|
"peerDependenciesMeta": {
|
|
54
55
|
"@opentelemetry/api": {
|
|
@@ -71,12 +72,19 @@
|
|
|
71
72
|
],
|
|
72
73
|
"imports": {
|
|
73
74
|
"#app/paths": {
|
|
75
|
+
"workerd": "./src/runtime/app/paths/server.js",
|
|
74
76
|
"browser": "./src/runtime/app/paths/client.js",
|
|
75
77
|
"default": "./src/runtime/app/paths/server.js"
|
|
76
78
|
},
|
|
77
79
|
"#app/env/public": {
|
|
80
|
+
"workerd": "./src/runtime/app/env/public/server.js",
|
|
78
81
|
"browser": "./src/runtime/app/env/public/client.js",
|
|
79
82
|
"default": "./src/runtime/app/env/public/server.js"
|
|
83
|
+
},
|
|
84
|
+
"#internal": {
|
|
85
|
+
"workerd": "./src/exports/internal/server/index.js",
|
|
86
|
+
"browser": "./src/exports/internal/client.js",
|
|
87
|
+
"default": "./src/exports/internal/server/index.js"
|
|
80
88
|
}
|
|
81
89
|
},
|
|
82
90
|
"exports": {
|
|
@@ -94,11 +102,11 @@
|
|
|
94
102
|
"import": "./src/exports/internal/env.js"
|
|
95
103
|
},
|
|
96
104
|
"./internal/types": {
|
|
97
|
-
"
|
|
105
|
+
"types": "./src/exports/internal/types.d.ts"
|
|
98
106
|
},
|
|
99
107
|
"./internal/server": {
|
|
100
108
|
"types": "./types/index.d.ts",
|
|
101
|
-
"import": "./src/exports/internal/server.js"
|
|
109
|
+
"import": "./src/exports/internal/server/index.js"
|
|
102
110
|
},
|
|
103
111
|
"./node": {
|
|
104
112
|
"types": "./types/index.d.ts",
|
|
@@ -108,6 +116,10 @@
|
|
|
108
116
|
"types": "./types/index.d.ts",
|
|
109
117
|
"import": "./src/exports/hooks/index.js"
|
|
110
118
|
},
|
|
119
|
+
"./env": {
|
|
120
|
+
"types": "./types/index.d.ts",
|
|
121
|
+
"import": "./src/exports/env/index.js"
|
|
122
|
+
},
|
|
111
123
|
"./vite": {
|
|
112
124
|
"types": "./types/index.d.ts",
|
|
113
125
|
"import": "./src/exports/vite/index.js"
|
|
@@ -119,7 +131,7 @@
|
|
|
119
131
|
},
|
|
120
132
|
"scripts": {
|
|
121
133
|
"lint": "prettier --config ../../.prettierrc --check .",
|
|
122
|
-
"check": "tsc && cd ./test/types && tsc",
|
|
134
|
+
"check": "tsc && cd ./test/types && tsc && cd ./app-error-enhanced && tsc",
|
|
123
135
|
"check:all": "tsc && pnpm -r --filter=\"./**\" check",
|
|
124
136
|
"format": "prettier --config ../../.prettierrc --write .",
|
|
125
137
|
"test": "pnpm test:unit && pnpm test:integration",
|
|
@@ -18,11 +18,23 @@ 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);
|
|
25
|
-
const extensions = [
|
|
25
|
+
const extensions = [
|
|
26
|
+
'.html',
|
|
27
|
+
'.js',
|
|
28
|
+
'.mjs',
|
|
29
|
+
'.json',
|
|
30
|
+
'.css',
|
|
31
|
+
'.svg',
|
|
32
|
+
'.xml',
|
|
33
|
+
'.wasm',
|
|
34
|
+
'.txt',
|
|
35
|
+
'.md',
|
|
36
|
+
'.mdx'
|
|
37
|
+
];
|
|
26
38
|
|
|
27
39
|
/**
|
|
28
40
|
* Creates the Builder which is passed to adapters for building the application.
|
|
@@ -125,7 +137,7 @@ export function create_builder({
|
|
|
125
137
|
manifest_path,
|
|
126
138
|
env,
|
|
127
139
|
out_dir: config.kit.outDir,
|
|
128
|
-
origin: config.kit.
|
|
140
|
+
origin: config.kit.paths.origin || 'http://sveltekit-prerender',
|
|
129
141
|
assets: config.kit.files.assets
|
|
130
142
|
});
|
|
131
143
|
|
|
@@ -144,7 +156,7 @@ export function create_builder({
|
|
|
144
156
|
generateEnvModule() {
|
|
145
157
|
if (!build_data.client?.uses_env_dynamic_public) return;
|
|
146
158
|
|
|
147
|
-
const dest = `${config.kit.outDir}/output/prerendered/dependencies/${config.kit.appDir}
|
|
159
|
+
const dest = `${config.kit.outDir}/output/prerendered/dependencies/${config.kit.appDir}`;
|
|
148
160
|
const env = loadEnv(vite_config.mode, config.kit.env.dir, '');
|
|
149
161
|
|
|
150
162
|
/** @type {Record<string, any>} */
|
|
@@ -161,7 +173,9 @@ export function create_builder({
|
|
|
161
173
|
|
|
162
174
|
handle_issues(issues);
|
|
163
175
|
|
|
164
|
-
|
|
176
|
+
const payload = devalue.uneval(values);
|
|
177
|
+
|
|
178
|
+
write(`${dest}/env.js`, `export const env=${payload}`);
|
|
165
179
|
},
|
|
166
180
|
|
|
167
181
|
generateManifest({ relativePath, routes: subset }) {
|
|
@@ -291,53 +305,25 @@ async function compress_file(file, format = 'gz') {
|
|
|
291
305
|
* - Imports `exports` from the entrypoint (dynamically, if `tla` is true)
|
|
292
306
|
* - Re-exports `exports` from the entrypoint
|
|
293
307
|
*
|
|
294
|
-
* `default` receives special treatment: It will be imported as `default` and exported with `export default`.
|
|
295
|
-
*
|
|
296
308
|
* @param {{ instrumentation: string; start: string; exports: string[] }} opts
|
|
297
309
|
* @returns {string}
|
|
298
310
|
*/
|
|
299
311
|
function create_instrumentation_facade({ instrumentation, start, exports }) {
|
|
300
312
|
const import_instrumentation = `import './${instrumentation}';`;
|
|
301
313
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
* you can do evil things like `export { c as class }`.
|
|
308
|
-
* in order to import these, you need to alias them, and then un-alias them when re-exporting
|
|
309
|
-
* this map will allow us to generate the following:
|
|
310
|
-
* import { class as _1 } from 'entrypoint';
|
|
311
|
-
* export { _1 as class };
|
|
312
|
-
*/
|
|
313
|
-
let alias = `_${alias_index++}`;
|
|
314
|
-
while (exports.includes(alias)) {
|
|
315
|
-
alias = `_${alias_index++}`;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
aliases.set(name, alias);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
const import_statements = [];
|
|
322
|
-
const export_statements = [];
|
|
323
|
-
|
|
324
|
-
for (const name of exports) {
|
|
325
|
-
const alias = aliases.get(name);
|
|
326
|
-
if (alias) {
|
|
327
|
-
import_statements.push(`${name}: ${alias}`);
|
|
328
|
-
export_statements.push(`${alias} as ${name}`);
|
|
329
|
-
} else {
|
|
330
|
-
import_statements.push(`${name}`);
|
|
331
|
-
export_statements.push(`${name}`);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
314
|
+
const { namespace, declarations, reexports } = create_exported_declarations(
|
|
315
|
+
exports,
|
|
316
|
+
(name, ns) => `${ns}.${name}`,
|
|
317
|
+
'__mod'
|
|
318
|
+
);
|
|
334
319
|
|
|
335
|
-
const
|
|
336
|
-
`const
|
|
337
|
-
|
|
320
|
+
const parts = [
|
|
321
|
+
`const ${namespace} = await import('./${start}');`,
|
|
322
|
+
declarations.join('\n'),
|
|
323
|
+
reexports.length > 0 ? `export { ${reexports.join(', ')} };` : ''
|
|
338
324
|
]
|
|
339
325
|
.filter(Boolean)
|
|
340
326
|
.join('\n');
|
|
341
327
|
|
|
342
|
-
return `${import_instrumentation}\n${
|
|
328
|
+
return `${import_instrumentation}\n${parts}`;
|
|
343
329
|
}
|
package/src/core/adapt/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
/** @import { Adapter } from '@sveltejs/kit' */
|
|
2
1
|
import { styleText } from 'node:util';
|
|
3
2
|
import { create_builder } from './builder.js';
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
|
-
* @param {Adapter} adapter
|
|
7
5
|
* @param {import('types').ValidatedConfig} config
|
|
8
6
|
* @param {import('types').BuildData} build_data
|
|
9
7
|
* @param {import('types').ServerMetadata} server_metadata
|
|
@@ -15,7 +13,6 @@ import { create_builder } from './builder.js';
|
|
|
15
13
|
* @param {Record<string, import('@sveltejs/kit').EnvVarConfig<any>> | null} explicit_env_config
|
|
16
14
|
*/
|
|
17
15
|
export async function adapt(
|
|
18
|
-
adapter,
|
|
19
16
|
config,
|
|
20
17
|
build_data,
|
|
21
18
|
server_metadata,
|
|
@@ -26,7 +23,7 @@ export async function adapt(
|
|
|
26
23
|
vite_config,
|
|
27
24
|
explicit_env_config
|
|
28
25
|
) {
|
|
29
|
-
const { name, adapt } = adapter;
|
|
26
|
+
const { name, adapt } = config.kit.adapter;
|
|
30
27
|
|
|
31
28
|
console.log(styleText(['bold', 'cyan'], `\n> Using ${name}`));
|
|
32
29
|
|
package/src/core/config/index.js
CHANGED
|
@@ -1,13 +1,77 @@
|
|
|
1
|
-
/** @import { Config } from '@sveltejs/kit' */
|
|
1
|
+
/** @import { Config, KitConfig } from '@sveltejs/kit' */
|
|
2
|
+
/** @import { Options, SvelteConfig } from '@sveltejs/vite-plugin-svelte' */
|
|
2
3
|
/** @import { ValidatedConfig } from 'types' */
|
|
3
4
|
/** @import { ResolvedConfig } from 'vite' */
|
|
4
5
|
import fs from 'node:fs';
|
|
5
6
|
import path from 'node:path';
|
|
6
7
|
import process from 'node:process';
|
|
7
8
|
import * as url from 'node:url';
|
|
8
|
-
import
|
|
9
|
+
import {
|
|
10
|
+
validate_kit_options,
|
|
11
|
+
kit_options,
|
|
12
|
+
kit_experimental_options,
|
|
13
|
+
validate_svelte_options
|
|
14
|
+
} from './options.js';
|
|
9
15
|
import { resolve_entry } from '../../utils/filesystem.js';
|
|
10
16
|
import { import_peer } from '../../utils/import.js';
|
|
17
|
+
import { stackless } from '../../utils/error.js';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Splits the config passed to the `sveltekit` Vite plugin into the options that
|
|
21
|
+
* SvelteKit processes itself and the options that are forwarded to
|
|
22
|
+
* `vite-plugin-svelte`. SvelteKit makes no assumptions about which options
|
|
23
|
+
* `vite-plugin-svelte` accepts — it plucks out its own options and passes
|
|
24
|
+
* everything else along (`vite-plugin-svelte` does its own validation).
|
|
25
|
+
* @param {KitConfig & Omit<Options, 'onwarn'> & Pick<SvelteConfig, 'vitePlugin'>} config
|
|
26
|
+
* @returns {{ svelte_config: Config, vite_plugin_svelte_config: Record<string, any> }}
|
|
27
|
+
*/
|
|
28
|
+
export function split_config(config) {
|
|
29
|
+
const { extensions, compilerOptions, vitePlugin, preprocess, ...rest } = config;
|
|
30
|
+
|
|
31
|
+
/** @type {KitConfig} */
|
|
32
|
+
const kit = {};
|
|
33
|
+
|
|
34
|
+
/** @type {Record<string, any>} */
|
|
35
|
+
const vite_plugin_svelte_config = {};
|
|
36
|
+
|
|
37
|
+
for (const key in rest) {
|
|
38
|
+
if (key === 'experimental') {
|
|
39
|
+
// `experimental` is a namespace that both SvelteKit and vite-plugin-svelte
|
|
40
|
+
// use, so pluck out the flags SvelteKit recognises and pass the rest along
|
|
41
|
+
const experimental = /** @type {Record<string, any>} */ (rest[key]) ?? {};
|
|
42
|
+
|
|
43
|
+
/** @type {Record<string, any>} */
|
|
44
|
+
const kit_experimental = {};
|
|
45
|
+
/** @type {Record<string, any>} */
|
|
46
|
+
const vps_experimental = {};
|
|
47
|
+
|
|
48
|
+
for (const flag in experimental) {
|
|
49
|
+
if (kit_experimental_options.includes(flag)) {
|
|
50
|
+
kit_experimental[flag] = experimental[flag];
|
|
51
|
+
} else {
|
|
52
|
+
vps_experimental[flag] = experimental[flag];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (Object.keys(kit_experimental).length > 0) {
|
|
57
|
+
kit.experimental = kit_experimental;
|
|
58
|
+
}
|
|
59
|
+
if (Object.keys(vps_experimental).length > 0) {
|
|
60
|
+
vite_plugin_svelte_config.experimental = vps_experimental;
|
|
61
|
+
}
|
|
62
|
+
} else if (kit_options.includes(key)) {
|
|
63
|
+
// @ts-expect-error - we've verified this is one of SvelteKit's own options
|
|
64
|
+
kit[key] = rest[key];
|
|
65
|
+
} else {
|
|
66
|
+
vite_plugin_svelte_config[key] = /** @type {Record<string, any>} */ (rest)[key];
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
svelte_config: { extensions, compilerOptions, vitePlugin, preprocess, kit },
|
|
72
|
+
vite_plugin_svelte_config
|
|
73
|
+
};
|
|
74
|
+
}
|
|
11
75
|
|
|
12
76
|
/**
|
|
13
77
|
* Loads the template (src/app.html by default) and validates that it has the
|
|
@@ -70,98 +134,95 @@ export async function load_vite_config(config) {
|
|
|
70
134
|
*/
|
|
71
135
|
export function extract_svelte_config(vite_config) {
|
|
72
136
|
const plugin = vite_config.plugins.find((p) => p.name === 'vite-plugin-sveltekit-setup');
|
|
73
|
-
return plugin?.api.options ?? process_config({});
|
|
137
|
+
return plugin?.api.options ?? process_config(validate_config({}), vite_config.root);
|
|
74
138
|
}
|
|
75
139
|
|
|
76
140
|
/**
|
|
77
|
-
* @param {
|
|
141
|
+
* @param {ValidatedConfig} config
|
|
142
|
+
* @param {string} cwd
|
|
78
143
|
* @returns {ValidatedConfig}
|
|
79
144
|
*/
|
|
80
|
-
export function process_config(config,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
145
|
+
export function process_config(config, cwd) {
|
|
146
|
+
if (
|
|
147
|
+
config.kit.csp?.directives?.['require-trusted-types-for']?.includes('script') &&
|
|
148
|
+
config.kit.serviceWorker.register &&
|
|
149
|
+
resolve_entry(path.resolve(cwd, config.kit.files.serviceWorker)) &&
|
|
150
|
+
!config.kit.csp?.directives?.['trusted-types']?.includes('sveltekit-trusted-url')
|
|
151
|
+
) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
"The `csp.directives['trusted-types']` option must include 'sveltekit-trusted-url' when `serviceWorker.register` is true"
|
|
154
|
+
);
|
|
155
|
+
}
|
|
85
156
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
157
|
+
config.kit.outDir = path.resolve(cwd, config.kit.outDir);
|
|
158
|
+
config.kit.env.dir = path.resolve(cwd, config.kit.env.dir);
|
|
159
|
+
|
|
160
|
+
for (const key in config.kit.files) {
|
|
161
|
+
if (key === 'hooks') {
|
|
162
|
+
config.kit.files.hooks.client = path.resolve(cwd, config.kit.files.hooks.client);
|
|
163
|
+
config.kit.files.hooks.server = path.resolve(cwd, config.kit.files.hooks.server);
|
|
164
|
+
config.kit.files.hooks.universal = path.resolve(cwd, config.kit.files.hooks.universal);
|
|
165
|
+
} else if (key !== 'lib' /* TODO remove when we remove the `lib` option altogether */) {
|
|
166
|
+
// @ts-expect-error
|
|
167
|
+
config.kit.files[key] = path.resolve(cwd, config.kit.files[key]);
|
|
98
168
|
}
|
|
99
|
-
|
|
100
|
-
return validated;
|
|
101
|
-
} catch (e) {
|
|
102
|
-
const error = /** @type {Error} */ (e);
|
|
103
|
-
|
|
104
|
-
// redact the stack trace — it's not helpful to users
|
|
105
|
-
error.stack = `Error loading ${source}: ${error.message}\n`;
|
|
106
|
-
throw error;
|
|
107
169
|
}
|
|
170
|
+
|
|
171
|
+
return config;
|
|
108
172
|
}
|
|
109
173
|
|
|
110
174
|
/**
|
|
111
175
|
* @param {Config} config
|
|
112
|
-
* @param {string} [cwd]
|
|
113
176
|
* @returns {ValidatedConfig}
|
|
114
177
|
*/
|
|
115
|
-
export function validate_config(config
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
'The Svelte config file must have a configuration object as its default export. See https://svelte.dev/docs/kit/configuration'
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/** @type {ValidatedConfig} */
|
|
123
|
-
const validated = options(config, 'config');
|
|
124
|
-
const files = validated.kit.files;
|
|
125
|
-
|
|
126
|
-
files.hooks.client ??= path.join(files.src, 'hooks.client');
|
|
127
|
-
files.hooks.server ??= path.join(files.src, 'hooks.server');
|
|
128
|
-
files.hooks.universal ??= path.join(files.src, 'hooks');
|
|
129
|
-
files.lib ??= path.join(files.src, 'lib');
|
|
130
|
-
files.params ??= path.join(files.src, 'params');
|
|
131
|
-
files.routes ??= path.join(files.src, 'routes');
|
|
132
|
-
files.serviceWorker ??= path.join(files.src, 'service-worker');
|
|
133
|
-
files.appTemplate ??= path.join(files.src, 'app.html');
|
|
134
|
-
files.errorTemplate ??= path.join(files.src, 'error.html');
|
|
135
|
-
|
|
136
|
-
if (validated.kit.router.resolution === 'server') {
|
|
137
|
-
if (validated.kit.router.type === 'hash') {
|
|
138
|
-
throw new Error(
|
|
139
|
-
"The `router.resolution` option cannot be 'server' if `router.type` is 'hash'"
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
if (validated.kit.output.bundleStrategy !== 'split') {
|
|
178
|
+
export function validate_config(config) {
|
|
179
|
+
try {
|
|
180
|
+
if (typeof config !== 'object') {
|
|
143
181
|
throw new Error(
|
|
144
|
-
|
|
182
|
+
'The SvelteKit options from the Vite config must be an object. See https://svelte.dev/docs/kit/configuration'
|
|
145
183
|
);
|
|
146
184
|
}
|
|
147
|
-
}
|
|
148
185
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
186
|
+
const validated = /** @type {ValidatedConfig} */ ({
|
|
187
|
+
...validate_svelte_options(config, 'config'),
|
|
188
|
+
kit: validate_kit_options(config.kit, 'config')
|
|
189
|
+
});
|
|
190
|
+
const files = validated.kit.files;
|
|
191
|
+
|
|
192
|
+
files.hooks.client ??= path.join(files.src, 'hooks.client');
|
|
193
|
+
files.hooks.server ??= path.join(files.src, 'hooks.server');
|
|
194
|
+
files.hooks.universal ??= path.join(files.src, 'hooks');
|
|
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
|
+
}
|
|
154
212
|
}
|
|
213
|
+
|
|
155
214
|
if (
|
|
156
|
-
validated.kit.
|
|
157
|
-
|
|
158
|
-
!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')
|
|
159
217
|
) {
|
|
160
218
|
throw new Error(
|
|
161
|
-
"The `csp.directives['trusted-types']` option must include '
|
|
219
|
+
"The `csp.directives['trusted-types']` option must include 'svelte-trusted-html'"
|
|
162
220
|
);
|
|
163
221
|
}
|
|
164
|
-
}
|
|
165
222
|
|
|
166
|
-
|
|
223
|
+
return validated;
|
|
224
|
+
} catch (e) {
|
|
225
|
+
const error = /** @type {Error} */ (e);
|
|
226
|
+
throw stackless(`Error loading SvelteKit options from Vite config: ${error.message}`);
|
|
227
|
+
}
|
|
167
228
|
}
|