@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,7 +1,7 @@
|
|
|
1
1
|
import { BROWSER, DEV } from 'esm-env';
|
|
2
2
|
import { writable } from 'svelte/store';
|
|
3
3
|
import { assets } from '$app/paths';
|
|
4
|
-
import { version } from '
|
|
4
|
+
import { version } from '$app/env';
|
|
5
5
|
import { noop } from '../../utils/functions.js';
|
|
6
6
|
import { PRELOAD_PRIORITIES } from './constants.js';
|
|
7
7
|
|
|
@@ -35,12 +35,12 @@ const warned = new WeakSet();
|
|
|
35
35
|
/** @typedef {keyof typeof valid_link_options} LinkOptionName */
|
|
36
36
|
|
|
37
37
|
const valid_link_options = /** @type {const} */ ({
|
|
38
|
-
'preload-code': ['', '
|
|
39
|
-
'preload-data': ['', '
|
|
40
|
-
keepfocus: ['', 'true', '
|
|
41
|
-
noscroll: ['', 'true', '
|
|
42
|
-
reload: ['', 'true', '
|
|
43
|
-
replacestate: ['', 'true', '
|
|
38
|
+
'preload-code': ['', 'false', 'tap', 'hover', 'viewport', 'eager'],
|
|
39
|
+
'preload-data': ['', 'false', 'tap', 'hover'],
|
|
40
|
+
keepfocus: ['', 'true', 'false'],
|
|
41
|
+
noscroll: ['', 'true', 'false'],
|
|
42
|
+
reload: ['', 'true', 'false'],
|
|
43
|
+
replacestate: ['', 'true', 'false']
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
/**
|
|
@@ -194,7 +194,6 @@ export function get_router_options(element) {
|
|
|
194
194
|
case '':
|
|
195
195
|
case 'true':
|
|
196
196
|
return true;
|
|
197
|
-
case 'off':
|
|
198
197
|
case 'false':
|
|
199
198
|
return false;
|
|
200
199
|
default:
|
|
@@ -203,8 +202,8 @@ export function get_router_options(element) {
|
|
|
203
202
|
}
|
|
204
203
|
|
|
205
204
|
return {
|
|
206
|
-
preload_code: levels[preload_code ?? '
|
|
207
|
-
preload_data: levels[preload_data ?? '
|
|
205
|
+
preload_code: levels[preload_code ?? 'false'],
|
|
206
|
+
preload_data: levels[preload_data ?? 'false'],
|
|
208
207
|
keepfocus: get_option_state(keepfocus),
|
|
209
208
|
noscroll: get_option_state(noscroll),
|
|
210
209
|
reload: get_option_state(reload),
|
|
@@ -271,7 +270,6 @@ export function create_updated_store() {
|
|
|
271
270
|
try {
|
|
272
271
|
const res = await fetch(`${assets}/${__SVELTEKIT_APP_VERSION_FILE__}`, {
|
|
273
272
|
headers: {
|
|
274
|
-
pragma: 'no-cache',
|
|
275
273
|
'cache-control': 'no-cache'
|
|
276
274
|
}
|
|
277
275
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** @import { RemoteForm } from '@sveltejs/kit' */
|
|
2
1
|
/** @import { BinaryFormMeta, InternalRemoteFormIssue } from 'types' */
|
|
3
2
|
/** @import { StandardSchemaV1 } from '@standard-schema/spec' */
|
|
4
3
|
|
|
@@ -146,7 +145,10 @@ export async function deserialize_binary_form(request) {
|
|
|
146
145
|
throw deserialize_error('no body');
|
|
147
146
|
}
|
|
148
147
|
|
|
149
|
-
|
|
148
|
+
// TODO: remove this workaround once we upgrade to TS 6.0
|
|
149
|
+
const reader = /** @type {ReadableStreamDefaultReader<Uint8Array<ArrayBuffer>>} */ (
|
|
150
|
+
request.body.getReader()
|
|
151
|
+
);
|
|
150
152
|
|
|
151
153
|
/** @type {Array<Promise<Uint8Array<ArrayBuffer> | undefined>>} */
|
|
152
154
|
const chunks = [];
|
|
@@ -858,42 +860,3 @@ export function build_path_string(path) {
|
|
|
858
860
|
|
|
859
861
|
return result;
|
|
860
862
|
}
|
|
861
|
-
|
|
862
|
-
/**
|
|
863
|
-
* @param {RemoteForm<any, any>} instance
|
|
864
|
-
* @deprecated remove in 3.0
|
|
865
|
-
*/
|
|
866
|
-
export function throw_on_old_property_access(instance) {
|
|
867
|
-
Object.defineProperty(instance, 'field', {
|
|
868
|
-
value: (/** @type {string} */ name) => {
|
|
869
|
-
const new_name = name.endsWith('[]') ? name.slice(0, -2) : name;
|
|
870
|
-
throw new Error(
|
|
871
|
-
`\`form.field\` has been removed: Instead of \`<input name={form.field('${name}')} />\` do \`<input {...form.fields.${new_name}.as(type)} />\``
|
|
872
|
-
);
|
|
873
|
-
}
|
|
874
|
-
});
|
|
875
|
-
|
|
876
|
-
for (const property of ['input', 'issues']) {
|
|
877
|
-
Object.defineProperty(instance, property, {
|
|
878
|
-
get() {
|
|
879
|
-
const new_name = property === 'issues' ? 'issues' : 'value';
|
|
880
|
-
return new Proxy(
|
|
881
|
-
{},
|
|
882
|
-
{
|
|
883
|
-
get(_, prop) {
|
|
884
|
-
const prop_string = typeof prop === 'string' ? prop : String(prop);
|
|
885
|
-
const old =
|
|
886
|
-
prop_string.includes('[') || prop_string.includes('.')
|
|
887
|
-
? `['${prop_string}']`
|
|
888
|
-
: `.${prop_string}`;
|
|
889
|
-
const replacement = `.${prop_string}.${new_name}()`;
|
|
890
|
-
throw new Error(
|
|
891
|
-
`\`form.${property}\` has been removed: Instead of \`form.${property}${old}\` write \`form.fields${replacement}\``
|
|
892
|
-
);
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
);
|
|
896
|
-
}
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
|
-
}
|
|
@@ -4,9 +4,6 @@ import { normalize_path, resolve } from '../../utils/url.js';
|
|
|
4
4
|
import { add_data_suffix } from '../pathname.js';
|
|
5
5
|
import { text_encoder } from '../utils.js';
|
|
6
6
|
|
|
7
|
-
// eslint-disable-next-line no-control-regex -- control characters are invalid in cookie names
|
|
8
|
-
const INVALID_COOKIE_CHARACTER_REGEX = /[\x00-\x1F\x7F()<>@,;:"/[\]?={} \t]/;
|
|
9
|
-
|
|
10
7
|
/**
|
|
11
8
|
* Tracks all cookies set during dev mode so we can emit warnings
|
|
12
9
|
* when we detect that there's likely cookie misusage due to wrong paths
|
|
@@ -20,14 +17,6 @@ const cookie_paths = {};
|
|
|
20
17
|
*/
|
|
21
18
|
const MAX_COOKIE_SIZE = 4129;
|
|
22
19
|
|
|
23
|
-
// TODO 3.0 remove this check
|
|
24
|
-
/** @param {import('./page/types.js').Cookie['options']} options */
|
|
25
|
-
function validate_options(options) {
|
|
26
|
-
if (options?.path === undefined) {
|
|
27
|
-
throw new Error('You must specify a `path` when setting, deleting or serializing cookies');
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
20
|
/**
|
|
32
21
|
* Generates a unique key for a cookie based on its domain, path, and name in
|
|
33
22
|
* the format: `<domain>/<path>?<name>`.
|
|
@@ -49,7 +38,9 @@ function generate_cookie_key(domain, path, name) {
|
|
|
49
38
|
*/
|
|
50
39
|
export function get_cookies(request, url) {
|
|
51
40
|
const header = request.headers.get('cookie') ?? '';
|
|
52
|
-
const initial_cookies =
|
|
41
|
+
const initial_cookies = /** @type {Record<string, string>} */ (
|
|
42
|
+
parse(header, { decode: (value) => value })
|
|
43
|
+
);
|
|
53
44
|
|
|
54
45
|
/** @type {string | undefined} */
|
|
55
46
|
let normalized_url;
|
|
@@ -57,9 +48,10 @@ export function get_cookies(request, url) {
|
|
|
57
48
|
/** @type {Map<string, import('./page/types.js').Cookie>} */
|
|
58
49
|
const new_cookies = new Map();
|
|
59
50
|
|
|
60
|
-
/** @type {import('cookie').
|
|
51
|
+
/** @type {import('cookie').SerializeOptions} */
|
|
61
52
|
const defaults = {
|
|
62
53
|
httpOnly: true,
|
|
54
|
+
path: '/',
|
|
63
55
|
sameSite: 'lax',
|
|
64
56
|
secure: url.hostname === 'localhost' && url.protocol === 'http:' ? false : true
|
|
65
57
|
};
|
|
@@ -73,7 +65,7 @@ export function get_cookies(request, url) {
|
|
|
73
65
|
|
|
74
66
|
/**
|
|
75
67
|
* @param {string} name
|
|
76
|
-
* @param {import('cookie').
|
|
68
|
+
* @param {import('cookie').ParseOptions} [opts]
|
|
77
69
|
*/
|
|
78
70
|
get(name, opts) {
|
|
79
71
|
// Look for the most specific matching cookie from new_cookies
|
|
@@ -115,7 +107,7 @@ export function get_cookies(request, url) {
|
|
|
115
107
|
},
|
|
116
108
|
|
|
117
109
|
/**
|
|
118
|
-
* @param {import('cookie').
|
|
110
|
+
* @param {import('cookie').ParseOptions} [opts]
|
|
119
111
|
*/
|
|
120
112
|
getAll(opts) {
|
|
121
113
|
const cookies = parse(header, { decode: opts?.decode });
|
|
@@ -142,47 +134,37 @@ export function get_cookies(request, url) {
|
|
|
142
134
|
cookies[c.name] = c.value;
|
|
143
135
|
}
|
|
144
136
|
|
|
145
|
-
return
|
|
137
|
+
return /** @type {Array<{ name: string; value: string }>} */ (
|
|
138
|
+
Object.entries(cookies)
|
|
139
|
+
.filter(([, value]) => value != null)
|
|
140
|
+
.map(([name, value]) => ({ name, value }))
|
|
141
|
+
);
|
|
146
142
|
},
|
|
147
143
|
|
|
148
144
|
/**
|
|
149
145
|
* @param {string} name
|
|
150
146
|
* @param {string} value
|
|
151
|
-
* @param {import('
|
|
147
|
+
* @param {import('cookie').SerializeOptions} options
|
|
152
148
|
*/
|
|
153
149
|
set(name, value, options) {
|
|
154
|
-
// TODO: remove this check in 3.0
|
|
155
|
-
const illegal_characters = name.match(INVALID_COOKIE_CHARACTER_REGEX);
|
|
156
|
-
if (illegal_characters) {
|
|
157
|
-
console.warn(
|
|
158
|
-
`The cookie name "${name}" will be invalid in SvelteKit 3.0 as it contains ${illegal_characters.join(
|
|
159
|
-
' and '
|
|
160
|
-
)}. See RFC 2616 for more details https://datatracker.ietf.org/doc/html/rfc2616#section-2.2`
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
validate_options(options);
|
|
165
150
|
set_internal(name, value, { ...defaults, ...options });
|
|
166
151
|
},
|
|
167
152
|
|
|
168
153
|
/**
|
|
169
154
|
* @param {string} name
|
|
170
|
-
*
|
|
155
|
+
* @param {import('cookie').SerializeOptions} options
|
|
171
156
|
*/
|
|
172
157
|
delete(name, options) {
|
|
173
|
-
validate_options(options);
|
|
174
158
|
cookies.set(name, '', { ...options, maxAge: 0 });
|
|
175
159
|
},
|
|
176
160
|
|
|
177
161
|
/**
|
|
178
162
|
* @param {string} name
|
|
179
163
|
* @param {string} value
|
|
180
|
-
*
|
|
164
|
+
* @param {import('cookie').SerializeOptions} options
|
|
181
165
|
*/
|
|
182
166
|
serialize(name, value, options) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
let path = options.path;
|
|
167
|
+
let path = options.path ?? '/';
|
|
186
168
|
|
|
187
169
|
if (!options.domain || options.domain === url.hostname) {
|
|
188
170
|
if (!normalized_url) {
|
|
@@ -217,7 +199,9 @@ export function get_cookies(request, url) {
|
|
|
217
199
|
|
|
218
200
|
// explicit header has highest precedence
|
|
219
201
|
if (header) {
|
|
220
|
-
const parsed =
|
|
202
|
+
const parsed = /** @type {Record<string, string>} */ (
|
|
203
|
+
parse(header, { decode: (value) => value })
|
|
204
|
+
);
|
|
221
205
|
for (const name in parsed) {
|
|
222
206
|
combined_cookies[name] = parsed[name];
|
|
223
207
|
}
|
|
@@ -234,7 +218,7 @@ export function get_cookies(request, url) {
|
|
|
234
218
|
/**
|
|
235
219
|
* @param {string} name
|
|
236
220
|
* @param {string} value
|
|
237
|
-
* @param {import('
|
|
221
|
+
* @param {import('cookie').SerializeOptions} options
|
|
238
222
|
*/
|
|
239
223
|
function set_internal(name, value, options) {
|
|
240
224
|
if (!normalized_url) {
|
|
@@ -242,7 +226,7 @@ export function get_cookies(request, url) {
|
|
|
242
226
|
return;
|
|
243
227
|
}
|
|
244
228
|
|
|
245
|
-
let path = options.path;
|
|
229
|
+
let path = options.path ?? '/';
|
|
246
230
|
|
|
247
231
|
if (!options.domain || options.domain === url.hostname) {
|
|
248
232
|
path = resolve(normalized_url, path);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as devalue from 'devalue';
|
|
2
|
+
import { rendered_env } from '__sveltekit/env';
|
|
2
3
|
|
|
3
4
|
/** @type {string} */
|
|
4
|
-
let
|
|
5
|
+
let payload;
|
|
5
6
|
|
|
6
7
|
/** @type {string} */
|
|
7
8
|
let etag;
|
|
@@ -14,7 +15,10 @@ let headers;
|
|
|
14
15
|
* @returns {Response}
|
|
15
16
|
*/
|
|
16
17
|
export function get_public_env(request) {
|
|
17
|
-
|
|
18
|
+
const env = rendered_env;
|
|
19
|
+
const script = request.url.endsWith('.script.js');
|
|
20
|
+
|
|
21
|
+
payload ??= devalue.uneval(env);
|
|
18
22
|
etag ??= `W/${Date.now()}`;
|
|
19
23
|
headers ??= new Headers({
|
|
20
24
|
'content-type': 'application/javascript; charset=utf-8',
|
|
@@ -25,5 +29,9 @@ export function get_public_env(request) {
|
|
|
25
29
|
return new Response(undefined, { status: 304, headers });
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
if (script) {
|
|
33
|
+
return new Response(`globalThis.__sveltekit_sw={env:${payload}}`, { headers });
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return new Response(`export const env=${payload}`, { headers });
|
|
29
37
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { parseSetCookie } from 'cookie';
|
|
2
2
|
import { noop } from '../../utils/functions.js';
|
|
3
|
-
import { get_set_cookies } from '../../utils/http.js';
|
|
4
3
|
import { respond } from './respond.js';
|
|
5
4
|
import * as paths from '$app/paths/internal/server';
|
|
6
5
|
import { read_implementation } from '__sveltekit/server';
|
|
@@ -83,9 +82,8 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
|
|
|
83
82
|
|
|
84
83
|
// handle fetch requests for static assets. e.g. prebaked data, etc.
|
|
85
84
|
// we need to support everything the browser's fetch supports
|
|
86
|
-
const prefix = paths.assets || paths.base;
|
|
87
85
|
const filename = (
|
|
88
|
-
decoded.startsWith(
|
|
86
|
+
decoded.startsWith(paths.assets) ? decoded.slice(paths.assets.length) : decoded
|
|
89
87
|
).slice(1);
|
|
90
88
|
const filename_html = `${filename}/index.html`; // path may also match path/index.html
|
|
91
89
|
|
|
@@ -153,18 +151,16 @@ export function create_fetch({ event, options, manifest, state, get_cookie_heade
|
|
|
153
151
|
|
|
154
152
|
const response = await internal_fetch(request, options, manifest, state);
|
|
155
153
|
|
|
156
|
-
for (const str of
|
|
157
|
-
const { name, value, ...options } =
|
|
158
|
-
decodeValues: false
|
|
159
|
-
});
|
|
154
|
+
for (const str of response.headers.getSetCookie()) {
|
|
155
|
+
const { name, value, ...options } = parseSetCookie(str, { decode: (v) => v });
|
|
160
156
|
|
|
161
157
|
const path = options.path ?? (url.pathname.split('/').slice(0, -1).join('/') || '/');
|
|
162
158
|
|
|
163
159
|
// options.sameSite is string, something more specific is required - type cast is safe
|
|
164
|
-
set_internal(name, value, {
|
|
160
|
+
set_internal(name, /** @type {string} */ (value), {
|
|
165
161
|
path,
|
|
166
162
|
encode: (value) => value,
|
|
167
|
-
.../** @type {import('cookie').
|
|
163
|
+
.../** @type {import('cookie').SerializeOptions} */ (options)
|
|
168
164
|
});
|
|
169
165
|
}
|
|
170
166
|
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
/** @import { PromiseWithResolvers } from '../../utils/promise.js' */
|
|
2
1
|
import { noop } from '../../utils/functions.js';
|
|
3
|
-
import { with_resolvers } from '../../utils/promise.js';
|
|
4
2
|
import { IN_WEBCONTAINER } from './constants.js';
|
|
5
3
|
import { respond } from './respond.js';
|
|
6
|
-
import { set_private_env, set_public_env } from '../shared-server.js';
|
|
7
4
|
import { options, get_hooks } from '__SERVER__/internal.js';
|
|
8
|
-
import { filter_env } from '../../utils/env.js';
|
|
9
5
|
import { format_server_error } from './utils.js';
|
|
10
6
|
import { set_read_implementation, set_manifest } from '__sveltekit/server';
|
|
7
|
+
import { set_env } from '__sveltekit/env';
|
|
11
8
|
import { set_app } from './app.js';
|
|
12
9
|
|
|
13
10
|
/** @type {Promise<any>} */
|
|
@@ -36,7 +33,9 @@ export class Server {
|
|
|
36
33
|
|
|
37
34
|
/** @type {typeof respond} */
|
|
38
35
|
this.respond = async (...args) => {
|
|
39
|
-
const { promise, resolve } = /** @type {PromiseWithResolvers<void>} */ (
|
|
36
|
+
const { promise, resolve } = /** @type {PromiseWithResolvers<void>} */ (
|
|
37
|
+
Promise.withResolvers()
|
|
38
|
+
);
|
|
40
39
|
|
|
41
40
|
const previous = current;
|
|
42
41
|
current = promise;
|
|
@@ -58,10 +57,7 @@ export class Server {
|
|
|
58
57
|
// been done already.
|
|
59
58
|
|
|
60
59
|
// set env, in case it's used in initialisation
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
set_private_env(filter_env(env, env_private_prefix, env_public_prefix));
|
|
64
|
-
set_public_env(filter_env(env, env_public_prefix, env_private_prefix));
|
|
60
|
+
set_env(env);
|
|
65
61
|
|
|
66
62
|
if (read) {
|
|
67
63
|
// Wrap the read function to handle MaybePromise<ReadableStream>
|
|
@@ -8,7 +8,6 @@ import { serialize_data } from './serialize_data.js';
|
|
|
8
8
|
import { s } from '../../../utils/misc.js';
|
|
9
9
|
import { Csp } from './csp.js';
|
|
10
10
|
import { uneval_action_response } from './actions.js';
|
|
11
|
-
import { public_env } from '../../shared-server.js';
|
|
12
11
|
import { SVELTE_KIT_ASSETS } from '../../../constants.js';
|
|
13
12
|
import { SCHEME } from '../../../utils/url.js';
|
|
14
13
|
import { create_server_routing_response, generate_route_object } from './server_routing.js';
|
|
@@ -23,6 +22,7 @@ import {
|
|
|
23
22
|
} from '../utils.js';
|
|
24
23
|
import { create_remote_key } from '../../shared.js';
|
|
25
24
|
import { get_status } from '../../../utils/error.js';
|
|
25
|
+
import * as env from '__sveltekit/env';
|
|
26
26
|
|
|
27
27
|
// TODO rename this function/module
|
|
28
28
|
|
|
@@ -293,7 +293,7 @@ export async function render_response({
|
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
-
const head = new Head(rendered.head
|
|
296
|
+
const head = new Head(rendered.head);
|
|
297
297
|
let body = rendered.html;
|
|
298
298
|
|
|
299
299
|
/** @param {string} path */
|
|
@@ -331,7 +331,7 @@ export async function render_response({
|
|
|
331
331
|
// include them in disabled state so that Vite can detect them and doesn't try to add them
|
|
332
332
|
attributes.push('disabled', 'media="(max-width: 0)"');
|
|
333
333
|
} else {
|
|
334
|
-
if (resolve_opts.preload({ type: 'css', path })) {
|
|
334
|
+
if (options.link_header_preload && resolve_opts.preload({ type: 'css', path })) {
|
|
335
335
|
link_headers.add(`<${encodeURI(path)}>; rel="preload"; as="style"; nopush`);
|
|
336
336
|
}
|
|
337
337
|
}
|
|
@@ -345,11 +345,18 @@ export async function render_response({
|
|
|
345
345
|
if (resolve_opts.preload({ type: 'font', path })) {
|
|
346
346
|
const ext = dep.slice(dep.lastIndexOf('.') + 1);
|
|
347
347
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
348
|
+
if (options.link_header_preload && !state.prerendering) {
|
|
349
|
+
link_headers.add(
|
|
350
|
+
`<${encodeURI(path)}>; rel="preload"; as="font"; type="font/${ext}"; crossorigin; nopush`
|
|
351
|
+
);
|
|
352
|
+
} else {
|
|
353
|
+
head.add_link_tag(path, [
|
|
354
|
+
'rel="preload"',
|
|
355
|
+
'as="font"',
|
|
356
|
+
`type="font/${ext}"`,
|
|
357
|
+
'crossorigin'
|
|
358
|
+
]);
|
|
359
|
+
}
|
|
353
360
|
}
|
|
354
361
|
}
|
|
355
362
|
|
|
@@ -376,15 +383,19 @@ export async function render_response({
|
|
|
376
383
|
(path) => resolve_opts.preload({ type: 'js', path })
|
|
377
384
|
);
|
|
378
385
|
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
link_headers.add(`<${encodeURI(path)}>; rel="modulepreload"; nopush`);
|
|
386
|
+
/** @type {(path: string) => void} */
|
|
387
|
+
let add_preload;
|
|
382
388
|
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
389
|
+
// see the kit.output.preloadStrategy option for details on why we have multiple options here
|
|
390
|
+
if (options.link_header_preload && !state.prerendering) {
|
|
391
|
+
add_preload = (path) =>
|
|
392
|
+
link_headers.add(`<${encodeURI(path)}>; rel="modulepreload"; nopush`);
|
|
393
|
+
} else {
|
|
394
|
+
add_preload = (path) => head.add_link_tag(path, ['rel="modulepreload"']);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
for (const path of included_modulepreloads) {
|
|
398
|
+
add_preload(path);
|
|
388
399
|
}
|
|
389
400
|
}
|
|
390
401
|
|
|
@@ -400,11 +411,11 @@ export async function render_response({
|
|
|
400
411
|
|
|
401
412
|
const blocks = [];
|
|
402
413
|
|
|
403
|
-
// when serving a prerendered page in an app that uses $env/
|
|
414
|
+
// when serving a prerendered page in an app that uses $app/env/public, we must
|
|
404
415
|
// import the env.js module so that it evaluates before any user code can evaluate.
|
|
405
416
|
// TODO revert to using top-level await once https://bugs.webkit.org/show_bug.cgi?id=242740 is fixed
|
|
406
417
|
// https://github.com/sveltejs/kit/pull/11601
|
|
407
|
-
const load_env_eagerly = client.uses_env_dynamic_public && state.prerendering;
|
|
418
|
+
const load_env_eagerly = client.uses_env_dynamic_public && state.prerendering; // TODO implement uses_env_dynamic_public
|
|
408
419
|
|
|
409
420
|
const properties = [`base: ${base_expression}`];
|
|
410
421
|
|
|
@@ -413,7 +424,7 @@ export async function render_response({
|
|
|
413
424
|
}
|
|
414
425
|
|
|
415
426
|
if (client.uses_env_dynamic_public) {
|
|
416
|
-
properties.push(`env: ${load_env_eagerly ? 'null' :
|
|
427
|
+
properties.push(`env: ${load_env_eagerly ? 'null' : devalue.uneval(env.rendered_env)}`);
|
|
417
428
|
}
|
|
418
429
|
|
|
419
430
|
if (chunks) {
|
|
@@ -667,7 +678,7 @@ export async function render_response({
|
|
|
667
678
|
headers.set('content-security-policy-report-only', report_only_header);
|
|
668
679
|
}
|
|
669
680
|
|
|
670
|
-
if (link_headers.size) {
|
|
681
|
+
if (options.link_header_preload && link_headers.size) {
|
|
671
682
|
headers.set('link', Array.from(link_headers).join(', '));
|
|
672
683
|
}
|
|
673
684
|
}
|
|
@@ -677,7 +688,7 @@ export async function render_response({
|
|
|
677
688
|
body,
|
|
678
689
|
assets,
|
|
679
690
|
nonce: /** @type {string} */ (csp.nonce),
|
|
680
|
-
env:
|
|
691
|
+
env: env.explicit_public_env
|
|
681
692
|
});
|
|
682
693
|
|
|
683
694
|
// TODO flush chunks as early as we can
|
|
@@ -734,32 +745,26 @@ export async function render_response({
|
|
|
734
745
|
|
|
735
746
|
class Head {
|
|
736
747
|
#rendered;
|
|
737
|
-
#prerendering;
|
|
738
748
|
/** @type {string[]} */
|
|
739
749
|
#http_equiv = [];
|
|
740
750
|
/** @type {string[]} */
|
|
741
751
|
#link_tags = [];
|
|
742
752
|
/** @type {string[]} */
|
|
743
|
-
#script_preloads = [];
|
|
744
|
-
/** @type {string[]} */
|
|
745
753
|
#style_tags = [];
|
|
746
754
|
/** @type {string[]} */
|
|
747
755
|
#stylesheet_links = [];
|
|
748
756
|
|
|
749
757
|
/**
|
|
750
758
|
* @param {string} rendered
|
|
751
|
-
* @param {boolean} prerendering
|
|
752
759
|
*/
|
|
753
|
-
constructor(rendered
|
|
760
|
+
constructor(rendered) {
|
|
754
761
|
this.#rendered = rendered;
|
|
755
|
-
this.#prerendering = prerendering;
|
|
756
762
|
}
|
|
757
763
|
|
|
758
764
|
build() {
|
|
759
765
|
return [
|
|
760
766
|
...this.#http_equiv,
|
|
761
767
|
...this.#link_tags,
|
|
762
|
-
...this.#script_preloads,
|
|
763
768
|
this.#rendered,
|
|
764
769
|
...this.#style_tags,
|
|
765
770
|
...this.#stylesheet_links
|
|
@@ -784,25 +789,16 @@ class Head {
|
|
|
784
789
|
this.#stylesheet_links.push(`<link href="${href}" ${attributes.join(' ')}>`);
|
|
785
790
|
}
|
|
786
791
|
|
|
787
|
-
/** @param {string} href */
|
|
788
|
-
add_script_preload(href) {
|
|
789
|
-
this.#script_preloads.push(
|
|
790
|
-
`<link rel="preload" as="script" crossorigin="anonymous" href="${href}">`
|
|
791
|
-
);
|
|
792
|
-
}
|
|
793
|
-
|
|
794
792
|
/**
|
|
795
793
|
* @param {string} href
|
|
796
794
|
* @param {string[]} attributes
|
|
797
795
|
*/
|
|
798
796
|
add_link_tag(href, attributes) {
|
|
799
|
-
if (!this.#prerendering) return;
|
|
800
797
|
this.#link_tags.push(`<link href="${href}" ${attributes.join(' ')}>`);
|
|
801
798
|
}
|
|
802
799
|
|
|
803
800
|
/** @param {string} tag */
|
|
804
801
|
add_http_equiv(tag) {
|
|
805
|
-
if (!this.#prerendering) return;
|
|
806
802
|
this.#http_equiv.push(tag);
|
|
807
803
|
}
|
|
808
804
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SerializeOptions } from 'cookie';
|
|
2
2
|
import {
|
|
3
3
|
CspDirectives,
|
|
4
4
|
ServerDataNode,
|
|
@@ -39,7 +39,9 @@ export interface CspOpts {
|
|
|
39
39
|
export interface Cookie {
|
|
40
40
|
name: string;
|
|
41
41
|
value: string;
|
|
42
|
-
options:
|
|
42
|
+
options: SerializeOptions & {
|
|
43
|
+
path: string;
|
|
44
|
+
};
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
export type ServerDataSerializer = {
|
|
@@ -8,7 +8,7 @@ import { is_endpoint_request, render_endpoint } from './endpoint.js';
|
|
|
8
8
|
import { render_page } from './page/index.js';
|
|
9
9
|
import { render_response } from './page/render.js';
|
|
10
10
|
import { respond_with_error } from './page/respond_with_error.js';
|
|
11
|
-
import {
|
|
11
|
+
import { is_form_content_type } from '../../utils/http.js';
|
|
12
12
|
import {
|
|
13
13
|
handle_fatal_error,
|
|
14
14
|
has_prerendered_path,
|
|
@@ -317,7 +317,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
317
317
|
return resolve_route(resolved_path, new URL(request.url), manifest);
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
-
if (resolved_path === `/${app_dir}/env.js`) {
|
|
320
|
+
if (resolved_path === `/${app_dir}/env.js` || resolved_path === `/${app_dir}/env.script.js`) {
|
|
321
321
|
return get_public_env(request);
|
|
322
322
|
}
|
|
323
323
|
|
|
@@ -517,7 +517,7 @@ export async function internal_respond(request, options, manifest, state) {
|
|
|
517
517
|
if (value) headers.set(key, value);
|
|
518
518
|
}
|
|
519
519
|
|
|
520
|
-
for (const cookie of
|
|
520
|
+
for (const cookie of response.headers.getSetCookie()) {
|
|
521
521
|
headers.append('set-cookie', cookie);
|
|
522
522
|
}
|
|
523
523
|
|
|
@@ -9,6 +9,7 @@ import { negotiate } from '../../utils/http.js';
|
|
|
9
9
|
import { fix_stack_trace } from '../shared-server.js';
|
|
10
10
|
import { ENDPOINT_METHODS } from '../../constants.js';
|
|
11
11
|
import { escape_html } from '../../utils/escape.js';
|
|
12
|
+
import * as path from '../../utils/path.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* @param {Partial<Record<import('types').HttpMethod, any>>} mod
|
|
@@ -212,10 +213,7 @@ let relative = (file) => file;
|
|
|
212
213
|
|
|
213
214
|
if (DEV) {
|
|
214
215
|
try {
|
|
215
|
-
|
|
216
|
-
const process = await import('node:process');
|
|
217
|
-
|
|
218
|
-
relative = (file) => path.relative(process.cwd(), file);
|
|
216
|
+
relative = (file) => path.relative(__SVELTEKIT_ROOT__, file);
|
|
219
217
|
} catch {
|
|
220
218
|
// do nothing
|
|
221
219
|
}
|
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `$env/dynamic/private`
|
|
3
|
-
* @type {Record<string, string>}
|
|
4
|
-
*/
|
|
5
|
-
export let private_env = {};
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* `$env/dynamic/public`
|
|
9
|
-
* @type {Record<string, string>}
|
|
10
|
-
*/
|
|
11
|
-
export let public_env = {};
|
|
12
|
-
|
|
13
1
|
/** @param {any} error */
|
|
14
2
|
export let fix_stack_trace = (error) => error?.stack;
|
|
15
3
|
|
|
16
|
-
/** @type {(environment: Record<string, string>) => void} */
|
|
17
|
-
export function set_private_env(environment) {
|
|
18
|
-
private_env = environment;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** @type {(environment: Record<string, string>) => void} */
|
|
22
|
-
export function set_public_env(environment) {
|
|
23
|
-
public_env = environment;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
4
|
/** @param {(error: Error) => string} value */
|
|
27
5
|
export function set_fix_stack_trace(value) {
|
|
28
6
|
fix_stack_trace = value;
|