@sveltejs/kit 2.42.1 → 2.43.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/package.json +8 -2
  2. package/src/core/postbuild/analyse.js +4 -0
  3. package/src/core/postbuild/prerender.js +18 -6
  4. package/src/core/sync/write_server.js +2 -1
  5. package/src/exports/public.d.ts +39 -38
  6. package/src/exports/vite/dev/index.js +1 -1
  7. package/src/exports/vite/index.js +14 -52
  8. package/src/exports/vite/module_ids.js +0 -1
  9. package/src/runtime/app/paths/client.js +57 -0
  10. package/src/runtime/app/paths/index.js +1 -16
  11. package/src/runtime/app/paths/internal/client.js +3 -0
  12. package/src/runtime/app/paths/internal/server.js +24 -0
  13. package/src/runtime/app/paths/public.d.ts +29 -0
  14. package/src/runtime/app/paths/server.js +31 -0
  15. package/src/runtime/app/paths/types.d.ts +2 -65
  16. package/src/runtime/app/server/index.js +1 -1
  17. package/src/runtime/app/server/remote/form.js +4 -6
  18. package/src/runtime/app/server/remote/prerender.js +21 -16
  19. package/src/runtime/app/server/remote/query.js +9 -5
  20. package/src/runtime/app/server/remote/shared.js +22 -6
  21. package/src/runtime/client/client.js +3 -3
  22. package/src/runtime/client/remote-functions/command.svelte.js +1 -1
  23. package/src/runtime/client/remote-functions/form.svelte.js +1 -1
  24. package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
  25. package/src/runtime/client/remote-functions/query.svelte.js +1 -1
  26. package/src/runtime/client/utils.js +1 -1
  27. package/src/runtime/server/fetch.js +1 -1
  28. package/src/runtime/server/page/render.js +55 -38
  29. package/src/runtime/server/page/server_routing.js +1 -1
  30. package/src/runtime/server/remote.js +1 -1
  31. package/src/runtime/server/respond.js +1 -1
  32. package/src/runtime/utils.js +2 -1
  33. package/src/types/global-private.d.ts +4 -0
  34. package/src/types/internal.d.ts +2 -1
  35. package/src/version.js +1 -1
  36. package/types/index.d.ts +65 -65
  37. package/types/index.d.ts.map +7 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "2.42.1",
3
+ "version": "2.43.0",
4
4
  "description": "SvelteKit is the fastest way to build Svelte apps",
5
5
  "keywords": [
6
6
  "framework",
@@ -41,7 +41,7 @@
41
41
  "@types/set-cookie-parser": "^2.4.7",
42
42
  "dts-buddy": "^0.6.2",
43
43
  "rollup": "^4.14.2",
44
- "svelte": "^5.38.5",
44
+ "svelte": "^5.39.3",
45
45
  "svelte-preprocess": "^6.0.0",
46
46
  "typescript": "^5.3.3",
47
47
  "vite": "^6.3.5",
@@ -69,6 +69,12 @@
69
69
  "types",
70
70
  "svelte-kit.js"
71
71
  ],
72
+ "imports": {
73
+ "#app/paths": {
74
+ "browser": "./src/runtime/app/paths/client.js",
75
+ "default": "./src/runtime/app/paths/server.js"
76
+ }
77
+ },
72
78
  "exports": {
73
79
  "./package.json": "./package.json",
74
80
  ".": {
@@ -255,8 +255,12 @@ function list_features(route, manifest_data, server_manifest, tracked_features)
255
255
  manifest_data.routes.find((r) => r.id === route.id)
256
256
  );
257
257
 
258
+ const visited = new Set();
258
259
  /** @param {string} id */
259
260
  function visit(id) {
261
+ if (visited.has(id)) return;
262
+ visited.add(id);
263
+
260
264
  const chunk = server_manifest[id];
261
265
  if (!chunk) return;
262
266
 
@@ -15,6 +15,7 @@ import * as devalue from 'devalue';
15
15
  import { createReadableStream } from '@sveltejs/kit/node';
16
16
  import generate_fallback from './fallback.js';
17
17
  import { stringify_remote_arg } from '../../runtime/shared.js';
18
+ import { filter_env } from '../../utils/env.js';
18
19
 
19
20
  export default forked(import.meta.url, prerender);
20
21
 
@@ -125,12 +126,6 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
125
126
 
126
127
  installPolyfills();
127
128
 
128
- const server = new Server(manifest);
129
- await server.init({
130
- env,
131
- read: (file) => createReadableStream(`${config.outDir}/output/server/${file}`)
132
- });
133
-
134
129
  /** @type {Map<string, string>} */
135
130
  const saved = new Map();
136
131
 
@@ -489,6 +484,15 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
489
484
  }
490
485
  }
