@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.
- package/package.json +62 -36
- package/src/cli.js +15 -12
- package/src/constants.js +6 -1
- package/src/core/adapt/builder.js +66 -72
- package/src/core/adapt/index.js +17 -6
- package/src/core/config/index.js +134 -80
- package/src/core/config/options.js +295 -273
- package/src/core/config/types.d.ts +1 -1
- package/src/core/env.js +146 -16
- package/src/core/generate_manifest/index.js +18 -15
- package/src/core/postbuild/analyse.js +8 -20
- package/src/core/postbuild/crawl.js +22 -6
- package/src/core/postbuild/entities.js +8 -2
- package/src/core/postbuild/fallback.js +4 -2
- package/src/core/postbuild/prerender.js +222 -70
- package/src/core/postbuild/queue.js +2 -1
- package/src/core/sync/create_manifest_data/conflict.js +1 -1
- package/src/core/sync/create_manifest_data/index.js +82 -62
- package/src/core/sync/sync.js +40 -31
- package/src/core/sync/ts.js +1 -1
- package/src/core/sync/utils.js +22 -2
- package/src/core/sync/{write_non_ambient.js → write_app_types.js} +107 -58
- package/src/core/sync/write_client_manifest.js +14 -29
- package/src/core/sync/write_env.js +7 -5
- package/src/core/sync/write_server.js +37 -45
- package/src/core/sync/write_tsconfig/index.js +274 -0
- package/src/core/sync/write_tsconfig/test-app/package.json +7 -0
- package/src/core/sync/write_tsconfig/utils.js +77 -0
- package/src/core/sync/write_tsconfig/validate.js +128 -0
- package/src/core/sync/write_types/index.js +127 -123
- package/src/core/utils.js +30 -5
- package/src/exports/env/index.js +77 -0
- package/src/exports/env/public.d.ts +55 -0
- package/src/exports/hooks/index.js +3 -9
- package/src/exports/hooks/public.d.ts +195 -0
- package/src/exports/hooks/sequence.js +9 -6
- package/src/exports/index.js +52 -29
- package/src/exports/internal/client.js +5 -0
- package/src/exports/internal/env.js +8 -5
- package/src/exports/internal/index.js +1 -90
- package/src/exports/internal/{event.js → server/event.js} +2 -3
- package/src/exports/internal/server/index.js +37 -0
- package/src/exports/internal/server/telemetry.js +95 -0
- package/src/exports/internal/shared.js +90 -0
- package/src/exports/node/index.js +64 -22
- package/src/exports/params/index.js +70 -0
- package/src/exports/params/public.d.ts +63 -0
- package/src/exports/public.d.ts +50 -1733
- package/src/exports/remote/index.js +11 -0
- package/src/exports/remote/public.d.ts +519 -0
- package/src/exports/url.js +86 -0
- package/src/exports/vite/build/build_server.js +54 -65
- package/src/exports/vite/build/remote.js +24 -19
- package/src/exports/vite/build/utils.js +0 -8
- package/src/exports/vite/dev/index.js +218 -146
- package/src/exports/vite/index.js +1590 -858
- package/src/exports/vite/module_ids.js +2 -2
- package/src/exports/vite/preview/index.js +40 -32
- package/src/exports/vite/public.d.ts +588 -0
- package/src/exports/vite/utils.js +84 -46
- package/src/pathname.js +55 -0
- package/src/runner.js +15 -0
- package/src/runtime/app/env/internal.js +4 -4
- package/src/runtime/app/env/types.d.ts +1 -1
- package/src/runtime/app/environment/index.js +3 -3
- package/src/runtime/app/{forms.js → forms/index.js} +73 -42
- package/src/runtime/app/forms/public.d.ts +2 -0
- package/src/runtime/app/forms/types.d.ts +56 -0
- package/src/runtime/app/internal/transport.js +53 -0
- package/src/runtime/app/manifest/index.js +1 -0
- package/src/runtime/app/{navigation.js → navigation/index.js} +2 -1
- package/src/runtime/app/navigation/public.d.ts +237 -0
- package/src/runtime/app/paths/client.js +37 -37
- package/src/runtime/app/paths/index.js +1 -1
- package/src/runtime/app/paths/internal/client.js +34 -2
- package/src/runtime/app/paths/internal/server.js +6 -23
- package/src/runtime/app/paths/internal.d.ts +3 -0
- package/src/runtime/app/paths/public.d.ts +1 -29
- package/src/runtime/app/paths/server.js +36 -17
- package/src/runtime/app/paths/types.d.ts +11 -19
- package/src/runtime/app/server/index.js +2 -2
- package/src/runtime/app/server/public.d.ts +201 -0
- package/src/runtime/app/server/remote/command.js +13 -11
- package/src/runtime/app/server/remote/form.js +61 -39
- package/src/runtime/app/server/remote/prerender.js +45 -45
- package/src/runtime/app/server/remote/query.js +106 -108
- package/src/runtime/app/server/remote/requested.js +27 -19
- package/src/runtime/app/server/remote/shared.js +76 -76
- package/src/runtime/app/service-worker/index.js +24 -0
- package/src/runtime/app/state/client.js +4 -2
- package/src/runtime/app/state/index.js +7 -5
- package/src/runtime/app/state/public.d.ts +72 -0
- package/src/runtime/app/state/server.js +3 -0
- package/src/runtime/app/stores.js +15 -78
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client-entry.js +3 -0
- package/src/runtime/client/client.js +1336 -648
- package/src/runtime/client/constants.js +3 -6
- package/src/runtime/client/entry.js +24 -3
- package/src/runtime/client/fetcher.js +25 -25
- package/src/runtime/client/ndjson.js +1 -1
- package/src/runtime/client/parse.js +1 -1
- package/src/runtime/client/payload.js +17 -0
- package/src/runtime/client/remote-functions/cache.svelte.js +3 -1
- package/src/runtime/client/remote-functions/command.svelte.js +37 -61
- package/src/runtime/client/remote-functions/form.svelte.js +267 -178
- package/src/runtime/client/remote-functions/prerender.svelte.js +32 -11
- package/src/runtime/client/remote-functions/query/index.js +10 -17
- package/src/runtime/client/remote-functions/query/instance.svelte.js +64 -18
- package/src/runtime/client/remote-functions/query/proxy.js +5 -5
- package/src/runtime/client/remote-functions/query-batch.svelte.js +61 -70
- package/src/runtime/client/remote-functions/query-live/index.js +1 -1
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +63 -21
- package/src/runtime/client/remote-functions/query-live/iterator.js +15 -12
- package/src/runtime/client/remote-functions/query-live/proxy.js +2 -12
- package/src/runtime/client/remote-functions/shared.svelte.js +90 -65
- package/src/runtime/client/snapshots.js +147 -0
- package/src/runtime/client/state.svelte.js +94 -55
- package/src/runtime/client/stream.js +3 -2
- package/src/runtime/client/types.d.ts +13 -9
- package/src/runtime/client/utils.js +22 -110
- package/src/runtime/components/root.svelte +56 -0
- package/src/runtime/env/dynamic/private.js +7 -0
- package/src/runtime/env/dynamic/public.js +7 -0
- package/src/runtime/env/static/private.js +6 -0
- package/src/runtime/env/static/public.js +6 -0
- package/src/runtime/form-utils.js +172 -61
- package/src/runtime/pathname.js +20 -32
- package/src/runtime/props.svelte.js +72 -0
- package/src/runtime/server/constants.js +0 -3
- package/src/runtime/server/cookie.js +72 -55
- package/src/runtime/server/csrf.js +65 -0
- package/src/runtime/server/data/index.js +49 -53
- package/src/runtime/server/dev.js +22 -0
- package/src/runtime/server/endpoint.js +6 -7
- package/src/runtime/server/env_module.js +0 -5
- package/src/runtime/server/errors.js +160 -0
- package/src/runtime/server/fetch.js +32 -39
- package/src/runtime/server/index.js +90 -64
- package/src/runtime/server/internal.js +71 -0
- package/src/runtime/server/page/actions.js +85 -64
- package/src/runtime/server/page/crypto.js +2 -2
- package/src/runtime/server/page/csp.js +88 -104
- package/src/runtime/server/page/data_serializer.js +24 -25
- package/src/runtime/server/page/index.js +36 -53
- package/src/runtime/server/page/load_data.js +50 -57
- package/src/runtime/server/page/render.js +173 -239
- package/src/runtime/server/page/respond_with_error.js +17 -31
- package/src/runtime/server/page/serialize_data.js +2 -13
- package/src/runtime/server/page/server_routing.js +85 -26
- package/src/runtime/server/remote-functions.js +640 -0
- package/src/runtime/server/respond.js +190 -131
- package/src/runtime/server/sourcemaps.js +183 -0
- package/src/runtime/server/state.js +53 -0
- package/src/runtime/server/utils.js +13 -155
- package/src/runtime/shared.js +20 -40
- package/src/runtime/utils.js +3 -0
- package/src/types/ambient-private.d.ts +11 -1
- package/src/types/ambient.d.ts +87 -36
- package/src/types/global-private.d.ts +25 -25
- package/src/types/internal.d.ts +163 -157
- package/src/types/private.d.ts +41 -1
- package/src/utils/error.js +28 -4
- package/src/utils/escape.js +9 -25
- package/src/utils/features.js +1 -1
- package/src/utils/filesystem.js +1 -23
- package/src/utils/fork.js +7 -2
- package/src/utils/hash.js +21 -0
- package/src/utils/http.js +8 -7
- package/src/utils/import.js +9 -2
- package/src/utils/imports.js +83 -0
- package/src/utils/mime.js +9 -0
- package/src/utils/page_nodes.js +6 -7
- package/src/utils/params.js +67 -0
- package/src/utils/regex.js +9 -0
- package/src/utils/routing.js +145 -73
- package/src/utils/shared-iterator.js +5 -0
- package/src/utils/streaming.js +14 -4
- package/src/utils/url.js +33 -2
- package/src/version.js +1 -1
- package/types/index.d.ts +2616 -2433
- package/types/index.d.ts.map +120 -106
- package/src/core/sync/write_ambient.js +0 -18
- package/src/core/sync/write_root.js +0 -148
- package/src/core/sync/write_tsconfig.js +0 -250
- package/src/exports/internal/server.js +0 -22
- package/src/exports/node/polyfills.js +0 -30
- package/src/runtime/server/app.js +0 -9
- package/src/runtime/server/remote.js +0 -457
- package/src/runtime/shared-server.js +0 -7
- package/src/runtime/telemetry/otel.js +0 -21
- package/src/runtime/telemetry/record_span.js +0 -65
- package/src/types/synthetic/$lib.md +0 -5
- /package/src/exports/internal/{remote-functions.js → server/remote-functions.js} +0 -0
- /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 {
|
|
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 {
|
|
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.
|
|
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('
|
|
20
|
+
* <img alt="a potato" src={asset('potato.jpg')} />
|
|
19
21
|
* ```
|
|
20
22
|
* @since 2.26
|
|
21
23
|
*
|
|
22
|
-
* @param {
|
|
24
|
+
* @param {AssetPath} file
|
|
23
25
|
* @returns {string}
|
|
24
26
|
*/
|
|
25
27
|
export function asset(file) {
|
|
26
|
-
|
|
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(
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
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('
|
|
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 {
|
|
87
|
-
* @returns {Promise<{ id:
|
|
101
|
+
* @param {URL | string} url
|
|
102
|
+
* @returns {Promise<{ [K in RouteId]: { id: K; params: RouteParams<K>; } }[RouteId] | null>}
|
|
88
103
|
*/
|
|
89
|
-
export
|
|
90
|
-
|
|
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
|
|
1
|
+
export { asset, resolve, match } from '#app/paths';
|
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
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 =
|
|
12
|
+
assets = path;
|
|
30
13
|
}
|
|
@@ -1,29 +1 @@
|
|
|
1
|
-
|
|
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
|
|
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 '
|
|
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
|
-
|
|
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
|
-
//
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
9
|
-
?
|
|
10
|
-
: T extends `${infer
|
|
11
|
-
?
|
|
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
|
|
15
|
-
T extends RouteId
|
|
16
|
-
? RouteParams<
|
|
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<
|
|
19
|
-
:
|
|
20
|
-
|
|
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 '
|
|
2
|
-
import { assets } from '
|
|
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
|
/**
|