@sveltejs/kit 1.0.0-next.43 → 1.0.0-next.430

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/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 +488 -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 +97 -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 +91 -0
  23. package/src/core/sync/write_tsconfig.js +195 -0
  24. package/src/core/sync/write_types.js +775 -0
  25. package/src/core/utils.js +70 -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 +102 -0
  35. package/src/runtime/client/ambient.d.ts +17 -0
  36. package/src/runtime/client/client.js +1289 -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 +21 -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 +135 -0
  60. package/src/runtime/server/page/render.js +362 -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 +108 -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 +160 -0
  74. package/src/vite/dev/index.js +551 -0
  75. package/src/vite/index.js +574 -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 +345 -0
  79. package/svelte-kit.js +1 -1
  80. package/types/ambient.d.ts +357 -0
  81. package/types/index.d.ts +343 -0
  82. package/types/internal.d.ts +308 -0
  83. package/types/private.d.ts +209 -0
  84. package/CHANGELOG.md +0 -431
  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/.DS_Store +0 -0
  95. package/dist/chunks/index.js +0 -3521
  96. package/dist/chunks/index2.js +0 -587
  97. package/dist/chunks/index3.js +0 -246
  98. package/dist/chunks/index4.js +0 -538
  99. package/dist/chunks/index5.js +0 -761
  100. package/dist/chunks/index6.js +0 -322
  101. package/dist/chunks/standard.js +0 -99
  102. package/dist/chunks/utils.js +0 -83
  103. package/dist/cli.js +0 -546
  104. package/dist/ssr.js +0 -2581
