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

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