@sveltejs/kit 3.0.0-next.11 → 3.0.0-next.13
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 +10 -10
- package/src/cli.js +8 -8
- package/src/constants.js +1 -1
- package/src/core/config/options.js +43 -35
- package/src/core/env.js +25 -11
- package/src/core/postbuild/prerender.js +3 -3
- package/src/core/sync/sync.js +11 -14
- package/src/core/sync/utils.js +21 -1
- package/src/core/sync/{write_non_ambient.js → write_app_types.js} +24 -23
- package/src/core/sync/write_client_manifest.js +4 -12
- package/src/core/sync/write_env.js +6 -4
- package/src/core/sync/write_server.js +10 -15
- package/src/core/sync/write_tsconfig/index.js +257 -0
- package/src/core/sync/write_tsconfig/utils.js +162 -0
- package/src/core/sync/write_types/index.js +80 -88
- package/src/exports/index.js +23 -12
- package/src/exports/internal/server/index.js +3 -1
- package/src/exports/internal/shared.js +4 -12
- package/src/exports/public.d.ts +87 -62
- package/src/exports/vite/build/remote.js +10 -12
- package/src/exports/vite/dev/index.js +113 -88
- package/src/exports/vite/index.js +452 -237
- package/src/exports/vite/module_ids.js +3 -1
- package/src/exports/vite/utils.js +1 -10
- package/src/runner.js +13 -0
- package/src/runtime/app/forms.js +4 -0
- package/src/runtime/app/manifest/index.js +1 -0
- package/src/runtime/app/paths/client.js +30 -30
- package/src/runtime/app/paths/internal/client.js +26 -0
- package/src/runtime/app/paths/server.js +22 -9
- package/src/runtime/app/paths/types.d.ts +11 -19
- package/src/runtime/app/server/remote/command.js +12 -7
- package/src/runtime/app/server/remote/form.js +37 -26
- package/src/runtime/app/server/remote/prerender.js +22 -11
- package/src/runtime/app/server/remote/query.js +5 -4
- package/src/runtime/app/server/remote/requested.js +4 -4
- package/src/runtime/app/server/remote/shared.js +48 -30
- package/src/runtime/app/service-worker/index.js +24 -0
- package/src/runtime/app/state/client.js +3 -0
- package/src/runtime/app/state/index.js +3 -3
- package/src/runtime/app/state/server.js +3 -0
- package/src/runtime/client/client.js +627 -311
- package/src/runtime/client/constants.js +2 -6
- package/src/runtime/client/fetcher.js +27 -17
- package/src/runtime/client/remote-functions/form.svelte.js +82 -58
- 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 +2 -2
- package/src/runtime/client/remote-functions/query-batch.svelte.js +3 -4
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +2 -2
- package/src/runtime/client/remote-functions/query-live/iterator.js +15 -10
- package/src/runtime/client/remote-functions/shared.svelte.js +15 -11
- package/src/runtime/client/state.svelte.js +54 -33
- package/src/runtime/client/types.d.ts +1 -2
- package/src/runtime/client/utils.js +21 -14
- package/src/runtime/components/root.svelte +4 -14
- package/src/runtime/form-utils.js +89 -54
- package/src/runtime/props.svelte.js +71 -0
- package/src/runtime/server/cookie.js +1 -1
- package/src/runtime/server/data/index.js +31 -28
- package/src/runtime/server/errors.js +1 -1
- package/src/runtime/server/fetch.js +4 -6
- package/src/runtime/server/page/actions.js +3 -3
- package/src/runtime/server/page/csp.js +86 -103
- package/src/runtime/server/page/index.js +1 -2
- package/src/runtime/server/page/load_data.js +15 -5
- package/src/runtime/server/page/render.js +46 -52
- package/src/runtime/server/page/respond_with_error.js +1 -3
- package/src/runtime/server/remote-functions.js +66 -35
- package/src/runtime/server/respond.js +56 -16
- package/src/runtime/server/utils.js +10 -0
- package/src/types/ambient-private.d.ts +9 -1
- package/src/types/ambient.d.ts +23 -28
- package/src/types/global-private.d.ts +12 -0
- package/src/types/internal.d.ts +15 -10
- package/src/types/private.d.ts +3 -12
- package/src/utils/url.js +12 -0
- package/src/version.js +1 -1
- package/types/index.d.ts +172 -155
- package/types/index.d.ts.map +5 -1
- package/src/core/sync/write_ambient.js +0 -18
- package/src/core/sync/write_tsconfig.js +0 -258
- package/src/runtime/types.d.ts +0 -8
- /package/src/core/sync/{write_tsconfig_test → write_tsconfig/test-app}/package.json +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.13",
|
|
4
4
|
"description": "SvelteKit is the fastest way to build Svelte apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@opentelemetry/api": "^1.9.0",
|
|
33
|
-
"@playwright/test": "
|
|
33
|
+
"@playwright/test": "~1.61.0",
|
|
34
34
|
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
35
35
|
"@types/connect": "^3.4.38",
|
|
36
36
|
"@types/node": "^22.19.19",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"svelte": "^5.56.3",
|
|
41
41
|
"svelte-preprocess": "^6.0.5",
|
|
42
42
|
"typescript": "~6.0.3",
|
|
43
|
-
"valibot": "^1.2
|
|
43
|
+
"valibot": "^1.4.2",
|
|
44
44
|
"vite": "^8.1.5",
|
|
45
45
|
"vitest": "^4.1.10"
|
|
46
46
|
},
|
|
@@ -136,15 +136,15 @@
|
|
|
136
136
|
"format": "prettier --config ../../.prettierrc --write .",
|
|
137
137
|
"test": "pnpm test:unit && pnpm test:integration",
|
|
138
138
|
"test:integration": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test",
|
|
139
|
-
"test:
|
|
140
|
-
"test:
|
|
139
|
+
"test:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:dev",
|
|
140
|
+
"test:build": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:build",
|
|
141
|
+
"test:cross-platform:dev": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:dev",
|
|
142
|
+
"test:cross-platform:build": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:cross-platform:build",
|
|
141
143
|
"test:server-side-route-resolution:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:server-side-route-resolution:dev",
|
|
142
|
-
"test:server-side-route-resolution:build": "pnpm
|
|
144
|
+
"test:server-side-route-resolution:build": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:server-side-route-resolution:build",
|
|
143
145
|
"test:svelte-async:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:svelte-async:dev",
|
|
144
|
-
"test:svelte-async:build": "pnpm
|
|
145
|
-
"test:unit
|
|
146
|
-
"test:unit:prod": "NODE_ENV=production vitest --config kit.vitest.config.js run csp.spec.js cookie.spec.js",
|
|
147
|
-
"test:unit": "pnpm test:unit:dev && pnpm test:unit:prod",
|
|
146
|
+
"test:svelte-async:build": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:svelte-async:build",
|
|
147
|
+
"test:unit": "vitest run ./",
|
|
148
148
|
"generate:version": "node scripts/generate-version.js",
|
|
149
149
|
"generate:types": "node scripts/generate-dts.js"
|
|
150
150
|
}
|
package/src/cli.js
CHANGED
|
@@ -75,19 +75,19 @@ if (!command) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
if (command === 'sync') {
|
|
78
|
-
// create placeholder
|
|
78
|
+
// create placeholder node_modules/$app/tsconfig/tsconfig.json if necessary, to squelch warnings.
|
|
79
79
|
// this isn't bulletproof — if someone has some esoteric config, it will continue
|
|
80
80
|
// to harmlessly warn — but we handle the 90% case and clean up after ourselves
|
|
81
|
-
const
|
|
82
|
-
const base_tsconfig = `${
|
|
81
|
+
const dir = 'node_modules/$app/tsconfig';
|
|
82
|
+
const base_tsconfig = `${dir}/tsconfig.json`;
|
|
83
83
|
const base_tsconfig_json = '{}';
|
|
84
84
|
|
|
85
|
-
const sveltekit_dir_exists = fs.existsSync(
|
|
85
|
+
const sveltekit_dir_exists = fs.existsSync(dir);
|
|
86
86
|
const base_tsconfig_exists = fs.existsSync(base_tsconfig);
|
|
87
87
|
|
|
88
88
|
if (!base_tsconfig_exists) {
|
|
89
89
|
try {
|
|
90
|
-
fs.mkdirSync(
|
|
90
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
91
91
|
} catch {
|
|
92
92
|
// ignore
|
|
93
93
|
}
|
|
@@ -100,7 +100,7 @@ if (command === 'sync') {
|
|
|
100
100
|
const sveltekit_config = extract_svelte_config(vite_config);
|
|
101
101
|
|
|
102
102
|
const sync = await import('./core/sync/sync.js');
|
|
103
|
-
sync.all_types(sveltekit_config);
|
|
103
|
+
sync.all_types(sveltekit_config, vite_config.root);
|
|
104
104
|
|
|
105
105
|
const explicit_env_entry = resolve_explicit_env_entry(sveltekit_config.kit);
|
|
106
106
|
await sync.env(sveltekit_config.kit, explicit_env_entry, vite_config.root, values.mode);
|
|
@@ -113,8 +113,8 @@ if (command === 'sync') {
|
|
|
113
113
|
fs.unlinkSync(base_tsconfig);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
if (!sveltekit_dir_exists && fs.readdirSync(
|
|
117
|
-
fs.rmSync(
|
|
116
|
+
if (!sveltekit_dir_exists && fs.readdirSync(dir).length === 0) {
|
|
117
|
+
fs.rmSync(dir, { recursive: true });
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
} else {
|
package/src/constants.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export const SVELTE_KIT_ASSETS = '/_svelte_kit_assets';
|
|
6
6
|
|
|
7
|
-
export const GENERATED_COMMENT = '// this file is generated — do not edit it
|
|
7
|
+
export const GENERATED_COMMENT = '// this file is generated — do not edit it';
|
|
8
8
|
|
|
9
9
|
export const ENDPOINT_METHODS = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'];
|
|
10
10
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @import { SvelteConfig } from '@sveltejs/vite-plugin-svelte' */
|
|
2
2
|
/** @import { ValidatedKitConfig } from 'types' */
|
|
3
3
|
/** @import { Validator } from './types.js' */
|
|
4
|
+
import { styleText } from 'node:util';
|
|
4
5
|
|
|
5
6
|
const directives = object({
|
|
6
7
|
'child-src': string_array(),
|
|
@@ -77,17 +78,21 @@ export const validate_kit_options = object({
|
|
|
77
78
|
return input;
|
|
78
79
|
}),
|
|
79
80
|
|
|
80
|
-
alias:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
81
|
+
alias: deprecate(
|
|
82
|
+
validate({}, (input, keypath) => {
|
|
83
|
+
if (typeof input !== 'object') {
|
|
84
|
+
throw new Error(`${keypath} should be an object`);
|
|
85
|
+
}
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
for (const key in input) {
|
|
88
|
+
assert_string(input[key], `${keypath}.${key}`);
|
|
89
|
+
}
|
|
88
90
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
return input;
|
|
92
|
+
}),
|
|
93
|
+
(keypath) =>
|
|
94
|
+
`The \`${keypath}\` option is deprecated, and will be removed in a future version of SvelteKit. Use subpath imports instead: https://svelte.dev/docs/kit/$lib`
|
|
95
|
+
),
|
|
91
96
|
|
|
92
97
|
appDir: validate('_app', (input, keypath) => {
|
|
93
98
|
assert_string(input, keypath);
|
|
@@ -270,47 +275,50 @@ export const validate_kit_options = object({
|
|
|
270
275
|
}),
|
|
271
276
|
|
|
272
277
|
serviceWorker: object({
|
|
278
|
+
files: removed(),
|
|
273
279
|
register: boolean(true),
|
|
274
280
|
// options could be undefined but if it is defined we only validate that
|
|
275
281
|
// it's an object since the type comes from the browser itself
|
|
276
|
-
options: validate(undefined, object({}, true))
|
|
277
|
-
files: fun((filename) => !/\.DS_Store/.test(filename))
|
|
282
|
+
options: validate(undefined, object({}, true))
|
|
278
283
|
}),
|
|
279
284
|
|
|
280
285
|
tracing: object({
|
|
281
286
|
server: boolean(false)
|
|
282
287
|
}),
|
|
283
288
|
|
|
284
|
-
typescript:
|
|
285
|
-
|
|
286
|
-
|
|
289
|
+
typescript: deprecate(
|
|
290
|
+
object({
|
|
291
|
+
config: fun((config) => config)
|
|
292
|
+
}),
|
|
293
|
+
(keypath) => {
|
|
294
|
+
return `The \`${keypath}\` option is deprecated, and will be removed in a future version. Add configuration to tsconfig.json directly`;
|
|
295
|
+
}
|
|
296
|
+
),
|
|
287
297
|
|
|
288
298
|
version: object({
|
|
289
299
|
name: string(Date.now().toString()),
|
|
290
|
-
pollInterval: number(
|
|
300
|
+
pollInterval: number(3_600_000)
|
|
291
301
|
})
|
|
292
302
|
});
|
|
293
303
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
// };
|
|
313
|
-
// }
|
|
304
|
+
/**
|
|
305
|
+
* @param {Validator} fn
|
|
306
|
+
* @param {(keypath: string) => string} get_message
|
|
307
|
+
* @returns {Validator}
|
|
308
|
+
*/
|
|
309
|
+
function deprecate(
|
|
310
|
+
fn,
|
|
311
|
+
get_message = (keypath) =>
|
|
312
|
+
`The \`${keypath}\` option is deprecated, and will be removed in a future version`
|
|
313
|
+
) {
|
|
314
|
+
return (input, keypath) => {
|
|
315
|
+
if (input !== undefined) {
|
|
316
|
+
console.warn(styleText(['bold', 'yellow'], get_message(keypath)));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return fn(input, keypath);
|
|
320
|
+
};
|
|
321
|
+
}
|
|
314
322
|
|
|
315
323
|
// Derive the names of SvelteKit's own config options from the schema, so they
|
|
316
324
|
// stay in sync automatically. These are used to separate Kit's options from
|
package/src/core/env.js
CHANGED
|
@@ -10,6 +10,7 @@ import { runtime_directory } from './utils.js';
|
|
|
10
10
|
import { resolve_entry } from '../utils/filesystem.js';
|
|
11
11
|
import { handle_issues, validate } from '../exports/internal/env.js';
|
|
12
12
|
import { get_config_aliases } from '../exports/vite/utils.js';
|
|
13
|
+
import { get_runner } from '../runner.js';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* @typedef {'public' | 'private'} EnvType
|
|
@@ -52,12 +53,14 @@ export async function load_explicit_env(kit, file, root, mode) {
|
|
|
52
53
|
/** @type {Record<string, EnvVarConfig<any>>} */
|
|
53
54
|
let variables;
|
|
54
55
|
|
|
56
|
+
const runner = get_runner(server);
|
|
57
|
+
|
|
55
58
|
/** @type {import('../runtime/app/env/internal.js')} */ (
|
|
56
|
-
await
|
|
59
|
+
await runner.import(`${runtime_directory}/app/env/internal.js`)
|
|
57
60
|
).set_building();
|
|
58
61
|
|
|
59
62
|
try {
|
|
60
|
-
({ variables } = await
|
|
63
|
+
({ variables } = await runner.import(file));
|
|
61
64
|
|
|
62
65
|
if (!variables || typeof variables !== 'object') {
|
|
63
66
|
throw new Error(`${file} must export a variables object`);
|
|
@@ -238,25 +241,35 @@ export function create_sveltekit_env_public(variables, env, prelude) {
|
|
|
238
241
|
* `env.js`. If there are none, values are inlined.
|
|
239
242
|
* @param {Record<string, EnvVarConfig<any>> | null} variables
|
|
240
243
|
* @param {Record<string, string>} env
|
|
244
|
+
* @param {string} version
|
|
241
245
|
* @param {string} global
|
|
242
246
|
* @param {string} base
|
|
243
247
|
* @param {string} app_dir
|
|
244
248
|
*/
|
|
245
|
-
export function create_sveltekit_env_service_worker(
|
|
249
|
+
export function create_sveltekit_env_service_worker(
|
|
250
|
+
variables,
|
|
251
|
+
env,
|
|
252
|
+
version,
|
|
253
|
+
global,
|
|
254
|
+
base,
|
|
255
|
+
app_dir
|
|
256
|
+
) {
|
|
246
257
|
const has_dynamic_public_env = Object.values(variables ?? {}).some(
|
|
247
258
|
(config) => config.public && !config.static
|
|
248
259
|
);
|
|
249
260
|
|
|
250
261
|
if (!has_dynamic_public_env) {
|
|
251
|
-
return create_sveltekit_env_service_worker_dev(variables, env, global);
|
|
262
|
+
return create_sveltekit_env_service_worker_dev(variables, env, version, global);
|
|
252
263
|
}
|
|
253
264
|
|
|
254
265
|
return dedent`
|
|
255
266
|
import { env } from '${base}/${app_dir}/env.js';
|
|
256
267
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
268
|
+
${global} = {
|
|
269
|
+
base: location.pathname.split('/').slice(0, -1).join('/'),
|
|
270
|
+
env,
|
|
271
|
+
version: ${JSON.stringify(version)}
|
|
272
|
+
};
|
|
260
273
|
`;
|
|
261
274
|
}
|
|
262
275
|
|
|
@@ -264,9 +277,10 @@ export function create_sveltekit_env_service_worker(variables, env, global, base
|
|
|
264
277
|
* Creates the `__sveltekit/env/service-worker` module used in development
|
|
265
278
|
* @param {Record<string, EnvVarConfig<any>> | null} variables
|
|
266
279
|
* @param {Record<string, string>} env
|
|
280
|
+
* @param {string} version
|
|
267
281
|
* @param {string} global
|
|
268
282
|
*/
|
|
269
|
-
export function create_sveltekit_env_service_worker_dev(variables, env, global) {
|
|
283
|
+
export function create_sveltekit_env_service_worker_dev(variables, env, version, global) {
|
|
270
284
|
/** @type {string[]} */
|
|
271
285
|
const properties = [];
|
|
272
286
|
|
|
@@ -283,12 +297,12 @@ export function create_sveltekit_env_service_worker_dev(variables, env, global)
|
|
|
283
297
|
handle_issues(issues);
|
|
284
298
|
|
|
285
299
|
return dedent`
|
|
286
|
-
globalThis.__SVELTEKIT_EXPERIMENTAL_EXPLICIT_ENVIRONMENT_VARIABLES__ = true;
|
|
287
|
-
|
|
288
300
|
${global} = {
|
|
301
|
+
base: location.pathname.split('/').slice(0, -1).join('/'),
|
|
289
302
|
env: {
|
|
290
303
|
${properties.join(',\n\t\t') || '// empty'}
|
|
291
|
-
}
|
|
304
|
+
},
|
|
305
|
+
version: ${JSON.stringify(version)}
|
|
292
306
|
};
|
|
293
307
|
`;
|
|
294
308
|
}
|
|
@@ -265,7 +265,7 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env, vit
|
|
|
265
265
|
/** @type {Map<string, Set<string>>} */
|
|
266
266
|
const expected_hashlinks = new Map();
|
|
267
267
|
|
|
268
|
-
/** @type {Map<string, string
|
|
268
|
+
/** @type {Map<string, Set<string>>} */
|
|
269
269
|
const actual_hashlinks = new Map();
|
|
270
270
|
|
|
271
271
|
/**
|
|
@@ -394,7 +394,7 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env, vit
|
|
|
394
394
|
handle_invalid_url({ href, referrer: decoded });
|
|
395
395
|
}
|
|
396
396
|
|
|
397
|
-
actual_hashlinks.set(decoded, ids);
|
|
397
|
+
actual_hashlinks.set(decoded, new Set(ids));
|
|
398
398
|
|
|
399
399
|
/** @param {string} href */
|
|
400
400
|
const removePrerenderOrigin = (href) => {
|
|
@@ -646,7 +646,7 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env, vit
|
|
|
646
646
|
// ignore fragment links to pages that were not prerendered
|
|
647
647
|
if (!hashlinks) continue;
|
|
648
648
|
|
|
649
|
-
if (!hashlinks.
|
|
649
|
+
if (!hashlinks.has(id) && !SPECIAL_HASHLINKS.has(id)) {
|
|
650
650
|
handle_missing_id({ id, path, referrers: Array.from(referrers) });
|
|
651
651
|
}
|
|
652
652
|
}
|
package/src/core/sync/sync.js
CHANGED
|
@@ -1,11 +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 { write_tsconfig } from './write_tsconfig.js';
|
|
4
|
+
import { write_tsconfig } from './write_tsconfig/index.js';
|
|
6
5
|
import { write_types, write_all_types } from './write_types/index.js';
|
|
7
|
-
import {
|
|
8
|
-
import { write_non_ambient } from './write_non_ambient.js';
|
|
6
|
+
import { write_app_types } from './write_app_types.js';
|
|
9
7
|
import { write_server } from './write_server.js';
|
|
10
8
|
import {
|
|
11
9
|
create_node_analyser,
|
|
@@ -21,7 +19,6 @@ import { write_env } from './write_env.js';
|
|
|
21
19
|
*/
|
|
22
20
|
export function init(config, root) {
|
|
23
21
|
write_tsconfig(config.kit, root);
|
|
24
|
-
write_ambient(config.kit);
|
|
25
22
|
}
|
|
26
23
|
|
|
27
24
|
/**
|
|
@@ -37,7 +34,7 @@ export function create(config, root) {
|
|
|
37
34
|
write_client_manifest(config.kit, manifest_data, `${output}/client`);
|
|
38
35
|
write_server(config, output, root);
|
|
39
36
|
write_all_types(config, manifest_data, root);
|
|
40
|
-
|
|
37
|
+
write_app_types(config.kit, manifest_data, root);
|
|
41
38
|
|
|
42
39
|
return { manifest_data };
|
|
43
40
|
}
|
|
@@ -65,7 +62,7 @@ export function update(config, manifest_data, file, root) {
|
|
|
65
62
|
}
|
|
66
63
|
|
|
67
64
|
write_types(config, manifest_data, file, root);
|
|
68
|
-
|
|
65
|
+
write_app_types(config.kit, manifest_data, root);
|
|
69
66
|
}
|
|
70
67
|
|
|
71
68
|
/**
|
|
@@ -81,13 +78,13 @@ export function all(config, root) {
|
|
|
81
78
|
/**
|
|
82
79
|
* Run sync.init and then generate all type files.
|
|
83
80
|
* @param {import('types').ValidatedConfig} config
|
|
81
|
+
* @param {string} root
|
|
84
82
|
*/
|
|
85
|
-
export function all_types(config) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
write_non_ambient(config.kit, manifest_data);
|
|
83
|
+
export function all_types(config, root) {
|
|
84
|
+
init(config, root);
|
|
85
|
+
const manifest_data = create_manifest_data({ config, cwd: root });
|
|
86
|
+
write_all_types(config, manifest_data, root);
|
|
87
|
+
write_app_types(config.kit, manifest_data, root);
|
|
91
88
|
}
|
|
92
89
|
|
|
93
90
|
/**
|
|
@@ -100,7 +97,7 @@ export function all_types(config) {
|
|
|
100
97
|
export async function env(kit, entry, root, mode) {
|
|
101
98
|
const env_config = await load_explicit_env(kit, entry, root, mode);
|
|
102
99
|
|
|
103
|
-
write_env(
|
|
100
|
+
write_env(entry, env_config, root);
|
|
104
101
|
|
|
105
102
|
return env_config;
|
|
106
103
|
}
|
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 { mkdirp, resolve_entry } from '../../utils/filesystem.js';
|
|
4
5
|
|
|
5
6
|
/** @type {Map<string, string>} */
|
|
6
7
|
const previous_contents = new Map();
|
|
@@ -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
|
+
}
|
|
@@ -22,10 +22,6 @@ const remove_group_segments = (/** @type {string} */ id) => {
|
|
|
22
22
|
* @returns {string[]}
|
|
23
23
|
*/
|
|
24
24
|
function get_pathnames_for_trailing_slash(pathname, route) {
|
|
25
|
-
if (pathname === '/') {
|
|
26
|
-
return [pathname];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
25
|
/** @type {Set<string>} */
|
|
30
26
|
const pathnames = new Set();
|
|
31
27
|
|
|
@@ -55,12 +51,8 @@ function get_pathnames_for_trailing_slash(pathname, route) {
|
|
|
55
51
|
// people could use to type their own components.
|
|
56
52
|
// The T generic is needed or else there's a "all declarations must have identical type parameters" error.
|
|
57
53
|
const template = `
|
|
58
|
-
${GENERATED_COMMENT}
|
|
59
|
-
|
|
60
54
|
declare module "svelte/elements" {
|
|
61
55
|
export interface HTMLAttributes<T> {
|
|
62
|
-
'data-sveltekit-keepfocus'?: true | false | '' | undefined | null;
|
|
63
|
-
'data-sveltekit-noscroll'?: true | false | '' | undefined | null;
|
|
64
56
|
'data-sveltekit-preload-code'?:
|
|
65
57
|
| true
|
|
66
58
|
| false
|
|
@@ -74,18 +66,18 @@ declare module "svelte/elements" {
|
|
|
74
66
|
'data-sveltekit-preload-data'?: true | false | '' | 'hover' | 'tap' | undefined | null;
|
|
75
67
|
'data-sveltekit-reload'?: true | false | '' | undefined | null;
|
|
76
68
|
'data-sveltekit-replacestate'?: true | false | '' | undefined | null;
|
|
69
|
+
'data-sveltekit-reset'?: true | false | '' | undefined | null;
|
|
77
70
|
}
|
|
78
71
|
}
|
|
79
|
-
|
|
80
|
-
export {};
|
|
81
72
|
`;
|
|
82
73
|
|
|
83
74
|
/**
|
|
84
75
|
* Generate app types interface extension
|
|
85
76
|
* @param {import('types').ManifestData} manifest_data
|
|
86
77
|
* @param {import('types').ValidatedKitConfig} config
|
|
78
|
+
* @param {string} dir
|
|
87
79
|
*/
|
|
88
|
-
function generate_app_types(manifest_data, config) {
|
|
80
|
+
function generate_app_types(manifest_data, config, dir) {
|
|
89
81
|
/** @type {Map<string, string>} */
|
|
90
82
|
const matcher_types = new Map();
|
|
91
83
|
|
|
@@ -100,7 +92,7 @@ function generate_app_types(manifest_data, config) {
|
|
|
100
92
|
resolve_entry(config.files.params) ??
|
|
101
93
|
config.files.params.replace(/\.(js|ts)$/, '') + '.js';
|
|
102
94
|
|
|
103
|
-
return posixify(path.relative(
|
|
95
|
+
return posixify(path.relative(dir, params_file));
|
|
104
96
|
};
|
|
105
97
|
|
|
106
98
|
type = `import('@sveltejs/kit').MatcherParam<(typeof import('${path_to_params()}').params)[${JSON.stringify(matcher)}]>`;
|
|
@@ -201,7 +193,7 @@ function generate_app_types(manifest_data, config) {
|
|
|
201
193
|
|
|
202
194
|
for (const route of manifest_data.routes) {
|
|
203
195
|
const pathname = remove_group_segments(route.id);
|
|
204
|
-
let normalized_pathname = pathname;
|
|
196
|
+
let normalized_pathname = pathname.slice(1);
|
|
205
197
|
|
|
206
198
|
/** @type {(path: string) => string} */
|
|
207
199
|
let serialise = s;
|
|
@@ -215,7 +207,7 @@ function generate_app_types(manifest_data, config) {
|
|
|
215
207
|
|
|
216
208
|
dynamic_routes.push(route_type);
|
|
217
209
|
|
|
218
|
-
normalized_pathname = replace_required_params(replace_optional_params(pathname));
|
|
210
|
+
normalized_pathname = replace_required_params(replace_optional_params(pathname)).slice(1);
|
|
219
211
|
serialise = (p) => `\`${p}\` & {}`;
|
|
220
212
|
}
|
|
221
213
|
|
|
@@ -240,7 +232,7 @@ function generate_app_types(manifest_data, config) {
|
|
|
240
232
|
layouts.push(`${s(route.id)}: ${layout_type}`);
|
|
241
233
|
}
|
|
242
234
|
|
|
243
|
-
const assets = manifest_data.assets.map((asset) => s(
|
|
235
|
+
const assets = manifest_data.assets.map((asset) => s(asset.file));
|
|
244
236
|
|
|
245
237
|
return [
|
|
246
238
|
'declare module "$app/types" {',
|
|
@@ -248,22 +240,31 @@ function generate_app_types(manifest_data, config) {
|
|
|
248
240
|
`\t\tRouteId(): ${manifest_data.routes.map((r) => s(r.id)).join(' | ')};`,
|
|
249
241
|
`\t\tRouteParams(): {\n\t\t\t${dynamic_routes.join(';\n\t\t\t')}\n\t\t};`,
|
|
250
242
|
`\t\tLayoutParams(): {\n\t\t\t${layouts.join(';\n\t\t\t')}\n\t\t};`,
|
|
251
|
-
`\t\
|
|
252
|
-
'\t\tResolvedPathname(): `${"" | `/${string}
|
|
253
|
-
`\t\
|
|
243
|
+
`\t\tPath(): ${Array.from(pathnames).join(' | ')};`,
|
|
244
|
+
'\t\tResolvedPathname(): `${"/" | `/${string}/`}${ReturnType<AppTypes[\'Path\']>}`;',
|
|
245
|
+
`\t\tAssetPath(): ${assets.join(' | ') || 'never'};`,
|
|
254
246
|
'\t}',
|
|
255
247
|
'}'
|
|
256
248
|
].join('\n');
|
|
257
249
|
}
|
|
258
250
|
|
|
259
251
|
/**
|
|
260
|
-
* Writes
|
|
252
|
+
* Writes `node_modules/$app/types/index.d.ts`. This file contains
|
|
253
|
+
* declarations for `$app/types` and `svelte/elements`, and
|
|
254
|
+
* imports `env.ts` which declares `$app/env/(public|private)`
|
|
261
255
|
* @param {import('types').ValidatedKitConfig} config
|
|
262
256
|
* @param {import('types').ManifestData} manifest_data
|
|
257
|
+
* @param {string} root
|
|
263
258
|
*/
|
|
264
|
-
export function
|
|
265
|
-
const
|
|
266
|
-
|
|
259
|
+
export function write_app_types(config, manifest_data, root) {
|
|
260
|
+
const dir = path.join(root, 'node_modules/$app/types');
|
|
261
|
+
|
|
262
|
+
const content = [
|
|
263
|
+
GENERATED_COMMENT,
|
|
264
|
+
`import '@sveltejs/kit';\nimport './env';`,
|
|
265
|
+
generate_app_types(manifest_data, config, dir),
|
|
266
|
+
template.trim()
|
|
267
|
+
].join('\n\n');
|
|
267
268
|
|
|
268
|
-
write_if_changed(path.join(
|
|
269
|
+
write_if_changed(path.join(dir, 'index.d.ts'), content);
|
|
269
270
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { styleText } from 'node:util';
|
|
1
|
+
import { check_spelling, dedent, write_if_changed } from './utils.js';
|
|
3
2
|
import { relative_path, resolve_entry } from '../../utils/filesystem.js';
|
|
4
3
|
import { s } from '../../utils/misc.js';
|
|
5
|
-
import { dedent, write_if_changed } from './utils.js';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Writes the client manifest to disk. The manifest is used to power the router. It contains the
|
|
@@ -123,15 +121,9 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
|
|
|
123
121
|
const client_hooks_file = resolve_entry(kit.files.hooks.client);
|
|
124
122
|
const universal_hooks_file = resolve_entry(kit.files.hooks.universal);
|
|
125
123
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
styleText(
|
|
130
|
-
['bold', 'yellow'],
|
|
131
|
-
`Unexpected + prefix. Did you mean ${typo.split('/').at(-1)?.slice(1)}?` +
|
|
132
|
-
` at ${path.resolve(typo)}`
|
|
133
|
-
)
|
|
134
|
-
);
|
|
124
|
+
if (!client_hooks_file) {
|
|
125
|
+
check_spelling('src/hooks.client', 'src/+hooks.client', 'Unexpected + prefix');
|
|
126
|
+
check_spelling('src/hooks.client', 'src/hook.client', 'Missing s suffix');
|
|
135
127
|
}
|
|
136
128
|
|
|
137
129
|
// Stringified version of
|
|
@@ -10,16 +10,18 @@ const DOCS = '// See https://svelte.dev/docs/kit/environment-variables for more
|
|
|
10
10
|
* Writes ambient declarations including types reference to @sveltejs/kit,
|
|
11
11
|
* and the existing environment variables in process.env to
|
|
12
12
|
* $env/static/private and $env/static/public
|
|
13
|
-
* @param {import('types').ValidatedKitConfig} kit
|
|
14
13
|
* @param {string | null} entry
|
|
15
14
|
* @param {Record<string, EnvVarConfig<any>> | null} env_config
|
|
15
|
+
* @param {string} root
|
|
16
16
|
*/
|
|
17
|
-
export function write_env(
|
|
17
|
+
export function write_env(entry, env_config, root) {
|
|
18
18
|
const content = [];
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
const dir = path.join(root, 'node_modules/$app/types');
|
|
21
|
+
const out = path.join(dir, 'env.d.ts');
|
|
20
22
|
|
|
21
23
|
if (entry && env_config) {
|
|
22
|
-
const relative = posixify(path.relative(
|
|
24
|
+
const relative = posixify(path.relative(dir, entry));
|
|
23
25
|
content.push(
|
|
24
26
|
`// This file is generated from ${relative}.\n${DOCS}`,
|
|
25
27
|
create_explicit_env_types(env_config, relative, 'private'),
|