@sveltejs/kit 2.63.0 → 3.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/package.json +17 -22
  2. package/src/cli.js +19 -16
  3. package/src/core/adapt/builder.js +25 -77
  4. package/src/core/adapt/index.js +6 -4
  5. package/src/core/config/index.js +12 -84
  6. package/src/core/config/options.js +36 -46
  7. package/src/core/env.js +5 -130
  8. package/src/core/generate_manifest/find_server_assets.js +3 -2
  9. package/src/core/generate_manifest/index.js +11 -3
  10. package/src/core/postbuild/analyse.js +19 -16
  11. package/src/core/postbuild/fallback.js +0 -3
  12. package/src/core/postbuild/prerender.js +18 -17
  13. package/src/core/postbuild/queue.js +3 -4
  14. package/src/core/sync/create_manifest_data/index.js +16 -18
  15. package/src/core/sync/sync.js +30 -25
  16. package/src/core/sync/utils.js +0 -15
  17. package/src/core/sync/write_ambient.js +3 -54
  18. package/src/core/sync/write_client_manifest.js +8 -9
  19. package/src/core/sync/write_env.js +5 -1
  20. package/src/core/sync/write_non_ambient.js +7 -7
  21. package/src/core/sync/write_root.js +40 -88
  22. package/src/core/sync/write_server.js +16 -23
  23. package/src/core/sync/write_tsconfig.js +28 -24
  24. package/src/core/sync/write_types/index.js +31 -25
  25. package/src/core/utils.js +14 -11
  26. package/src/exports/index.js +8 -21
  27. package/src/exports/node/index.js +8 -13
  28. package/src/exports/public.d.ts +35 -76
  29. package/src/exports/vite/build/build_server.js +14 -11
  30. package/src/exports/vite/build/remote.js +6 -7
  31. package/src/exports/vite/build/utils.js +7 -5
  32. package/src/exports/vite/dev/index.js +30 -31
  33. package/src/exports/vite/index.js +938 -732
  34. package/src/exports/vite/module_ids.js +1 -6
  35. package/src/exports/vite/options.js +17 -0
  36. package/src/exports/vite/preview/index.js +3 -5
  37. package/src/exports/vite/static_analysis/index.js +11 -5
  38. package/src/exports/vite/utils.js +9 -45
  39. package/src/runtime/app/env/internal.js +3 -0
  40. package/src/runtime/app/env/public/client.js +0 -6
  41. package/src/runtime/app/env/public/server.js +0 -6
  42. package/src/runtime/app/environment/index.js +3 -7
  43. package/src/runtime/app/server/index.js +4 -2
  44. package/src/runtime/app/server/remote/form.js +0 -51
  45. package/src/runtime/app/server/remote/query.js +0 -7
  46. package/src/runtime/app/server/remote/shared.js +4 -3
  47. package/src/runtime/app/state/client.js +1 -12
  48. package/src/runtime/client/client.js +1 -1
  49. package/src/runtime/client/constants.js +0 -1
  50. package/src/runtime/client/remote-functions/form.svelte.js +0 -31
  51. package/src/runtime/client/remote-functions/query/index.js +2 -2
  52. package/src/runtime/client/remote-functions/query/instance.svelte.js +1 -2
  53. package/src/runtime/client/remote-functions/query-batch.svelte.js +2 -2
  54. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +5 -8
  55. package/src/runtime/client/utils.js +8 -10
  56. package/src/runtime/components/{svelte-5/layout.svelte → layout.svelte} +1 -1
  57. package/src/runtime/form-utils.js +4 -41
  58. package/src/runtime/server/cookie.js +21 -37
  59. package/src/runtime/server/env_module.js +1 -3
  60. package/src/runtime/server/fetch.js +6 -10
  61. package/src/runtime/server/index.js +3 -9
  62. package/src/runtime/server/page/render.js +32 -44
  63. package/src/runtime/server/page/types.d.ts +4 -2
  64. package/src/runtime/server/respond.js +2 -2
  65. package/src/runtime/server/utils.js +2 -4
  66. package/src/runtime/shared-server.js +0 -22
  67. package/src/runtime/shared.js +0 -15
  68. package/src/types/global-private.d.ts +5 -1
  69. package/src/types/internal.d.ts +3 -8
  70. package/src/utils/css.js +3 -19
  71. package/src/utils/filesystem.js +1 -30
  72. package/src/utils/http.js +0 -21
  73. package/src/utils/import.js +7 -6
  74. package/src/utils/os.js +7 -0
  75. package/src/utils/path.js +23 -0
  76. package/src/utils/shared-iterator.js +3 -0
  77. package/src/utils/streaming.js +2 -4
  78. package/src/utils/url.js +1 -1
  79. package/src/utils/vite.js +28 -0
  80. package/src/version.js +1 -1
  81. package/types/index.d.ts +45 -138
  82. package/types/index.d.ts.map +1 -8
  83. package/src/exports/vite/build/build_service_worker.js +0 -165
  84. package/src/runtime/app/environment/types.d.ts +0 -19
  85. package/src/runtime/components/svelte-4/error.svelte +0 -6
  86. package/src/runtime/components/svelte-4/layout.svelte +0 -1
  87. package/src/runtime/env/dynamic/private.js +0 -1
  88. package/src/runtime/env/dynamic/public.js +0 -1
  89. package/src/types/synthetic/$env+dynamic+private.md +0 -43
  90. package/src/types/synthetic/$env+dynamic+public.md +0 -46
  91. package/src/types/synthetic/$env+static+private.md +0 -31
  92. package/src/types/synthetic/$env+static+public.md +0 -31
  93. package/src/utils/env.js +0 -13
  94. package/src/utils/promise.js +0 -29
  95. /package/src/runtime/components/{svelte-5/error.svelte → error.svelte} +0 -0
