@sveltejs/kit 3.0.0-next.2 → 3.0.0-next.21

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 (195) hide show
  1. package/package.json +62 -36
  2. package/src/cli.js +15 -12
  3. package/src/constants.js +6 -1
  4. package/src/core/adapt/builder.js +66 -72
  5. package/src/core/adapt/index.js +17 -6
  6. package/src/core/config/index.js +134 -80
  7. package/src/core/config/options.js +295 -273
  8. package/src/core/config/types.d.ts +1 -1
  9. package/src/core/env.js +146 -16
  10. package/src/core/generate_manifest/index.js +18 -15
  11. package/src/core/postbuild/analyse.js +8 -20
  12. package/src/core/postbuild/crawl.js +22 -6
  13. package/src/core/postbuild/entities.js +8 -2
  14. package/src/core/postbuild/fallback.js +4 -2
  15. package/src/core/postbuild/prerender.js +222 -70
  16. package/src/core/postbuild/queue.js +2 -1
  17. package/src/core/sync/create_manifest_data/conflict.js +1 -1
  18. package/src/core/sync/create_manifest_data/index.js +82 -62
  19. package/src/core/sync/sync.js +40 -31
  20. package/src/core/sync/ts.js +1 -1
  21. package/src/core/sync/utils.js +22 -2
  22. package/src/core/sync/{write_non_ambient.js → write_app_types.js} +107 -58
  23. package/src/core/sync/write_client_manifest.js +14 -29
  24. package/src/core/sync/write_env.js +7 -5
  25. package/src/core/sync/write_server.js +37 -45
  26. package/src/core/sync/write_tsconfig/index.js +274 -0
  27. package/src/core/sync/write_tsconfig/test-app/package.json +7 -0
  28. package/src/core/sync/write_tsconfig/utils.js +77 -0
  29. package/src/core/sync/write_tsconfig/validate.js +128 -0
  30. package/src/core/sync/write_types/index.js +127 -123
  31. package/src/core/utils.js +30 -5
  32. package/src/exports/env/index.js +77 -0
  33. package/src/exports/env/public.d.ts +55 -0
  34. package/src/exports/hooks/index.js +3 -9
  35. package/src/exports/hooks/public.d.ts +195 -0
  36. package/src/exports/hooks/sequence.js +9 -6
  37. package/src/exports/index.js +52 -29
  38. package/src/exports/internal/client.js +5 -0
  39. package/src/exports/internal/env.js +8 -5
  40. package/src/exports/internal/index.js +1 -90
  41. package/src/exports/internal/{event.js → server/event.js} +2 -3
  42. package/src/exports/internal/server/index.js +37 -0
  43. package/src/exports/internal/server/telemetry.js +95 -0
  44. package/src/exports/internal/shared.js +90 -0
  45. package/src/exports/node/index.js +64 -22
  46. package/src/exports/params/index.js +70 -0
  47. package/src/exports/params/public.d.ts +63 -0
  48. package/src/exports/public.d.ts +50 -1733
  49. package/src/exports/remote/index.js +11 -0
  50. package/src/exports/remote/public.d.ts +519 -0
  51. package/src/exports/url.js +86 -0
  52. package/src/exports/vite/build/build_server.js +54 -65
  53. package/src/exports/vite/build/remote.js +24 -19
  54. package/src/exports/vite/build/utils.js +0 -8
  55. package/src/exports/vite/dev/index.js +218 -146
  56. package/src/exports/vite/index.js +1590 -858
  57. package/src/exports/vite/module_ids.js +2 -2
  58. package/src/exports/vite/preview/index.js +40 -32
  59. package/src/exports/vite/public.d.ts +588 -0
  60. package/src/exports/vite/utils.js +84 -46
  61. package/src/pathname.js +55 -0
  62. package/src/runner.js +15 -0
  63. package/src/runtime/app/env/internal.js +4 -4
  64. package/src/runtime/app/env/types.d.ts +1 -1
  65. package/src/runtime/app/environment/index.js +3 -3
  66. package/src/runtime/app/{forms.js → forms/index.js} +73 -42
  67. package/src/runtime/app/forms/public.d.ts +2 -0
  68. package/src/runtime/app/forms/types.d.ts +56 -0
  69. package/src/runtime/app/internal/transport.js +53 -0
  70. package/src/runtime/app/manifest/index.js +1 -0
  71. package/src/runtime/app/{navigation.js → navigation/index.js} +2 -1
  72. package/src/runtime/app/navigation/public.d.ts +237 -0
  73. package/src/runtime/app/paths/client.js +37 -37
  74. package/src/runtime/app/paths/index.js +1 -1
  75. package/src/runtime/app/paths/internal/client.js +34 -2
  76. package/src/runtime/app/paths/internal/server.js +6 -23
  77. package/src/runtime/app/paths/internal.d.ts +3 -0
  78. package/src/runtime/app/paths/public.d.ts +1 -29
  79. package/src/runtime/app/paths/server.js +36 -17
  80. package/src/runtime/app/paths/types.d.ts +11 -19
  81. package/src/runtime/app/server/index.js +2 -2
  82. package/src/runtime/app/server/public.d.ts +201 -0
  83. package/src/runtime/app/server/remote/command.js +13 -11
  84. package/src/runtime/app/server/remote/form.js +61 -39
  85. package/src/runtime/app/server/remote/prerender.js +45 -45
  86. package/src/runtime/app/server/remote/query.js +106 -108
  87. package/src/runtime/app/server/remote/requested.js +27 -19
  88. package/src/runtime/app/server/remote/shared.js +76 -76
  89. package/src/runtime/app/service-worker/index.js +24 -0
  90. package/src/runtime/app/state/client.js +4 -2
  91. package/src/runtime/app/state/index.js +7 -5
  92. package/src/runtime/app/state/public.d.ts +72 -0
  93. package/src/runtime/app/state/server.js +3 -0
  94. package/src/runtime/app/stores.js +15 -78
  95. package/src/runtime/client/bundle.js +1 -1
  96. package/src/runtime/client/client-entry.js +3 -0
  97. package/src/runtime/client/client.js +1336 -648
  98. package/src/runtime/client/constants.js +3 -6
  99. package/src/runtime/client/entry.js +24 -3
  100. package/src/runtime/client/fetcher.js +25 -25
  101. package/src/runtime/client/ndjson.js +1 -1
  102. package/src/runtime/client/parse.js +1 -1
  103. package/src/runtime/client/payload.js +17 -0
  104. package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
  105. package/src/runtime/client/remote-functions/command.svelte.js +37 -61
  106. package/src/runtime/client/remote-functions/form.svelte.js +267 -178
  107. package/src/runtime/client/remote-functions/prerender.svelte.js +32 -11
  108. package/src/runtime/client/remote-functions/query/index.js +10 -17
  109. package/src/runtime/client/remote-functions/query/instance.svelte.js +64 -18
  110. package/src/runtime/client/remote-functions/query/proxy.js +5 -5
  111. package/src/runtime/client/remote-functions/query-batch.svelte.js +61 -70
  112. package/src/runtime/client/remote-functions/query-live/index.js +1 -1
  113. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +63 -21
  114. package/src/runtime/client/remote-functions/query-live/iterator.js +15 -12
  115. package/src/runtime/client/remote-functions/query-live/proxy.js +2 -12
  116. package/src/runtime/client/remote-functions/shared.svelte.js +90 -65
  117. package/src/runtime/client/snapshots.js +147 -0
  118. package/src/runtime/client/state.svelte.js +94 -55
  119. package/src/runtime/client/stream.js +3 -2
  120. package/src/runtime/client/types.d.ts +13 -9
  121. package/src/runtime/client/utils.js +22 -110
  122. package/src/runtime/components/root.svelte +56 -0
  123. package/src/runtime/env/dynamic/private.js +7 -0
  124. package/src/runtime/env/dynamic/public.js +7 -0
  125. package/src/runtime/env/static/private.js +6 -0
  126. package/src/runtime/env/static/public.js +6 -0
  127. package/src/runtime/form-utils.js +172 -61
  128. package/src/runtime/pathname.js +20 -32
  129. package/src/runtime/props.svelte.js +72 -0
  130. package/src/runtime/server/constants.js +0 -3
  131. package/src/runtime/server/cookie.js +72 -55
  132. package/src/runtime/server/csrf.js +65 -0
  133. package/src/runtime/server/data/index.js +49 -53
  134. package/src/runtime/server/dev.js +22 -0
  135. package/src/runtime/server/endpoint.js +6 -7
  136. package/src/runtime/server/env_module.js +0 -5
  137. package/src/runtime/server/errors.js +160 -0
  138. package/src/runtime/server/fetch.js +32 -39
  139. package/src/runtime/server/index.js +90 -64
  140. package/src/runtime/server/internal.js +71 -0
  141. package/src/runtime/server/page/actions.js +85 -64
  142. package/src/runtime/server/page/crypto.js +2 -2
  143. package/src/runtime/server/page/csp.js +88 -104
  144. package/src/runtime/server/page/data_serializer.js +24 -25
  145. package/src/runtime/server/page/index.js +36 -53
  146. package/src/runtime/server/page/load_data.js +50 -57
  147. package/src/runtime/server/page/render.js +173 -239
  148. package/src/runtime/server/page/respond_with_error.js +17 -31
  149. package/src/runtime/server/page/serialize_data.js +2 -13
  150. package/src/runtime/server/page/server_routing.js +85 -26
  151. package/src/runtime/server/remote-functions.js +640 -0
  152. package/src/runtime/server/respond.js +190 -131
  153. package/src/runtime/server/sourcemaps.js +183 -0
  154. package/src/runtime/server/state.js +53 -0
  155. package/src/runtime/server/utils.js +13 -155
  156. package/src/runtime/shared.js +20 -40
  157. package/src/runtime/utils.js +3 -0
  158. package/src/types/ambient-private.d.ts +11 -1
  159. package/src/types/ambient.d.ts +87 -36
  160. package/src/types/global-private.d.ts +25 -25
  161. package/src/types/internal.d.ts +163 -157
  162. package/src/types/private.d.ts +41 -1
  163. package/src/utils/error.js +28 -4
  164. package/src/utils/escape.js +9 -25
  165. package/src/utils/features.js +1 -1
  166. package/src/utils/filesystem.js +1 -23
  167. package/src/utils/fork.js +7 -2
  168. package/src/utils/hash.js +21 -0
  169. package/src/utils/http.js +8 -7
  170. package/src/utils/import.js +9 -2
  171. package/src/utils/imports.js +83 -0
  172. package/src/utils/mime.js +9 -0
  173. package/src/utils/page_nodes.js +6 -7
  174. package/src/utils/params.js +67 -0
  175. package/src/utils/regex.js +9 -0
  176. package/src/utils/routing.js +145 -73
  177. package/src/utils/shared-iterator.js +5 -0
  178. package/src/utils/streaming.js +14 -4
  179. package/src/utils/url.js +33 -2
  180. package/src/version.js +1 -1
  181. package/types/index.d.ts +2616 -2433
  182. package/types/index.d.ts.map +120 -106
  183. package/src/core/sync/write_ambient.js +0 -18
  184. package/src/core/sync/write_root.js +0 -148
  185. package/src/core/sync/write_tsconfig.js +0 -250
  186. package/src/exports/internal/server.js +0 -22
  187. package/src/exports/node/polyfills.js +0 -30
  188. package/src/runtime/server/app.js +0 -9
  189. package/src/runtime/server/remote.js +0 -457
  190. package/src/runtime/shared-server.js +0 -7
  191. package/src/runtime/telemetry/otel.js +0 -21
  192. package/src/runtime/telemetry/record_span.js +0 -65
  193. package/src/types/synthetic/$lib.md +0 -5
  194. /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
  195. /package/src/{runtime/telemetry/noop.js → telemetry.js} +0 -0
