@sveltejs/kit 1.0.0-next.52 → 1.0.0-next.520

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