@sveltejs/kit 3.0.0-next.7 → 3.0.0-next.9

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 (61) hide show
  1. package/package.json +6 -3
  2. package/src/core/config/index.js +1 -2
  3. package/src/core/config/options.js +5 -2
  4. package/src/core/env.js +1 -0
  5. package/src/core/sync/create_manifest_data/index.js +1 -1
  6. package/src/core/sync/sync.js +0 -2
  7. package/src/core/sync/write_client_manifest.js +0 -7
  8. package/src/core/sync/write_non_ambient.js +2 -2
  9. package/src/core/sync/write_server.js +0 -3
  10. package/src/core/sync/write_tsconfig.js +14 -4
  11. package/src/core/sync/write_tsconfig_test/package.json +7 -0
  12. package/src/core/sync/write_types/index.js +17 -14
  13. package/src/core/utils.js +2 -2
  14. package/src/exports/hooks/sequence.js +3 -2
  15. package/src/exports/index.js +1 -1
  16. package/src/exports/node/index.js +4 -8
  17. package/src/exports/public.d.ts +22 -23
  18. package/src/exports/vite/dev/index.js +4 -7
  19. package/src/exports/vite/index.js +110 -59
  20. package/src/exports/vite/preview/index.js +13 -14
  21. package/src/exports/vite/utils.js +14 -14
  22. package/src/runtime/app/env/internal.js +4 -4
  23. package/src/runtime/app/environment/index.js +3 -3
  24. package/src/runtime/app/forms.js +2 -2
  25. package/src/runtime/app/paths/internal/client.js +4 -2
  26. package/src/runtime/app/paths/internal/server.js +2 -23
  27. package/src/runtime/app/paths/server.js +2 -2
  28. package/src/runtime/app/server/remote/prerender.js +1 -2
  29. package/src/runtime/client/bundle.js +1 -1
  30. package/src/runtime/client/client-entry.js +3 -0
  31. package/src/runtime/client/client.js +217 -172
  32. package/src/runtime/client/entry.js +24 -3
  33. package/src/runtime/client/payload.js +17 -0
  34. package/src/runtime/client/remote-functions/form.svelte.js +6 -6
  35. package/src/runtime/client/state.svelte.js +0 -1
  36. package/src/runtime/client/types.d.ts +2 -6
  37. package/src/runtime/components/root.svelte +66 -0
  38. package/src/runtime/env/dynamic/private.js +7 -0
  39. package/src/runtime/env/dynamic/public.js +7 -0
  40. package/src/runtime/env/static/private.js +6 -0
  41. package/src/runtime/env/static/public.js +6 -0
  42. package/src/runtime/form-utils.js +1 -4
  43. package/src/runtime/server/cookie.js +51 -23
  44. package/src/runtime/server/csrf.js +1 -1
  45. package/src/runtime/server/data/index.js +8 -12
  46. package/src/runtime/server/page/index.js +7 -14
  47. package/src/runtime/server/page/render.js +71 -78
  48. package/src/runtime/server/remote.js +2 -1
  49. package/src/runtime/server/respond.js +1 -1
  50. package/src/runtime/server/utils.js +28 -5
  51. package/src/runtime/types.d.ts +8 -0
  52. package/src/types/global-private.d.ts +10 -17
  53. package/src/types/internal.d.ts +25 -26
  54. package/src/utils/import.js +6 -1
  55. package/src/utils/imports.js +83 -0
  56. package/src/utils/routing.js +6 -6
  57. package/src/version.js +1 -1
  58. package/types/index.d.ts +34 -285
  59. package/types/index.d.ts.map +3 -26
  60. package/src/core/sync/write_root.js +0 -127
  61. package/src/types/synthetic/$lib.md +0 -5
@@ -1,7 +1,8 @@
1
1
  /** @import { EnvVarConfig, KitConfig } from '@sveltejs/kit' */
2
2
  /** @import { Options, SvelteConfig } from '@sveltejs/vite-plugin-svelte' */
3
3
  /** @import { PreprocessorGroup } from 'svelte/compiler' */
4
- /** @import { Plugin, Manifest, ResolvedConfig, UserConfig, ViteDevServer, Rolldown } from 'vite' */
4
+ /** @import { BuildData, ManifestData, Prerendered, ServerMetadata, RemoteInternals, ValidatedConfig, ValidatedKitConfig } from 'types' */
5
+ /** @import { Manifest, Plugin, ResolvedConfig, Rolldown, UserConfig, ViteDevServer } from 'vite' */
5
6
  import fs from 'node:fs';
6
7
  import path from 'node:path';
7
8
  import process from 'node:process';
@@ -42,6 +43,7 @@ import analyse from '../../core/postbuild/analyse.js';
42
43
  import { s } from '../../utils/misc.js';
