@sveltejs/kit 1.0.0-next.45 → 1.0.0-next.452

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