@@ -1,9 +1,9 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import process from 'node:process';
4
3
  import MagicString from 'magic-string';
5
- import { posixify, rimraf, walk } from '../../../utils/filesystem.js';
4
+ import { rimraf, walk } from '../../../utils/filesystem.js';
6
5
  import { compact } from '../../../utils/array.js';
6
+ import { posixify } from '../../../utils/os.js';
7
7
  import { ts } from '../ts.js';
8
8
  const remove_relative_parent_traversals = (/** @type {string} */ path) =>
9
9
  path.replace(/\.\.\//g, '');
@@ -25,21 +25,20 @@ const is_whitespace = (/** @type {string} */ char) => /\s/.test(char);
25
25
  * @typedef {Map<import('types').PageNode, {route: import('types').RouteData, proxies: Proxies}>} RoutesMap
26
26
  */
27
27
 
28
- const cwd = process.cwd();
29
-
30
28
  /**
31
29
  * Creates types for the whole manifest
32
30
  * @param {import('types').ValidatedConfig} config
33
31
  * @param {import('types').ManifestData} manifest_data
32
+ * @param {string} root The project root directory
34
33
  */
35
- export function write_all_types(config, manifest_data) {
34
+ export function write_all_types(config, manifest_data, root) {
36
35
  if (!ts) return;
37
36
 
38
37
  const types_dir = `${config.kit.outDir}/types`;
39
38
 
40
39
  // empty out files that no longer need to exist
41
40
  const routes_dir = remove_relative_parent_traversals(
42
- posixify(path.relative('.', config.kit.files.routes))
41
+ posixify(path.relative(root, config.kit.files.routes))
43
42
  );
44
43
  const expected_directories = new Set(
45
44
  manifest_data.routes.map((route) => path.join(routes_dir, route.id))
@@ -109,7 +108,7 @@ export function write_all_types(config, manifest_data) {
109
108
 
110
109
  const source_last_updated = Math.max(
111
110
  // ctimeMs includes move operations whereas mtimeMs does not
112
- ...input_files.map((file) => fs.statSync(file).ctimeMs)
111
+ ...input_files.map((file) => fs.statSync(path.resolve(root, file)).ctimeMs)
113
112
  );
114
113
  const types_last_updated = Math.max(...output_files.map((file) => file.updated));
115
114
 
@@ -124,7 +123,7 @@ export function write_all_types(config, manifest_data) {
124
123
  if (should_generate) {
125
124
  // track which old files end up being surplus to requirements
126
125
  const to_delete = new Set(output_files.map((file) => file.name));
127
- update_types(config, routes_map, route, to_delete);
126
+ update_types(config, routes_map, route, root, to_delete);
128
127
  meta_data[route.id] = input_files;
129
128
  }
130
129
  }
@@ -138,8 +137,9 @@ export function write_all_types(config, manifest_data) {
138
137
  * @param {import('types').ValidatedConfig} config
139
138
  * @param {import('types').ManifestData} manifest_data
140
139
  * @param {string} file
140
+ * @param {string} root The project root directory
141
141
  */
142
- export function write_types(config, manifest_data, file) {
142
+ export function write_types(config, manifest_data, file, root) {
143
143
  if (!ts) return;
144
144
 
145
145
  if (!path.basename(file).startsWith('+')) {
@@ -153,7 +153,7 @@ export function write_types(config, manifest_data, file) {
153
153
  if (!route) return;
154
154
  if (!route.leaf && !route.layout && !route.endpoint) return; // nothing to do
155
155
 
156
- update_types(config, create_routes_map(manifest_data), route);
156
+ update_types(config, create_routes_map(manifest_data), route, root);
157
157
  }
158
158
 
159
159
  /**
@@ -176,11 +176,12 @@ function create_routes_map(manifest_data) {
176
176
  * @param {import('types').ValidatedConfig} config
177
177
  * @param {RoutesMap} routes
178
178
  * @param {import('types').RouteData} route
179
+ * @param {string} root The project root directory
179
180
  * @param {Set<string>} [to_delete]
180
181
  */
181
- function update_types(config, routes, route, to_delete = new Set()) {
182
+ function update_types(config, routes, route, root, to_delete = new Set()) {
182
183
  const routes_dir = remove_relative_parent_traversals(
183
- posixify(path.relative('.', config.kit.files.routes))
184
+ posixify(path.relative(root, config.kit.files.routes))
184
185
  );
185
186
  const outdir = path.join(config.kit.outDir, 'types', routes_dir, route.id);
186
187
 
@@ -251,7 +252,7 @@ function update_types(config, routes, route, to_delete = new Set()) {
251
252
  declarations: d,
252
253
  exports: e,
253
254
  proxies
254
- } = process_node(route.leaf, outdir, true, route_info.proxies);
255
+ } = process_node(route.leaf, outdir, true, route_info.proxies, root);
255
256
 
256
257
  exports.push(...e);
257
258
  declarations.push(...d);
@@ -300,7 +301,7 @@ function update_types(config, routes, route, to_delete = new Set()) {
300
301
  layout_params.push({ ...param, optional: true });
301
302
  }
302
303
 
303
- ensureProxies(page, leaf.proxies);
304
+ ensureProxies(page, leaf.proxies, root);
304
305
 
305
306
  if (
306
307
  // Be defensive - if a proxy doesn't exist (because it couldn't be created), assume a load function exists.
@@ -336,6 +337,7 @@ function update_types(config, routes, route, to_delete = new Set()) {
336
337
  outdir,
337
338
  false,
338
339
  { server: null, universal: null },
340
+ root,
339
341
  all_pages_have_load
340
342
  );
341
343
 
@@ -375,9 +377,10 @@ function update_types(config, routes, route, to_delete = new Set()) {
375
377
  * @param {string} outdir
376
378
  * @param {boolean} is_page
377
379
  * @param {Proxies} proxies
380
+ * @param {string} root The project root directory
378
381
  * @param {boolean} [all_pages_have_load]
379
382
  */
380
- function process_node(node, outdir, is_page, proxies, all_pages_have_load = true) {
383
+ function process_node(node, outdir, is_page, proxies, root, all_pages_have_load = true) {
381
384
  const params = `${is_page ? 'Route' : 'Layout'}Params`;
382
385
  const prefix = is_page ? 'Page' : 'Layout';
383
386
 
@@ -393,7 +396,7 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
393
396
  /** @type {string} */
394
397
  let data;
395
398
 
396
- ensureProxies(node, proxies);
399
+ ensureProxies(node, proxies, root);
397
400
 
398
401
  if (node.server) {
399
402
  const basename = path.basename(node.server);
@@ -426,7 +429,7 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
426
429
  // The advantage is that type updates are reflected without saving.
427
430
  const from = proxy.modified
428
431
  ? `./proxy${replace_ext_with_js(basename)}`
429
- : path_to_original(outdir, node.server);
432
+ : path_to_original(outdir, node.server, root);
430
433
 
431
434
  exports.push(
432
435
  'type ExcludeActionFailure<T> = T extends Kit.ActionFailure<any> ? never : T extends void ? never : T;',
@@ -495,7 +498,7 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
495
498
  // The advantage is that type updates are reflected without saving.
496
499
  const from = proxy.modified
497
500
  ? `./proxy${replace_ext_with_js(path.basename(file_path))}`
498
- : path_to_original(outdir, file_path);
501
+ : path_to_original(outdir, file_path, root);
499
502
  const type = `Kit.LoadProperties<Awaited<ReturnType<typeof import('${from}').load>>>`;
500
503
  return expand ? `Expand<OptionalUnion<EnsureDefined<${type}>>>` : type;
501
504
  } else {
@@ -515,24 +518,26 @@ function process_node(node, outdir, is_page, proxies, all_pages_have_load = true
515
518
  *
516
519
  * @param {import('types').PageNode} node
517
520
  * @param {Proxies} proxies
521
+ * @param {string} root The project root directory
518
522
  */
519
- function ensureProxies(node, proxies) {
523
+ function ensureProxies(node, proxies, root) {
520
524
  if (node.server && !proxies.server) {
521
- proxies.server = createProxy(node.server, true);
525
+ proxies.server = createProxy(node.server, true, root);
522
526
  }
523
527
 
524
528
  if (node.universal && !proxies.universal) {
525
- proxies.universal = createProxy(node.universal, false);
529
+ proxies.universal = createProxy(node.universal, false, root);
526
530
  }
527
531
  }
528
532
 
529
533
  /**
530
534
  * @param {string} file_path
531
535
  * @param {boolean} is_server
536
+ * @param {string} root The project root directory
532
537
  * @returns {Proxy}
533
538
  */
534
- function createProxy(file_path, is_server) {
535
- const proxy = tweak_types(fs.readFileSync(file_path, 'utf8'), is_server);
539
+ function createProxy(file_path, is_server, root) {
540
+ const proxy = tweak_types(fs.readFileSync(path.resolve(root, file_path), 'utf8'), is_server);
536
541
  if (proxy) {
537
542
  return {
538
543
  ...proxy,
@@ -577,9 +582,10 @@ function get_parent_type(node, type) {
577
582
  /**
578
583
  * @param {string} outdir
579
584
  * @param {string} file_path
585
+ * @param {string} root The project root directory
580
586
  */
581
- function path_to_original(outdir, file_path) {
582
- return posixify(path.relative(outdir, path.join(cwd, replace_ext_with_js(file_path))));
587
+ function path_to_original(outdir, file_path, root) {
588
+ return posixify(path.relative(outdir, path.join(root, replace_ext_with_js(file_path))));
583
589
  }
584
590
 
585
591
  /**
package/src/core/utils.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
- import process from 'node:process';
4
3
  import { fileURLToPath } from 'node:url';
5
- import colors from 'kleur';
6
- import { posixify, to_fs } from '../utils/filesystem.js';
4
+ import { styleText } from 'node:util';
5
+ import { to_fs } from '../utils/vite.js';
7
6
  import { noop } from '../utils/functions.js';
7
+ import { posixify } from '../utils/os.js';
8
8
 
9
9
  /**
10
10
  * Resolved path of the `runtime` directory
@@ -20,10 +20,14 @@ export const runtime_directory = posixify(fileURLToPath(new URL('../runtime', im
20
20
  * This allows us to import SvelteKit internals that aren't exposed via `pkg.exports` in a
21
21
  * way that works whether `@sveltejs/kit` is installed inside the project's `node_modules`
22
22
  * or in a workspace root
23
+ * @param {string} root
24
+ * @returns {string}
23
25
  */
24
- export const runtime_base = runtime_directory.startsWith(process.cwd())
25
- ? `/${path.relative('.', runtime_directory)}`
26
- : to_fs(runtime_directory);
26
+ export function get_runtime_base(root) {
27
+ return runtime_directory.startsWith(root)
28
+ ? `/${path.relative(root, runtime_directory)}`
29
+ : to_fs(runtime_directory);
30
+ }
27
31
 
28
32
  /** @param {{ verbose: boolean }} opts */
29
33
  export function logger({ verbose }) {
@@ -33,11 +37,10 @@ export function logger({ verbose }) {
33
37
  /** @param {string} msg */
34
38
  const err = (msg) => console.error(msg.replace(/^/gm, ' '));
35
39
 
36
- log.success = (msg) => log(colors.green(`✔ ${msg}`));
37
- log.error = (msg) => err(colors.bold().red(msg));
38
- log.warn = (msg) => log(colors.bold().yellow(msg));
39
-
40
- log.minor = verbose ? (msg) => log(colors.grey(msg)) : noop;
40
+ log.success = (msg) => log(styleText('green', `✔ ${msg}`));
41
+ log.error = (msg) => err(styleText(['bold', 'red'], msg));
42
+ log.warn = (msg) => log(styleText(['bold', 'yellow'], msg));
43
+ log.minor = verbose ? (msg) => log(styleText('grey', msg)) : noop;
41
44
  log.info = verbose ? log : noop;
42
45
 
43
46
  return log;
@@ -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);
@@ -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
- let message = `Content-length of ${content_length} exceeds limit of ${body_size_limit} bytes.`;
42
-
43
- if (body_size_limit === 0) {
44
- // https://github.com/sveltejs/kit/pull/11589
45
- // TODO this exists to aid migration — remove in a future version
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' ? get_set_cookies(response.headers) : value);
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));
@@ -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: (fn: (route: RouteDefinition) => AdapterEntry) => Promise<void>;
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 build-time environment variables as `$env/dynamic/public` if the app uses it.
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#cookieparsestr-options)
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').CookieParseOptions) => string | undefined;
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#cookieparsestr-options)
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').CookieParseOptions) => Array<{ name: string; value: string }>;
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. The `sameSite` option defaults to `lax`.
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
- * 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
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, passed directly to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-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
- * 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
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, passed directly to `cookie.serialize`. The `path` must match the path of the cookie you want to delete. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-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').CookieSerializeOptions & { path: string }) => void;
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. The `sameSite` option defaults to `lax`.
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, passed directly to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-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,27 +456,9 @@ 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?: {
479
- /**
480
- * Whether to enable explicit environment variables using `src/env.js` or `src/env.ts`.
481
- * @since 2.62.0
482
- * @default false
483
- */
484
- explicitEnvironmentVariables?: boolean;
485
-
486
462
  /**
487
463
  * Options for enabling server-side [OpenTelemetry](https://opentelemetry.io/) tracing for SvelteKit operations including the [`handle` hook](https://svelte.dev/docs/kit/hooks#Server-hooks-handle), [`load` functions](https://svelte.dev/docs/kit/load), [form actions](https://svelte.dev/docs/kit/form-actions), and [remote functions](https://svelte.dev/docs/kit/remote-functions).
488
464
  * @default { server: false, serverFile: false }
@@ -627,6 +603,16 @@ export interface KitConfig {
627
603
  * Options related to the build output format
628
604
  */
629
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;
630
616
  /**
631
617
  * SvelteKit will preload the JavaScript modules needed for the initial page to avoid import 'waterfalls', resulting in faster application startup. There
632
618
  * are three strategies with different trade-offs:
@@ -635,6 +621,7 @@ export interface KitConfig {
635
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.
636
622
  * @default "modulepreload"
637
623
  * @since 1.8.4
624
+ * @deprecated removed in 3.0
638
625
  */
639
626
  preloadStrategy?: 'modulepreload' | 'preload-js' | 'preload-mjs';
640
627
  /**
@@ -643,7 +630,7 @@ export interface KitConfig {
643
630
  * - If `'single'`, creates just one .js bundle and one .css file containing code for the entire app.
644
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).
645
632
  *
646
- * When using `'split'`, you can also adjust the bundling behaviour by setting [`output.experimentalMinChunkSize`](https://rollupjs.org/configuration-options/#output-experimentalminchunksize) and [`output.manualChunks`](https://rollupjs.org/configuration-options/#output-manualchunks) inside your Vite config's [`build.rollupOptions`](https://vite.dev/config/build-options.html#build-rollupoptions).
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).
647
634
  *
648
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.
649
636
  *
@@ -1288,13 +1275,6 @@ export interface NavigationGoto extends NavigationBase {
1288
1275
  * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
1289
1276
  */
1290
1277
  type: 'goto';
1291
-
1292
- // TODO 3.0 remove this property, so that it only exists when type is 'popstate'
1293
- // (would possibly be a breaking change to do it prior to that)
1294
- /**
1295
- * In case of a history back/forward navigation, the number of steps to go back/forward
1296
- */
1297
- delta?: undefined;
1298
1278
  }
1299
1279
 
1300
1280
  export interface NavigationLeave extends NavigationBase {
@@ -1303,13 +1283,6 @@ export interface NavigationLeave extends NavigationBase {
1303
1283
  * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring
1304
1284
  */
1305
1285
  type: 'leave';
1306
-
1307
- // TODO 3.0 remove this property, so that it only exists when type is 'popstate'
1308
- // (would possibly be a breaking change to do it prior to that)
1309
- /**
1310
- * In case of a history back/forward navigation, the number of steps to go back/forward
1311
- */
1312
- delta?: undefined;
1313
1286
  }
1314
1287
 
1315
1288
  export interface NavigationFormSubmit extends NavigationBase {
@@ -1323,13 +1296,6 @@ export interface NavigationFormSubmit extends NavigationBase {
1323
1296
  * The `SubmitEvent` that caused the navigation
1324
1297
  */
1325
1298
  event: SubmitEvent;
1326
-
1327
- // TODO 3.0 remove this property, so that it only exists when type is 'popstate'
1328
- // (would possibly be a breaking change to do it prior to that)
1329
- /**
1330
- * In case of a history back/forward navigation, the number of steps to go back/forward
1331
- */
1332
- delta?: undefined;
1333
1299
  }
1334
1300
 
1335
1301
  export interface NavigationPopState extends NavigationBase {
@@ -1361,13 +1327,6 @@ export interface NavigationLink extends NavigationBase {
1361
1327
  * The `PointerEvent` that caused the navigation
1362
1328
  */
1363
1329
  event: PointerEvent;
1364
-
1365
- // TODO 3.0 remove this property, so that it only exists when type is 'popstate'
1366
- // (would possibly be a breaking change to do it prior to that)
1367
- /**
1368
- * In case of a history back/forward navigation, the number of steps to go back/forward
1369
- */
1370
- delta?: undefined;
1371
1330
  }
1372
1331
 
1373
1332
  export type Navigation =