@@ -0,0 +1,237 @@
1
+ import type { LayoutParams as AppLayoutParams, RouteId as AppRouteId } from '$app/types';
2
+
3
+ export * from './index.js';
4
+
5
+ /**
6
+ * Information about the target of a specific navigation.
7
+ */
8
+ export interface NavigationTarget<
9
+ Params extends AppLayoutParams<'/'> = AppLayoutParams<'/'>,
10
+ RouteId extends AppRouteId | null = AppRouteId | null
11
+ > {
12
+ /**
13
+ * Parameters of the target page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
14
+ * Is `null` if the target is not part of the SvelteKit app (could not be resolved to a route).
15
+ */
16
+ params: Params | null;
17
+ /**
18
+ * Info about the target route
19
+ */
20
+ route: {
21
+ /**
22
+ * The ID of the current route - e.g. for `src/routes/blog/[slug]`, it would be `/blog/[slug]`. It is `null` when no route is matched.
23
+ */
24
+ id: RouteId | null;
25
+ };
26
+ /**
27
+ * The URL that is navigated to
28
+ */
29
+ url: URL;
30
+ /**
31
+ * The scroll position associated with this navigation.
32
+ *
33
+ * For the `from` target, this is the scroll position at the moment of navigation.
34
+ *
35
+ * For the `to` target, this represents the scroll position that will be or was restored:
36
+ * - In `beforeNavigate` and `onNavigate`, this is only available for `popstate` navigations (back/forward button)
37
+ * and will be `null` for other navigation types, since the final scroll position isn't known
38
+ * ahead of time.
39
+ * - In `afterNavigate`, this is always the scroll position that was applied after the navigation
40
+ * completed.
41
+ */
42
+ scroll: { x: number; y: number } | null;
43
+ }
44
+
45
+ export interface GotoOptions {
46
+ /**
47
+ * If `true`, replaces the current history entry rather than creating a new one.
48
+ * @default false
49
+ */
50
+ replace?: boolean;
51
+ /** @deprecated Use `replace` instead. */
52
+ replaceState?: boolean;
53
+ /**
54
+ * If `true`, updates the URL and `page.state` without navigating.
55
+ * @default false
56
+ */
57
+ shallow?: boolean;
58
+ /**
59
+ * If `true`, resets the scroll position (to the top of the page, or to the element
60
+ * matching the URL's `#hash` if there is one) and resets focus (to the `<body>`, or the
61
+ * `autofocus` element if there is one) once the navigation completes.
62
+ *
63
+ * If `false`, the current scroll position and focused element are left alone.
64
+ * @default true, or false when `shallow` is true
65
+ */
66
+ reset?: boolean;
67
+ /**
68
+ * If `true`, reruns all `load` functions and queries of the page.
69
+ * @default false
70
+ */
71
+ refreshAll?: boolean;
72
+ /** Causes any `load` functions to rerun if they depend on one of the URLs. */
73
+ invalidate?: Array<string | URL | ((url: URL) => boolean)>;
74
+ /** @deprecated Use `refreshAll` instead. */
75
+ invalidateAll?: boolean;
76
+ /** An optional object that will be available as `page.state`. */
77
+ state?: App.PageState;
78
+ /**
79
+ * If `true`, `page.state` will be restored after a full page reload.
80
+ * @default false
81
+ */
82
+ persistState?: boolean;
83
+ }
84
+
85
+ /**
86
+ * - `enter`: The app has hydrated/started
87
+ * - `form`: The user submitted a `<form method="GET">`
88
+ * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
89
+ * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
90
+ * - `link`: Navigation was triggered by a link click
91
+ * - `popstate`: Navigation was triggered by back/forward navigation
92
+ */
93
+ export type NavigationType = 'enter' | 'form' | 'leave' | 'link' | 'goto' | 'popstate';
94
+
95
+ export interface NavigationBase {
96
+ /**
97
+ * The type of navigation:
98
+ * - `enter`: The app has hydrated/started
99
+ * - `form`: The user submitted a `<form method="GET">`
100
+ * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
101
+ * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
102
+ * - `link`: Navigation was triggered by a link click
103
+ * - `popstate`: Navigation was triggered by back/forward navigation
104
+ */
105
+ type: NavigationType;
106
+ /** Whether this is a shallow navigation. */
107
+ shallow: boolean;
108
+ /**
109
+ * Where navigation was triggered from
110
+ */
111
+ from: NavigationTarget | null;
112
+ /**
113
+ * Where navigation is going to/has gone to
114
+ */
115
+ to: NavigationTarget | null;
116
+ /**
117
+ * Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation).
118
+ */
119
+ willUnload: boolean;
120
+ /**
121
+ * A promise that resolves once the navigation is complete, and rejects if the navigation
122
+ * fails or is aborted. In the case of a `willUnload` navigation, the promise will never resolve
123
+ */
124
+ complete: Promise<void>;
125
+ }
126
+
127
+ /**
128
+ * The navigation that occurs when the app starts/hydrates
129
+ */
130
+ export interface NavigationEnter extends NavigationBase {
131
+ type: 'enter';
132
+
133
+ /**
134
+ * In case of a history back/forward navigation, the number of steps to go back/forward
135
+ */
136
+ delta?: undefined;
137
+
138
+ /**
139
+ * Dispatched `Event` object when navigation occurred by `popstate` or `link`.
140
+ */
141
+ event?: undefined;
142
+ }
143
+
144
+ export type NavigationExternal = NavigationGoto | NavigationLeave;
145
+
146
+ /**
147
+ * A navigation triggered by a `goto(...)` call or a redirect
148
+ */
149
+ export interface NavigationGoto extends NavigationBase {
150
+ type: 'goto';
151
+ }
152
+
153
+ /**
154
+ * A navigation triggered by the tab being closed, or the user navigating to a different document
155
+ */
156
+ export interface NavigationLeave extends NavigationBase {
157
+ type: 'leave';
158
+ }
159
+
160
+ /**
161
+ * A navigation triggered by a `<form method="GET">`
162
+ */
163
+ export interface NavigationFormSubmit extends NavigationBase {
164
+ type: 'form';
165
+
166
+ /**
167
+ * The `SubmitEvent` that caused the navigation
168
+ */
169
+ event: SubmitEvent;
170
+ }
171
+
172
+ /**
173
+ * A navigation triggered by back/forward navigation
174
+ */
175
+ export interface NavigationPopState extends NavigationBase {
176
+ type: 'popstate';
177
+
178
+ /**
179
+ * In case of a history back/forward navigation, the number of steps to go back/forward
180
+ */
181
+ delta: number;
182
+
183
+ /**
184
+ * The `PopStateEvent` that caused the navigation
185
+ */
186
+ event: PopStateEvent;
187
+ }
188
+
189
+ /**
190
+ * A navigation triggered by a link click
191
+ */
192
+ export interface NavigationLink extends NavigationBase {
193
+ type: 'link';
194
+
195
+ /**
196
+ * The `PointerEvent` that caused the navigation
197
+ */
198
+ event: PointerEvent;
199
+ }
200
+
201
+ export type Navigation =
202
+ | NavigationExternal
203
+ | NavigationFormSubmit
204
+ | NavigationPopState
205
+ | NavigationLink;
206
+
207
+ /**
208
+ * The argument passed to [`beforeNavigate`](https://svelte.dev/docs/kit/$app-navigation#beforeNavigate) callbacks.
209
+ */
210
+ export type BeforeNavigate = Navigation & {
211
+ /**
212
+ * Call this to prevent the navigation from starting.
213
+ */
214
+ cancel: () => void;
215
+ };
216
+
217
+ /**
218
+ * The argument passed to [`onNavigate`](https://svelte.dev/docs/kit/$app-navigation#onNavigate) callbacks.
219
+ */
220
+ export type OnNavigate = Navigation & {
221
+ type: Exclude<NavigationType, 'enter' | 'leave'>;
222
+ /**
223
+ * Since `onNavigate` callbacks are called immediately before a client-side navigation, they will never be called with a navigation that unloads the page.
224
+ */
225
+ willUnload: false;
226
+ };
227
+
228
+ /**
229
+ * The argument passed to [`afterNavigate`](https://svelte.dev/docs/kit/$app-navigation#afterNavigate) callbacks.
230
+ */
231
+ export type AfterNavigate = (Navigation | NavigationEnter) & {
232
+ type: Exclude<NavigationType, 'leave'>;
233
+ /**
234
+ * Since `afterNavigate` callbacks are called after a navigation completes, they will never be called with a navigation that unloads the page.
235
+ */
236
+ willUnload: false;
237
+ };
@@ -1,11 +1,13 @@
1
- /** @import { Asset, RouteId, RouteIdWithSearchOrHash, Pathname, PathnameWithSearchOrHash, ResolvedPathname } from '$app/types' */
1
+ /** @import { AssetPath, RouteId, RouteIdWithSearchOrHash, PathnameWithSearchOrHash, ResolvedPathname, RouteParams } from '$app/types' */
2
2
  /** @import { ResolveArgs } from './types.js' */
