@sveltejs/kit 2.63.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 +17 -22
- package/src/cli.js +19 -16
- package/src/core/adapt/builder.js +25 -77
- package/src/core/adapt/index.js +6 -4
- package/src/core/config/index.js +12 -84
- package/src/core/config/options.js +36 -46
- package/src/core/env.js +5 -130
- 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 +19 -16
- package/src/core/postbuild/fallback.js +0 -3
- package/src/core/postbuild/prerender.js +18 -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 +30 -25
- package/src/core/sync/utils.js +0 -15
- package/src/core/sync/write_ambient.js +3 -54
- package/src/core/sync/write_client_manifest.js +8 -9
- package/src/core/sync/write_env.js +5 -1
- package/src/core/sync/write_non_ambient.js +7 -7
- package/src/core/sync/write_root.js +40 -88
- package/src/core/sync/write_server.js +16 -23
- package/src/core/sync/write_tsconfig.js +28 -24
- package/src/core/sync/write_types/index.js +31 -25
- package/src/core/utils.js +14 -11
- package/src/exports/index.js +8 -21
- package/src/exports/node/index.js +8 -13
- package/src/exports/public.d.ts +35 -76
- 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 +30 -31
- package/src/exports/vite/index.js +938 -732
- package/src/exports/vite/module_ids.js +1 -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 +9 -45
- package/src/runtime/app/env/internal.js +3 -0
- package/src/runtime/app/env/public/client.js +0 -6
- package/src/runtime/app/env/public/server.js +0 -6
- 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 +0 -7
- 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/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 +8 -10
- 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 +1 -3
- package/src/runtime/server/fetch.js +6 -10
- package/src/runtime/server/index.js +3 -9
- package/src/runtime/server/page/render.js +32 -44
- package/src/runtime/server/page/types.d.ts +4 -2
- package/src/runtime/server/respond.js +2 -2
- 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/global-private.d.ts +5 -1
- package/src/types/internal.d.ts +3 -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 +7 -6
- 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 +45 -138
- package/types/index.d.ts.map +1 -8
- package/src/exports/vite/build/build_service_worker.js +0 -165
- package/src/runtime/app/environment/index.js +0 -10
- package/src/runtime/app/environment/types.d.ts +0 -19
- 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/components/{svelte-5/error.svelte → error.svelte} +0 -0
package/src/core/env.js
CHANGED
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
/** @import { EnvVarConfig } from '@sveltejs/kit' */
|
|
3
3
|
/** @import { ValidatedKitConfig } from 'types' */
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import process from 'node:process';
|
|
6
5
|
import * as vite from 'vite';
|
|
7
6
|
import * as devalue from 'devalue';
|
|
8
7
|
import { GENERATED_COMMENT } from '../constants.js';
|
|
9
8
|
import { dedent } from './sync/utils.js';
|
|
10
|
-
import {
|
|
9
|
+
import { runtime_directory } from './utils.js';
|
|
11
10
|
import { resolve_entry } from '../utils/filesystem.js';
|
|
12
11
|
import { handle_issues, validate } from '../exports/internal/env.js';
|
|
13
12
|
import { get_config_aliases } from '../exports/vite/utils.js';
|
|
@@ -16,42 +15,22 @@ import { get_config_aliases } from '../exports/vite/utils.js';
|
|
|
16
15
|
* @typedef {'public' | 'private'} EnvType
|
|
17
16
|
*/
|
|
18
17
|
|
|
19
|
-
let warned = false;
|
|
20
|
-
|
|
21
18
|
/**
|
|
22
19
|
* @param {import('types').ValidatedKitConfig} config
|
|
23
20
|
* @returns {string | null}
|
|
24
21
|
*/
|
|
25
22
|
export function resolve_explicit_env_entry(config) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (resolved) {
|
|
29
|
-
if (config.experimental.explicitEnvironmentVariables) {
|
|
30
|
-
return resolved;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!warned) {
|
|
34
|
-
console.warn(
|
|
35
|
-
`${path.relative(process.cwd(), resolved)} requires the \`experimental.explicitEnvironmentVariables\` flag to be set`
|
|
36
|
-
);
|
|
37
|
-
warned = true;
|
|
38
|
-
}
|
|
39
|
-
} else if (config.experimental.explicitEnvironmentVariables) {
|
|
40
|
-
console.warn(
|
|
41
|
-
'experimental.explicitEnvironmentVariables was set, but no src/env.ts or src/env.js file could be found'
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return null;
|
|
23
|
+
return resolve_entry(path.join(config.files.src, 'env')) ?? null;
|
|
46
24
|
}
|
|
47
25
|
|
|
48
26
|
/**
|
|
49
27
|
* @param {ValidatedKitConfig} kit
|
|
50
28
|
* @param {string | null} file
|
|
29
|
+
* @param {string} root
|
|
51
30
|
* @param {string} mode
|
|
52
31
|
* @returns {Promise<Record<string, EnvVarConfig<any>> | null>}
|
|
53
32
|
*/
|
|
54
|
-
export async function load_explicit_env(kit, file, mode) {
|
|
33
|
+
export async function load_explicit_env(kit, file, root, mode) {
|
|
55
34
|
if (!file) return null;
|
|
56
35
|
|
|
57
36
|
const server = await vite.createServer({
|
|
@@ -64,7 +43,7 @@ export async function load_explicit_env(kit, file, mode) {
|
|
|
64
43
|
resolve: {
|
|
65
44
|
alias: [
|
|
66
45
|
{ find: '$app/env', replacement: `${runtime_directory}/app/env` },
|
|
67
|
-
...get_config_aliases(kit)
|
|
46
|
+
...get_config_aliases(kit, root)
|
|
68
47
|
]
|
|
69
48
|
}
|
|
70
49
|
});
|
|
@@ -106,55 +85,6 @@ export async function load_explicit_env(kit, file, mode) {
|
|
|
106
85
|
return variables;
|
|
107
86
|
}
|
|
108
87
|
|
|
109
|
-
/**
|
|
110
|
-
* @param {string} id
|
|
111
|
-
* @param {Record<string, string>} env
|
|
112
|
-
* @param {boolean} disabled
|
|
113
|
-
* @returns {string}
|
|
114
|
-
*/
|
|
115
|
-
export function create_static_module(id, env, disabled) {
|
|
116
|
-
/** @type {string[]} */
|
|
117
|
-
const statements = [];
|
|
118
|
-
|
|
119
|
-
if (disabled) {
|
|
120
|
-
statements.push(
|
|
121
|
-
`throw new Error('Cannot import \`${id}\` when \`experimental.explicitEnvironmentVariables\` is enabled. Use \`${id.replace('$env/static', '$app/env')}\` instead.');`
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
for (const key in env) {
|
|
126
|
-
if (!valid_identifier.test(key) || reserved.has(key)) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const comment = `/** @type {import('${id}').${key}} */`;
|
|
131
|
-
const declaration = `export const ${key} = ${JSON.stringify(env[key])};`;
|
|
132
|
-
|
|
133
|
-
statements.push(`${comment}\n${declaration}`);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return GENERATED_COMMENT + statements.join('\n\n');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* @param {EnvType} type
|
|
141
|
-
* @param {Record<string, string> | undefined} dev_values If in a development mode, values to pre-populate the module with.
|
|
142
|
-
* @param {boolean} disabled
|
|
143
|
-
*/
|
|
144
|
-
export function create_dynamic_module(type, dev_values, disabled) {
|
|
145
|
-
const prelude = disabled
|
|
146
|
-
? `throw new Error('Cannot import \`$env/dynamic/${type}\` when \`experimental.explicitEnvironmentVariables\` is enabled. Use \`$app/env/${type}\` instead.');\n\n`
|
|
147
|
-
: '';
|
|
148
|
-
|
|
149
|
-
if (dev_values) {
|
|
150
|
-
const keys = Object.entries(dev_values).map(
|
|
151
|
-
([k, v]) => `${JSON.stringify(k)}: ${JSON.stringify(v)}`
|
|
152
|
-
);
|
|
153
|
-
return `${prelude}export const env = {\n${keys.join(',\n')}\n}`;
|
|
154
|
-
}
|
|
155
|
-
return `${prelude}export { ${type}_env as env } from '${runtime_base}/shared-server.js';`;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
88
|
/**
|
|
159
89
|
* Creates the `__sveltekit/env` module
|
|
160
90
|
* @param {Record<string, EnvVarConfig<any>> | null} variables
|
|
@@ -325,61 +255,6 @@ function create_jsdoc(description) {
|
|
|
325
255
|
.join('\n')}\n */`;
|
|
326
256
|
}
|
|
327
257
|
|
|
328
|
-
/**
|
|
329
|
-
* @param {EnvType} id
|
|
330
|
-
* @param {import('types').Env} env
|
|
331
|
-
* @returns {string}
|
|
332
|
-
*/
|
|
333
|
-
export function create_static_types(id, env) {
|
|
334
|
-
const declarations = Object.keys(env[id])
|
|
335
|
-
.filter((k) => valid_identifier.test(k))
|
|
336
|
-
.map((k) => `export const ${k}: string;`);
|
|
337
|
-
|
|
338
|
-
return dedent`
|
|
339
|
-
declare module '$env/static/${id}' {
|
|
340
|
-
${declarations.join('\n')}
|
|
341
|
-
}
|
|
342
|
-
`;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
/**
|
|
346
|
-
* @param {EnvType} id
|
|
347
|
-
* @param {import('types').Env} env
|
|
348
|
-
* @param {{
|
|
349
|
-
* public_prefix: string;
|
|
350
|
-
* private_prefix: string;
|
|
351
|
-
* }} prefixes
|
|
352
|
-
* @returns {string}
|
|
353
|
-
*/
|
|
354
|
-
export function create_dynamic_types(id, env, { public_prefix, private_prefix }) {
|
|
355
|
-
const properties = Object.keys(env[id])
|
|
356
|
-
.filter((k) => valid_identifier.test(k))
|
|
357
|
-
.map((k) => `${k}: string;`);
|
|
358
|
-
|
|
359
|
-
const public_prefixed = `[key: \`${public_prefix}\${string}\`]`;
|
|
360
|
-
const private_prefixed = `[key: \`${private_prefix}\${string}\`]`;
|
|
361
|
-
|
|
362
|
-
if (id === 'private') {
|
|
363
|
-
if (public_prefix) {
|
|
364
|
-
properties.push(`${public_prefixed}: undefined;`);
|
|
365
|
-
}
|
|
366
|
-
properties.push(`${private_prefixed}: string | undefined;`);
|
|
367
|
-
} else {
|
|
368
|
-
if (private_prefix) {
|
|
369
|
-
properties.push(`${private_prefixed}: undefined;`);
|
|
370
|
-
}
|
|
371
|
-
properties.push(`${public_prefixed}: string | undefined;`);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
return dedent`
|
|
375
|
-
declare module '$env/dynamic/${id}' {
|
|
376
|
-
export const env: {
|
|
377
|
-
${properties.join('\n')}
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
`;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
258
|
/**
|
|
384
259
|
* @param {Record<string, EnvVarConfig<any>>} variables
|
|
385
260
|
* @param {string} relative
|
|
@@ -4,8 +4,9 @@ import { find_deps } from '../../exports/vite/build/utils.js';
|
|
|
4
4
|
* Finds all the assets that are imported by server files associated with `routes`
|
|
5
5
|
* @param {import('types').BuildData} build_data
|
|
6
6
|
* @param {import('types').RouteData[]} routes
|
|
7
|
+
* @param {string} root
|
|
7
8
|
*/
|
|
8
|
-
export function find_server_assets(build_data, routes) {
|
|
9
|
+
export function find_server_assets(build_data, routes, root) {
|
|
9
10
|
/**
|
|
10
11
|
* All nodes actually used in the routes definition (prerendered routes are omitted).
|
|
11
12
|
* Root layout/error is always included as they are needed for 404 and root errors.
|
|
@@ -19,7 +20,7 @@ export function find_server_assets(build_data, routes) {
|
|
|
19
20
|
/** @param {string} id */
|
|
20
21
|
function add_assets(id) {
|
|
21
22
|
if (id in build_data.server_manifest) {
|
|
22
|
-
const deps = find_deps(build_data.server_manifest, id, false);
|
|
23
|
+
const deps = find_deps(build_data.server_manifest, id, false, root);
|
|
23
24
|
for (const asset of deps.assets) {
|
|
24
25
|
server_assets.add(asset);
|
|
25
26
|
}
|
|
@@ -20,9 +20,17 @@ import { uneval } from 'devalue';
|
|
|
20
20
|
* relative_path: string;
|
|
21
21
|
* routes: import('types').RouteData[];
|
|
22
22
|
* remotes: RemoteChunk[];
|
|
23
|
+
* root: string;
|
|
23
24
|
* }} opts
|
|
24
25
|
*/
|
|
25
|
-
export function generate_manifest({
|
|
26
|
+
export function generate_manifest({
|
|
27
|
+
build_data,
|
|
28
|
+
prerendered,
|
|
29
|
+
relative_path,
|
|
30
|
+
routes,
|
|
31
|
+
remotes,
|
|
32
|
+
root
|
|
33
|
+
}) {
|
|
26
34
|
/**
|
|
27
35
|
* @type {Map<any, number>} The new index of each node in the filtered nodes array
|
|
28
36
|
*/
|
|
@@ -34,7 +42,7 @@ export function generate_manifest({ build_data, prerendered, relative_path, rout
|
|
|
34
42
|
*/
|
|
35
43
|
const used_nodes = new Set([0, 1]);
|
|
36
44
|
|
|
37
|
-
const server_assets = find_server_assets(build_data, routes);
|
|
45
|
+
const server_assets = find_server_assets(build_data, routes, root);
|
|
38
46
|
|
|
39
47
|
for (const route of routes) {
|
|
40
48
|
if (route.page) {
|
|
@@ -119,7 +127,7 @@ export function generate_manifest({ build_data, prerendered, relative_path, rout
|
|
|
119
127
|
pattern: ${route.pattern},
|
|
120
128
|
params: ${s(route.params)},
|
|
121
129
|
page: ${route.page ? `{ layouts: ${get_nodes(route.page.layouts)}, errors: ${get_nodes(route.page.errors)}, leaf: ${reindexed.get(route.page.leaf)} }` : 'null'},
|
|
122
|
-
endpoint: ${route.endpoint ? loader(join_relative(relative_path, resolve_symlinks(build_data.server_manifest, route.endpoint.file).chunk.file)) : 'null'}
|
|
130
|
+
endpoint: ${route.endpoint ? loader(join_relative(relative_path, resolve_symlinks(build_data.server_manifest, route.endpoint.file, root).chunk.file)) : 'null'}
|
|
123
131
|
}
|
|
124
132
|
`;
|
|
125
133
|
}).filter(Boolean).join(',\n')}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
+
/** @import { Adapter } from '@sveltejs/kit' */
|
|
1
2
|
/** @import { RemoteChunk } from 'types' */
|
|
2
3
|
import { join } from 'node:path';
|
|
3
4
|
import { pathToFileURL } from 'node:url';
|
|
4
5
|
import { validate_server_exports } from '../../utils/exports.js';
|
|
5
|
-
import {
|
|
6
|
+
import { extract_svelte_config, load_vite_config } from '../config/index.js';
|
|
6
7
|
import { forked } from '../../utils/fork.js';
|
|
7
|
-
import { installPolyfills } from '../../exports/node/polyfills.js';
|
|
8
8
|
import { ENDPOINT_METHODS } from '../../constants.js';
|
|
9
|
-
import { filter_env } from '../../utils/env.js';
|
|
10
9
|
import { has_server_load, resolve_route } from '../../utils/routing.js';
|
|
11
10
|
import { check_feature } from '../../utils/features.js';
|
|
12
11
|
import { createReadableStream } from '@sveltejs/kit/node';
|
|
@@ -25,6 +24,8 @@ export default forked(import.meta.url, analyse);
|
|
|
25
24
|
* env: Record<string, string>;
|
|
26
25
|
* out: string;
|
|
27
26
|
* remotes: RemoteChunk[];
|
|
27
|
+
* root: string;
|
|
28
|
+
* vite_config_file: string | undefined;
|
|
28
29
|
* }} opts
|
|
29
30
|
*/
|
|
30
31
|
async function analyse({
|
|
@@ -35,37 +36,39 @@ async function analyse({
|
|
|
35
36
|
tracked_features,
|
|
36
37
|
env,
|
|
37
38
|
out,
|
|
38
|
-
remotes
|
|
39
|
+
remotes,
|
|
40
|
+
root,
|
|
41
|
+
vite_config_file
|
|
39
42
|
}) {
|
|
40
43
|
/** @type {import('@sveltejs/kit').SSRManifest} */
|
|
41
44
|
const manifest = (await import(pathToFileURL(manifest_path).href)).manifest;
|
|
42
45
|
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
const vite_config = await load_vite_config(vite_config_file);
|
|
47
|
+
|
|
48
|
+
const config = extract_svelte_config(vite_config).kit;
|
|
49
|
+
|
|
50
|
+
// TODO i think this can just be config.adapter?
|
|
51
|
+
/** @type {Adapter | undefined} */
|
|
52
|
+
const adapter = vite_config.plugins.find(
|
|
53
|
+
(plugin) => plugin.name === 'vite-plugin-sveltekit-adapter'
|
|
54
|
+
)?.api?.adapter;
|
|
45
55
|
|
|
46
56
|
const server_root = join(config.outDir, 'output');
|
|
47
57
|
|
|
48
58
|
/** @type {import('types').ServerInternalModule} */
|
|
49
59
|
const internal = await import(pathToFileURL(`${server_root}/server/internal.js`).href);
|
|
50
60
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
// configure `import { building } from '$app/environment'` and `$app/env` —
|
|
61
|
+
// configure `import { building } from '$app/env'` —
|
|
54
62
|
// essential we do this before analysing the code
|
|
55
63
|
internal.set_building();
|
|
56
64
|
|
|
57
65
|
// set env, `read`, and `manifest`, in case they're used in initialisation
|
|
58
|
-
const { publicPrefix: public_prefix, privatePrefix: private_prefix } = config.env;
|
|
59
|
-
const private_env = filter_env(env, private_prefix, public_prefix);
|
|
60
|
-
const public_env = filter_env(env, public_prefix, private_prefix);
|
|
61
|
-
internal.set_private_env(private_env);
|
|
62
|
-
internal.set_public_env(public_env);
|
|
63
66
|
internal.set_env(env);
|
|
64
67
|
internal.set_manifest(manifest);
|
|
65
68
|
internal.set_read_implementation((file) => createReadableStream(`${server_root}/server/${file}`));
|
|
66
69
|
|
|
67
70
|
// first, build server nodes without the client manifest so we can analyse it
|
|
68
|
-
build_server_nodes(out, config, manifest_data, server_manifest, null, null, null);
|
|
71
|
+
build_server_nodes(out, config, manifest_data, server_manifest, null, null, null, root);
|
|
69
72
|
|
|
70
73
|
/** @type {import('types').ServerMetadata} */
|
|
71
74
|
const metadata = {
|
|
@@ -131,7 +134,7 @@ async function analyse({
|
|
|
131
134
|
server_manifest,
|
|
132
135
|
tracked_features
|
|
133
136
|
)) {
|
|
134
|
-
check_feature(route.id, route_config, feature,
|
|
137
|
+
check_feature(route.id, route_config, feature, adapter);
|
|
135
138
|
}
|
|
136
139
|
}
|
|
137
140
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
|
-
import { installPolyfills } from '../../exports/node/polyfills.js';
|
|
5
4
|
import { forked } from '../../utils/fork.js';
|
|
6
5
|
|
|
7
6
|
export default forked(import.meta.url, generate_fallback);
|
|
@@ -16,8 +15,6 @@ export default forked(import.meta.url, generate_fallback);
|
|
|
16
15
|
* }} opts
|
|
17
16
|
*/
|
|
18
17
|
async function generate_fallback({ manifest_path, env, out_dir, origin, assets }) {
|
|
19
|
-
installPolyfills();
|
|
20
|
-
|
|
21
18
|
const server_root = join(out_dir, 'output');
|
|
22
19
|
|
|
23
20
|
/** @type {import('types').ServerInternalModule} */
|
|
@@ -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,6 @@ 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
|
-
const { publicPrefix: public_prefix, privatePrefix: private_prefix } = config.env;
|
|
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);
|
|
500
501
|
internal.set_env(env);
|
|
501
502
|
internal.set_manifest(manifest);
|
|
502
503
|
internal.set_read_implementation((file) => createReadableStream(`${out}/server/${file}`));
|
|
@@ -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';
|
|
@@ -17,26 +18,27 @@ import { write_env } from './write_env.js';
|
|
|
17
18
|
/**
|
|
18
19
|
* Initialize SvelteKit's generated files that only depend on the config and mode.
|
|
19
20
|
* @param {import('types').ValidatedConfig} config
|
|
20
|
-
* @param {string}
|
|
21
|
+
* @param {string} root The project root directory
|
|
21
22
|
*/
|
|
22
|
-
export function init(config,
|
|
23
|
-
write_tsconfig(config.kit);
|
|
24
|
-
write_ambient(config.kit
|
|
23
|
+
export function init(config, root) {
|
|
24
|
+
write_tsconfig(config.kit, root);
|
|
25
|
+
write_ambient(config.kit);
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Update SvelteKit's generated files
|
|
29
30
|
* @param {import('types').ValidatedConfig} config
|
|
31
|
+
* @param {string} root The project root directory
|
|
30
32
|
*/
|
|
31
|
-
export function create(config) {
|
|
32
|
-
const manifest_data = create_manifest_data({ config });
|
|
33
|
+
export function create(config, root) {
|
|
34
|
+
const manifest_data = create_manifest_data({ config, cwd: root });
|
|
33
35
|
|
|
34
36
|
const output = path.join(config.kit.outDir, 'generated');
|
|
35
37
|
|
|
36
38
|
write_client_manifest(config.kit, manifest_data, `${output}/client`);
|
|
37
|
-
write_server(config, output);
|
|
39
|
+
write_server(config, output, root);
|
|
38
40
|
write_root(manifest_data, config, output);
|
|
39
|
-
write_all_types(config, manifest_data);
|
|
41
|
+
write_all_types(config, manifest_data, root);
|
|
40
42
|
write_non_ambient(config.kit, manifest_data);
|
|
41
43
|
|
|
42
44
|
return { manifest_data };
|
|
@@ -49,9 +51,10 @@ export function create(config) {
|
|
|
49
51
|
* @param {import('types').ValidatedConfig} config
|
|
50
52
|
* @param {import('types').ManifestData} manifest_data
|
|
51
53
|
* @param {string} file
|
|
54
|
+
* @param {string} root The project root directory
|
|
52
55
|
*/
|
|
53
|
-
export function update(config, manifest_data, file) {
|
|
54
|
-
const node_analyser = create_node_analyser();
|
|
56
|
+
export function update(config, manifest_data, file, root) {
|
|
57
|
+
const node_analyser = create_node_analyser(root);
|
|
55
58
|
|
|
56
59
|
for (const node of manifest_data.nodes) {
|
|
57
60
|
node.page_options = node_analyser.get_page_options(node);
|
|
@@ -59,33 +62,33 @@ export function update(config, manifest_data, file) {
|
|
|
59
62
|
|
|
60
63
|
for (const route of manifest_data.routes) {
|
|
61
64
|
if (route.endpoint) {
|
|
62
|
-
route.endpoint.page_options = get_page_options(route.endpoint.file);
|
|
65
|
+
route.endpoint.page_options = get_page_options(route.endpoint.file, root);
|
|
63
66
|
}
|
|
64
67
|
}
|
|
65
68
|
|
|
66
|
-
write_types(config, manifest_data, file);
|
|
69
|
+
write_types(config, manifest_data, file, root);
|
|
67
70
|
write_non_ambient(config.kit, manifest_data);
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
74
|
* Run sync.init and sync.create in series, returning the result from sync.create.
|
|
72
75
|
* @param {import('types').ValidatedConfig} config
|
|
73
|
-
* @param {string}
|
|
76
|
+
* @param {string} root The project root directory
|
|
74
77
|
*/
|
|
75
|
-
export function all(config,
|
|
76
|
-
init(config,
|
|
77
|
-
return create(config);
|
|
78
|
+
export function all(config, root) {
|
|
79
|
+
init(config, root);
|
|
80
|
+
return create(config, root);
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
/**
|
|
81
84
|
* Run sync.init and then generate all type files.
|
|
82
85
|
* @param {import('types').ValidatedConfig} config
|
|
83
|
-
* @param {string} mode The Vite mode
|
|
84
86
|
*/
|
|
85
|
-
export function all_types(config
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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);
|
|
89
92
|
write_non_ambient(config.kit, manifest_data);
|
|
90
93
|
}
|
|
91
94
|
|
|
@@ -93,10 +96,11 @@ export function all_types(config, mode) {
|
|
|
93
96
|
* Generate modules and types for explicit env vars
|
|
94
97
|
* @param {import('types').ValidatedKitConfig} kit
|
|
95
98
|
* @param {string | null} entry
|
|
99
|
+
* @param {string} root The Vite root
|
|
96
100
|
* @param {string} mode The Vite mode
|
|
97
101
|
*/
|
|
98
|
-
export async function env(kit, entry, mode) {
|
|
99
|
-
const env_config = await load_explicit_env(kit, entry, mode);
|
|
102
|
+
export async function env(kit, entry, root, mode) {
|
|
103
|
+
const env_config = await load_explicit_env(kit, entry, root, mode);
|
|
100
104
|
|
|
101
105
|
write_env(kit, entry, env_config);
|
|
102
106
|
|
|
@@ -106,7 +110,8 @@ export async function env(kit, entry, mode) {
|
|
|
106
110
|
/**
|
|
107
111
|
* Regenerate __SERVER__/internal.js in response to src/{app.html,error.html,service-worker.js} changing
|
|
108
112
|
* @param {import('types').ValidatedConfig} config
|
|
113
|
+
* @param {string} root The project root directory
|
|
109
114
|
*/
|
|
110
|
-
export function server(config) {
|
|
111
|
-
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);
|
|
112
117
|
}
|