@sveltejs/kit 3.0.0-next.22 → 3.0.0-next.24

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.
Files changed (106) hide show
  1. package/package.json +40 -9
  2. package/src/cli.js +3 -3
  3. package/src/constants.js +13 -1
  4. package/src/core/adapt/builder.js +2 -3
  5. package/src/core/env.js +139 -181
  6. package/src/core/postbuild/analyse.js +9 -4
  7. package/src/core/postbuild/prerender.js +22 -23
  8. package/src/core/sync/create_manifest_data/index.js +29 -33
  9. package/src/core/sync/sync.js +23 -40
  10. package/src/core/sync/write_app_manifest.js +83 -0
  11. package/src/core/sync/write_client_manifest.js +6 -4
  12. package/src/core/sync/write_server.js +10 -6
  13. package/src/core/sync/write_types/index.js +2 -2
  14. package/src/core/utils.js +0 -28
  15. package/src/exports/hooks/public.d.ts +9 -1
  16. package/src/exports/index.js +10 -0
  17. package/src/exports/node/index.js +77 -5
  18. package/src/exports/public.d.ts +9 -0
  19. package/src/exports/vite/build/build_server.js +3 -3
  20. package/src/exports/vite/build/utils.js +48 -4
  21. package/src/exports/vite/dev/index.js +11 -22
  22. package/src/exports/vite/index.js +62 -345
  23. package/src/exports/vite/module_ids.js +1 -11
  24. package/src/exports/vite/plugins/env-vars.js +117 -0
  25. package/src/exports/vite/preview/index.js +6 -4
  26. package/src/exports/vite/utils.js +2 -4
  27. package/src/runtime/app/env/{types.d.ts → client.js} +9 -4
  28. package/src/runtime/app/env/index.js +1 -2
  29. package/src/runtime/app/env/private/index.js +1 -0
  30. package/src/runtime/app/env/public/client.js +1 -1
  31. package/src/runtime/app/env/public/server.js +1 -1
  32. package/src/runtime/app/env/{internal.js → server.js} +4 -4
  33. package/src/runtime/app/forms/client.js +263 -0
  34. package/src/runtime/app/forms/index.js +1 -263
  35. package/src/runtime/app/forms/public.d.ts +1 -1
  36. package/src/runtime/app/forms/server.js +6 -0
  37. package/src/runtime/app/forms/shared.js +34 -0
  38. package/src/runtime/app/manifest/index.js +1 -1
  39. package/src/runtime/app/navigation/client.js +15 -0
  40. package/src/runtime/app/navigation/index.js +1 -15
  41. package/src/runtime/app/navigation/public.d.ts +1 -1
  42. package/src/runtime/app/navigation/server.js +15 -0
  43. package/src/runtime/app/paths/server.js +1 -1
  44. package/src/runtime/app/server/public.d.ts +512 -0
  45. package/src/runtime/app/server/remote/command.js +1 -1
  46. package/src/runtime/app/server/remote/form.js +16 -6
  47. package/src/runtime/app/server/remote/prerender.js +2 -3
  48. package/src/runtime/app/server/remote/query.js +2 -2
  49. package/src/runtime/app/server/remote/requested.js +3 -3
  50. package/src/runtime/app/state/client.svelte.js +207 -0
  51. package/src/runtime/app/state/index.js +1 -66
  52. package/src/runtime/app/state/public.d.ts +1 -1
  53. package/src/runtime/client/bundle.js +1 -1
  54. package/src/runtime/client/client.js +206 -274
  55. package/src/runtime/client/fetcher.js +18 -8
  56. package/src/runtime/client/remote-functions/command.svelte.js +1 -1
  57. package/src/runtime/client/remote-functions/form.svelte.js +10 -7
  58. package/src/runtime/client/remote-functions/prerender.svelte.js +2 -2
  59. package/src/runtime/client/remote-functions/query/index.js +1 -1
  60. package/src/runtime/client/remote-functions/query/instance.svelte.js +2 -1
  61. package/src/runtime/client/remote-functions/query-batch.svelte.js +1 -1
  62. package/src/runtime/client/remote-functions/query-live/index.js +1 -1
  63. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +4 -3
  64. package/src/runtime/client/remote-functions/query-live/iterator.js +1 -1
  65. package/src/runtime/client/remote-functions/shared.svelte.js +3 -3
  66. package/src/runtime/client/snapshots.js +1 -3
  67. package/src/runtime/client/stream.js +27 -20
  68. package/src/runtime/client/utils.js +7 -3
  69. package/src/runtime/components/root.svelte +5 -5
  70. package/src/runtime/env/dynamic/private.js +1 -1
  71. package/src/runtime/env/static/private.js +1 -1
  72. package/src/runtime/error-chain.js +54 -0
  73. package/src/runtime/form-utils.js +53 -77
  74. package/src/runtime/invalid-import.js +1 -0
  75. package/src/runtime/props.svelte.js +1 -1
  76. package/src/runtime/server/data/index.js +1 -1
  77. package/src/runtime/server/endpoint.js +8 -3
  78. package/src/runtime/server/env_module.js +1 -1
  79. package/src/runtime/server/errors.js +2 -2
  80. package/src/runtime/server/index.js +2 -2
  81. package/src/runtime/server/page/actions.js +77 -122
  82. package/src/runtime/server/page/index.js +37 -69
  83. package/src/runtime/server/page/render.js +18 -23
  84. package/src/runtime/server/remote-functions.js +15 -43
  85. package/src/runtime/server/respond.js +23 -3
  86. package/src/telemetry.js +1 -33
  87. package/src/types/ambient-private.d.ts +9 -17
  88. package/src/types/internal.d.ts +21 -5
  89. package/src/types/private.d.ts +1 -1
  90. package/src/utils/exports.js +1 -0
  91. package/src/utils/filesystem.js +9 -21
  92. package/src/utils/functions.js +10 -0
  93. package/src/utils/promise.js +25 -0
  94. package/src/utils/routing.js +0 -11
  95. package/src/utils/url.js +0 -11
  96. package/src/version.js +1 -1
  97. package/types/index.d.ts +1134 -1136
  98. package/types/index.d.ts.map +50 -50
  99. package/src/exports/remote/index.js +0 -11
  100. package/src/exports/remote/public.d.ts +0 -519
  101. package/src/runtime/app/env/private.js +0 -1
  102. package/src/runtime/app/env/standard-schema.d.ts +0 -0
  103. package/src/runtime/app/state/client.js +0 -63
  104. package/src/runtime/client/state.svelte.js +0 -98
  105. package/src/runtime/server/ambient.d.ts +0 -4
  106. package/src/utils/path.js +0 -23