3
- import { base, assets, hash_routing } from './internal/client.js';
3
+ import { base, assets, hash_routing, match_implementation } from './internal/client.js';
4
4
  import { resolve_route } from '../../../utils/routing.js';
5
- import { get_navigation_intent } from '../../client/client.js';
5
+ import { DEV } from 'esm-env';
6
+
7
+ export { base, assets, app_dir } from './internal/client.js';
6
8
 
7
9
  /**
8
- * 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.
10
+ * Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.paths.assets`](https://svelte.dev/docs/kit/configuration#paths) if configured, or otherwise by prefixing it with the base path.
9
11
  *
10
12
  * During server rendering, the base path is relative and depends on the page currently being rendered.
11
13
  *
@@ -15,15 +17,26 @@ import { get_navigation_intent } from '../../client/client.js';
15
17
  * import { asset } from '$app/paths';
16
18
  * </script>
17
19
  *
18
- * <img alt="a potato" src={asset('/potato.jpg')} />
20
+ * <img alt="a potato" src={asset('potato.jpg')} />
19
21
  * ```
20
22
  * @since 2.26
21
23
  *
22
- * @param {Asset} file
24
+ * @param {AssetPath} file
23
25
  * @returns {string}
24
26
  */
25
27
  export function asset(file) {
26
- return (assets || base) + file;
28
+ let path = /** @type {string} */ (file);
29
+
30
+ // TODO 4.0 remove this
31
+ if (path[0] === '/') {
32
+ if (DEV) {
33
+ console.warn(`\`asset('${path}')\` should now be \`asset('${path.slice(1)}')\``);
34
+ }
35
+
36
+ path = path.slice(1);
37
+ }
38
+
39
+ return (assets || base) + '/' + path;
27
40
  }
