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