43
44
  import { hash } from '../../utils/hash.js';
44
45
  import { dedent } from '../../core/sync/utils.js';
46
+ import { get_import_aliases, get_hash_import_keys } from '../../utils/imports.js';
45
47
  import {
46
48
  app_env_private,
47
49
  app_server,
@@ -60,6 +62,7 @@ import { process_config, split_config, validate_config } from '../../core/config
60
62
  import { treeshake_prerendered_remotes } from './build/remote.js';
61
63
 
62
64
  /**
65
+ * The posix-ified root of the project based on the Vite configuration.
63
66
  * Populated after Vite plugins' `config` hooks run
64
67
  * @type {string}
65
68
  */
@@ -95,7 +98,7 @@ const enforced_config = {
95
98
  resolve: {
96
99
  alias: {
97
100
  $app: true,
98
- $lib: true,
101
+ $env: true,
99
102
  '$service-worker': true
100
103
  }
101
104
  }
@@ -259,14 +262,14 @@ function plugin_root() {
259
262
  * - https://rolldown.rs/apis/plugin-api#output-generation-hooks
260
263
  *
261
264
  * @param {object} opts
262
- * @param {import('types').ValidatedConfig} opts.svelte_config
265
+ * @param {ValidatedConfig} opts.svelte_config
263
266
  * @return {Plugin[]}
264
267
  */
265
268
  function kit({ svelte_config }) {
266
269
  /** @type {typeof import('vite')} */
267
270
  let vite;
268
271
 
269
- /** @type {import('types').ValidatedKitConfig} */
272
+ /** @type {ValidatedKitConfig} */
270
273
  let kit;
271
274
  /** @type {string} `kit.outDir` but posix-ified */
272
275
  let out_dir;
@@ -285,10 +288,10 @@ function kit({ svelte_config }) {
285
288
  /** @type {Record<string, string>} */
286
289
  let env;
287
290
 
288
- /** @type {import('types').ManifestData} */
291
+ /** @type {ManifestData} */
289
292
  let manifest_data;
290
293
 
291
- /** @type {import('types').ServerMetadata | undefined} only set at build time once analysis is finished */
294
+ /** @type {ServerMetadata | undefined} only set at build time once analysis is finished */
292
295
  let build_metadata = undefined;
293
296
 
294
297
  /** @type {UserConfig} */
@@ -301,10 +304,14 @@ function kit({ svelte_config }) {
301
304
 
302
305
  /** @type {string} */
303
306
  let normalized_cwd;
304
- /** @type {string} */
305
- let normalized_lib;
307
+ /** @type {Array<{ alias: string, path: string }>} */
308
+ let normalized_aliases;
306
309
  /** @type {string} */
307
310
  let normalized_node_modules;
311
+ /** @type {string} */
312
+ let normalized_routes;
313
+ /** @type {string} */
314
+ let normalized_assets;
308
315
  /**
309
316
  * A map showing which features (such as `$app/server:read`) are defined
310
317
  * in which chunks, so that we can later determine which routes use which features
@@ -350,11 +357,21 @@ function kit({ svelte_config }) {
350
357
  vite = await import_peer('vite', root);
351
358
 
352
359
  normalized_cwd = vite.normalizePath(root);
353
- normalized_lib = vite.normalizePath(kit.files.lib);
360
+ normalized_aliases = get_import_aliases(root, vite.normalizePath.bind(vite));
354
361
  normalized_node_modules = vite.normalizePath(path.resolve(root, 'node_modules'));
362
+ normalized_routes = vite.normalizePath(path.resolve(root, kit.files.routes));
363
+ normalized_assets = vite.normalizePath(path.resolve(root, kit.files.assets));
364
+
365
+ // Add `#`-prefixed import keys to the enforced config so users are warned
366
+ // if they try to set them in their Vite config's resolve.alias
367
+ const enforced_alias = /** @type {Record<string, true>} */ (
368
+ /** @type {any} */ (enforced_config.resolve).alias
369
+ );
370
+ for (const key of get_hash_import_keys(root)) {
371
+ enforced_alias[key] = true;
372
+ }
355
373
 
356
374
  const allow = new Set([
357
- kit.files.lib,
358
375
  kit.files.routes,
359
376
  kit.files.src,
360
377
  kit.outDir,
@@ -370,6 +387,11 @@ function kit({ svelte_config }) {
370
387
  path.resolve(vite.searchForWorkspaceRoot(process.cwd()), 'node_modules')
371
388
  ]);
372
389
 
390
+ // Add directories from `#`-prefixed package.json imports to the allow list
391
+ for (const { path: alias_path } of normalized_aliases) {
392
+ allow.add(alias_path);
393
+ }
394
+
373
395
  // We can only add directories to the allow list, so we find out
374
396
  // if there's a client hooks file and pass its directory
375
397
  const client_hooks = resolve_entry(kit.files.hooks.client);
@@ -384,6 +406,7 @@ function kit({ svelte_config }) {
384
406
  alias: [
385
407
  { find: '__SERVER__', replacement: `${generated}/server` },
386
408
  { find: '$app', replacement: `${runtime_directory}/app` },
409
+ { find: '$env', replacement: `${runtime_directory}/env` },
387
410
  ...get_config_aliases(kit, root)
388
411
  ]
389
412
  },
@@ -457,7 +480,7 @@ function kit({ svelte_config }) {
457
480
  }
458
481
 
459
482
  const define = {
460
- __SVELTEKIT_APP_DIR__: s(kit.appDir),
483
+ __SVELTEKIT_APP_DIR__: s(posixify(kit.appDir)),
461
484
  __SVELTEKIT_APP_VERSION__: s(kit.version.name),
462
485
  __SVELTEKIT_EMBEDDED__: s(kit.embedded),
463
486
  __SVELTEKIT_FORK_PRELOADS__: s(kit.experimental.forkPreloads),
@@ -467,7 +490,9 @@ function kit({ svelte_config }) {
467
490
  __SVELTEKIT_CLIENT_ROUTING__: s(kit.router.resolution === 'client'),
468
491
  __SVELTEKIT_HASH_ROUTING__: s(kit.router.type === 'hash'),
469
492
  __SVELTEKIT_SERVER_TRACING_ENABLED__: s(kit.tracing.server),
470
- __SVELTEKIT_EXPERIMENTAL_USE_TRANSFORM_ERROR__: s(kit.experimental.handleRenderingErrors),
493
+ __SVELTEKIT_SUPPORTS_ASYNC__: s(
494
+ svelte_config.compilerOptions?.experimental?.async ?? false
495
+ ),
471
496
  __SVELTEKIT_ROOT__: s(root),
472
497
  __SVELTEKIT_DEV__: s(!is_build)
473
498
  };
@@ -485,7 +510,7 @@ function kit({ svelte_config }) {
485
510
  new_config.define = {
486
511
  ...define,
487
512
  __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
488
- __SVELTEKIT_PAYLOAD__: kit_global,
513
+ __SVELTEKIT_PAYLOAD__: kit_global, // only relevant when bundleStrategy !== 'split'
489
514
  __SVELTEKIT_HAS_SERVER_LOAD__: 'true',
490
515
  __SVELTEKIT_HAS_UNIVERSAL_LOAD__: 'true'
491
516
  };
@@ -621,7 +646,7 @@ function kit({ svelte_config }) {
621
646
  return create_sveltekit_env_public(
622
647
  explicit_env_config,
623
648
  env,
624
- `const env = ${kit_global}.env;`
649
+ `import { payload } from ${s(`${runtime_directory}/client/payload.js`)};\nconst env = payload.env;`
625
650
  );
626
651
 
627
652
  case sveltekit_env_public_server:
@@ -647,18 +672,18 @@ function kit({ svelte_config }) {
647
672
 
648
673
  case sveltekit_server: {
649
674
  return dedent`
650
- export let read_implementation = null;
675
+ export let read_implementation = null;
651
676
 
652
- export let manifest = null;
677
+ export let manifest = null;
653
678
 
654
- export function set_read_implementation(fn) {
655
- read_implementation = fn;
656
- }
679
+ export function set_read_implementation(fn) {
680
+ read_implementation = fn;
681
+ }
657
682
 
658
- export function set_manifest(_) {
659
- manifest = _;
660
- }
661
- `;
683
+ export function set_manifest(_) {
684
+ manifest = _;
685
+ }
686
+ `;
662
687
  }
663
688
  }
664
689
  }
@@ -674,7 +699,7 @@ function kit({ svelte_config }) {
674
699
 
675
700
  /**
676
701
  * Ensures that client-side code can't accidentally import server-side code,
677
- * whether in `*.server.js` files, `$app/server`, `$lib/server`, or `$app/env/private`
702
+ * whether in `*.server.js` files, `$app/server`, any `/server/` directory, or `$app/env/private`
678
703
  * @type {Plugin}
679
704
  */
680
705
  const plugin_guard = {
@@ -700,7 +725,7 @@ function kit({ svelte_config }) {
700
725
  const resolved = await this.resolve(id, importer, { ...options, skipSelf: true });
701
726
 
702
727
  if (resolved) {
703
- const normalized = normalize_id(resolved.id, normalized_lib, normalized_cwd);
728
+ const normalized = normalize_id(resolved.id, normalized_aliases, normalized_cwd);
704
729
 
705
730
  let importers = import_map.get(normalized);
706
731
 
@@ -709,7 +734,7 @@ function kit({ svelte_config }) {
709
734
  import_map.set(normalized, importers);
710
735
  }
711
736
 
712
- importers.add(normalize_id(importer, normalized_lib, normalized_cwd));
737
+ importers.add(normalize_id(importer, normalized_aliases, normalized_cwd));
713
738
  }
714
739
  }
715
740
  }
@@ -731,19 +756,22 @@ function kit({ svelte_config }) {
731
756
  const is_internal =
732
757
  id.startsWith(normalized_cwd) && !id.startsWith(normalized_node_modules);
733
758
 
734
- const normalized = normalize_id(id, normalized_lib, normalized_cwd);
759
+ const normalized = normalize_id(id, normalized_aliases, normalized_cwd);
760
+
761
+ // server-only directories: any file in a `/server/` folder inside the cwd,
762
+ // except those inside the routes or assets directories
763
+ const is_in_routes = id.startsWith(normalized_routes + '/');
764
+ const is_in_assets = id.startsWith(normalized_assets + '/');
765
+ const is_server_only_directory =
766
+ is_internal && !is_in_routes && !is_in_assets && server_only_directory_pattern.test(id);
735
767
 
736
768
  const is_server_only =
737
769
  normalized === '$app/env/private' ||
738
770
  normalized === '$app/server' ||
739
- (normalized.startsWith('$lib/') && server_only_directory_pattern.test(id)) ||
771
+ is_server_only_directory ||
740
772
  (is_internal && server_only_module_pattern.test(id));
741
773
 
742
- // skip .server.js files outside the cwd or in node_modules, as the filename might not mean 'server-only module' in this context
743
- // TODO: address https://github.com/sveltejs/kit/issues/12529
744
- if (!is_server_only) {
745
- return;
746
- }
774
+ if (!is_server_only) return;
747
775
 
748
776
  // in dev, this doesn't exist, so we need to create it
749
777
  manifest_data ??= sync.all(svelte_config, root).manifest_data;
@@ -863,7 +891,7 @@ function kit({ svelte_config }) {
863
891
  },
864
892
 
865
893
  async transform(code, id) {
866
- const normalized = normalize_id(id, normalized_lib, normalized_cwd);
894
+ const normalized = normalize_id(id, normalized_aliases, normalized_cwd);
867
895
  if (!svelte_config.kit.moduleExtensions.some((ext) => normalized.endsWith(`.remote${ext}`))) {
868
896
  return;
869
897
  }
@@ -918,7 +946,7 @@ function kit({ svelte_config }) {
918
946
 
919
947
  // For the client, read the exports and create a new module that only contains fetch functions with the correct metadata
920
948
 
921
- /** @type {Map<string, import('types').RemoteInternals['type']>} */
949
+ /** @type {Map<string, RemoteInternals['type']>} */
922
950
  const map = new Map();
923
951
 
924
952
  // in dev, load the server module here (which will result in this hook
@@ -992,7 +1020,7 @@ function kit({ svelte_config }) {
992
1020
  let vite_server_manifest;
993
1021
  /** @type {Manifest | null} */
994
1022
  let vite_client_manifest = null;
995
- /** @type {import('types').Prerendered} */
1023
+ /** @type {Prerendered} */
996
1024
  let prerendered;
997
1025
 
998
1026
  /** @type {Set<string>} */
@@ -1084,7 +1112,7 @@ function kit({ svelte_config }) {
1084
1112
  throw new Error(
1085
1113
  `Cannot import ${normalize_id(
1086
1114
  id,
1087
- normalized_lib,
1115
+ normalized_aliases,
1088
1116
  normalized_cwd
1089
1117
  )} into service-worker code. Only the modules $service-worker and $app/env/public are available in service workers.`
1090
1118
  );
@@ -1178,9 +1206,12 @@ function kit({ svelte_config }) {
1178
1206
  );
1179
1207
  }
1180
1208
 
1181
- const normalized_cwd = vite.normalizePath(vite_config.root);
1182
- const normalized_lib = vite.normalizePath(kit.files.lib);
1183
- const relative = normalize_id(id, normalized_lib, normalized_cwd);
1209
+ const sw_normalized_cwd = vite.normalizePath(vite_config.root);
1210
+ const sw_normalized_aliases = get_import_aliases(
1211
+ vite_config.root,
1212
+ vite.normalizePath.bind(vite)
1213
+ );
1214
+ const relative = normalize_id(id, sw_normalized_aliases, sw_normalized_cwd);
1184
1215
  const stripped = strip_virtual_prefix(relative);
1185
1216
  throw new Error(
1186
1217
  `Cannot import ${stripped} into service-worker code. Only the modules $service-worker and $app/env/public are available in service workers.`
@@ -1228,7 +1259,7 @@ function kit({ svelte_config }) {
1228
1259
  let new_config;
1229
1260
 
1230
1261
  if (is_build) {
1231
- const prefix = `${kit.appDir}/immutable`;
1262
+ const app_immutable = `${kit.appDir}/immutable`;
1232
1263
 
1233
1264
  /** @type {Record<string, string>} */
1234
1265
  const server_input = {
@@ -1297,6 +1328,7 @@ function kit({ svelte_config }) {
1297
1328
  client_input['bundle'] = `${runtime_directory}/client/bundle.js`;
1298
1329
  } else {
1299
1330
  client_input['entry/start'] = `${runtime_directory}/client/entry.js`;
1331
+ client_input['entry/payload'] = `${runtime_directory}/client/payload.js`;
1300
1332
  client_input['entry/app'] = `${out_dir}/generated/client-optimized/app.js`;
1301
1333
  manifest_data.nodes.forEach((node, i) => {
1302
1334
  if (node.component || node.universal) {
@@ -1309,9 +1341,9 @@ function kit({ svelte_config }) {
1309
1341
 
1310
1342
  /** @type {string} */
1311
1343
  const base = (kit.paths.assets || kit.paths.base) + '/';
1312
- const root_to_assets = prefix + '/assets/';
1344
+ const root_to_assets = app_immutable + '/assets/';
1313
1345
  const assets_to_root =
1314
- prefix
1346
+ app_immutable
1315
1347
  .split('/')
1316
1348
  .map(() => '..')
1317
1349
  .join('/') + '/../';
@@ -1334,7 +1366,7 @@ function kit({ svelte_config }) {
1334
1366
  rolldownOptions: {
1335
1367
  output: {
1336
1368
  name: `__sveltekit_${version_hash}.app`,
1337
- assetFileNames: `${prefix}/assets/[name].[hash][extname]`,
1369
+ assetFileNames: `${app_immutable}/assets/[name].[hash][extname]`,
1338
1370
  hoistTransitiveImports: false,
1339
1371
  sourcemapIgnoreList
1340
1372
  },
@@ -1373,7 +1405,7 @@ function kit({ svelte_config }) {
1373
1405
  }
1374
1406
  }
1375
1407
  },
1376
- // during the initial server build we don't know yet
1408
+ // these are stubs that will be replaced after the initial server build
1377
1409
  define: {
1378
1410
  __SVELTEKIT_HAS_SERVER_LOAD__: 'true',
1379
1411
  __SVELTEKIT_HAS_UNIVERSAL_LOAD__: 'true',
@@ -1387,8 +1419,8 @@ function kit({ svelte_config }) {
1387
1419
  input: inline ? client_input['bundle'] : client_input,
1388
1420
  output: {
1389
1421
  format: inline ? 'iife' : 'esm',
1390
- entryFileNames: `${prefix}/[name].[hash].js`,
1391
- chunkFileNames: `${prefix}/chunks/[hash].js`,
1422
+ entryFileNames: `${app_immutable}/[name].[hash].js`,
1423
+ chunkFileNames: `${app_immutable}/chunks/[hash].js`,
1392
1424
  codeSplitting:
1393
1425
  svelte_config.kit.output.bundleStrategy === 'split' ? undefined : false
1394
1426
  },
@@ -1405,7 +1437,8 @@ function kit({ svelte_config }) {
1405
1437
  }
1406
1438
  },
1407
1439
  define: {
1408
- __SVELTEKIT_PAYLOAD__: kit_global
1440
+ __SVELTEKIT_PAYLOAD__:
1441
+ svelte_config.kit.output.bundleStrategy !== 'split' ? kit_global : 'undefined'
1409
1442
  }
1410
1443
  }
1411
1444
  },
@@ -1424,6 +1457,11 @@ function kit({ svelte_config }) {
1424
1457
  return { relative };
1425
1458
  }
1426
1459
 
1460
+ if (!relative) return;
1461
+
1462
+ // ensure assets loaded by CSS files are loaded relative to the
1463
+ // CSS file rather than the default of relative to the root
1464
+
1427
1465
  // _app/immutable/assets files
1428
1466
  if (filename.startsWith(root_to_assets)) {
1429
1467
  return `./${filename.slice(root_to_assets.length)}`;
@@ -1462,16 +1500,16 @@ function kit({ svelte_config }) {
1462
1500
  * Adds the SvelteKit middleware to do SSR in dev mode.
1463
1501
  * @see https://vitejs.dev/guide/api-plugin.html#configureserver
1464
1502
  */
1465
- async configureServer(vite) {
1466
- return await dev(vite, vite_config, svelte_config, () => remotes, root);
1503
+ async configureServer(server) {
1504
+ return await dev(server, vite_config, svelte_config, () => remotes, root);
1467
1505
  },
1468
1506
 
1469
1507
  /**
1470
1508
  * Adds the SvelteKit middleware to do SSR in preview mode.
1471
1509
  * @see https://vitejs.dev/guide/api-plugin.html#configurepreviewserver
1472
1510
  */
1473
- configurePreviewServer(vite) {
1474
- return preview(vite, vite_config, svelte_config);
1511
+ configurePreviewServer(server) {
1512
+ return preview(server, vite_config, svelte_config);
1475
1513
  },
1476
1514
 
1477
1515
  applyToEnvironment(environment) {
@@ -1519,13 +1557,13 @@ function kit({ svelte_config }) {
1519
1557
  await builder.build(builder.environments.ssr)
1520
1558
  );
1521
1559
 
1522
- const verbose = vite_config.logLevel === 'info';
1560
+ const verbose = builder.config.logLevel === 'info';
1523
1561
  const log = logger({ verbose });
1524
1562
 
1525
1563
  /** @type {Manifest} */
1526
1564
  vite_server_manifest = JSON.parse(read(`${out}/server/.vite/manifest.json`));
1527
1565
 
1528
- /** @type {import('types').BuildData} */
1566
+ /** @type {BuildData} */
1529
1567
  const build_data = {
1530
1568
  app_dir: kit.appDir,
1531
1569
  app_path: `${kit.paths.base.slice(1)}${kit.paths.base ? '/' : ''}${kit.appDir}`,
@@ -1663,15 +1701,28 @@ function kit({ svelte_config }) {
1663
1701
  );
1664
1702
 
1665
1703
  if (svelte_config.kit.output.bundleStrategy === 'split') {
1666
- const start = deps_of(`${runtime_directory}/client/entry.js`);
1704
+ const start_entry = posixify(path.relative(root, `${runtime_directory}/client/entry.js`));
1705
+ const start = find_deps(vite_manifest, start_entry, false, root);
1706
+ const runtime_entry = resolve_symlinks(vite_manifest, start_entry, root).chunk
1707
+ .dynamicImports?.[0]; // client/entry.js dynamically imports client/client-entry.js
1708
+ if (!runtime_entry) throw new Error('Could not find the client runtime chunk');
1709
+ const runtime = find_deps(vite_manifest, runtime_entry, false, root);
1667
1710
  const app = deps_of(`${out_dir}/generated/client-optimized/app.js`);
1668
1711
 
1669
1712
  build_data.client = {
1670
1713
  start: start.file,
1671
1714
  app: app.file,
1672
- imports: [...start.imports, ...app.imports],
1673
- stylesheets: [...start.stylesheets, ...app.stylesheets],
1674
- fonts: [...start.fonts, ...app.fonts],
1715
+ imports: Array.from(
1716
+ new Set([
1717
+ ...start.imports,
1718
+ runtime.file,
1719
+ ...runtime.imports,
1720
+ app.file,
1721
+ ...app.imports
1722
+ ])
1723
+ ),
1724
+ stylesheets: [...start.stylesheets, ...runtime.stylesheets, ...app.stylesheets],
1725
+ fonts: [...start.fonts, ...runtime.fonts, ...app.fonts],
1675
1726
  uses_env_dynamic_public
1676
1727
  };
1677
1728
 
@@ -1947,7 +1998,7 @@ function find_overridden_config(config, resolved_config, enforced_config, path,
1947
1998
  }
1948
1999
 
1949
2000
  /**
1950
- * @param {import('types').ValidatedConfig} config
2001
+ * @param {ValidatedConfig} config
1951
2002
  */
1952
2003
  const create_service_worker_module = (config) => dedent`
1953
2004
  if (typeof self === 'undefined' || self instanceof ServiceWorkerGlobalScope === false) {
@@ -1,3 +1,6 @@
1
+ /** @import { NextHandleFunction } from 'connect' */
2
+ /** @import { PreviewServer, ResolvedConfig } from 'vite' */
3
+ /** @import { ValidatedConfig, ServerInternalModule, ServerModule } from 'types' */
1
4
  import fs from 'node:fs';
2
5
  import { join } from 'node:path';
3
6
  import { pathToFileURL } from 'node:url';
@@ -8,14 +11,10 @@ import { createReadableStream, getRequest, setResponse } from '../../../exports/
8
11
  import { SVELTE_KIT_ASSETS } from '../../../constants.js';
9
12
  import { is_chrome_devtools_request, not_found } from '../utils.js';
10
13
 
11
- /** @typedef {import('http').IncomingMessage} Req */
12
- /** @typedef {import('http').ServerResponse} Res */
13
- /** @typedef {(req: Req, res: Res, next: () => void) => void} Handler */
14
-
15
14
  /**
16
- * @param {import('vite').PreviewServer} vite
17
- * @param {import('vite').ResolvedConfig} vite_config
18
- * @param {import('types').ValidatedConfig} svelte_config
15
+ * @param {PreviewServer} vite
16
+ * @param {ResolvedConfig} vite_config
17
+ * @param {ValidatedConfig} svelte_config
19
18
  */
20
19
  export async function preview(vite, vite_config, svelte_config) {
21
20
  const { paths } = svelte_config.kit;
@@ -37,10 +36,10 @@ export async function preview(vite, vite_config, svelte_config) {
37
36
  await import(pathToFileURL(instrumentation).href);
38
37
  }
39
38
 
40
- /** @type {import('types').ServerInternalModule} */
39
+ /** @type {ServerInternalModule} */
41
40
  const { set_assets } = await import(pathToFileURL(join(dir, 'internal.js')).href);
42
41
 
43
- /** @type {import('types').ServerModule} */
42
+ /** @type {ServerModule} */
44
43
  const { Server } = await import(pathToFileURL(join(dir, 'index.js')).href);
45
44
 
46
45
  const { manifest } = await import(pathToFileURL(join(dir, 'manifest.js')).href);
@@ -204,12 +203,12 @@ export async function preview(vite, vite_config, svelte_config) {
204
203
  vite.middlewares.use(async (req, res) => {
205
204
  const host = req.headers[':authority'] || req.headers.host;
206
205
 
207
- const request = await getRequest({
206
+ const request = getRequest({
208
207
  base: `${protocol}://${host}`,
209
208
  request: req
210
209
  });
211
210
 
212
- await setResponse(
211
+ setResponse(
213
212
  res,
214
213
  await server.respond(request, {
215
214
  getClientAddress: () => {
@@ -233,7 +232,7 @@ export async function preview(vite, vite_config, svelte_config) {
233
232
 
234
233
  /**
235
234
  * @param {string} dir
236
- * @returns {Handler}
235
+ * @returns {NextHandleFunction}
237
236
  */
238
237
  const mutable = (dir) =>
239
238
  fs.existsSync(dir)
@@ -245,8 +244,8 @@ const mutable = (dir) =>
245
244
 
246
245
  /**
247
246
  * @param {string} scope
248
- * @param {Handler} handler
249
- * @returns {Handler}
247
+ * @param {NextHandleFunction} handler
248
+ * @returns {NextHandleFunction}
250
249
  */
251
250
  function scoped(scope, handler) {
252
251
  if (scope === '') return handler;
@@ -18,14 +18,10 @@ import {
18
18
  *
19
19
  * @param {import('types').ValidatedKitConfig} config
20
20
  * @param {string} root
21
- * */
21
+ */
22
22
  export function get_config_aliases(config, root) {
23
23
  /** @type {import('vite').Alias[]} */
24
- const alias = [
25
- // For now, we handle `$lib` specially here rather than make it a default value for
26
- // `config.alias` since it has special meaning for packaging, etc.
27
- { find: '$lib', replacement: config.files.lib }
28
- ];
24
+ const alias = [];
29
25
 
30
26
  for (let [key, value] of Object.entries(config.alias)) {
31
27
  value = posixify(value);
@@ -36,16 +32,16 @@ export function get_config_aliases(config, root) {
36
32
  // Doing just `{ find: key.slice(0, -2) ,..}` would mean `import .. from "key"` would also be matched, which we don't want
37
33
  alias.push({
38
34
  find: new RegExp(`^${escape_for_regexp(key.slice(0, -2))}\\/(.+)$`),
39
- replacement: `${path.resolve(root, value)}/$1`
35
+ replacement: `${posixify(path.resolve(root, value))}/$1`
40
36
  });
41
37
  } else if (key + '/*' in config.alias) {
42
38
  // key and key/* both exist -> the replacement for key needs to happen _only_ on import .. from "key"
43
39
  alias.push({
44
40
  find: new RegExp(`^${escape_for_regexp(key)}$`),
45
- replacement: path.resolve(root, value)
41
+ replacement: posixify(path.resolve(root, value))
46
42
  });
47
43
  } else {
48
- alias.push({ find: key, replacement: path.resolve(root, value) });
44
+ alias.push({ find: key, replacement: posixify(path.resolve(root, value)) });
49
45
  }
50
46
  }
51
47
 
@@ -118,16 +114,20 @@ export function not_found(req, res, base) {
118
114
  const query_pattern = /\?.*$/s;
119
115
 
120
116
  /**
121
- * Removes cwd/lib path from the start of the id
117
+ * Removes cwd path from the start of the id and replaces any `#`-prefixed
118
+ * import alias target paths with their alias names.
122
119
  * @param {string} id
123
- * @param {string} lib
120
+ * @param {Array<{ alias: string, path: string }>} aliases — sorted by path length descending
124
121
  * @param {string} cwd
125
122
  */
126
- export function normalize_id(id, lib, cwd) {
123
+ export function normalize_id(id, aliases, cwd) {
127
124
  id = id.replace(query_pattern, '');
128
125
 
129
- if (id.startsWith(lib)) {
130
- id = id.replace(lib, '$lib');
126
+ for (const { alias, path } of aliases) {
127
+ if (id === path || id.startsWith(path + '/')) {
128
+ id = id.replace(path, alias);
129
+ break;
130
+ }
131
131
  }
132
132
 
133
133
  if (id.startsWith(cwd)) {
@@ -1,4 +1,7 @@
1
- export const version = __SVELTEKIT_APP_VERSION__;
1
+ import { BROWSER } from 'esm-env';
2
+ import { payload } from '../../client/payload.js';
3
+
4
+ export const version = BROWSER ? payload.version : __SVELTEKIT_APP_VERSION__;
2
5
  export let building = false;
3
6
  export let prerendering = false;
4
7
 
@@ -9,6 +12,3 @@ export function set_building() {
9
12
  export function set_prerendering() {
10
13
  prerendering = true;
11
14
  }
12
-
13
- // force /@vite/client to be injected
14
- import.meta.hot;
@@ -1,6 +1,6 @@
1
- import { dev } from '../env/index.js';
1
+ import { DEV } from 'esm-env';
2
2
  export * from '../env/index.js';
3
3
 
4
- if (dev) {
5
- console.warn('`$app/environment` is now `$app/env`');
4
+ if (DEV) {
5
+ console.warn('`$app/environment` is deprecated, use `$app/env` instead');
6
6
  }
@@ -1,7 +1,7 @@
1
1
  import * as devalue from 'devalue';
2
2
  import { BROWSER, DEV } from 'esm-env';
3
3
  import { noop } from '../../utils/functions.js';
4
- import { invalidateAll } from './navigation.js';
4
+ import { refreshAll } from './navigation.js';
5
5
  import { app as client_app, applyAction, handle_error } from '../client/client.js';
6
6
  import { app as server_app } from '../server/app.js';
7
7
 
@@ -106,7 +106,7 @@ export function enhance(form_element, submit = noop) {
106
106
  HTMLFormElement.prototype.reset.call(form_element);
107
107
  }
108
108
  if (shouldInvalidateAll) {
109
- await invalidateAll();
109
+ await refreshAll();
110
110
  }
111
111
  }
112
112
 
@@ -1,4 +1,6 @@
1
- export const base = __SVELTEKIT_PAYLOAD__?.base ?? __SVELTEKIT_PATHS_BASE__;
2
- export const assets = __SVELTEKIT_PAYLOAD__?.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__;
1
+ import { payload } from '../../../client/payload.js';
2
+
3
+ export const base = payload.base ?? __SVELTEKIT_PATHS_BASE__;
4
+ export const assets = payload.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__;
3
5
  export const app_dir = __SVELTEKIT_APP_DIR__;
4
6
  export const hash_routing = __SVELTEKIT_HASH_ROUTING__;
@@ -1,30 +1,9 @@
1
- export let base = __SVELTEKIT_PATHS_BASE__;
1
+ export const base = __SVELTEKIT_PATHS_BASE__;
2
2
  export let assets = __SVELTEKIT_PATHS_ASSETS__ || base;
3
3
  export const app_dir = __SVELTEKIT_APP_DIR__;
4
4
  export const relative = __SVELTEKIT_PATHS_RELATIVE__;
5
5
 
6
- const initial = { base, assets };
7
-
8
- /**
9
- * `base` could be overridden during rendering to be relative;
10
- * this one's the original non-relative base path
11
- */
12
- export const initial_base = initial.base;
13
-
14
- /**
15
- * @param {{ base: string, assets: string }} paths
16
- */
17
- export function override(paths) {
18
- base = paths.base;
19
- assets = paths.assets;
20
- }
21
-
22
- export function reset() {
23
- base = initial.base;
24
- assets = initial.assets;
25
- }
26
-
27
6
  /** @param {string} path */
28
7
  export function set_assets(path) {
29
- assets = initial.assets = path;
8
+ assets = path;
30
9
  }