@sveltejs/kit 3.0.0-next.2 → 3.0.0-next.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +62 -36
- package/src/cli.js +15 -12
- package/src/constants.js +6 -1
- package/src/core/adapt/builder.js +66 -72
- package/src/core/adapt/index.js +17 -6
- package/src/core/config/index.js +134 -80
- package/src/core/config/options.js +295 -273
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +146 -16
- package/src/core/generate_manifest/index.js +18 -15
- package/src/core/postbuild/analyse.js +8 -20
- 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 +222 -70
- 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 +82 -62
- package/src/core/sync/sync.js +40 -31
- 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} +107 -58
- package/src/core/sync/write_client_manifest.js +14 -29
- package/src/core/sync/write_env.js +7 -5
- package/src/core/sync/write_server.js +37 -45
- 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 +127 -123
- 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 +195 -0
- package/src/exports/hooks/sequence.js +9 -6
- package/src/exports/index.js +52 -29
- 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} +2 -3
- 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 +50 -1733
- package/src/exports/remote/index.js +11 -0
- package/src/exports/remote/public.d.ts +519 -0
- package/src/exports/url.js +86 -0
- package/src/exports/vite/build/build_server.js +54 -65
- 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 +218 -146
- package/src/exports/vite/index.js +1590 -858
- package/src/exports/vite/module_ids.js +2 -2
- package/src/exports/vite/preview/index.js +40 -32
- package/src/exports/vite/public.d.ts +588 -0
- package/src/exports/vite/utils.js +84 -46
- 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 +201 -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 +76 -76
- 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 +72 -55
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +49 -53
- package/src/runtime/server/dev.js +22 -0
- package/src/runtime/server/endpoint.js +6 -7
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/errors.js +160 -0
- package/src/runtime/server/fetch.js +32 -39
- package/src/runtime/server/index.js +90 -64
- package/src/runtime/server/internal.js +71 -0
- package/src/runtime/server/page/actions.js +85 -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 +24 -25
- package/src/runtime/server/page/index.js +36 -53
- package/src/runtime/server/page/load_data.js +50 -57
- package/src/runtime/server/page/render.js +173 -239
- package/src/runtime/server/page/respond_with_error.js +17 -31
- 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 +640 -0
- package/src/runtime/server/respond.js +190 -131
- package/src/runtime/server/sourcemaps.js +183 -0
- package/src/runtime/server/state.js +53 -0
- package/src/runtime/server/utils.js +13 -155
- 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 +163 -157
- 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 +2616 -2433
- package/types/index.d.ts.map +120 -106
- 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,4 +1,4 @@
|
|
|
1
|
-
import { lookup } from '
|
|
1
|
+
import { lookup } from '../../../utils/mime.js';
|
|
2
2
|
import fs from 'node:fs';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { styleText } from 'node:util';
|
|
@@ -29,35 +29,54 @@ export default function create_manifest_data({
|
|
|
29
29
|
}) {
|
|
30
30
|
const assets = create_assets(config);
|
|
31
31
|
const hooks = create_hooks(config, cwd);
|
|
32
|
-
const
|
|
32
|
+
const params = resolve_params(config, cwd);
|
|
33
33
|
const { nodes, routes } = create_routes_and_nodes(cwd, config, fallback);
|
|
34
34
|
|
|
35
|
-
// validate matcher names used in parameterised routes
|
|
36
|
-
for (const route of routes) {
|
|
37
|
-
for (const param of route.params) {
|
|
38
|
-
if (param.matcher && !matchers[param.matcher]) {
|
|
39
|
-
throw new Error(`No matcher found for parameter '${param.matcher}' in route ${route.id}`);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
35
|
return {
|
|
45
36
|
assets,
|
|
46
37
|
hooks,
|
|
47
|
-
|
|
38
|
+
params,
|
|
48
39
|
nodes,
|
|
49
40
|
routes
|
|
50
41
|
};
|
|
51
42
|
}
|
|
52
43
|
|
|
44
|
+
/**
|
|
45
|
+
* Whether this route has a `+page`. Independent of `is_endpoint_route` — a route can be both.
|
|
46
|
+
* @param {import('types').RouteData} route
|
|
47
|
+
* @returns {boolean}
|
|
48
|
+
*/
|
|
49
|
+
export function is_page_route(route) {
|
|
50
|
+
return !!route.page;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Whether this route has a `+server`. Independent of `is_page_route` — a route can be both.
|
|
55
|
+
* @param {import('types').RouteData} route
|
|
56
|
+
* @returns {boolean}
|
|
57
|
+
*/
|
|
58
|
+
export function is_endpoint_route(route) {
|
|
59
|
+
return !!route.endpoint;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Whether the router can match this route. `manifest_data.routes` also contains entries for
|
|
64
|
+
* directories with layouts or errors, which never reach `event.route.id`.
|
|
65
|
+
* @param {import('types').RouteData} route
|
|
66
|
+
* @returns {boolean}
|
|
67
|
+
*/
|
|
68
|
+
export function is_app_route(route) {
|
|
69
|
+
return is_page_route(route) || is_endpoint_route(route);
|
|
70
|
+
}
|
|
71
|
+
|
|
53
72
|
/**
|
|
54
73
|
* Returns a list of files in the `static` directory.
|
|
55
74
|
* @param {import('types').ValidatedConfig} config
|
|
56
75
|
*/
|
|
57
76
|
export function create_assets(config) {
|
|
58
|
-
return list_files(config.
|
|
77
|
+
return list_files(config.files.assets).map((file) => ({
|
|
59
78
|
file,
|
|
60
|
-
size: fs.statSync(path.resolve(config.
|
|
79
|
+
size: fs.statSync(path.resolve(config.files.assets, file)).size,
|
|
61
80
|
type: lookup(file) || null
|
|
62
81
|
}));
|
|
63
82
|
}
|
|
@@ -67,9 +86,9 @@ export function create_assets(config) {
|
|
|
67
86
|
* @param {string} cwd
|
|
68
87
|
*/
|
|
69
88
|
function create_hooks(config, cwd) {
|
|
70
|
-
const client = resolve_entry(config.
|
|
71
|
-
const server = resolve_entry(config.
|
|
72
|
-
const universal = resolve_entry(config.
|
|
89
|
+
const client = resolve_entry(config.files.hooks.client);
|
|
90
|
+
const server = resolve_entry(config.files.hooks.server);
|
|
91
|
+
const universal = resolve_entry(config.files.hooks.universal);
|
|
73
92
|
|
|
74
93
|
return {
|
|
75
94
|
client: client && posixify(path.relative(cwd, client)),
|
|
@@ -82,38 +101,9 @@ function create_hooks(config, cwd) {
|
|
|
82
101
|
* @param {import('types').ValidatedConfig} config
|
|
83
102
|
* @param {string} cwd
|
|
84
103
|
*/
|
|
85
|
-
function
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
/** @type {Record<string, string>} */
|
|
89
|
-
const matchers = {};
|
|
90
|
-
if (fs.existsSync(config.kit.files.params)) {
|
|
91
|
-
for (const file of fs.readdirSync(config.kit.files.params)) {
|
|
92
|
-
const ext = path.extname(file);
|
|
93
|
-
if (!config.kit.moduleExtensions.includes(ext)) continue;
|
|
94
|
-
const type = file.slice(0, -ext.length);
|
|
95
|
-
|
|
96
|
-
if (/^\w+$/.test(type)) {
|
|
97
|
-
const matcher_file = path.join(params_base, file);
|
|
98
|
-
|
|
99
|
-
// Disallow same matcher with different extensions
|
|
100
|
-
if (matchers[type]) {
|
|
101
|
-
throw new Error(`Duplicate matchers: ${matcher_file} and ${matchers[type]}`);
|
|
102
|
-
} else {
|
|
103
|
-
matchers[type] = matcher_file;
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
// Allow for matcher test collocation
|
|
107
|
-
if (type.endsWith('.test') || type.endsWith('.spec')) continue;
|
|
108
|
-
|
|
109
|
-
throw new Error(
|
|
110
|
-
`Matcher names can only have underscores and alphanumeric characters — "${file}" is invalid`
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return matchers;
|
|
104
|
+
function resolve_params(config, cwd) {
|
|
105
|
+
const params_file = resolve_entry(config.files.params);
|
|
106
|
+
return params_file ? posixify(path.relative(cwd, params_file)) : null;
|
|
117
107
|
}
|
|
118
108
|
|
|
119
109
|
/**
|
|
@@ -123,17 +113,17 @@ function create_matchers(config, cwd) {
|
|
|
123
113
|
*/
|
|
124
114
|
function create_routes_and_nodes(cwd, config, fallback) {
|
|
125
115
|
/** @type {import('types').RouteData[]} */
|
|
126
|
-
|
|
116
|
+
let routes = [];
|
|
127
117
|
|
|
128
|
-
const routes_base = posixify(path.relative(cwd, config.
|
|
118
|
+
const routes_base = posixify(path.relative(cwd, config.files.routes));
|
|
129
119
|
|
|
130
|
-
const valid_extensions = [...config.extensions, ...config.
|
|
120
|
+
const valid_extensions = [...config.extensions, ...config.moduleExtensions];
|
|
131
121
|
|
|
132
122
|
/** @type {import('types').PageNode[]} */
|
|
133
123
|
const nodes = [];
|
|
134
124
|
|
|
135
125
|
// create route data by processing files in `src/routes`
|
|
136
|
-
if (fs.existsSync(config.
|
|
126
|
+
if (fs.existsSync(config.files.routes)) {
|
|
137
127
|
/**
|
|
138
128
|
* @param {number} depth
|
|
139
129
|
* @param {string} id
|
|
@@ -163,7 +153,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
163
153
|
);
|
|
164
154
|
}
|
|
165
155
|
|
|
166
|
-
return String.
|
|
156
|
+
return String.fromCodePoint(parseInt(code, 16));
|
|
167
157
|
}
|
|
168
158
|
});
|
|
169
159
|
|
|
@@ -180,7 +170,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
180
170
|
throw new Error(`Route ${id} should be renamed to ${id.replace(/#/g, '[x+23]')}`);
|
|
181
171
|
}
|
|
182
172
|
|
|
183
|
-
if (/\[
|
|
173
|
+
if (/\[\.\.\.[\w-]+\]\/\[\[/.test(id)) {
|
|
184
174
|
throw new Error(
|
|
185
175
|
`Invalid route ${id} — an [[optional]] route segment cannot follow a [...rest] route segment`
|
|
186
176
|
);
|
|
@@ -221,10 +211,17 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
221
211
|
|
|
222
212
|
// We can't use withFileTypes because of a NodeJs bug which returns wrong results
|
|
223
213
|
// with isDirectory() in case of symlinks: https://github.com/nodejs/node/issues/30646
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
214
|
+
// We sort the entries because `readdirSync` order is not guaranteed and differs
|
|
215
|
+
// between runtimes (e.g. Node returns entries alphabetically, Bun in directory
|
|
216
|
+
// order). Node indices are assigned from this traversal order, so without sorting
|
|
217
|
+
// the SSR and client manifests can disagree, causing hydration mismatches.
|
|
218
|
+
const files = fs
|
|
219
|
+
.readdirSync(dir)
|
|
220
|
+
.sort()
|
|
221
|
+
.map((name) => ({
|
|
222
|
+
is_dir: fs.statSync(path.join(dir, name)).isDirectory(),
|
|
223
|
+
name
|
|
224
|
+
}));
|
|
228
225
|
|
|
229
226
|
// process files first
|
|
230
227
|
for (const file of files) {
|
|
@@ -254,6 +251,15 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
254
251
|
continue;
|
|
255
252
|
}
|
|
256
253
|
|
|
254
|
+
// allow e.g. `+page.stories.svelte` or `+server.test.ts`
|
|
255
|
+
if (
|
|
256
|
+
file.name.includes('.test.') ||
|
|
257
|
+
file.name.includes('.spec.') ||
|
|
258
|
+
file.name.includes('.stories.')
|
|
259
|
+
) {
|
|
260
|
+
continue;
|
|
261
|
+
}
|
|
262
|
+
|
|
257
263
|
if (file.name.endsWith('.d.ts')) {
|
|
258
264
|
let name = file.name.slice(0, -5);
|
|
259
265
|
const ext = valid_extensions.find((ext) => name.endsWith(ext));
|
|
@@ -274,10 +280,10 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
274
280
|
project_relative,
|
|
275
281
|
file.name,
|
|
276
282
|
config.extensions,
|
|
277
|
-
config.
|
|
283
|
+
config.moduleExtensions
|
|
278
284
|
);
|
|
279
285
|
|
|
280
|
-
if (config.
|
|
286
|
+
if (config.router.type === 'hash' && item.kind === 'server') {
|
|
281
287
|
throw new Error(
|
|
282
288
|
`Cannot use server-only files in an app with \`router.type === 'hash': ${project_relative}`
|
|
283
289
|
);
|
|
@@ -368,7 +374,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
368
374
|
const root = routes[0];
|
|
369
375
|
if (!root.leaf && !root.error && !root.layout && !root.endpoint) {
|
|
370
376
|
throw new Error(
|
|
371
|
-
'No routes found. If you are using a custom src/routes directory, make sure it is specified in your
|
|
377
|
+
'No routes found. If you are using a custom src/routes directory, make sure it is specified in your SvelteKit Vite plugin options'
|
|
372
378
|
);
|
|
373
379
|
}
|
|
374
380
|
}
|
|
@@ -471,6 +477,9 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
471
477
|
}
|
|
472
478
|
}
|
|
473
479
|
|
|
480
|
+
// remove route objects with no route file
|
|
481
|
+
routes = routes.filter((route) => route.endpoint || route.leaf || route.layout || route.error);
|
|
482
|
+
|
|
474
483
|
// add parents to error nodes so that we can compute which page options apply to them
|
|
475
484
|
for (const route of routes) {
|
|
476
485
|
if (!route.error) continue;
|
|
@@ -495,6 +504,17 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
495
504
|
if (route.endpoint) {
|
|
496
505
|
route.endpoint.page_options = get_page_options(route.endpoint.file, cwd);
|
|
497
506
|
}
|
|
507
|
+
|
|
508
|
+
if (route.page && route.endpoint) {
|
|
509
|
+
const page = nodes[route.page.leaf];
|
|
510
|
+
if (page.page_options?.prerender || route.endpoint.page_options?.prerender) {
|
|
511
|
+
const endpoint_file = route.endpoint.file.split('/').pop();
|
|
512
|
+
|
|
513
|
+
throw new Error(
|
|
514
|
+
`Cannot prerender a route (${route.id}) with both a \`+page.svelte\` and a \`${endpoint_file}\``
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
498
518
|
}
|
|
499
519
|
|
|
500
520
|
return {
|
package/src/core/sync/sync.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import process from 'node:process';
|
|
3
2
|
import create_manifest_data from './create_manifest_data/index.js';
|
|
4
3
|
import { write_client_manifest } from './write_client_manifest.js';
|
|
5
|
-
import {
|
|
6
|
-
import { write_tsconfig } from './write_tsconfig.js';
|
|
4
|
+
import { write_tsconfig } from './write_tsconfig/index.js';
|
|
7
5
|
import { write_types, write_all_types } from './write_types/index.js';
|
|
8
|
-
import {
|
|
9
|
-
import { write_non_ambient } from './write_non_ambient.js';
|
|
6
|
+
import { write_app_types } from './write_app_types.js';
|
|
10
7
|
import { write_server } from './write_server.js';
|
|
11
8
|
import {
|
|
12
9
|
create_node_analyser,
|
|
@@ -21,8 +18,7 @@ import { write_env } from './write_env.js';
|
|
|
21
18
|
* @param {string} root The project root directory
|
|
22
19
|
*/
|
|
23
20
|
export function init(config, root) {
|
|
24
|
-
write_tsconfig(config
|
|
25
|
-
write_ambient(config.kit);
|
|
21
|
+
write_tsconfig(config, root);
|
|
26
22
|
}
|
|
27
23
|
|
|
28
24
|
/**
|
|
@@ -33,13 +29,12 @@ export function init(config, root) {
|
|
|
33
29
|
export function create(config, root) {
|
|
34
30
|
const manifest_data = create_manifest_data({ config, cwd: root });
|
|
35
31
|
|
|
36
|
-
const output = path.join(config.
|
|
32
|
+
const output = path.join(config.outDir, 'generated');
|
|
37
33
|
|
|
38
|
-
write_client_manifest(config
|
|
34
|
+
write_client_manifest(config, manifest_data, `${output}/client`);
|
|
39
35
|
write_server(config, output, root);
|
|
40
|
-
write_root(manifest_data, config, output);
|
|
41
36
|
write_all_types(config, manifest_data, root);
|
|
42
|
-
|
|
37
|
+
write_app_types(config, manifest_data, root);
|
|
43
38
|
|
|
44
39
|
return { manifest_data };
|
|
45
40
|
}
|
|
@@ -52,22 +47,35 @@ export function create(config, root) {
|
|
|
52
47
|
* @param {import('types').ManifestData} manifest_data
|
|
53
48
|
* @param {string} file
|
|
54
49
|
* @param {string} root The project root directory
|
|
50
|
+
* @returns {boolean} Whether the update completed, or a full manifest rebuild is needed
|
|
55
51
|
*/
|
|
56
52
|
export function update(config, manifest_data, file, root) {
|
|
57
|
-
|
|
53
|
+
try {
|
|
54
|
+
const node_analyser = create_node_analyser(root);
|
|
58
55
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
for (const node of manifest_data.nodes) {
|
|
57
|
+
node.page_options = node_analyser.get_page_options(node);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
for (const route of manifest_data.routes) {
|
|
61
|
+
if (route.endpoint) {
|
|
62
|
+
route.endpoint.page_options = get_page_options(route.endpoint.file, root);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
write_types(config, manifest_data, file, root);
|
|
67
|
+
write_app_types(config, manifest_data, root);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
// A route file can disappear before the watcher delivers its unlink event. In that case,
|
|
70
|
+
// the manifest is stale and must be rebuilt instead of incrementally updated.
|
|
71
|
+
if (error && typeof error === 'object' && 'code' in error && error.code === 'ENOENT') {
|
|
72
|
+
return false;
|
|
66
73
|
}
|
|
74
|
+
|
|
75
|
+
throw error;
|
|
67
76
|
}
|
|
68
77
|
|
|
69
|
-
|
|
70
|
-
write_non_ambient(config.kit, manifest_data);
|
|
78
|
+
return true;
|
|
71
79
|
}
|
|
72
80
|
|
|
73
81
|
/**
|
|
@@ -83,26 +91,27 @@ export function all(config, root) {
|
|
|
83
91
|
/**
|
|
84
92
|
* Run sync.init and then generate all type files.
|
|
85
93
|
* @param {import('types').ValidatedConfig} config
|
|
94
|
+
* @param {string} root
|
|
86
95
|
*/
|
|
87
|
-
export function all_types(config) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
write_non_ambient(config.kit, manifest_data);
|
|
96
|
+
export function all_types(config, root) {
|
|
97
|
+
init(config, root);
|
|
98
|
+
const manifest_data = create_manifest_data({ config, cwd: root });
|
|
99
|
+
write_all_types(config, manifest_data, root);
|
|
100
|
+
write_app_types(config, manifest_data, root);
|
|
93
101
|
}
|
|
94
102
|
|
|
95
103
|
/**
|
|
96
104
|
* Generate modules and types for explicit env vars
|
|
97
|
-
* @param {import('
|
|
105
|
+
* @param {typeof import('vite')} vite
|
|
106
|
+
* @param {import('types').ValidatedConfig} kit
|
|
98
107
|
* @param {string | null} entry
|
|
99
108
|
* @param {string} root The Vite root
|
|
100
109
|
* @param {string} mode The Vite mode
|
|
101
110
|
*/
|
|
102
|
-
export async function env(kit, entry, root, mode) {
|
|
103
|
-
const env_config = await load_explicit_env(kit, entry, root, mode);
|
|
111
|
+
export async function env(vite, kit, entry, root, mode) {
|
|
112
|
+
const env_config = await load_explicit_env(vite, kit, entry, root, mode);
|
|
104
113
|
|
|
105
|
-
write_env(
|
|
114
|
+
write_env(entry, env_config, root);
|
|
106
115
|
|
|
107
116
|
return env_config;
|
|
108
117
|
}
|
|
@@ -113,5 +122,5 @@ export async function env(kit, entry, root, mode) {
|
|
|
113
122
|
* @param {string} root The project root directory
|
|
114
123
|
*/
|
|
115
124
|
export function server(config, root) {
|
|
116
|
-
write_server(config, path.join(config.
|
|
125
|
+
write_server(config, path.join(config.outDir, 'generated'), root);
|
|
117
126
|
}
|
package/src/core/sync/ts.js
CHANGED
package/src/core/sync/utils.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
|
-
import {
|
|
3
|
+
import { styleText } from 'node:util';
|
|
4
|
+
import { resolve_entry } from '../../utils/filesystem.js';
|
|
4
5
|
|
|
5
6
|
/** @type {Map<string, string>} */
|
|
6
7
|
const previous_contents = new Map();
|
|
@@ -21,7 +22,7 @@ export function write_if_changed(file, code) {
|
|
|
21
22
|
*/
|
|
22
23
|
export function write(file, code) {
|
|
23
24
|
previous_contents.set(file, code);
|
|
24
|
-
|
|
25
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
25
26
|
fs.writeFileSync(file, code);
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -68,3 +69,22 @@ export function dedent(strings, ...values) {
|
|
|
68
69
|
|
|
69
70
|
return str;
|
|
70
71
|
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {string} original
|
|
75
|
+
* @param {string} typo The common misspelling to check for
|
|
76
|
+
* @param {string} description What was wrong with the filename
|
|
77
|
+
*/
|
|
78
|
+
export function check_spelling(original, typo, description) {
|
|
79
|
+
const misspelled = resolve_entry(typo);
|
|
80
|
+
if (!misspelled) return;
|
|
81
|
+
|
|
82
|
+
const corrected = path.basename(misspelled).replace(path.basename(typo), path.basename(original));
|
|
83
|
+
|
|
84
|
+
console.warn(
|
|
85
|
+
styleText(
|
|
86
|
+
['bold', 'yellow'],
|
|
87
|
+
`${description}. Did you mean ${corrected}?` + ` at ${path.resolve(misspelled)}`
|
|
88
|
+
)
|
|
89
|
+
);
|
|
90
|
+
}
|