491
486
 
487
+ // the user's remote function modules may reference environment variables at
488
+ // the top-level so we need to set `env` before evaluating those modules
489
+ // to avoid potential runtime errors
490
+ const { publicPrefix: public_prefix, privatePrefix: private_prefix } = config.env;
491
+ const private_env = filter_env(env, private_prefix, public_prefix);
492
+ const public_env = filter_env(env, public_prefix, private_prefix);
493
+ internal.set_private_env(private_env);
494
+ internal.set_public_env(public_env);
495
+
492
496
  /** @type {Array<import('types').RemoteInfo & { type: 'prerender'}>} */
493
497
  const prerender_functions = [];
494
498
 
@@ -507,6 +511,14 @@ async function prerender({ hash, out, manifest_path, metadata, verbose, env }) {
507
511
  return { prerendered, prerender_map };
508
512
  }
509
513
 
514
+ // only run the server after the `should_prerender` check so that we
515
+ // don't run the user's init hook unnecessarily
516
+ const server = new Server(manifest);
517
+ await server.init({
518
+ env,
519
+ read: (file) => createReadableStream(`${config.outDir}/output/server/${file}`)
520
+ });
521
+
510
522
  log.info('Prerendering');
511
523
 
512
524
  for (const entry of config.prerender.entries) {
@@ -31,12 +31,13 @@ const server_template = ({
31
31
  }) => `
32
32
  import root from '../root.${isSvelte5Plus() ? 'js' : 'svelte'}';
33
33
  import { set_building, set_prerendering } from '__sveltekit/environment';
34
- import { set_assets } from '__sveltekit/paths';
34
+ import { set_assets } from '$app/paths/internal/server';
35
35
  import { set_manifest, set_read_implementation } from '__sveltekit/server';
36
36
  import { set_private_env, set_public_env } from '${runtime_directory}/shared-server.js';
37
37
 
38
38
  export const options = {
39
39
  app_template_contains_nonce: ${template.includes('%sveltekit.nonce%')},
40
+ async: ${s(!!config.compilerOptions?.experimental?.async)},
40
41
  csp: ${s(config.kit.csp)},
41
42
  csrf_check_origin: ${s(config.kit.csrf.checkOrigin && !config.kit.csrf.trustedOrigins.includes('*'))},
42
43
  csrf_trusted_origins: ${s(config.kit.csrf.trustedOrigins)},
@@ -1810,20 +1810,17 @@ export interface Snapshot<T = any> {
1810
1810
  restore: (snapshot: T) => void;
1811
1811
  }
1812
1812
 
1813
- // If T is unknown or RemoteFormInput, the types below will recurse indefinitely and create giant unions that TS can't handle
1814
- type WillRecurseIndefinitely<T> = unknown extends T
1815
- ? true
1816
- : RemoteFormInput extends T
1817
- ? true
1818
- : false;
1813
+ // If T is unknown or has an index signature, the types below will recurse indefinitely and create giant unions that TS can't handle
1814
+ type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
1819
1815
 
1820
1816
  // Helper type to convert union to intersection
1821
1817
  type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void
1822
1818
  ? I
1823
1819
  : never;
1824
1820
 
1825
- type FlattenInput<T, Prefix extends string> =
1826
- WillRecurseIndefinitely<T> extends true
1821
+ type FlattenInput<T, Prefix extends string> = T extends string | number | boolean | null | undefined
1822
+ ? { [P in Prefix]: string }
1823
+ : WillRecurseIndefinitely<T> extends true
1827
1824
  ? { [key: string]: string }
1828
1825
  : T extends Array<infer U>
1829
1826
  ? U extends string | File
@@ -1831,17 +1828,22 @@ type FlattenInput<T, Prefix extends string> =
1831
1828
  : FlattenInput<U, `${Prefix}[${number}]`>
1832
1829
  : T extends File
1833
1830
  ? { [P in Prefix]: string }
1834
- : T extends object
1835
- ? {
1836
- [K in keyof T]: FlattenInput<
1837
- T[K],
1838
- Prefix extends '' ? K & string : `${Prefix}.${K & string}`
1839
- >;
1840
- }[keyof T]
1841
- : { [P in Prefix]: string };
1842
-
1843
- type FlattenIssues<T, Prefix extends string> =
1844
- WillRecurseIndefinitely<T> extends true
1831
+ : {
1832
+ // Required<T> is crucial here to avoid an undefined type to sneak into the union, which would turn the intersection into never
1833
+ [K in keyof Required<T>]: FlattenInput<
1834
+ T[K],
1835
+ Prefix extends '' ? K & string : `${Prefix}.${K & string}`
1836
+ >;
1837
+ }[keyof T];
1838
+
1839
+ type FlattenIssues<T, Prefix extends string> = T extends
1840
+ | string
1841
+ | number
1842
+ | boolean
1843
+ | null
1844
+ | undefined
1845
+ ? { [P in Prefix]: RemoteFormIssue[] }
1846
+ : WillRecurseIndefinitely<T> extends true
1845
1847
  ? { [key: string]: RemoteFormIssue[] }
1846
1848
  : T extends Array<infer U>
1847
1849
  ? { [P in Prefix | `${Prefix}[${number}]`]: RemoteFormIssue[] } & FlattenIssues<
@@ -1850,17 +1852,17 @@ type FlattenIssues<T, Prefix extends string> =
1850
1852
  >
1851
1853
  : T extends File
1852
1854
  ? { [P in Prefix]: RemoteFormIssue[] }
1853
- : T extends object
1854
- ? {
1855
- [K in keyof T]: FlattenIssues<
1856
- T[K],
1857
- Prefix extends '' ? K & string : `${Prefix}.${K & string}`
1858
- >;
1859
- }[keyof T]
1860
- : { [P in Prefix]: RemoteFormIssue[] };
1861
-
1862
- type FlattenKeys<T, Prefix extends string> =
1863
- WillRecurseIndefinitely<T> extends true
1855
+ : {
1856
+ // Required<T> is crucial here to avoid an undefined type to sneak into the union, which would turn the intersection into never
1857
+ [K in keyof Required<T>]: FlattenIssues<
1858
+ T[K],
1859
+ Prefix extends '' ? K & string : `${Prefix}.${K & string}`
1860
+ >;
1861
+ }[keyof T];
1862
+
1863
+ type FlattenKeys<T, Prefix extends string> = T extends string | number | boolean | null | undefined
1864
+ ? { [P in Prefix]: string }
1865
+ : WillRecurseIndefinitely<T> extends true
1864
1866
  ? { [key: string]: string }
1865
1867
  : T extends Array<infer U>
1866
1868
  ? U extends string | File
@@ -1868,14 +1870,13 @@ type FlattenKeys<T, Prefix extends string> =
1868
1870
  : FlattenKeys<U, `${Prefix}[${number}]`>
1869
1871
  : T extends File
1870
1872
  ? { [P in Prefix]: string }
1871
- : T extends object
1872
- ? {
1873
- [K in keyof T]: FlattenKeys<
1874
- T[K],
1875
- Prefix extends '' ? K & string : `${Prefix}.${K & string}`
1876
- >;
1877
- }[keyof T]
1878
- : { [P in Prefix]: string };
1873
+ : {
1874
+ // Required<T> is crucial here to avoid an undefined type to sneak into the union, which would turn the intersection into never
1875
+ [K in keyof Required<T>]: FlattenKeys<
1876
+ T[K],
1877
+ Prefix extends '' ? K & string : `${Prefix}.${K & string}`
1878
+ >;
1879
+ }[keyof T];
1879
1880
 
1880
1881
  export interface RemoteFormInput {
1881
1882
  [key: string]: FormDataEntryValue | FormDataEntryValue[] | RemoteFormInput | RemoteFormInput[];
@@ -522,7 +522,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes) {
522
522
  );
523
523
  set_fix_stack_trace(fix_stack_trace);
524
524
 
525
- const { set_assets } = await vite.ssrLoadModule('__sveltekit/paths');
525
+ const { set_assets } = await vite.ssrLoadModule('$app/paths/internal/server');
526
526
  set_assets(assets);
527
527
 
528
528
  const server = new Server(manifest);
@@ -36,7 +36,6 @@ import {
36
36
  env_static_public,
37
37
  service_worker,
38
38
  sveltekit_environment,
39
- sveltekit_paths,
40
39
  sveltekit_server
41
40
  } from './module_ids.js';
42
41
  import { import_peer } from '../../utils/import.js';
@@ -318,7 +317,7 @@ async function kit({ svelte_config }) {
318
317
  // because they for example use esbuild.build with `platform: 'browser'`
319
318
  'esm-env',
320
319
  // This forces `$app/*` modules to be bundled, since they depend on
321
- // virtual modules like `__sveltekit/paths` (this isn't a valid bare
320
+ // virtual modules like `__sveltekit/environment` (this isn't a valid bare
322
321
  // import, but it works with vite-node's externalization logic, which
323
322
  // uses basic concatenation)
324
323
  '@sveltejs/kit/src/runtime'
@@ -326,18 +325,26 @@ async function kit({ svelte_config }) {
326
325
  }
327
326
  };
328
327
 
328
+ const define = {
329
+ __SVELTEKIT_APP_DIR__: s(kit.appDir),
330
+ __SVELTEKIT_EMBEDDED__: s(kit.embedded),
331
+ __SVELTEKIT_EXPERIMENTAL__REMOTE_FUNCTIONS__: s(kit.experimental.remoteFunctions),
332
+ __SVELTEKIT_PATHS_ASSETS__: s(kit.paths.assets),
333
+ __SVELTEKIT_PATHS_BASE__: s(kit.paths.base),
334
+ __SVELTEKIT_PATHS_RELATIVE__: s(kit.paths.relative),
335
+ __SVELTEKIT_CLIENT_ROUTING__: s(kit.router.resolution === 'client'),
336
+ __SVELTEKIT_SERVER_TRACING_ENABLED__: s(kit.experimental.tracing.server)
337
+ };
338
+
329
339
  if (is_build) {
330
340
  if (!new_config.build) new_config.build = {};
331
341
  new_config.build.ssr = !secondary_build_started;
332
342
 
333
343
  new_config.define = {
344
+ ...define,
334
345
  __SVELTEKIT_ADAPTER_NAME__: s(kit.adapter?.name),
335
346
  __SVELTEKIT_APP_VERSION_FILE__: s(`${kit.appDir}/version.json`),
336
347
  __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: s(kit.version.pollInterval),
337
- __SVELTEKIT_EMBEDDED__: s(kit.embedded),
338
- __SVELTEKIT_EXPERIMENTAL__REMOTE_FUNCTIONS__: s(kit.experimental.remoteFunctions),
339
- __SVELTEKIT_CLIENT_ROUTING__: s(kit.router.resolution === 'client'),
340
- __SVELTEKIT_SERVER_TRACING_ENABLED__: s(kit.experimental.tracing.server),
341
348
  __SVELTEKIT_PAYLOAD__: new_config.build.ssr
342
349
  ? '{}'
343
350
  : `globalThis.__sveltekit_${version_hash}`
@@ -348,11 +355,8 @@ async function kit({ svelte_config }) {
348
355
  }
349
356
  } else {
350
357
  new_config.define = {
358
+ ...define,
351
359
  __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
352
- __SVELTEKIT_EMBEDDED__: s(kit.embedded),
353
- __SVELTEKIT_EXPERIMENTAL__REMOTE_FUNCTIONS__: s(kit.experimental.remoteFunctions),
354
- __SVELTEKIT_CLIENT_ROUTING__: s(kit.router.resolution === 'client'),
355
- __SVELTEKIT_SERVER_TRACING_ENABLED__: s(kit.experimental.tracing.server),
356
360
  __SVELTEKIT_PAYLOAD__: 'globalThis.__sveltekit_dev'
357
361
  };
358
362
 
@@ -460,48 +464,6 @@ async function kit({ svelte_config }) {
460
464
  case service_worker:
461
465
  return create_service_worker_module(svelte_config);
462
466
 
463
- // for internal use only. it's published as $app/paths externally
464
- // we use this alias so that we won't collide with user aliases
465
- case sveltekit_paths: {
466
- const { assets, base } = svelte_config.kit.paths;
467
-
468
- // use the values defined in `global`, but fall back to hard-coded values
469
- // for the sake of things like Vitest which may import this module
470
- // outside the context of a page
471
- if (browser) {
472
- return dedent`
473
- export const base = ${global}?.base ?? ${s(base)};
474
- export const assets = ${global}?.assets ?? ${assets ? s(assets) : 'base'};
475
- export const app_dir = ${s(kit.appDir)};
476
- `;
477
- }
478
-
479
- return dedent`
480
- export let base = ${s(base)};
481
- export let assets = ${assets ? s(assets) : 'base'};
482
- export const app_dir = ${s(kit.appDir)};
483
-
484
- export const relative = ${svelte_config.kit.paths.relative};
485
-
486
- const initial = { base, assets };
487
-
488
- export function override(paths) {
489
- base = paths.base;
490
- assets = paths.assets;
491
- }
492
-
493
- export function reset() {
494
- base = initial.base;
495
- assets = initial.assets;
496
- }
497
-
498
- /** @param {string} path */
499
- export function set_assets(path) {
500
- assets = initial.assets = path;
501
- }
502
- `;
503
- }
504
-
505
467
  case sveltekit_environment: {
506
468
  const { version } = svelte_config.kit;
507
469
 
@@ -9,7 +9,6 @@ export const env_dynamic_public = '\0virtual:env/dynamic/public';
9
9
  export const service_worker = '\0virtual:service-worker';
10
10
 
11
11
  export const sveltekit_environment = '\0virtual:__sveltekit/environment';
12
- export const sveltekit_paths = '\0virtual:__sveltekit/paths';
13
12
  export const sveltekit_server = '\0virtual:__sveltekit/server';
14
13
 
15
14
  export const app_server = posixify(
@@ -0,0 +1,57 @@
1
+ /** @import { Asset, RouteId, Pathname, ResolvedPathname } from '$app/types' */
2
+ /** @import { ResolveArgs } from './types.js' */
3
+ import { base, assets } from './internal/client.js';
4
+ import { resolve_route } from '../../../utils/routing.js';
5
+
6
+ /**
7
+ * Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.kit.paths.assets`](https://svelte.dev/docs/kit/configuration#paths) if configured, or otherwise by prefixing it with the base path.
8
+ *
9
+ * During server rendering, the base path is relative and depends on the page currently being rendered.
10
+ *
11
+ * @example
12
+ * ```svelte
13
+ * <script>
14
+ * import { asset } from '$app/paths';
15
+ * </script>
16
+ *
17
+ * <img alt="a potato" src={asset('/potato.jpg')} />
18
+ * ```
19
+ * @since 2.26
20
+ *
21
+ * @param {Asset} file
22
+ * @returns {string}
23
+ */
24
+ export function asset(file) {
25
+ return (assets || base) + file;
26
+ }
27
+
28
+ /**
29
+ * Resolve a pathname by prefixing it with the base path, if any, or resolve a route ID by populating dynamic segments with parameters.
30
+ *
31
+ * During server rendering, the base path is relative and depends on the page currently being rendered.
32
+ *
33
+ * @example
34
+ * ```js
35
+ * import { resolve } from '$app/paths';
36
+ *
37
+ * // using a pathname
38
+ * const resolved = resolve(`/blog/hello-world`);
39
+ *
40
+ * // using a route ID plus parameters
41
+ * const resolved = resolve('/blog/[slug]', {
42
+ * slug: 'hello-world'
43
+ * });
44
+ * ```
45
+ * @since 2.26
46
+ *
47
+ * @template {RouteId | Pathname} T
48
+ * @param {ResolveArgs<T>} args
49
+ * @returns {ResolvedPathname}
50
+ */
51
+ export function resolve(...args) {
52
+ // The type error is correct here, and if someone doesn't pass params when they should there's a runtime error,
53
+ // but we don't want to adjust the internal resolve_route function to accept `undefined`, hence the type cast.
54
+ return base + resolve_route(args[0], /** @type {Record<string, string>} */ (args[1]));
55
+ }
56
+
57
+ export { base, assets, resolve as resolveRoute };
@@ -1,16 +1 @@
1
- import { base, assets } from '__sveltekit/paths';
2
- import { resolve_route } from '../../../utils/routing.js';
3
-
4
- /** @type {import('./types.d.ts').asset} */
5
- export function asset(file) {
6
- return (assets || base) + file;
7
- }
8
-
9
- /** @type {import('./types.d.ts').resolve} */
10
- export function resolve(id, params) {
11
- // The type error is correct here, and if someone doesn't pass params when they should there's a runtime error,
12
- // but we don't want to adjust the internal resolve_route function to accept `undefined`, hence the type cast.
13
- return base + resolve_route(id, /** @type {Record<string, string>} */ (params));
14
- }
15
-
16
- export { base, assets, resolve as resolveRoute };
1
+ export * from '#app/paths';
@@ -0,0 +1,3 @@
1
+ export const base = __SVELTEKIT_PAYLOAD__?.base ?? __SVELTEKIT_PATHS_BASE__;
2
+ export const assets = __SVELTEKIT_PAYLOAD__?.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__;
3
+ export const app_dir = __SVELTEKIT_APP_DIR__;
@@ -0,0 +1,24 @@
1
+ export let base = __SVELTEKIT_PATHS_BASE__;
2
+ export let assets = __SVELTEKIT_PATHS_ASSETS__ || base;
3
+ export const app_dir = __SVELTEKIT_APP_DIR__;
4
+ export const relative = __SVELTEKIT_PATHS_RELATIVE__;
5
+
6
+ const initial = { base, assets };
7
+
8
+ /**
9
+ * @param {{ base: string, assets: string }} paths
10
+ */
11
+ export function override(paths) {
12
+ base = paths.base;
13
+ assets = paths.assets;
14
+ }
15
+
16
+ export function reset() {
17
+ base = initial.base;
18
+ assets = initial.assets;
19
+ }
20
+
21
+ /** @param {string} path */
22
+ export function set_assets(path) {
23
+ assets = initial.assets = path;
24
+ }
@@ -0,0 +1,29 @@
1
+ import { RouteId, Pathname, ResolvedPathname } from '$app/types';
2
+ import { ResolveArgs } from './types.js';
3
+
4
+ export { resolve, asset } from './client.js';
5
+
6
+ /**
7
+ * A string that matches [`config.kit.paths.base`](https://svelte.dev/docs/kit/configuration#paths).
8
+ *
9
+ * Example usage: `<a href="{base}/your-page">Link</a>`
10
+ *
11
+ * @deprecated Use [`resolve(...)`](https://svelte.dev/docs/kit/$app-paths#resolve) instead
12
+ */
13
+ export let base: '' | `/${string}`;
14
+
15
+ /**
16
+ * An absolute path that matches [`config.kit.paths.assets`](https://svelte.dev/docs/kit/configuration#paths).
17
+ *
18
+ * > [!NOTE] If a value for `config.kit.paths.assets` is specified, it will be replaced with `'/_svelte_kit_assets'` during `vite dev` or `vite preview`, since the assets don't yet live at their eventual URL.
19
+ *
20
+ * @deprecated Use [`asset(...)`](https://svelte.dev/docs/kit/$app-paths#asset) instead
21
+ */
22
+ export let assets: '' | `https://${string}` | `http://${string}` | '/_svelte_kit_assets';
23
+
24
+ /**
25
+ * @deprecated Use [`resolve(...)`](https://svelte.dev/docs/kit/$app-paths#resolve) instead
26
+ */
27
+ export function resolveRoute<T extends RouteId | Pathname>(
28
+ ...args: ResolveArgs<T>
29
+ ): ResolvedPathname;
@@ -0,0 +1,31 @@
1
+ import { base, assets, relative } from './internal/server.js';
2
+ import { resolve_route } from '../../../utils/routing.js';
3
+ import { get_request_store } from '../../../exports/internal/server.js'; // TODO not sure why we can't use `@sveltejs/kit/internal/server` here
4
+
5
+ /** @type {import('./client.js').asset} */
6
+ export function asset(file) {
7
+ // @ts-expect-error we use the `resolve` mechanism, but with the 'wrong' input
8
+ return assets ? assets + file : resolve(file);
9
+ }
10
+
11
+ /** @type {import('./client.js').resolve} */
12
+ export function resolve(id, params) {
13
+ const resolved = resolve_route(id, /** @type {Record<string, string>} */ (params));
14
+
15
+ if (relative) {
16
+ const { event, state } = get_request_store();
17
+
18
+ if (state.prerendering?.fallback) {
19
+ return resolved;
20
+ }
21
+
22
+ const segments = event.url.pathname.slice(base.length).split('/').slice(2);
23
+ const prefix = segments.map(() => '..').join('/') || '.';
24
+
25
+ return prefix + resolved;
26
+ }
27
+
28
+ return resolved;
29
+ }
30
+
31
+ export { base, assets, resolve as resolveRoute };
@@ -1,70 +1,7 @@
1
- import { Asset, RouteId, RouteParams, Pathname, ResolvedPathname } from '$app/types';
1
+ import { Pathname, RouteId, RouteParams } from '$app/types';
2
2
 
3
- /**
4
- * A string that matches [`config.kit.paths.base`](https://svelte.dev/docs/kit/configuration#paths).
5
- *
6
- * Example usage: `<a href="{base}/your-page">Link</a>`
7
- *
8
- * @deprecated Use [`resolve(...)`](https://svelte.dev/docs/kit/$app-paths#resolve) instead
9
- */
10
- export let base: '' | `/${string}`;
11
-
12
- /**
13
- * An absolute path that matches [`config.kit.paths.assets`](https://svelte.dev/docs/kit/configuration#paths).
14
- *
15
- * > [!NOTE] If a value for `config.kit.paths.assets` is specified, it will be replaced with `'/_svelte_kit_assets'` during `vite dev` or `vite preview`, since the assets don't yet live at their eventual URL.
16
- *
17
- * @deprecated Use [`asset(...)`](https://svelte.dev/docs/kit/$app-paths#asset) instead
18
- */
19
- export let assets: '' | `https://${string}` | `http://${string}` | '/_svelte_kit_assets';
20
-
21
- type ResolveArgs<T extends RouteId | Pathname> = T extends RouteId
3
+ export type ResolveArgs<T extends RouteId | Pathname> = T extends RouteId
22
4
  ? RouteParams<T> extends Record<string, never>
23
5
  ? [route: T]
24
6
  : [route: T, params: RouteParams<T>]
25
7
  : [route: T];
26
-
27
- /**
28
- * Resolve a pathname by prefixing it with the base path, if any, or resolve a route ID by populating dynamic segments with parameters.
29
- *
30
- * During server rendering, the base path is relative and depends on the page currently being rendered.
31
- *
32
- * @example
33
- * ```js
34
- * import { resolve } from '$app/paths';
35
- *
36
- * // using a pathname
37
- * const resolved = resolve(`/blog/hello-world`);
38
- *
39
- * // using a route ID plus parameters
40
- * const resolved = resolve('/blog/[slug]', {
41
- * slug: 'hello-world'
42
- * });
43
- * ```
44
- * @since 2.26
45
- */
46
- export function resolve<T extends RouteId | Pathname>(...args: ResolveArgs<T>): ResolvedPathname;
47
-
48
- /**
49
- * Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.kit.paths.assets`](https://svelte.dev/docs/kit/configuration#paths) if configured, or otherwise by prefixing it with the base path.
50
- *
51
- * During server rendering, the base path is relative and depends on the page currently being rendered.
52
- *
53
- * @example
54
- * ```svelte
55
- * <script>
56
- * import { asset } from '$app/paths';
57
- * </script>
58
- *
59
- * <img alt="a potato" src={asset('/potato.jpg')} />
60
- * ```
61
- * @since 2.26
62
- */
63
- export function asset(file: Asset): string;
64
-
65
- /**
66
- * @deprecated Use [`resolve(...)`](https://svelte.dev/docs/kit/$app-paths#resolve) instead
67
- */
68
- export function resolveRoute<T extends RouteId | Pathname>(
69
- ...args: ResolveArgs<T>
70
- ): ResolvedPathname;
@@ -1,5 +1,5 @@
1
1
  import { read_implementation, manifest } from '__sveltekit/server';
2
- import { base } from '__sveltekit/paths';
2
+ import { base } from '$app/paths';
3
3
  import { DEV } from 'esm-env';
4
4
  import { base64_decode } from '../../utils.js';
5
5
 
@@ -3,7 +3,7 @@
3
3
  /** @import { StandardSchemaV1 } from '@standard-schema/spec' */
4
4
  import { get_request_store } from '@sveltejs/kit/internal/server';
5
5
  import { DEV } from 'esm-env';
6
- import { run_remote_function } from './shared.js';
6
+ import { get_cache, run_remote_function } from './shared.js';
7
7
  import { convert_formdata, flatten_issues } from '../../../utils.js';
8
8
 
9
9
  /**
@@ -166,7 +166,7 @@ export function form(validate_or_fn, maybe_fn) {
166
166
  // We don't need to care about args or deduplicating calls, because uneval results are only relevant in full page reloads
167
167
  // where only one form submission is active at the same time
168
168
  if (!event.isRemoteRequest) {
169
- (state.remote_data ??= {})[__.id] = output;
169
+ get_cache(__, state)[''] ??= output;
170
170
  }
171
171
 
172
172
  return output;
@@ -189,8 +189,7 @@ export function form(validate_or_fn, maybe_fn) {
189
189
  Object.defineProperty(instance, property, {
190
190
  get() {
191
191
  try {
192
- const { remote_data } = get_request_store().state;
193
- return remote_data?.[__.id]?.[property] ?? {};
192
+ return get_cache(__)?.['']?.[property] ?? {};
194
193
  } catch {
195
194
  return undefined;
196
195
  }
@@ -201,8 +200,7 @@ export function form(validate_or_fn, maybe_fn) {
201
200
  Object.defineProperty(instance, 'result', {
202
201
  get() {
203
202
  try {
204
- const { remote_data } = get_request_store().state;
205
- return remote_data?.[__.id]?.result;
203
+ return get_cache(__)?.['']?.result;
206
204
  } catch {
207
205
  return undefined;
208
206
  }