@sveltejs/kit 3.0.0-next.7 → 3.0.0-next.8
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 +2 -2
- package/src/core/config/options.js +1 -1
- package/src/core/env.js +1 -0
- package/src/core/sync/create_manifest_data/index.js +1 -1
- package/src/core/sync/sync.js +0 -2
- package/src/core/sync/write_client_manifest.js +0 -7
- package/src/core/sync/write_non_ambient.js +2 -2
- package/src/core/sync/write_server.js +0 -3
- package/src/core/sync/write_types/index.js +17 -14
- package/src/core/utils.js +2 -2
- package/src/exports/node/index.js +4 -8
- package/src/exports/public.d.ts +21 -14
- package/src/exports/vite/dev/index.js +3 -3
- package/src/exports/vite/index.js +64 -44
- package/src/exports/vite/preview/index.js +13 -14
- package/src/exports/vite/utils.js +5 -5
- package/src/runtime/app/env/internal.js +4 -4
- package/src/runtime/app/forms.js +2 -2
- package/src/runtime/app/paths/internal/client.js +4 -2
- package/src/runtime/app/paths/internal/server.js +2 -23
- package/src/runtime/app/paths/server.js +2 -2
- package/src/runtime/client/bundle.js +1 -1
- package/src/runtime/client/client-entry.js +3 -0
- package/src/runtime/client/client.js +216 -171
- package/src/runtime/client/entry.js +24 -3
- package/src/runtime/client/payload.js +17 -0
- package/src/runtime/client/remote-functions/form.svelte.js +6 -6
- package/src/runtime/client/types.d.ts +2 -6
- package/src/runtime/components/root.svelte +66 -0
- package/src/runtime/form-utils.js +1 -4
- package/src/runtime/server/cookie.js +17 -7
- package/src/runtime/server/page/index.js +7 -14
- package/src/runtime/server/page/render.js +71 -78
- package/src/runtime/server/remote.js +2 -1
- package/src/runtime/server/utils.js +28 -5
- package/src/runtime/types.d.ts +8 -0
- package/src/types/global-private.d.ts +10 -17
- package/src/types/internal.d.ts +21 -25
- package/src/utils/import.js +6 -1
- package/src/utils/routing.js +6 -6
- package/src/version.js +1 -1
- package/types/index.d.ts +34 -43
- package/types/index.d.ts.map +3 -2
- package/src/core/sync/write_root.js +0 -127
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.8",
|
|
4
4
|
"description": "SvelteKit is the fastest way to build Svelte apps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"framework",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@opentelemetry/api": "^1.0.0",
|
|
49
49
|
"@sveltejs/vite-plugin-svelte": "^7.0.0",
|
|
50
|
-
"svelte": "^5.
|
|
50
|
+
"svelte": "^5.56.4",
|
|
51
51
|
"typescript": "^6.0.0",
|
|
52
52
|
"vite": "^8.0.12"
|
|
53
53
|
},
|
package/src/core/env.js
CHANGED
|
@@ -38,6 +38,7 @@ export async function load_explicit_env(kit, file, root, mode) {
|
|
|
38
38
|
logLevel: 'silent',
|
|
39
39
|
mode,
|
|
40
40
|
define: {
|
|
41
|
+
__SVELTEKIT_PAYLOAD__: 'undefined', // coming in through static import in env/internal.js but will end up unused
|
|
41
42
|
__SVELTEKIT_APP_VERSION__: JSON.stringify(kit.version.name) // needed by $app/env
|
|
42
43
|
},
|
|
43
44
|
resolve: {
|
|
@@ -142,7 +142,7 @@ function create_routes_and_nodes(cwd, config, fallback) {
|
|
|
142
142
|
throw new Error(`Route ${id} should be renamed to ${id.replace(/#/g, '[x+23]')}`);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
if (/\[
|
|
145
|
+
if (/\[\.\.\.[\w-]+\]\/\[\[/.test(id)) {
|
|
146
146
|
throw new Error(
|
|
147
147
|
`Invalid route ${id} — an [[optional]] route segment cannot follow a [...rest] route segment`
|
|
148
148
|
);
|
package/src/core/sync/sync.js
CHANGED
|
@@ -2,7 +2,6 @@ import path from 'node:path';
|
|
|
2
2
|
import process from 'node:process';
|
|
3
3
|
import create_manifest_data from './create_manifest_data/index.js';
|
|
4
4
|
import { write_client_manifest } from './write_client_manifest.js';
|
|
5
|
-
import { write_root } from './write_root.js';
|
|
6
5
|
import { write_tsconfig } from './write_tsconfig.js';
|
|
7
6
|
import { write_types, write_all_types } from './write_types/index.js';
|
|
8
7
|
import { write_ambient } from './write_ambient.js';
|
|
@@ -37,7 +36,6 @@ export function create(config, root) {
|
|
|
37
36
|
|
|
38
37
|
write_client_manifest(config.kit, manifest_data, `${output}/client`);
|
|
39
38
|
write_server(config, output, root);
|
|
40
|
-
write_root(manifest_data, config, output);
|
|
41
39
|
write_all_types(config, manifest_data, root);
|
|
42
40
|
write_non_ambient(config.kit, manifest_data);
|
|
43
41
|
|
|
@@ -139,11 +139,6 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
|
|
|
139
139
|
write_if_changed(
|
|
140
140
|
`${output}/app.js`,
|
|
141
141
|
dedent`
|
|
142
|
-
// in dev, this makes Vite inject its client as this module's first dependency,
|
|
143
|
-
// so that global constant replacements are installed before any other module
|
|
144
|
-
// (including user hooks) evaluates. In build it's inert.
|
|
145
|
-
import.meta.hot;
|
|
146
|
-
|
|
147
142
|
${
|
|
148
143
|
client_hooks_file
|
|
149
144
|
? `import * as client_hooks from '${relative_path(output, client_hooks_file)}';`
|
|
@@ -181,8 +176,6 @@ export function write_client_manifest(kit, manifest_data, output, metadata) {
|
|
|
181
176
|
|
|
182
177
|
export const decode = (type, value) => decoders[type](value);
|
|
183
178
|
|
|
184
|
-
export { default as root } from '../root.js';
|
|
185
|
-
|
|
186
179
|
export const get_error_template = () => import('../shared/error-template.js').then(m => m.default);
|
|
187
180
|
`
|
|
188
181
|
);
|
|
@@ -209,7 +209,7 @@ function generate_app_types(manifest_data, config) {
|
|
|
209
209
|
if (route.params.length > 0) {
|
|
210
210
|
const params = route.params.map((p) => {
|
|
211
211
|
const type = get_matcher_type(p.matcher);
|
|
212
|
-
return `${p.name}${p.optional ? '?:' : ':'} ${type}${p.optional ? ' | undefined' : ''}`;
|
|
212
|
+
return `${/^\w+$/.test(p.name) ? p.name : `'${p.name}'`}${p.optional ? '?:' : ':'} ${type}${p.optional ? ' | undefined' : ''}`;
|
|
213
213
|
});
|
|
214
214
|
const route_type = `${s(route.id)}: { ${params.join('; ')} }`;
|
|
215
215
|
|
|
@@ -230,7 +230,7 @@ function generate_app_types(manifest_data, config) {
|
|
|
230
230
|
const params = Array.from(layout_params)
|
|
231
231
|
.map(([name, { optional, matchers }]) => {
|
|
232
232
|
const type = get_matchers_type(matchers);
|
|
233
|
-
return `${name}${optional ? '?:' : ':'} ${type}${optional ? ' | undefined' : ''}`;
|
|
233
|
+
return `${/^\w+$/.test(name) ? name : `'${name}'`}${optional ? '?:' : ':'} ${type}${optional ? ' | undefined' : ''}`;
|
|
234
234
|
})
|
|
235
235
|
.join('; ');
|
|
236
236
|
|
|
@@ -24,7 +24,6 @@ const server_template = ({
|
|
|
24
24
|
has_service_worker,
|
|
25
25
|
template
|
|
26
26
|
}) => `
|
|
27
|
-
import root from '../root.js';
|
|
28
27
|
import { set_building, set_prerendering } from '$app/env/internal';
|
|
29
28
|
import { set_assets } from '$app/paths/internal/server';
|
|
30
29
|
import { set_manifest, set_read_implementation } from '__sveltekit/server';
|
|
@@ -40,10 +39,8 @@ export const options = {
|
|
|
40
39
|
hooks: null, // added lazily, via \`get_hooks\`
|
|
41
40
|
link_header_preload: ${s(config.kit.output.linkHeaderPreload)},
|
|
42
41
|
paths_origin: ${s(config.kit.paths.origin)},
|
|
43
|
-
root,
|
|
44
42
|
service_worker: ${has_service_worker},
|
|
45
43
|
service_worker_options: ${config.kit.serviceWorker.register ? s(config.kit.serviceWorker.options) : 'null'},
|
|
46
|
-
server_error_boundaries: ${s(!!config.kit.experimental.handleRenderingErrors)},
|
|
47
44
|
templates: {
|
|
48
45
|
app: ({ head, body, assets, nonce, env }) => ${s(template)
|
|
49
46
|
.replace('%sveltekit.head%', '" + head + "')
|
|
@@ -231,7 +231,9 @@ function update_types(config, routes, route, root, to_delete = new Set()) {
|
|
|
231
231
|
'type OptionalUnion<U extends Record<string, any>, A extends keyof U = U extends U ? keyof U : never> = U extends unknown ? { [P in Exclude<A, keyof U>]?: never } & U : never;',
|
|
232
232
|
|
|
233
233
|
// Re-export `Snapshot` from @sveltejs/kit — in future we could use this to infer <T> from the return type of `snapshot.capture`
|
|
234
|
-
'export type Snapshot<T = any> = Kit.Snapshot<T>;'
|
|
234
|
+
'export type Snapshot<T = any> = Kit.Snapshot<T>;',
|
|
235
|
+
|
|
236
|
+
'export type ErrorProps = { error: App.Error };'
|
|
235
237
|
);
|
|
236
238
|
}
|
|
237
239
|
|
|
@@ -263,15 +265,8 @@ function update_types(config, routes, route, root, to_delete = new Set()) {
|
|
|
263
265
|
|
|
264
266
|
if (route.leaf.server) {
|
|
265
267
|
exports.push(
|
|
266
|
-
'export type Action<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Action<RouteParams, OutputData, RouteId>'
|
|
267
|
-
|
|
268
|
-
exports.push(
|
|
269
|
-
'export type Actions<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Actions<RouteParams, OutputData, RouteId>'
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
if (route.leaf.server) {
|
|
274
|
-
exports.push(
|
|
268
|
+
'export type Action<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Action<RouteParams, OutputData, RouteId>',
|
|
269
|
+
'export type Actions<OutputData extends Record<string, any> | void = Record<string, any> | void> = Kit.Actions<RouteParams, OutputData, RouteId>',
|
|
275
270
|
'export type PageProps = { params: RouteParams; data: PageData; form: ActionData }'
|
|
276
271
|
);
|
|
277
272
|
} else {
|
|
@@ -612,7 +607,7 @@ function generate_params_type(params, outdir, config) {
|
|
|
612
607
|
return `{ ${params
|
|
613
608
|
.map(
|
|
614
609
|
(param) =>
|
|
615
|
-
`${param.name}${param.optional ? '?' : ''}: ${
|
|
610
|
+
`${/^\w+$/.test(param.name) ? param.name : `'${param.name}'`}${param.optional ? '?' : ''}: ${
|
|
616
611
|
param.matcher
|
|
617
612
|
? `import('@sveltejs/kit').MatcherParam<(typeof import('${params_import}').params)[${JSON.stringify(param.matcher)}]>`
|
|
618
613
|
: 'string'
|
|
@@ -643,6 +638,16 @@ export function tweak_types(content, is_server) {
|
|
|
643
638
|
const code = new MagicString(content);
|
|
644
639
|
|
|
645
640
|
const exports = new Map();
|
|
641
|
+
/** @param {import('typescript').BindingName} name */
|
|
642
|
+
function add_export(name) {
|
|
643
|
+
if (ts.isIdentifier(name)) {
|
|
644
|
+
if (names.has(name.text)) exports.set(name.text, name.text);
|
|
645
|
+
} else {
|
|
646
|
+
for (const element of name.elements) {
|
|
647
|
+
if (ts.isBindingElement(element)) add_export(element.name);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
}
|
|
646
651
|
|
|
647
652
|
ast.forEachChild((node) => {
|
|
648
653
|
if (
|
|
@@ -669,9 +674,7 @@ export function tweak_types(content, is_server) {
|
|
|
669
674
|
|
|
670
675
|
if (ts.isVariableStatement(node)) {
|
|
671
676
|
node.declarationList.declarations.forEach((declaration) => {
|
|
672
|
-
|
|
673
|
-
exports.set(declaration.name.text, declaration.name.text);
|
|
674
|
-
}
|
|
677
|
+
add_export(declaration.name);
|
|
675
678
|
});
|
|
676
679
|
}
|
|
677
680
|
}
|
package/src/core/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ import { noop } from '../utils/functions.js';
|
|
|
7
7
|
import { posixify } from '../utils/os.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* Resolved path of the `runtime` directory
|
|
10
|
+
* Resolved path of the `runtime` directory posix-ified
|
|
11
11
|
*
|
|
12
12
|
* TODO Windows issue:
|
|
13
13
|
* Vite or sth else somehow sets the driver letter inconsistently to lower or upper case depending on the run environment.
|
|
@@ -25,7 +25,7 @@ export const runtime_directory = posixify(fileURLToPath(new URL('../runtime', im
|
|
|
25
25
|
*/
|
|
26
26
|
export function get_runtime_base(root) {
|
|
27
27
|
return runtime_directory.startsWith(root)
|
|
28
|
-
? `/${path.relative(root, runtime_directory)}`
|
|
28
|
+
? `/${posixify(path.relative(root, runtime_directory))}`
|
|
29
29
|
: to_fs(runtime_directory);
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -119,11 +119,9 @@ function get_raw_body(req, body_size_limit) {
|
|
|
119
119
|
* base: string;
|
|
120
120
|
* bodySizeLimit?: number;
|
|
121
121
|
* }} options
|
|
122
|
-
* @returns {
|
|
122
|
+
* @returns {Request}
|
|
123
123
|
*/
|
|
124
|
-
|
|
125
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
126
|
-
export async function getRequest({ request, base, bodySizeLimit }) {
|
|
124
|
+
export function getRequest({ request, base, bodySizeLimit }) {
|
|
127
125
|
let headers = /** @type {Record<string, string>} */ (request.headers);
|
|
128
126
|
if (request.httpVersionMajor >= 2) {
|
|
129
127
|
// the Request constructor rejects headers with ':' in the name
|
|
@@ -205,11 +203,9 @@ function drain_request(res) {
|
|
|
205
203
|
/**
|
|
206
204
|
* @param {import('http').ServerResponse} res
|
|
207
205
|
* @param {Response} response
|
|
208
|
-
* @returns {
|
|
206
|
+
* @returns {void}
|
|
209
207
|
*/
|
|
210
|
-
|
|
211
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
212
|
-
export async function setResponse(res, response) {
|
|
208
|
+
export function setResponse(res, response) {
|
|
213
209
|
res.once('finish', () => drain_request(res));
|
|
214
210
|
res.once('close', () => drain_request(res));
|
|
215
211
|
|
package/src/exports/public.d.ts
CHANGED
|
@@ -157,7 +157,8 @@ export interface Builder {
|
|
|
157
157
|
|
|
158
158
|
/**
|
|
159
159
|
* Generate a server-side manifest to initialise the SvelteKit [server](https://svelte.dev/docs/kit/@sveltejs-kit#Server) with.
|
|
160
|
-
* @param opts
|
|
160
|
+
* @param opts
|
|
161
|
+
* @param opts.relativePath A relative path to the base directory of the server build output
|
|
161
162
|
*/
|
|
162
163
|
generateManifest: (opts: { relativePath: string; routes?: RouteDefinition[] }) => string;
|
|
163
164
|
|
|
@@ -509,15 +510,6 @@ export interface KitConfig {
|
|
|
509
510
|
* @default false
|
|
510
511
|
*/
|
|
511
512
|
forkPreloads?: boolean;
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* Whether to enable the experimental handling of rendering errors.
|
|
515
|
-
* When enabled, `<svelte:boundary>` is used to wrap components at each level
|
|
516
|
-
* where there's an `+error.svelte`, rendering the error page if the component fails.
|
|
517
|
-
* In addition, error boundaries also work on the server and the error object goes through `handleError`.
|
|
518
|
-
* @default false
|
|
519
|
-
*/
|
|
520
|
-
handleRenderingErrors?: boolean;
|
|
521
513
|
};
|
|
522
514
|
/**
|
|
523
515
|
* Where to find various files within your project.
|
|
@@ -1439,7 +1431,7 @@ export interface Page<
|
|
|
1439
1431
|
/**
|
|
1440
1432
|
* The URL of the current page.
|
|
1441
1433
|
*/
|
|
1442
|
-
url:
|
|
1434
|
+
url: ReadonlyURL & { readonly pathname: ResolvedPathname | (string & {}) };
|
|
1443
1435
|
/**
|
|
1444
1436
|
* The parameters of the current page - e.g. for a route like `/blog/[slug]`, a `{ slug: string }` object.
|
|
1445
1437
|
*/
|
|
@@ -1742,7 +1734,9 @@ export interface ResolveOptions {
|
|
|
1742
1734
|
*/
|
|
1743
1735
|
filterSerializedResponseHeaders?: (name: string, value: string) => boolean;
|
|
1744
1736
|
/**
|
|
1745
|
-
* Determines
|
|
1737
|
+
* Determines which files should be preloaded. Files are preloaded via `<link>` tags added to the
|
|
1738
|
+
* `<head>` tag; if `output.linkHeaderPreload` is enabled, dynamically rendered pages use the
|
|
1739
|
+
* [`Link` response header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link) instead.
|
|
1746
1740
|
* By default, `js` and `css` files will be preloaded.
|
|
1747
1741
|
* @param input the type of the file and its path
|
|
1748
1742
|
*/
|
|
@@ -1777,19 +1771,24 @@ export interface ServerInitOptions {
|
|
|
1777
1771
|
read?: (file: string) => MaybePromise<ReadableStream | null>;
|
|
1778
1772
|
}
|
|
1779
1773
|
|
|
1774
|
+
/**
|
|
1775
|
+
* Information required to instantiate a new `Server` instance.
|
|
1776
|
+
*/
|
|
1780
1777
|
export interface SSRManifest {
|
|
1778
|
+
/** The directory where SvelteKit keeps its stuff, including static assets (such as JS and CSS) and internally-used routes. */
|
|
1781
1779
|
appDir: string;
|
|
1780
|
+
/** The `base` and `appDir` settings combined without a leading slash. */
|
|
1782
1781
|
appPath: string;
|
|
1783
1782
|
/** Static files from `config.files.assets` and the service worker (if any). */
|
|
1784
1783
|
assets: Set<string>;
|
|
1785
1784
|
mimeTypes: Record<string, string>;
|
|
1786
1785
|
|
|
1787
|
-
/** private fields */
|
|
1786
|
+
/** @internal private fields */
|
|
1788
1787
|
_: {
|
|
1789
1788
|
client: BuildData['client'];
|
|
1790
1789
|
nodes: SSRNodeLoader[];
|
|
1791
1790
|
/** hashed filename -> import to that file */
|
|
1792
|
-
remotes: Record<string, () => Promise<any>>;
|
|
1791
|
+
remotes: Record<string, () => Promise<{ default: Record<string, any> }>>;
|
|
1793
1792
|
routes: SSRRoute[];
|
|
1794
1793
|
prerendered_routes: Set<string>;
|
|
1795
1794
|
matchers: () => Promise<Record<string, ParamMatcher>>;
|
|
@@ -1980,6 +1979,14 @@ export interface Snapshot<T = any> {
|
|
|
1980
1979
|
restore: (snapshot: T) => void;
|
|
1981
1980
|
}
|
|
1982
1981
|
|
|
1982
|
+
export type ReadonlyURLSearchParams = Omit<URLSearchParams, 'set' | 'append' | 'delete' | 'sort'>;
|
|
1983
|
+
|
|
1984
|
+
export type ReadonlyURL = Readonly<
|
|
1985
|
+
Omit<URL, 'searchParams'> & {
|
|
1986
|
+
searchParams: ReadonlyURLSearchParams;
|
|
1987
|
+
}
|
|
1988
|
+
>;
|
|
1989
|
+
|
|
1983
1990
|
// If T is unknown or has an index signature, the types below will recurse indefinitely and create giant unions that TS can't handle
|
|
1984
1991
|
type WillRecurseIndefinitely<T> = unknown extends T ? true : string extends keyof T ? true : false;
|
|
1985
1992
|
|
|
@@ -528,7 +528,7 @@ export async function dev(vite, vite_config, svelte_config, get_remotes, root) {
|
|
|
528
528
|
read: (file) => createReadableStream(from_fs(file))
|
|
529
529
|
});
|
|
530
530
|
|
|
531
|
-
const request =
|
|
531
|
+
const request = getRequest({
|
|
532
532
|
base,
|
|
533
533
|
request: req
|
|
534
534
|
});
|
|
@@ -579,10 +579,10 @@ export async function dev(vite, vite_config, svelte_config, get_remotes, root) {
|
|
|
579
579
|
if (rendered.status === 404) {
|
|
580
580
|
// @ts-expect-error
|
|
581
581
|
serve_static_middleware.handle(req, res, () => {
|
|
582
|
-
|
|
582
|
+
setResponse(res, rendered);
|
|
583
583
|
});
|
|
584
584
|
} else {
|
|
585
|
-
|
|
585
|
+
setResponse(res, rendered);
|
|
586
586
|
}
|
|
587
587
|
} catch (e) {
|
|
588
588
|
const error = coalesce_to_error(e);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/** @import { EnvVarConfig, KitConfig } from '@sveltejs/kit' */
|
|
2
2
|
/** @import { Options, SvelteConfig } from '@sveltejs/vite-plugin-svelte' */
|
|
3
3
|
/** @import { PreprocessorGroup } from 'svelte/compiler' */
|
|
4
|
-
/** @import {
|
|
4
|
+
/** @import { BuildData, ManifestData, Prerendered, ServerMetadata, RemoteInternals, ValidatedConfig, ValidatedKitConfig } from 'types' */
|
|
5
|
+
/** @import { Manifest, Plugin, ResolvedConfig, Rolldown, UserConfig, ViteDevServer } from 'vite' */
|
|
5
6
|
import fs from 'node:fs';
|
|
6
7
|
import path from 'node:path';
|
|
7
8
|
import process from 'node:process';
|
|
@@ -60,6 +61,7 @@ import { process_config, split_config, validate_config } from '../../core/config
|
|
|
60
61
|
import { treeshake_prerendered_remotes } from './build/remote.js';
|
|
61
62
|
|
|
62
63
|
/**
|
|
64
|
+
* The posix-ified root of the project based on the Vite configuration.
|
|
63
65
|
* Populated after Vite plugins' `config` hooks run
|
|
64
66
|
* @type {string}
|
|
65
67
|
*/
|
|
@@ -259,14 +261,14 @@ function plugin_root() {
|
|
|
259
261
|
* - https://rolldown.rs/apis/plugin-api#output-generation-hooks
|
|
260
262
|
*
|
|
261
263
|
* @param {object} opts
|
|
262
|
-
* @param {
|
|
264
|
+
* @param {ValidatedConfig} opts.svelte_config
|
|
263
265
|
* @return {Plugin[]}
|
|
264
266
|
*/
|
|
265
267
|
function kit({ svelte_config }) {
|
|
266
268
|
/** @type {typeof import('vite')} */
|
|
267
269
|
let vite;
|
|
268
270
|
|
|
269
|
-
/** @type {
|
|
271
|
+
/** @type {ValidatedKitConfig} */
|
|
270
272
|
let kit;
|
|
271
273
|
/** @type {string} `kit.outDir` but posix-ified */
|
|
272
274
|
let out_dir;
|
|
@@ -285,10 +287,10 @@ function kit({ svelte_config }) {
|
|
|
285
287
|
/** @type {Record<string, string>} */
|
|
286
288
|
let env;
|
|
287
289
|
|
|
288
|
-
/** @type {
|
|
290
|
+
/** @type {ManifestData} */
|
|
289
291
|
let manifest_data;
|
|
290
292
|
|
|
291
|
-
/** @type {
|
|
293
|
+
/** @type {ServerMetadata | undefined} only set at build time once analysis is finished */
|
|
292
294
|
let build_metadata = undefined;
|
|
293
295
|
|
|
294
296
|
/** @type {UserConfig} */
|
|
@@ -457,7 +459,7 @@ function kit({ svelte_config }) {
|
|
|
457
459
|
}
|
|
458
460
|
|
|
459
461
|
const define = {
|
|
460
|
-
__SVELTEKIT_APP_DIR__: s(kit.appDir),
|
|
462
|
+
__SVELTEKIT_APP_DIR__: s(posixify(kit.appDir)),
|
|
461
463
|
__SVELTEKIT_APP_VERSION__: s(kit.version.name),
|
|
462
464
|
__SVELTEKIT_EMBEDDED__: s(kit.embedded),
|
|
463
465
|
__SVELTEKIT_FORK_PRELOADS__: s(kit.experimental.forkPreloads),
|
|
@@ -467,7 +469,9 @@ function kit({ svelte_config }) {
|
|
|
467
469
|
__SVELTEKIT_CLIENT_ROUTING__: s(kit.router.resolution === 'client'),
|
|
468
470
|
__SVELTEKIT_HASH_ROUTING__: s(kit.router.type === 'hash'),
|
|
469
471
|
__SVELTEKIT_SERVER_TRACING_ENABLED__: s(kit.tracing.server),
|
|
470
|
-
|
|
472
|
+
__SVELTEKIT_SUPPORTS_ASYNC__: s(
|
|
473
|
+
svelte_config.compilerOptions?.experimental?.async ?? false
|
|
474
|
+
),
|
|
471
475
|
__SVELTEKIT_ROOT__: s(root),
|
|
472
476
|
__SVELTEKIT_DEV__: s(!is_build)
|
|
473
477
|
};
|
|
@@ -485,7 +489,7 @@ function kit({ svelte_config }) {
|
|
|
485
489
|
new_config.define = {
|
|
486
490
|
...define,
|
|
487
491
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
|
|
488
|
-
__SVELTEKIT_PAYLOAD__: kit_global,
|
|
492
|
+
__SVELTEKIT_PAYLOAD__: kit_global, // only relevant when bundleStrategy !== 'split'
|
|
489
493
|
__SVELTEKIT_HAS_SERVER_LOAD__: 'true',
|
|
490
494
|
__SVELTEKIT_HAS_UNIVERSAL_LOAD__: 'true'
|
|
491
495
|
};
|
|
@@ -621,7 +625,7 @@ function kit({ svelte_config }) {
|
|
|
621
625
|
return create_sveltekit_env_public(
|
|
622
626
|
explicit_env_config,
|
|
623
627
|
env,
|
|
624
|
-
`
|
|
628
|
+
`import { payload } from ${s(`${runtime_directory}/client/payload.js`)};\nconst env = payload.env;`
|
|
625
629
|
);
|
|
626
630
|
|
|
627
631
|
case sveltekit_env_public_server:
|
|
@@ -647,18 +651,18 @@ function kit({ svelte_config }) {
|
|
|
647
651
|
|
|
648
652
|
case sveltekit_server: {
|
|
649
653
|
return dedent`
|
|
650
|
-
|
|
654
|
+
export let read_implementation = null;
|
|
651
655
|
|
|
652
|
-
|
|
656
|
+
export let manifest = null;
|
|
653
657
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
658
|
+
export function set_read_implementation(fn) {
|
|
659
|
+
read_implementation = fn;
|
|
660
|
+
}
|
|
657
661
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
+
export function set_manifest(_) {
|
|
663
|
+
manifest = _;
|
|
664
|
+
}
|
|
665
|
+
`;
|
|
662
666
|
}
|
|
663
667
|
}
|
|
664
668
|
}
|
|
@@ -739,11 +743,7 @@ function kit({ svelte_config }) {
|
|
|
739
743
|
(normalized.startsWith('$lib/') && server_only_directory_pattern.test(id)) ||
|
|
740
744
|
(is_internal && server_only_module_pattern.test(id));
|
|
741
745
|
|
|
742
|
-
|
|
743
|
-
// TODO: address https://github.com/sveltejs/kit/issues/12529
|
|
744
|
-
if (!is_server_only) {
|
|
745
|
-
return;
|
|
746
|
-
}
|
|
746
|
+
if (!is_server_only) return;
|
|
747
747
|
|
|
748
748
|
// in dev, this doesn't exist, so we need to create it
|
|
749
749
|
manifest_data ??= sync.all(svelte_config, root).manifest_data;
|
|
@@ -918,7 +918,7 @@ function kit({ svelte_config }) {
|
|
|
918
918
|
|
|
919
919
|
// For the client, read the exports and create a new module that only contains fetch functions with the correct metadata
|
|
920
920
|
|
|
921
|
-
/** @type {Map<string,
|
|
921
|
+
/** @type {Map<string, RemoteInternals['type']>} */
|
|
922
922
|
const map = new Map();
|
|
923
923
|
|
|
924
924
|
// in dev, load the server module here (which will result in this hook
|
|
@@ -992,7 +992,7 @@ function kit({ svelte_config }) {
|
|
|
992
992
|
let vite_server_manifest;
|
|
993
993
|
/** @type {Manifest | null} */
|
|
994
994
|
let vite_client_manifest = null;
|
|
995
|
-
/** @type {
|
|
995
|
+
/** @type {Prerendered} */
|
|
996
996
|
let prerendered;
|
|
997
997
|
|
|
998
998
|
/** @type {Set<string>} */
|
|
@@ -1228,7 +1228,7 @@ function kit({ svelte_config }) {
|
|
|
1228
1228
|
let new_config;
|
|
1229
1229
|
|
|
1230
1230
|
if (is_build) {
|
|
1231
|
-
const
|
|
1231
|
+
const app_immutable = `${kit.appDir}/immutable`;
|
|
1232
1232
|
|
|
1233
1233
|
/** @type {Record<string, string>} */
|
|
1234
1234
|
const server_input = {
|
|
@@ -1297,6 +1297,7 @@ function kit({ svelte_config }) {
|
|
|
1297
1297
|
client_input['bundle'] = `${runtime_directory}/client/bundle.js`;
|
|
1298
1298
|
} else {
|
|
1299
1299
|
client_input['entry/start'] = `${runtime_directory}/client/entry.js`;
|
|
1300
|
+
client_input['entry/payload'] = `${runtime_directory}/client/payload.js`;
|
|
1300
1301
|
client_input['entry/app'] = `${out_dir}/generated/client-optimized/app.js`;
|
|
1301
1302
|
manifest_data.nodes.forEach((node, i) => {
|
|
1302
1303
|
if (node.component || node.universal) {
|
|
@@ -1309,9 +1310,9 @@ function kit({ svelte_config }) {
|
|
|
1309
1310
|
|
|
1310
1311
|
/** @type {string} */
|
|
1311
1312
|
const base = (kit.paths.assets || kit.paths.base) + '/';
|
|
1312
|
-
const root_to_assets =
|
|
1313
|
+
const root_to_assets = app_immutable + '/assets/';
|
|
1313
1314
|
const assets_to_root =
|
|
1314
|
-
|
|
1315
|
+
app_immutable
|
|
1315
1316
|
.split('/')
|
|
1316
1317
|
.map(() => '..')
|
|
1317
1318
|
.join('/') + '/../';
|
|
@@ -1334,7 +1335,7 @@ function kit({ svelte_config }) {
|
|
|
1334
1335
|
rolldownOptions: {
|
|
1335
1336
|
output: {
|
|
1336
1337
|
name: `__sveltekit_${version_hash}.app`,
|
|
1337
|
-
assetFileNames: `${
|
|
1338
|
+
assetFileNames: `${app_immutable}/assets/[name].[hash][extname]`,
|
|
1338
1339
|
hoistTransitiveImports: false,
|
|
1339
1340
|
sourcemapIgnoreList
|
|
1340
1341
|
},
|
|
@@ -1373,7 +1374,7 @@ function kit({ svelte_config }) {
|
|
|
1373
1374
|
}
|
|
1374
1375
|
}
|
|
1375
1376
|
},
|
|
1376
|
-
//
|
|
1377
|
+
// these are stubs that will be replaced after the initial server build
|
|
1377
1378
|
define: {
|
|
1378
1379
|
__SVELTEKIT_HAS_SERVER_LOAD__: 'true',
|
|
1379
1380
|
__SVELTEKIT_HAS_UNIVERSAL_LOAD__: 'true',
|
|
@@ -1387,8 +1388,8 @@ function kit({ svelte_config }) {
|
|
|
1387
1388
|
input: inline ? client_input['bundle'] : client_input,
|
|
1388
1389
|
output: {
|
|
1389
1390
|
format: inline ? 'iife' : 'esm',
|
|
1390
|
-
entryFileNames: `${
|
|
1391
|
-
chunkFileNames: `${
|
|
1391
|
+
entryFileNames: `${app_immutable}/[name].[hash].js`,
|
|
1392
|
+
chunkFileNames: `${app_immutable}/chunks/[hash].js`,
|
|
1392
1393
|
codeSplitting:
|
|
1393
1394
|
svelte_config.kit.output.bundleStrategy === 'split' ? undefined : false
|
|
1394
1395
|
},
|
|
@@ -1405,7 +1406,8 @@ function kit({ svelte_config }) {
|
|
|
1405
1406
|
}
|
|
1406
1407
|
},
|
|
1407
1408
|
define: {
|
|
1408
|
-
__SVELTEKIT_PAYLOAD__:
|
|
1409
|
+
__SVELTEKIT_PAYLOAD__:
|
|
1410
|
+
svelte_config.kit.output.bundleStrategy !== 'split' ? kit_global : 'undefined'
|
|
1409
1411
|
}
|
|
1410
1412
|
}
|
|
1411
1413
|
},
|
|
@@ -1424,6 +1426,11 @@ function kit({ svelte_config }) {
|
|
|
1424
1426
|
return { relative };
|
|
1425
1427
|
}
|
|
1426
1428
|
|
|
1429
|
+
if (!relative) return;
|
|
1430
|
+
|
|
1431
|
+
// ensure assets loaded by CSS files are loaded relative to the
|
|
1432
|
+
// CSS file rather than the default of relative to the root
|
|
1433
|
+
|
|
1427
1434
|
// _app/immutable/assets files
|
|
1428
1435
|
if (filename.startsWith(root_to_assets)) {
|
|
1429
1436
|
return `./${filename.slice(root_to_assets.length)}`;
|
|
@@ -1462,16 +1469,16 @@ function kit({ svelte_config }) {
|
|
|
1462
1469
|
* Adds the SvelteKit middleware to do SSR in dev mode.
|
|
1463
1470
|
* @see https://vitejs.dev/guide/api-plugin.html#configureserver
|
|
1464
1471
|
*/
|
|
1465
|
-
async configureServer(
|
|
1466
|
-
return await dev(
|
|
1472
|
+
async configureServer(server) {
|
|
1473
|
+
return await dev(server, vite_config, svelte_config, () => remotes, root);
|
|
1467
1474
|
},
|
|
1468
1475
|
|
|
1469
1476
|
/**
|
|
1470
1477
|
* Adds the SvelteKit middleware to do SSR in preview mode.
|
|
1471
1478
|
* @see https://vitejs.dev/guide/api-plugin.html#configurepreviewserver
|
|
1472
1479
|
*/
|
|
1473
|
-
configurePreviewServer(
|
|
1474
|
-
return preview(
|
|
1480
|
+
configurePreviewServer(server) {
|
|
1481
|
+
return preview(server, vite_config, svelte_config);
|
|
1475
1482
|
},
|
|
1476
1483
|
|
|
1477
1484
|
applyToEnvironment(environment) {
|
|
@@ -1519,13 +1526,13 @@ function kit({ svelte_config }) {
|
|
|
1519
1526
|
await builder.build(builder.environments.ssr)
|
|
1520
1527
|
);
|
|
1521
1528
|
|
|
1522
|
-
const verbose =
|
|
1529
|
+
const verbose = builder.config.logLevel === 'info';
|
|
1523
1530
|
const log = logger({ verbose });
|
|
1524
1531
|
|
|
1525
1532
|
/** @type {Manifest} */
|
|
1526
1533
|
vite_server_manifest = JSON.parse(read(`${out}/server/.vite/manifest.json`));
|
|
1527
1534
|
|
|
1528
|
-
/** @type {
|
|
1535
|
+
/** @type {BuildData} */
|
|
1529
1536
|
const build_data = {
|
|
1530
1537
|
app_dir: kit.appDir,
|
|
1531
1538
|
app_path: `${kit.paths.base.slice(1)}${kit.paths.base ? '/' : ''}${kit.appDir}`,
|
|
@@ -1663,15 +1670,28 @@ function kit({ svelte_config }) {
|
|
|
1663
1670
|
);
|
|
1664
1671
|
|
|
1665
1672
|
if (svelte_config.kit.output.bundleStrategy === 'split') {
|
|
1666
|
-
const
|
|
1673
|
+
const start_entry = posixify(path.relative(root, `${runtime_directory}/client/entry.js`));
|
|
1674
|
+
const start = find_deps(vite_manifest, start_entry, false, root);
|
|
1675
|
+
const runtime_entry = resolve_symlinks(vite_manifest, start_entry, root).chunk
|
|
1676
|
+
.dynamicImports?.[0]; // client/entry.js dynamically imports client/client-entry.js
|
|
1677
|
+
if (!runtime_entry) throw new Error('Could not find the client runtime chunk');
|
|
1678
|
+
const runtime = find_deps(vite_manifest, runtime_entry, false, root);
|
|
1667
1679
|
const app = deps_of(`${out_dir}/generated/client-optimized/app.js`);
|
|
1668
1680
|
|
|
1669
1681
|
build_data.client = {
|
|
1670
1682
|
start: start.file,
|
|
1671
1683
|
app: app.file,
|
|
1672
|
-
imports:
|
|
1673
|
-
|
|
1674
|
-
|
|
1684
|
+
imports: Array.from(
|
|
1685
|
+
new Set([
|
|
1686
|
+
...start.imports,
|
|
1687
|
+
runtime.file,
|
|
1688
|
+
...runtime.imports,
|
|
1689
|
+
app.file,
|
|
1690
|
+
...app.imports
|
|
1691
|
+
])
|
|
1692
|
+
),
|
|
1693
|
+
stylesheets: [...start.stylesheets, ...runtime.stylesheets, ...app.stylesheets],
|
|
1694
|
+
fonts: [...start.fonts, ...runtime.fonts, ...app.fonts],
|
|
1675
1695
|
uses_env_dynamic_public
|
|
1676
1696
|
};
|
|
1677
1697
|
|
|
@@ -1947,7 +1967,7 @@ function find_overridden_config(config, resolved_config, enforced_config, path,
|
|
|
1947
1967
|
}
|
|
1948
1968
|
|
|
1949
1969
|
/**
|
|
1950
|
-
* @param {
|
|
1970
|
+
* @param {ValidatedConfig} config
|
|
1951
1971
|
*/
|
|
1952
1972
|
const create_service_worker_module = (config) => dedent`
|
|
1953
1973
|
if (typeof self === 'undefined' || self instanceof ServiceWorkerGlobalScope === false) {
|