@@ -0,0 +1,574 @@
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
+ /**
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(svelte_config.kit.env, vite_config_env.mode);
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
+ '/@id/__x00__$env/dynamic/private', //dev
215
+ '\0$env/dynamic/private', // prod
216
+ '/@id/__x00__$env/static/private', // dev
217
+ '\0$env/static/private' // prod
218
+ ]);
219
+
220
+ if (is_build) {
221
+ manifest_data = (await sync.all(svelte_config, config_env.mode)).manifest_data;
222
+
223
+ const new_config = vite_client_build_config();
224
+
225
+ const warning = warn_overridden_config(config, new_config);
226
+ if (warning) console.error(warning + '\n');
227
+
228
+ return new_config;
229
+ }
230
+
231
+ // dev and preview config can be shared
232
+ /** @type {import('vite').UserConfig} */
233
+ const result = {
234
+ appType: 'custom',
235
+ base: './',
236
+ build: {
237
+ rollupOptions: {
238
+ // Vite dependency crawler needs an explicit JS entry point
239
+ // eventhough server otherwise works without it
240
+ input: `${runtime_directory}/client/start.js`
241
+ }
242
+ },
243
+ define: {
244
+ __SVELTEKIT_DEV__: 'true',
245
+ __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0'
246
+ },
247
+ publicDir: svelte_config.kit.files.assets,
248
+ resolve: {
249
+ alias: get_aliases(svelte_config.kit)
250
+ },
251
+ root: cwd,
252
+ server: {
253
+ fs: {
254
+ allow: [
255
+ ...new Set([
256
+ svelte_config.kit.files.lib,
257
+ svelte_config.kit.files.routes,
258
+ svelte_config.kit.outDir,
259
+ path.resolve(cwd, 'src'),
260
+ path.resolve(cwd, 'node_modules'),
261
+ path.resolve(vite.searchForWorkspaceRoot(cwd), 'node_modules')
262
+ ])
263
+ ]
264
+ },
265
+ watch: {
266
+ ignored: [
267
+ // Ignore all siblings of config.kit.outDir/generated
268
+ `${posixify(svelte_config.kit.outDir)}/!(generated)`
269
+ ]
270
+ }
271
+ },
272
+ ssr: {
273
+ // Without this, Vite will treat `@sveltejs/kit` as noExternal if it's
274
+ // a linked dependency, and that causes modules to be imported twice
275
+ // under different IDs, which breaks a bunch of stuff
276
+ // https://github.com/vitejs/vite/pull/9296
277
+ external: ['@sveltejs/kit']
278
+ },
279
+ optimizeDeps: {
280
+ exclude: ['@sveltejs/kit']
281
+ }
282
+ };
283
+
284
+ deferred_warning = warn_overridden_config(config, result);
285
+ return result;
286
+ },
287
+
288
+ async resolveId(id) {
289
+ // treat $env/static/[public|private] as virtual
290
+ if (id.startsWith('$env/')) return `\0${id}`;
291
+ },
292
+
293
+ async load(id) {
294
+ switch (id) {
295
+ case '\0$env/static/private':
296
+ return create_static_module('$env/static/private', env.private);
297
+ case '\0$env/static/public':
298
+ return create_static_module('$env/static/public', env.public);
299
+ case '\0$env/dynamic/private':
300
+ return create_dynamic_module('private');
301
+ case '\0$env/dynamic/public':
302
+ return create_dynamic_module('public');
303
+ }
304
+ },
305
+
306
+ /**
307
+ * Stores the final config.
308
+ */
309
+ configResolved(config) {
310
+ vite_config = config;
311
+ },
312
+
313
+ /**
314
+ * Clears the output directories.
315
+ */
316
+ buildStart() {
317
+ if (vite_config.build.ssr) {
318
+ return;
319
+ }
320
+
321
+ // Reset for new build. Goes here because `build --watch` calls buildStart but not config
322
+ completed_build = false;
323
+
324
+ if (is_build) {
325
+ rimraf(paths.build_dir);
326
+ mkdirp(paths.build_dir);
327
+
328
+ rimraf(paths.output_dir);
329
+ mkdirp(paths.output_dir);
330
+ }
331
+ },
332
+
333
+ /**
334
+ * Vite builds a single bundle. We need three bundles: client, server, and service worker.
335
+ * The user's package.json scripts will invoke the Vite CLI to execute the client build. We
336
+ * then use this hook to kick off builds for the server and service worker.
337
+ */
338
+ async writeBundle(_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(`Client build completed. Wrote ${chunks.length} chunks and ${assets.length} assets`);
371
+
372
+ log.info('Building server');
373
+ const options = {
374
+ cwd,
375
+ config: svelte_config,
376
+ vite_config,
377
+ vite_config_env,
378
+ build_dir: paths.build_dir, // TODO just pass `paths`
379
+ manifest_data,
380
+ output_dir: paths.output_dir,
381
+ service_worker_entry_file: resolve_entry(svelte_config.kit.files.serviceWorker)
382
+ };
383
+ const client = client_build_info(assets, chunks);
384
+ const server = await build_server(options, client);
385
+
386
+ /** @type {import('types').BuildData} */
387
+ build_data = {
388
+ app_dir: svelte_config.kit.appDir,
389
+ manifest_data,
390
+ service_worker: options.service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
391
+ client,
392
+ server
393
+ };
394
+
395
+ const manifest_path = `${paths.output_dir}/server/manifest.js`;
396
+ fs.writeFileSync(
397
+ manifest_path,
398
+ `export const manifest = ${generate_manifest({
399
+ build_data,
400
+ relative_path: '.',
401
+ routes: manifest_data.routes
402
+ })};\n`
403
+ );
404
+
405
+ log.info('Prerendering');
406
+ await new Promise((fulfil, reject) => {
407
+ const results_path = `${svelte_config.kit.outDir}/generated/prerendered.json`;
408
+
409
+ // do prerendering in a subprocess so any dangling stuff gets killed upon completion
410
+ const script = fileURLToPath(new URL('../core/prerender/prerender.js', import.meta.url));
411
+
412
+ const child = fork(
413
+ script,
414
+ [vite_config.build.outDir, results_path, manifest_path, '' + verbose],
415
+ {
416
+ stdio: 'inherit'
417
+ }
418
+ );
419
+
420
+ child.on('exit', (code) => {
421
+ if (code) {
422
+ reject(new Error(`Prerendering failed with code ${code}`));
423
+ } else {
424
+ prerendered = JSON.parse(fs.readFileSync(results_path, 'utf8'), (key, value) => {
425
+ if (key === 'pages' || key === 'assets' || key === 'redirects') {
426
+ return new Map(value);
427
+ }
428
+ return value;
429
+ });
430
+ fulfil(undefined);
431
+ }
432
+ });
433
+ });
434
+
435
+ if (options.service_worker_entry_file) {
436
+ if (svelte_config.kit.paths.assets) {
437
+ throw new Error('Cannot use service worker alongside config.kit.paths.assets');
438
+ }
439
+
440
+ log.info('Building service worker');
441
+
442
+ await build_service_worker(options, prerendered, client.vite_manifest);
443
+ }
444
+
445
+ console.log(
446
+ `\nRun ${colors.bold().cyan('npm run preview')} to preview your production build locally.`
447
+ );
448
+
449
+ completed_build = true;
450
+ },
451
+
452
+ /**
453
+ * Runs the adapter.
454
+ */
455
+ async closeBundle() {
456
+ // vite calls closeBundle when dev-server restarts, ignore that,
457
+ // and only adapt when build successfully completes.
458
+ const is_restart = !completed_build;
459
+ if (vite_config.build.ssr || is_restart) {
460
+ return;
461
+ }
462
+
463
+ if (svelte_config.kit.adapter) {
464
+ const { adapt } = await import('../core/adapt/index.js');
465
+ await adapt(svelte_config, build_data, prerendered, { log });
466
+ } else {
467
+ console.log(colors.bold().yellow('\nNo adapter specified'));
468
+
469
+ const link = colors.bold().cyan('https://kit.svelte.dev/docs/adapters');
470
+ console.log(
471
+ `See ${link} to learn how to configure your app to run on the platform of your choosing`
472
+ );
473
+ }
474
+
475
+ // avoid making the manifest available to users
476
+ fs.unlinkSync(`${paths.output_dir}/client/${vite_config.build.manifest}`);
477
+ fs.unlinkSync(`${paths.output_dir}/server/${vite_config.build.manifest}`);
478
+ },
479
+
480
+ /**
481
+ * Adds the SvelteKit middleware to do SSR in dev mode.
482
+ * @see https://vitejs.dev/guide/api-plugin.html#configureserver
483
+ */
484
+ async configureServer(vite) {
485
+ // This method is called by Vite after clearing the screen.
486
+ // This patch ensures we can log any important messages afterwards for the user to see.
487
+ const print_urls = vite.printUrls;
488
+ vite.printUrls = function () {
489
+ print_urls.apply(this);
490
+ if (deferred_warning) console.error('\n' + deferred_warning);
491
+ };
492
+
493
+ return await dev(vite, vite_config, svelte_config, illegal_imports);
494
+ },
495
+
496
+ /**
497
+ * Adds the SvelteKit middleware to do SSR in preview mode.
498
+ * @see https://vitejs.dev/guide/api-plugin.html#configurepreviewserver
499
+ */
500
+ configurePreviewServer(vite) {
501
+ return preview(vite, vite_config, svelte_config);
502
+ }
503
+ };
504
+ }
505
+
506
+ function check_vite_version() {
507
+ // TODO parse from kit peer deps and maybe do a full semver compare if we ever require feature releases a min
508
+ const min_required_vite_major = 3;
509
+ const vite_version = vite.version ?? '2.x'; // vite started exporting it's version in 3.0
510
+ const current_vite_major = parseInt(vite_version.split('.')[0], 10);
511
+
512
+ if (current_vite_major < min_required_vite_major) {
513
+ throw new Error(
514
+ `Vite version ${current_vite_major} is no longer supported. Please upgrade to version ${min_required_vite_major}`
515
+ );
516
+ }
517
+ }
518
+
519
+ /** @param {import('rollup').OutputBundle} bundle */
520
+ function collect_output(bundle) {
521
+ /** @type {import('rollup').OutputChunk[]} */
522
+ const chunks = [];
523
+ /** @type {import('rollup').OutputAsset[]} */
524
+ const assets = [];
525
+ for (const value of Object.values(bundle)) {
526
+ // collect asset and output chunks
527
+ if (value.type === 'asset') {
528
+ assets.push(value);
529
+ } else {
530
+ chunks.push(value);
531
+ }
532
+ }
533
+ return { assets, chunks };
534
+ }
535
+
536
+ /**
537
+ * @param {Record<string, any>} config
538
+ * @param {Record<string, any>} resolved_config
539
+ */
540
+ function warn_overridden_config(config, resolved_config) {
541
+ const overridden = find_overridden_config(config, resolved_config, enforced_config, '', []);
542
+
543
+ if (overridden.length > 0) {
544
+ return (
545
+ colors.bold().red('The following Vite config options will be overridden by SvelteKit:') +
546
+ overridden.map((key) => `\n - ${key}`).join('')
547
+ );
548
+ }
549
+ }
550
+
551
+ /**
552
+ * @param {Record<string, any>} config
553
+ * @param {Record<string, any>} resolved_config
554
+ * @param {import('./types').EnforcedConfig} enforced_config
555
+ * @param {string} path
556
+ * @param {string[]} out used locally to compute the return value
557
+ */
558
+ function find_overridden_config(config, resolved_config, enforced_config, path, out) {
559
+ for (const key in enforced_config) {
560
+ if (typeof config === 'object' && config !== null && key in config) {
561
+ const enforced = enforced_config[key];
562
+
563
+ if (enforced === true) {
564
+ if (config[key] !== resolved_config[key]) {
565
+ out.push(path + key);
566
+ }
567
+ } else {
568
+ find_overridden_config(config[key], resolved_config[key], enforced, path + key + '.', out);
569
+ }
570
+ }
571
+ }
572
+
573
+ return out;
574
+ }