@sveltejs/kit 2.62.0 → 3.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +28 -22
- package/src/cli.js +49 -20
- package/src/core/adapt/builder.js +38 -69
- package/src/core/adapt/index.js +11 -6
- package/src/core/config/index.js +12 -82
- package/src/core/config/options.js +36 -45
- package/src/core/env.js +240 -60
- package/src/core/generate_manifest/find_server_assets.js +3 -2
- package/src/core/generate_manifest/index.js +11 -3
- package/src/core/postbuild/analyse.js +20 -16
- package/src/core/postbuild/fallback.js +0 -3
- package/src/core/postbuild/prerender.js +19 -17
- package/src/core/postbuild/queue.js +3 -4
- package/src/core/sync/create_manifest_data/index.js +16 -18
- package/src/core/sync/sync.js +44 -23
- package/src/core/sync/utils.js +0 -15
- package/src/core/sync/write_ambient.js +5 -50
- package/src/core/sync/write_client_manifest.js +8 -9
- package/src/core/sync/write_env.js +36 -0
- package/src/core/sync/write_non_ambient.js +7 -7
- package/src/core/sync/write_root.js +41 -89
- package/src/core/sync/write_server.js +18 -24
- package/src/core/sync/write_tsconfig.js +29 -24
- package/src/core/sync/write_types/index.js +31 -25
- package/src/core/utils.js +14 -11
- package/src/exports/hooks/index.js +13 -0
- package/src/exports/index.js +8 -21
- package/src/exports/internal/env.js +71 -0
- package/src/exports/internal/types.d.ts +3 -0
- package/src/exports/node/index.js +8 -13
- package/src/exports/public.d.ts +68 -69
- package/src/exports/vite/build/build_server.js +14 -11
- package/src/exports/vite/build/remote.js +6 -7
- package/src/exports/vite/build/utils.js +7 -5
- package/src/exports/vite/dev/index.js +32 -33
- package/src/exports/vite/index.js +1015 -711
- package/src/exports/vite/module_ids.js +10 -6
- package/src/exports/vite/options.js +17 -0
- package/src/exports/vite/preview/index.js +3 -5
- package/src/exports/vite/static_analysis/index.js +11 -5
- package/src/exports/vite/utils.js +11 -41
- package/src/runtime/app/env/index.js +2 -0
- package/src/runtime/app/env/internal.js +14 -0
- package/src/runtime/app/env/private.js +1 -0
- package/src/runtime/app/env/public/client.js +1 -0
- package/src/runtime/app/env/public/index.js +1 -0
- package/src/runtime/app/env/public/server.js +1 -0
- package/src/runtime/app/env/standard-schema.d.ts +0 -0
- package/src/runtime/app/server/index.js +4 -2
- package/src/runtime/app/server/remote/form.js +0 -51
- package/src/runtime/app/server/remote/query.js +1 -8
- package/src/runtime/app/server/remote/shared.js +4 -3
- package/src/runtime/app/state/client.js +1 -12
- package/src/runtime/client/client.js +1 -1
- package/src/runtime/client/constants.js +0 -1
- package/src/runtime/client/remote-functions/form.svelte.js +0 -31
- package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
- package/src/runtime/client/remote-functions/query/index.js +2 -2
- package/src/runtime/client/remote-functions/query/instance.svelte.js +1 -2
- package/src/runtime/client/remote-functions/query-batch.svelte.js +2 -2
- package/src/runtime/client/remote-functions/query-live/instance.svelte.js +5 -8
- package/src/runtime/client/utils.js +9 -11
- package/src/runtime/components/{svelte-5/layout.svelte → layout.svelte} +1 -1
- package/src/runtime/form-utils.js +4 -41
- package/src/runtime/server/cookie.js +21 -37
- package/src/runtime/server/env_module.js +12 -4
- package/src/runtime/server/fetch.js +6 -10
- package/src/runtime/server/index.js +5 -9
- package/src/runtime/server/page/render.js +33 -37
- package/src/runtime/server/page/types.d.ts +4 -2
- package/src/runtime/server/respond.js +3 -3
- package/src/runtime/server/utils.js +2 -4
- package/src/runtime/shared-server.js +0 -22
- package/src/runtime/shared.js +0 -15
- package/src/types/ambient-private.d.ts +25 -9
- package/src/types/global-private.d.ts +6 -0
- package/src/types/internal.d.ts +4 -8
- package/src/utils/css.js +3 -19
- package/src/utils/filesystem.js +1 -30
- package/src/utils/http.js +0 -21
- package/src/utils/import.js +8 -7
- package/src/utils/os.js +7 -0
- package/src/utils/path.js +23 -0
- package/src/utils/shared-iterator.js +3 -0
- package/src/utils/streaming.js +2 -4
- package/src/utils/url.js +1 -1
- package/src/utils/vite.js +28 -0
- package/src/version.js +1 -1
- package/types/index.d.ts +85 -109
- package/types/index.d.ts.map +5 -6
- package/src/exports/vite/build/build_service_worker.js +0 -149
- package/src/runtime/app/environment/index.js +0 -2
- package/src/runtime/components/svelte-4/error.svelte +0 -6
- package/src/runtime/components/svelte-4/layout.svelte +0 -1
- package/src/runtime/env/dynamic/private.js +0 -1
- package/src/runtime/env/dynamic/public.js +0 -1
- package/src/types/synthetic/$env+dynamic+private.md +0 -43
- package/src/types/synthetic/$env+dynamic+public.md +0 -46
- package/src/types/synthetic/$env+static+private.md +0 -31
- package/src/types/synthetic/$env+static+public.md +0 -31
- package/src/utils/env.js +0 -13
- package/src/utils/promise.js +0 -29
- /package/src/runtime/app/{environment → env}/types.d.ts +0 -0
- /package/src/runtime/components/{svelte-5/error.svelte → error.svelte} +0 -0
|
@@ -1 +1,14 @@
|
|
|
1
|
+
/** @import { EnvVarConfig } from '@sveltejs/kit' */
|
|
2
|
+
|
|
1
3
|
export { sequence } from './sequence.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Utility for defining [environment variables](https://svelte.dev/docs/kit/environment-variables),
|
|
7
|
+
* which are made available via `$app/env/public` and `$app/env/private`.
|
|
8
|
+
* @template {Record<string, EnvVarConfig<any>>} T
|
|
9
|
+
* @param {T} variables
|
|
10
|
+
* @returns {T}
|
|
11
|
+
*/
|
|
12
|
+
export function defineEnvVars(variables) {
|
|
13
|
+
return variables;
|
|
14
|
+
}
|
package/src/exports/index.js
CHANGED
|
@@ -14,19 +14,6 @@ import { text_encoder } from '../runtime/utils.js';
|
|
|
14
14
|
|
|
15
15
|
export { VERSION } from '../version.js';
|
|
16
16
|
|
|
17
|
-
// TODO 3.0: remove these types as they are not used anymore (we can't remove them yet because that would be a breaking change)
|
|
18
|
-
/**
|
|
19
|
-
* @template {number} TNumber
|
|
20
|
-
* @template {any[]} [TArray=[]]
|
|
21
|
-
* @typedef {TNumber extends TArray['length'] ? TArray[number] : LessThan<TNumber, [...TArray, TArray['length']]>} LessThan
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @template {number} TStart
|
|
26
|
-
* @template {number} TEnd
|
|
27
|
-
* @typedef {Exclude<TEnd | LessThan<TEnd>, LessThan<TStart>>} NumericRange
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
17
|
// Keep the status codes as `number` because restricting to certain numbers makes it unnecessarily hard to use compared to the benefits
|
|
31
18
|
// (we have runtime errors already to check for invalid codes). Also see https://github.com/sveltejs/kit/issues/11780
|
|
32
19
|
|
|
@@ -44,7 +31,7 @@ export { VERSION } from '../version.js';
|
|
|
44
31
|
* @param {number} status
|
|
45
32
|
* @param {App.Error} body
|
|
46
33
|
* @return {never}
|
|
47
|
-
* @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
34
|
+
* @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
48
35
|
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
49
36
|
*/
|
|
50
37
|
/**
|
|
@@ -58,7 +45,7 @@ export { VERSION } from '../version.js';
|
|
|
58
45
|
* @param {number} status
|
|
59
46
|
* @param {{ message: string } extends App.Error ? App.Error | string | undefined : never} [body]
|
|
60
47
|
* @return {never}
|
|
61
|
-
* @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
48
|
+
* @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
62
49
|
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
63
50
|
*/
|
|
64
51
|
/**
|
|
@@ -69,7 +56,7 @@ export { VERSION } from '../version.js';
|
|
|
69
56
|
* @param {number} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.
|
|
70
57
|
* @param {{ message: string } extends App.Error ? App.Error | string | undefined : never} body An object that conforms to the App.Error type. If a string is passed, it will be used as the message property.
|
|
71
58
|
* @return {never}
|
|
72
|
-
* @throws {HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
59
|
+
* @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
|
|
73
60
|
* @throws {Error} If the provided status is invalid (not between 400 and 599).
|
|
74
61
|
*/
|
|
75
62
|
export function error(status, body) {
|
|
@@ -85,7 +72,7 @@ export function error(status, body) {
|
|
|
85
72
|
* @template {number} T
|
|
86
73
|
* @param {unknown} e
|
|
87
74
|
* @param {T} [status] The status to filter for.
|
|
88
|
-
* @return {e is (HttpError & { status: T extends undefined ? never : T })}
|
|
75
|
+
* @return {e is (import('./public.js').HttpError & { status: T extends undefined ? never : T })}
|
|
89
76
|
*/
|
|
90
77
|
export function isHttpError(e, status) {
|
|
91
78
|
if (!(e instanceof HttpError)) return false;
|
|
@@ -105,7 +92,7 @@ export function isHttpError(e, status) {
|
|
|
105
92
|
*
|
|
106
93
|
* @param {300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | ({} & number)} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#redirection_messages). Must be in the range 300-308.
|
|
107
94
|
* @param {string | URL} location The location to redirect to.
|
|
108
|
-
* @throws {Redirect} This error instructs SvelteKit to redirect to the specified location.
|
|
95
|
+
* @throws {import('./public.js').Redirect} This error instructs SvelteKit to redirect to the specified location.
|
|
109
96
|
* @throws {Error} If the provided status is invalid or the location cannot be used as a header value.
|
|
110
97
|
* @return {never}
|
|
111
98
|
*/
|
|
@@ -124,7 +111,7 @@ export function redirect(status, location) {
|
|
|
124
111
|
/**
|
|
125
112
|
* Checks whether this is a redirect thrown by {@link redirect}.
|
|
126
113
|
* @param {unknown} e The object to check.
|
|
127
|
-
* @return {e is Redirect}
|
|
114
|
+
* @return {e is import('./public.js').Redirect}
|
|
128
115
|
*/
|
|
129
116
|
export function isRedirect(e) {
|
|
130
117
|
return e instanceof Redirect;
|
|
@@ -134,10 +121,9 @@ export function isRedirect(e) {
|
|
|
134
121
|
* Create a JSON `Response` object from the supplied data.
|
|
135
122
|
* @param {any} data The value that will be serialized as JSON.
|
|
136
123
|
* @param {ResponseInit} [init] Options such as `status` and `headers` that will be added to the response. `Content-Type: application/json` and `Content-Length` headers will be added automatically.
|
|
124
|
+
* @deprecated use `Response.json`
|
|
137
125
|
*/
|
|
138
126
|
export function json(data, init) {
|
|
139
|
-
// TODO deprecate this in favour of `Response.json` when it's
|
|
140
|
-
// more widely supported
|
|
141
127
|
const body = JSON.stringify(data);
|
|
142
128
|
|
|
143
129
|
// we can't just do `text(JSON.stringify(data), init)` because
|
|
@@ -162,6 +148,7 @@ export function json(data, init) {
|
|
|
162
148
|
* Create a `Response` object from the supplied body.
|
|
163
149
|
* @param {string} body The value that will be used as-is.
|
|
164
150
|
* @param {ResponseInit} [init] Options such as `status` and `headers` that will be added to the response. A `Content-Length` header will be added automatically.
|
|
151
|
+
* @deprecated use `new Response`
|
|
165
152
|
*/
|
|
166
153
|
export function text(body, init) {
|
|
167
154
|
const headers = new Headers(init?.headers);
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
2
|
+
/** @import { EnvVarConfig } from '@sveltejs/kit' */
|
|
3
|
+
|
|
4
|
+
import { stackless } from '../vite/utils.js';
|
|
5
|
+
|
|
6
|
+
const MISSING = {
|
|
7
|
+
message: `Value is missing. If it is optional, add a Standard Schema validator declaring it as such.`
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const BAD_VALIDATOR = {
|
|
11
|
+
message: 'Variable was configured with a validator that does not implement Standard Schema'
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const ASYNC_VALIDATOR = {
|
|
15
|
+
message: 'Variable uses an async validator, which is not supported'
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {Record<string, EnvVarConfig<any>>} variables
|
|
20
|
+
* @param {string | undefined} value
|
|
21
|
+
* @param {string} name
|
|
22
|
+
* @param {Record<string, StandardSchemaV1.Issue[]>} issues
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export function validate(variables, value, name, issues) {
|
|
26
|
+
const config = variables[name] ?? {};
|
|
27
|
+
const validator = config.schema;
|
|
28
|
+
|
|
29
|
+
if (!validator) {
|
|
30
|
+
if (!value) issues[name] = [MISSING];
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!validator['~standard']) {
|
|
35
|
+
issues[name] = [BAD_VALIDATOR];
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const result = validator['~standard'].validate(value);
|
|
40
|
+
|
|
41
|
+
if (result instanceof Promise) {
|
|
42
|
+
issues[name] = [ASYNC_VALIDATOR];
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (result.issues) {
|
|
47
|
+
issues[name] = [...result.issues];
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return result.value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {Record<string, StandardSchemaV1.Issue[]>} issues
|
|
56
|
+
*/
|
|
57
|
+
export function handle_issues(issues) {
|
|
58
|
+
const entries = Object.entries(issues);
|
|
59
|
+
|
|
60
|
+
if (entries.length === 0) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let message = 'Invalid environment variables\n';
|
|
65
|
+
|
|
66
|
+
for (const [name, issues] of entries) {
|
|
67
|
+
message += `\n${name}\n${issues.map((issue) => ` - ${issue.message}`).join('\n')}\n`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
throw stackless(message);
|
|
71
|
+
}
|
|
@@ -2,7 +2,6 @@ import { createReadStream } from 'node:fs';
|
|
|
2
2
|
import { Readable } from 'node:stream';
|
|
3
3
|
import { SvelteKitError } from '../internal/index.js';
|
|
4
4
|
import { noop } from '../../utils/functions.js';
|
|
5
|
-
import { get_set_cookies } from '../../utils/http.js';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* @param {import('http').IncomingMessage} req
|
|
@@ -38,15 +37,11 @@ function get_raw_body(req, body_size_limit) {
|
|
|
38
37
|
return new ReadableStream({
|
|
39
38
|
start(controller) {
|
|
40
39
|
if (body_size_limit !== undefined && has_content_length && content_length > body_size_limit) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
message += ' To disable body size limits, specify Infinity rather than 0.';
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const error = new SvelteKitError(413, 'Payload Too Large', message);
|
|
40
|
+
const error = new SvelteKitError(
|
|
41
|
+
413,
|
|
42
|
+
'Payload Too Large',
|
|
43
|
+
`Content-length of ${content_length} exceeds limit of ${body_size_limit} bytes.`
|
|
44
|
+
);
|
|
50
45
|
|
|
51
46
|
controller.error(error);
|
|
52
47
|
return;
|
|
@@ -133,9 +128,9 @@ export async function getRequest({ request, base, bodySizeLimit }) {
|
|
|
133
128
|
delete headers[':scheme'];
|
|
134
129
|
}
|
|
135
130
|
|
|
136
|
-
// TODO: Whenever Node >=22 is minimum supported version, we can use `request.readableAborted`
|
|
137
|
-
// @see https://github.com/nodejs/node/blob/5cf3c3e24c7257a0c6192ed8ef71efec8ddac22b/lib/internal/streams/readable.js#L1443-L1453
|
|
138
131
|
const controller = new AbortController();
|
|
132
|
+
// TODO: Whenever Node >=22.17 is the minimum supported version, we can do `if (request.readableAborted) controller.abort()` instead
|
|
133
|
+
// see https://github.com/nodejs/node/blob/5cf3c3e24c7257a0c6192ed8ef71efec8ddac22b/lib/internal/streams/readable.js#L1443-L1453
|
|
139
134
|
let errored = false;
|
|
140
135
|
let end_emitted = false;
|
|
141
136
|
request.once('error', () => (errored = true));
|
|
@@ -169,7 +164,7 @@ export async function getRequest({ request, base, bodySizeLimit }) {
|
|
|
169
164
|
export async function setResponse(res, response) {
|
|
170
165
|
for (const [key, value] of response.headers) {
|
|
171
166
|
try {
|
|
172
|
-
res.setHeader(key, key === 'set-cookie' ?
|
|
167
|
+
res.setHeader(key, key === 'set-cookie' ? response.headers.getSetCookie() : value);
|
|
173
168
|
} catch (error) {
|
|
174
169
|
res.getHeaderNames().forEach((name) => res.removeHeader(name));
|
|
175
170
|
res.writeHead(500).end(String(error));
|
package/src/exports/public.d.ts
CHANGED
|
@@ -122,13 +122,12 @@ export interface Builder {
|
|
|
122
122
|
/** An array of all routes (including prerendered) */
|
|
123
123
|
routes: RouteDefinition[];
|
|
124
124
|
|
|
125
|
-
// TODO 3.0 remove this method
|
|
126
125
|
/**
|
|
127
126
|
* Create separate functions that map to one or more routes of your app.
|
|
128
127
|
* @param fn A function that groups a set of routes into an entry point
|
|
129
|
-
* @deprecated Use `builder.routes` instead
|
|
128
|
+
* @deprecated removed in 3.0. Use `builder.routes` instead
|
|
130
129
|
*/
|
|
131
|
-
createEntries
|
|
130
|
+
createEntries?: (fn: (route: RouteDefinition) => AdapterEntry) => Promise<void>;
|
|
132
131
|
|
|
133
132
|
/**
|
|
134
133
|
* Find all the assets imported by server files belonging to `routes`
|
|
@@ -141,7 +140,7 @@ export interface Builder {
|
|
|
141
140
|
generateFallback: (dest: string) => Promise<void>;
|
|
142
141
|
|
|
143
142
|
/**
|
|
144
|
-
* Generate a module exposing
|
|
143
|
+
* Generate a module exposing public environment variables as `$app/env/public` if the app uses it.
|
|
145
144
|
*/
|
|
146
145
|
generateEnvModule: () => void;
|
|
147
146
|
|
|
@@ -264,57 +263,50 @@ export interface Cookies {
|
|
|
264
263
|
/**
|
|
265
264
|
* Gets a cookie that was previously set with `cookies.set`, or from the request headers.
|
|
266
265
|
* @param name the name of the cookie
|
|
267
|
-
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#
|
|
266
|
+
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
|
|
268
267
|
*/
|
|
269
|
-
get: (name: string, opts?: import('cookie').
|
|
268
|
+
get: (name: string, opts?: import('cookie').ParseOptions) => string | undefined;
|
|
270
269
|
|
|
271
270
|
/**
|
|
272
271
|
* Gets all cookies that were previously set with `cookies.set`, or from the request headers.
|
|
273
|
-
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#
|
|
272
|
+
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookieparsecookiestr-options)
|
|
274
273
|
*/
|
|
275
|
-
getAll: (opts?: import('cookie').
|
|
274
|
+
getAll: (opts?: import('cookie').ParseOptions) => Array<{ name: string; value: string }>;
|
|
276
275
|
|
|
277
276
|
/**
|
|
278
277
|
* Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request.
|
|
279
278
|
*
|
|
280
|
-
* The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
|
|
279
|
+
* The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
|
|
281
280
|
*
|
|
282
|
-
*
|
|
281
|
+
* The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
|
|
283
282
|
* @param name the name of the cookie
|
|
284
283
|
* @param value the cookie value
|
|
285
|
-
* @param opts the options
|
|
284
|
+
* @param opts the options passed to `cookie.serialize` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
|
|
286
285
|
*/
|
|
287
|
-
set: (
|
|
288
|
-
name: string,
|
|
289
|
-
value: string,
|
|
290
|
-
opts: import('cookie').CookieSerializeOptions & { path: string }
|
|
291
|
-
) => void;
|
|
286
|
+
set: (name: string, value: string, opts: import('cookie').SerializeOptions) => void;
|
|
292
287
|
|
|
293
288
|
/**
|
|
294
289
|
* Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
|
|
295
290
|
*
|
|
296
|
-
*
|
|
291
|
+
* The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
|
|
292
|
+
*
|
|
293
|
+
* The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
|
|
297
294
|
* @param name the name of the cookie
|
|
298
|
-
* @param opts the options
|
|
295
|
+
* @param opts the options passed to `cookie.serialize` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
|
|
299
296
|
*/
|
|
300
|
-
delete: (name: string, opts: import('cookie').
|
|
297
|
+
delete: (name: string, opts: import('cookie').SerializeOptions) => void;
|
|
301
298
|
|
|
302
299
|
/**
|
|
303
300
|
* Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
|
|
304
301
|
*
|
|
305
|
-
* The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
|
|
306
|
-
*
|
|
307
|
-
* You must specify a `path` for the cookie. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children
|
|
302
|
+
* The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP.
|
|
308
303
|
*
|
|
304
|
+
* The `path` option is `'/'` by default. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children.
|
|
309
305
|
* @param name the name of the cookie
|
|
310
306
|
* @param value the cookie value
|
|
311
|
-
* @param opts the options
|
|
307
|
+
* @param opts the options passed to `cookie.serialize` with the SvelteKit defaults described above. See documentation [here](https://github.com/jshttp/cookie?tab=readme-ov-file#cookiestringifysetcookiesetcookieobj-options)
|
|
312
308
|
*/
|
|
313
|
-
serialize: (
|
|
314
|
-
name: string,
|
|
315
|
-
value: string,
|
|
316
|
-
opts: import('cookie').CookieSerializeOptions & { path: string }
|
|
317
|
-
) => string;
|
|
309
|
+
serialize: (name: string, value: string, opts: import('cookie').SerializeOptions) => string;
|
|
318
310
|
}
|
|
319
311
|
|
|
320
312
|
/**
|
|
@@ -329,9 +321,11 @@ export interface Emulator {
|
|
|
329
321
|
}
|
|
330
322
|
|
|
331
323
|
export interface KitConfig {
|
|
324
|
+
// TODO: remove this in 4.0
|
|
332
325
|
/**
|
|
333
326
|
* Your [adapter](https://svelte.dev/docs/kit/adapters) is run when executing `vite build`. It determines how the output is converted for different platforms.
|
|
334
327
|
* @default undefined
|
|
328
|
+
* @deprecated removed in 3.0.0. Adapters should now be passed to the `sveltekit` Vite plugin in `vite.config.js`
|
|
335
329
|
*/
|
|
336
330
|
adapter?: Adapter;
|
|
337
331
|
/**
|
|
@@ -428,7 +422,7 @@ export interface KitConfig {
|
|
|
428
422
|
*
|
|
429
423
|
* To allow people to make `POST`, `PUT`, `PATCH`, or `DELETE` requests with a `Content-Type` of `application/x-www-form-urlencoded`, `multipart/form-data`, or `text/plain` to your app from other origins, you will need to disable this option. Be careful!
|
|
430
424
|
* @default true
|
|
431
|
-
* @deprecated Use `trustedOrigins: ['*']` instead
|
|
425
|
+
* @deprecated removed in 3.0. Use `trustedOrigins: ['*']` instead
|
|
432
426
|
*/
|
|
433
427
|
checkOrigin?: boolean;
|
|
434
428
|
/**
|
|
@@ -462,17 +456,6 @@ export interface KitConfig {
|
|
|
462
456
|
* @default "."
|
|
463
457
|
*/
|
|
464
458
|
dir?: string;
|
|
465
|
-
/**
|
|
466
|
-
* A prefix that signals that an environment variable is safe to expose to client-side code. See [`$env/static/public`](https://svelte.dev/docs/kit/$env-static-public) and [`$env/dynamic/public`](https://svelte.dev/docs/kit/$env-dynamic-public). Note that Vite's [`envPrefix`](https://vitejs.dev/config/shared-options.html#envprefix) must be set separately if you are using Vite's environment variable handling - though use of that feature should generally be unnecessary.
|
|
467
|
-
* @default "PUBLIC_"
|
|
468
|
-
*/
|
|
469
|
-
publicPrefix?: string;
|
|
470
|
-
/**
|
|
471
|
-
* A prefix that signals that an environment variable is unsafe to expose to client-side code. Environment variables matching neither the public nor the private prefix will be discarded completely. See [`$env/static/private`](https://svelte.dev/docs/kit/$env-static-private) and [`$env/dynamic/private`](https://svelte.dev/docs/kit/$env-dynamic-private).
|
|
472
|
-
* @default ""
|
|
473
|
-
* @since 1.21.0
|
|
474
|
-
*/
|
|
475
|
-
privatePrefix?: string;
|
|
476
459
|
};
|
|
477
460
|
/** Experimental features. Here be dragons. These are not subject to semantic versioning, so breaking changes or removal can happen in any release. */
|
|
478
461
|
experimental?: {
|
|
@@ -620,6 +603,16 @@ export interface KitConfig {
|
|
|
620
603
|
* Options related to the build output format
|
|
621
604
|
*/
|
|
622
605
|
output?: {
|
|
606
|
+
/**
|
|
607
|
+
* Whether to use the [HTTP `Link` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Link) to preload assets instead of the [`<link>` HTML element](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/link) for non-prerendered pages.
|
|
608
|
+
*
|
|
609
|
+
* Note that some web servers such as Nginx and Apache have a default header size limit which may be easily exceeded.
|
|
610
|
+
* If you are using one of these web servers, you may want to leave this as `false` or configure a higher limit.
|
|
611
|
+
*
|
|
612
|
+
* @default false
|
|
613
|
+
* @since 3.0.0
|
|
614
|
+
*/
|
|
615
|
+
linkHeaderPreload?: boolean;
|
|
623
616
|
/**
|
|
624
617
|
* SvelteKit will preload the JavaScript modules needed for the initial page to avoid import 'waterfalls', resulting in faster application startup. There
|
|
625
618
|
* are three strategies with different trade-offs:
|
|
@@ -628,6 +621,7 @@ export interface KitConfig {
|
|
|
628
621
|
* - `preload-mjs` - uses `<link rel="preload">` but with the `.mjs` extension which prevents double-parsing in Chromium. Some static webservers will fail to serve .mjs files with a `Content-Type: application/javascript` header, which will cause your application to break. If that doesn't apply to you, this is the option that will deliver the best performance for the largest number of users, until `modulepreload` is more widely supported.
|
|
629
622
|
* @default "modulepreload"
|
|
630
623
|
* @since 1.8.4
|
|
624
|
+
* @deprecated removed in 3.0
|
|
631
625
|
*/
|
|
632
626
|
preloadStrategy?: 'modulepreload' | 'preload-js' | 'preload-mjs';
|
|
633
627
|
/**
|
|
@@ -636,7 +630,7 @@ export interface KitConfig {
|
|
|
636
630
|
* - If `'single'`, creates just one .js bundle and one .css file containing code for the entire app.
|
|
637
631
|
* - If `'inline'`, inlines all JavaScript and CSS of the entire app into the HTML. The result is usable without a server (i.e. you can just open the file in your browser).
|
|
638
632
|
*
|
|
639
|
-
* When using `'split'`, you can also adjust the bundling behaviour by setting [`output.
|
|
633
|
+
* When using `'split'`, you can also adjust the bundling behaviour by setting [`output.codeSplitting`](https://rolldown.rs/reference/OutputOptions.codeSplitting) inside your Vite config's [`build.rolldownOptions`](https://vite.dev/config/build-options#build-rolldownoptions).
|
|
640
634
|
*
|
|
641
635
|
* If you want to inline your assets, you'll need to set Vite's [`build.assetsInlineLimit`](https://vite.dev/config/build-options.html#build-assetsinlinelimit) option to an appropriate size then import your assets through Vite.
|
|
642
636
|
*
|
|
@@ -1281,13 +1275,6 @@ export interface NavigationGoto extends NavigationBase {
|
|
|
1281
1275
|
* - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
|
|
1282
1276
|
*/
|
|
1283
1277
|
type: 'goto';
|
|
1284
|
-
|
|
1285
|
-
// TODO 3.0 remove this property, so that it only exists when type is 'popstate'
|
|
1286
|
-
// (would possibly be a breaking change to do it prior to that)
|
|
1287
|
-
/**
|
|
1288
|
-
* In case of a history back/forward navigation, the number of steps to go back/forward
|
|
1289
|
-
*/
|
|
1290
|
-
delta?: undefined;
|
|
1291
1278
|
}
|
|
1292
1279
|
|
|
1293
1280
|
export interface NavigationLeave extends NavigationBase {
|
|
@@ -1296,13 +1283,6 @@ export interface NavigationLeave extends NavigationBase {
|
|
|
1296
1283
|
* - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
|
|
1297
1284
|
*/
|
|
1298
1285
|
type: 'leave';
|
|
1299
|
-
|
|
1300
|
-
// TODO 3.0 remove this property, so that it only exists when type is 'popstate'
|
|
1301
|
-
// (would possibly be a breaking change to do it prior to that)
|
|
1302
|
-
/**
|
|
1303
|
-
* In case of a history back/forward navigation, the number of steps to go back/forward
|
|
1304
|
-
*/
|
|
1305
|
-
delta?: undefined;
|
|
1306
1286
|
}
|
|
1307
1287
|
|
|
1308
1288
|
export interface NavigationFormSubmit extends NavigationBase {
|
|
@@ -1316,13 +1296,6 @@ export interface NavigationFormSubmit extends NavigationBase {
|
|
|
1316
1296
|
* The `SubmitEvent` that caused the navigation
|
|
1317
1297
|
*/
|
|
1318
1298
|
event: SubmitEvent;
|
|
1319
|
-
|
|
1320
|
-
// TODO 3.0 remove this property, so that it only exists when type is 'popstate'
|
|
1321
|
-
// (would possibly be a breaking change to do it prior to that)
|
|
1322
|
-
/**
|
|
1323
|
-
* In case of a history back/forward navigation, the number of steps to go back/forward
|
|
1324
|
-
*/
|
|
1325
|
-
delta?: undefined;
|
|
1326
1299
|
}
|
|
1327
1300
|
|
|
1328
1301
|
export interface NavigationPopState extends NavigationBase {
|
|
@@ -1354,13 +1327,6 @@ export interface NavigationLink extends NavigationBase {
|
|
|
1354
1327
|
* The `PointerEvent` that caused the navigation
|
|
1355
1328
|
*/
|
|
1356
1329
|
event: PointerEvent;
|
|
1357
|
-
|
|
1358
|
-
// TODO 3.0 remove this property, so that it only exists when type is 'popstate'
|
|
1359
|
-
// (would possibly be a breaking change to do it prior to that)
|
|
1360
|
-
/**
|
|
1361
|
-
* In case of a history back/forward navigation, the number of steps to go back/forward
|
|
1362
|
-
*/
|
|
1363
|
-
delta?: undefined;
|
|
1364
1330
|
}
|
|
1365
1331
|
|
|
1366
1332
|
export type Navigation =
|
|
@@ -2314,4 +2280,37 @@ export type RemoteLiveQueryFunction<Input, Output, _Validated = Input> = (
|
|
|
2314
2280
|
arg: undefined extends Input ? Input | void : Input
|
|
2315
2281
|
) => RemoteLiveQuery<Output>;
|
|
2316
2282
|
|
|
2283
|
+
/**
|
|
2284
|
+
* [Environment variables](https://svelte.dev/docs/kit/environment-variables) can be configured by exporting
|
|
2285
|
+
* a `variables` object from `src/env.ts`, using [`defineEnvVars`](https://svelte.dev/docs/kit/@sveltejs-kit-hooks#defineEnvVars).
|
|
2286
|
+
*/
|
|
2287
|
+
export interface EnvVarConfig<T> {
|
|
2288
|
+
/**
|
|
2289
|
+
* Whether the environment variable can be accessed by client-side code.
|
|
2290
|
+
* - if `true`, it can be imported from `$app/env/public`
|
|
2291
|
+
* - if `false`, it can be imported from `$app/env/private`, which is a [server-only module](https://svelte.dev/docs/kit/server-only-modules)
|
|
2292
|
+
* @default false
|
|
2293
|
+
*/
|
|
2294
|
+
public?: boolean;
|
|
2295
|
+
/**
|
|
2296
|
+
* Whether the value is determined at build time or when the app runs.
|
|
2297
|
+
* - if `true`, the build time value is inlined into the bundle. This enables optimisations like dead-code elimination
|
|
2298
|
+
* - if `false`, the value is read from the environment when the app starts
|
|
2299
|
+
* @default false
|
|
2300
|
+
*/
|
|
2301
|
+
static?: boolean;
|
|
2302
|
+
/**
|
|
2303
|
+
* A [Standard Schema](https://standardschema.dev/) validator that is applied to the value when the app starts.
|
|
2304
|
+
* The validator can output any value — not necessarily a string — but public, non-static values must be
|
|
2305
|
+
* serializable by [devalue](https://github.com/sveltejs/devalue) so that they can be sent to the browser.
|
|
2306
|
+
*
|
|
2307
|
+
* If omitted, the value must be a non-empty string.
|
|
2308
|
+
*/
|
|
2309
|
+
schema?: StandardSchemaV1<string | undefined, T>;
|
|
2310
|
+
/**
|
|
2311
|
+
* A description of the variable that will be used for inline documentation on hover.
|
|
2312
|
+
*/
|
|
2313
|
+
description?: string;
|
|
2314
|
+
}
|
|
2315
|
+
|
|
2317
2316
|
export * from './index.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @import { AssetDependencies, ManifestData, SSRNode, ValidatedKitConfig } from 'types' */
|
|
2
|
-
/** @import { Manifest,
|
|
2
|
+
/** @import { Manifest, Rolldown } from 'vite' */
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import { mkdirp } from '../../../utils/filesystem.js';
|
|
5
5
|
import {
|
|
@@ -24,6 +24,7 @@ import { escape_for_interpolation } from '../../../utils/escape.js';
|
|
|
24
24
|
* @param {null} client_manifest
|
|
25
25
|
* @param {null} assets_path
|
|
26
26
|
* @param {null} client_chunks
|
|
27
|
+
* @param {string} root
|
|
27
28
|
* @returns {void}
|
|
28
29
|
*/
|
|
29
30
|
/**
|
|
@@ -34,7 +35,8 @@ import { escape_for_interpolation } from '../../../utils/escape.js';
|
|
|
34
35
|
* @param {Manifest} server_manifest
|
|
35
36
|
* @param {Manifest} client_manifest
|
|
36
37
|
* @param {string} assets_path
|
|
37
|
-
* @param {
|
|
38
|
+
* @param {Rolldown.RolldownOutput['output']} client_chunks
|
|
39
|
+
* @param {string} root
|
|
38
40
|
* @returns {void}
|
|
39
41
|
*/
|
|
40
42
|
/**
|
|
@@ -44,8 +46,8 @@ import { escape_for_interpolation } from '../../../utils/escape.js';
|
|
|
44
46
|
* @param {Manifest} server_manifest
|
|
45
47
|
* @param {Manifest | null} client_manifest
|
|
46
48
|
* @param {string | null} assets_path
|
|
47
|
-
* @param {
|
|
48
|
-
* @
|
|
49
|
+
* @param {Rolldown.RolldownOutput['output'] | null} client_chunks
|
|
50
|
+
* @param {string} root
|
|
49
51
|
*/
|
|
50
52
|
export function build_server_nodes(
|
|
51
53
|
out,
|
|
@@ -54,7 +56,8 @@ export function build_server_nodes(
|
|
|
54
56
|
server_manifest,
|
|
55
57
|
client_manifest,
|
|
56
58
|
assets_path,
|
|
57
|
-
client_chunks
|
|
59
|
+
client_chunks,
|
|
60
|
+
root
|
|
58
61
|
) {
|
|
59
62
|
mkdirp(`${out}/server/nodes`);
|
|
60
63
|
mkdirp(`${out}/server/stylesheets`);
|
|
@@ -156,7 +159,7 @@ export function build_server_nodes(
|
|
|
156
159
|
exports.push(
|
|
157
160
|
'let component_cache;',
|
|
158
161
|
`export const component = async () => component_cache ??= (await import('../${
|
|
159
|
-
resolve_symlinks(server_manifest, node.component).chunk.file
|
|
162
|
+
resolve_symlinks(server_manifest, node.component, root).chunk.file
|
|
160
163
|
}')).default;`
|
|
161
164
|
);
|
|
162
165
|
}
|
|
@@ -166,7 +169,7 @@ export function build_server_nodes(
|
|
|
166
169
|
exports.push(`export const universal = ${s(node.page_options, null, 2)};`);
|
|
167
170
|
} else {
|
|
168
171
|
imports.push(
|
|
169
|
-
`import * as universal from '../${resolve_symlinks(server_manifest, node.universal).chunk.file}';`
|
|
172
|
+
`import * as universal from '../${resolve_symlinks(server_manifest, node.universal, root).chunk.file}';`
|
|
170
173
|
);
|
|
171
174
|
// TODO: when building for analysis, explain why the file was loaded on the server if we fail to load it
|
|
172
175
|
exports.push('export { universal };');
|
|
@@ -176,7 +179,7 @@ export function build_server_nodes(
|
|
|
176
179
|
|
|
177
180
|
if (node.server) {
|
|
178
181
|
imports.push(
|
|
179
|
-
`import * as server from '../${resolve_symlinks(server_manifest, node.server).chunk.file}';`
|
|
182
|
+
`import * as server from '../${resolve_symlinks(server_manifest, node.server, root).chunk.file}';`
|
|
180
183
|
);
|
|
181
184
|
exports.push('export { server };');
|
|
182
185
|
exports.push(`export const server_id = ${s(node.server)};`);
|
|
@@ -188,7 +191,7 @@ export function build_server_nodes(
|
|
|
188
191
|
kit.output.bundleStrategy === 'split'
|
|
189
192
|
) {
|
|
190
193
|
const entry_path = `${normalizePath(kit.outDir)}/generated/client-optimized/nodes/${i}.js`;
|
|
191
|
-
const entry = find_deps(client_manifest, entry_path, true);
|
|
194
|
+
const entry = find_deps(client_manifest, entry_path, true, root);
|
|
192
195
|
|
|
193
196
|
// Eagerly load client stylesheets and fonts imported by the SSR-ed page to avoid FOUC.
|
|
194
197
|
// However, if it is not used during SSR (not present in the server manifest),
|
|
@@ -197,13 +200,13 @@ export function build_server_nodes(
|
|
|
197
200
|
/** @type {AssetDependencies | undefined} */
|
|
198
201
|
let component;
|
|
199
202
|
if (node.component) {
|
|
200
|
-
component = find_deps(server_manifest, node.component, true);
|
|
203
|
+
component = find_deps(server_manifest, node.component, true, root);
|
|
201
204
|
}
|
|
202
205
|
|
|
203
206
|
/** @type {AssetDependencies | undefined} */
|
|
204
207
|
let universal;
|
|
205
208
|
if (node.universal) {
|
|
206
|
-
universal = find_deps(server_manifest, node.universal, true);
|
|
209
|
+
universal = find_deps(server_manifest, node.universal, true, root);
|
|
207
210
|
}
|
|
208
211
|
|
|
209
212
|
/** @type {Set<string>} */
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
/** @import { ServerMetadata } from 'types' */
|
|
2
|
-
/** @import {
|
|
2
|
+
/** @import { Rolldown } from 'vite' */
|
|
3
3
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { Parser } from 'acorn';
|
|
7
7
|
import MagicString from 'magic-string';
|
|
8
|
-
import { posixify } from '../../../utils/
|
|
9
|
-
import { import_peer } from '../../../utils/import.js';
|
|
8
|
+
import { posixify } from '../../../utils/os.js';
|
|
10
9
|
|
|
11
10
|
/**
|
|
11
|
+
* @param {typeof import('vite')} vite
|
|
12
12
|
* @param {string} out
|
|
13
13
|
* @param {Array<{ hash: string, file: string }>} remotes
|
|
14
14
|
* @param {ServerMetadata} metadata
|
|
15
15
|
* @param {string} cwd
|
|
16
|
-
* @param {
|
|
16
|
+
* @param {Rolldown.RolldownOutput} server_bundle
|
|
17
17
|
* @param {NonNullable<import('vitest/config').ViteUserConfig['build']>['sourcemap']} sourcemap
|
|
18
18
|
*/
|
|
19
19
|
export async function treeshake_prerendered_remotes(
|
|
20
|
+
vite,
|
|
20
21
|
out,
|
|
21
22
|
remotes,
|
|
22
23
|
metadata,
|
|
@@ -26,8 +27,6 @@ export async function treeshake_prerendered_remotes(
|
|
|
26
27
|
) {
|
|
27
28
|
if (remotes.length === 0) return;
|
|
28
29
|
|
|
29
|
-
const vite = /** @type {typeof import('vite')} */ (await import_peer('vite'));
|
|
30
|
-
|
|
31
30
|
for (const remote of remotes) {
|
|
32
31
|
const exports_map = metadata.remotes.get(remote.hash);
|
|
33
32
|
if (!exports_map) continue;
|
|
@@ -90,7 +89,7 @@ export async function treeshake_prerendered_remotes(
|
|
|
90
89
|
const stubbed = modified_code.toString();
|
|
91
90
|
fs.writeFileSync(chunk_path, stubbed);
|
|
92
91
|
|
|
93
|
-
const bundle = /** @type {import('vite').
|
|
92
|
+
const bundle = /** @type {import('vite').Rolldown.RolldownOutput} */ (
|
|
94
93
|
await vite.build({
|
|
95
94
|
configFile: false,
|
|
96
95
|
build: {
|