@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.
Files changed (104) hide show
  1. package/package.json +28 -22
  2. package/src/cli.js +49 -20
  3. package/src/core/adapt/builder.js +38 -69
  4. package/src/core/adapt/index.js +11 -6
  5. package/src/core/config/index.js +12 -82
  6. package/src/core/config/options.js +36 -45
  7. package/src/core/env.js +240 -60
  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 +20 -16
  11. package/src/core/postbuild/fallback.js +0 -3
  12. package/src/core/postbuild/prerender.js +19 -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 +44 -23
  16. package/src/core/sync/utils.js +0 -15
  17. package/src/core/sync/write_ambient.js +5 -50
  18. package/src/core/sync/write_client_manifest.js +8 -9
  19. package/src/core/sync/write_env.js +36 -0
  20. package/src/core/sync/write_non_ambient.js +7 -7
  21. package/src/core/sync/write_root.js +41 -89
  22. package/src/core/sync/write_server.js +18 -24
  23. package/src/core/sync/write_tsconfig.js +29 -24
  24. package/src/core/sync/write_types/index.js +31 -25
  25. package/src/core/utils.js +14 -11
  26. package/src/exports/hooks/index.js +13 -0
  27. package/src/exports/index.js +8 -21
  28. package/src/exports/internal/env.js +71 -0
  29. package/src/exports/internal/types.d.ts +3 -0
  30. package/src/exports/node/index.js +8 -13
  31. package/src/exports/public.d.ts +68 -69
  32. package/src/exports/vite/build/build_server.js +14 -11
  33. package/src/exports/vite/build/remote.js +6 -7
  34. package/src/exports/vite/build/utils.js +7 -5
  35. package/src/exports/vite/dev/index.js +32 -33
  36. package/src/exports/vite/index.js +1015 -711
  37. package/src/exports/vite/module_ids.js +10 -6
  38. package/src/exports/vite/options.js +17 -0
  39. package/src/exports/vite/preview/index.js +3 -5
  40. package/src/exports/vite/static_analysis/index.js +11 -5
  41. package/src/exports/vite/utils.js +11 -41
  42. package/src/runtime/app/env/index.js +2 -0
  43. package/src/runtime/app/env/internal.js +14 -0
  44. package/src/runtime/app/env/private.js +1 -0
  45. package/src/runtime/app/env/public/client.js +1 -0
  46. package/src/runtime/app/env/public/index.js +1 -0
  47. package/src/runtime/app/env/public/server.js +1 -0
  48. package/src/runtime/app/env/standard-schema.d.ts +0 -0
  49. package/src/runtime/app/server/index.js +4 -2
  50. package/src/runtime/app/server/remote/form.js +0 -51
  51. package/src/runtime/app/server/remote/query.js +1 -8
  52. package/src/runtime/app/server/remote/shared.js +4 -3
  53. package/src/runtime/app/state/client.js +1 -12
  54. package/src/runtime/client/client.js +1 -1
  55. package/src/runtime/client/constants.js +0 -1
  56. package/src/runtime/client/remote-functions/form.svelte.js +0 -31
  57. package/src/runtime/client/remote-functions/prerender.svelte.js +1 -1
  58. package/src/runtime/client/remote-functions/query/index.js +2 -2
  59. package/src/runtime/client/remote-functions/query/instance.svelte.js +1 -2
  60. package/src/runtime/client/remote-functions/query-batch.svelte.js +2 -2
  61. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +5 -8
  62. package/src/runtime/client/utils.js +9 -11
  63. package/src/runtime/components/{svelte-5/layout.svelte → layout.svelte} +1 -1
  64. package/src/runtime/form-utils.js +4 -41
  65. package/src/runtime/server/cookie.js +21 -37
  66. package/src/runtime/server/env_module.js +12 -4
  67. package/src/runtime/server/fetch.js +6 -10
  68. package/src/runtime/server/index.js +5 -9
  69. package/src/runtime/server/page/render.js +33 -37
  70. package/src/runtime/server/page/types.d.ts +4 -2
  71. package/src/runtime/server/respond.js +3 -3
  72. package/src/runtime/server/utils.js +2 -4
  73. package/src/runtime/shared-server.js +0 -22
  74. package/src/runtime/shared.js +0 -15
  75. package/src/types/ambient-private.d.ts +25 -9
  76. package/src/types/global-private.d.ts +6 -0
  77. package/src/types/internal.d.ts +4 -8
  78. package/src/utils/css.js +3 -19
  79. package/src/utils/filesystem.js +1 -30
  80. package/src/utils/http.js +0 -21
  81. package/src/utils/import.js +8 -7
  82. package/src/utils/os.js +7 -0
  83. package/src/utils/path.js +23 -0
  84. package/src/utils/shared-iterator.js +3 -0
  85. package/src/utils/streaming.js +2 -4
  86. package/src/utils/url.js +1 -1
  87. package/src/utils/vite.js +28 -0
  88. package/src/version.js +1 -1
  89. package/types/index.d.ts +85 -109
  90. package/types/index.d.ts.map +5 -6
  91. package/src/exports/vite/build/build_service_worker.js +0 -149
  92. package/src/runtime/app/environment/index.js +0 -2
  93. package/src/runtime/components/svelte-4/error.svelte +0 -6
  94. package/src/runtime/components/svelte-4/layout.svelte +0 -1
  95. package/src/runtime/env/dynamic/private.js +0 -1
  96. package/src/runtime/env/dynamic/public.js +0 -1
  97. package/src/types/synthetic/$env+dynamic+private.md +0 -43
  98. package/src/types/synthetic/$env+dynamic+public.md +0 -46
  99. package/src/types/synthetic/$env+static+private.md +0 -31
  100. package/src/types/synthetic/$env+static+public.md +0 -31
  101. package/src/utils/env.js +0 -13
  102. package/src/utils/promise.js +0 -29
  103. /package/src/runtime/app/{environment → env}/types.d.ts +0 -0
  104. /package/src/runtime/components/{svelte-5/error.svelte → error.svelte} +0 -0
