@sveltejs/kit 1.0.0-next.42 → 1.0.0-next.422

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 (126) hide show
  1. package/README.md +12 -9
  2. package/package.json +95 -63
  3. package/src/cli.js +112 -0
  4. package/src/core/adapt/builder.js +207 -0
  5. package/src/core/adapt/index.js +19 -0
  6. package/src/core/config/index.js +86 -0
  7. package/src/core/config/options.js +482 -0
  8. package/src/core/config/types.d.ts +1 -0
  9. package/src/core/constants.js +5 -0
  10. package/src/core/env.js +91 -0
  11. package/src/core/generate_manifest/index.js +99 -0
  12. package/src/core/prerender/crawl.js +194 -0
  13. package/src/core/prerender/prerender.js +378 -0
  14. package/src/core/prerender/queue.js +80 -0
  15. package/src/core/sync/create_manifest_data/index.js +506 -0
  16. package/src/core/sync/create_manifest_data/types.d.ts +40 -0
  17. package/src/core/sync/sync.js +59 -0
  18. package/src/core/sync/utils.js +44 -0
  19. package/src/core/sync/write_ambient.js +27 -0
  20. package/src/core/sync/write_client_manifest.js +82 -0
  21. package/src/core/sync/write_matchers.js +25 -0
  22. package/src/core/sync/write_root.js +88 -0
  23. package/src/core/sync/write_tsconfig.js +189 -0
  24. package/src/core/sync/write_types.js +769 -0
  25. package/src/core/utils.js +58 -0
  26. package/src/hooks.js +26 -0
  27. package/src/index/index.js +45 -0
  28. package/src/index/private.js +33 -0
  29. package/src/node/index.js +145 -0
  30. package/src/node/polyfills.js +40 -0
  31. package/src/runtime/app/env.js +11 -0
  32. package/src/runtime/app/navigation.js +22 -0
  33. package/src/runtime/app/paths.js +1 -0
  34. package/src/runtime/app/stores.js +91 -0
  35. package/src/runtime/client/ambient.d.ts +17 -0
  36. package/src/runtime/client/client.js +1258 -0
  37. package/src/runtime/client/fetcher.js +60 -0
  38. package/src/runtime/client/parse.js +36 -0
  39. package/src/runtime/client/singletons.js +11 -0
  40. package/src/runtime/client/start.js +46 -0
  41. package/src/runtime/client/types.d.ts +105 -0
  42. package/src/runtime/client/utils.js +113 -0
  43. package/src/runtime/components/error.svelte +16 -0
  44. package/{assets → src/runtime}/components/layout.svelte +0 -0
  45. package/src/runtime/env/dynamic/private.js +1 -0
  46. package/src/runtime/env/dynamic/public.js +1 -0
  47. package/src/runtime/env-private.js +7 -0
  48. package/src/runtime/env-public.js +7 -0
  49. package/src/runtime/env.js +6 -0
  50. package/src/runtime/hash.js +16 -0
  51. package/src/runtime/paths.js +11 -0
  52. package/src/runtime/server/endpoint.js +58 -0
  53. package/src/runtime/server/index.js +448 -0
  54. package/src/runtime/server/page/cookie.js +25 -0
  55. package/src/runtime/server/page/crypto.js +239 -0
  56. package/src/runtime/server/page/csp.js +249 -0
  57. package/src/runtime/server/page/fetch.js +266 -0
  58. package/src/runtime/server/page/index.js +416 -0
  59. package/src/runtime/server/page/load_data.js +127 -0
  60. package/src/runtime/server/page/render.js +359 -0
  61. package/src/runtime/server/page/respond_with_error.js +94 -0
  62. package/src/runtime/server/page/types.d.ts +44 -0
  63. package/src/runtime/server/utils.js +116 -0
  64. package/src/utils/error.js +22 -0
  65. package/src/utils/escape.js +104 -0
  66. package/src/utils/filesystem.js +108 -0
  67. package/src/utils/http.js +55 -0
  68. package/src/utils/misc.js +1 -0
  69. package/src/utils/routing.js +107 -0
  70. package/src/utils/url.js +97 -0
  71. package/src/vite/build/build_server.js +337 -0
  72. package/src/vite/build/build_service_worker.js +90 -0
  73. package/src/vite/build/utils.js +157 -0
  74. package/src/vite/dev/index.js +568 -0
  75. package/src/vite/index.js +566 -0
  76. package/src/vite/preview/index.js +186 -0
  77. package/src/vite/types.d.ts +3 -0
  78. package/src/vite/utils.js +334 -0
  79. package/svelte-kit.js +1 -1
  80. package/types/ambient.d.ts +355 -0
  81. package/types/index.d.ts +342 -0
  82. package/types/internal.d.ts +308 -0
  83. package/types/private.d.ts +209 -0
  84. package/CHANGELOG.md +0 -425
  85. package/assets/components/error.svelte +0 -13
  86. package/assets/runtime/app/env.js +0 -5
  87. package/assets/runtime/app/navigation.js +0 -41
  88. package/assets/runtime/app/paths.js +0 -1
  89. package/assets/runtime/app/stores.js +0 -93
  90. package/assets/runtime/chunks/utils.js +0 -19
  91. package/assets/runtime/internal/singletons.js +0 -23
  92. package/assets/runtime/internal/start.js +0 -770
  93. package/assets/runtime/paths.js +0 -12
  94. package/dist/api.js +0 -28
  95. package/dist/api.js.map +0 -1
  96. package/dist/chunks/index.js +0 -3521
  97. package/dist/chunks/index2.js +0 -587
  98. package/dist/chunks/index3.js +0 -246
  99. package/dist/chunks/index4.js +0 -530
  100. package/dist/chunks/index5.js +0 -761
  101. package/dist/chunks/index6.js +0 -322
  102. package/dist/chunks/standard.js +0 -99
  103. package/dist/chunks/utils.js +0 -83
  104. package/dist/cli.js +0 -546
  105. package/dist/cli.js.map +0 -1
  106. package/dist/create_app.js +0 -592
  107. package/dist/create_app.js.map +0 -1
  108. package/dist/index.js +0 -392
  109. package/dist/index.js.map +0 -1
  110. package/dist/index2.js +0 -3519
  111. package/dist/index2.js.map +0 -1
  112. package/dist/index3.js +0 -320
  113. package/dist/index3.js.map +0 -1
  114. package/dist/index4.js +0 -323
  115. package/dist/index4.js.map +0 -1
  116. package/dist/index5.js +0 -247
  117. package/dist/index5.js.map +0 -1
  118. package/dist/index6.js +0 -761
  119. package/dist/index6.js.map +0 -1
  120. package/dist/renderer.js +0 -2499
  121. package/dist/renderer.js.map +0 -1
  122. package/dist/ssr.js +0 -2581
  123. package/dist/standard.js +0 -100
  124. package/dist/standard.js.map +0 -1
  125. package/dist/utils.js +0 -84
  126. package/dist/utils.js.map +0 -1