28
41
 
29
42
  const pathname_prefix = hash_routing ? '#' : '';
@@ -38,7 +51,7 @@ const pathname_prefix = hash_routing ? '#' : '';
38
51
  * import { resolve } from '$app/paths';
39
52
  *
40
53
  * // using a pathname
41
- * const resolved = resolve(`/blog/hello-world`);
54
+ * const resolved = resolve(`blog/hello-world`);
42
55
  *
43
56
  * // using a route ID plus parameters
44
57
  * const resolved = resolve('/blog/[slug]', {
@@ -52,18 +65,20 @@ const pathname_prefix = hash_routing ? '#' : '';
52
65
  * @returns {ResolvedPathname}
53
66
  */
54
67
  export function resolve(...args) {
55
- if (!args[0].startsWith('/')) {
56
- throw new Error(
57
- `Cannot use \`resolve(...)\` with a non-absolute pathname or route ID (got "${args[0]}"). ` +
58
- '`resolve` is only for internal pathnames and route IDs; external URLs should be used directly.'
68
+ const [id, params] = /** @type {[string, Record<string, string>?]} */ (args);
69
+
70
+ if (id[0] === '/') {
71
+ // route ID
72
+ if (id.includes('[') && !params) {
73
+ throw new Error(`Missing params for dynamic route ID ${id}`);
74
+ }
75
+
76
+ return (
77
+ /** @type {ResolvedPathname} */ (base + pathname_prefix + resolve_route(id, params ?? {}))
59
78
  );
60
79
  }
61
80
 
62
- // The type error is correct here, and if someone doesn't pass params when they should there's a runtime error,
63
- // but we don't want to adjust the internal resolve_route function to accept `undefined`, hence the type cast.
64
- return (
65
- base + pathname_prefix + resolve_route(args[0], /** @type {Record<string, string>} */ (args[1]))
66
- );
81
+ return /** @type {ResolvedPathname} */ (base + pathname_prefix + '/' + id);
67
82
  }
68
83
 
69
84
  /**
@@ -73,7 +88,7 @@ export function resolve(...args) {
73
88
  * ```js
74
89
  * import { match } from '$app/paths';
75
90
  *
76
- * const route = await match('/blog/hello-world');
91
+ * const route = await match('blog/hello-world');
77
92
  *
78
93
  * if (route?.id === '/blog/[slug]') {
79
94
  * const slug = route.params.slug;
@@ -83,24 +98,9 @@ export function resolve(...args) {
83
98
  * ```
84
99
  * @since 2.52.0
85
100
  *
86
- * @param {Pathname | URL | (string & {})} url
87
- * @returns {Promise<{ id: RouteId, params: Record<string, string> } | null>}
101
+ * @param {URL | string} url
102
+ * @returns {Promise<{ [K in RouteId]: { id: K; params: RouteParams<K>; } }[RouteId] | null>}
88
103
  */
89
- export async function match(url) {
90
- if (typeof url === 'string') {
91
- url = new URL(url, location.href);
92
- }
93
-
94
- const intent = await get_navigation_intent(url, false);
95
-
96
- if (intent) {
97
- return {
98
- id: /** @type {RouteId} */ (intent.route.id),
99
- params: intent.params
100
- };
101
- }
102
-
103
- return null;
104
+ export function match(url) {
105
+ return match_implementation(url);
104
106
  }
105
-
106
- export { base, assets, resolve as resolveRoute };
@@ -1 +1 @@
1
- export * from '#app/paths';
1
+ export { asset, resolve, match } from '#app/paths';
@@ -1,4 +1,36 @@
1
- export const base = __SVELTEKIT_PAYLOAD__?.base ?? __SVELTEKIT_PATHS_BASE__;
2
- export const assets = __SVELTEKIT_PAYLOAD__?.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__;
1
+ // TODO get rid of this module — merge the contents into `../client.js`, and expose it to the
2
+ // rest of the codebase as `#app/paths/client`, with an export condition that errors if
3
+ // it is imported on the server
4
+
5
+ /** @import { RouteId } from '$app/types' */
6
+ import { payload } from '../../../client/payload.js';
7
+
8
+ export const base = payload.base ?? __SVELTEKIT_PATHS_BASE__;
9
+ export const assets = payload.assets ?? base ?? __SVELTEKIT_PATHS_ASSETS__;
3
10
  export const app_dir = __SVELTEKIT_APP_DIR__;
4
11
  export const hash_routing = __SVELTEKIT_HASH_ROUTING__;
12
+
13
+ /**
14
+ * We make this configurable per-environment so that it's possible to import `$app/paths`
15
+ * into a service worker without importing the entire client
16
+ * @param {URL | string} _url
17
+ * @returns {Promise<{ [K in RouteId]: { id: K; params: import('$app/types').RouteParams<K>; } }[RouteId] | null>}
18
+ */
19
+ // eslint-disable-next-line @typescript-eslint/require-await
20
+ export let match_implementation = async (_url) => {
21
+ // @ts-ignore
22
+ if (typeof ServiceWorkerGlobalScope !== 'undefined' && self instanceof ServiceWorkerGlobalScope) {
23
+ throw new Error(
24
+ 'Cannot use `match(...)` inside a service worker, as it depends on the SvelteKit client instance'
25
+ );
26
+ }
27
+
28
+ return null;
29
+ };
30
+
31
+ /**
32
+ * @param {typeof match_implementation} fn
33
+ */
34
+ export function set_match_implementation(fn) {
35
+ match_implementation = fn;
36
+ }
@@ -1,30 +1,13 @@
1
- export let base = __SVELTEKIT_PATHS_BASE__;
1
+ // TODO get rid of this module — merge the contents into `../server.js`, and expose it to the
2
+ // rest of the codebase as `#app/paths/server`, with an export condition that errors if
3
+ // it is imported on the client
4
+
5
+ export const base = __SVELTEKIT_PATHS_BASE__;
2
6
  export let assets = __SVELTEKIT_PATHS_ASSETS__ || base;
3
7
  export const app_dir = __SVELTEKIT_APP_DIR__;
4
8
  export const relative = __SVELTEKIT_PATHS_RELATIVE__;
5
9
 
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
10
  /** @param {string} path */
28
11
  export function set_assets(path) {
29
- assets = initial.assets = path;
12
+ assets = path;
30
13
  }
@@ -0,0 +1,3 @@
1
+ import '../../../types/global-private.js';
2
+
3
+ export * from './client.js';
@@ -1,29 +1 @@
1
- import { RouteIdWithSearchOrHash, PathnameWithSearchOrHash, ResolvedPathname } from '$app/types';
2
- import { ResolveArgs } from './types.js';
3
-
4
- export { resolve, asset, match } 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 RouteIdWithSearchOrHash | PathnameWithSearchOrHash>(
28
- ...args: ResolveArgs<T>
29
- ): ResolvedPathname;
1
+ export { asset, resolve, match } from './client.js';
@@ -1,32 +1,53 @@
1
- import { base, assets, relative, initial_base } from './internal/server.js';
1
+ import { base, assets, relative } from './internal/server.js';
2
2
  import { resolve_route, find_route } from '../../../utils/routing.js';
3
3
  import { decode_pathname } from '../../../utils/url.js';
4
+ import { add_data_suffix } from '../../../pathname.js';
4
5
  import { try_get_request_store } from '@sveltejs/kit/internal/server';
5
- import { manifest } from '__sveltekit/server';
6
+ import { manifest } from '../../server/internal.js';
6
7
  import { get_hooks } from '__SERVER__/internal.js';
8
+ import { DEV } from 'esm-env';
7
9
 
8
- /** @type {import('./client.js').asset} */
10
+ export { base, assets, app_dir } from './internal/server.js';
11
+
12
+ /** @type {typeof import('./client.js').asset} */
9
13
  export function asset(file) {
10
- // @ts-expect-error we use the `resolve` mechanism, but with the 'wrong' input
11
- return assets && assets !== base ? assets + file : resolve(file);
14
+ // TODO 4.0 remove this
15
+ if (file[0] === '/') {
16
+ if (DEV) {
17
+ console.warn(`\`asset('${file}')\` should now be \`asset('${file.slice(1)}')\``);
18
+ }
19
+
20
+ file = file.slice(1);
21
+ }
22
+
23
+ return assets !== base ? `${assets}/${file}` : resolve(file);
12
24
  }
13
25
 
14
- /** @type {import('./client.js').resolve} */
26
+ /** @type {typeof import('./client.js').resolve} */
15
27
  export function resolve(id, params) {
16
- if (!id.startsWith('/')) {
17
- throw new Error(
18
- `Cannot use \`resolve(...)\` with a non-absolute pathname or route ID (got "${id}"). ` +
19
- '`resolve` is only for internal pathnames and route IDs; external URLs should be used directly.'
20
- );
21
- }
28
+ let resolved;
22
29
 
23
- const resolved = resolve_route(id, /** @type {Record<string, string>} */ (params));
30
+ if (id[0] === '/') {
31
+ // route ID
32
+ if (id.includes('[') && !params) {
33
+ throw new Error(`Missing params for dynamic route ID ${id}`);
34
+ }
35
+
36
+ resolved = resolve_route(id, params ?? {});
37
+ } else {
38
+ resolved = '/' + id;
39
+ }
24
40
 
25
41
  if (relative) {
26
42
  const store = try_get_request_store();
27
43
 
28
44
  if (store && !store.state.prerendering?.fallback) {
29
- const after_base = store.event.url.pathname.slice(initial_base.length);
45
+ // the relative path depth must reflect the URL the browser is actually at, which
46
+ // for a data request includes the `__data.json` suffix that was stripped during routing
47
+ const pathname = store.event.isDataRequest
48
+ ? add_data_suffix(store.event.url.pathname)
49
+ : store.event.url.pathname;
50
+ const after_base = pathname.slice(base.length);
30
51
  const segments = after_base.split('/').slice(2);
31
52
  const prefix = segments.map(() => '..').join('/') || '.';
32
53
 
@@ -37,7 +58,7 @@ export function resolve(id, params) {
37
58
  return base + resolved;
38
59
  }
39
60
 
40
- /** @type {import('./client.js').match} */
61
+ /** @type {typeof import('./client.js').match} */
41
62
  export async function match(url) {
42
63
  const store = try_get_request_store();
43
64
 
@@ -74,5 +95,3 @@ export async function match(url) {
74
95
 
75
96
  return null;
76
97
  }
77
-
78
- export { base, assets, resolve as resolveRoute };
@@ -1,23 +1,15 @@
1
- import {
2
- PathnameWithSearchOrHash,
3
- RouteId,
4
- RouteIdWithSearchOrHash,
5
- RouteParams
6
- } from '$app/types';
1
+ import { RouteId, RouteParams } from '$app/types';
7
2
 
8
- type StripSearchOrHash<T extends string> = T extends `${infer Pathname}?${string}`
9
- ? Pathname
10
- : T extends `${infer Pathname}#${string}`
11
- ? Pathname
3
+ type StripSearchOrHash<T extends string> = T extends `${infer U}?${string}`
4
+ ? U
5
+ : T extends `${infer U}#${string}`
6
+ ? U
12
7
  : T;
13
8
 
14
- export type ResolveArgs<T extends RouteIdWithSearchOrHash | PathnameWithSearchOrHash> =
15
- T extends RouteId
16
- ? RouteParams<T> extends Record<string, never>
9
+ export type ResolveArgs<T> = T extends `/${string}`
10
+ ? StripSearchOrHash<T> extends infer U extends RouteId
11
+ ? RouteParams<U> extends Record<string, never>
17
12
  ? [route: T]
18
- : [route: T, params: RouteParams<T>]
19
- : StripSearchOrHash<T> extends infer U extends RouteId
20
- ? RouteParams<U> extends Record<string, never>
21
- ? [route: T]
22
- : [route: T, params: RouteParams<U>]
23
- : [route: T];
13
+ : [route: T, params: RouteParams<U>]
14
+ : [never]
15
+ : [pathname: T];
@@ -1,5 +1,5 @@
1
- import { read_implementation, manifest } from '__sveltekit/server';
2
- import { assets } from '$app/paths/internal/server';
1
+ import { read_implementation, manifest } from '../../server/internal.js';
2
+ import { assets } from '#app/paths';
3
3
  import { base64_decode } from '../../utils.js';
4
4
 
5
5
  /**