@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.
- package/package.json +58 -36
- package/src/cli.js +14 -11
- package/src/constants.js +6 -1
- package/src/core/adapt/builder.js +54 -60
- package/src/core/adapt/index.js +2 -5
- package/src/core/config/index.js +141 -76
- package/src/core/config/options.js +260 -260
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +143 -13
- package/src/core/generate_manifest/index.js +18 -15
- package/src/core/postbuild/analyse.js +7 -19
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/entities.js +8 -2
- package/src/core/postbuild/fallback.js +4 -2
- package/src/core/postbuild/prerender.js +193 -69
- package/src/core/postbuild/queue.js +2 -1
- package/src/core/sync/create_manifest_data/conflict.js +1 -1
- package/src/core/sync/create_manifest_data/index.js +72 -52
- package/src/core/sync/sync.js +35 -26
- package/src/core/sync/ts.js +1 -1
- package/src/core/sync/utils.js +22 -2
- package/src/core/sync/{write_non_ambient.js → write_app_types.js} +105 -56
- package/src/core/sync/write_client_manifest.js +13 -28
- package/src/core/sync/write_env.js +7 -5
- package/src/core/sync/write_server.js +25 -33
- package/src/core/sync/write_tsconfig/index.js +274 -0
- package/src/core/sync/write_tsconfig/test-app/package.json +7 -0
- package/src/core/sync/write_tsconfig/utils.js +77 -0
- package/src/core/sync/write_tsconfig/validate.js +128 -0
- package/src/core/sync/write_types/index.js +119 -116
- package/src/core/utils.js +30 -5
- package/src/exports/env/index.js +77 -0
- package/src/exports/env/public.d.ts +55 -0
- package/src/exports/hooks/index.js +3 -9
- package/src/exports/hooks/public.d.ts +194 -0
- package/src/exports/hooks/sequence.js +9 -6
- package/src/exports/index.js +53 -20
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +8 -5
- 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 +37 -0
- package/src/exports/internal/server/telemetry.js +95 -0
- package/src/exports/internal/shared.js +90 -0
- package/src/exports/node/index.js +64 -22
- package/src/exports/params/index.js +70 -0
- package/src/exports/params/public.d.ts +63 -0
- package/src/exports/public.d.ts +219 -1118
- package/src/exports/url.js +86 -0
- package/src/exports/vite/build/build_server.js +53 -64
- package/src/exports/vite/build/remote.js +24 -19
- package/src/exports/vite/build/utils.js +0 -8
- package/src/exports/vite/dev/index.js +199 -125
- package/src/exports/vite/index.js +1514 -833
- package/src/exports/vite/module_ids.js +2 -2
- package/src/exports/vite/preview/index.js +32 -24
- package/src/exports/vite/utils.js +83 -45
- package/src/pathname.js +55 -0
- package/src/runner.js +15 -0
- package/src/runtime/app/env/internal.js +4 -4
- package/src/runtime/app/env/types.d.ts +1 -1
- package/src/runtime/app/environment/index.js +3 -3
- package/src/runtime/app/{forms.js → forms/index.js} +73 -42
- package/src/runtime/app/forms/public.d.ts +2 -0
- package/src/runtime/app/forms/types.d.ts +56 -0
- package/src/runtime/app/internal/transport.js +53 -0
- package/src/runtime/app/manifest/index.js +1 -0
- package/src/runtime/app/{navigation.js → navigation/index.js} +2 -1
- package/src/runtime/app/navigation/public.d.ts +237 -0
- package/src/runtime/app/paths/client.js +37 -37
- package/src/runtime/app/paths/index.js +1 -1
- package/src/runtime/app/paths/internal/client.js +34 -2
- package/src/runtime/app/paths/internal/server.js +6 -23
- package/src/runtime/app/paths/internal.d.ts +3 -0
- package/src/runtime/app/paths/public.d.ts +1 -29
- package/src/runtime/app/paths/server.js +36 -17
- package/src/runtime/app/paths/types.d.ts +11 -19
- package/src/runtime/app/server/index.js +2 -2
- package/src/runtime/app/server/public.d.ts +519 -0
- package/src/runtime/app/server/remote/command.js +13 -11
- package/src/runtime/app/server/remote/form.js +61 -39
- package/src/runtime/app/server/remote/prerender.js +45 -45
- package/src/runtime/app/server/remote/query.js +106 -108
- package/src/runtime/app/server/remote/requested.js +27 -19
- package/src/runtime/app/server/remote/shared.js +75 -75
- package/src/runtime/app/service-worker/index.js +24 -0
- package/src/runtime/app/state/client.js +4 -2
- package/src/runtime/app/state/index.js +7 -5
- package/src/runtime/app/state/public.d.ts +72 -0
- package/src/runtime/app/state/server.js +3 -0
- package/src/runtime/app/stores.js +15 -78
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client-entry.js +3 -0
- package/src/runtime/client/client.js +1336 -648
- package/src/runtime/client/constants.js +3 -6
- package/src/runtime/client/entry.js +24 -3
- package/src/runtime/client/fetcher.js +25 -25
- package/src/runtime/client/ndjson.js +1 -1
- package/src/runtime/client/parse.js +1 -1
- package/src/runtime/client/payload.js +17 -0
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/command.svelte.js +37 -61
- package/src/runtime/client/remote-functions/form.svelte.js +267 -178
- package/src/runtime/client/remote-functions/prerender.svelte.js +32 -11
- package/src/runtime/client/remote-functions/query/index.js +10 -17
- package/src/runtime/client/remote-functions/query/instance.svelte.js +64 -18
- package/src/runtime/client/remote-functions/query/proxy.js +5 -5
- package/src/runtime/client/remote-functions/query-batch.svelte.js +61 -70
- package/src/runtime/client/remote-functions/query-live/index.js +1 -1
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +63 -21
- package/src/runtime/client/remote-functions/query-live/iterator.js +15 -12
- package/src/runtime/client/remote-functions/query-live/proxy.js +2 -12
- package/src/runtime/client/remote-functions/shared.svelte.js +90 -65
- package/src/runtime/client/snapshots.js +147 -0
- package/src/runtime/client/state.svelte.js +94 -55
- package/src/runtime/client/stream.js +3 -2
- package/src/runtime/client/types.d.ts +13 -9
- package/src/runtime/client/utils.js +22 -110
- package/src/runtime/components/root.svelte +56 -0
- package/src/runtime/env/dynamic/private.js +7 -0
- package/src/runtime/env/dynamic/public.js +7 -0
- package/src/runtime/env/static/private.js +6 -0
- package/src/runtime/env/static/public.js +6 -0
- package/src/runtime/form-utils.js +172 -61
- package/src/runtime/pathname.js +20 -32
- package/src/runtime/props.svelte.js +72 -0
- package/src/runtime/server/constants.js +0 -3
- package/src/runtime/server/cookie.js +70 -53
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +48 -52
- package/src/runtime/server/dev.js +22 -0
- package/src/runtime/server/endpoint.js +3 -4
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/errors.js +160 -0
- package/src/runtime/server/fetch.js +31 -38
- package/src/runtime/server/index.js +90 -64
- package/src/runtime/server/internal.js +71 -0
- package/src/runtime/server/page/actions.js +84 -64
- package/src/runtime/server/page/crypto.js +2 -2
- package/src/runtime/server/page/csp.js +88 -104
- package/src/runtime/server/page/data_serializer.js +22 -23
- package/src/runtime/server/page/index.js +35 -53
- package/src/runtime/server/page/load_data.js +47 -54
- package/src/runtime/server/page/render.js +172 -238
- package/src/runtime/server/page/respond_with_error.js +16 -30
- package/src/runtime/server/page/serialize_data.js +2 -13
- package/src/runtime/server/page/server_routing.js +85 -26
- package/src/runtime/server/remote-functions.js +639 -0
- package/src/runtime/server/respond.js +188 -129
- package/src/runtime/server/sourcemaps.js +183 -0
- package/src/runtime/server/state.js +53 -0
- package/src/runtime/server/utils.js +12 -154
- package/src/runtime/shared.js +20 -40
- package/src/runtime/utils.js +3 -0
- package/src/types/ambient-private.d.ts +11 -1
- package/src/types/ambient.d.ts +87 -36
- package/src/types/global-private.d.ts +25 -25
- package/src/types/internal.d.ts +160 -150
- package/src/types/private.d.ts +41 -1
- package/src/utils/error.js +28 -4
- package/src/utils/escape.js +9 -25
- package/src/utils/features.js +1 -1
- package/src/utils/filesystem.js +1 -23
- package/src/utils/fork.js +7 -2
- package/src/utils/hash.js +21 -0
- package/src/utils/http.js +8 -7
- package/src/utils/import.js +9 -2
- package/src/utils/imports.js +83 -0
- package/src/utils/mime.js +9 -0
- package/src/utils/page_nodes.js +6 -7
- package/src/utils/params.js +67 -0
- package/src/utils/regex.js +9 -0
- package/src/utils/routing.js +145 -73
- package/src/utils/shared-iterator.js +5 -0
- package/src/utils/streaming.js +14 -4
- package/src/utils/url.js +33 -2
- package/src/version.js +1 -1
- package/types/index.d.ts +2291 -2135
- package/types/index.d.ts.map +116 -108
- package/src/core/sync/write_ambient.js +0 -18
- package/src/core/sync/write_root.js +0 -148
- package/src/core/sync/write_tsconfig.js +0 -250
- package/src/exports/internal/server.js +0 -22
- package/src/exports/node/polyfills.js +0 -30
- package/src/runtime/server/app.js +0 -9
- package/src/runtime/server/remote.js +0 -457
- package/src/runtime/shared-server.js +0 -7
- package/src/runtime/telemetry/otel.js +0 -21
- package/src/runtime/telemetry/record_span.js +0 -65
- package/src/types/synthetic/$lib.md +0 -5
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
- /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
|
|
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
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
76
|
-
|
|
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
|
-
|
|
80
|
-
|
|
208
|
+
return input;
|
|
209
|
+
}),
|
|
210
|
+
origin: validate(undefined, (input, keypath) => {
|
|
211
|
+
assert_string(input, keypath);
|
|
81
212
|
|
|
82
|
-
|
|
83
|
-
assert_string(input, keypath);
|
|
213
|
+
let url;
|
|
84
214
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
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
|
-
),
|
|
237
|
+
return origin;
|
|
238
|
+
}),
|
|
239
|
+
relative: boolean(true)
|
|
240
|
+
}),
|
|
267
241
|
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
} catch {
|
|
276
|
-
throw new Error(`${keypath} must be a valid origin`);
|
|
277
|
-
}
|
|
258
|
+
return input;
|
|
259
|
+
}),
|
|
278
260
|
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
|
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:
|
|
1
|
+
export type Validator<T = any> = (input: any, keypath: string) => T;
|