@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,13 +1,14 @@
|
|
|
1
|
+
/** @import { Adapter } from '@sveltejs/kit' */
|
|
1
2
|
import { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
3
|
import { dirname, join } from 'node:path';
|
|
3
4
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
5
|
+
import { mkdirp, walk } from '../../utils/filesystem.js';
|
|
6
|
+
import { posixify } from '../../utils/os.js';
|
|
6
7
|
import { noop } from '../../utils/functions.js';
|
|
7
8
|
import { decode_uri, is_root_relative, resolve } from '../../utils/url.js';
|
|
8
9
|
import { escape_html } from '../../utils/escape.js';
|
|
9
10
|
import { logger } from '../utils.js';
|
|
10
|
-
import {
|
|
11
|
+
import { extract_svelte_config, load_vite_config } from '../config/index.js';
|
|
11
12
|
import { get_route_segments } from '../../utils/routing.js';
|
|
12
13
|
import { queue } from './queue.js';
|
|
13
14
|
import { crawl } from './crawl.js';
|
|
@@ -16,7 +17,6 @@ import * as devalue from 'devalue';
|
|
|
16
17
|
import { createReadableStream } from '@sveltejs/kit/node';
|
|
17
18
|
import generate_fallback from './fallback.js';
|
|
18
19
|
import { stringify_remote_arg } from '../../runtime/shared.js';
|
|
19
|
-
import { filter_env } from '../../utils/env.js';
|
|
20
20
|
|
|
21
21
|
export default forked(import.meta.url, prerender);
|
|
22
22
|
|
|
@@ -33,10 +33,11 @@ const SPECIAL_HASHLINKS = new Set(['', 'top']);
|
|
|
33
33
|
* manifest_path: string;
|
|
34
34
|
* metadata: import('types').ServerMetadata;
|
|
35
35
|
* verbose: boolean;
|
|
36
|
-
* env: Record<string, string
|
|
36
|
+
* env: Record<string, string>;
|
|
37
|
+
* vite_config_file: string | undefined;
|
|
37
38
|
* }} opts
|
|
38
39
|
*/
|
|
39
|
-
async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
|
|
40
|
+
async function prerender({ hash, out, manifest_path, metadata, verbose, env, vite_config_file }) {
|
|
40
41
|
/** @type {import('@sveltejs/kit').SSRManifest} */
|
|
41
42
|
const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;
|
|
42
43
|
|
|
@@ -46,7 +47,7 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
|
|
|
46
47
|
/** @type {import('types').ServerModule} */
|
|
47
48
|
const { Server } = await import(pathToFileURL(`${out}/server/index.js`).href);
|
|
48
49
|
|
|
49
|
-
// configure `import { building } from
|
|
50
|
+
// configure `import { building } from `$app/env` —
|
|
50
51
|
// essential we do this before analysing the code
|
|
51
52
|
internal.set_building();
|
|
52
53
|
internal.set_prerendering();
|
|
@@ -100,8 +101,9 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
|
|
|
100
101
|
/** @type {Set<string>} */
|
|
101
102
|
const prerendered_routes = new Set();
|
|
102
103
|
|
|
103
|
-
|
|
104
|
-
|
|
104
|
+
const vite_config = await load_vite_config(vite_config_file);
|
|
105
|
+
|
|
106
|
+
const config = extract_svelte_config(vite_config).kit;
|
|
105
107
|
|
|
106
108
|
if (hash) {
|
|
107
109
|
const fallback = await generate_fallback({
|
|
@@ -123,13 +125,17 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
|
|
|
123
125
|
return { prerendered, prerender_map };
|
|
124
126
|
}
|
|
125
127
|
|
|
126
|
-
|
|
128
|
+
// TODO this can just be config.adapter?
|
|
129
|
+
/** @type {Adapter | undefined} */
|
|
130
|
+
const adapter = vite_config.plugins.find(
|
|
131
|
+
(plugin) => plugin.name === 'vite-plugin-sveltekit-adapter'
|
|
132
|
+
)?.api?.adapter;
|
|
133
|
+
|
|
134
|
+
const emulator = await adapter?.emulate?.();
|
|
127
135
|
|
|
128
136
|
/** @type {import('types').Logger} */
|
|
129
137
|
const log = logger({ verbose });
|
|
130
138
|
|
|
131
|
-
installPolyfills();
|
|
132
|
-
|
|
133
139
|
/** @type {Map<string, string>} */
|
|
134
140
|
const saved = new Map();
|
|
135
141
|
|
|
@@ -492,11 +498,7 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
|
|
|
492
498
|
// the user's remote function modules may reference environment variables,
|
|
493
499
|
// `read` or the `manifest` at the top-level so we need to set them before
|
|
494
500
|
// evaluating those modules to avoid potential runtime errors
|
|
495
|
-
|
|
496
|
-
const private_env = filter_env(env, private_prefix, public_prefix);
|
|
497
|
-
const public_env = filter_env(env, public_prefix, private_prefix);
|
|
498
|
-
internal.set_private_env(private_env);
|
|
499
|
-
internal.set_public_env(public_env);
|
|
501
|
+
internal.set_env(env);
|
|
500
502
|
internal.set_manifest(manifest);
|
|
501
503
|
internal.set_read_implementation((file) => createReadableStream(`${out}/server/${file}`));
|
|
502
504
|
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/** @import { PromiseWithResolvers } from '../../utils/promise.js' */
|
|
2
|
-
import { with_resolvers } from '../../utils/promise.js';
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* @typedef {{
|
|
6
3
|
* fn: () => Promise<any>,
|
|
@@ -13,7 +10,9 @@ import { with_resolvers } from '../../utils/promise.js';
|
|
|
13
10
|
export function queue(concurrency) {
|
|
14
11
|
/** @type {Task[]} */
|
|
15
12
|
const tasks = [];
|
|
16
|
-
const { promise, resolve, reject } = /** @type {PromiseWithResolvers<void>} */ (
|
|
13
|
+
const { promise, resolve, reject } = /** @type {PromiseWithResolvers<void>} */ (
|
|
14
|
+
Promise.withResolvers()
|
|
15
|
+
);
|
|
17
16
|
|
|
18
17
|
let current = 0;
|
|
19
18
|
let closed = false;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
+
import { lookup } from 'mrmime';
|
|
1
2
|
import fs from 'node:fs';
|
|
2
3
|
import path from 'node:path';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import { list_files, runtime_directory } from '../../utils.js';
|
|
7
|
-
import { posixify, resolve_entry } from '../../../utils/filesystem.js';
|
|
4
|
+
import { styleText } from 'node:util';
|
|
5
|
+
import { resolve_entry } from '../../../utils/filesystem.js';
|
|
6
|
+
import { posixify } from '../../../utils/os.js';
|
|
8
7
|
import { parse_route_id } from '../../../utils/routing.js';
|
|
8
|
+
import { list_files, runtime_directory } from '../../utils.js';
|
|
9
9
|
import { prevent_conflicts } from './conflict.js';
|
|
10
10
|
import { sort_routes } from './sort.js';
|
|
11
|
-
import { isSvelte5Plus } from '../utils.js';
|
|
12
11
|
import {
|
|
13
12
|
create_node_analyser,
|
|
14
13
|
get_page_options
|
|
@@ -19,14 +18,14 @@ import {
|
|
|
19
18
|
* @param {{
|
|
20
19
|
* config: import('types').ValidatedConfig;
|
|
21
20
|
* fallback?: string;
|
|
22
|
-
* cwd
|
|
21
|
+
* cwd: string;
|
|
23
22
|
* }} opts
|
|
24
23
|
* @returns {import('types').ManifestData}
|
|
25
24
|
*/
|
|
26
25
|
export default function create_manifest_data({
|
|
27
26
|
config,
|
|
28
|
-
fallback = `${runtime_directory}/components
|
|
29
|
-
cwd
|
|
27
|
+
fallback = `${runtime_directory}/components`,
|
|
28
|
+
cwd
|
|
30
29
|
}) {
|
|
31
30
|
const assets = create_assets(config);
|
|
32
31
|
const hooks = create_hooks(config, cwd);
|
|
@@ -116,8 +115,8 @@ function create_matchers(config, cwd) {
|
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
/**
|
|
119
|
-
* @param {import('types').ValidatedConfig} config
|
|
120
118
|
* @param {string} cwd
|
|
119
|
+
* @param {import('types').ValidatedConfig} config
|
|
121
120
|
* @param {string} fallback
|
|
122
121
|
*/
|
|
123
122
|
function create_routes_and_nodes(cwd, config, fallback) {
|
|
@@ -241,12 +240,11 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
241
240
|
);
|
|
242
241
|
if (typo) {
|
|
243
242
|
console.log(
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
.
|
|
247
|
-
`
|
|
248
|
-
|
|
249
|
-
)
|
|
243
|
+
styleText(
|
|
244
|
+
['bold', 'yellow'],
|
|
245
|
+
`Missing route file prefix. Did you mean +${file.name}?` +
|
|
246
|
+
` at ${path.join(dir, file.name)}`
|
|
247
|
+
)
|
|
250
248
|
);
|
|
251
249
|
}
|
|
252
250
|
|
|
@@ -421,7 +419,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
421
419
|
|
|
422
420
|
const indexes = new Map(nodes.map((node, i) => [node, i]));
|
|
423
421
|
|
|
424
|
-
const node_analyser = create_node_analyser();
|
|
422
|
+
const node_analyser = create_node_analyser(cwd);
|
|
425
423
|
|
|
426
424
|
for (const route of routes) {
|
|
427
425
|
if (!route.leaf) continue;
|
|
@@ -473,7 +471,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
473
471
|
|
|
474
472
|
for (const route of routes) {
|
|
475
473
|
if (route.endpoint) {
|
|
476
|
-
route.endpoint.page_options = get_page_options(route.endpoint.file);
|
|
474
|
+
route.endpoint.page_options = get_page_options(route.endpoint.file, cwd);
|
|
477
475
|
}
|
|
478
476
|
}
|
|
479
477
|
|
package/src/core/sync/sync.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import process from 'node:process';
|
|
2
3
|
import create_manifest_data from './create_manifest_data/index.js';
|
|
3
4
|
import { write_client_manifest } from './write_client_manifest.js';
|
|
4
5
|
import { write_root } from './write_root.js';
|
|
@@ -11,30 +12,33 @@ import {
|
|
|
11
12
|
create_node_analyser,
|
|
12
13
|
get_page_options
|
|
13
14
|
} from '../../exports/vite/static_analysis/index.js';
|
|
15
|
+
import { load_explicit_env } from '../env.js';
|
|
16
|
+
import { write_env } from './write_env.js';
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
19
|
* Initialize SvelteKit's generated files that only depend on the config and mode.
|
|
17
20
|
* @param {import('types').ValidatedConfig} config
|
|
18
|
-
* @param {string}
|
|
21
|
+
* @param {string} root The project root directory
|
|
19
22
|
*/
|
|
20
|
-
export function init(config,
|
|
21
|
-
write_tsconfig(config.kit);
|
|
22
|
-
write_ambient(config.kit
|
|
23
|
+
export function init(config, root) {
|
|
24
|
+
write_tsconfig(config.kit, root);
|
|
25
|
+
write_ambient(config.kit);
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* Update SvelteKit's generated files
|
|
27
30
|
* @param {import('types').ValidatedConfig} config
|
|
31
|
+
* @param {string} root The project root directory
|
|
28
32
|
*/
|
|
29
|
-
export function create(config) {
|
|
30
|
-
const manifest_data = create_manifest_data({ config });
|
|
33
|
+
export function create(config, root) {
|
|
34
|
+
const manifest_data = create_manifest_data({ config, cwd: root });
|
|
31
35
|
|
|
32
36
|
const output = path.join(config.kit.outDir, 'generated');
|
|
33
37
|
|
|
34
38
|
write_client_manifest(config.kit, manifest_data, `${output}/client`);
|
|
35
|
-
write_server(config, output);
|
|
39
|
+
write_server(config, output, root);
|
|
36
40
|
write_root(manifest_data, config, output);
|
|
37
|
-
write_all_types(config, manifest_data);
|
|
41
|
+
write_all_types(config, manifest_data, root);
|
|
38
42
|
write_non_ambient(config.kit, manifest_data);
|
|
39
43
|
|
|
40
44
|
return { manifest_data };
|
|
@@ -47,9 +51,10 @@ export function create(config) {
|
|
|
47
51
|
* @param {import('types').ValidatedConfig} config
|
|
48
52
|
* @param {import('types').ManifestData} manifest_data
|
|
49
53
|
* @param {string} file
|
|
54
|
+
* @param {string} root The project root directory
|
|
50
55
|
*/
|
|
51
|
-
export function update(config, manifest_data, file) {
|
|
52
|
-
const node_analyser = create_node_analyser();
|
|
56
|
+
export function update(config, manifest_data, file, root) {
|
|
57
|
+
const node_analyser = create_node_analyser(root);
|
|
53
58
|
|
|
54
59
|
for (const node of manifest_data.nodes) {
|
|
55
60
|
node.page_options = node_analyser.get_page_options(node);
|
|
@@ -57,40 +62,56 @@ export function update(config, manifest_data, file) {
|
|
|
57
62
|
|
|
58
63
|
for (const route of manifest_data.routes) {
|
|
59
64
|
if (route.endpoint) {
|
|
60
|
-
route.endpoint.page_options = get_page_options(route.endpoint.file);
|
|
65
|
+
route.endpoint.page_options = get_page_options(route.endpoint.file, root);
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
|
|
64
|
-
write_types(config, manifest_data, file);
|
|
69
|
+
write_types(config, manifest_data, file, root);
|
|
65
70
|
write_non_ambient(config.kit, manifest_data);
|
|
66
71
|
}
|
|
67
72
|
|
|
68
73
|
/**
|
|
69
74
|
* Run sync.init and sync.create in series, returning the result from sync.create.
|
|
70
75
|
* @param {import('types').ValidatedConfig} config
|
|
71
|
-
* @param {string}
|
|
76
|
+
* @param {string} root The project root directory
|
|
72
77
|
*/
|
|
73
|
-
export function all(config,
|
|
74
|
-
init(config,
|
|
75
|
-
return create(config);
|
|
78
|
+
export function all(config, root) {
|
|
79
|
+
init(config, root);
|
|
80
|
+
return create(config, root);
|
|
76
81
|
}
|
|
77
82
|
|
|
78
83
|
/**
|
|
79
84
|
* Run sync.init and then generate all type files.
|
|
80
85
|
* @param {import('types').ValidatedConfig} config
|
|
81
|
-
* @param {string} mode The Vite mode
|
|
82
86
|
*/
|
|
83
|
-
export function all_types(config
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
export function all_types(config) {
|
|
88
|
+
const cwd = process.cwd();
|
|
89
|
+
init(config, cwd);
|
|
90
|
+
const manifest_data = create_manifest_data({ config, cwd });
|
|
91
|
+
write_all_types(config, manifest_data, cwd);
|
|
87
92
|
write_non_ambient(config.kit, manifest_data);
|
|
88
93
|
}
|
|
89
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Generate modules and types for explicit env vars
|
|
97
|
+
* @param {import('types').ValidatedKitConfig} kit
|
|
98
|
+
* @param {string | null} entry
|
|
99
|
+
* @param {string} root The Vite root
|
|
100
|
+
* @param {string} mode The Vite mode
|
|
101
|
+
*/
|
|
102
|
+
export async function env(kit, entry, root, mode) {
|
|
103
|
+
const env_config = await load_explicit_env(kit, entry, root, mode);
|
|
104
|
+
|
|
105
|
+
write_env(kit, entry, env_config);
|
|
106
|
+
|
|
107
|
+
return env_config;
|
|
108
|
+
}
|
|
109
|
+
|
|
90
110
|
/**
|
|
91
111
|
* Regenerate __SERVER__/internal.js in response to src/{app.html,error.html,service-worker.js} changing
|
|
92
112
|
* @param {import('types').ValidatedConfig} config
|
|
113
|
+
* @param {string} root The project root directory
|
|
93
114
|
*/
|
|
94
|
-
export function server(config) {
|
|
95
|
-
write_server(config, path.join(config.kit.outDir, 'generated'));
|
|
115
|
+
export function server(config, root) {
|
|
116
|
+
write_server(config, path.join(config.kit.outDir, 'generated'), root);
|
|
96
117
|
}
|
package/src/core/sync/utils.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { mkdirp } from '../../utils/filesystem.js';
|
|
4
|
-
import { import_peer } from '../../utils/import.js';
|
|
5
|
-
|
|
6
|
-
/** @type {{ VERSION: string }} */
|
|
7
|
-
const { VERSION } = await import_peer('svelte/compiler');
|
|
8
|
-
|
|
9
|
-
const [MAJOR, MINOR] = VERSION.split('.').map(Number);
|
|
10
4
|
|
|
11
5
|
/** @type {Map<string, string>} */
|
|
12
6
|
const previous_contents = new Map();
|
|
@@ -74,12 +68,3 @@ export function dedent(strings, ...values) {
|
|
|
74
68
|
|
|
75
69
|
return str;
|
|
76
70
|
}
|
|
77
|
-
|
|
78
|
-
export function isSvelte5Plus() {
|
|
79
|
-
return MAJOR >= 5;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// TODO 3.0 remove this once we can bump the peerDep range
|
|
83
|
-
export function supportsTrustedTypes() {
|
|
84
|
-
return (MAJOR === 5 && MINOR >= 51) || MAJOR > 5;
|
|
85
|
-
}
|
|
@@ -1,63 +1,18 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
1
|
import path from 'node:path';
|
|
3
|
-
import { fileURLToPath } from 'node:url';
|
|
4
|
-
import { get_env } from '../../exports/vite/utils.js';
|
|
5
2
|
import { GENERATED_COMMENT } from '../../constants.js';
|
|
6
|
-
import { create_dynamic_types, create_static_types } from '../env.js';
|
|
7
3
|
import { write_if_changed } from './utils.js';
|
|
8
4
|
|
|
9
|
-
// TODO
|
|
10
|
-
// inside either `packages/kit` or `svelte.dev/docs/kit`
|
|
11
|
-
const descriptions_dir = fileURLToPath(new URL('../../../src/types/synthetic', import.meta.url));
|
|
12
|
-
|
|
13
|
-
/** @param {string} filename */
|
|
14
|
-
function read_description(filename) {
|
|
15
|
-
const content = fs.readFileSync(`${descriptions_dir}/${filename}`, 'utf8');
|
|
16
|
-
return `/**\n${content
|
|
17
|
-
.trim()
|
|
18
|
-
.split('\n')
|
|
19
|
-
.map((line) => ` * ${line}`)
|
|
20
|
-
.join('\n')}\n */`;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @param {import('types').Env} env
|
|
25
|
-
* @param {{
|
|
26
|
-
* public_prefix: string;
|
|
27
|
-
* private_prefix: string;
|
|
28
|
-
* }} prefixes
|
|
29
|
-
*/
|
|
30
|
-
const template = (env, prefixes) => `
|
|
31
|
-
${GENERATED_COMMENT}
|
|
32
|
-
|
|
33
|
-
/// <reference types="@sveltejs/kit" />
|
|
34
|
-
|
|
35
|
-
${read_description('$env+static+private.md')}
|
|
36
|
-
${create_static_types('private', env)}
|
|
37
|
-
|
|
38
|
-
${read_description('$env+static+public.md')}
|
|
39
|
-
${create_static_types('public', env)}
|
|
40
|
-
|
|
41
|
-
${read_description('$env+dynamic+private.md')}
|
|
42
|
-
${create_dynamic_types('private', env, prefixes)}
|
|
43
|
-
|
|
44
|
-
${read_description('$env+dynamic+public.md')}
|
|
45
|
-
${create_dynamic_types('public', env, prefixes)}
|
|
46
|
-
`;
|
|
5
|
+
// TODO get rid of this, it's useless
|
|
47
6
|
|
|
48
7
|
/**
|
|
49
8
|
* Writes ambient declarations including types reference to @sveltejs/kit,
|
|
50
9
|
* and the existing environment variables in process.env to
|
|
51
10
|
* $env/static/private and $env/static/public
|
|
52
11
|
* @param {import('types').ValidatedKitConfig} config
|
|
53
|
-
* @param {string} mode The Vite mode
|
|
54
12
|
*/
|
|
55
|
-
export function write_ambient(config
|
|
56
|
-
|
|
57
|
-
const
|
|
13
|
+
export function write_ambient(config) {
|
|
14
|
+
/** @type {string} */
|
|
15
|
+
const content = `${GENERATED_COMMENT}\n/// <reference types="@sveltejs/kit" />`;
|
|
58
16
|
|
|
59
|
-
write_if_changed(
|
|
60
|
-
path.join(config.outDir, 'ambient.d.ts'),
|
|
61
|
-
template(env, { public_prefix, private_prefix })
|
|
62
|
-
);
|
|
17
|
+
write_if_changed(path.join(config.outDir, 'ambient.d.ts'), content);
|
|
63
18
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { styleText } from 'node:util';
|
|
2
3
|
import { relative_path, resolve_entry } from '../../utils/filesystem.js';
|
|
3
4
|
import { s } from '../../utils/misc.js';
|
|
4
|
-
import { dedent,
|
|
5
|
-
import colors from 'kleur';
|
|
5
|
+
import { dedent, write_if_changed } from './utils.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Writes the client manifest to disk. The manifest is used to power the router. It contains the
|
|
@@ -126,12 +126,11 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
|
|
|
126
126
|
const typo = resolve_entry('src/+hooks.client');
|
|
127
127
|
if (typo) {
|
|
128
128
|
console.log(
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
.
|
|
132
|
-
`
|
|
133
|
-
|
|
134
|
-
)
|
|
129
|
+
styleText(
|
|
130
|
+
['bold', 'yellow'],
|
|
131
|
+
`Unexpected + prefix. Did you mean ${typo.split('/').at(-1)?.slice(1)}?` +
|
|
132
|
+
` at ${path.resolve(typo)}`
|
|
133
|
+
)
|
|
135
134
|
);
|
|
136
135
|
}
|
|
137
136
|
|
|
@@ -177,7 +176,7 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
|
|
|
177
176
|
|
|
178
177
|
export const decode = (type, value) => decoders[type](value);
|
|
179
178
|
|
|
180
|
-
export { default as root } from '../root
|
|
179
|
+
export { default as root } from '../root.js';
|
|
181
180
|
`
|
|
182
181
|
);
|
|
183
182
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** @import { EnvVarConfig } from '@sveltejs/kit' */
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { create_explicit_env_types } from '../env.js';
|
|
4
|
+
import { write_if_changed } from './utils.js';
|
|
5
|
+
|
|
6
|
+
const DOCS = '// See https://svelte.dev/docs/kit/environment-variables for more information';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Writes ambient declarations including types reference to @sveltejs/kit,
|
|
10
|
+
* and the existing environment variables in process.env to
|
|
11
|
+
* $env/static/private and $env/static/public
|
|
12
|
+
* @param {import('types').ValidatedKitConfig} kit
|
|
13
|
+
* @param {string | null} entry
|
|
14
|
+
* @param {Record<string, EnvVarConfig<any>> | null} env_config
|
|
15
|
+
*/
|
|
16
|
+
export function write_env(kit, entry, env_config) {
|
|
17
|
+
const content = [];
|
|
18
|
+
const out = path.join(kit.outDir, 'env.d.ts');
|
|
19
|
+
|
|
20
|
+
if (entry && env_config) {
|
|
21
|
+
const relative = path.relative(kit.outDir, entry);
|
|
22
|
+
content.push(
|
|
23
|
+
`// This file is generated from ${relative}.\n${DOCS}`,
|
|
24
|
+
create_explicit_env_types(env_config, relative, 'private'),
|
|
25
|
+
create_explicit_env_types(env_config, relative, 'public')
|
|
26
|
+
);
|
|
27
|
+
} else {
|
|
28
|
+
content.push(
|
|
29
|
+
DOCS,
|
|
30
|
+
create_explicit_env_types({}, '', 'private'),
|
|
31
|
+
create_explicit_env_types({}, '', 'public')
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
write_if_changed(out, content.join('\n\n'));
|
|
36
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { GENERATED_COMMENT } from '../../constants.js';
|
|
3
|
-
import { posixify } from '../../utils/
|
|
3
|
+
import { posixify } from '../../utils/os.js';
|
|
4
4
|
import { write_if_changed } from './utils.js';
|
|
5
5
|
import { s } from '../../utils/misc.js';
|
|
6
6
|
import { get_route_segments } from '../../utils/routing.js';
|
|
@@ -58,21 +58,21 @@ ${GENERATED_COMMENT}
|
|
|
58
58
|
|
|
59
59
|
declare module "svelte/elements" {
|
|
60
60
|
export interface HTMLAttributes<T> {
|
|
61
|
-
'data-sveltekit-keepfocus'?: true |
|
|
62
|
-
'data-sveltekit-noscroll'?: true |
|
|
61
|
+
'data-sveltekit-keepfocus'?: true | false | '' | undefined | null;
|
|
62
|
+
'data-sveltekit-noscroll'?: true | false | '' | undefined | null;
|
|
63
63
|
'data-sveltekit-preload-code'?:
|
|
64
64
|
| true
|
|
65
|
+
| false
|
|
65
66
|
| ''
|
|
66
67
|
| 'eager'
|
|
67
68
|
| 'viewport'
|
|
68
69
|
| 'hover'
|
|
69
70
|
| 'tap'
|
|
70
|
-
| 'off'
|
|
71
71
|
| undefined
|
|
72
72
|
| null;
|
|
73
|
-
'data-sveltekit-preload-data'?: true |
|
|
74
|
-
'data-sveltekit-reload'?: true |
|
|
75
|
-
'data-sveltekit-replacestate'?: true |
|
|
73
|
+
'data-sveltekit-preload-data'?: true | false | '' | 'hover' | 'tap' | undefined | null;
|
|
74
|
+
'data-sveltekit-reload'?: true | false | '' | undefined | null;
|
|
75
|
+
'data-sveltekit-replacestate'?: true | false | '' | undefined | null;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|