@@ -1,7 +1,6 @@
1
1
  /** @import { Transport } from '@sveltejs/kit' */
2
2
  import * as devalue from 'devalue';
3
3
  import { base64_decode, base64_encode, text_encoder } from './utils.js';
4
- import * as svelte from 'svelte';
5
4
 
6
5
  /**
7
6
  * @param {string} route_id
@@ -305,17 +304,3 @@ export function split_remote_key(key) {
305
304
  payload: key.slice(i + 1)
306
305
  };
307
306
  }
308
-
309
- /**
310
- * @template T
311
- * @param {string} key
312
- * @param {() => T} fn
313
- * @returns {T}
314
- * @deprecated TODO remove in SvelteKit 3.0
315
- */
316
- export function unfriendly_hydratable(key, fn) {
317
- if (!svelte.hydratable) {
318
- throw new Error('Remote functions require Svelte 5.44.0 or later');
319
- }
320
- return svelte.hydratable(key, fn);
321
- }
@@ -1,12 +1,3 @@
1
- /** Internal version of $app/environment */
2
- declare module '__sveltekit/environment' {
3
- export const building: boolean;
4
- export const prerendering: boolean;
5
- export const version: string;
6
- export function set_building(): void;
7
- export function set_prerendering(): void;
8
- }
9
-
10
1
  /** Internal version of $app/paths */
