@sveltejs/kit 2.62.0 → 3.0.0-next.0
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 +28 -22
- package/src/cli.js +49 -20
- package/src/core/adapt/builder.js +38 -69
- package/src/core/adapt/index.js +11 -6
- package/src/core/config/index.js +12 -82
- package/src/core/config/options.js +36 -45
- package/src/core/env.js +240 -60
- package/src/core/generate_manifest/find_server_assets.js +3 -2
- package/src/core/generate_manifest/index.js +11 -3
- package/src/core/postbuild/analyse.js +20 -16
- package/src/core/postbuild/fallback.js +0 -3
- package/src/core/postbuild/prerender.js +19 -17
- package/src/core/postbuild/queue.js +3 -4
- package/src/core/sync/create_manifest_data/index.js +16 -18
- package/src/core/sync/sync.js +44 -23
- package/src/core/sync/utils.js +0 -15
- package/src/core/sync/write_ambient.js +5 -50
- package/src/core/sync/write_client_manifest.js +8 -9
- package/src/core/sync/write_env.js +36 -0
- package/src/core/sync/write_non_ambient.js +7 -7
- package/src/core/sync/write_root.js +41 -89
- package/src/core/sync/write_server.js +18 -24
- package/src/core/sync/write_tsconfig.js +29 -24
- package/src/core/sync/write_types/index.js +31 -25
- package/src/core/utils.js +14 -11
- package/src/exports/hooks/index.js +13 -0
- package/src/exports/index.js +8 -21
- package/src/exports/internal/env.js +71 -0
- package/src/exports/internal/types.d.ts +3 -0
- package/src/exports/node/index.js +8 -13
- package/src/exports/public.d.ts +68 -69
- package/src/exports/vite/build/build_server.js +14 -11
- package/src/exports/vite/build/remote.js +6 -7
- package/src/exports/vite/build/utils.js +7 -5
- package/src/exports/vite/dev/index.js +32 -33
- package/src/exports/vite/index.js +1015 -711
- package/src/exports/vite/module_ids.js +10 -6
- package/src/exports/vite/options.js +17 -0
- package/src/exports/vite/preview/index.js +3 -5
- package/src/exports/vite/static_analysis/index.js +11 -5
- package/src/exports/vite/utils.js +11 -41
- package/src/runtime/app/env/index.js +2 -0
- package/src/runtime/app/env/internal.js +14 -0
- package/src/runtime/app/env/private.js +1 -0
- package/src/runtime/app/env/public/client.js +1 -0
- package/src/runtime/app/env/public/index.js +1 -0
- package/src/runtime/app/env/public/server.js +1 -0
- package/src/runtime/app/env/standard-schema.d.ts +0 -0
- package/src/runtime/app/server/index.js +4 -2
- package/src/runtime/app/server/remote/form.js +0 -51
- package/src/runtime/app/server/remote/query.js +1 -8
- package/src/runtime/app/server/remote/shared.js +4 -3
- package/src/runtime/app/state/client.js +1 -12
- package/src/runtime/client/client.js +1 -1
- package/src/runtime/client/constants.js +0 -1
- package/src/runtime/client/remote-functions/form.svelte.js +0 -31
- package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
- package/src/runtime/client/remote-functions/query/index.js +2 -2
- package/src/runtime/client/remote-functions/query/instance.svelte.js +1 -2
- package/src/runtime/client/remote-functions/query-batch.svelte.js +2 -2
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +5 -8
- package/src/runtime/client/utils.js +9 -11
- package/src/runtime/components/{svelte-5/layout.svelte → layout.svelte} +1 -1
- package/src/runtime/form-utils.js +4 -41
- package/src/runtime/server/cookie.js +21 -37
- package/src/runtime/server/env_module.js +12 -4
- package/src/runtime/server/fetch.js +6 -10
- package/src/runtime/server/index.js +5 -9
- package/src/runtime/server/page/render.js +33 -37
- package/src/runtime/server/page/types.d.ts +4 -2
- package/src/runtime/server/respond.js +3 -3
- package/src/runtime/server/utils.js +2 -4
- package/src/runtime/shared-server.js +0 -22
- package/src/runtime/shared.js +0 -15
- package/src/types/ambient-private.d.ts +25 -9
- package/src/types/global-private.d.ts +6 -0
- package/src/types/internal.d.ts +4 -8
- package/src/utils/css.js +3 -19
- package/src/utils/filesystem.js +1 -30
- package/src/utils/http.js +0 -21
- package/src/utils/import.js +8 -7
- package/src/utils/os.js +7 -0
- package/src/utils/path.js +23 -0
- package/src/utils/shared-iterator.js +3 -0
- package/src/utils/streaming.js +2 -4
- package/src/utils/url.js +1 -1
- package/src/utils/vite.js +28 -0
- package/src/version.js +1 -1
- package/types/index.d.ts +85 -109
- package/types/index.d.ts.map +5 -6
- package/src/exports/vite/build/build_service_worker.js +0 -149
- package/src/runtime/app/environment/index.js +0 -2
- package/src/runtime/components/svelte-4/error.svelte +0 -6
- package/src/runtime/components/svelte-4/layout.svelte +0 -1
- package/src/runtime/env/dynamic/private.js +0 -1
- package/src/runtime/env/dynamic/public.js +0 -1
- package/src/types/synthetic/$env+dynamic+private.md +0 -43
- package/src/types/synthetic/$env+dynamic+public.md +0 -46
- package/src/types/synthetic/$env+static+private.md +0 -31
- package/src/types/synthetic/$env+static+public.md +0 -31
- package/src/utils/env.js +0 -13
- package/src/utils/promise.js +0 -29
- /package/src/runtime/app/{environment → env}/types.d.ts +0 -0
- /package/src/runtime/components/{svelte-5/error.svelte → error.svelte} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { dedent,
|
|
1
|
+
import { dedent, write_if_changed } from './utils.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* @param {import('types').ManifestData} manifest_data
|
|
@@ -8,7 +8,7 @@ import { dedent, isSvelte5Plus, write_if_changed } from './utils.js';
|
|
|
8
8
|
export function write_root(manifest_data, config, output) {
|
|
9
9
|
// TODO remove default layout altogether
|
|
10
10
|
|
|
11
|
-
const use_boundaries = config.kit.experimental.handleRenderingErrors
|
|
11
|
+
const use_boundaries = config.kit.experimental.handleRenderingErrors;
|
|
12
12
|
|
|
13
13
|
const max_depth = Math.max(
|
|
14
14
|
...manifest_data.routes.map((route) =>
|
|
@@ -26,7 +26,7 @@ export function write_root(manifest_data, config, output) {
|
|
|
26
26
|
/** @type {string} */
|
|
27
27
|
let pyramid;
|
|
28
28
|
|
|
29
|
-
if (
|
|
29
|
+
if (use_boundaries) {
|
|
30
30
|
// with the @const we force the data[depth] access to be derived, which is important to not fire updates needlessly
|
|
31
31
|
// TODO in Svelte 5 we should rethink the client.js side, we can likely make data a $state and only update indexes that changed there, simplifying this a lot
|
|
32
32
|
pyramid = dedent`
|
|
@@ -55,39 +55,21 @@ export function write_root(manifest_data, config, output) {
|
|
|
55
55
|
`;
|
|
56
56
|
} else {
|
|
57
57
|
pyramid = dedent`
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
? `<!-- svelte-ignore binding_property_non_reactive -->
|
|
61
|
-
<Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} params={page.params} />`
|
|
62
|
-
: `<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} {form} params={page.params} />`
|
|
63
|
-
}`;
|
|
58
|
+
<!-- svelte-ignore binding_property_non_reactive -->
|
|
59
|
+
<Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} params={page.params} />`;
|
|
64
60
|
|
|
65
61
|
while (l--) {
|
|
66
62
|
pyramid = dedent`
|
|
67
63
|
{#if constructors[${l + 1}]}
|
|
68
|
-
${
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
<!-- svelte-ignore binding_property_non_reactive -->
|
|
72
|
-
<Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} params={page.params}>
|
|
73
|
-
${pyramid}
|
|
74
|
-
</Pyramid_${l}>`
|
|
75
|
-
: dedent`<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} params={page.params}>
|
|
64
|
+
{@const Pyramid_${l} = constructors[${l}]}
|
|
65
|
+
<!-- svelte-ignore binding_property_non_reactive -->
|
|
66
|
+
<Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} params={page.params}>
|
|
76
67
|
${pyramid}
|
|
77
|
-
</
|
|
78
|
-
}
|
|
79
|
-
|
|
68
|
+
</Pyramid_${l}>
|
|
80
69
|
{:else}
|
|
81
|
-
${
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
{@const Pyramid_${l} = constructors[${l}]}
|
|
85
|
-
<!-- svelte-ignore binding_property_non_reactive -->
|
|
86
|
-
<Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} params={page.params} />
|
|
87
|
-
`
|
|
88
|
-
: dedent`<svelte:component this={constructors[${l}]} bind:this={components[${l}]} data={data_${l}} {form} params={page.params} />`
|
|
89
|
-
}
|
|
90
|
-
|
|
70
|
+
{@const Pyramid_${l} = constructors[${l}]}
|
|
71
|
+
<!-- svelte-ignore binding_property_non_reactive -->
|
|
72
|
+
<Pyramid_${l} bind:this={components[${l}]} data={data_${l}} {form} params={page.params} />
|
|
91
73
|
{/if}
|
|
92
74
|
`;
|
|
93
75
|
}
|
|
@@ -97,62 +79,34 @@ export function write_root(manifest_data, config, output) {
|
|
|
97
79
|
`${output}/root.svelte`,
|
|
98
80
|
dedent`
|
|
99
81
|
<!-- This file is generated by @sveltejs/kit — do not edit it! -->
|
|
100
|
-
|
|
82
|
+
<svelte:options runes={true} />
|
|
101
83
|
<script>
|
|
102
|
-
import { setContext,
|
|
103
|
-
import { browser } from '$app/
|
|
84
|
+
import { setContext, onMount, tick } from 'svelte';
|
|
85
|
+
import { browser } from '$app/env';
|
|
104
86
|
|
|
105
87
|
// stores
|
|
106
|
-
${
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
: dedent`
|
|
115
|
-
export let stores;
|
|
116
|
-
export let page;
|
|
117
|
-
|
|
118
|
-
export let constructors;
|
|
119
|
-
export let components = [];
|
|
120
|
-
export let form;
|
|
121
|
-
${levels.map((l) => `export let data_${l} = null;`).join('\n')}
|
|
122
|
-
`
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
if (!browser) {
|
|
88
|
+
let { stores, page, constructors, components = [], form, ${use_boundaries ? 'errors = [], error, ' : ''}${levels
|
|
89
|
+
.map((l) => `data_${l} = null`)
|
|
90
|
+
.join(', ')} } = $props();
|
|
91
|
+
${use_boundaries ? `let data = $derived({${levels.map((l) => `'${l}': data_${l}`).join(', ')}})` : ''}
|
|
92
|
+
|
|
93
|
+
if (browser) {
|
|
94
|
+
$effect.pre(() => stores.page.set(page));
|
|
95
|
+
} else {
|
|
126
96
|
// svelte-ignore state_referenced_locally
|
|
127
97
|
setContext('__svelte__', stores);
|
|
98
|
+
// svelte-ignore state_referenced_locally
|
|
99
|
+
stores.page.set(page);
|
|
128
100
|
}
|
|
129
101
|
|
|
130
|
-
${
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
$effect.pre(() => stores.page.set(page));
|
|
135
|
-
} else {
|
|
136
|
-
// svelte-ignore state_referenced_locally
|
|
137
|
-
stores.page.set(page);
|
|
138
|
-
}
|
|
139
|
-
`
|
|
140
|
-
: '$: stores.page.set(page);'
|
|
141
|
-
}
|
|
142
|
-
${
|
|
143
|
-
isSvelte5Plus()
|
|
144
|
-
? dedent`
|
|
145
|
-
$effect(() => {
|
|
146
|
-
stores;page;constructors;components;form;${use_boundaries ? 'errors;error;' : ''}${levels.map((l) => `data_${l}`).join(';')};
|
|
147
|
-
stores.page.notify();
|
|
148
|
-
});
|
|
149
|
-
`
|
|
150
|
-
: 'afterUpdate(stores.page.notify);'
|
|
151
|
-
}
|
|
102
|
+
$effect(() => {
|
|
103
|
+
stores;page;constructors;components;form;${use_boundaries ? 'errors;error;' : ''}${levels.map((l) => `data_${l}`).join(';')};
|
|
104
|
+
stores.page.notify();
|
|
105
|
+
});
|
|
152
106
|
|
|
153
|
-
let mounted = $
|
|
154
|
-
let navigated = $
|
|
155
|
-
let title = $
|
|
107
|
+
let mounted = $state(false);
|
|
108
|
+
let navigated = $state(false);
|
|
109
|
+
let title = $state(null);
|
|
156
110
|
|
|
157
111
|
onMount(() => {
|
|
158
112
|
const unsubscribe = stores.page.subscribe(() => {
|
|
@@ -168,7 +122,7 @@ export function write_root(manifest_data, config, output) {
|
|
|
168
122
|
return unsubscribe;
|
|
169
123
|
});
|
|
170
124
|
|
|
171
|
-
|
|
125
|
+
const Pyramid_${max_depth} = $derived(constructors[${max_depth}]);
|
|
172
126
|
</script>
|
|
173
127
|
|
|
174
128
|
${pyramid}
|
|
@@ -183,14 +137,12 @@ export function write_root(manifest_data, config, output) {
|
|
|
183
137
|
`
|
|
184
138
|
);
|
|
185
139
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
);
|
|
195
|
-
}
|
|
140
|
+
write_if_changed(
|
|
141
|
+
`${output}/root.js`,
|
|
142
|
+
dedent`
|
|
143
|
+
import { asClassComponent } from 'svelte/legacy';
|
|
144
|
+
import Root from './root.svelte';
|
|
145
|
+
export default asClassComponent(Root);
|
|
146
|
+
`
|
|
147
|
+
);
|
|
196
148
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import
|
|
2
|
+
import { styleText } from 'node:util';
|
|
3
3
|
import { hash } from '../../utils/hash.js';
|
|
4
|
-
import {
|
|
4
|
+
import { resolve_entry } from '../../utils/filesystem.js';
|
|
5
|
+
import { posixify } from '../../utils/os.js';
|
|
5
6
|
import { s } from '../../utils/misc.js';
|
|
6
7
|
import { load_error_page, load_template } from '../config/index.js';
|
|
7
|
-
import {
|
|
8
|
-
import { isSvelte5Plus, write_if_changed } from './utils.js';
|
|
9
|
-
import colors from 'kleur';
|
|
8
|
+
import { write_if_changed } from './utils.js';
|
|
10
9
|
import { escape_html } from '../../utils/escape.js';
|
|
11
10
|
|
|
12
11
|
/**
|
|
@@ -15,7 +14,6 @@ import { escape_html } from '../../utils/escape.js';
|
|
|
15
14
|
* universal_hooks: string | null;
|
|
16
15
|
* config: import('types').ValidatedConfig;
|
|
17
16
|
* has_service_worker: boolean;
|
|
18
|
-
* runtime_directory: string;
|
|
19
17
|
* template: string;
|
|
20
18
|
* error_page: string;
|
|
21
19
|
* }} opts
|
|
@@ -25,28 +23,25 @@ const server_template = ({
|
|
|
25
23
|
server_hooks,
|
|
26
24
|
universal_hooks,
|
|
27
25
|
has_service_worker,
|
|
28
|
-
runtime_directory,
|
|
29
26
|
template,
|
|
30
27
|
error_page
|
|
31
28
|
}) => `
|
|
32
|
-
import root from '../root
|
|
33
|
-
import { set_building, set_prerendering } from '
|
|
29
|
+
import root from '../root.js';
|
|
30
|
+
import { set_building, set_prerendering } from '$app/env/internal';
|
|
34
31
|
import { set_assets } from '$app/paths/internal/server';
|
|
35
32
|
import { set_manifest, set_read_implementation } from '__sveltekit/server';
|
|
36
|
-
import {
|
|
33
|
+
import { set_env } from '__sveltekit/env';
|
|
37
34
|
|
|
38
35
|
export const options = {
|
|
39
36
|
app_template_contains_nonce: ${template.includes('%sveltekit.nonce%')},
|
|
40
37
|
async: ${s(!!config.compilerOptions?.experimental?.async)},
|
|
41
38
|
csp: ${s(config.kit.csp)},
|
|
42
|
-
csrf_check_origin: ${s(
|
|
39
|
+
csrf_check_origin: ${s(!config.kit.csrf.trustedOrigins.includes('*'))},
|
|
43
40
|
csrf_trusted_origins: ${s(config.kit.csrf.trustedOrigins)},
|
|
44
41
|
embedded: ${config.kit.embedded},
|
|
45
|
-
env_public_prefix: '${config.kit.env.publicPrefix}',
|
|
46
|
-
env_private_prefix: '${config.kit.env.privatePrefix}',
|
|
47
42
|
hash_routing: ${s(config.kit.router.type === 'hash')},
|
|
48
43
|
hooks: null, // added lazily, via \`get_hooks\`
|
|
49
|
-
|
|
44
|
+
link_header_preload: ${s(config.kit.output.linkHeaderPreload)},
|
|
50
45
|
root,
|
|
51
46
|
service_worker: ${has_service_worker},
|
|
52
47
|
service_worker_options: ${config.kit.serviceWorker.register ? s(config.kit.serviceWorker.options) : 'null'},
|
|
@@ -92,7 +87,7 @@ export async function get_hooks() {
|
|
|
92
87
|
};
|
|
93
88
|
}
|
|
94
89
|
|
|
95
|
-
export { set_assets, set_building, set_manifest, set_prerendering,
|
|
90
|
+
export { set_assets, set_building, set_env, set_manifest, set_prerendering, set_read_implementation };
|
|
96
91
|
`;
|
|
97
92
|
|
|
98
93
|
// TODO need to re-run this whenever src/app.html or src/error.html are
|
|
@@ -103,20 +98,20 @@ export { set_assets, set_building, set_manifest, set_prerendering, set_private_e
|
|
|
103
98
|
* Write server configuration to disk
|
|
104
99
|
* @param {import('types').ValidatedConfig} config
|
|
105
100
|
* @param {string} output
|
|
101
|
+
* @param {string} root The project root directory
|
|
106
102
|
*/
|
|
107
|
-
export function write_server(config, output) {
|
|
103
|
+
export function write_server(config, output, root) {
|
|
108
104
|
const server_hooks_file = resolve_entry(config.kit.files.hooks.server);
|
|
109
105
|
const universal_hooks_file = resolve_entry(config.kit.files.hooks.universal);
|
|
110
106
|
|
|
111
107
|
const typo = resolve_entry('src/+hooks.server');
|
|
112
108
|
if (typo) {
|
|
113
109
|
console.log(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
.
|
|
117
|
-
`
|
|
118
|
-
|
|
119
|
-
)
|
|
110
|
+
styleText(
|
|
111
|
+
['bold', 'yellow'],
|
|
112
|
+
`Unexpected + prefix. Did you mean ${typo.split('/').at(-1)?.slice(1)}?` +
|
|
113
|
+
` at ${path.resolve(typo)}`
|
|
114
|
+
)
|
|
120
115
|
);
|
|
121
116
|
}
|
|
122
117
|
|
|
@@ -135,8 +130,7 @@ export function write_server(config, output) {
|
|
|
135
130
|
universal_hooks: universal_hooks_file ? relative(universal_hooks_file) : null,
|
|
136
131
|
has_service_worker:
|
|
137
132
|
config.kit.serviceWorker.register && !!resolve_entry(config.kit.files.serviceWorker),
|
|
138
|
-
|
|
139
|
-
template: load_template(process.cwd(), config),
|
|
133
|
+
template: load_template(root, config),
|
|
140
134
|
error_page: load_error_page(config)
|
|
141
135
|
})
|
|
142
136
|
);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { posixify } from '../../utils/filesystem.js';
|
|
3
|
+
import { styleText } from 'node:util';
|
|
4
|
+
import { posixify } from '../../utils/os.js';
|
|
6
5
|
import { write_if_changed } from './utils.js';
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -17,10 +16,11 @@ function maybe_file(cwd, file) {
|
|
|
17
16
|
}
|
|
18
17
|
|
|
19
18
|
/**
|
|
19
|
+
* @param {string} cwd
|
|
20
20
|
* @param {string} file
|
|
21
21
|
*/
|
|
22
|
-
function project_relative(file) {
|
|
23
|
-
return posixify(path.relative(
|
|
22
|
+
function project_relative(cwd, file) {
|
|
23
|
+
return posixify(path.relative(cwd, file));
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
@@ -37,28 +37,32 @@ function remove_trailing_slashstar(file) {
|
|
|
37
37
|
/**
|
|
38
38
|
* Generates the tsconfig that the user's tsconfig inherits from.
|
|
39
39
|
* @param {import('types').ValidatedKitConfig} kit
|
|
40
|
+
* @param {string} cwd
|
|
40
41
|
*/
|
|
41
|
-
export function write_tsconfig(kit, cwd
|
|
42
|
+
export function write_tsconfig(kit, cwd) {
|
|
42
43
|
const out = path.join(kit.outDir, 'tsconfig.json');
|
|
43
44
|
|
|
44
45
|
const user_config = load_user_tsconfig(cwd);
|
|
45
46
|
if (user_config) validate_user_config(cwd, out, user_config);
|
|
46
47
|
|
|
47
|
-
write_if_changed(out, JSON.stringify(get_tsconfig(kit), null, '\t'));
|
|
48
|
+
write_if_changed(out, JSON.stringify(get_tsconfig(kit, cwd), null, '\t'));
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
/**
|
|
51
52
|
* Generates the tsconfig that the user's tsconfig inherits from.
|
|
52
53
|
* @param {import('types').ValidatedKitConfig} kit
|
|
54
|
+
* @param {string} cwd
|
|
53
55
|
*/
|
|
54
|
-
export function get_tsconfig(kit) {
|
|
56
|
+
export function get_tsconfig(kit, cwd) {
|
|
55
57
|
/** @param {string} file */
|
|
56
58
|
const config_relative = (file) => posixify(path.relative(kit.outDir, file));
|
|
57
59
|
|
|
58
60
|
const include = new Set([
|
|
59
61
|
'ambient.d.ts', // careful: changing this name would be a breaking change, because it's referenced in the service-workers documentation
|
|
62
|
+
'env.d.ts',
|
|
60
63
|
'non-ambient.d.ts',
|
|
61
64
|
'./types/**/$types.d.ts',
|
|
65
|
+
config_relative('svelte.config.js'),
|
|
62
66
|
config_relative('vite.config.js'),
|
|
63
67
|
config_relative('vite.config.ts')
|
|
64
68
|
]);
|
|
@@ -74,11 +78,11 @@ export function get_tsconfig(kit) {
|
|
|
74
78
|
|
|
75
79
|
// Test folder is a special case - we advocate putting tests in a top-level test folder
|
|
76
80
|
// and it's not configurable (should we make it?)
|
|
77
|
-
const test_folder = project_relative('test');
|
|
81
|
+
const test_folder = project_relative(cwd, 'test');
|
|
78
82
|
include.add(config_relative(`${test_folder}/**/*.js`));
|
|
79
83
|
include.add(config_relative(`${test_folder}/**/*.ts`));
|
|
80
84
|
include.add(config_relative(`${test_folder}/**/*.svelte`));
|
|
81
|
-
const tests_folder = project_relative('tests');
|
|
85
|
+
const tests_folder = project_relative(cwd, 'tests');
|
|
82
86
|
include.add(config_relative(`${tests_folder}/**/*.js`));
|
|
83
87
|
include.add(config_relative(`${tests_folder}/**/*.ts`));
|
|
84
88
|
include.add(config_relative(`${tests_folder}/**/*.svelte`));
|
|
@@ -101,7 +105,7 @@ export function get_tsconfig(kit) {
|
|
|
101
105
|
compilerOptions: {
|
|
102
106
|
// generated options
|
|
103
107
|
paths: {
|
|
104
|
-
...get_tsconfig_paths(kit),
|
|
108
|
+
...get_tsconfig_paths(kit, cwd),
|
|
105
109
|
'$app/types': ['./types/index.d.ts']
|
|
106
110
|
},
|
|
107
111
|
rootDirs: [config_relative('.'), './types'],
|
|
@@ -169,22 +173,22 @@ function validate_user_config(cwd, out, config) {
|
|
|
169
173
|
// TODO: baseUrl will be removed in TypeScript 7.0
|
|
170
174
|
if (baseUrl || paths) {
|
|
171
175
|
console.warn(
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
.
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
)
|
|
176
|
+
styleText(
|
|
177
|
+
['bold', 'yellow'],
|
|
178
|
+
`You have specified a baseUrl and/or paths in your ${config.kind} which interferes with SvelteKit's auto-generated tsconfig.json. ` +
|
|
179
|
+
'Remove it to avoid problems with intellisense. For path aliases, use `kit.alias` instead: https://svelte.dev/docs/kit/configuration#alias'
|
|
180
|
+
)
|
|
178
181
|
);
|
|
179
182
|
}
|
|
180
183
|
} else {
|
|
181
|
-
let relative = posixify(path.relative(
|
|
184
|
+
let relative = posixify(path.relative(cwd, out));
|
|
182
185
|
if (!relative.startsWith('./')) relative = './' + relative;
|
|
183
186
|
|
|
184
187
|
console.warn(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
+
styleText(
|
|
189
|
+
['bold', 'yellow'],
|
|
190
|
+
`Your ${config.kind} should extend the configuration generated by SvelteKit:`
|
|
191
|
+
)
|
|
188
192
|
);
|
|
189
193
|
console.warn(`{\n "extends": "${relative}"\n}`);
|
|
190
194
|
}
|
|
@@ -200,8 +204,9 @@ const value_regex = /^(.*?)((\/\*)|(\.\w+))?$/;
|
|
|
200
204
|
* Related to vite alias creation.
|
|
201
205
|
*
|
|
202
206
|
* @param {import('types').ValidatedKitConfig} config
|
|
207
|
+
* @param {string} cwd
|
|
203
208
|
*/
|
|
204
|
-
function get_tsconfig_paths(config) {
|
|
209
|
+
function get_tsconfig_paths(config, cwd) {
|
|
205
210
|
/** @param {string} file */
|
|
206
211
|
const config_relative = (file) => {
|
|
207
212
|
let relative_path = path.relative(config.outDir, file);
|
|
@@ -212,8 +217,8 @@ function get_tsconfig_paths(config) {
|
|
|
212
217
|
};
|
|
213
218
|
|
|
214
219
|
const alias = { ...config.alias };
|
|
215
|
-
if (fs.existsSync(project_relative(config.files.lib))) {
|
|
216
|
-
alias['$lib'] = project_relative(config.files.lib);
|
|
220
|
+
if (fs.existsSync(project_relative(cwd, config.files.lib))) {
|
|
221
|
+
alias['$lib'] = project_relative(cwd, config.files.lib);
|
|
217
222
|
}
|
|
218
223
|
|
|
219
224
|
/** @type {Record<string, string[]>} */
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import process from 'node:process';
|
|
4
3
|
import MagicString from 'magic-string';
|
|
5
|
-
import {
|
|
4
|
+
import { rimraf, walk } from '../../../utils/filesystem.js';
|
|
6
5
|
import { compact } from '../../../utils/array.js';
|
|
6
|
+
import { posixify } from '../../../utils/os.js';
|
|
7
7
|
import { ts } from '../ts.js';
|
|
8
8
|
const remove_relative_parent_traversals = (/** @type {string} */ path) =>
|
|
9
9
|
path.replace(/\.\.\//g, '');
|
|
@@ -25,21 +25,20 @@ const is_whitespace = (/** @type {string} */ char) => /\s/.test(char);
|
|
|
25
25
|
* @typedef {Map<import('types').PageNode, {route: import('types').RouteData, proxies: Proxies}>} RoutesMap
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
const cwd = process.cwd();
|
|
29
|
-
|
|
30
28
|
/**
|
|
31
29
|
* Creates types for the whole manifest
|
|
32
30
|
* @param {import('types').ValidatedConfig} config
|
|
33
31
|
* @param {import('types').ManifestData} manifest_data
|
|
32
|
+
* @param {string} root The project root directory
|
|
34
33
|
*/
|
|
35
|
-
export function write_all_types(config, manifest_data) {
|
|
34
|
+
export function write_all_types(config, manifest_data, root) {
|
|
36
35
|
if (!ts) return;
|
|
37
36
|
|
|
38
37
|
const types_dir = `${config.kit.outDir}/types`;
|
|
39
38
|
|
|
40
39
|
// empty out files that no longer need to exist
|
|
41
40
|
const routes_dir = remove_relative_parent_traversals(
|
|
42
|
-
posixify(path.relative(
|
|
41
|
+
posixify(path.relative(root, config.kit.files.routes))
|
|
43
42
|
);
|
|
44
43
|
const expected_directories = new Set(
|
|
45
44
|
manifest_data.routes.map((route) => path.join(routes_dir, route.id))
|
|
@@ -109,7 +108,7 @@ export function write_all_types(config, manifest_data) {
|
|
|
109
108
|
|
|
110
109
|
const source_last_updated = Math.max(
|
|
111
110
|
// ctimeMs includes move operations whereas mtimeMs does not
|
|
112
|
-
...input_files.map((file) => fs.statSync(file).ctimeMs)
|
|
111
|
+
...input_files.map((file) => fs.statSync(path.resolve(root, file)).ctimeMs)
|
|
113
112
|
);
|
|
114
113
|
const types_last_updated = Math.max(...output_files.map((file) => file.updated));
|
|
115
114
|
|
|
@@ -124,7 +123,7 @@ export function write_all_types(config, manifest_data) {
|
|
|
124
123
|
if (should_generate) {
|
|
125
124
|
// track which old files end up being surplus to requirements
|
|
126
125
|
const to_delete = new Set(output_files.map((file) => file.name));
|
|
127
|
-
update_types(config, routes_map, route, to_delete);
|
|
126
|
+
update_types(config, routes_map, route, root, to_delete);
|
|
128
127
|
meta_data[route.id] = input_files;
|
|
129
128
|
}
|
|
130
129
|
}
|
|
@@ -138,8 +137,9 @@ export function write_all_types(config, manifest_data) {
|
|
|
138
137
|
* @param {import('types').ValidatedConfig} config
|
|
139
138
|
* @param {import('types').ManifestData} manifest_data
|
|
140
139
|
* @param {string} file
|
|
140
|
+
* @param {string} root The project root directory
|
|
141
141
|
*/
|
|
142
|
-
export function write_types(config, manifest_data, file) {
|
|
142
|
+
export function write_types(config, manifest_data, file, root) {
|
|
143
143
|
if (!ts) return;
|
|
144
144
|
|
|
145
145
|
if (!path.basename(file).startsWith('+')) {
|
|
@@ -153,7 +153,7 @@ export function write_types(config, manifest_data, file) {
|
|
|
153
153
|
if (!route) return;
|
|
154
154
|
if (!route.leaf && !route.layout && !route.endpoint) return; // nothing to do
|
|
155
155
|
|
|
156
|
-
update_types(config, create_routes_map(manifest_data), route);
|
|
156
|
+
update_types(config, create_routes_map(manifest_data), route, root);
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
/**
|
|
@@ -176,11 +176,12 @@ function create_routes_map(manifest_data) {
|
|
|
176
176
|
* @param {import('types').ValidatedConfig} config
|
|
177
177
|
* @param {RoutesMap} routes
|
|
178
178
|
* @param {import('types').RouteData} route
|
|
179
|
+
* @param {string} root The project root directory
|
|
179
180
|
* @param {Set<string>} [to_delete]
|
|
180
181
|
*/
|
|
181
|
-
function update_types(config, routes, route, to_delete = new Set()) {
|
|
182
|
+
function update_types(config, routes, route, root, to_delete = new Set()) {
|
|
182
183
|
const routes_dir = remove_relative_parent_traversals(
|
|
183
|
-
posixify(path.relative(
|
|
184
|
+
posixify(path.relative(root, config.kit.files.routes))
|
|
184
185
|
);
|
|
185
186
|
const outdir = path.join(config.kit.outDir, 'types', routes_dir, route.id);
|
|
186
187
|
|
|
@@ -251,7 +252,7 @@ function update_types(config, routes, route, to_delete = new Set()) {
|
|
|
251
252
|
declarations: d,
|
|
252
253
|
exports: e,
|
|
253
254
|
proxies
|
|
254
|
-
} = process_node(route.leaf, outdir, true, route_info.proxies);
|
|
255
|
+
} = process_node(route.leaf, outdir, true, route_info.proxies, root);
|
|
255
256
|
|
|
256
257
|
exports.push(...e);
|
|
257
258
|
declarations.push(...d);
|
|
@@ -300,7 +301,7 @@ function update_types(config, routes, route, to_delete = new Set()) {
|
|
|
300
301
|
layout_params.push({ ...param, optional: true });
|
|
301
302
|
}
|
|
302
303
|
|
|
303
|
-
ensureProxies(page, leaf.proxies);
|
|
304
|
+
ensureProxies(page, leaf.proxies, root);
|
|
304
305
|
|
|
305
306
|
if (
|
|
306
307
|
// Be defensive - if a proxy doesn't exist (because it couldn't be created), assume a load function exists.
|
|
@@ -336,6 +337,7 @@ function update_types(config, routes, route, to_delete = new Set()) {
|
|
|
336
337
|
outdir,
|
|
337
338
|
false,
|
|
338
339
|
{ server: null, universal: null },
|
|
340
|
+
root,
|
|
339
341
|
all_pages_have_load
|
|
340
342
|
);
|
|
341
343
|
|
|
@@ -375,9 +377,10 @@ function update_types(config, routes, route, to_delete = new Set()) {
|
|
|
375
377
|
* @param {string} outdir
|
|
376
378
|
* @param {boolean} is_page
|
|
377
379
|
* @param {Proxies} proxies
|
|
380
|
+
* @param {string} root The project root directory
|
|
378
381
|
* @param {boolean} [all_pages_have_load]
|
|
379
382
|
*/
|
|
380
|
-
function process_node(node, outdir, is_page, proxies, all_pages_have_load = true) {
|
|
383
|
+
function process_node(node, outdir, is_page, proxies, root, all_pages_have_load = true) {
|
|
381
384
|
const params = `${is_page ? 'Route' : 'Layout'}Params`;
|
|
382
385
|
const prefix = is_page ? 'Page' : 'Layout';
|
|
383
386
|
|
|
@@ -393,7 +396,7 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
|
|
|
393
396
|
/** @type {string} */
|
|
394
397
|
let data;
|
|
395
398
|
|
|
396
|
-
ensureProxies(node, proxies);
|
|
399
|
+
ensureProxies(node, proxies, root);
|
|
397
400
|
|
|
398
401
|
if (node.server) {
|
|
399
402
|
const basename = path.basename(node.server);
|
|
@@ -426,7 +429,7 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
|
|
|
426
429
|
// The advantage is that type updates are reflected without saving.
|
|
427
430
|
const from = proxy.modified
|
|
428
431
|
? `./proxy${replace_ext_with_js(basename)}`
|
|
429
|
-
: path_to_original(outdir, node.server);
|
|
432
|
+
: path_to_original(outdir, node.server, root);
|
|
430
433
|
|
|
431
434
|
exports.push(
|
|
432
435
|
'type ExcludeActionFailure<T> = T extends Kit.ActionFailure<any> ? never : T extends void ? never : T;',
|
|
@@ -495,7 +498,7 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
|
|
|
495
498
|
// The advantage is that type updates are reflected without saving.
|
|
496
499
|
const from = proxy.modified
|
|
497
500
|
? `./proxy${replace_ext_with_js(path.basename(file_path))}`
|
|
498
|
-
: path_to_original(outdir, file_path);
|
|
501
|
+
: path_to_original(outdir, file_path, root);
|
|
499
502
|
const type = `Kit.LoadProperties<Awaited<ReturnType<typeof import('${from}').load>>>`;
|
|
500
503
|
return expand ? `Expand<OptionalUnion<EnsureDefined<${type}>>>` : type;
|
|
501
504
|
} else {
|
|
@@ -515,24 +518,26 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
|
|
|
515
518
|
*
|
|
516
519
|
* @param {import('types').PageNode} node
|
|
517
520
|
* @param {Proxies} proxies
|
|
521
|
+
* @param {string} root The project root directory
|
|
518
522
|
*/
|
|
519
|
-
function ensureProxies(node, proxies) {
|
|
523
|
+
function ensureProxies(node, proxies, root) {
|
|
520
524
|
if (node.server && !proxies.server) {
|
|
521
|
-
proxies.server = createProxy(node.server, true);
|
|
525
|
+
proxies.server = createProxy(node.server, true, root);
|
|
522
526
|
}
|
|
523
527
|
|
|
524
528
|
if (node.universal && !proxies.universal) {
|
|
525
|
-
proxies.universal = createProxy(node.universal, false);
|
|
529
|
+
proxies.universal = createProxy(node.universal, false, root);
|
|
526
530
|
}
|
|
527
531
|
}
|
|
528
532
|
|
|
529
533
|
/**
|
|
530
534
|
* @param {string} file_path
|
|
531
535
|
* @param {boolean} is_server
|
|
536
|
+
* @param {string} root The project root directory
|
|
532
537
|
* @returns {Proxy}
|
|
533
538
|
*/
|
|
534
|
-
function createProxy(file_path, is_server) {
|
|
535
|
-
const proxy = tweak_types(fs.readFileSync(file_path, 'utf8'), is_server);
|
|
539
|
+
function createProxy(file_path, is_server, root) {
|
|
540
|
+
const proxy = tweak_types(fs.readFileSync(path.resolve(root, file_path), 'utf8'), is_server);
|
|
536
541
|
if (proxy) {
|
|
537
542
|
return {
|
|
538
543
|
...proxy,
|
|
@@ -577,9 +582,10 @@ function get_parent_type(node, type) {
|
|
|
577
582
|
/**
|
|
578
583
|
* @param {string} outdir
|
|
579
584
|
* @param {string} file_path
|
|
585
|
+
* @param {string} root The project root directory
|
|
580
586
|
*/
|
|
581
|
-
function path_to_original(outdir, file_path) {
|
|
582
|
-
return posixify(path.relative(outdir, path.join(
|
|
587
|
+
function path_to_original(outdir, file_path, root) {
|
|
588
|
+
return posixify(path.relative(outdir, path.join(root, replace_ext_with_js(file_path))));
|
|
583
589
|
}
|
|
584
590
|
|
|
585
591
|
/**
|
package/src/core/utils.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import process from 'node:process';
|
|
4
3
|
import { fileURLToPath } from 'node:url';
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
4
|
+
import { styleText } from 'node:util';
|
|
5
|
+
import { to_fs } from '../utils/vite.js';
|
|
7
6
|
import { noop } from '../utils/functions.js';
|
|
7
|
+
import { posixify } from '../utils/os.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Resolved path of the `runtime` directory
|
|
@@ -20,10 +20,14 @@ export const runtime_directory = posixify(fileURLToPath(new URL('../runtime', im
|
|
|
20
20
|
* This allows us to import SvelteKit internals that aren't exposed via `pkg.exports` in a
|
|
21
21
|
* way that works whether `@sveltejs/kit` is installed inside the project's `node_modules`
|
|
22
22
|
* or in a workspace root
|
|
23
|
+
* @param {string} root
|
|
24
|
+
* @returns {string}
|
|
23
25
|
*/
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
export function get_runtime_base(root) {
|
|
27
|
+
return runtime_directory.startsWith(root)
|
|
28
|
+
? `/${path.relative(root, runtime_directory)}`
|
|
29
|
+
: to_fs(runtime_directory);
|
|
30
|
+
}
|
|
27
31
|
|
|
28
32
|
/** @param {{ verbose: boolean }} opts */
|
|
29
33
|
export function logger({ verbose }) {
|
|
@@ -33,11 +37,10 @@ export function logger({ verbose }) {
|
|
|
33
37
|
/** @param {string} msg */
|
|
34
38
|
const err = (msg) => console.error(msg.replace(/^/gm, ' '));
|
|
35
39
|
|
|
36
|
-
log.success = (msg) => log(
|
|
37
|
-
log.error = (msg) => err(
|
|
38
|
-
log.warn = (msg) => log(
|
|
39
|
-
|
|
40
|
-
log.minor = verbose ? (msg) => log(colors.grey(msg)) : noop;
|
|
40
|
+
log.success = (msg) => log(styleText('green', `✔ ${msg}`));
|
|
41
|
+
log.error = (msg) => err(styleText(['bold', 'red'], msg));
|
|
42
|
+
log.warn = (msg) => log(styleText(['bold', 'yellow'], msg));
|
|
43
|
+
log.minor = verbose ? (msg) => log(styleText('grey', msg)) : noop;
|
|
41
44
|
log.info = verbose ? log : noop;
|
|
42
45
|
|
|
43
46
|
return log;
|