@@ -0,0 +1,566 @@
1
+ import { fork } from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import colors from 'kleur';
5
+ import { svelte } from '@sveltejs/vite-plugin-svelte';
6
+ import * as vite from 'vite';
7
+ import { mkdirp, posixify, rimraf } from '../utils/filesystem.js';
8
+ import * as sync from '../core/sync/sync.js';
9
+ import { build_server } from './build/build_server.js';
10
+ import { build_service_worker } from './build/build_service_worker.js';
11
+ import { load_config } from '../core/config/index.js';
12
+ import { dev } from './dev/index.js';
13
+ import { generate_manifest } from '../core/generate_manifest/index.js';
14
+ import { runtime_directory, logger } from '../core/utils.js';
15
+ import { find_deps, get_default_build_config } from './build/utils.js';
16
+ import { preview } from './preview/index.js';
17
+ import { get_aliases, resolve_entry, prevent_illegal_rollup_imports, get_env } from './utils.js';
18
+ import { fileURLToPath } from 'node:url';
19
+ import { create_module } from '../core/env.js';
20
+
21
+ const cwd = process.cwd();
22
+
23
+ /** @type {import('./types').EnforcedConfig} */
24
+ const enforced_config = {
25
+ appType: true,
26
+ base: true,
27
+ build: {
28
+ cssCodeSplit: true,
29
+ emptyOutDir: true,
30
+ lib: {
31
+ entry: true,
32
+ name: true,
33
+ formats: true
34
+ },
35
+ manifest: true,
36
+ outDir: true,
37
+ polyfillModulePreload: true,
38
+ rollupOptions: {
39
+ input: true,
40
+ output: {
41
+ format: true,
42
+ entryFileNames: true,
43
+ chunkFileNames: true,
44
+ assetFileNames: true
45
+ },
46
+ preserveEntrySignatures: true
47
+ },
48
+ ssr: true
49
+ },
50
+ publicDir: true,
51
+ resolve: {
52
+ alias: {
53
+ $app: true,
54
+ $lib: true,
55
+ '$service-worker': true
56
+ }
57
+ },
58
+ root: true
59
+ };
60
+
61
+ /**
62
+ * @return {import('vite').Plugin[]}
63
+ */
64
+ export function sveltekit() {
65
+ return [...svelte(), kit()];
66
+ }
67
+
68
+ /**
69
+ * Returns the SvelteKit Vite plugin. Vite executes Rollup hooks as well as some of its own.
70
+ * Background reading is available at:
71
+ * - https://vitejs.dev/guide/api-plugin.html
72
+ * - https://rollupjs.org/guide/en/#plugin-development
73
+ *
74
+ * You can get an idea of the lifecycle by looking at the flow charts here:
75
+ * - https://rollupjs.org/guide/en/#build-hooks
76
+ * - https://rollupjs.org/guide/en/#output-generation-hooks
77
+ *
78
+ * @return {import('vite').Plugin}
79
+ */
80
+ function kit() {
81
+ /** @type {import('types').ValidatedConfig} */
82
+ let svelte_config;
83
+
84
+ /** @type {import('vite').ResolvedConfig} */
85
+ let vite_config;
86
+
87
+ /** @type {import('vite').ConfigEnv} */
88
+ let vite_config_env;
89
+
90
+ /** @type {import('types').ManifestData} */
91
+ let manifest_data;
92
+
93
+ /** @type {boolean} */
94
+ let is_build;
95
+
96
+ /** @type {import('types').Logger} */
97
+ let log;
98
+
99
+ /** @type {import('types').Prerendered} */
100
+ let prerendered;
101
+
102
+ /** @type {import('types').BuildData} */
103
+ let build_data;
104
+
105
+ /** @type {Set<string>} */
106
+ let illegal_imports;
107
+
108
+ /** @type {string | undefined} */
109
+ let deferred_warning;
110
+
111
+ /** @type {{ public: Record<string, string>; private: Record<string, string> }} */
112
+ let env;
113
+
114
+ /**
115
+ * @type {{
116
+ * build_dir: string;
117
+ * output_dir: string;
118
+ * client_out_dir: string;
119
+ * }}
120
+ */
121
+ let paths;
122
+
123
+ let completed_build = false;
124
+
125
+ function vite_client_build_config() {
126
+ /** @type {Record<string, string>} */
127
+ const input = {
128
+ // Put unchanging assets in immutable directory. We don't set that in the
129
+ // outDir so that other plugins can add mutable assets to the bundle
130
+ start: `${runtime_directory}/client/start.js`
131
+ };
132
+
133
+ manifest_data.nodes.forEach((node) => {
134
+ if (node.component) {
135
+ const resolved = path.resolve(cwd, node.component);
136
+ const relative = decodeURIComponent(
137
+ path.relative(svelte_config.kit.files.routes, resolved)
138
+ );
139
+
140
+ const name = relative.startsWith('..')
141
+ ? path.basename(node.component)
142
+ : posixify(path.join('pages', relative));
143
+ input[`components/${name}`] = resolved;
144
+ }
145
+
146
+ if (node.shared) {
147
+ const resolved = path.resolve(cwd, node.shared);
148
+ const relative = decodeURIComponent(
149
+ path.relative(svelte_config.kit.files.routes, resolved)
150
+ );
151
+
152
+ const name = relative.startsWith('..')
153
+ ? path.basename(node.shared)
154
+ : posixify(path.join('pages', relative));
155
+ input[`modules/${name}`] = resolved;
156
+ }
157
+ });
158
+
159
+ return get_default_build_config({
160
+ config: svelte_config,
161
+ input,
162
+ ssr: false,
163
+ outDir: `${paths.client_out_dir}`
164
+ });
165
+ }
166
+
167
+ /**
168
+ * @param {import('rollup').OutputAsset[]} assets
169
+ * @param {import('rollup').OutputChunk[]} chunks
170
+ */
171
+ function client_build_info(assets, chunks) {
172
+ /** @type {import('vite').Manifest} */
173
+ const vite_manifest = JSON.parse(
174
+ fs.readFileSync(`${paths.client_out_dir}/${vite_config.build.manifest}`, 'utf-8')
175
+ );
176
+
177
+ const entry_id = posixify(path.relative(cwd, `${runtime_directory}/client/start.js`));
178
+
179
+ return {
180
+ assets,
181
+ chunks,
182
+ entry: find_deps(vite_manifest, entry_id, false),
183
+ vite_manifest
184
+ };
185
+ }
186
+
187
+ // TODO remove this for 1.0
188
+ check_vite_version();
189
+
190
+ return {
191
+ name: 'vite-plugin-svelte-kit',
192
+
193
+ /**
194
+ * Build the SvelteKit-provided Vite config to be merged with the user's vite.config.js file.
195
+ * @see https://vitejs.dev/guide/api-plugin.html#config
196
+ */
197
+ async config(config, config_env) {
198
+ vite_config_env = config_env;
199
+ svelte_config = await load_config();
200
+ env = get_env(vite_config_env.mode, svelte_config.kit.env.publicPrefix);
201
+
202
+ // The config is created in build_server for SSR mode and passed inline
203
+ if (config.build?.ssr) return;
204
+
205
+ is_build = config_env.command === 'build';
206
+
207
+ paths = {
208
+ build_dir: `${svelte_config.kit.outDir}/build`,
209
+ output_dir: `${svelte_config.kit.outDir}/output`,
210
+ client_out_dir: `${svelte_config.kit.outDir}/output/client`
211
+ };
212
+
213
+ illegal_imports = new Set([
214
+ vite.normalizePath(`${svelte_config.kit.outDir}/runtime/env/dynamic/private.js`),
215
+ vite.normalizePath(`${svelte_config.kit.outDir}/runtime/env/static/private.js`)
216
+ ]);
217
+
218
+ if (is_build) {
219
+ manifest_data = (await sync.all(svelte_config, config_env.mode)).manifest_data;
220
+
221
+ const new_config = vite_client_build_config();
222
+
223
+ const warning = warn_overridden_config(config, new_config);
224
+ if (warning) console.error(warning + '\n');
225
+
226
+ return new_config;
227
+ }
228
+
229
+ // dev and preview config can be shared
230
+ /** @type {import('vite').UserConfig} */
231
+ const result = {
232
+ appType: 'custom',
233
+ base: './',
234
+ build: {
235
+ rollupOptions: {
236
+ // Vite dependency crawler needs an explicit JS entry point
237
+ // eventhough server otherwise works without it
238
+ input: `${runtime_directory}/client/start.js`
239
+ }
240
+ },
241
+ define: {
242
+ __SVELTEKIT_DEV__: 'true',
243
+ __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0'
244
+ },
245
+ publicDir: svelte_config.kit.files.assets,
246
+ resolve: {
247
+ alias: get_aliases(svelte_config.kit)
248
+ },
249
+ root: cwd,
250
+ server: {
251
+ fs: {
252
+ allow: [
253
+ ...new Set([
254
+ svelte_config.kit.files.lib,
255
+ svelte_config.kit.files.routes,
256
+ svelte_config.kit.outDir,
257
+ path.resolve(cwd, 'src'),
258
+ path.resolve(cwd, 'node_modules'),
259
+ path.resolve(vite.searchForWorkspaceRoot(cwd), 'node_modules')
260
+ ])
261
+ ]
262
+ },
263
+ watch: {
264
+ ignored: [
265
+ // Ignore all siblings of config.kit.outDir/generated
266
+ `${posixify(svelte_config.kit.outDir)}/!(generated)`
267
+ ]
268
+ }
269
+ },
270
+ ssr: {
271
+ // Without this, Vite will treat `@sveltejs/kit` as noExternal if it's
272
+ // a linked dependency, and that causes modules to be imported twice
273
+ // under different IDs, which breaks a bunch of stuff
274
+ // https://github.com/vitejs/vite/pull/9296
275
+ external: ['@sveltejs/kit']
276
+ }
277
+ };
278
+
279
+ deferred_warning = warn_overridden_config(config, result);
280
+ return result;
281
+ },
282
+
283
+ async resolveId(id) {
284
+ // treat $env/static/[public|private] as virtual
285
+ if (id.startsWith('$env/static/')) return `\0${id}`;
286
+ },
287
+
288
+ async load(id) {
289
+ switch (id) {
290
+ case '\0$env/static/private':
291
+ return create_module('$env/static/private', env.private);
292
+ case '\0$env/static/public':
293
+ return create_module('$env/static/public', env.public);
294
+ }
295
+ },
296
+
297
+ /**
298
+ * Stores the final config.
299
+ */
300
+ configResolved(config) {
301
+ vite_config = config;
302
+ },
303
+
304
+ /**
305
+ * Clears the output directories.
306
+ */
307
+ buildStart() {
308
+ if (vite_config.build.ssr) {
309
+ return;
310
+ }
311
+
312
+ // Reset for new build. Goes here because `build --watch` calls buildStart but not config
313
+ completed_build = false;
314
+
315
+ if (is_build) {
316
+ rimraf(paths.build_dir);
317
+ mkdirp(paths.build_dir);
318
+
319
+ rimraf(paths.output_dir);
320
+ mkdirp(paths.output_dir);
321
+ }
322
+ },
323
+
324
+ /**
325
+ * Vite builds a single bundle. We need three bundles: client, server, and service worker.
326
+ * The user's package.json scripts will invoke the Vite CLI to execute the client build. We
327
+ * then use this hook to kick off builds for the server and service worker.
328
+ */
329
+ async writeBundle(_options, bundle) {
330
+ if (vite_config.build.ssr) {
331
+ return;
332
+ }
333
+
334
+ manifest_data.nodes.forEach((_node, i) => {
335
+ const id = vite.normalizePath(
336
+ path.resolve(svelte_config.kit.outDir, `generated/nodes/${i}.js`)
337
+ );
338
+
339
+ const module_node = this.getModuleInfo(id);
340
+
341
+ if (module_node) {
342
+ prevent_illegal_rollup_imports(
343
+ this.getModuleInfo.bind(this),
344
+ module_node,
345
+ illegal_imports,
346
+ svelte_config.kit.outDir
347
+ );
348
+ }
349
+ });
350
+
351
+ const verbose = vite_config.logLevel === 'info';
352
+ log = logger({
353
+ verbose
354
+ });
355
+
356
+ fs.writeFileSync(
357
+ `${paths.client_out_dir}/${svelte_config.kit.appDir}/version.json`,
358
+ JSON.stringify({ version: svelte_config.kit.version.name })
359
+ );
360
+
361
+ const { assets, chunks } = collect_output(bundle);
362
+ log.info(`Client build completed. Wrote ${chunks.length} chunks and ${assets.length} assets`);
363
+
364
+ log.info('Building server');
365
+ const options = {
366
+ cwd,
367
+ config: svelte_config,
368
+ vite_config,
369
+ vite_config_env,
370
+ build_dir: paths.build_dir, // TODO just pass `paths`
371
+ manifest_data,
372
+ output_dir: paths.output_dir,
373
+ service_worker_entry_file: resolve_entry(svelte_config.kit.files.serviceWorker)
374
+ };
375
+ const client = client_build_info(assets, chunks);
376
+ const server = await build_server(options, client);
377
+
378
+ /** @type {import('types').BuildData} */
379
+ build_data = {
380
+ app_dir: svelte_config.kit.appDir,
381
+ manifest_data,
382
+ service_worker: options.service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
383
+ client,
384
+ server
385
+ };
386
+
387
+ const manifest_path = `${paths.output_dir}/server/manifest.js`;
388
+ fs.writeFileSync(
389
+ manifest_path,
390
+ `export const manifest = ${generate_manifest({
391
+ build_data,
392
+ relative_path: '.',
393
+ routes: manifest_data.routes
394
+ })};\n`
395
+ );
396
+
397
+ log.info('Prerendering');
398
+ await new Promise((fulfil, reject) => {
399
+ const results_path = `${svelte_config.kit.outDir}/generated/prerendered.json`;
400
+
401
+ // do prerendering in a subprocess so any dangling stuff gets killed upon completion
402
+ const script = fileURLToPath(new URL('../core/prerender/prerender.js', import.meta.url));
403
+
404
+ const child = fork(
405
+ script,
406
+ [vite_config.build.outDir, results_path, manifest_path, '' + verbose],
407
+ {
408
+ stdio: 'inherit'
409
+ }
410
+ );
411
+
412
+ child.on('exit', (code) => {
413
+ if (code) {
414
+ reject(new Error(`Prerendering failed with code ${code}`));
415
+ } else {
416
+ prerendered = JSON.parse(fs.readFileSync(results_path, 'utf8'), (key, value) => {
417
+ if (key === 'pages' || key === 'assets' || key === 'redirects') {
418
+ return new Map(value);
419
+ }
420
+ return value;
421
+ });
422
+ fulfil(undefined);
423
+ }
424
+ });
425
+ });
426
+
427
+ if (options.service_worker_entry_file) {
428
+ if (svelte_config.kit.paths.assets) {
429
+ throw new Error('Cannot use service worker alongside config.kit.paths.assets');
430
+ }
431
+
432
+ log.info('Building service worker');
433
+
434
+ await build_service_worker(options, prerendered, client.vite_manifest);
435
+ }
436
+
437
+ console.log(
438
+ `\nRun ${colors.bold().cyan('npm run preview')} to preview your production build locally.`
439
+ );
440
+
441
+ completed_build = true;
442
+ },
443
+
444
+ /**
445
+ * Runs the adapter.
446
+ */
447
+ async closeBundle() {
448
+ // vite calls closeBundle when dev-server restarts, ignore that,
449
+ // and only adapt when build successfully completes.
450
+ const is_restart = !completed_build;
451
+ if (vite_config.build.ssr || is_restart) {
452
+ return;
453
+ }
454
+
455
+ if (svelte_config.kit.adapter) {
456
+ const { adapt } = await import('../core/adapt/index.js');
457
+ await adapt(svelte_config, build_data, prerendered, { log });
458
+ } else {
459
+ console.log(colors.bold().yellow('\nNo adapter specified'));
460
+
461
+ const link = colors.bold().cyan('https://kit.svelte.dev/docs/adapters');
462
+ console.log(
463
+ `See ${link} to learn how to configure your app to run on the platform of your choosing`
464
+ );
465
+ }
466
+
467
+ // avoid making the manifest available to users
468
+ fs.unlinkSync(`${paths.output_dir}/client/${vite_config.build.manifest}`);
469
+ fs.unlinkSync(`${paths.output_dir}/server/${vite_config.build.manifest}`);
470
+ },
471
+
472
+ /**
473
+ * Adds the SvelteKit middleware to do SSR in dev mode.
474
+ * @see https://vitejs.dev/guide/api-plugin.html#configureserver
475
+ */
476
+ async configureServer(vite) {
477
+ // This method is called by Vite after clearing the screen.
478
+ // This patch ensures we can log any important messages afterwards for the user to see.
479
+ const print_urls = vite.printUrls;
480
+ vite.printUrls = function () {
481
+ print_urls.apply(this);
482
+ if (deferred_warning) console.error('\n' + deferred_warning);
483
+ };
484
+
485
+ return await dev(vite, vite_config, svelte_config, illegal_imports);
486
+ },
487
+
488
+ /**
489
+ * Adds the SvelteKit middleware to do SSR in preview mode.
490
+ * @see https://vitejs.dev/guide/api-plugin.html#configurepreviewserver
491
+ */
492
+ configurePreviewServer(vite) {
493
+ return preview(vite, vite_config, svelte_config);
494
+ }
495
+ };
496
+ }
497
+
498
+ function check_vite_version() {
499
+ // TODO parse from kit peer deps and maybe do a full semver compare if we ever require feature releases a min
500
+ const min_required_vite_major = 3;
501
+ const vite_version = vite.version ?? '2.x'; // vite started exporting it's version in 3.0
502
+ const current_vite_major = parseInt(vite_version.split('.')[0], 10);
503
+
504
+ if (current_vite_major < min_required_vite_major) {
505
+ throw new Error(
506
+ `Vite version ${current_vite_major} is no longer supported. Please upgrade to version ${min_required_vite_major}`
507
+ );
508
+ }
509
+ }
510
+
511
+ /** @param {import('rollup').OutputBundle} bundle */
512
+ function collect_output(bundle) {
513
+ /** @type {import('rollup').OutputChunk[]} */
514
+ const chunks = [];
515
+ /** @type {import('rollup').OutputAsset[]} */
516
+ const assets = [];
517
+ for (const value of Object.values(bundle)) {
518
+ // collect asset and output chunks
519
+ if (value.type === 'asset') {
520
+ assets.push(value);
521
+ } else {
522
+ chunks.push(value);
523
+ }
524
+ }
525
+ return { assets, chunks };
526
+ }
527
+
528
+ /**
529
+ * @param {Record<string, any>} config
530
+ * @param {Record<string, any>} resolved_config
531
+ */
532
+ function warn_overridden_config(config, resolved_config) {
533
+ const overridden = find_overridden_config(config, resolved_config, enforced_config, '', []);
534
+
535
+ if (overridden.length > 0) {
536
+ return (
537
+ colors.bold().red('The following Vite config options will be overridden by SvelteKit:') +
538
+ overridden.map((key) => `\n - ${key}`).join('')
539
+ );
540
+ }
541
+ }
542
+
543
+ /**
544
+ * @param {Record<string, any>} config
545
+ * @param {Record<string, any>} resolved_config
546
+ * @param {import('./types').EnforcedConfig} enforced_config
547
+ * @param {string} path
548
+ * @param {string[]} out used locally to compute the return value
549
+ */
550
+ function find_overridden_config(config, resolved_config, enforced_config, path, out) {
551
+ for (const key in enforced_config) {
552
+ if (typeof config === 'object' && config !== null && key in config) {
553
+ const enforced = enforced_config[key];
554
+
555
+ if (enforced === true) {
556
+ if (config[key] !== resolved_config[key]) {
557
+ out.push(path + key);
558
+ }
559
+ } else {
560
+ find_overridden_config(config[key], resolved_config[key], enforced, path + key + '.', out);
561
+ }
562
+ }
563
+ }
564
+
565
+ return out;
566
+ }