11
2
  declare module '__sveltekit/paths' {
12
3
  export let base: '' | `/${string}`;
@@ -27,3 +18,28 @@ declare module '__sveltekit/server' {
27
18
  export function set_manifest(manifest: SSRManifest): void;
28
19
  export function set_read_implementation(fn: (path: string) => ReadableStream): void;
29
20
  }
21
+
22
+ declare module '__sveltekit/env' {
23
+ // exported environment variables are defined in env.d.ts
24
+
25
+ /** Populate exported environment variables */
26
+ export function set_env(environment: Record<string, string>): void;
27
+
28
+ /** public env vars */
29
+ export const explicit_public_env: Record<string, any>;
30
+
31
+ /** public env vars that should be inlined when a page is rendered */
32
+ export const rendered_env: Record<string, any>;
33
+ }
34
+
35
+ declare module '__sveltekit/env/private' {
36
+ // exported environment variables are defined in env.d.ts
37
+ }
38
+
39
+ declare module '__sveltekit/env/public/client' {
40
+ // exported environment variables are defined in env.d.ts
41
+ }
42
+
43
+ declare module '__sveltekit/env/public/server' {
44
+ // exported environment variables are defined in env.d.ts
45
+ }
@@ -1,6 +1,7 @@
1
1
  declare global {
2
2
  const __SVELTEKIT_ADAPTER_NAME__: string;
3
3
  const __SVELTEKIT_APP_DIR__: string;
4
+ const __SVELTEKIT_APP_VERSION__: string;
4
5
  const __SVELTEKIT_APP_VERSION_FILE__: string;
5
6
  const __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: number;
6
7
  /**
@@ -47,6 +48,11 @@ declare global {
47
48
  /** Resolve a placeholder promise */
48
49
  resolve?: (data: { id: number; data: any; error: any }) => void;
49
50
  };
51
+ /**
52
+ * The Vite `root` setting used to construct paths to nodes and components
53
+ * for the SSR manifest during development
54
+ */
55
+ const __SVELTEKIT_ROOT__: string;
50
56
  /**
51
57
  * This makes the use of specific features visible at both dev and build time, in such a
52
58
  * way that we can error when they are not supported by the target platform.
@@ -44,10 +44,9 @@ export interface ServerModule {
44
44
  export interface ServerInternalModule {
45
45
  set_assets(path: string): void;
46
46
  set_building(): void;
47
+ set_env(environment: Record<string, string>): void;
47
48
  set_manifest(manifest: SSRManifest): void;
48
49
  set_prerendering(): void;
49
- set_private_env(environment: Record<string, string>): void;
50
- set_public_env(environment: Record<string, string>): void;
51
50
  set_read_implementation(implementation: (path: string) => ReadableStream): void;
52
51
  set_version(version: string): void;
53
52
  set_fix_stack_trace(fix_stack_trace: (error: unknown) => string): void;
@@ -500,11 +499,9 @@ export interface SSROptions {
500
499
  csrf_check_origin: boolean;
501
500
  csrf_trusted_origins: string[];
502
501
  embedded: boolean;
503
- env_public_prefix: string;
504
- env_private_prefix: string;
505
502
  hash_routing: boolean;
506
503
  hooks: ServerHooks;
507
- preload_strategy: ValidatedConfig['kit']['output']['preloadStrategy'];
504
+ link_header_preload: ValidatedConfig['kit']['output']['linkHeaderPreload'];
508
505
  root: SSRComponent['default'];
509
506
  service_worker: boolean;
510
507
  service_worker_options: RegistrationOptions;
@@ -606,9 +603,8 @@ export type ValidatedConfig = Config & {
606
603
  extensions: string[];
607
604
  };
608
605
 
609
- export type ValidatedKitConfig = Omit<RecursiveRequired<KitConfig>, 'adapter'> & {
610
- adapter?: Adapter;
611
- };
606
+ // TODO: remove the omit in 4.0
607
+ export type ValidatedKitConfig = Omit<RecursiveRequired<KitConfig>, 'adapter'>;
612
608
 
613
609
  export type BinaryFormMeta = {
614
610
  remote_refreshes?: string[];
package/src/utils/css.js CHANGED
@@ -1,19 +1,10 @@
1
1
  import MagicString from 'magic-string';
2
- import * as svelte from 'svelte/compiler';
2
+ import { parseCss } from 'svelte/compiler';
3
3
 
4
- /** @typedef {ReturnType<typeof import('svelte/compiler').parseCss>['children']} StyleSheetChildren */
4
+ /** @typedef {ReturnType<typeof parseCss>['children']} StyleSheetChildren */
5
5
 
6
6
  /** @typedef {{ property: string; value: string; start: number; end: number; type: 'Declaration' }} Declaration */
7
7
 
8
- const parse = svelte.parseCss
9
- ? svelte.parseCss
10
- : /** @param {string} css */
11
- (css) => {
12
- return /** @type {{ css: { children: StyleSheetChildren } }} */ (
13
- svelte.parse(`<style>${css}</style>`)
14
- ).css;
15
- };
16
-
17
8
  const SKIP_PARSING_REGEX = /url\(/i;
18
9
 
19
10
  /** Capture a single url(...) so we can process them one at a time */
@@ -31,8 +22,6 @@ const HASH_OR_QUERY_REGEX = /[#?]/;
31
22
  */
32
23
  const VITE_ASSET_PREFIX = './';
33
24
 
34
- const AST_OFFSET = '<style>'.length;
35
-
36
25
  /**
37
26
  * We need to fix the asset URLs in the CSS before we inline them into a document
38
27
  * because they are now relative to the document instead of the CSS file.
@@ -70,7 +59,7 @@ export function fix_css_urls({
70
59
 
71
60
  const s = new MagicString(css);
72
61
 
73
- const parsed = parse(css);
62
+ const parsed = parseCss(css);
74
63
 
75
64
  for (const child of parsed.children) {
76
65
  find_declarations(child, (declaration) => {
@@ -128,11 +117,6 @@ export function fix_css_urls({
128
117
 
129
118
  if (declaration.value === new_value) return;
130
119
 
131
- if (!svelte.parseCss) {
132
- declaration.start = declaration.start - AST_OFFSET;
133
- declaration.end = declaration.end - AST_OFFSET;
134
- }
135
-
136
120
  s.update(declaration.start, declaration.end, `${declaration.property}: ${new_value}`);
137
121
  });
138
122
  }
@@ -1,5 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
+ import { posixify } from './os.js';
3
4
 
4
5
  /** @param {string} dir */
5
6
  export function mkdirp(dir) {
@@ -110,11 +111,6 @@ export function walk(cwd, dirs = false) {
110
111
  return (walk_dir(''), all_files);
111
112
  }
112
113
 
113
- /** @param {string} str */
114
- export function posixify(str) {
115
- return str.replace(/\\/g, '/');
116
- }
117
-
118
114
  /**
119
115
  * Like `path.join`, but posixified and with a leading `./` if necessary
120
116
  * @param {string[]} str
@@ -138,31 +134,6 @@ export function relative_path(from, to) {
138
134
  return join_relative(path.relative(from, to));
139
135
  }
140
136
 
141
- /**
142
- * Prepend given path with `/@fs` prefix
143
- * @param {string} str
144
- */
145
- export function to_fs(str) {
146
- str = posixify(str);
147
- return `/@fs${
148
- // Windows/Linux separation - Windows starts with a drive letter, we need a / in front there
149
- str.startsWith('/') ? '' : '/'
150
- }${str}`;
151
- }
152
-
153
- /**
154
- * Removes `/@fs` prefix from given path and posixifies it
155
- * @param {string} str
156
- */
157
- export function from_fs(str) {
158
- str = posixify(str);
159
- if (!str.startsWith('/@fs')) return str;
160
-
161
- str = str.slice(4);
162
- // Windows/Linux separation - Windows starts with a drive letter, we need to strip the additional / here
163
- return str[2] === ':' && /[A-Z]/.test(str[1]) ? str.slice(1) : str;
164
- }
165
-
166
137
  /**
167
138
  * Given an entry point like [cwd]/src/hooks, returns a filename like [cwd]/src/hooks.js or [cwd]/src/hooks/index.js
168
139
  * @param {string} entry
package/src/utils/http.js CHANGED
@@ -1,4 +1,3 @@
1
- import * as set_cookie_parser from 'set-cookie-parser';
2
1
  import { BINARY_FORM_CONTENT_TYPE } from '../runtime/form-utils.js';
3
2
 
4
3
  /**
@@ -57,26 +56,6 @@ export function negotiate(accept, types) {
57
56
  return accepted;
58
57
  }
59
58
 
60
- /**
61
- * Reads all `Set-Cookie` headers as separate values. `Headers.get('set-cookie')`
62
- * collapses them into a single comma-joined string that browsers cannot parse, so
63
- * we use `Headers.getSetCookie()` where available and fall back to splitting the
64
- * joined string otherwise.
65
- *
66
- * TODO 3.0 `getSetCookie` is available in Node 19.7+; once we drop support for
67
- * older versions we can use it directly and remove the `splitCookiesString` fallback
68
- * @param {Headers} headers
69
- * @returns {string[]}
70
- */
71
- export function get_set_cookies(headers) {
72
- if (typeof headers.getSetCookie === 'function') {
73
- return headers.getSetCookie();
74
- }
75
-
76
- const set_cookie = headers.get('set-cookie');
77
- return set_cookie ? set_cookie_parser.splitCookiesString(set_cookie) : [];
78
- }
79
-
80
59
  /**
81
60
  * Returns `true` if the request contains a `content-type` header with the given type
82
61
  * @param {Request} request
@@ -1,16 +1,16 @@
1
- import process from 'node:process';
2
1
  import fs from 'node:fs';
3
2
  import path from 'node:path';
4
3
 
5
4
  /**
6
- * Resolves a peer dependency relative to the current CWD. Duplicated with `packages/adapter-auto`
5
+ * Resolves a peer dependency relative to the current working directory. Duplicated with `packages/adapter-auto`
7
6
  * @param {string} dependency
7
+ * @param {string} root
8
8
  */
9
- function resolve_peer(dependency) {
9
+ function resolve_peer(dependency, root) {
10
10
  let [name, ...parts] = dependency.split('/');
11
11
  if (name[0] === '@') name += `/${parts.shift()}`;
12
12
 
13
- let dir = process.cwd();
13
+ let dir = root;
14
14
 
15
15
  while (!fs.existsSync(`${dir}/node_modules/${name}/package.json`)) {
16
16
  if (dir === (dir = path.dirname(dir))) {
@@ -42,11 +42,12 @@ function resolve_peer(dependency) {
42
42
  * Resolve a dependency relative to the current working directory,
43
43
  * rather than relative to this package (but falls back to trying that, if necessary)
44
44
  * @param {string} dependency
45
+ * @param {string} root
45
46
  */
46
- export async function import_peer(dependency) {
47
+ export async function import_peer(dependency, root) {
47
48
  try {
48
- return await import(resolve_peer(dependency));
49
+ return await import(/* @vite-ignore */ resolve_peer(dependency, root));
49
50
  } catch {
50
- return await import(dependency);
51
+ return await import(/* @vite-ignore */ dependency);
51
52
  }
52
53
  }
@@ -0,0 +1,7 @@
1
+ // this file needs to remain node-agnostic because it could be imported into an
2
+ // environment without access to `node:*`
3
+
4
+ /** @param {string} str */
5
+ export function posixify(str) {
6
+ return str.replace(/\\/g, '/');
7
+ }
@@ -0,0 +1,23 @@
1
+ // This file contains Node-agnostic path utilities so that it can be used in
2
+ // environments that do not have access to `node:path` (e.g. Cloudflare Workers).
3
+
4
+ /**
5
+ * @param {string} from
6
+ * @param {string} to
7
+ * @returns {string}
8
+ */
9
+ export function relative(from, to) {
10
+ const from_parts = from.split('/').filter(Boolean);
11
+ const to_parts = to.split('/').filter(Boolean);
12
+ let i = 0;
13
+ while (i < from_parts.length && i < to_parts.length && from_parts[i] === to_parts[i]) i++;
14
+ return [...Array(from_parts.length - i).fill('..'), ...to_parts.slice(i)].join('/') || '.';
15
+ }
16
+
17
+ /**
18
+ * @param {...string} parts
19
+ * @returns {string}
20
+ */
21
+ export function join(...parts) {
22
+ return parts.join('/');
23
+ }
@@ -205,6 +205,9 @@ export class SharedIterator {
205
205
  },
206
206
  [Symbol.asyncIterator]() {
207
207
  return iterator;
208
+ },
209
+ async [Symbol.asyncDispose]() {
210
+ // TODO: investigate if this needs to be implemented
208
211
  }
209
212
  };
210
213
 
@@ -1,5 +1,3 @@
1
- import { with_resolvers } from './promise.js';
2
-
3
1
  /**
4
2
  * Create an async iterator and a function to push values into it
5
3
  * @template T
@@ -12,7 +10,7 @@ export function create_async_iterator() {
12
10
  let resolved = -1;
13
11
  let returned = -1;
14
12
 
15
- /** @type {import('./promise.js').PromiseWithResolvers<T>[]} */
13
+ /** @type {PromiseWithResolvers<T>[]} */
16
14
  const deferred = [];
17
15
 
18
16
  return {
@@ -32,7 +30,7 @@ export function create_async_iterator() {
32
30
  };
33
31
  },
34
32
  add: (promise) => {
35
- deferred.push(with_resolvers());
33
+ deferred.push(Promise.withResolvers());
36
34
  void promise.then((value) => {
37
35
  deferred[++resolved].resolve(value);
38
36
  });
package/src/utils/url.js CHANGED
@@ -6,7 +6,7 @@ import { BROWSER, DEV } from 'esm-env';
6
6
  */
7
7
  export const SCHEME = /^[a-z][a-z\d+\-.]+:/i;
8
8
 
9
- const internal = new URL('sveltekit-internal://');
9
+ const internal = new URL('a://');
10
10
 
11
11
  /**
12
12
  * @param {string} base
@@ -0,0 +1,28 @@
1
+ // this file needs to be runtime agnostic and avoid importing from `node:*` since
2
+ // it may not be available in edge environments
3
+ import { posixify } from './os.js';
4
+
5
+ /**
6
+ * Prepend given path with `/@fs` prefix
7
+ * @param {string} str
8
+ */
9
+ export function to_fs(str) {
10
+ str = posixify(str);
11
+ return `/@fs${
12
+ // Windows/Linux separation - Windows starts with a drive letter, we need a / in front there
13
+ str.startsWith('/') ? '' : '/'
14
+ }${str}`;
15
+ }
16
+
17
+ /**
18
+ * Removes `/@fs` prefix from given path and posixifies it
19
+ * @param {string} str
20
+ */
21
+ export function from_fs(str) {
22
+ str = posixify(str);
23
+ if (!str.startsWith('/@fs')) return str;
24
+
25
+ str = str.slice(4);
26
+ // Windows/Linux separation - Windows starts with a drive letter, we need to strip the additional / here
27
+ return str[2] === ':' && /[A-Z]/.test(str[1]) ? str.slice(1) : str;
28
+ }
package/src/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // generated during release, do not modify
2
2
 
3
3
  /** @type {string} */
4
- export const VERSION = '2.62.0';
4
+ export const VERSION = '3.0.0-next.0';