@sveltejs/kit 3.0.0-next.23 → 3.0.0-next.25
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 +51 -8
- package/src/cli.js +3 -3
- package/src/constants.js +19 -1
- package/src/core/adapt/builder.js +3 -5
- package/src/core/env.js +137 -182
- package/src/core/postbuild/analyse.js +9 -4
- package/src/core/postbuild/prerender.js +5 -6
- package/src/core/sync/create_manifest_data/index.js +29 -33
- package/src/core/sync/sync.js +23 -40
- package/src/core/sync/write_app_manifest.js +83 -0
- package/src/core/sync/write_client_manifest.js +6 -4
- package/src/core/sync/write_server.js +12 -22
- package/src/core/sync/write_types/index.js +2 -2
- package/src/core/utils.js +10 -28
- package/src/exports/adapter.js +22 -0
- package/src/exports/hooks/public.d.ts +9 -1
- package/src/exports/node/index.js +77 -5
- package/src/exports/public.d.ts +1 -1
- package/src/exports/vite/build/build_server.js +3 -3
- package/src/exports/vite/build/service-worker.js +98 -0
- package/src/exports/vite/build/utils.js +48 -4
- package/src/exports/vite/dev/index.js +28 -25
- package/src/exports/vite/index.js +94 -747
- package/src/exports/vite/module_ids.js +1 -11
- package/src/exports/vite/plugins/env-vars.js +159 -0
- package/src/exports/vite/plugins/guard.js +205 -0
- package/src/exports/vite/preview/index.js +6 -4
- package/src/exports/vite/utils.js +99 -4
- package/src/runtime/app/env/{types.d.ts → client.js} +9 -4
- package/src/runtime/app/env/index.js +1 -2
- package/src/runtime/app/env/private/index.js +1 -0
- package/src/runtime/app/env/public/client.js +1 -1
- package/src/runtime/app/env/public/server.js +1 -1
- package/src/runtime/app/env/{internal.js → server.js} +4 -4
- package/src/runtime/app/forms/client.js +263 -0
- package/src/runtime/app/forms/index.js +1 -263
- package/src/runtime/app/forms/public.d.ts +1 -1
- package/src/runtime/app/forms/server.js +6 -0
- package/src/runtime/app/forms/shared.js +34 -0
- package/src/runtime/app/manifest/index.js +1 -1
- package/src/runtime/app/navigation/client.js +15 -0
- package/src/runtime/app/navigation/index.js +1 -15
- package/src/runtime/app/navigation/public.d.ts +1 -1
- package/src/runtime/app/navigation/server.js +15 -0
- package/src/runtime/app/paths/server.js +1 -1
- package/src/runtime/app/server/remote/form.js +11 -1
- package/src/runtime/app/server/remote/prerender.js +1 -2
- package/src/runtime/app/server/remote/query.js +3 -3
- package/src/runtime/app/state/client.svelte.js +207 -0
- package/src/runtime/app/state/index.js +1 -66
- package/src/runtime/app/state/public.d.ts +1 -1
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client.js +210 -278
- package/src/runtime/client/fetcher.js +18 -8
- package/src/runtime/client/remote-functions/form.svelte.js +9 -6
- package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
- package/src/runtime/client/remote-functions/query-live/iterator.js +1 -1
- package/src/runtime/client/remote-functions/shared.svelte.js +2 -2
- package/src/runtime/client/snapshots.js +1 -3
- package/src/runtime/client/stream.js +27 -20
- package/src/runtime/client/utils.js +7 -3
- package/src/runtime/components/root.svelte +5 -5
- package/src/runtime/env/dynamic/private.js +1 -1
- package/src/runtime/env/static/private.js +1 -1
- package/src/runtime/error-chain.js +54 -0
- package/src/runtime/form-utils.js +55 -87
- package/src/runtime/invalid-import.js +1 -0
- package/src/runtime/props.svelte.js +1 -1
- package/src/runtime/server/data/index.js +12 -27
- package/src/runtime/server/endpoint.js +8 -3
- package/src/runtime/server/env_module.js +1 -1
- package/src/runtime/server/errors.js +9 -12
- package/src/runtime/server/fetch.js +14 -16
- package/src/runtime/server/index.js +30 -27
- package/src/runtime/server/internal.js +34 -4
- package/src/runtime/server/page/actions.js +77 -124
- package/src/runtime/server/page/data_serializer.js +6 -10
- package/src/runtime/server/page/index.js +45 -82
- package/src/runtime/server/page/render.js +34 -52
- package/src/runtime/server/page/respond_with_error.js +7 -9
- package/src/runtime/server/remote-functions.js +138 -166
- package/src/runtime/server/respond.js +75 -30
- package/src/runtime/server/state.js +1 -0
- package/src/runtime/server/utils.js +0 -7
- package/src/runtime/utils.js +41 -0
- package/src/telemetry.js +1 -33
- package/src/types/ambient-private.d.ts +9 -17
- package/src/types/global-private.d.ts +8 -0
- package/src/types/internal.d.ts +27 -15
- package/src/types/private.d.ts +1 -1
- package/src/utils/exports.js +1 -0
- package/src/utils/filesystem.js +10 -22
- package/src/utils/functions.js +10 -0
- package/src/utils/routing.js +0 -11
- package/src/utils/streaming.js +5 -15
- package/src/utils/url.js +0 -11
- package/src/version.js +1 -1
- package/types/index.d.ts +54 -29
- package/types/index.d.ts.map +10 -5
- package/src/runtime/app/env/private.js +0 -1
- package/src/runtime/app/env/standard-schema.d.ts +0 -0
- package/src/runtime/app/state/client.js +0 -63
- package/src/runtime/client/state.svelte.js +0 -98
- package/src/runtime/server/ambient.d.ts +0 -4
- package/src/utils/path.js +0 -23
|
@@ -2,52 +2,35 @@
|
|
|
2
2
|
/** @import { EnvVarConfig } from '@sveltejs/kit/env' */
|
|
3
3
|
/** @import { Options } from '@sveltejs/vite-plugin-svelte' */
|
|
4
4
|
/** @import { PreprocessorGroup } from 'svelte/compiler' */
|
|
5
|
-
/** @import {
|
|
5
|
+
/** @import { BuildData, ManifestData, Prerendered, RemoteChunk, RemoteInternals, ServerMetadata, ValidatedConfig } from 'types' */
|
|
6
6
|
/** @import { Manifest, Plugin, ResolvedConfig, Rolldown, UserConfig, ViteDevServer } from 'vite' */
|
|
7
7
|
import fs from 'node:fs';
|
|
8
8
|
import path from 'node:path';
|
|
9
9
|
import process from 'node:process';
|
|
10
10
|
import { styleText } from 'node:util';
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
and,
|
|
14
|
-
code,
|
|
15
|
-
exactRegex,
|
|
16
|
-
importerId,
|
|
17
|
-
include,
|
|
18
|
-
not,
|
|
19
|
-
prefixRegex
|
|
20
|
-
} from '@rolldown/pluginutils';
|
|
12
|
+
import { code, include, prefixRegex } from '@rolldown/pluginutils';
|
|
21
13
|
import MagicString from 'magic-string';
|
|
22
14
|
|
|
23
15
|
import { copy, read, resolve_entry } from '../../utils/filesystem.js';
|
|
24
16
|
import { posixify } from '../../utils/os.js';
|
|
25
17
|
import { to_fs } from '../../utils/vite.js';
|
|
26
|
-
import {
|
|
27
|
-
create_sveltekit_env,
|
|
28
|
-
create_sveltekit_env_public,
|
|
29
|
-
resolve_explicit_env_entry,
|
|
30
|
-
create_sveltekit_env_service_worker,
|
|
31
|
-
create_sveltekit_env_service_worker_dev,
|
|
32
|
-
create_sveltekit_env_private,
|
|
33
|
-
create_exported_declarations
|
|
34
|
-
} from '../../core/env.js';
|
|
18
|
+
import { create_exported_declarations } from '../../core/env.js';
|
|
35
19
|
import * as sync from '../../core/sync/sync.js';
|
|
36
20
|
import { load_and_validate_params } from '../../utils/params.js';
|
|
37
|
-
import { runtime_directory, logger } from '../../core/utils.js';
|
|
21
|
+
import { runtime_directory, logger, get_global_name } from '../../core/utils.js';
|
|
38
22
|
import { generate_manifest } from '../../core/generate_manifest/index.js';
|
|
39
23
|
import { build_server_nodes } from './build/build_server.js';
|
|
40
24
|
import { find_deps, resolve_symlinks } from './build/utils.js';
|
|
41
|
-
import { dev
|
|
25
|
+
import { dev } from './dev/index.js';
|
|
42
26
|
import { preview } from './preview/index.js';
|
|
43
27
|
import {
|
|
28
|
+
enforced_config,
|
|
44
29
|
error_for_missing_config,
|
|
45
30
|
get_config_aliases,
|
|
46
31
|
is_remote_module,
|
|
47
|
-
normalize_id,
|
|
48
32
|
remote_module_pattern,
|
|
49
|
-
|
|
50
|
-
server_only_module_pattern
|
|
33
|
+
warn_overridden_config
|
|
51
34
|
} from './utils.js';
|
|
52
35
|
import { stackless } from '../../utils/error.js';
|
|
53
36
|
import { adapt } from '../../core/adapt/index.js';
|
|
@@ -57,63 +40,18 @@ import analyse from '../../core/postbuild/analyse.js';
|
|
|
57
40
|
import { s } from '../../utils/misc.js';
|
|
58
41
|
import { hash } from '../../utils/hash.js';
|
|
59
42
|
import { dedent } from '../../core/sync/utils.js';
|
|
60
|
-
import
|
|
61
|
-
is_app_route,
|
|
62
|
-
is_endpoint_route,
|
|
63
|
-
is_page_route
|
|
64
|
-
} from '../../core/sync/create_manifest_data/index.js';
|
|
43
|
+
import create_manifest_data from '../../core/sync/create_manifest_data/index.js';
|
|
65
44
|
import { get_import_aliases, get_hash_import_keys } from '../../utils/imports.js';
|
|
66
|
-
import {
|
|
67
|
-
app_env_private,
|
|
68
|
-
app_server,
|
|
69
|
-
sveltekit_env,
|
|
70
|
-
sveltekit_env_private,
|
|
71
|
-
sveltekit_env_service_worker,
|
|
72
|
-
sveltekit_manifest_data,
|
|
73
|
-
sveltekit_env_public_client,
|
|
74
|
-
sveltekit_env_public_server
|
|
75
|
-
} from './module_ids.js';
|
|
76
45
|
import { import_peer } from '../../utils/import.js';
|
|
77
46
|
import { compact } from '../../utils/array.js';
|
|
78
47
|
import { should_ignore, has_children } from './static_analysis/utils.js';
|
|
79
48
|
import { process_config, split_config, validate_config } from '../../core/config/index.js';
|
|
80
49
|
import { treeshake_prerendered_remotes } from './build/remote.js';
|
|
81
50
|
import { get_runner } from '../../runner.js';
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
base: true,
|
|
87
|
-
build: {
|
|
88
|
-
cssCodeSplit: true,
|
|
89
|
-
emptyOutDir: true,
|
|
90
|
-
lib: {
|
|
91
|
-
entry: true,
|
|
92
|
-
name: true,
|
|
93
|
-
formats: true
|
|
94
|
-
},
|
|
95
|
-
manifest: true,
|
|
96
|
-
outDir: true,
|
|
97
|
-
rolldownOptions: {
|
|
98
|
-
input: true,
|
|
99
|
-
output: {
|
|
100
|
-
format: true,
|
|
101
|
-
entryFileNames: true,
|
|
102
|
-
chunkFileNames: true,
|
|
103
|
-
assetFileNames: true
|
|
104
|
-
},
|
|
105
|
-
preserveEntrySignatures: true
|
|
106
|
-
},
|
|
107
|
-
ssr: true
|
|
108
|
-
},
|
|
109
|
-
publicDir: true,
|
|
110
|
-
resolve: {
|
|
111
|
-
alias: {
|
|
112
|
-
$app: true,
|
|
113
|
-
$env: true
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
};
|
|
51
|
+
import { plugin_env_vars, plugin_service_worker_env_vars } from './plugins/env-vars.js';
|
|
52
|
+
import { plugin_guard } from './plugins/guard.js';
|
|
53
|
+
import { get_manifest_routes, write_app_manifest } from '../../core/sync/write_app_manifest.js';
|
|
54
|
+
import { plugin_service_worker_build } from './build/service-worker.js';
|
|
117
55
|
|
|
118
56
|
const options_regex = /(export\s+const\s+(prerender|csr|ssr|trailingSlash))\s*=/s;
|
|
119
57
|
|
|
@@ -294,9 +232,6 @@ function kit({ svelte_config }) {
|
|
|
294
232
|
/** @type {string} The base directory for the Vite builds */
|
|
295
233
|
let out;
|
|
296
234
|
|
|
297
|
-
/** @type {string} */
|
|
298
|
-
let version_hash;
|
|
299
|
-
|
|
300
235
|
/** @type {ResolvedConfig} */
|
|
301
236
|
let vite_config;
|
|
302
237
|
|
|
@@ -317,16 +252,8 @@ function kit({ svelte_config }) {
|
|
|
317
252
|
|
|
318
253
|
/** @type {string | null} */
|
|
319
254
|
let service_worker_entry_file;
|
|
320
|
-
/** @type {string} */
|
|
321
|
-
let normalized_cwd;
|
|
322
255
|
/** @type {Array<{ alias: string, path: string }>} */
|
|
323
256
|
let normalized_aliases;
|
|
324
|
-
/** @type {string} */
|
|
325
|
-
let normalized_node_modules;
|
|
326
|
-
/** @type {string} */
|
|
327
|
-
let normalized_routes;
|
|
328
|
-
/** @type {string} */
|
|
329
|
-
let normalized_assets;
|
|
330
257
|
/**
|
|
331
258
|
* A map showing which features (such as `$app/server:read`) are defined
|
|
332
259
|
* in which chunks, so that we can later determine which routes use which features
|
|
@@ -337,6 +264,9 @@ function kit({ svelte_config }) {
|
|
|
337
264
|
const sourcemapIgnoreList = /** @param {string} relative_path */ (relative_path) =>
|
|
338
265
|
relative_path.includes('node_modules') || relative_path.includes(kit.outDir);
|
|
339
266
|
|
|
267
|
+
/** @type {string} the `__sveltekit_xxx` name, without `globalThis.` */
|
|
268
|
+
let global_name;
|
|
269
|
+
|
|
340
270
|
/** @type {string} name for `globalThis.__sveltekit_xxx` */
|
|
341
271
|
let kit_global;
|
|
342
272
|
|
|
@@ -402,21 +332,17 @@ function kit({ svelte_config }) {
|
|
|
402
332
|
out_dir = posixify(kit.outDir);
|
|
403
333
|
out = `${out_dir}/output`;
|
|
404
334
|
|
|
405
|
-
|
|
335
|
+
global_name = get_global_name(kit.version.name, !is_build);
|
|
336
|
+
kit_global = `globalThis.${global_name}`;
|
|
406
337
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
: 'globalThis.__sveltekit_dev';
|
|
338
|
+
service_worker_entry_file = resolve_entry(kit.files.serviceWorker);
|
|
339
|
+
service_worker_entry_file &&= posixify(service_worker_entry_file);
|
|
410
340
|
|
|
411
341
|
vite = await import_peer('vite', root);
|
|
412
342
|
|
|
413
343
|
env = vite.loadEnv(config_env.mode, kit.env.dir, '');
|
|
414
344
|
|
|
415
|
-
normalized_cwd = vite.normalizePath(root);
|
|
416
345
|
normalized_aliases = get_import_aliases(root, vite.normalizePath.bind(vite));
|
|
417
|
-
normalized_node_modules = vite.normalizePath(path.resolve(root, 'node_modules'));
|
|
418
|
-
normalized_routes = vite.normalizePath(path.resolve(root, kit.files.routes));
|
|
419
|
-
normalized_assets = vite.normalizePath(path.resolve(root, kit.files.assets));
|
|
420
346
|
|
|
421
347
|
// Add `#`-prefixed import keys to the enforced config so users are warned
|
|
422
348
|
// if they try to set them in their Vite config's resolve.alias
|
|
@@ -453,8 +379,6 @@ function kit({ svelte_config }) {
|
|
|
453
379
|
const client_hooks = resolve_entry(kit.files.hooks.client);
|
|
454
380
|
if (client_hooks) allow.add(path.dirname(client_hooks));
|
|
455
381
|
|
|
456
|
-
const generated = path.posix.join(out_dir, 'generated');
|
|
457
|
-
|
|
458
382
|
// dev and preview config can be shared
|
|
459
383
|
/** @type {UserConfig} */
|
|
460
384
|
const new_config = {
|
|
@@ -468,12 +392,11 @@ function kit({ svelte_config }) {
|
|
|
468
392
|
},
|
|
469
393
|
resolve: {
|
|
470
394
|
alias: [
|
|
471
|
-
{ find: '__SERVER__', replacement: `${generated}/server` },
|
|
472
395
|
{ find: '$app', replacement: `${runtime_directory}/app` },
|
|
473
396
|
{ find: '$env', replacement: `${runtime_directory}/env` },
|
|
474
397
|
{
|
|
475
|
-
find: '
|
|
476
|
-
replacement: `${
|
|
398
|
+
find: '<sveltekit:generated>',
|
|
399
|
+
replacement: `${out_dir}/generated/${is_build ? 'build' : 'dev'}`
|
|
477
400
|
},
|
|
478
401
|
...get_config_aliases(kit, root)
|
|
479
402
|
]
|
|
@@ -520,7 +443,7 @@ function kit({ svelte_config }) {
|
|
|
520
443
|
// because they for example use rolldown.build with `platform: 'browser'`
|
|
521
444
|
'esm-env',
|
|
522
445
|
// This forces `$app/*` modules to be bundled, since they depend on
|
|
523
|
-
//
|
|
446
|
+
// generated modules like `<sveltekit:generated>/env/config.js` (this isn't a valid bare
|
|
524
447
|
// import, but it works with vite-node's externalization logic, which
|
|
525
448
|
// uses basic concatenation)
|
|
526
449
|
'@sveltejs/kit/src/runtime'
|
|
@@ -567,7 +490,12 @@ function kit({ svelte_config }) {
|
|
|
567
490
|
__SVELTEKIT_SUPPORTS_ASYNC__: s(
|
|
568
491
|
svelte_config.compilerOptions?.experimental?.async ?? false
|
|
569
492
|
),
|
|
570
|
-
__SVELTEKIT_DEV__: s(!is_build)
|
|
493
|
+
__SVELTEKIT_DEV__: s(!is_build),
|
|
494
|
+
__SVELTEKIT_GLOBAL_NAME__: s(global_name),
|
|
495
|
+
__SVELTEKIT_CSRF_CHECK_ORIGIN__: s(!kit.csrf.trustedOrigins.includes('*')),
|
|
496
|
+
__SVELTEKIT_LINK_HEADER_PRELOAD__: s(kit.output.linkHeaderPreload),
|
|
497
|
+
__SVELTEKIT_PATHS_ORIGIN__: s(kit.paths.origin) ?? 'undefined',
|
|
498
|
+
__SVELTEKIT_SERVICE_WORKER__: s(kit.serviceWorker.register && !!service_worker_entry_file)
|
|
571
499
|
};
|
|
572
500
|
|
|
573
501
|
if (is_build) {
|
|
@@ -578,7 +506,8 @@ function kit({ svelte_config }) {
|
|
|
578
506
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: s(kit.version.pollInterval)
|
|
579
507
|
};
|
|
580
508
|
|
|
581
|
-
manifest_data =
|
|
509
|
+
manifest_data = create_manifest_data(svelte_config, root);
|
|
510
|
+
sync.all(svelte_config, root, manifest_data);
|
|
582
511
|
} else {
|
|
583
512
|
new_config.define = {
|
|
584
513
|
...define,
|
|
@@ -633,6 +562,11 @@ function kit({ svelte_config }) {
|
|
|
633
562
|
configResolved(config) {
|
|
634
563
|
vite_config = config;
|
|
635
564
|
|
|
565
|
+
if (!is_build) {
|
|
566
|
+
// Dependency scanning starts before configureServer creates the full manifest
|
|
567
|
+
write_app_manifest(`${out_dir}/generated/dev`, undefined, false);
|
|
568
|
+
}
|
|
569
|
+
|
|
636
570
|
const unsupported_plugins = vite_config.plugins.filter((plugin) => plugin.transformIndexHtml);
|
|
637
571
|
if (unsupported_plugins.length) {
|
|
638
572
|
const verbose = vite_config.logLevel === 'info' || vite_config.logLevel === undefined;
|
|
@@ -653,284 +587,9 @@ function kit({ svelte_config }) {
|
|
|
653
587
|
}
|
|
654
588
|
};
|
|
655
589
|
|
|
656
|
-
/** @type {string | null} */
|
|
657
|
-
let explicit_env_entry = null;
|
|
658
|
-
|
|
659
590
|
/** @type {Record<string, EnvVarConfig<any>> | null} */
|
|
660
591
|
let explicit_env_config = null;
|
|
661
592
|
|
|
662
|
-
/** @type {Plugin} */
|
|
663
|
-
const plugin_virtual_modules = {
|
|
664
|
-
name: 'vite-plugin-sveltekit-virtual-modules',
|
|
665
|
-
|
|
666
|
-
async configResolved(config) {
|
|
667
|
-
explicit_env_entry = resolve_explicit_env_entry(kit);
|
|
668
|
-
explicit_env_config = await sync.env(vite, kit, explicit_env_entry, config.root, config.mode);
|
|
669
|
-
},
|
|
670
|
-
|
|
671
|
-
configureServer(server) {
|
|
672
|
-
server.watcher.on('all', async (_, file) => {
|
|
673
|
-
if (!file.includes('env')) {
|
|
674
|
-
return;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
const resolved = resolve_explicit_env_entry(kit);
|
|
678
|
-
|
|
679
|
-
if (file === explicit_env_entry || file === resolved) {
|
|
680
|
-
explicit_env_entry = resolved;
|
|
681
|
-
explicit_env_config = await sync.env(
|
|
682
|
-
vite,
|
|
683
|
-
kit,
|
|
684
|
-
explicit_env_entry,
|
|
685
|
-
vite_config.root,
|
|
686
|
-
vite_config.mode
|
|
687
|
-
);
|
|
688
|
-
|
|
689
|
-
for (const id of [sveltekit_env, sveltekit_env_public_client]) {
|
|
690
|
-
invalidate_module(server, id);
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
server.hot.send({ type: 'full-reload' });
|
|
694
|
-
}
|
|
695
|
-
});
|
|
696
|
-
},
|
|
697
|
-
|
|
698
|
-
applyToEnvironment(environment) {
|
|
699
|
-
return environment.name !== 'serviceWorker';
|
|
700
|
-
},
|
|
701
|
-
|
|
702
|
-
resolveId: {
|
|
703
|
-
filter: {
|
|
704
|
-
id: prefixRegex('__sveltekit/')
|
|
705
|
-
},
|
|
706
|
-
handler(id) {
|
|
707
|
-
if (id === '__sveltekit/manifest') {
|
|
708
|
-
return `${out_dir}/generated/client-optimized/app.js`;
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
if (id === '__sveltekit/remote') {
|
|
712
|
-
return `${runtime_directory}/client/remote-functions/index.js`;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
return `\0virtual:${id}`;
|
|
716
|
-
}
|
|
717
|
-
},
|
|
718
|
-
|
|
719
|
-
load: {
|
|
720
|
-
filter: {
|
|
721
|
-
id: [
|
|
722
|
-
exactRegex(sveltekit_env),
|
|
723
|
-
exactRegex(sveltekit_env_private),
|
|
724
|
-
exactRegex(sveltekit_env_public_client),
|
|
725
|
-
exactRegex(sveltekit_env_public_server),
|
|
726
|
-
exactRegex(sveltekit_env_service_worker),
|
|
727
|
-
exactRegex(sveltekit_manifest_data)
|
|
728
|
-
]
|
|
729
|
-
},
|
|
730
|
-
handler(id) {
|
|
731
|
-
switch (id) {
|
|
732
|
-
case sveltekit_manifest_data:
|
|
733
|
-
return create_manifest_data_module(is_build, manifest_data);
|
|
734
|
-
|
|
735
|
-
case sveltekit_env:
|
|
736
|
-
return create_sveltekit_env(explicit_env_config, env, explicit_env_entry, !is_build);
|
|
737
|
-
|
|
738
|
-
case sveltekit_env_public_client:
|
|
739
|
-
return create_sveltekit_env_public(
|
|
740
|
-
explicit_env_config,
|
|
741
|
-
env,
|
|
742
|
-
`import { payload } from ${s(`${runtime_directory}/client/payload.js`)};\nconst env = payload.env;`
|
|
743
|
-
);
|
|
744
|
-
|
|
745
|
-
case sveltekit_env_public_server:
|
|
746
|
-
return create_sveltekit_env_public(
|
|
747
|
-
explicit_env_config,
|
|
748
|
-
env,
|
|
749
|
-
`import { rendered_env as env } from '__sveltekit/env';`
|
|
750
|
-
);
|
|
751
|
-
|
|
752
|
-
case sveltekit_env_private:
|
|
753
|
-
return create_sveltekit_env_private(explicit_env_config, env);
|
|
754
|
-
|
|
755
|
-
case sveltekit_env_service_worker:
|
|
756
|
-
return is_build
|
|
757
|
-
? create_sveltekit_env_service_worker(
|
|
758
|
-
explicit_env_config,
|
|
759
|
-
env,
|
|
760
|
-
kit.version.name,
|
|
761
|
-
kit_global,
|
|
762
|
-
kit.paths.base,
|
|
763
|
-
kit.appDir
|
|
764
|
-
)
|
|
765
|
-
: create_sveltekit_env_service_worker_dev(
|
|
766
|
-
explicit_env_config,
|
|
767
|
-
env,
|
|
768
|
-
kit.version.name,
|
|
769
|
-
kit_global
|
|
770
|
-
);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
};
|
|
775
|
-
|
|
776
|
-
/** @type {Map<string, Set<string>>} */
|
|
777
|
-
const import_map = new Map();
|
|
778
|
-
|
|
779
|
-
/**
|
|
780
|
-
* Ensures that client-side code can't accidentally import server-side code,
|
|
781
|
-
* whether in `*.server.js` files, `$app/server`, any `/server/` directory, or `$app/env/private`
|
|
782
|
-
* @type {Plugin}
|
|
783
|
-
*/
|
|
784
|
-
const plugin_guard = {
|
|
785
|
-
name: 'vite-plugin-sveltekit-guard',
|
|
786
|
-
|
|
787
|
-
// Run this plugin before built-in resolution, so that relative imports
|
|
788
|
-
// are added to the module graph
|
|
789
|
-
enforce: 'pre',
|
|
790
|
-
|
|
791
|
-
applyToEnvironment(environment) {
|
|
792
|
-
// the import map is only read for client-side violations in `load`, so skip other environments
|
|
793
|
-
return environment.config.consumer === 'client';
|
|
794
|
-
},
|
|
795
|
-
|
|
796
|
-
resolveId: {
|
|
797
|
-
// composable filters are not accepted type-wise but still work during build
|
|
798
|
-
// see https://github.com/vitejs/rolldown-vite/issues/605
|
|
799
|
-
filter: /** @type {any} */ (
|
|
800
|
-
/** @satisfies {TopLevelFilterExpression[]} */ ([
|
|
801
|
-
include(and(importerId(/.+/), not(importerId(/index\.html$/))))
|
|
802
|
-
])
|
|
803
|
-
),
|
|
804
|
-
async handler(id, importer, options) {
|
|
805
|
-
// composable filters only work during build so we still need this guard for dev
|
|
806
|
-
// see https://github.com/vitejs/rolldown-vite/issues/605
|
|
807
|
-
if (importer && !importer.endsWith('index.html')) {
|
|
808
|
-
const resolved = await this.resolve(id, importer, { ...options, skipSelf: true });
|
|
809
|
-
|
|
810
|
-
if (resolved) {
|
|
811
|
-
const normalized = normalize_id(resolved.id, normalized_aliases, normalized_cwd);
|
|
812
|
-
|
|
813
|
-
let importers = import_map.get(normalized);
|
|
814
|
-
|
|
815
|
-
if (!importers) {
|
|
816
|
-
importers = new Set();
|
|
817
|
-
import_map.set(normalized, importers);
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
importers.add(normalize_id(importer, normalized_aliases, normalized_cwd));
|
|
821
|
-
}
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
},
|
|
825
|
-
|
|
826
|
-
load: {
|
|
827
|
-
filter: {
|
|
828
|
-
id: [
|
|
829
|
-
exactRegex(app_server),
|
|
830
|
-
exactRegex(app_env_private),
|
|
831
|
-
server_only_module_pattern,
|
|
832
|
-
server_only_directory_pattern
|
|
833
|
-
]
|
|
834
|
-
},
|
|
835
|
-
handler(id) {
|
|
836
|
-
const normalized = normalize_id(id, normalized_aliases, normalized_cwd);
|
|
837
|
-
|
|
838
|
-
let is_server_only = normalized === '$app/env/private' || normalized === '$app/server';
|
|
839
|
-
|
|
840
|
-
// skip .server.js files outside the cwd or in node_modules, as the filename might not mean 'server-only module' in this context
|
|
841
|
-
if (id.startsWith(normalized_cwd) && !id.startsWith(normalized_node_modules)) {
|
|
842
|
-
// e.g. `server.ts` or `foo.server.ts`
|
|
843
|
-
is_server_only ||= server_only_module_pattern.test(id);
|
|
844
|
-
|
|
845
|
-
// e.g. `server/foo.ts`, unless in `src/routes` or `static`
|
|
846
|
-
is_server_only ||=
|
|
847
|
-
server_only_directory_pattern.test(id) &&
|
|
848
|
-
!id.startsWith(normalized_routes + '/') &&
|
|
849
|
-
!id.startsWith(normalized_assets + '/');
|
|
850
|
-
}
|
|
851
|
-
|
|
852
|
-
if (!is_server_only) return;
|
|
853
|
-
|
|
854
|
-
// in dev, this doesn't exist, so we need to create it
|
|
855
|
-
manifest_data ??= sync.all(svelte_config, root).manifest_data;
|
|
856
|
-
|
|
857
|
-
/** @type {Set<string>} */
|
|
858
|
-
const entrypoints = new Set();
|
|
859
|
-
for (const node of manifest_data.nodes) {
|
|
860
|
-
if (node.component) entrypoints.add(node.component);
|
|
861
|
-
if (node.universal) entrypoints.add(node.universal);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
if (manifest_data.hooks.client) entrypoints.add(manifest_data.hooks.client);
|
|
865
|
-
if (manifest_data.hooks.universal) entrypoints.add(manifest_data.hooks.universal);
|
|
866
|
-
|
|
867
|
-
if (service_worker_entry_file) {
|
|
868
|
-
entrypoints.add(posixify(path.relative(root, service_worker_entry_file)));
|
|
869
|
-
}
|
|
870
|
-
|
|
871
|
-
// Walk up the import graph from the server-only module, looking for a chain
|
|
872
|
-
// that leads back to a client entrypoint. We search all candidates (not just
|
|
873
|
-
// the first) because a module can be imported by both server and client code,
|
|
874
|
-
// and a greedy first-match could follow a server-only branch that never
|
|
875
|
-
// reaches an entrypoint — see https://github.com/sveltejs/kit/issues/16232
|
|
876
|
-
/** @type {Set<string>} */
|
|
877
|
-
const visited = new Set([normalized]);
|
|
878
|
-
|
|
879
|
-
/**
|
|
880
|
-
* @param {string} current
|
|
881
|
-
* @param {string[]} chain
|
|
882
|
-
* @returns {string[] | null}
|
|
883
|
-
*/
|
|
884
|
-
function find_chain(current, chain) {
|
|
885
|
-
const importers = import_map.get(current);
|
|
886
|
-
if (!importers) return null;
|
|
887
|
-
|
|
888
|
-
for (const importer of importers) {
|
|
889
|
-
if (visited.has(importer)) continue;
|
|
890
|
-
visited.add(importer);
|
|
891
|
-
|
|
892
|
-
const next_chain = [...chain, importer];
|
|
893
|
-
if (entrypoints.has(importer)) {
|
|
894
|
-
return next_chain;
|
|
895
|
-
}
|
|
896
|
-
const result = find_chain(importer, next_chain);
|
|
897
|
-
if (result) return result;
|
|
898
|
-
}
|
|
899
|
-
return null;
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
const chain = find_chain(normalized, [normalized]);
|
|
903
|
-
|
|
904
|
-
if (chain) {
|
|
905
|
-
if (chain.some((id) => remote_module_pattern.test(id))) {
|
|
906
|
-
error_for_missing_config('remote functions', 'experimental.remoteFunctions', 'true');
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
const pyramid = chain
|
|
910
|
-
.reverse()
|
|
911
|
-
.map((id, i) => {
|
|
912
|
-
return `${' '.repeat(i + 1)}${id}`;
|
|
913
|
-
})
|
|
914
|
-
.join(' imports\n');
|
|
915
|
-
|
|
916
|
-
let message = `Cannot import ${normalized} into code that runs in the browser, as this could leak sensitive information.`;
|
|
917
|
-
message += `\n\n${pyramid}`;
|
|
918
|
-
message += `\n\nIf you're only using the import as a type, change it to \`import type\`.`;
|
|
919
|
-
|
|
920
|
-
throw stackless(message);
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
// No chain from this server-only module to a client entrypoint was found —
|
|
924
|
-
// the module is only imported from server code, which is valid.
|
|
925
|
-
}
|
|
926
|
-
},
|
|
927
|
-
|
|
928
|
-
// avoid watch mode rebuilds using stale import map data
|
|
929
|
-
buildEnd() {
|
|
930
|
-
import_map.clear();
|
|
931
|
-
}
|
|
932
|
-
};
|
|
933
|
-
|
|
934
593
|
/** @type {ViteDevServer} */
|
|
935
594
|
let dev_server;
|
|
936
595
|
|
|
@@ -1077,7 +736,11 @@ function kit({ svelte_config }) {
|
|
|
1077
736
|
'__remote'
|
|
1078
737
|
);
|
|
1079
738
|
|
|
1080
|
-
|
|
739
|
+
const relative = posixify(
|
|
740
|
+
path.relative(path.dirname(id), `${runtime_directory}/client/remote-functions/index.js`)
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
let result = `import * as ${namespace} from '${relative}';\n\n${declarations.join('\n')}`;
|
|
1081
744
|
if (reexports.length > 0) {
|
|
1082
745
|
result += `\nexport { ${reexports.join(', ')} };`;
|
|
1083
746
|
}
|
|
@@ -1130,205 +793,6 @@ function kit({ svelte_config }) {
|
|
|
1130
793
|
|
|
1131
794
|
/** @type {Array<{ path: string }> | null} */
|
|
1132
795
|
let immutable = null;
|
|
1133
|
-
/** @type {string | null} */
|
|
1134
|
-
let manifest_data_code = null;
|
|
1135
|
-
|
|
1136
|
-
/**
|
|
1137
|
-
* Creates the service worker virtual modules
|
|
1138
|
-
* @type {Plugin}
|
|
1139
|
-
*/
|
|
1140
|
-
const plugin_service_worker = {
|
|
1141
|
-
name: 'vite-plugin-sveltekit-service-worker',
|
|
1142
|
-
|
|
1143
|
-
config(config) {
|
|
1144
|
-
service_worker_entry_file = resolve_entry(kit.files.serviceWorker);
|
|
1145
|
-
|
|
1146
|
-
if (!service_worker_entry_file) return;
|
|
1147
|
-
|
|
1148
|
-
service_worker_entry_file = posixify(service_worker_entry_file);
|
|
1149
|
-
|
|
1150
|
-
if (kit.paths.assets) {
|
|
1151
|
-
throw new Error('Cannot use service worker alongside config.paths.assets');
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
const user_service_worker_output_config =
|
|
1155
|
-
config.environments?.serviceWorker?.build?.rolldownOptions?.output;
|
|
1156
|
-
|
|
1157
|
-
/** @type {import('vite').UserConfig} */
|
|
1158
|
-
const new_config = {
|
|
1159
|
-
environments: {
|
|
1160
|
-
serviceWorker: {
|
|
1161
|
-
build: {
|
|
1162
|
-
modulePreload: false,
|
|
1163
|
-
rolldownOptions: {
|
|
1164
|
-
external: [`${kit.paths.base}/${kit.appDir}/env.js`],
|
|
1165
|
-
input: {
|
|
1166
|
-
'service-worker': service_worker_entry_file
|
|
1167
|
-
},
|
|
1168
|
-
output: {
|
|
1169
|
-
format: 'es',
|
|
1170
|
-
entryFileNames: 'service-worker.js',
|
|
1171
|
-
assetFileNames: `${kit.appDir}/immutable/assets/[name].[hash][extname]`,
|
|
1172
|
-
codeSplitting:
|
|
1173
|
-
(Array.isArray(user_service_worker_output_config)
|
|
1174
|
-
? user_service_worker_output_config[0].codeSplitting
|
|
1175
|
-
: user_service_worker_output_config?.codeSplitting) ?? false
|
|
1176
|
-
}
|
|
1177
|
-
},
|
|
1178
|
-
outDir: `${out}/client`,
|
|
1179
|
-
minify: initial_config.build?.minify,
|
|
1180
|
-
// avoid overwriting the client build Vite manifest
|
|
1181
|
-
manifest: '.vite/service-worker-manifest.json'
|
|
1182
|
-
},
|
|
1183
|
-
consumer: 'client'
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
};
|
|
1187
|
-
|
|
1188
|
-
warn_overridden_config(config, new_config);
|
|
1189
|
-
|
|
1190
|
-
return new_config;
|
|
1191
|
-
},
|
|
1192
|
-
|
|
1193
|
-
// our serviceWorker environment only exists when building because Vite only
|
|
1194
|
-
// supports the default client environment during development (for now)
|
|
1195
|
-
applyToEnvironment(environment) {
|
|
1196
|
-
return environment.name === 'serviceWorker';
|
|
1197
|
-
},
|
|
1198
|
-
|
|
1199
|
-
resolveId: {
|
|
1200
|
-
filter: {
|
|
1201
|
-
id: prefixRegex('__sveltekit/')
|
|
1202
|
-
},
|
|
1203
|
-
handler(id) {
|
|
1204
|
-
return `\0virtual:${id}`;
|
|
1205
|
-
}
|
|
1206
|
-
},
|
|
1207
|
-
|
|
1208
|
-
load: {
|
|
1209
|
-
filter: {
|
|
1210
|
-
id: [
|
|
1211
|
-
exactRegex('\0virtual:app/manifest'),
|
|
1212
|
-
exactRegex(sveltekit_manifest_data),
|
|
1213
|
-
exactRegex(sveltekit_env_service_worker),
|
|
1214
|
-
exactRegex(sveltekit_env_public_client)
|
|
1215
|
-
]
|
|
1216
|
-
},
|
|
1217
|
-
handler(id) {
|
|
1218
|
-
if (!manifest_data_code) {
|
|
1219
|
-
// the client build computes `immutable`, unless it was skipped
|
|
1220
|
-
// because every route has `csr: false`
|
|
1221
|
-
immutable ??= collect_immutable(vite_server_manifest, kit.appDir, new Set());
|
|
1222
|
-
|
|
1223
|
-
manifest_data_code = dedent`
|
|
1224
|
-
export const immutable = [
|
|
1225
|
-
${immutable.map((entry) => s(entry)).join(',\n')}
|
|
1226
|
-
];
|
|
1227
|
-
|
|
1228
|
-
export const assets = [
|
|
1229
|
-
${stringify_assets(manifest_data.assets)}
|
|
1230
|
-
];
|
|
1231
|
-
|
|
1232
|
-
export const prerendered = [
|
|
1233
|
-
${prerendered.paths.map((path) => s({ path: path.replace(kit.paths.base, '').slice(1) })).join(',\n')}
|
|
1234
|
-
];
|
|
1235
|
-
|
|
1236
|
-
export const routes = [
|
|
1237
|
-
${stringify_routes(manifest_data.routes)}
|
|
1238
|
-
];
|
|
1239
|
-
`;
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
if (id === '\0virtual:app/manifest') {
|
|
1243
|
-
return `export { immutable, assets, prerendered, routes } from '__sveltekit/manifest-data';`;
|
|
1244
|
-
}
|
|
1245
|
-
|
|
1246
|
-
if (id === sveltekit_manifest_data) {
|
|
1247
|
-
return manifest_data_code;
|
|
1248
|
-
}
|
|
1249
|
-
|
|
1250
|
-
if (id === sveltekit_env_service_worker) {
|
|
1251
|
-
return is_build
|
|
1252
|
-
? create_sveltekit_env_service_worker(
|
|
1253
|
-
explicit_env_config,
|
|
1254
|
-
env,
|
|
1255
|
-
kit.version.name,
|
|
1256
|
-
kit_global,
|
|
1257
|
-
kit.paths.base,
|
|
1258
|
-
kit.appDir
|
|
1259
|
-
)
|
|
1260
|
-
: create_sveltekit_env_service_worker_dev(
|
|
1261
|
-
explicit_env_config,
|
|
1262
|
-
env,
|
|
1263
|
-
kit.version.name,
|
|
1264
|
-
kit_global
|
|
1265
|
-
);
|
|
1266
|
-
}
|
|
1267
|
-
|
|
1268
|
-
if (id === sveltekit_env_public_client) {
|
|
1269
|
-
return create_sveltekit_env_public(
|
|
1270
|
-
explicit_env_config,
|
|
1271
|
-
env,
|
|
1272
|
-
`const env = ${kit_global}.env;`
|
|
1273
|
-
);
|
|
1274
|
-
}
|
|
1275
|
-
}
|
|
1276
|
-
},
|
|
1277
|
-
|
|
1278
|
-
generateBundle(_, bundle) {
|
|
1279
|
-
const invalid_modules = new Set();
|
|
1280
|
-
const modules = new Map([
|
|
1281
|
-
[`${runtime_directory}/app/forms/index.js`, '$app/forms'],
|
|
1282
|
-
[`${runtime_directory}/app/navigation/index.js`, '$app/navigation'],
|
|
1283
|
-
[`${runtime_directory}/app/state/index.js`, '$app/state']
|
|
1284
|
-
]);
|
|
1285
|
-
|
|
1286
|
-
for (const output of Object.values(bundle)) {
|
|
1287
|
-
if (output.type !== 'chunk') continue;
|
|
1288
|
-
|
|
1289
|
-
for (const id of output.moduleIds) {
|
|
1290
|
-
const module = modules.get(id);
|
|
1291
|
-
if (module) invalid_modules.add(module);
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
|
|
1295
|
-
if (invalid_modules.size > 0) {
|
|
1296
|
-
throw new Error(
|
|
1297
|
-
`Cannot import ${Array.from(modules.values())
|
|
1298
|
-
.filter((module) => invalid_modules.has(module))
|
|
1299
|
-
.join(', ')} into service-worker code.`
|
|
1300
|
-
);
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
};
|
|
1304
|
-
|
|
1305
|
-
/** @type {Plugin} */
|
|
1306
|
-
const plugin_service_worker_env = {
|
|
1307
|
-
name: 'vite-plugin-sveltekit-service-worker-env',
|
|
1308
|
-
configResolved() {
|
|
1309
|
-
if (service_worker_entry_file) {
|
|
1310
|
-
// @ts-expect-error transform is defined in this object
|
|
1311
|
-
plugin_service_worker_env.transform.filter = {
|
|
1312
|
-
id: exactRegex(service_worker_entry_file)
|
|
1313
|
-
};
|
|
1314
|
-
}
|
|
1315
|
-
},
|
|
1316
|
-
applyToEnvironment(environment) {
|
|
1317
|
-
return !!service_worker_entry_file && environment.config.consumer === 'client';
|
|
1318
|
-
},
|
|
1319
|
-
transform: {
|
|
1320
|
-
handler(code) {
|
|
1321
|
-
// prepend the service worker with an import that configures
|
|
1322
|
-
// `env`, in case `$app/env/public` is imported. In production
|
|
1323
|
-
// this is required: dynamic public env vars aren't known at
|
|
1324
|
-
// build time, so `env.js` is loaded at runtime. In dev, the
|
|
1325
|
-
// imported module just inlines the current values instead.
|
|
1326
|
-
return {
|
|
1327
|
-
code: `import '__sveltekit/env/service-worker';\n${code}`
|
|
1328
|
-
};
|
|
1329
|
-
}
|
|
1330
|
-
}
|
|
1331
|
-
};
|
|
1332
796
|
|
|
1333
797
|
/** @type {Map<string, Rolldown.RolldownOutput['output']>} */
|
|
1334
798
|
const watch_build_output = new Map();
|
|
@@ -1356,8 +820,8 @@ function kit({ svelte_config }) {
|
|
|
1356
820
|
/** @type {Record<string, string>} */
|
|
1357
821
|
const server_input = {
|
|
1358
822
|
index: `${runtime_directory}/server/index.js`,
|
|
1359
|
-
internal:
|
|
1360
|
-
env: '
|
|
823
|
+
internal: `<sveltekit:generated>/server.js`,
|
|
824
|
+
env: '<sveltekit:generated>/env/config.js',
|
|
1361
825
|
['remote-entry']: `${runtime_directory}/app/server/remote/index.js`
|
|
1362
826
|
};
|
|
1363
827
|
|
|
@@ -1421,10 +885,11 @@ function kit({ svelte_config }) {
|
|
|
1421
885
|
} else {
|
|
1422
886
|
client_input['entry/start'] = `${runtime_directory}/client/entry.js`;
|
|
1423
887
|
client_input['entry/payload'] = `${runtime_directory}/client/payload.js`;
|
|
1424
|
-
client_input['entry/app'] = `${out_dir}/generated/client-optimized/app.js`;
|
|
888
|
+
client_input['entry/app'] = `${out_dir}/generated/build/client-optimized/app.js`;
|
|
1425
889
|
manifest_data.nodes.forEach((node, i) => {
|
|
1426
890
|
if (node.component || node.universal) {
|
|
1427
|
-
client_input[`nodes/${i}`] =
|
|
891
|
+
client_input[`nodes/${i}`] =
|
|
892
|
+
`${out_dir}/generated/build/client-optimized/nodes/${i}.js`;
|
|
1428
893
|
}
|
|
1429
894
|
});
|
|
1430
895
|
}
|
|
@@ -1457,7 +922,7 @@ function kit({ svelte_config }) {
|
|
|
1457
922
|
manifest: true,
|
|
1458
923
|
rolldownOptions: {
|
|
1459
924
|
output: {
|
|
1460
|
-
name:
|
|
925
|
+
name: `${global_name}.app`,
|
|
1461
926
|
assetFileNames: `${app_immutable}/assets/[name].[hash][extname]`,
|
|
1462
927
|
hoistTransitiveImports: false,
|
|
1463
928
|
sourcemapIgnoreList
|
|
@@ -1466,7 +931,7 @@ function kit({ svelte_config }) {
|
|
|
1466
931
|
onwarn(warning, handler) {
|
|
1467
932
|
if (
|
|
1468
933
|
warning.code === 'IMPORT_IS_UNDEFINED' &&
|
|
1469
|
-
warning.id === `${out_dir}/generated/client-optimized/app.js`
|
|
934
|
+
warning.id === `${out_dir}/generated/build/client-optimized/app.js`
|
|
1470
935
|
) {
|
|
1471
936
|
// ignore e.g. undefined `handleError` hook when
|
|
1472
937
|
// referencing `client_hooks.handleError`
|
|
@@ -1533,7 +998,7 @@ function kit({ svelte_config }) {
|
|
|
1533
998
|
groups: [
|
|
1534
999
|
{
|
|
1535
1000
|
name: 'sveltekit-manifest',
|
|
1536
|
-
test:
|
|
1001
|
+
test: '<sveltekit:generated>/app-manifest.js'
|
|
1537
1002
|
}
|
|
1538
1003
|
]
|
|
1539
1004
|
}
|
|
@@ -1625,8 +1090,6 @@ function kit({ svelte_config }) {
|
|
|
1625
1090
|
root,
|
|
1626
1091
|
(data) => {
|
|
1627
1092
|
manifest_data = data;
|
|
1628
|
-
// Invalidate the manifest data module so it reloads with new routes/files
|
|
1629
|
-
invalidate_module(server, sveltekit_manifest_data);
|
|
1630
1093
|
}
|
|
1631
1094
|
);
|
|
1632
1095
|
},
|
|
@@ -1778,7 +1241,8 @@ function kit({ svelte_config }) {
|
|
|
1778
1241
|
write_client_manifest(
|
|
1779
1242
|
kit,
|
|
1780
1243
|
manifest_data,
|
|
1781
|
-
`${out_dir}/generated/client-optimized`,
|
|
1244
|
+
`${out_dir}/generated/build/client-optimized`,
|
|
1245
|
+
root,
|
|
1782
1246
|
build_metadata.nodes
|
|
1783
1247
|
);
|
|
1784
1248
|
|
|
@@ -1889,7 +1353,11 @@ function kit({ svelte_config }) {
|
|
|
1889
1353
|
const uses_env_dynamic_public =
|
|
1890
1354
|
has_explicit_dynamic_public_env &&
|
|
1891
1355
|
client_chunks.some(
|
|
1892
|
-
(chunk) =>
|
|
1356
|
+
(chunk) =>
|
|
1357
|
+
chunk.type === 'chunk' &&
|
|
1358
|
+
chunk.modules[
|
|
1359
|
+
posixify(fs.realpathSync(`${out_dir}/generated/build/env/public/client.js`))
|
|
1360
|
+
]
|
|
1893
1361
|
);
|
|
1894
1362
|
|
|
1895
1363
|
if (kit.output.bundleStrategy === 'split') {
|
|
@@ -1901,7 +1369,7 @@ function kit({ svelte_config }) {
|
|
|
1901
1369
|
.dynamicImports?.[0]; // client/entry.js dynamically imports client/client-entry.js
|
|
1902
1370
|
if (!runtime_entry) throw new Error('Could not find the client runtime chunk');
|
|
1903
1371
|
const runtime = find_deps(vite_client_manifest, runtime_entry, false, root);
|
|
1904
|
-
const app = deps_of(`${out_dir}/generated/client-optimized/app.js`);
|
|
1372
|
+
const app = deps_of(`${out_dir}/generated/build/client-optimized/app.js`);
|
|
1905
1373
|
|
|
1906
1374
|
build_data.client = {
|
|
1907
1375
|
start: start.file,
|
|
@@ -1926,11 +1394,11 @@ function kit({ svelte_config }) {
|
|
|
1926
1394
|
if (kit.router.resolution === 'server') {
|
|
1927
1395
|
const nodes = manifest_data.nodes.map((node, i) => {
|
|
1928
1396
|
if (node.component || node.universal) {
|
|
1929
|
-
const entry = `${out_dir}/generated/client-optimized/nodes/${i}.js`;
|
|
1397
|
+
const entry = `${out_dir}/generated/build/client-optimized/nodes/${i}.js`;
|
|
1930
1398
|
const deps = deps_of(entry, true);
|
|
1931
1399
|
const file = resolve_symlinks(
|
|
1932
1400
|
/** @type {Manifest} */ (vite_client_manifest),
|
|
1933
|
-
`${out_dir}/generated/client-optimized/nodes/${i}.js`,
|
|
1401
|
+
`${out_dir}/generated/build/client-optimized/nodes/${i}.js`,
|
|
1934
1402
|
root
|
|
1935
1403
|
).chunk.file;
|
|
1936
1404
|
|
|
@@ -2088,12 +1556,17 @@ function kit({ svelte_config }) {
|
|
|
2088
1556
|
if (service_worker_entry_file) {
|
|
2089
1557
|
log.info('Building service worker');
|
|
2090
1558
|
|
|
2091
|
-
//
|
|
2092
|
-
builder.environments.serviceWorker.config.define =
|
|
2093
|
-
builder.environments.
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
1559
|
+
// Add defines for `$app/manifest`
|
|
1560
|
+
builder.environments.serviceWorker.config.define = {
|
|
1561
|
+
...builder.environments.serviceWorker.config.define,
|
|
1562
|
+
|
|
1563
|
+
__SVELTEKIT_MANIFEST_ASSETS__: s(
|
|
1564
|
+
manifest_data.assets.map((asset) => ({ path: asset.file }))
|
|
1565
|
+
),
|
|
1566
|
+
__SVELTEKIT_MANIFEST_IMMUTABLE__: s(immutable),
|
|
1567
|
+
__SVELTEKIT_MANIFEST_PRERENDERED__: s(prerendered_paths),
|
|
1568
|
+
__SVELTEKIT_MANIFEST_ROUTES__: s(get_manifest_routes(manifest_data.routes))
|
|
1569
|
+
};
|
|
2097
1570
|
|
|
2098
1571
|
// we have to overwrite this because it can't be configured per environment in the config hook
|
|
2099
1572
|
builder.environments.serviceWorker.config.experimental.renderBuiltUrl = (filename) => {
|
|
@@ -2158,7 +1631,8 @@ function kit({ svelte_config }) {
|
|
|
2158
1631
|
// these are set once per plugin initialisation or when the config hook
|
|
2159
1632
|
// runs. However, those don't re-run during watch mode. So, we need to
|
|
2160
1633
|
// re-initialise them manually here
|
|
2161
|
-
manifest_data =
|
|
1634
|
+
manifest_data = create_manifest_data(svelte_config, root);
|
|
1635
|
+
sync.all(svelte_config, root, manifest_data);
|
|
2162
1636
|
|
|
2163
1637
|
tracked_features = {};
|
|
2164
1638
|
|
|
@@ -2167,21 +1641,11 @@ function kit({ svelte_config }) {
|
|
|
2167
1641
|
emitted_remote_hashes.clear();
|
|
2168
1642
|
|
|
2169
1643
|
immutable = null;
|
|
2170
|
-
manifest_data_code = null;
|
|
2171
1644
|
|
|
2172
1645
|
finalise = null;
|
|
2173
1646
|
|
|
2174
1647
|
fs.mkdirSync(out, { recursive: true });
|
|
2175
1648
|
|
|
2176
|
-
explicit_env_entry = resolve_explicit_env_entry(kit);
|
|
2177
|
-
explicit_env_config = await sync.env(
|
|
2178
|
-
vite,
|
|
2179
|
-
kit,
|
|
2180
|
-
explicit_env_entry,
|
|
2181
|
-
vite_config.root,
|
|
2182
|
-
vite_config.mode
|
|
2183
|
-
);
|
|
2184
|
-
|
|
2185
1649
|
await load_and_validate_params({
|
|
2186
1650
|
routes: manifest_data.routes,
|
|
2187
1651
|
params_path: manifest_data.params,
|
|
@@ -2244,10 +1708,29 @@ function kit({ svelte_config }) {
|
|
|
2244
1708
|
plugin_setup,
|
|
2245
1709
|
plugin_remote_guard,
|
|
2246
1710
|
plugin_remote,
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
1711
|
+
plugin_env_vars(svelte_config, (vars) => {
|
|
1712
|
+
explicit_env_config = vars;
|
|
1713
|
+
}),
|
|
1714
|
+
process.env.TEST !== 'true'
|
|
1715
|
+
? plugin_guard(
|
|
1716
|
+
svelte_config,
|
|
1717
|
+
() => ({
|
|
1718
|
+
vite,
|
|
1719
|
+
root,
|
|
1720
|
+
normalized_aliases,
|
|
1721
|
+
service_worker_entry_file
|
|
1722
|
+
}),
|
|
1723
|
+
// in dev, this doesn't exist yet, so we need to create it
|
|
1724
|
+
() => (manifest_data ??= create_manifest_data(svelte_config, root))
|
|
1725
|
+
)
|
|
1726
|
+
: undefined,
|
|
1727
|
+
plugin_service_worker_build(svelte_config, () => ({
|
|
1728
|
+
service_worker_entry_file,
|
|
1729
|
+
kit_global,
|
|
1730
|
+
initial_config,
|
|
1731
|
+
out
|
|
1732
|
+
})),
|
|
1733
|
+
plugin_service_worker_env_vars(() => service_worker_entry_file),
|
|
2251
1734
|
plugin_compile,
|
|
2252
1735
|
plugin_adapter,
|
|
2253
1736
|
svelte_config.adapter?.vite?.plugins?.post
|
|
@@ -2255,52 +1738,6 @@ function kit({ svelte_config }) {
|
|
|
2255
1738
|
);
|
|
2256
1739
|
}
|
|
2257
1740
|
|
|
2258
|
-
/**
|
|
2259
|
-
* @param {UserConfig} config
|
|
2260
|
-
* @param {UserConfig} resolved_config
|
|
2261
|
-
*/
|
|
2262
|
-
function warn_overridden_config(config, resolved_config) {
|
|
2263
|
-
const overridden = find_overridden_config(config, resolved_config, enforced_config, '', []);
|
|
2264
|
-
|
|
2265
|
-
if (overridden.length > 0) {
|
|
2266
|
-
console.error(
|
|
2267
|
-
styleText(
|
|
2268
|
-
['bold', 'red'],
|
|
2269
|
-
'The following Vite config options will be overridden by SvelteKit:'
|
|
2270
|
-
) + overridden.map((key) => `\n - ${key}`).join('')
|
|
2271
|
-
);
|
|
2272
|
-
}
|
|
2273
|
-
}
|
|
2274
|
-
|
|
2275
|
-
/**
|
|
2276
|
-
* @param {Record<string, any>} config
|
|
2277
|
-
* @param {Record<string, any>} resolved_config
|
|
2278
|
-
* @param {import('./types.js').EnforcedConfig} enforced_config
|
|
2279
|
-
* @param {string} path
|
|
2280
|
-
* @param {string[]} out used locally to compute the return value
|
|
2281
|
-
*/
|
|
2282
|
-
function find_overridden_config(config, resolved_config, enforced_config, path, out) {
|
|
2283
|
-
if (config == null || resolved_config == null) {
|
|
2284
|
-
return out;
|
|
2285
|
-
}
|
|
2286
|
-
|
|
2287
|
-
for (const key in enforced_config) {
|
|
2288
|
-
if (typeof config === 'object' && key in config && key in resolved_config) {
|
|
2289
|
-
const enforced = enforced_config[key];
|
|
2290
|
-
const resolved = resolved_config[key];
|
|
2291
|
-
|
|
2292
|
-
if (enforced === true) {
|
|
2293
|
-
if (comparable(config[key]) !== comparable(resolved)) {
|
|
2294
|
-
out.push(path + key);
|
|
2295
|
-
}
|
|
2296
|
-
} else {
|
|
2297
|
-
find_overridden_config(config[key], resolved, enforced, path + key + '.', out);
|
|
2298
|
-
}
|
|
2299
|
-
}
|
|
2300
|
-
}
|
|
2301
|
-
return out;
|
|
2302
|
-
}
|
|
2303
|
-
|
|
2304
1741
|
/**
|
|
2305
1742
|
* Collects the content-hashed files of a Vite manifest, in the shape of
|
|
2306
1743
|
* `$app/manifest`'s `immutable` export.
|
|
@@ -2331,96 +1768,6 @@ const collect_immutable = (manifest, app_dir, inlined) => {
|
|
|
2331
1768
|
return Array.from(files, (path) => ({ path }));
|
|
2332
1769
|
};
|
|
2333
1770
|
|
|
2334
|
-
/**
|
|
2335
|
-
* Normalizes a config value for comparison, since Windows paths may use backslashes
|
|
2336
|
-
* and differ in casing (e.g. the drive letter) depending on where they came from.
|
|
2337
|
-
* @param {any} value
|
|
2338
|
-
*/
|
|
2339
|
-
function comparable(value) {
|
|
2340
|
-
if (typeof value !== 'string') return value;
|
|
2341
|
-
const normalized = posixify(value);
|
|
2342
|
-
return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
|
|
2343
|
-
}
|
|
2344
|
-
|
|
2345
|
-
/**
|
|
2346
|
-
* @param {Asset[] | undefined} assets
|
|
2347
|
-
* @returns {string}
|
|
2348
|
-
*/
|
|
2349
|
-
function stringify_assets(assets) {
|
|
2350
|
-
return assets?.map((asset) => s({ path: asset.file })).join(',\n') ?? '';
|
|
2351
|
-
}
|
|
2352
|
-
|
|
2353
|
-
/**
|
|
2354
|
-
* @param {RouteData[] | undefined} routes
|
|
2355
|
-
* @returns {Array<{ id: string; page: boolean; endpoint: boolean }>}
|
|
2356
|
-
*/
|
|
2357
|
-
function get_manifest_routes(routes) {
|
|
2358
|
-
return (
|
|
2359
|
-
routes?.filter(is_app_route).map((route) => ({
|
|
2360
|
-
id: route.id,
|
|
2361
|
-
page: is_page_route(route),
|
|
2362
|
-
endpoint: is_endpoint_route(route)
|
|
2363
|
-
})) ?? []
|
|
2364
|
-
);
|
|
2365
|
-
}
|
|
2366
|
-
|
|
2367
|
-
/**
|
|
2368
|
-
* @param {RouteData[] | undefined} routes
|
|
2369
|
-
* @returns {string}
|
|
2370
|
-
*/
|
|
2371
|
-
function stringify_routes(routes) {
|
|
2372
|
-
return get_manifest_routes(routes)
|
|
2373
|
-
.map((route) => s(route))
|
|
2374
|
-
.join(',\n');
|
|
2375
|
-
}
|
|
2376
|
-
|
|
2377
|
-
/**
|
|
2378
|
-
* Creates the `$app/manifest` data module. During development, real values
|
|
2379
|
-
* are emitted for `assets` and `routes` (the only data known at that point).
|
|
2380
|
-
*
|
|
2381
|
-
* During build, bare identifier placeholders (fake globals) are emitted.
|
|
2382
|
-
* The bundler leaves these as unresolved global references in the output,
|
|
2383
|
-
* which are then replaced with real values by scanning the output chunks
|
|
2384
|
-
* after each build completes. This avoids the content-hash feedback loop:
|
|
2385
|
-
* the manifest data lives in its own chunk with a fixed filename, so
|
|
2386
|
-
* importers' hashes are stable regardless of the manifest content.
|
|
2387
|
-
*
|
|
2388
|
-
* @param {boolean} is_build
|
|
2389
|
-
* @param {ManifestData | undefined} manifest_data
|
|
2390
|
-
* @returns {string}
|
|
2391
|
-
*/
|
|
2392
|
-
const create_manifest_data_module = (is_build, manifest_data) => {
|
|
2393
|
-
if (is_build) {
|
|
2394
|
-
// Bare identifiers (fake globals) — the bundler leaves these as
|
|
2395
|
-
// unresolved global references in the output. They are replaced
|
|
2396
|
-
// with real values by `replace_manifest_placeholder_variables`
|
|
2397
|
-
// after each build completes.
|
|
2398
|
-
return dedent`
|
|
2399
|
-
export const immutable = __SVELTEKIT_MANIFEST_IMMUTABLE__;
|
|
2400
|
-
export const assets = __SVELTEKIT_MANIFEST_ASSETS__;
|
|
2401
|
-
export const prerendered = __SVELTEKIT_MANIFEST_PRERENDERED__;
|
|
2402
|
-
export const routes = __SVELTEKIT_MANIFEST_ROUTES__;
|
|
2403
|
-
`;
|
|
2404
|
-
}
|
|
2405
|
-
|
|
2406
|
-
// In dev, `manifest_data` may not be set yet on the very first load,
|
|
2407
|
-
// but `configureServer` (which calls `sync.create`) runs before any
|
|
2408
|
-
// module is served, so it will be set by the time this is called.
|
|
2409
|
-
return dedent`
|
|
2410
|
-
// empty during dev
|
|
2411
|
-
export const immutable = [];
|
|
2412
|
-
export const prerendered = [];
|
|
2413
|
-
|
|
2414
|
-
export const assets = [
|
|
2415
|
-
${stringify_assets(manifest_data?.assets)}
|
|
2416
|
-
];
|
|
2417
|
-
|
|
2418
|
-
export const routes = [
|
|
2419
|
-
${stringify_routes(manifest_data?.routes)}
|
|
2420
|
-
];
|
|
2421
|
-
`;
|
|
2422
|
-
};
|
|
2423
|
-
|
|
2424
1771
|
/**
|
|
2425
1772
|
* Replaces manifest data placeholder identifiers in output chunks with real
|
|
2426
1773
|
* values, or strings that are valid JS (so thecode doesn't crash during prerendering)
|