@@ -2,7 +2,7 @@
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 { Asset, BuildData, ManifestData, Prerendered, RemoteChunk, RemoteInternals, RouteData, ServerMetadata, ValidatedConfig } from 'types' */
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';
@@ -23,22 +23,14 @@ import MagicString from 'magic-string';
23
23
  import { copy, read, resolve_entry } from '../../utils/filesystem.js';
24
24
  import { posixify } from '../../utils/os.js';
25
25
  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';
26
+ import { create_exported_declarations } from '../../core/env.js';
35
27
  import * as sync from '../../core/sync/sync.js';
36
28
  import { load_and_validate_params } from '../../utils/params.js';
37
29
  import { runtime_directory, logger } from '../../core/utils.js';
38
30
  import { generate_manifest } from '../../core/generate_manifest/index.js';
39
31
  import { build_server_nodes } from './build/build_server.js';
40
32
  import { find_deps, resolve_symlinks } from './build/utils.js';
41
- import { dev, invalidate_module } from './dev/index.js';
33
+ import { dev } from './dev/index.js';
42
34
  import { preview } from './preview/index.js';
43
35
  import {
44
36
  error_for_missing_config,
@@ -57,28 +49,17 @@ import analyse from '../../core/postbuild/analyse.js';
57
49
  import { s } from '../../utils/misc.js';
58
50
  import { hash } from '../../utils/hash.js';
59
51
  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';
52
+ import create_manifest_data from '../../core/sync/create_manifest_data/index.js';
65
53
  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';
54
+ import { app_env_private, app_server } from './module_ids.js';
76
55
  import { import_peer } from '../../utils/import.js';
77
56
  import { compact } from '../../utils/array.js';
78
57
  import { should_ignore, has_children } from './static_analysis/utils.js';
79
58
  import { process_config, split_config, validate_config } from '../../core/config/index.js';
80
59
  import { treeshake_prerendered_remotes } from './build/remote.js';
81
60
  import { get_runner } from '../../runner.js';
61
+ import { plugin_env_vars } from './plugins/env-vars.js';
62
+ import { get_manifest_routes, write_app_manifest } from '../../core/sync/write_app_manifest.js';
82
63
 
83
64
  /** @type {import('./types.js').EnforcedConfig} */
84
65
  const enforced_config = {
@@ -110,7 +91,8 @@ const enforced_config = {
110
91
  resolve: {
111
92
  alias: {
112
93
  $app: true,
113
- $env: true
94
+ $env: true,
95
+ '<sveltekit:generated>': true
114
96
  }
115
97
  }
116
98
  };
@@ -453,8 +435,6 @@ function kit({ svelte_config }) {
453
435
  const client_hooks = resolve_entry(kit.files.hooks.client);
454
436
  if (client_hooks) allow.add(path.dirname(client_hooks));
455
437
 
456
- const generated = path.posix.join(out_dir, 'generated');
457
-
458
438
  // dev and preview config can be shared
459
439
  /** @type {UserConfig} */
460
440
  const new_config = {
@@ -468,12 +448,11 @@ function kit({ svelte_config }) {
468
448
  },
469
449
  resolve: {
470
450
  alias: [
471
- { find: '__SERVER__', replacement: `${generated}/server` },
472
451
  { find: '$app', replacement: `${runtime_directory}/app` },
473
452
  { find: '$env', replacement: `${runtime_directory}/env` },
474
453
  {
475
- find: '__sveltekit/server',
476
- replacement: `${runtime_directory}/server/internal.js`
454
+ find: '<sveltekit:generated>',
455
+ replacement: `${out_dir}/generated/${is_build ? 'build' : 'dev'}`
477
456
  },
478
457
  ...get_config_aliases(kit, root)
479
458
  ]
@@ -520,7 +499,7 @@ function kit({ svelte_config }) {
520
499
  // because they for example use rolldown.build with `platform: 'browser'`
521
500
  'esm-env',
522
501
  // This forces `$app/*` modules to be bundled, since they depend on
523
- // virtual modules like `__sveltekit/env` (this isn't a valid bare
502
+ // generated modules like `<sveltekit:generated>/env/config.js` (this isn't a valid bare
524
503
  // import, but it works with vite-node's externalization logic, which
525
504
  // uses basic concatenation)
526
505
  '@sveltejs/kit/src/runtime'
@@ -578,7 +557,8 @@ function kit({ svelte_config }) {
578
557
  __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: s(kit.version.pollInterval)
579
558
  };
580
559
 
581
- manifest_data = sync.all(svelte_config, root).manifest_data;
560
+ manifest_data = create_manifest_data(svelte_config, root);
561
+ sync.all(svelte_config, root, manifest_data);
582
562
  } else {
583
563
  new_config.define = {
584
564
  ...define,
@@ -633,6 +613,11 @@ function kit({ svelte_config }) {
633
613
  configResolved(config) {
634
614
  vite_config = config;
635
615
 
616
+ if (!is_build) {
617
+ // Dependency scanning starts before configureServer creates the full manifest
618
+ write_app_manifest(`${out_dir}/generated/dev`, undefined, false);
619
+ }
620
+
636
621
  const unsupported_plugins = vite_config.plugins.filter((plugin) => plugin.transformIndexHtml);
637
622
  if (unsupported_plugins.length) {
638
623
  const verbose = vite_config.logLevel === 'info' || vite_config.logLevel === undefined;
@@ -653,126 +638,9 @@ function kit({ svelte_config }) {
653
638
  }
654
639
  };
655
640
 
656
- /** @type {string | null} */
657
- let explicit_env_entry = null;
658
-
659
641
  /** @type {Record<string, EnvVarConfig<any>> | null} */
660
642
  let explicit_env_config = null;
661
643
 
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
644
  /** @type {Map<string, Set<string>>} */
777
645
  const import_map = new Map();
778
646
 
@@ -852,7 +720,7 @@ function kit({ svelte_config }) {
852
720
  if (!is_server_only) return;
853
721
 
854
722
  // in dev, this doesn't exist, so we need to create it
855
- manifest_data ??= sync.all(svelte_config, root).manifest_data;
723
+ manifest_data ??= create_manifest_data(svelte_config, root);
856
724
 
857
725
  /** @type {Set<string>} */
858
726
  const entrypoints = new Set();
@@ -1077,7 +945,11 @@ function kit({ svelte_config }) {
1077
945
  '__remote'
1078
946
  );
1079
947
 
1080
- let result = `import * as ${namespace} from '__sveltekit/remote';\n\n${declarations.join('\n')}`;
948
+ const relative = posixify(
949
+ path.relative(path.dirname(id), `${runtime_directory}/client/remote-functions/index.js`)
950
+ );
951
+
952
+ let result = `import * as ${namespace} from '${relative}';\n\n${declarations.join('\n')}`;
1081
953
  if (reexports.length > 0) {
1082
954
  result += `\nexport { ${reexports.join(', ')} };`;
1083
955
  }
@@ -1130,8 +1002,6 @@ function kit({ svelte_config }) {
1130
1002
 
1131
1003
  /** @type {Array<{ path: string }> | null} */
1132
1004
  let immutable = null;
1133
- /** @type {string | null} */
1134
- let manifest_data_code = null;
1135
1005
 
1136
1006
  /**
1137
1007
  * Creates the service worker virtual modules
@@ -1158,6 +1028,9 @@ function kit({ svelte_config }) {
1158
1028
  const new_config = {
1159
1029
  environments: {
1160
1030
  serviceWorker: {
1031
+ define: {
1032
+ __SVELTEKIT_PAYLOAD__: kit_global
1033
+ },
1161
1034
  build: {
1162
1035
  modulePreload: false,
1163
1036
  rolldownOptions: {
@@ -1196,85 +1069,6 @@ function kit({ svelte_config }) {
1196
1069
  return environment.name === 'serviceWorker';
1197
1070
  },
1198
1071
 
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
1072
  generateBundle(_, bundle) {
1279
1073
  const invalid_modules = new Set();
1280
1074
  const modules = new Map([
@@ -1324,7 +1118,7 @@ function kit({ svelte_config }) {
1324
1118
  // build time, so `env.js` is loaded at runtime. In dev, the
1325
1119
  // imported module just inlines the current values instead.
1326
1120
  return {
1327
- code: `import '__sveltekit/env/service-worker';\n${code}`
1121
+ code: `import '<sveltekit:generated>/env/service-worker.js';\n${code}`
1328
1122
  };
1329
1123
  }
1330
1124
  }
@@ -1356,8 +1150,8 @@ function kit({ svelte_config }) {
1356
1150
  /** @type {Record<string, string>} */
1357
1151
  const server_input = {
1358
1152
  index: `${runtime_directory}/server/index.js`,
1359
- internal: `${out_dir}/generated/server/internal.js`,
1360
- env: '__sveltekit/env',
1153
+ internal: `<sveltekit:generated>/server.js`,
1154
+ env: '<sveltekit:generated>/env/config.js',
1361
1155
  ['remote-entry']: `${runtime_directory}/app/server/remote/index.js`
1362
1156
  };
1363
1157
 
@@ -1421,10 +1215,11 @@ function kit({ svelte_config }) {
1421
1215
  } else {
1422
1216
  client_input['entry/start'] = `${runtime_directory}/client/entry.js`;
1423
1217
  client_input['entry/payload'] = `${runtime_directory}/client/payload.js`;
1424
- client_input['entry/app'] = `${out_dir}/generated/client-optimized/app.js`;
1218
+ client_input['entry/app'] = `${out_dir}/generated/build/client-optimized/app.js`;
1425
1219
  manifest_data.nodes.forEach((node, i) => {
1426
1220
  if (node.component || node.universal) {
1427
- client_input[`nodes/${i}`] = `${out_dir}/generated/client-optimized/nodes/${i}.js`;
1221
+ client_input[`nodes/${i}`] =
1222
+ `${out_dir}/generated/build/client-optimized/nodes/${i}.js`;
1428
1223
  }
1429
1224
  });
1430
1225
  }
@@ -1466,7 +1261,7 @@ function kit({ svelte_config }) {
1466
1261
  onwarn(warning, handler) {
1467
1262
  if (
1468
1263
  warning.code === 'IMPORT_IS_UNDEFINED' &&
1469
- warning.id === `${out_dir}/generated/client-optimized/app.js`
1264
+ warning.id === `${out_dir}/generated/build/client-optimized/app.js`
1470
1265
  ) {
1471
1266
  // ignore e.g. undefined `handleError` hook when
1472
1267
  // referencing `client_hooks.handleError`
@@ -1533,7 +1328,7 @@ function kit({ svelte_config }) {
1533
1328
  groups: [
1534
1329
  {
1535
1330
  name: 'sveltekit-manifest',
1536
- test: sveltekit_manifest_data
1331
+ test: '<sveltekit:generated>/app-manifest.js'
1537
1332
  }
1538
1333
  ]
1539
1334
  }
@@ -1625,8 +1420,6 @@ function kit({ svelte_config }) {
1625
1420
  root,
1626
1421
  (data) => {
1627
1422
  manifest_data = data;
1628
- // Invalidate the manifest data module so it reloads with new routes/files
1629
- invalidate_module(server, sveltekit_manifest_data);
1630
1423
  }
1631
1424
  );
1632
1425
  },
@@ -1778,7 +1571,8 @@ function kit({ svelte_config }) {
1778
1571
  write_client_manifest(
1779
1572
  kit,
1780
1573
  manifest_data,
1781
- `${out_dir}/generated/client-optimized`,
1574
+ `${out_dir}/generated/build/client-optimized`,
1575
+ root,
1782
1576
  build_metadata.nodes
1783
1577
  );
1784
1578
 
@@ -1889,7 +1683,11 @@ function kit({ svelte_config }) {
1889
1683
  const uses_env_dynamic_public =
1890
1684
  has_explicit_dynamic_public_env &&
1891
1685
  client_chunks.some(
1892
- (chunk) => chunk.type === 'chunk' && chunk.modules[sveltekit_env_public_client]
1686
+ (chunk) =>
1687
+ chunk.type === 'chunk' &&
1688
+ chunk.modules[
1689
+ posixify(fs.realpathSync(`${out_dir}/generated/build/env/public/client.js`))
1690
+ ]
1893
1691
  );
1894
1692
 
1895
1693
  if (kit.output.bundleStrategy === 'split') {
@@ -1901,7 +1699,7 @@ function kit({ svelte_config }) {
1901
1699
  .dynamicImports?.[0]; // client/entry.js dynamically imports client/client-entry.js
1902
1700
  if (!runtime_entry) throw new Error('Could not find the client runtime chunk');
1903
1701
  const runtime = find_deps(vite_client_manifest, runtime_entry, false, root);
1904
- const app = deps_of(`${out_dir}/generated/client-optimized/app.js`);
1702
+ const app = deps_of(`${out_dir}/generated/build/client-optimized/app.js`);
1905
1703
 
1906
1704
  build_data.client = {
1907
1705
  start: start.file,
@@ -1926,11 +1724,11 @@ function kit({ svelte_config }) {
1926
1724
  if (kit.router.resolution === 'server') {
1927
1725
  const nodes = manifest_data.nodes.map((node, i) => {
1928
1726
  if (node.component || node.universal) {
1929
- const entry = `${out_dir}/generated/client-optimized/nodes/${i}.js`;
1727
+ const entry = `${out_dir}/generated/build/client-optimized/nodes/${i}.js`;
1930
1728
  const deps = deps_of(entry, true);
1931
1729
  const file = resolve_symlinks(
1932
1730
  /** @type {Manifest} */ (vite_client_manifest),
1933
- `${out_dir}/generated/client-optimized/nodes/${i}.js`,
1731
+ `${out_dir}/generated/build/client-optimized/nodes/${i}.js`,
1934
1732
  root
1935
1733
  ).chunk.file;
1936
1734
 
@@ -2088,12 +1886,17 @@ function kit({ svelte_config }) {
2088
1886
  if (service_worker_entry_file) {
2089
1887
  log.info('Building service worker');
2090
1888
 
2091
- // mirror client settings that we couldn't set per environment in the config hook
2092
- builder.environments.serviceWorker.config.define =
2093
- builder.environments.client.config.define;
2094
- builder.environments.serviceWorker.config.resolve.alias = [
2095
- ...get_config_aliases(kit, vite_config.root)
2096
- ];
1889
+ // Add defines for `$app/manifest`
1890
+ builder.environments.serviceWorker.config.define = {
1891
+ ...builder.environments.serviceWorker.config.define,
1892
+
1893
+ __SVELTEKIT_MANIFEST_ASSETS__: s(
1894
+ manifest_data.assets.map((asset) => ({ path: asset.file }))
1895
+ ),
1896
+ __SVELTEKIT_MANIFEST_IMMUTABLE__: s(immutable),
1897
+ __SVELTEKIT_MANIFEST_PRERENDERED__: s(prerendered_paths),
1898
+ __SVELTEKIT_MANIFEST_ROUTES__: s(get_manifest_routes(manifest_data.routes))
1899
+ };
2097
1900
 
2098
1901
  // we have to overwrite this because it can't be configured per environment in the config hook
2099
1902
  builder.environments.serviceWorker.config.experimental.renderBuiltUrl = (filename) => {
@@ -2158,7 +1961,8 @@ function kit({ svelte_config }) {
2158
1961
  // these are set once per plugin initialisation or when the config hook
2159
1962
  // runs. However, those don't re-run during watch mode. So, we need to
2160
1963
  // re-initialise them manually here
2161
- manifest_data = sync.all(svelte_config, root).manifest_data;
1964
+ manifest_data = create_manifest_data(svelte_config, root);
1965
+ sync.all(svelte_config, root, manifest_data);
2162
1966
 
2163
1967
  tracked_features = {};
2164
1968
 
@@ -2167,21 +1971,11 @@ function kit({ svelte_config }) {
2167
1971
  emitted_remote_hashes.clear();
2168
1972
 
2169
1973
  immutable = null;
2170
- manifest_data_code = null;
2171
1974
 
2172
1975
  finalise = null;
2173
1976
 
2174
1977
  fs.mkdirSync(out, { recursive: true });
2175
1978
 
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
1979
  await load_and_validate_params({
2186
1980
  routes: manifest_data.routes,
2187
1981
  params_path: manifest_data.params,
@@ -2244,7 +2038,9 @@ function kit({ svelte_config }) {
2244
2038
  plugin_setup,
2245
2039
  plugin_remote_guard,
2246
2040
  plugin_remote,
2247
- plugin_virtual_modules,
2041
+ plugin_env_vars(svelte_config, (vars) => {
2042
+ explicit_env_config = vars;
2043
+ }),
2248
2044
  process.env.TEST !== 'true' ? plugin_guard : undefined,
2249
2045
  plugin_service_worker,
2250
2046
  plugin_service_worker_env,
@@ -2342,85 +2138,6 @@ function comparable(value) {
2342
2138
  return process.platform === 'win32' ? normalized.toLowerCase() : normalized;
2343
2139
  }
2344
2140
 
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
2141
  /**
2425
2142
  * Replaces manifest data placeholder identifiers in output chunks with real
2426
2143
  * values, or strings that are valid JS (so thecode doesn't crash during prerendering)
@@ -1,20 +1,10 @@
1
1
  import { fileURLToPath } from 'node:url';
2
2
  import { posixify } from '../../utils/os.js';
3
3
 
4
- export const sveltekit_env = '\0virtual:__sveltekit/env';
5
- export const sveltekit_env_public_client = '\0virtual:__sveltekit/env/public/client';
6
- export const sveltekit_env_public_server = '\0virtual:__sveltekit/env/public/server';
7
- export const sveltekit_env_private = '\0virtual:__sveltekit/env/private';
8
- export const sveltekit_env_service_worker = '\0virtual:__sveltekit/env/service-worker';
9
- export const sveltekit_server = '\0virtual:__sveltekit/server';
10
- export const service_worker = '\0virtual:service-worker';
11
-
12
- export const sveltekit_manifest_data = '\0virtual:__sveltekit/manifest-data';
13
-
14
4
  export const app_server = posixify(
15
5
  fileURLToPath(new URL('../../runtime/app/server/index.js', import.meta.url))
16
6
  );
17
7
 
18
8
  export const app_env_private = posixify(
19
- fileURLToPath(new URL('../../runtime/app/env/private.js', import.meta.url))
9
+ fileURLToPath(new URL('../../runtime/app/env/private/index.js', import.meta.url))
20
10
  );