@sveltejs/kit 1.0.0-next.55 → 1.0.0-next.550
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/README.md +5 -2
- package/package.json +93 -67
- package/postinstall.js +47 -0
- package/scripts/special-types/$env+dynamic+private.md +10 -0
- package/scripts/special-types/$env+dynamic+public.md +8 -0
- package/scripts/special-types/$env+static+private.md +19 -0
- package/scripts/special-types/$env+static+public.md +7 -0
- package/scripts/special-types/$lib.md +5 -0
- package/src/cli.js +108 -0
- package/src/constants.js +5 -0
- package/src/core/adapt/builder.js +212 -0
- package/src/core/adapt/index.js +31 -0
- package/src/core/config/default-error.html +56 -0
- package/src/core/config/index.js +110 -0
- package/src/core/config/options.js +516 -0
- package/src/core/config/types.d.ts +1 -0
- package/src/core/env.js +121 -0
- package/src/core/generate_manifest/index.js +125 -0
- package/src/core/prerender/crawl.js +207 -0
- package/src/core/prerender/entities.js +2252 -0
- package/src/core/prerender/prerender.js +460 -0
- package/src/core/prerender/queue.js +80 -0
- package/src/core/sync/create_manifest_data/conflict.js +0 -0
- package/src/core/sync/create_manifest_data/index.js +513 -0
- package/src/core/sync/create_manifest_data/sort.js +161 -0
- package/src/core/sync/create_manifest_data/types.d.ts +37 -0
- package/src/core/sync/sync.js +78 -0
- package/src/core/sync/utils.js +33 -0
- package/src/core/sync/write_ambient.js +53 -0
- package/src/core/sync/write_client_manifest.js +106 -0
- package/src/core/sync/write_matchers.js +25 -0
- package/src/core/sync/write_root.js +91 -0
- package/src/core/sync/write_tsconfig.js +195 -0
- package/src/core/sync/write_types/index.js +809 -0
- package/src/core/utils.js +67 -0
- package/src/exports/hooks/index.js +1 -0
- package/src/exports/hooks/sequence.js +44 -0
- package/src/exports/index.js +45 -0
- package/src/exports/node/index.js +172 -0
- package/src/exports/node/polyfills.js +28 -0
- package/src/exports/vite/build/build_server.js +384 -0
- package/src/exports/vite/build/build_service_worker.js +92 -0
- package/src/exports/vite/build/utils.js +195 -0
- package/src/exports/vite/dev/index.js +588 -0
- package/src/exports/vite/graph_analysis/index.js +107 -0
- package/src/exports/vite/graph_analysis/types.d.ts +5 -0
- package/src/exports/vite/graph_analysis/utils.js +6 -0
- package/src/exports/vite/index.js +651 -0
- package/src/exports/vite/preview/index.js +193 -0
- package/src/exports/vite/types.d.ts +3 -0
- package/src/exports/vite/utils.js +171 -0
- package/src/runtime/app/env.js +1 -0
- package/src/runtime/app/environment.js +11 -0
- package/src/runtime/app/forms.js +141 -0
- package/src/runtime/app/navigation.js +23 -0
- package/src/runtime/app/paths.js +1 -0
- package/src/runtime/app/stores.js +102 -0
- package/src/runtime/client/ambient.d.ts +30 -0
- package/src/runtime/client/client.js +1726 -0
- package/src/runtime/client/fetcher.js +121 -0
- package/src/runtime/client/parse.js +60 -0
- package/src/runtime/client/singletons.js +21 -0
- package/src/runtime/client/start.js +43 -0
- package/src/runtime/client/types.d.ts +84 -0
- package/src/runtime/client/utils.js +166 -0
- package/src/runtime/components/error.svelte +16 -0
- package/{assets → src/runtime}/components/layout.svelte +0 -0
- package/src/runtime/control.js +98 -0
- package/src/runtime/env/dynamic/private.js +1 -0
- package/src/runtime/env/dynamic/public.js +1 -0
- package/src/runtime/env-private.js +6 -0
- package/src/runtime/env-public.js +6 -0
- package/src/runtime/env.js +6 -0
- package/src/runtime/hash.js +20 -0
- package/src/runtime/paths.js +11 -0
- package/src/runtime/server/cookie.js +231 -0
- package/src/runtime/server/data/index.js +144 -0
- package/src/runtime/server/endpoint.js +89 -0
- package/src/runtime/server/fetch.js +164 -0
- package/src/runtime/server/index.js +375 -0
- package/src/runtime/server/page/actions.js +258 -0
- package/src/runtime/server/page/crypto.js +239 -0
- package/src/runtime/server/page/csp.js +250 -0
- package/src/runtime/server/page/index.js +303 -0
- package/src/runtime/server/page/load_data.js +258 -0
- package/src/runtime/server/page/render.js +391 -0
- package/src/runtime/server/page/respond_with_error.js +102 -0
- package/src/runtime/server/page/serialize_data.js +87 -0
- package/src/runtime/server/page/types.d.ts +35 -0
- package/src/runtime/server/utils.js +205 -0
- package/src/utils/array.js +9 -0
- package/src/utils/error.js +22 -0
- package/src/utils/escape.js +46 -0
- package/src/utils/filesystem.js +166 -0
- package/src/utils/functions.js +16 -0
- package/src/utils/http.js +72 -0
- package/src/utils/misc.js +1 -0
- package/src/utils/promises.js +17 -0
- package/src/utils/routing.js +168 -0
- package/src/utils/unit_test.js +11 -0
- package/src/utils/url.js +159 -0
- package/svelte-kit.js +1 -1
- package/types/ambient.d.ts +469 -0
- package/types/index.d.ts +775 -0
- package/types/internal.d.ts +381 -0
- package/types/private.d.ts +229 -0
- package/CHANGELOG.md +0 -519
- package/assets/components/error.svelte +0 -13
- package/assets/runtime/app/env.js +0 -5
- package/assets/runtime/app/navigation.js +0 -48
- package/assets/runtime/app/paths.js +0 -1
- package/assets/runtime/app/stores.js +0 -93
- package/assets/runtime/chunks/utils.js +0 -22
- package/assets/runtime/internal/singletons.js +0 -23
- package/assets/runtime/internal/start.js +0 -823
- package/assets/runtime/paths.js +0 -12
- package/dist/chunks/index.js +0 -3544
- package/dist/chunks/index2.js +0 -572
- package/dist/chunks/index3.js +0 -246
- package/dist/chunks/index4.js +0 -569
- package/dist/chunks/index5.js +0 -751
- package/dist/chunks/index6.js +0 -323
- package/dist/chunks/standard.js +0 -99
- package/dist/chunks/utils.js +0 -83
- package/dist/cli.js +0 -558
- package/dist/ssr.js +0 -2620
- package/types.d.ts +0 -74
- package/types.internal.d.ts +0 -237
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<title>%sveltekit.error.message%</title>
|
|
6
|
+
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
|
|
10
|
+
Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
height: 100vh;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.error {
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
max-width: 32rem;
|
|
21
|
+
margin: 0 1rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.status {
|
|
25
|
+
font-weight: 200;
|
|
26
|
+
font-size: 3rem;
|
|
27
|
+
line-height: 1;
|
|
28
|
+
position: relative;
|
|
29
|
+
top: -0.05rem;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.message {
|
|
33
|
+
border-left: 1px solid #ccc;
|
|
34
|
+
padding: 0 0 0 1rem;
|
|
35
|
+
margin: 0 0 0 1rem;
|
|
36
|
+
min-height: 2.5rem;
|
|
37
|
+
display: flex;
|
|
38
|
+
align-items: center;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.message h1 {
|
|
42
|
+
font-weight: 400;
|
|
43
|
+
font-size: 1em;
|
|
44
|
+
margin: 0;
|
|
45
|
+
}
|
|
46
|
+
</style>
|
|
47
|
+
</head>
|
|
48
|
+
<body>
|
|
49
|
+
<div class="error">
|
|
50
|
+
<span class="status">%sveltekit.status%</span>
|
|
51
|
+
<div class="message">
|
|
52
|
+
<h1>%sveltekit.error.message%</h1>
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
</body>
|
|
56
|
+
</html>
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import * as url from 'url';
|
|
4
|
+
import options from './options.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Loads the template (src/app.html by default) and validates that it has the
|
|
8
|
+
* required content.
|
|
9
|
+
* @param {string} cwd
|
|
10
|
+
* @param {import('types').ValidatedConfig} config
|
|
11
|
+
*/
|
|
12
|
+
export function load_template(cwd, config) {
|
|
13
|
+
const { appTemplate } = config.kit.files;
|
|
14
|
+
const relative = path.relative(cwd, appTemplate);
|
|
15
|
+
|
|
16
|
+
if (fs.existsSync(appTemplate)) {
|
|
17
|
+
const contents = fs.readFileSync(appTemplate, 'utf8');
|
|
18
|
+
|
|
19
|
+
// TODO remove this for 1.0
|
|
20
|
+
const match = /%svelte\.([a-z]+)%/.exec(contents);
|
|
21
|
+
if (match) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`%svelte.${match[1]}% in ${relative} should be replaced with %sveltekit.${match[1]}%`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const expected_tags = ['%sveltekit.head%', '%sveltekit.body%'];
|
|
28
|
+
expected_tags.forEach((tag) => {
|
|
29
|
+
if (contents.indexOf(tag) === -1) {
|
|
30
|
+
throw new Error(`${relative} is missing ${tag}`);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
throw new Error(`${relative} does not exist`);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return fs.readFileSync(appTemplate, 'utf-8');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Loads the error page (src/error.html by default) if it exists.
|
|
42
|
+
* Falls back to a generic error page content.
|
|
43
|
+
* @param {import('types').ValidatedConfig} config
|
|
44
|
+
*/
|
|
45
|
+
export function load_error_page(config) {
|
|
46
|
+
const { errorTemplate } = config.kit.files;
|
|
47
|
+
return fs.readFileSync(errorTemplate, 'utf-8');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Loads and validates svelte.config.js
|
|
52
|
+
* @param {{ cwd?: string }} options
|
|
53
|
+
* @returns {Promise<import('types').ValidatedConfig>}
|
|
54
|
+
*/
|
|
55
|
+
export async function load_config({ cwd = process.cwd() } = {}) {
|
|
56
|
+
const config_file = path.join(cwd, 'svelte.config.js');
|
|
57
|
+
|
|
58
|
+
if (!fs.existsSync(config_file)) {
|
|
59
|
+
return process_config({}, { cwd });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const config = await import(`${url.pathToFileURL(config_file).href}?ts=${Date.now()}`);
|
|
63
|
+
|
|
64
|
+
return process_config(config.default, { cwd });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {import('types').Config} config
|
|
69
|
+
* @returns {import('types').ValidatedConfig}
|
|
70
|
+
*/
|
|
71
|
+
function process_config(config, { cwd = process.cwd() } = {}) {
|
|
72
|
+
const validated = validate_config(config);
|
|
73
|
+
|
|
74
|
+
validated.kit.outDir = path.resolve(cwd, validated.kit.outDir);
|
|
75
|
+
|
|
76
|
+
for (const key in validated.kit.files) {
|
|
77
|
+
// TODO remove for 1.0
|
|
78
|
+
if (key === 'template') continue;
|
|
79
|
+
|
|
80
|
+
if (key === 'hooks') {
|
|
81
|
+
validated.kit.files.hooks.client = path.resolve(cwd, validated.kit.files.hooks.client);
|
|
82
|
+
validated.kit.files.hooks.server = path.resolve(cwd, validated.kit.files.hooks.server);
|
|
83
|
+
} else {
|
|
84
|
+
// @ts-expect-error
|
|
85
|
+
validated.kit.files[key] = path.resolve(cwd, validated.kit.files[key]);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!fs.existsSync(validated.kit.files.errorTemplate)) {
|
|
90
|
+
validated.kit.files.errorTemplate = url.fileURLToPath(
|
|
91
|
+
new URL('./default-error.html', import.meta.url)
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return validated;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {import('types').Config} config
|
|
100
|
+
* @returns {import('types').ValidatedConfig}
|
|
101
|
+
*/
|
|
102
|
+
export function validate_config(config) {
|
|
103
|
+
if (typeof config !== 'object') {
|
|
104
|
+
throw new Error(
|
|
105
|
+
'svelte.config.js must have a configuration object as its default export. See https://kit.svelte.dev/docs/configuration'
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return options(config, 'config');
|
|
110
|
+
}
|
|
@@ -0,0 +1,516 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
|
|
3
|
+
/** @typedef {import('./types').Validator} Validator */
|
|
4
|
+
|
|
5
|
+
const directives = object({
|
|
6
|
+
'child-src': string_array(),
|
|
7
|
+
'default-src': string_array(),
|
|
8
|
+
'frame-src': string_array(),
|
|
9
|
+
'worker-src': string_array(),
|
|
10
|
+
'connect-src': string_array(),
|
|
11
|
+
'font-src': string_array(),
|
|
12
|
+
'img-src': string_array(),
|
|
13
|
+
'manifest-src': string_array(),
|
|
14
|
+
'media-src': string_array(),
|
|
15
|
+
'object-src': string_array(),
|
|
16
|
+
'prefetch-src': string_array(),
|
|
17
|
+
'script-src': string_array(),
|
|
18
|
+
'script-src-elem': string_array(),
|
|
19
|
+
'script-src-attr': string_array(),
|
|
20
|
+
'style-src': string_array(),
|
|
21
|
+
'style-src-elem': string_array(),
|
|
22
|
+
'style-src-attr': string_array(),
|
|
23
|
+
'base-uri': string_array(),
|
|
24
|
+
sandbox: string_array(),
|
|
25
|
+
'form-action': string_array(),
|
|
26
|
+
'frame-ancestors': string_array(),
|
|
27
|
+
'navigate-to': string_array(),
|
|
28
|
+
'report-uri': string_array(),
|
|
29
|
+
'report-to': string_array(),
|
|
30
|
+
'require-trusted-types-for': string_array(),
|
|
31
|
+
'trusted-types': string_array(),
|
|
32
|
+
'upgrade-insecure-requests': boolean(false),
|
|
33
|
+
'require-sri-for': string_array(),
|
|
34
|
+
'block-all-mixed-content': boolean(false),
|
|
35
|
+
'plugin-types': string_array(),
|
|
36
|
+
referrer: string_array()
|
|
37
|
+
});
|
|
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`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
input.forEach((extension) => {
|
|
48
|
+
if (extension[0] !== '.') {
|
|
49
|
+
throw new Error(`Each member of ${keypath} must start with '.' — saw '${extension}'`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!/^(\.[a-z0-9]+)+$/i.test(extension)) {
|
|
53
|
+
throw new Error(`File extensions must be alphanumeric — saw '${extension}'`);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return input;
|
|
58
|
+
}),
|
|
59
|
+
|
|
60
|
+
kit: object({
|
|
61
|
+
adapter: validate(null, (input, keypath) => {
|
|
62
|
+
if (typeof input !== 'object' || !input.adapt) {
|
|
63
|
+
let message = `${keypath} should be an object with an "adapt" method`;
|
|
64
|
+
|
|
65
|
+
if (Array.isArray(input) || typeof input === 'string') {
|
|
66
|
+
// for the early adapter adopters
|
|
67
|
+
message += ', rather than the name of an adapter';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
throw new Error(`${message}. See https://kit.svelte.dev/docs/adapters`);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return input;
|
|
74
|
+
}),
|
|
75
|
+
|
|
76
|
+
alias: validate({}, (input, keypath) => {
|
|
77
|
+
if (typeof input !== 'object') {
|
|
78
|
+
throw new Error(`${keypath} should be an object`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
for (const key in input) {
|
|
82
|
+
assert_string(input[key], `${keypath}.${key}`);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return input;
|
|
86
|
+
}),
|
|
87
|
+
|
|
88
|
+
// TODO: remove this for the 1.0 release
|
|
89
|
+
amp: error(
|
|
90
|
+
(keypath) =>
|
|
91
|
+
`${keypath} has been removed. See https://kit.svelte.dev/docs/seo#manual-setup-amp for details on how to support AMP`
|
|
92
|
+
),
|
|
93
|
+
|
|
94
|
+
appDir: validate('_app', (input, keypath) => {
|
|
95
|
+
assert_string(input, keypath);
|
|
96
|
+
|
|
97
|
+
if (input) {
|
|
98
|
+
if (input.startsWith('/') || input.endsWith('/')) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
"config.kit.appDir cannot start or end with '/'. See https://kit.svelte.dev/docs/configuration"
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
throw new Error(`${keypath} cannot be empty`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return input;
|
|
108
|
+
}),
|
|
109
|
+
|
|
110
|
+
// TODO: remove this for the 1.0 release
|
|
111
|
+
browser: object({
|
|
112
|
+
hydrate: error(
|
|
113
|
+
(keypath) =>
|
|
114
|
+
`${keypath} has been removed. You can set \`export const csr = false\` inside the top level +layout.js instead. See the PR for more information: https://github.com/sveltejs/kit/pull/6197`
|
|
115
|
+
),
|
|
116
|
+
router: error(
|
|
117
|
+
(keypath) =>
|
|
118
|
+
`${keypath} has been removed. You can set \`export const csr = false\` inside the top level +layout.js instead. See the PR for more information: https://github.com/sveltejs/kit/pull/6197`
|
|
119
|
+
)
|
|
120
|
+
}),
|
|
121
|
+
|
|
122
|
+
csp: object({
|
|
123
|
+
mode: list(['auto', 'hash', 'nonce']),
|
|
124
|
+
directives,
|
|
125
|
+
reportOnly: directives
|
|
126
|
+
}),
|
|
127
|
+
|
|
128
|
+
csrf: object({
|
|
129
|
+
checkOrigin: boolean(true)
|
|
130
|
+
}),
|
|
131
|
+
|
|
132
|
+
// TODO: remove this for the 1.0 release
|
|
133
|
+
endpointExtensions: error(
|
|
134
|
+
(keypath) => `${keypath} has been renamed to config.kit.moduleExtensions`
|
|
135
|
+
),
|
|
136
|
+
|
|
137
|
+
env: object({
|
|
138
|
+
dir: string(process.cwd()),
|
|
139
|
+
publicPrefix: string('PUBLIC_')
|
|
140
|
+
}),
|
|
141
|
+
|
|
142
|
+
files: object({
|
|
143
|
+
assets: string('static'),
|
|
144
|
+
hooks: (input, keypath) => {
|
|
145
|
+
// TODO remove this for the 1.0 release
|
|
146
|
+
if (typeof input === 'string') {
|
|
147
|
+
throw new Error(
|
|
148
|
+
`${keypath} is an object with { server: string, client: string } now. See the PR for more information: https://github.com/sveltejs/kit/pull/6586`
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return object({
|
|
153
|
+
client: string(join('src', 'hooks.client')),
|
|
154
|
+
server: string(join('src', 'hooks.server'))
|
|
155
|
+
})(input, keypath);
|
|
156
|
+
},
|
|
157
|
+
lib: string(join('src', 'lib')),
|
|
158
|
+
params: string(join('src', 'params')),
|
|
159
|
+
routes: string(join('src', 'routes')),
|
|
160
|
+
serviceWorker: string(join('src', 'service-worker')),
|
|
161
|
+
appTemplate: string(join('src', 'app.html')),
|
|
162
|
+
errorTemplate: string(join('src', 'error.html')),
|
|
163
|
+
// TODO: remove this for the 1.0 release
|
|
164
|
+
template: error(
|
|
165
|
+
() => 'config.kit.files.template has been renamed to config.kit.files.appTemplate'
|
|
166
|
+
)
|
|
167
|
+
}),
|
|
168
|
+
|
|
169
|
+
// TODO: remove this for the 1.0 release
|
|
170
|
+
headers: error(
|
|
171
|
+
(keypath) =>
|
|
172
|
+
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
|
|
173
|
+
),
|
|
174
|
+
|
|
175
|
+
// TODO: remove this for the 1.0 release
|
|
176
|
+
host: error(
|
|
177
|
+
(keypath) =>
|
|
178
|
+
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
|
|
179
|
+
),
|
|
180
|
+
|
|
181
|
+
// TODO remove for 1.0
|
|
182
|
+
hydrate: error((keypath) => `${keypath} has been moved to config.kit.browser.hydrate`),
|
|
183
|
+
|
|
184
|
+
inlineStyleThreshold: number(0),
|
|
185
|
+
|
|
186
|
+
methodOverride: error(
|
|
187
|
+
() =>
|
|
188
|
+
'Method overrides have been removed in favor of actions. See the PR for more information: https://github.com/sveltejs/kit/pull/6469'
|
|
189
|
+
),
|
|
190
|
+
|
|
191
|
+
moduleExtensions: string_array(['.js', '.ts']),
|
|
192
|
+
|
|
193
|
+
outDir: string('.svelte-kit'),
|
|
194
|
+
|
|
195
|
+
package: error((keypath) => `${keypath} has been removed — use @sveltejs/package instead`),
|
|
196
|
+
|
|
197
|
+
paths: object({
|
|
198
|
+
base: validate('', (input, keypath) => {
|
|
199
|
+
assert_string(input, keypath);
|
|
200
|
+
|
|
201
|
+
if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
|
|
202
|
+
throw new Error(
|
|
203
|
+
`${keypath} option must either be the empty string or a root-relative path that starts but doesn't end with '/'. See https://kit.svelte.dev/docs/configuration#paths`
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return input;
|
|
208
|
+
}),
|
|
209
|
+
assets: validate('', (input, keypath) => {
|
|
210
|
+
assert_string(input, keypath);
|
|
211
|
+
|
|
212
|
+
if (input) {
|
|
213
|
+
if (!/^[a-z]+:\/\//.test(input)) {
|
|
214
|
+
throw new Error(
|
|
215
|
+
`${keypath} option must be an absolute path, if specified. See https://kit.svelte.dev/docs/configuration#paths`
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (input.endsWith('/')) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
`${keypath} option must not end with '/'. See https://kit.svelte.dev/docs/configuration#paths`
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return input;
|
|
227
|
+
})
|
|
228
|
+
}),
|
|
229
|
+
|
|
230
|
+
prerender: object({
|
|
231
|
+
concurrency: number(1),
|
|
232
|
+
crawl: boolean(true),
|
|
233
|
+
createIndexFiles: error(
|
|
234
|
+
(keypath) =>
|
|
235
|
+
`${keypath} has been removed — it is now controlled by the trailingSlash option. See https://kit.svelte.dev/docs/configuration#trailingslash`
|
|
236
|
+
),
|
|
237
|
+
default: error(
|
|
238
|
+
(keypath) =>
|
|
239
|
+
`${keypath} has been removed. You can set it inside the top level +layout.js instead. See the PR for more information: https://github.com/sveltejs/kit/pull/6197`
|
|
240
|
+
),
|
|
241
|
+
enabled: boolean(true),
|
|
242
|
+
entries: validate(['*'], (input, keypath) => {
|
|
243
|
+
if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
|
|
244
|
+
throw new Error(`${keypath} must be an array of strings`);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
input.forEach((page) => {
|
|
248
|
+
if (page !== '*' && page[0] !== '/') {
|
|
249
|
+
throw new Error(
|
|
250
|
+
`Each member of ${keypath} must be either '*' or an absolute path beginning with '/' — saw '${page}'`
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
return input;
|
|
256
|
+
}),
|
|
257
|
+
|
|
258
|
+
// TODO: remove this for the 1.0 release
|
|
259
|
+
force: validate(undefined, (input, keypath) => {
|
|
260
|
+
const new_input = input ? 'warn' : 'fail';
|
|
261
|
+
const needs_option = new_input === 'warn';
|
|
262
|
+
throw new Error(
|
|
263
|
+
`${keypath} has been removed in favor of \`handleHttpError\`. In your case, set \`handleHttpError\` to "${new_input}"${
|
|
264
|
+
needs_option ? '' : ' (or leave it undefined)'
|
|
265
|
+
} to get the same behavior as you would with \`force: ${JSON.stringify(input)}\``
|
|
266
|
+
);
|
|
267
|
+
}),
|
|
268
|
+
|
|
269
|
+
handleHttpError: validate('fail', (input, keypath) => {
|
|
270
|
+
if (typeof input === 'function') return input;
|
|
271
|
+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
272
|
+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
273
|
+
}),
|
|
274
|
+
|
|
275
|
+
handleMissingId: validate('fail', (input, keypath) => {
|
|
276
|
+
if (typeof input === 'function') return input;
|
|
277
|
+
if (['fail', 'warn', 'ignore'].includes(input)) return input;
|
|
278
|
+
throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
|
|
279
|
+
}),
|
|
280
|
+
|
|
281
|
+
// TODO: remove this for the 1.0 release
|
|
282
|
+
onError: validate(undefined, (input, keypath) => {
|
|
283
|
+
let message = `${keypath} has been renamed to \`handleHttpError\``;
|
|
284
|
+
|
|
285
|
+
if (input === 'continue') {
|
|
286
|
+
message += ', and "continue" has been renamed to "warn"';
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
throw new Error(message);
|
|
290
|
+
}),
|
|
291
|
+
|
|
292
|
+
origin: validate('http://sveltekit-prerender', (input, keypath) => {
|
|
293
|
+
assert_string(input, keypath);
|
|
294
|
+
|
|
295
|
+
let origin;
|
|
296
|
+
|
|
297
|
+
try {
|
|
298
|
+
origin = new URL(input).origin;
|
|
299
|
+
} catch (e) {
|
|
300
|
+
throw new Error(`${keypath} must be a valid origin`);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if (input !== origin) {
|
|
304
|
+
throw new Error(`${keypath} must be a valid origin (${origin} rather than ${input})`);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return origin;
|
|
308
|
+
}),
|
|
309
|
+
|
|
310
|
+
// TODO: remove this for the 1.0 release
|
|
311
|
+
pages: error((keypath) => `${keypath} has been renamed to \`entries\`.`)
|
|
312
|
+
}),
|
|
313
|
+
|
|
314
|
+
// TODO: remove this for the 1.0 release
|
|
315
|
+
protocol: error(
|
|
316
|
+
(keypath) =>
|
|
317
|
+
`${keypath} has been removed. See https://github.com/sveltejs/kit/pull/3384 for details`
|
|
318
|
+
),
|
|
319
|
+
|
|
320
|
+
// TODO remove for 1.0
|
|
321
|
+
router: error(
|
|
322
|
+
(keypath) =>
|
|
323
|
+
`${keypath} has been removed. You can set \`export const csr = false\` inside the top level +layout.js instead. See the PR for more information: https://github.com/sveltejs/kit/pull/6197`
|
|
324
|
+
),
|
|
325
|
+
|
|
326
|
+
// TODO remove for 1.0
|
|
327
|
+
routes: error(
|
|
328
|
+
(keypath) =>
|
|
329
|
+
`${keypath} has been removed. See https://github.com/sveltejs/kit/discussions/5774 for details`
|
|
330
|
+
),
|
|
331
|
+
|
|
332
|
+
serviceWorker: object({
|
|
333
|
+
register: boolean(true),
|
|
334
|
+
files: fun((filename) => !/\.DS_Store/.test(filename))
|
|
335
|
+
}),
|
|
336
|
+
|
|
337
|
+
// TODO remove this for 1.0
|
|
338
|
+
ssr: error(
|
|
339
|
+
(keypath) =>
|
|
340
|
+
`${keypath} has been removed — use the handle hook instead: https://kit.svelte.dev/docs/hooks#server-hooks-handle`
|
|
341
|
+
),
|
|
342
|
+
|
|
343
|
+
// TODO remove this for 1.0
|
|
344
|
+
target: error((keypath) => `${keypath} is no longer required, and should be removed`),
|
|
345
|
+
|
|
346
|
+
trailingSlash: list(['never', 'always', 'ignore']),
|
|
347
|
+
|
|
348
|
+
version: object({
|
|
349
|
+
name: string(Date.now().toString()),
|
|
350
|
+
pollInterval: number(0)
|
|
351
|
+
}),
|
|
352
|
+
|
|
353
|
+
// TODO remove this for 1.0
|
|
354
|
+
vite: error((keypath) => `${keypath} has been removed — use vite.config.js instead`)
|
|
355
|
+
})
|
|
356
|
+
},
|
|
357
|
+
true
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* @param {Record<string, Validator>} children
|
|
362
|
+
* @param {boolean} [allow_unknown]
|
|
363
|
+
* @returns {Validator}
|
|
364
|
+
*/
|
|
365
|
+
function object(children, allow_unknown = false) {
|
|
366
|
+
return (input, keypath) => {
|
|
367
|
+
/** @type {Record<string, any>} */
|
|
368
|
+
const output = {};
|
|
369
|
+
|
|
370
|
+
if ((input && typeof input !== 'object') || Array.isArray(input)) {
|
|
371
|
+
throw new Error(`${keypath} should be an object`);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
for (const key in input) {
|
|
375
|
+
if (!(key in children)) {
|
|
376
|
+
if (allow_unknown) {
|
|
377
|
+
output[key] = input[key];
|
|
378
|
+
} else {
|
|
379
|
+
let message = `Unexpected option ${keypath}.${key}`;
|
|
380
|
+
|
|
381
|
+
// special case
|
|
382
|
+
if (keypath === 'config.kit' && key in options) {
|
|
383
|
+
message += ` (did you mean config.${key}?)`;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
throw new Error(message);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
for (const key in children) {
|
|
392
|
+
const validator = children[key];
|
|
393
|
+
output[key] = validator(input && input[key], `${keypath}.${key}`);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return output;
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* @param {any} fallback
|
|
402
|
+
* @param {(value: any, keypath: string) => any} fn
|
|
403
|
+
* @returns {Validator}
|
|
404
|
+
*/
|
|
405
|
+
function validate(fallback, fn) {
|
|
406
|
+
return (input, keypath) => {
|
|
407
|
+
return input === undefined ? fallback : fn(input, keypath);
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* @param {string | null} fallback
|
|
413
|
+
* @param {boolean} allow_empty
|
|
414
|
+
* @returns {Validator}
|
|
415
|
+
*/
|
|
416
|
+
function string(fallback, allow_empty = true) {
|
|
417
|
+
return validate(fallback, (input, keypath) => {
|
|
418
|
+
assert_string(input, keypath);
|
|
419
|
+
|
|
420
|
+
if (!allow_empty && input === '') {
|
|
421
|
+
throw new Error(`${keypath} cannot be empty`);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
return input;
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* @param {string[] | undefined} [fallback]
|
|
430
|
+
* @returns {Validator}
|
|
431
|
+
*/
|
|
432
|
+
function string_array(fallback) {
|
|
433
|
+
return validate(fallback, (input, keypath) => {
|
|
434
|
+
if (!Array.isArray(input) || input.some((value) => typeof value !== 'string')) {
|
|
435
|
+
throw new Error(`${keypath} must be an array of strings, if specified`);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
return input;
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* @param {number} fallback
|
|
444
|
+
* @returns {Validator}
|
|
445
|
+
*/
|
|
446
|
+
function number(fallback) {
|
|
447
|
+
return validate(fallback, (input, keypath) => {
|
|
448
|
+
if (typeof input !== 'number') {
|
|
449
|
+
throw new Error(`${keypath} should be a number, if specified`);
|
|
450
|
+
}
|
|
451
|
+
return input;
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* @param {boolean} fallback
|
|
457
|
+
* @returns {Validator}
|
|
458
|
+
*/
|
|
459
|
+
function boolean(fallback) {
|
|
460
|
+
return validate(fallback, (input, keypath) => {
|
|
461
|
+
if (typeof input !== 'boolean') {
|
|
462
|
+
throw new Error(`${keypath} should be true or false, if specified`);
|
|
463
|
+
}
|
|
464
|
+
return input;
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* @param {string[]} options
|
|
470
|
+
* @returns {Validator}
|
|
471
|
+
*/
|
|
472
|
+
function list(options, fallback = options[0]) {
|
|
473
|
+
return validate(fallback, (input, keypath) => {
|
|
474
|
+
if (!options.includes(input)) {
|
|
475
|
+
// prettier-ignore
|
|
476
|
+
const msg = options.length > 2
|
|
477
|
+
? `${keypath} should be one of ${options.slice(0, -1).map(input => `"${input}"`).join(', ')} or "${options[options.length - 1]}"`
|
|
478
|
+
: `${keypath} should be either "${options[0]}" or "${options[1]}"`;
|
|
479
|
+
|
|
480
|
+
throw new Error(msg);
|
|
481
|
+
}
|
|
482
|
+
return input;
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* @param {(filename: string) => boolean} fallback
|
|
488
|
+
* @returns {Validator}
|
|
489
|
+
*/
|
|
490
|
+
function fun(fallback) {
|
|
491
|
+
return validate(fallback, (input, keypath) => {
|
|
492
|
+
if (typeof input !== 'function') {
|
|
493
|
+
throw new Error(`${keypath} should be a function, if specified`);
|
|
494
|
+
}
|
|
495
|
+
return input;
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* @param {string} input
|
|
501
|
+
* @param {string} keypath
|
|
502
|
+
*/
|
|
503
|
+
function assert_string(input, keypath) {
|
|
504
|
+
if (typeof input !== 'string') {
|
|
505
|
+
throw new Error(`${keypath} should be a string, if specified`);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/** @param {(keypath?: string) => string} fn */
|
|
510
|
+
function error(fn) {
|
|
511
|
+
return validate(undefined, (_, keypath) => {
|
|
512
|
+
throw new Error(fn(keypath));
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
export default options;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Validator<T = any> = (input: T, keypath: string) => T;
|