@sveltejs/kit 2.63.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 (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/server/index.js +4 -2
  43. package/src/runtime/app/server/remote/form.js +0 -51
  44. package/src/runtime/app/server/remote/query.js +0 -7
  45. package/src/runtime/app/server/remote/shared.js +4 -3
  46. package/src/runtime/app/state/client.js +1 -12
  47. package/src/runtime/client/client.js +1 -1
  48. package/src/runtime/client/constants.js +0 -1
  49. package/src/runtime/client/remote-functions/form.svelte.js +0 -31
  50. package/src/runtime/client/remote-functions/query/index.js +2 -2
  51. package/src/runtime/client/remote-functions/query/instance.svelte.js +1 -2
  52. package/src/runtime/client/remote-functions/query-batch.svelte.js +2 -2
  53. package/src/runtime/client/remote-functions/query-live/instance.svelte.js +5 -8
  54. package/src/runtime/client/utils.js +8 -10
  55. package/src/runtime/components/{svelte-5/layout.svelte → layout.svelte} +1 -1
  56. package/src/runtime/form-utils.js +4 -41
  57. package/src/runtime/server/cookie.js +21 -37
  58. package/src/runtime/server/env_module.js +1 -3
  59. package/src/runtime/server/fetch.js +6 -10
  60. package/src/runtime/server/index.js +3 -9
  61. package/src/runtime/server/page/render.js +32 -44
  62. package/src/runtime/server/page/types.d.ts +4 -2
  63. package/src/runtime/server/respond.js +2 -2
  64. package/src/runtime/server/utils.js +2 -4
  65. package/src/runtime/shared-server.js +0 -22
  66. package/src/runtime/shared.js +0 -15
  67. package/src/types/global-private.d.ts +5 -1
  68. package/src/types/internal.d.ts +3 -8
  69. package/src/utils/css.js +3 -19
  70. package/src/utils/filesystem.js +1 -30
  71. package/src/utils/http.js +0 -21
  72. package/src/utils/import.js +7 -6
  73. package/src/utils/os.js +7 -0
  74. package/src/utils/path.js +23 -0
  75. package/src/utils/shared-iterator.js +3 -0
  76. package/src/utils/streaming.js +2 -4
  77. package/src/utils/url.js +1 -1
  78. package/src/utils/vite.js +28 -0
  79. package/src/version.js +1 -1
  80. package/types/index.d.ts +45 -138
  81. package/types/index.d.ts.map +1 -8
  82. package/src/exports/vite/build/build_service_worker.js +0 -165
  83. package/src/runtime/app/environment/index.js +0 -10
  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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "2.63.0",
3
+ "version": "3.0.0-next.0",
4
4
  "description": "SvelteKit is the fastest way to build Svelte apps",
5
5
  "keywords": [
6
6
  "framework",
@@ -20,38 +20,35 @@
20
20
  "dependencies": {
21
21
  "@standard-schema/spec": "^1.0.0",
22
22
  "@sveltejs/acorn-typescript": "^1.0.9",
23
- "@types/cookie": "^0.6.0",
24
23
  "acorn": "^8.16.0",
25
- "cookie": "^0.6.0",
24
+ "cookie": "^1.1.1",
26
25
  "devalue": "^5.8.1",
27
26
  "esm-env": "^1.2.2",
28
- "kleur": "^4.1.5",
29
27
  "magic-string": "^0.30.5",
30
28
  "mrmime": "^2.0.0",
31
- "set-cookie-parser": "^3.0.0",
32
29
  "sirv": "^3.0.0"
33
30
  },
34
31
  "devDependencies": {
35
32
  "@opentelemetry/api": "^1.0.0",
36
33
  "@playwright/test": "^1.60.0",
37
- "@sveltejs/vite-plugin-svelte": "^6.0.0-next.3",
34
+ "@sveltejs/vite-plugin-svelte": "^7.0.0",
38
35
  "@types/connect": "^3.4.38",
39
- "@types/node": "^18.19.130",
40
- "@types/set-cookie-parser": "^2.4.7",
36
+ "@types/node": "^22.19.19",
41
37
  "dts-buddy": "^0.8.0",
42
- "jsdom": "^26.1.0",
43
- "rollup": "^4.59.0",
38
+ "jsdom": "^29.1.1",
39
+ "rolldown": "^1.0.0-rc.6",
44
40
  "svelte": "^5.55.7",
45
- "typescript": "^5.3.3",
46
- "vite": "^6.4.2",
41
+ "svelte-preprocess": "^6.0.5",
42
+ "typescript": "~6.0.0",
43
+ "vite": "^8.0.10",
47
44
  "vitest": "^4.1.7"
48
45
  },
49
46
  "peerDependencies": {
47
+ "@sveltejs/vite-plugin-svelte": "^7.0.0",
50
48
  "@opentelemetry/api": "^1.0.0",
51
- "@sveltejs/vite-plugin-svelte": "^3.0.0 || ^4.0.0-next.1 || ^5.0.0 || ^6.0.0-next.0 || ^7.0.0",
52
- "svelte": "^4.0.0 || ^5.0.0-next.0",
53
- "typescript": "^5.3.3 || ^6.0.0",
54
- "vite": "^5.0.3 || ^6.0.0 || ^7.0.0-beta.0 || ^8.0.0"
49
+ "svelte": "^5.48.0",
50
+ "typescript": "^6.0.0",
51
+ "vite": "^8.0.0"
55
52
  },
56
53
  "peerDependenciesMeta": {
57
54
  "@opentelemetry/api": {
@@ -107,10 +104,6 @@
107
104
  "types": "./types/index.d.ts",
108
105
  "import": "./src/exports/node/index.js"
109
106
  },
110
- "./node/polyfills": {
111
- "types": "./types/index.d.ts",
112
- "import": "./src/exports/node/polyfills.js"
113
- },
114
107
  "./hooks": {
115
108
  "types": "./types/index.d.ts",
116
109
  "import": "./src/exports/hooks/index.js"
@@ -122,7 +115,7 @@
122
115
  },
123
116
  "types": "types/index.d.ts",
124
117
  "engines": {
125
- "node": ">=18.13"
118
+ "node": ">=22"
126
119
  },
127
120
  "scripts": {
128
121
  "lint": "prettier --config ../../.prettierrc --check .",
@@ -137,7 +130,9 @@
137
130
  "test:server-side-route-resolution:build": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:server-side-route-resolution:build",
138
131
  "test:svelte-async:dev": "pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:svelte-async:dev",
139
132
  "test:svelte-async:build": "pnpm test:unit && pnpm -r --workspace-concurrency 1 --filter=\"./test/**\" test:svelte-async:build",
140
- "test:unit": "vitest --config kit.vitest.config.js run",
133
+ "test:unit:dev": "vitest --config kit.vitest.config.js run",
134
+ "test:unit:prod": "NODE_ENV=production vitest --config kit.vitest.config.js run csp.spec.js cookie.spec.js",
135
+ "test:unit": "pnpm test:unit:dev && pnpm test:unit:prod",
141
136
  "generate:version": "node scripts/generate-version.js",
142
137
  "generate:types": "node scripts/generate-dts.js"
143
138
  }
package/src/cli.js CHANGED
@@ -1,8 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import process from 'node:process';
3
- import { parseArgs } from 'node:util';
4
- import colors from 'kleur';
5
- import { load_config } from './core/config/index.js';
3
+ import { parseArgs, styleText } from 'node:util';
4
+ import { extract_svelte_config, load_vite_config } from './core/config/index.js';
6
5
  import { coalesce_to_error } from './utils/error.js';
7
6
  import { resolve_explicit_env_entry } from './core/env.js';
8
7
 
@@ -12,9 +11,9 @@ function handle_error(e) {
12
11
 
13
12
  if (error.name === 'SyntaxError') throw error;
14
13
 
15
- console.error(colors.bold().red(`> ${error.message}`));
14
+ console.error(styleText(['bold', 'red'], `> ${error.message}`));
16
15
  if (error.stack) {
17
- console.error(colors.gray(error.stack.split('\n').slice(1).join('\n')));
16
+ console.error(styleText('grey', error.stack.split('\n').slice(1).join('\n')));
18
17
  }
19
18
 
20
19
  process.exit(1);
@@ -26,14 +25,15 @@ const help = `
26
25
  Usage: svelte-kit <command> [options]
27
26
 
28
27
  Commands:
29
- sync Synchronise generated type definitions
28
+ sync Synchronise generated type definitions
30
29
 
31
30
  Options:
32
- --version, -v Show version number
33
- --help, -h Show this help message
31
+ --version, -v Show version number
32
+ --help, -h Show this help message
34
33
 
35
34
  Sync Options:
36
- --mode <mode> Specify a mode for loading environment variables (default: development)
35
+ --config, -c <config> Specify a custom Vite config file
36
+ --mode <mode> Specify a mode for loading environment variables (default: development)
37
37
  `;
38
38
 
39
39
  let parsed;
@@ -42,14 +42,15 @@ try {
42
42
  options: {
43
43
  version: { type: 'boolean', short: 'v' },
44
44
  help: { type: 'boolean', short: 'h' },
45
- mode: { type: 'string', default: 'development' }
45
+ mode: { type: 'string', default: 'development' },
46
+ config: { type: 'string', short: 'c', default: undefined }
46
47
  },
47
48
  allowPositionals: true,
48
49
  strict: true
49
50
  });
50
51
  } catch (err) {
51
52
  const error = /** @type {Error} */ (err);
52
- console.error(colors.bold().red(`> ${error.message}`));
53
+ console.error(styleText(['bold', 'red'], `> ${error.message}`));
53
54
  console.log(help);
54
55
  process.exit(1);
55
56
  }
@@ -95,12 +96,14 @@ if (command === 'sync') {
95
96
  }
96
97
 
97
98
  try {
98
- const config = await load_config();
99
+ const vite_config = await load_vite_config(values.config);
100
+ const sveltekit_config = extract_svelte_config(vite_config);
101
+
99
102
  const sync = await import('./core/sync/sync.js');
100
- sync.all_types(config, values.mode);
103
+ sync.all_types(sveltekit_config);
101
104
 
102
- const explicit_env_entry = resolve_explicit_env_entry(config.kit);
103
- await sync.env(config.kit, explicit_env_entry, values.mode);
105
+ const explicit_env_entry = resolve_explicit_env_entry(sveltekit_config.kit);
106
+ await sync.env(sveltekit_config.kit, explicit_env_entry, vite_config.root, values.mode);
104
107
  } catch (error) {
105
108
  handle_error(error);
106
109
  } finally {
@@ -115,7 +118,7 @@ if (command === 'sync') {
115
118
  }
116
119
  }
117
120
  } else {
118
- console.error(colors.bold().red(`> Unknown command: ${command}`));
121
+ console.error(styleText(['bold', 'red'], `> Unknown command: ${command}`));
119
122
  console.log(help);
120
123
  process.exit(1);
121
124
  }
@@ -3,17 +3,17 @@
3
3
  /** @import { ResolvedConfig } from 'vite' */
4
4
  /** @import { RouteDefinition, EnvVarConfig } from '@sveltejs/kit' */
5
5
  /** @import { RouteData, ValidatedConfig, BuildData, ServerMetadata, ServerMetadataRoute, Prerendered, PrerenderMap, Logger, RemoteChunk } from 'types' */
6
- import colors from 'kleur';
6
+ import { loadEnv } from 'vite';
7
7
  import * as devalue from 'devalue';
8
8
  import { createReadStream, createWriteStream, existsSync, statSync } from 'node:fs';
9
9
  import { extname, resolve, join, dirname, relative } from 'node:path';
10
10
  import { pipeline } from 'node:stream';
11
- import { promisify } from 'node:util';
11
+ import { promisify, styleText } from 'node:util';
12
12
  import zlib from 'node:zlib';
13
- import { copy, rimraf, mkdirp, posixify } from '../../utils/filesystem.js';
13
+ import { copy, rimraf, mkdirp } from '../../utils/filesystem.js';
14
+ import { posixify } from '../../utils/os.js';
14
15
  import { generate_manifest } from '../generate_manifest/index.js';
15
16
  import { get_route_segments } from '../../utils/routing.js';
16
- import { get_env } from '../../exports/vite/utils.js';
17
17
  import generate_fallback from '../postbuild/fallback.js';
18
18
  import { write } from '../sync/utils.js';
19
19
  import { list_files } from '../utils.js';
@@ -109,71 +109,21 @@ export function create_builder({
109
109
  );
110
110
  },
111
111
 
112
- async createEntries(fn) {
113
- const seen = new Set();
114
-
115
- for (let i = 0; i < route_data.length; i += 1) {
116
- const route = route_data[i];
117
- if (prerender_map.get(route.id) === true) continue;
118
- const { id, filter, complete } = fn(routes[i]);
119
-
120
- if (seen.has(id)) continue;
121
- seen.add(id);
122
-
123
- const group = [route];
124
-
125
- // figure out which lower priority routes should be considered fallbacks
126
- for (let j = i + 1; j < route_data.length; j += 1) {
127
- if (prerender_map.get(routes[j].id) === true) continue;
128
- if (filter(routes[j])) {
129
- group.push(route_data[j]);
130
- }
131
- }
132
-
133
- const filtered = new Set(group);
134
-
135
- // heuristic: if /foo/[bar] is included, /foo/[bar].json should
136
- // also be included, since the page likely needs the endpoint
137
- // TODO is this still necessary, given the new way of doing things?
138
- filtered.forEach((route) => {
139
- if (route.page) {
140
- const endpoint = route_data.find((candidate) => candidate.id === route.id + '.json');
141
-
142
- if (endpoint) {
143
- filtered.add(endpoint);
144
- }
145
- }
146
- });
147
-
148
- if (filtered.size > 0) {
149
- await complete({
150
- generateManifest: ({ relativePath }) =>
151
- generate_manifest({
152
- build_data,
153
- prerendered: [],
154
- relative_path: relativePath,
155
- routes: Array.from(filtered),
156
- remotes
157
- })
158
- });
159
- }
160
- }
161
- },
162
-
163
112
  findServerAssets(route_data) {
164
113
  return find_server_assets(
165
114
  build_data,
166
- route_data.map((route) => /** @type {import('types').RouteData} */ (lookup.get(route)))
115
+ route_data.map((route) => /** @type {import('types').RouteData} */ (lookup.get(route))),
116
+ vite_config.root
167
117
  );
168
118
  },
169
119
 
170
120
  async generateFallback(dest) {
171
121
  const manifest_path = `${config.kit.outDir}/output/server/manifest-full.js`;
172
- const env = get_env(config.kit.env, vite_config.mode);
122
+ const env = loadEnv(vite_config.mode, config.kit.env.dir, '');
173
123
 
174
124
  const fallback = await generate_fallback({
175
125
  manifest_path,
176
- env: env.all,
126
+ env,
177
127
  out_dir: config.kit.outDir,
178
128
  origin: config.kit.prerender.origin,
179
129
  assets: config.kit.files.assets
@@ -181,11 +131,10 @@ export function create_builder({
181
131
 
182
132
  if (existsSync(dest)) {
183
133
  console.log(
184
- colors
185
- .bold()
186
- .yellow(
187
- `Overwriting ${dest} with fallback page. Consider using a different name for the fallback.`
188
- )
134
+ styleText(
135
+ ['bold', 'yellow'],
136
+ `Overwriting ${dest} with fallback page. Consider using a different name for the fallback.`
137
+ )
189
138
  );
190
139
  }
191
140
 
@@ -196,24 +145,22 @@ export function create_builder({
196
145
  if (!build_data.client?.uses_env_dynamic_public) return;
197
146
 
198
147
  const dest = `${config.kit.outDir}/output/prerendered/dependencies/${config.kit.appDir}/env.js`;
199
- const env = get_env(config.kit.env, vite_config.mode);
148
+ const env = loadEnv(vite_config.mode, config.kit.env.dir, '');
200
149
 
201
- const values = config.kit.experimental.explicitEnvironmentVariables ? {} : env.public;
150
+ /** @type {Record<string, any>} */
151
+ const values = {};
152
+ const variables = explicit_env_config ?? {};
202
153
 
203
- if (config.kit.experimental.explicitEnvironmentVariables) {
204
- const variables = explicit_env_config ?? {};
154
+ /** @type {Record<string, StandardSchemaV1.Issue[]>} */
155
+ const issues = {};
205
156
 
206
- /** @type {Record<string, StandardSchemaV1.Issue[]>} */
207
- const issues = {};
208
-
209
- for (const [name, config] of Object.entries(variables)) {
210
- if (config.static || !config.public) continue;
211
- values[name] = validate(variables, env.all[name], name, issues);
212
- }
213
-
214
- handle_issues(issues);
157
+ for (const [name, config] of Object.entries(variables)) {
158
+ if (config.static || !config.public) continue;
159
+ values[name] = validate(variables, env[name], name, issues);
215
160
  }
216
161
 
162
+ handle_issues(issues);
163
+
217
164
  write(dest, `export const env=${devalue.uneval(values)}`);
218
165
  },
219
166
 
@@ -225,7 +172,8 @@ export function create_builder({
225
172
  routes: subset
226
173
  ? subset.map((route) => /** @type {import('types').RouteData} */ (lookup.get(route)))
227
174
  : route_data.filter((route) => prerender_map.get(route.id) !== true),
228
- remotes
175
+ remotes,
176
+ root: vite_config.root
229
177
  });
230
178
  },
231
179
 
@@ -1,7 +1,9 @@
1
- import colors from 'kleur';
1
+ /** @import { Adapter } from '@sveltejs/kit' */
2
+ import { styleText } from 'node:util';
2
3
  import { create_builder } from './builder.js';
3
4
 
4
5
  /**
6
+ * @param {Adapter} adapter
5
7
  * @param {import('types').ValidatedConfig} config
6
8
  * @param {import('types').BuildData} build_data
7
9
  * @param {import('types').ServerMetadata} server_metadata
@@ -13,6 +15,7 @@ import { create_builder } from './builder.js';
13
15
  * @param {Record<string, import('@sveltejs/kit').EnvVarConfig<any>> | null} explicit_env_config
14
16
  */
15
17
  export async function adapt(
18
+ adapter,
16
19
  config,
17
20
  build_data,
18
21
  server_metadata,
@@ -23,10 +26,9 @@ export async function adapt(
23
26
  vite_config,
24
27
  explicit_env_config
25
28
  ) {
26
- // This is only called when adapter is truthy, so the cast is safe
27
- const { name, adapt } = /** @type {import('@sveltejs/kit').Adapter} */ (config.kit.adapter);
29
+ const { name, adapt } = adapter;
28
30
 
29
- console.log(colors.bold().cyan(`\n> Using ${name}`));
31
+ console.log(styleText(['bold', 'cyan'], `\n> Using ${name}`));
30
32
 
31
33
  const builder = create_builder({
32
34
  config,
@@ -16,7 +16,7 @@ import { import_peer } from '../../utils/import.js';
16
16
  * @param {ValidatedConfig} config
17
17
  */
18
18
  export function load_template(cwd, { kit }) {
19
- const { env, files } = kit;
19
+ const { files } = kit;
20
20
 
21
21
  const relative = path.relative(cwd, files.appTemplate);
22
22
 
@@ -33,16 +33,6 @@ export function load_template(cwd, { kit }) {
33
33
  }
34
34
  });
35
35
 
36
- if (!kit.experimental.explicitEnvironmentVariables) {
37
- for (const match of contents.matchAll(/%sveltekit\.env\.([^%]+)%/g)) {
38
- if (!match[1].startsWith(env.publicPrefix)) {
39
- throw new Error(
40
- `Environment variables in ${relative} must start with ${env.publicPrefix} (saw %sveltekit.env.${match[1]}%)`
41
- );
42
- }
43
- }
44
- }
45
-
46
36
  return contents;
47
37
  }
48
38
 
@@ -64,85 +54,23 @@ export function load_error_page(config) {
64
54
  }
65
55
 
66
56
  /**
67
- * Loads and validates Svelte config file. Tries Vite config first, falls back to svelte.config.js
68
- * @param {{ cwd?: string }} options
69
- * @returns {Promise<ValidatedConfig>}
57
+ * @param {string} [config]
70
58
  */
71
- export async function load_config({ cwd = process.cwd() } = {}) {
72
- try {
73
- const vite_config = await load_config_from_vite({ cwd });
74
- if (vite_config) {
75
- return vite_config;
76
- }
77
- } catch (e) {
78
- // TODO SvelteKit 3: fail completely instead
79
- console.error(
80
- 'Loading Svelte config from Vite config failed:',
81
- e,
82
- '\n\nFalling back to loading svelte.config.js'
83
- );
84
- }
85
-
86
- return load_svelte_config(cwd);
87
- }
88
-
89
- /**
90
- * Loads and validates Svelte config file
91
- * @param {string} [cwd]
92
- * @returns {Promise<ValidatedConfig>}
93
- */
94
- export async function load_svelte_config(cwd = process.cwd()) {
95
- const config_files = ['js', 'ts']
96
- .map((ext) => path.join(cwd, `svelte.config.${ext}`))
97
- .filter((f) => fs.existsSync(f));
98
-
99
- if (config_files.length === 0) {
100
- console.log(
101
- `No Svelte config file found in ${cwd} - using SvelteKit's default configuration without an adapter.`
102
- );
103
- return process_config({}, { cwd });
104
- }
105
-
106
- const config_file = config_files[0];
107
- if (config_files.length > 1) {
108
- console.log(
109
- `Found multiple Svelte config files in ${cwd}: ${config_files.map((f) => path.basename(f)).join(', ')}. Using ${path.basename(config_file)}`
110
- );
111
- }
59
+ export async function load_vite_config(config) {
60
+ const { resolveConfig } = /** @type {import('vite')} */ (
61
+ await import_peer('vite', process.cwd())
62
+ );
112
63
 
113
- const config = await import(`${url.pathToFileURL(config_file).href}?ts=${Date.now()}`);
114
- return process_config(config.default, { cwd, source: path.relative(cwd, config_file) });
64
+ return resolveConfig({ configFile: config }, 'build', process.env.MODE ?? 'production');
115
65
  }
116
66
 
117
67
  /**
118
- * Loads and validates Svelte config via Vite config resolution (if set that way).
119
- * @param {{ cwd?: string; mode?: string }} options
120
- * @returns {Promise<ValidatedConfig | undefined>}
68
+ * @param {ResolvedConfig} vite_config
69
+ * @returns {ValidatedConfig}
121
70
  */
122
- async function load_config_from_vite({ cwd = process.cwd(), mode } = {}) {
123
- const { resolveConfig } = await import_peer('vite');
124
- const current_cwd = process.cwd();
125
-
126
- if (cwd !== current_cwd) {
127
- process.chdir(cwd);
128
- }
129
-
130
- /** @type {ResolvedConfig} */
131
- let resolved;
132
-
133
- try {
134
- resolved = await resolveConfig({}, 'build', mode ?? process.env.MODE ?? 'production');
135
- } finally {
136
- if (cwd !== current_cwd) {
137
- process.chdir(current_cwd);
138
- }
139
- }
140
-
141
- const plugin = resolved.plugins.find(
142
- (plugin) => plugin.name === 'vite-plugin-sveltekit-setup' && plugin.api?.options
143
- );
144
-
145
- return plugin?.api.options;
71
+ export function extract_svelte_config(vite_config) {
72
+ const plugin = vite_config.plugins.find((p) => p.name === 'vite-plugin-sveltekit-setup');
73
+ return plugin?.api.options ?? process_config({});
146
74
  }
147
75
 
148
76
  /**
@@ -1,8 +1,6 @@
1
1
  /** @import { Validator } from './types.js' */
2
2
 
3
3
  import process from 'node:process';
4
- import colors from 'kleur';
5
- import { supportsTrustedTypes } from '../sync/utils.js';
6
4
 
7
5
  const directives = object({
8
6
  'child-src': string_array(),
@@ -29,14 +27,8 @@ const directives = object({
29
27
  'navigate-to': string_array(),
30
28
  'report-uri': string_array(),
31
29
  'report-to': string_array(),
32
- 'require-trusted-types-for': validate(undefined, (input, keypath) => {
33
- assert_trusted_types_supported(keypath);
34
- return string_array()(input, keypath);
35
- }),
36
- 'trusted-types': validate(undefined, (input, keypath) => {
37
- assert_trusted_types_supported(keypath);
38
- return string_array()(input, keypath);
39
- }),
30
+ 'require-trusted-types-for': string_array(),
31
+ 'trusted-types': string_array(),
40
32
  'upgrade-insecure-requests': boolean(false),
41
33
  'require-sri-for': string_array(),
42
34
  'block-all-mixed-content': boolean(false),
@@ -66,15 +58,9 @@ const options = object(
66
58
  }),
67
59
 
68
60
  kit: object({
69
- adapter: validate(null, (input, keypath) => {
61
+ adapter: validate(undefined, (input, keypath) => {
70
62
  if (typeof input !== 'object' || !input.adapt) {
71
- let message = `${keypath} should be an object with an "adapt" method`;
72
-
73
- if (Array.isArray(input) || typeof input === 'string') {
74
- // for the early adapter adopters
75
- message += ', rather than the name of an adapter';
76
- }
77
-
63
+ const message = `The SvelteKit Vite plugin ${keypath} should be an object with an \`adapt\` method`;
78
64
  throw new Error(`${message}. See https://svelte.dev/docs/kit/adapters`);
79
65
  }
80
66
 
@@ -116,10 +102,8 @@ const options = object(
116
102
  }),
117
103
 
118
104
  csrf: object({
119
- checkOrigin: deprecate(
120
- boolean(true),
121
- (keypath) =>
122
- `\`${keypath}\` has been deprecated in favour of \`csrf.trustedOrigins\`. It will be removed in a future version`
105
+ checkOrigin: removed(
106
+ (keypath) => `\`${keypath}\` has been removed in favour of \`csrf.trustedOrigins\``
123
107
  ),
124
108
  trustedOrigins: string_array([])
125
109
  }),
@@ -127,9 +111,7 @@ const options = object(
127
111
  embedded: boolean(false),
128
112
 
129
113
  env: object({
130
- dir: string(process.cwd()),
131
- publicPrefix: string('PUBLIC_'),
132
- privatePrefix: string('')
114
+ dir: string(process.cwd())
133
115
  }),
134
116
 
135
117
  experimental: object({
@@ -139,7 +121,6 @@ const options = object(
139
121
  instrumentation: object({
140
122
  server: boolean(false)
141
123
  }),
142
- explicitEnvironmentVariables: boolean(false),
143
124
  remoteFunctions: boolean(false),
144
125
  forkPreloads: boolean(false),
145
126
  handleRenderingErrors: boolean(false)
@@ -168,7 +149,10 @@ const options = object(
168
149
  outDir: string('.svelte-kit'),
169
150
 
170
151
  output: object({
171
- preloadStrategy: list(['modulepreload', 'preload-js', 'preload-mjs']),
152
+ linkHeaderPreload: boolean(false),
153
+ preloadStrategy: removed(
154
+ (keypath) => `\`${keypath}\` has been removed. modulepreload will always be used`
155
+ ),
172
156
  bundleStrategy: list(['split', 'single', 'inline'])
173
157
  }),
174
158
 
@@ -326,22 +310,37 @@ const options = object(
326
310
  true
327
311
  );
328
312
 
313
+ // /**
314
+ // * @param {Validator} fn
315
+ // * @param {(keypath: string) => string} get_message
316
+ // * @returns {Validator}
317
+ // */
318
+ // function deprecate(
319
+ // fn,
320
+ // get_message = (keypath) =>
321
+ // `The \`${keypath}\` option is deprecated, and will be removed in a future version`
322
+ // ) {
323
+ // return (input, keypath) => {
324
+ // if (input !== undefined) {
325
+ // console.warn(styleText(['bold', 'yellow'], get_message(keypath)));
326
+ // }
327
+
328
+ // return fn(input, keypath);
329
+ // };
330
+ // }
331
+
329
332
  /**
330
- * @param {Validator} fn
331
333
  * @param {(keypath: string) => string} get_message
332
334
  * @returns {Validator}
333
335
  */
334
- function deprecate(
335
- fn,
336
+ function removed(
336
337
  get_message = (keypath) =>
337
- `The \`${keypath}\` option is deprecated, and will be removed in a future version`
338
+ `The \`${keypath}\` option has been removed. Please see the list of breaking changes for your major release`
338
339
  ) {
339
340
  return (input, keypath) => {
340
- if (input !== undefined) {
341
- console.warn(colors.bold().yellow(get_message(keypath)));
341
+ if (typeof input !== 'undefined') {
342
+ throw new Error(get_message(keypath));
342
343
  }
343
-
344
- return fn(input, keypath);
345
344
  };
346
345
  }
347
346
 
@@ -350,7 +349,7 @@ function deprecate(
350
349
  * @param {boolean} [allow_unknown]
351
350
  * @returns {Validator}
352
351
  */
353
- function object(children, allow_unknown = false) {
352
+ export function object(children, allow_unknown = false) {
354
353
  return (input, keypath) => {
355
354
  /** @type {Record<string, any>} */
356
355
  const output = {};
@@ -390,7 +389,7 @@ function object(children, allow_unknown = false) {
390
389
  * @param {(value: any, keypath: string) => any} fn
391
390
  * @returns {Validator}
392
391
  */
393
- function validate(fallback, fn) {
392
+ export function validate(fallback, fn) {
394
393
  return (input, keypath) => {
395
394
  return input === undefined ? fallback : fn(input, keypath);
396
395
  };
@@ -494,13 +493,4 @@ function assert_string(input, keypath) {
494
493
  }
495
494
  }
496
495
 
497
- /** @param {string} keypath */
498
- function assert_trusted_types_supported(keypath) {
499
- if (!supportsTrustedTypes()) {
500
- throw new Error(
501
- `${keypath} is not supported by your version of Svelte. Please upgrade to Svelte 5.51.0 or later to use this directive.`
502
- );
503
- }
504
- }
505
-
506
496
  export default options;