@sveltejs/kit 3.0.0-next.4 → 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 +23 -18
- package/src/core/adapt/builder.js +29 -43
- package/src/core/adapt/index.js +1 -4
- package/src/core/config/index.js +135 -71
- package/src/core/config/options.js +291 -244
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +120 -5
- package/src/core/generate_manifest/index.js +12 -15
- package/src/core/postbuild/analyse.js +8 -12
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/prerender.js +40 -23
- package/src/core/sync/create_manifest_data/index.js +29 -49
- package/src/core/sync/write_client_manifest.js +14 -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 +13 -11
- package/src/core/sync/write_tsconfig.js +2 -4
- package/src/core/sync/write_types/index.js +11 -10
- package/src/exports/index.js +34 -12
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +1 -1
- 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 +58 -7
- package/src/exports/params.js +63 -0
- package/src/exports/public.d.ts +299 -145
- package/src/exports/url.js +84 -0
- package/src/exports/vite/build/build_server.js +6 -1
- package/src/exports/vite/dev/index.js +38 -37
- package/src/exports/vite/index.js +498 -353
- package/src/exports/vite/preview/index.js +16 -8
- package/src/exports/vite/utils.js +7 -11
- package/src/runtime/app/env/types.d.ts +1 -1
- package/src/runtime/app/forms.js +22 -5
- package/src/runtime/app/paths/client.js +4 -10
- package/src/runtime/app/paths/public.d.ts +0 -28
- package/src/runtime/app/paths/server.js +8 -4
- package/src/runtime/app/server/remote/form.js +10 -3
- package/src/runtime/app/server/remote/query.js +9 -18
- package/src/runtime/app/server/remote/requested.js +8 -4
- package/src/runtime/app/server/remote/shared.js +5 -7
- package/src/runtime/app/state/client.js +1 -2
- package/src/runtime/app/stores.js +13 -76
- package/src/runtime/client/client.js +205 -167
- package/src/runtime/client/fetcher.js +3 -2
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/form.svelte.js +122 -31
- package/src/runtime/client/remote-functions/prerender.svelte.js +17 -4
- package/src/runtime/client/remote-functions/query/index.js +3 -2
- package/src/runtime/client/remote-functions/query/instance.svelte.js +27 -11
- package/src/runtime/client/remote-functions/query-batch.svelte.js +4 -3
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +42 -15
- package/src/runtime/client/remote-functions/shared.svelte.js +18 -9
- package/src/runtime/client/state.svelte.js +66 -49
- package/src/runtime/client/types.d.ts +10 -2
- package/src/runtime/client/utils.js +0 -96
- package/src/runtime/form-utils.js +99 -18
- package/src/runtime/server/cookie.js +22 -33
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +7 -7
- 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 +2 -1
- package/src/runtime/server/page/load_data.js +1 -1
- package/src/runtime/server/page/render.js +36 -47
- package/src/runtime/server/page/respond_with_error.js +7 -8
- package/src/runtime/server/page/server_routing.js +13 -9
- package/src/runtime/server/remote.js +85 -39
- package/src/runtime/server/respond.js +92 -58
- package/src/runtime/server/utils.js +7 -7
- package/src/runtime/telemetry/otel.js +1 -1
- package/src/types/ambient.d.ts +10 -5
- package/src/types/global-private.d.ts +4 -4
- package/src/types/internal.d.ts +17 -20
- package/src/types/private.d.ts +33 -1
- package/src/types/synthetic/$lib.md +1 -1
- package/src/utils/error.js +12 -4
- package/src/utils/mime.js +9 -0
- package/src/utils/params.js +66 -0
- package/src/utils/routing.js +84 -38
- 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 +434 -269
- package/types/index.d.ts.map +19 -15
- package/src/exports/internal/server.js +0 -22
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
/** @import { SvelteConfig } from '@sveltejs/vite-plugin-svelte' */
|
|
2
|
+
/** @import { ValidatedKitConfig } from 'types' */
|
|
1
3
|
/** @import { Validator } from './types.js' */
|
|
2
4
|
|
|
3
|
-
import process from 'node:process';
|
|
4
|
-
|
|
5
5
|
const directives = object({
|
|
6
6
|
'child-src': string_array(),
|
|
7
7
|
'default-src': string_array(),
|
|
@@ -36,8 +36,8 @@ const directives = object({
|
|
|
36
36
|
referrer: string_array()
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
/** @type {Validator} */
|
|
40
|
-
const
|
|
39
|
+
/** @type {Validator<{ extensions: string[] } & SvelteConfig>} */
|
|
40
|
+
export const validate_svelte_options = object(
|
|
41
41
|
{
|
|
42
42
|
extensions: validate(['.svelte'], (input, keypath) => {
|
|
43
43
|
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
|
|
@@ -55,260 +55,296 @@ const options = object(
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
return input;
|
|
58
|
-
})
|
|
58
|
+
})
|
|
59
|
+
},
|
|
60
|
+
true
|
|
61
|
+
);
|
|
59
62
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
/** @type {Validator<ValidatedKitConfig>} */
|
|
64
|
+
export const validate_kit_options = object({
|
|
65
|
+
adapter: validate(undefined, (input, keypath) => {
|
|
66
|
+
if (typeof input !== 'object' || !input.adapt) {
|
|
67
|
+
const message = `The SvelteKit Vite plugin ${keypath} should be an object with an \`adapt\` method`;
|
|
68
|
+
throw new Error(`${message}. See https://svelte.dev/docs/kit/adapters`);
|
|
69
|
+
}
|
|
66
70
|
|
|
67
|
-
|
|
68
|
-
|
|
71
|
+
return input;
|
|
72
|
+
}),
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
+
alias: validate({}, (input, keypath) => {
|
|
75
|
+
if (typeof input !== 'object') {
|
|
76
|
+
throw new Error(`${keypath} should be an object`);
|
|
77
|
+
}
|
|
74
78
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
for (const key in input) {
|
|
80
|
+
assert_string(input[key], `${keypath}.${key}`);
|
|
81
|
+
}
|
|
78
82
|
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
return input;
|
|
84
|
+
}),
|
|
81
85
|
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
appDir: validate('_app', (input, keypath) => {
|
|
87
|
+
assert_string(input, keypath);
|
|
84
88
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
if (input) {
|
|
90
|
+
if (input.startsWith('/') || input.endsWith('/')) {
|
|
91
|
+
throw new Error(
|
|
92
|
+
`${keypath} cannot start or end with '/'. See https://svelte.dev/docs/kit/configuration`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
} else {
|
|
96
|
+
throw new Error(`${keypath} cannot be empty`);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return input;
|
|
100
|
+
}),
|
|
101
|
+
|
|
102
|
+
csp: object({
|
|
103
|
+
mode: list(['auto', 'hash', 'nonce']),
|
|
104
|
+
directives,
|
|
105
|
+
reportOnly: directives
|
|
106
|
+
}),
|
|
107
|
+
|
|
108
|
+
csrf: object({
|
|
109
|
+
checkOrigin: removed(
|
|
110
|
+
(keypath) => `\`${keypath}\` has been removed in favour of \`csrf.trustedOrigins\``
|
|
111
|
+
),
|
|
112
|
+
trustedOrigins: string_array([])
|
|
113
|
+
}),
|
|
114
|
+
|
|
115
|
+
embedded: boolean(false),
|
|
116
|
+
|
|
117
|
+
env: object({
|
|
118
|
+
dir: string('')
|
|
119
|
+
}),
|
|
120
|
+
|
|
121
|
+
experimental: object({
|
|
122
|
+
tracing: removed(
|
|
123
|
+
(keypath) =>
|
|
124
|
+
`\`${keypath}\` has been removed. Server-side tracing is now configured via \`tracing.server\``
|
|
125
|
+
),
|
|
126
|
+
instrumentation: removed(
|
|
127
|
+
(keypath) =>
|
|
128
|
+
`\`${keypath}\` has been removed. \`src/instrumentation.server.js\` is now included in the build automatically when it exists; no opt-in is required`
|
|
129
|
+
),
|
|
130
|
+
remoteFunctions: boolean(false),
|
|
131
|
+
forkPreloads: boolean(false),
|
|
132
|
+
handleRenderingErrors: boolean(false)
|
|
133
|
+
}),
|
|
134
|
+
|
|
135
|
+
files: object({
|
|
136
|
+
src: string('src'),
|
|
137
|
+
assets: string('static'),
|
|
138
|
+
hooks: object({
|
|
139
|
+
client: string(null),
|
|
140
|
+
server: string(null),
|
|
141
|
+
universal: string(null)
|
|
142
|
+
}),
|
|
143
|
+
lib: string(null),
|
|
144
|
+
params: string(null),
|
|
145
|
+
routes: string(null),
|
|
146
|
+
serviceWorker: string(null),
|
|
147
|
+
appTemplate: string(null),
|
|
148
|
+
errorTemplate: string(null)
|
|
149
|
+
}),
|
|
150
|
+
|
|
151
|
+
inlineStyleThreshold: number(0),
|
|
152
|
+
|
|
153
|
+
moduleExtensions: string_array(['.js', '.ts']),
|
|
154
|
+
|
|
155
|
+
outDir: string('.svelte-kit'),
|
|
156
|
+
|
|
157
|
+
output: object({
|
|
158
|
+
linkHeaderPreload: boolean(false),
|
|
159
|
+
preloadStrategy: removed(
|
|
160
|
+
(keypath) => `\`${keypath}\` has been removed. modulepreload will always be used`
|
|
161
|
+
),
|
|
162
|
+
bundleStrategy: list(['split', 'single', 'inline'])
|
|
163
|
+
}),
|
|
164
|
+
|
|
165
|
+
paths: object({
|
|
166
|
+
base: validate('', (input, keypath) => {
|
|
167
|
+
assert_string(input, keypath);
|
|
168
|
+
|
|
169
|
+
if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
|
|
170
|
+
throw new Error(
|
|
171
|
+
`${keypath} option must either be the empty string or a root-relative path that starts but doesn't end with '/'. See https://svelte.dev/docs/kit/configuration#paths`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return input;
|
|
176
|
+
}),
|
|
177
|
+
assets: validate('', (input, keypath) => {
|
|
178
|
+
assert_string(input, keypath);
|
|
179
|
+
|
|
180
|
+
if (input) {
|
|
181
|
+
if (!/^[a-z]+:\/\//.test(input)) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`${keypath} option must be an absolute path, if specified. See https://svelte.dev/docs/kit/configuration#paths`
|
|
184
|
+
);
|
|
93
185
|
}
|
|
94
186
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
reportOnly: directives
|
|
102
|
-
}),
|
|
103
|
-
|
|
104
|
-
csrf: object({
|
|
105
|
-
checkOrigin: removed(
|
|
106
|
-
(keypath) => `\`${keypath}\` has been removed in favour of \`csrf.trustedOrigins\``
|
|
107
|
-
),
|
|
108
|
-
trustedOrigins: string_array([])
|
|
109
|
-
}),
|
|
110
|
-
|
|
111
|
-
embedded: boolean(false),
|
|
112
|
-
|
|
113
|
-
env: object({
|
|
114
|
-
dir: string(process.cwd())
|
|
115
|
-
}),
|
|
116
|
-
|
|
117
|
-
experimental: object({
|
|
118
|
-
tracing: object({
|
|
119
|
-
server: boolean(false)
|
|
120
|
-
}),
|
|
121
|
-
instrumentation: object({
|
|
122
|
-
server: boolean(false)
|
|
123
|
-
}),
|
|
124
|
-
remoteFunctions: boolean(false),
|
|
125
|
-
forkPreloads: boolean(false),
|
|
126
|
-
handleRenderingErrors: boolean(false)
|
|
127
|
-
}),
|
|
128
|
-
|
|
129
|
-
files: object({
|
|
130
|
-
src: string('src'),
|
|
131
|
-
assets: string('static'),
|
|
132
|
-
hooks: object({
|
|
133
|
-
client: string(null),
|
|
134
|
-
server: string(null),
|
|
135
|
-
universal: string(null)
|
|
136
|
-
}),
|
|
137
|
-
lib: string(null),
|
|
138
|
-
params: string(null),
|
|
139
|
-
routes: string(null),
|
|
140
|
-
serviceWorker: string(null),
|
|
141
|
-
appTemplate: string(null),
|
|
142
|
-
errorTemplate: string(null)
|
|
143
|
-
}),
|
|
144
|
-
|
|
145
|
-
inlineStyleThreshold: number(0),
|
|
146
|
-
|
|
147
|
-
moduleExtensions: string_array(['.js', '.ts']),
|
|
148
|
-
|
|
149
|
-
outDir: string('.svelte-kit'),
|
|
150
|
-
|
|
151
|
-
output: object({
|
|
152
|
-
linkHeaderPreload: boolean(false),
|
|
153
|
-
preloadStrategy: removed(
|
|
154
|
-
(keypath) => `\`${keypath}\` has been removed. modulepreload will always be used`
|
|
155
|
-
),
|
|
156
|
-
bundleStrategy: list(['split', 'single', 'inline'])
|
|
157
|
-
}),
|
|
158
|
-
|
|
159
|
-
paths: object({
|
|
160
|
-
base: validate('', (input, keypath) => {
|
|
161
|
-
assert_string(input, keypath);
|
|
162
|
-
|
|
163
|
-
if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
|
|
164
|
-
throw new Error(
|
|
165
|
-
`${keypath} option must either be the empty string or a root-relative path that starts but doesn't end with '/'. See https://svelte.dev/docs/kit/configuration#paths`
|
|
166
|
-
);
|
|
167
|
-
}
|
|
187
|
+
if (input.endsWith('/')) {
|
|
188
|
+
throw new Error(
|
|
189
|
+
`${keypath} option must not end with '/'. See https://svelte.dev/docs/kit/configuration#paths`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
168
193
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (input) {
|
|
175
|
-
if (!/^[a-z]+:\/\//.test(input)) {
|
|
176
|
-
throw new Error(
|
|
177
|
-
`${keypath} option must be an absolute path, if specified. See https://svelte.dev/docs/kit/configuration#paths`
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (input.endsWith('/')) {
|
|
182
|
-
throw new Error(
|
|
183
|
-
`${keypath} option must not end with '/'. See https://svelte.dev/docs/kit/configuration#paths`
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
194
|
+
return input;
|
|
195
|
+
}),
|
|
196
|
+
origin: validate(undefined, (input, keypath) => {
|
|
197
|
+
assert_string(input, keypath);
|
|
187
198
|
|
|
188
|
-
|
|
189
|
-
}),
|
|
190
|
-
relative: boolean(true)
|
|
191
|
-
}),
|
|
192
|
-
|
|
193
|
-
prerender: object({
|
|
194
|
-
concurrency: number(1),
|
|
195
|
-
crawl: boolean(true),
|
|
196
|
-
entries: validate(['*'], (input, keypath) => {
|
|
197
|
-
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
|
|
198
|
-
throw new Error(`${keypath} must be an array of strings`);
|
|
199
|
-
}
|
|
199
|
+
let url;
|
|
200
200
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return input;
|
|
210
|
-
}),
|
|
211
|
-
|
|
212
|
-
handleHttpError: validate(
|
|
213
|
-
(/** @type {any} */ { message }) => {
|
|
214
|
-
throw new Error(
|
|
215
|
-
message +
|
|
216
|
-
'\nTo suppress or handle this error, implement `handleHttpError` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
217
|
-
);
|
|
218
|
-
},
|
|
219
|
-
(input, keypath) => {
|
|
220
|
-
if (typeof input === 'function') return input;
|
|
221
|
-
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
222
|
-
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
223
|
-
}
|
|
224
|
-
),
|
|
225
|
-
|
|
226
|
-
handleMissingId: validate(
|
|
227
|
-
(/** @type {any} */ { message }) => {
|
|
228
|
-
throw new Error(
|
|
229
|
-
message +
|
|
230
|
-
'\nTo suppress or handle this error, implement `handleMissingId` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
231
|
-
);
|
|
232
|
-
},
|
|
233
|
-
(input, keypath) => {
|
|
234
|
-
if (typeof input === 'function') return input;
|
|
235
|
-
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
236
|
-
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
237
|
-
}
|
|
238
|
-
),
|
|
239
|
-
|
|
240
|
-
handleEntryGeneratorMismatch: validate(
|
|
241
|
-
(/** @type {any} */ { message }) => {
|
|
242
|
-
throw new Error(
|
|
243
|
-
message +
|
|
244
|
-
'\nTo suppress or handle this error, implement `handleEntryGeneratorMismatch` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
245
|
-
);
|
|
246
|
-
},
|
|
247
|
-
(input, keypath) => {
|
|
248
|
-
if (typeof input === 'function') return input;
|
|
249
|
-
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
250
|
-
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
251
|
-
}
|
|
252
|
-
),
|
|
253
|
-
|
|
254
|
-
handleUnseenRoutes: validate(
|
|
255
|
-
(/** @type {any} */ { message }) => {
|
|
256
|
-
throw new Error(
|
|
257
|
-
message +
|
|
258
|
-
'\nTo suppress or handle this error, implement `handleUnseenRoutes` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
259
|
-
);
|
|
260
|
-
},
|
|
261
|
-
(input, keypath) => {
|
|
262
|
-
if (typeof input === 'function') return input;
|
|
263
|
-
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
264
|
-
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
265
|
-
}
|
|
266
|
-
),
|
|
201
|
+
try {
|
|
202
|
+
url = new URL(input);
|
|
203
|
+
} catch {
|
|
204
|
+
throw new Error(
|
|
205
|
+
`${keypath} must be a valid origin (e.g. 'https://my-site.com'). '${input}' could not be parsed as a URL`
|
|
206
|
+
);
|
|
207
|
+
}
|
|
267
208
|
|
|
268
|
-
|
|
269
|
-
|
|
209
|
+
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
|
|
210
|
+
throw new Error(
|
|
211
|
+
`${keypath} must be a valid origin — only 'http' and 'https' protocols are supported, received '${url.protocol}'`
|
|
212
|
+
);
|
|
213
|
+
}
|
|
270
214
|
|
|
271
|
-
|
|
215
|
+
const origin = url.origin;
|
|
272
216
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
|
|
217
|
+
if (input !== origin) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`${keypath} must be a valid origin — received '${input}' which contains a path, query, or hash. Use the bare origin '${origin}' instead`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
278
222
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
223
|
+
return origin;
|
|
224
|
+
}),
|
|
225
|
+
relative: boolean(true)
|
|
226
|
+
}),
|
|
282
227
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
);
|
|
228
|
+
prerender: object({
|
|
229
|
+
concurrency: number(1),
|
|
230
|
+
crawl: boolean(true),
|
|
231
|
+
entries: validate(['*'], (input, keypath) => {
|
|
232
|
+
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
|
|
233
|
+
throw new Error(`${keypath} must be an array of strings`);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
input.forEach((page) => {
|
|
237
|
+
if (page !== '*' && page[0] !== '/') {
|
|
238
|
+
throw new Error(
|
|
239
|
+
`Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
return input;
|
|
245
|
+
}),
|
|
246
|
+
|
|
247
|
+
handleHttpError: validate(
|
|
248
|
+
(/** @type {any} */ { message }) => {
|
|
249
|
+
throw new Error(
|
|
250
|
+
message +
|
|
251
|
+
'\nTo suppress or handle this error, implement `handleHttpError` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
252
|
+
);
|
|
253
|
+
},
|
|
254
|
+
(input, keypath) => {
|
|
255
|
+
if (typeof input === 'function') return input;
|
|
256
|
+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
257
|
+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
258
|
+
}
|
|
259
|
+
),
|
|
260
|
+
|
|
261
|
+
handleMissingId: validate(
|
|
262
|
+
(/** @type {any} */ { message }) => {
|
|
263
|
+
throw new Error(
|
|
264
|
+
message +
|
|
265
|
+
'\nTo suppress or handle this error, implement `handleMissingId` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
266
|
+
);
|
|
267
|
+
},
|
|
268
|
+
(input, keypath) => {
|
|
269
|
+
if (typeof input === 'function') return input;
|
|
270
|
+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
271
|
+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
272
|
+
}
|
|
273
|
+
),
|
|
274
|
+
|
|
275
|
+
handleEntryGeneratorMismatch: validate(
|
|
276
|
+
(/** @type {any} */ { message }) => {
|
|
277
|
+
throw new Error(
|
|
278
|
+
message +
|
|
279
|
+
'\nTo suppress or handle this error, implement `handleEntryGeneratorMismatch` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
280
|
+
);
|
|
281
|
+
},
|
|
282
|
+
(input, keypath) => {
|
|
283
|
+
if (typeof input === 'function') return input;
|
|
284
|
+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
285
|
+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
286
|
+
}
|
|
287
|
+
),
|
|
288
|
+
|
|
289
|
+
handleUnseenRoutes: validate(
|
|
290
|
+
(/** @type {any} */ { message }) => {
|
|
291
|
+
throw new Error(
|
|
292
|
+
message +
|
|
293
|
+
'\nTo suppress or handle this error, implement `handleUnseenRoutes` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
294
|
+
);
|
|
295
|
+
},
|
|
296
|
+
(input, keypath) => {
|
|
297
|
+
if (typeof input === 'function') return input;
|
|
298
|
+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
299
|
+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
300
|
+
}
|
|
301
|
+
),
|
|
302
|
+
|
|
303
|
+
handleInvalidUrl: validate(
|
|
304
|
+
(/** @type {any} */ { message }) => {
|
|
305
|
+
throw new Error(
|
|
306
|
+
message +
|
|
307
|
+
'\nTo suppress or handle this error, implement `handleInvalidUrl` in https://svelte.dev/docs/kit/configuration#prerender'
|
|
308
|
+
);
|
|
309
|
+
},
|
|
310
|
+
(input, keypath) => {
|
|
311
|
+
if (typeof input === 'function') return input;
|
|
312
|
+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
313
|
+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
314
|
+
}
|
|
315
|
+
),
|
|
316
|
+
|
|
317
|
+
origin: removed(
|
|
318
|
+
(keypath) => `\`${keypath}\` has been removed in favour of \`config.paths.origin\``
|
|
319
|
+
)
|
|
320
|
+
}),
|
|
321
|
+
|
|
322
|
+
router: object({
|
|
323
|
+
type: list(['pathname', 'hash']),
|
|
324
|
+
resolution: list(['client', 'server'])
|
|
325
|
+
}),
|
|
326
|
+
|
|
327
|
+
serviceWorker: object({
|
|
328
|
+
register: boolean(true),
|
|
329
|
+
// options could be undefined but if it is defined we only validate that
|
|
330
|
+
// it's an object since the type comes from the browser itself
|
|
331
|
+
options: validate(undefined, object({}, true)),
|
|
332
|
+
files: fun((filename) => !/\.DS_Store/.test(filename))
|
|
333
|
+
}),
|
|
334
|
+
|
|
335
|
+
tracing: object({
|
|
336
|
+
server: boolean(false)
|
|
337
|
+
}),
|
|
338
|
+
|
|
339
|
+
typescript: object({
|
|
340
|
+
config: fun((config) => config)
|
|
341
|
+
}),
|
|
342
|
+
|
|
343
|
+
version: object({
|
|
344
|
+
name: string(Date.now().toString()),
|
|
345
|
+
pollInterval: number(0)
|
|
346
|
+
})
|
|
347
|
+
});
|
|
312
348
|
|
|
313
349
|
// /**
|
|
314
350
|
// * @param {Validator} fn
|
|
@@ -321,6 +357,8 @@ const options = object(
|
|
|
321
357
|
// `The \`${keypath}\` option is deprecated, and will be removed in a future version`
|
|
322
358
|
// ) {
|
|
323
359
|
// return (input, keypath) => {
|
|
360
|
+
// keypath = remove_kit_prefix(keypath);
|
|
361
|
+
//
|
|
324
362
|
// if (input !== undefined) {
|
|
325
363
|
// console.warn(styleText(['bold', 'yellow'], get_message(keypath)));
|
|
326
364
|
// }
|
|
@@ -329,6 +367,17 @@ const options = object(
|
|
|
329
367
|
// };
|
|
330
368
|
// }
|
|
331
369
|
|
|
370
|
+
// Derive the names of SvelteKit's own config options from the schema, so they
|
|
371
|
+
// stay in sync automatically. These are used to separate Kit's options from
|
|
372
|
+
// `vite-plugin-svelte`'s options when config is passed via the Vite plugin.
|
|
373
|
+
const kit_defaults = validate_kit_options({}, 'config');
|
|
374
|
+
|
|
375
|
+
/** The names of the options that live under the `kit` namespace */
|
|
376
|
+
export const kit_options = Object.keys(kit_defaults);
|
|
377
|
+
|
|
378
|
+
/** The names of the options that live under the `kit.experimental` namespace */
|
|
379
|
+
export const kit_experimental_options = Object.keys(kit_defaults.experimental);
|
|
380
|
+
|
|
332
381
|
/**
|
|
333
382
|
* @param {(keypath: string) => string} get_message
|
|
334
383
|
* @returns {Validator}
|
|
@@ -366,7 +415,7 @@ export function object(children, allow_unknown = false) {
|
|
|
366
415
|
let message = `Unexpected option ${keypath}.${key}`;
|
|
367
416
|
|
|
368
417
|
// special case
|
|
369
|
-
if (keypath === 'config.kit' && key in
|
|
418
|
+
if (keypath === 'config.kit' && key in kit_options) {
|
|
370
419
|
message += ` (did you mean config.${key}?)`;
|
|
371
420
|
}
|
|
372
421
|
|
|
@@ -492,5 +541,3 @@ function assert_string(input, keypath) {
|
|
|
492
541
|
throw new Error(`${keypath} should be a string, if specified`);
|
|
493
542
|
}
|
|
494
543
|
}
|
|
495
|
-
|
|
496
|
-
export default options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type Validator<T = any> = (input:
|
|
1
|
+
export type Validator<T = any> = (input: any, keypath: string) => T;
|