@sveltejs/kit 3.0.0-next.2 → 3.0.0-next.21

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