@sveltejs/kit 1.0.0-next.28 → 1.0.0-next.280

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 (79) hide show
  1. package/README.md +12 -9
  2. package/assets/app/env.js +20 -0
  3. package/assets/app/navigation.js +79 -0
  4. package/assets/app/paths.js +1 -0
  5. package/assets/app/stores.js +97 -0
  6. package/assets/chunks/utils.js +13 -0
  7. package/assets/client/singletons.js +21 -0
  8. package/assets/client/start.js +1560 -0
  9. package/assets/components/error.svelte +18 -2
  10. package/assets/env.js +8 -0
  11. package/assets/paths.js +13 -0
  12. package/assets/server/index.js +2759 -0
  13. package/dist/chunks/amp_hook.js +56 -0
  14. package/dist/chunks/build.js +658 -0
  15. package/dist/chunks/cert.js +28154 -0
  16. package/dist/chunks/index.js +473 -0
  17. package/dist/chunks/index2.js +836 -0
  18. package/dist/chunks/index3.js +643 -0
  19. package/dist/chunks/index4.js +120 -0
  20. package/dist/chunks/index5.js +881 -0
  21. package/dist/chunks/index6.js +170 -0
  22. package/dist/chunks/index7.js +15584 -0
  23. package/dist/chunks/index8.js +4207 -0
  24. package/dist/chunks/misc.js +3 -0
  25. package/dist/chunks/multipart-parser.js +449 -0
  26. package/dist/cli.js +1132 -86
  27. package/dist/hooks.js +28 -0
  28. package/dist/install-fetch.js +6518 -0
  29. package/dist/node.js +95 -0
  30. package/package.json +97 -54
  31. package/svelte-kit.js +2 -0
  32. package/types/ambient.d.ts +208 -0
  33. package/types/index.d.ts +391 -0
  34. package/types/internal.d.ts +372 -0
  35. package/CHANGELOG.md +0 -326
  36. package/assets/runtime/app/navigation.js +0 -23
  37. package/assets/runtime/app/navigation.js.map +0 -1
  38. package/assets/runtime/app/paths.js +0 -2
  39. package/assets/runtime/app/paths.js.map +0 -1
  40. package/assets/runtime/app/stores.js +0 -78
  41. package/assets/runtime/app/stores.js.map +0 -1
  42. package/assets/runtime/internal/singletons.js +0 -15
  43. package/assets/runtime/internal/singletons.js.map +0 -1
  44. package/assets/runtime/internal/start.js +0 -591
  45. package/assets/runtime/internal/start.js.map +0 -1
  46. package/assets/runtime/utils-85ebcc60.js +0 -18
  47. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  48. package/dist/api.js +0 -44
  49. package/dist/api.js.map +0 -1
  50. package/dist/build.js +0 -246
  51. package/dist/build.js.map +0 -1
  52. package/dist/cli.js.map +0 -1
  53. package/dist/colors.js +0 -37
  54. package/dist/colors.js.map +0 -1
  55. package/dist/create_app.js +0 -580
  56. package/dist/create_app.js.map +0 -1
  57. package/dist/index.js +0 -368
  58. package/dist/index.js.map +0 -1
  59. package/dist/index2.js +0 -12035
  60. package/dist/index2.js.map +0 -1
  61. package/dist/index3.js +0 -549
  62. package/dist/index3.js.map +0 -1
  63. package/dist/index4.js +0 -74
  64. package/dist/index4.js.map +0 -1
  65. package/dist/index5.js +0 -464
  66. package/dist/index5.js.map +0 -1
  67. package/dist/index6.js +0 -735
  68. package/dist/index6.js.map +0 -1
  69. package/dist/logging.js +0 -43
  70. package/dist/logging.js.map +0 -1
  71. package/dist/package.js +0 -432
  72. package/dist/package.js.map +0 -1
  73. package/dist/renderer.js +0 -2425
  74. package/dist/renderer.js.map +0 -1
  75. package/dist/standard.js +0 -101
  76. package/dist/standard.js.map +0 -1
  77. package/dist/utils.js +0 -58
  78. package/dist/utils.js.map +0 -1
  79. package/svelte-kit +0 -3
@@ -0,0 +1,643 @@
1
+ import fs__default from 'fs';
2
+ import path__default from 'path';
3
+ import { p as print_config_conflicts, b as SVELTE_KIT, d as copy_assets, f as posixify, e as get_aliases, a as resolve_entry, l as load_template, r as runtime, m as mkdirp, h as rimraf } from '../cli.js';
4
+ import { d as deep_merge, a as create_app, c as create_manifest_data } from './index2.js';
5
+ import { g as generate_manifest } from './index4.js';
6
+ import vite from 'vite';
7
+ import { s } from './misc.js';
8
+ import { svelte } from '@sveltejs/vite-plugin-svelte';
9
+ import 'sade';
10
+ import 'child_process';
11
+ import 'net';
12
+ import 'url';
13
+ import 'os';
14
+
15
+ /**
16
+ * @param {{
17
+ * cwd: string;
18
+ * assets_base: string;
19
+ * config: import('types').ValidatedConfig
20
+ * manifest_data: import('types').ManifestData
21
+ * output_dir: string;
22
+ * service_worker_entry_file: string | null;
23
+ * }} options
24
+ * @param {import('vite').Manifest} client_manifest
25
+ */
26
+ async function build_service_worker(
27
+ { cwd, assets_base, config, manifest_data, output_dir, service_worker_entry_file },
28
+ client_manifest
29
+ ) {
30
+ // TODO add any assets referenced in template .html file, e.g. favicon?
31
+ const app_files = new Set();
32
+ for (const key in client_manifest) {
33
+ const { file, css } = client_manifest[key];
34
+ app_files.add(file);
35
+ if (css) {
36
+ css.forEach((file) => {
37
+ app_files.add(file);
38
+ });
39
+ }
40
+ }
41
+
42
+ const service_worker = `${cwd}/${SVELTE_KIT}/generated/service-worker.js`;
43
+
44
+ fs__default.writeFileSync(
45
+ service_worker,
46
+ `
47
+ export const timestamp = ${Date.now()};
48
+
49
+ export const build = [
50
+ ${Array.from(app_files)
51
+ .map((file) => `${s(`${config.kit.paths.base}/${config.kit.appDir}/${file}`)}`)
52
+ .join(',\n\t\t\t\t')}
53
+ ];
54
+
55
+ export const files = [
56
+ ${manifest_data.assets
57
+ .map((asset) => `${s(`${config.kit.paths.base}/${asset.file}`)}`)
58
+ .join(',\n\t\t\t\t')}
59
+ ];
60
+ `
61
+ .replace(/^\t{3}/gm, '')
62
+ .trim()
63
+ );
64
+
65
+ /** @type {[any, string[]]} */
66
+ const [merged_config, conflicts] = deep_merge(await config.kit.vite(), {
67
+ configFile: false,
68
+ root: cwd,
69
+ base: assets_base,
70
+ build: {
71
+ lib: {
72
+ entry: service_worker_entry_file,
73
+ name: 'app',
74
+ formats: ['es']
75
+ },
76
+ rollupOptions: {
77
+ output: {
78
+ entryFileNames: 'service-worker.js'
79
+ }
80
+ },
81
+ outDir: `${output_dir}/client`,
82
+ emptyOutDir: false
83
+ },
84
+ resolve: {
85
+ alias: {
86
+ '$service-worker': service_worker,
87
+ $lib: config.kit.files.lib
88
+ }
89
+ }
90
+ });
91
+
92
+ print_config_conflicts(conflicts, 'kit.vite.', 'build_service_worker');
93
+
94
+ await vite.build(merged_config);
95
+ }
96
+
97
+ /** @param {import('vite').UserConfig} config */
98
+ async function create_build(config) {
99
+ const { output } = /** @type {import('rollup').RollupOutput} */ (await vite.build(config));
100
+
101
+ const chunks = /** @type {import('rollup').OutputChunk[]} */ (
102
+ output.filter((output) => output.type === 'chunk')
103
+ );
104
+
105
+ const assets = /** @type {import('rollup').OutputAsset[]} */ (
106
+ output.filter((output) => output.type === 'asset')
107
+ );
108
+
109
+ return { chunks, assets };
110
+ }
111
+
112
+ /**
113
+ * @param {string} file
114
+ * @param {import('vite').Manifest} manifest
115
+ * @param {Set<string>} css
116
+ * @param {Set<string>} js
117
+ * @returns
118
+ */
119
+ function find_deps(file, manifest, js, css) {
120
+ const chunk = manifest[file];
121
+
122
+ if (js.has(chunk.file)) return;
123
+ js.add(chunk.file);
124
+
125
+ if (chunk.css) {
126
+ chunk.css.forEach((file) => css.add(file));
127
+ }
128
+
129
+ if (chunk.imports) {
130
+ chunk.imports.forEach((file) => find_deps(file, manifest, js, css));
131
+ }
132
+ }
133
+
134
+ /**
135
+ * @param {{
136
+ * cwd: string;
137
+ * assets_base: string;
138
+ * config: import('types').ValidatedConfig
139
+ * manifest_data: import('types').ManifestData
140
+ * output_dir: string;
141
+ * client_entry_file: string;
142
+ * service_worker_entry_file: string | null;
143
+ * service_worker_register: boolean;
144
+ * }} options
145
+ */
146
+ async function build_client({
147
+ cwd,
148
+ assets_base,
149
+ config,
150
+ manifest_data,
151
+ output_dir,
152
+ client_entry_file
153
+ }) {
154
+ process.env.VITE_SVELTEKIT_APP_VERSION = config.kit.version.name;
155
+ process.env.VITE_SVELTEKIT_APP_VERSION_FILE = `${config.kit.appDir}/version.json`;
156
+ process.env.VITE_SVELTEKIT_APP_VERSION_POLL_INTERVAL = `${config.kit.version.pollInterval}`;
157
+
158
+ create_app({
159
+ manifest_data,
160
+ output: `${SVELTE_KIT}/generated`,
161
+ cwd
162
+ });
163
+
164
+ copy_assets(`${SVELTE_KIT}/runtime`);
165
+
166
+ process.env.VITE_SVELTEKIT_AMP = config.kit.amp ? 'true' : '';
167
+
168
+ const client_out_dir = `${output_dir}/client/${config.kit.appDir}`;
169
+
170
+ /** @type {Record<string, string>} */
171
+ const input = {
172
+ start: path__default.resolve(cwd, client_entry_file)
173
+ };
174
+
175
+ // This step is optional — Vite/Rollup will create the necessary chunks
176
+ // for everything regardless — but it means that entry chunks reflect
177
+ // their location in the source code, which is helpful for debugging
178
+ manifest_data.components.forEach((file) => {
179
+ const resolved = path__default.resolve(cwd, file);
180
+ const relative = path__default.relative(config.kit.files.routes, resolved);
181
+
182
+ const name = relative.startsWith('..')
183
+ ? path__default.basename(file)
184
+ : posixify(path__default.join('pages', relative));
185
+ input[name] = resolved;
186
+ });
187
+
188
+ /** @type {[any, string[]]} */
189
+ const [merged_config, conflicts] = deep_merge(await config.kit.vite(), {
190
+ configFile: false,
191
+ root: cwd,
192
+ base: assets_base,
193
+ build: {
194
+ cssCodeSplit: true,
195
+ manifest: true,
196
+ outDir: client_out_dir,
197
+ polyfillDynamicImport: false,
198
+ rollupOptions: {
199
+ input,
200
+ output: {
201
+ entryFileNames: '[name]-[hash].js',
202
+ chunkFileNames: 'chunks/[name]-[hash].js',
203
+ assetFileNames: 'assets/[name]-[hash][extname]'
204
+ },
205
+ preserveEntrySignatures: 'strict'
206
+ }
207
+ },
208
+ resolve: {
209
+ alias: get_aliases(config)
210
+ },
211
+ plugins: [
212
+ svelte({
213
+ extensions: config.extensions,
214
+ // In AMP mode, we know that there are no conditional component imports. In that case, we
215
+ // don't need to include CSS for components that are imported but unused, so we can just
216
+ // include rendered CSS.
217
+ // This would also apply if hydrate and router are both false, but we don't know if one
218
+ // has been enabled at the page level, so we don't do anything there.
219
+ emitCss: !config.kit.amp,
220
+ compilerOptions: {
221
+ hydratable: !!config.kit.browser.hydrate
222
+ }
223
+ })
224
+ ]
225
+ });
226
+
227
+ print_config_conflicts(conflicts, 'kit.vite.', 'build_client');
228
+
229
+ const { chunks, assets } = await create_build(merged_config);
230
+
231
+ /** @type {import('vite').Manifest} */
232
+ const vite_manifest = JSON.parse(fs__default.readFileSync(`${client_out_dir}/manifest.json`, 'utf-8'));
233
+
234
+ const entry = posixify(client_entry_file);
235
+ const entry_js = new Set();
236
+ const entry_css = new Set();
237
+ find_deps(entry, vite_manifest, entry_js, entry_css);
238
+
239
+ fs__default.writeFileSync(
240
+ `${client_out_dir}/version.json`,
241
+ JSON.stringify({ version: process.env.VITE_SVELTEKIT_APP_VERSION })
242
+ );
243
+
244
+ return {
245
+ assets,
246
+ chunks,
247
+ entry: {
248
+ file: vite_manifest[entry].file,
249
+ js: Array.from(entry_js),
250
+ css: Array.from(entry_css)
251
+ },
252
+ vite_manifest
253
+ };
254
+ }
255
+
256
+ /**
257
+ * @param {{
258
+ * hooks: string;
259
+ * config: import('types').ValidatedConfig;
260
+ * has_service_worker: boolean;
261
+ * template: string;
262
+ * }} opts
263
+ * @returns
264
+ */
265
+ const server_template = ({ config, hooks, has_service_worker, template }) => `
266
+ import root from '__GENERATED__/root.svelte';
267
+ import { respond } from '${runtime}/server/index.js';
268
+ import { set_paths, assets, base } from '${runtime}/paths.js';
269
+ import { set_prerendering } from '${runtime}/env.js';
270
+ import * as user_hooks from ${s(hooks)};
271
+
272
+ const template = ({ head, body, assets, nonce }) => ${s(template)
273
+ .replace('%svelte.head%', '" + head + "')
274
+ .replace('%svelte.body%', '" + body + "')
275
+ .replace(/%svelte\.assets%/g, '" + assets + "')
276
+ .replace(/%svelte\.nonce%/g, '" + nonce + "')};
277
+
278
+ let read = null;
279
+
280
+ set_paths(${s(config.kit.paths)});
281
+
282
+ // this looks redundant, but the indirection allows us to access
283
+ // named imports without triggering Rollup's missing import detection
284
+ const get_hooks = hooks => ({
285
+ getSession: hooks.getSession || (() => ({})),
286
+ handle: hooks.handle || (({ event, resolve }) => resolve(event)),
287
+ handleError: hooks.handleError || (({ error }) => console.error(error.stack)),
288
+ externalFetch: hooks.externalFetch || fetch
289
+ });
290
+
291
+ let default_protocol = 'https';
292
+
293
+ // allow paths to be globally overridden
294
+ // in svelte-kit preview and in prerendering
295
+ export function override(settings) {
296
+ default_protocol = settings.protocol || default_protocol;
297
+ set_paths(settings.paths);
298
+ set_prerendering(settings.prerendering);
299
+ read = settings.read;
300
+ }
301
+
302
+ export class Server {
303
+ constructor(manifest) {
304
+ const hooks = get_hooks(user_hooks);
305
+
306
+ this.options = {
307
+ amp: ${config.kit.amp},
308
+ csp: ${s(config.kit.csp)},
309
+ dev: false,
310
+ floc: ${config.kit.floc},
311
+ get_stack: error => String(error), // for security
312
+ handle_error: (error, event) => {
313
+ hooks.handleError({
314
+ error,
315
+ event,
316
+
317
+ // TODO remove for 1.0
318
+ // @ts-expect-error
319
+ get request() {
320
+ throw new Error('request in handleError has been replaced with event. See https://github.com/sveltejs/kit/pull/3384 for details');
321
+ }
322
+ });
323
+ error.stack = this.options.get_stack(error);
324
+ },
325
+ hooks,
326
+ hydrate: ${s(config.kit.browser.hydrate)},
327
+ manifest,
328
+ method_override: ${s(config.kit.methodOverride)},
329
+ paths: { base, assets },
330
+ prefix: assets + '/${config.kit.appDir}/',
331
+ prerender: ${config.kit.prerender.enabled},
332
+ read,
333
+ root,
334
+ service_worker: ${has_service_worker ? "base + '/service-worker.js'" : 'null'},
335
+ router: ${s(config.kit.browser.router)},
336
+ template,
337
+ template_contains_nonce: ${template.includes('%svelte.nonce%')},
338
+ trailing_slash: ${s(config.kit.trailingSlash)}
339
+ };
340
+ }
341
+
342
+ respond(request, options = {}) {
343
+ if (!(request instanceof Request)) {
344
+ throw new Error('The first argument to app.render must be a Request object. See https://github.com/sveltejs/kit/pull/3384 for details');
345
+ }
346
+
347
+ return respond(request, this.options, options);
348
+ }
349
+ }
350
+ `;
351
+
352
+ /**
353
+ * @param {{
354
+ * cwd: string;
355
+ * assets_base: string;
356
+ * config: import('types').ValidatedConfig
357
+ * manifest_data: import('types').ManifestData
358
+ * build_dir: string;
359
+ * output_dir: string;
360
+ * service_worker_entry_file: string | null;
361
+ * service_worker_register: boolean;
362
+ * }} options
363
+ * @param {{ vite_manifest: import('vite').Manifest, assets: import('rollup').OutputAsset[] }} client
364
+ */
365
+ async function build_server(
366
+ {
367
+ cwd,
368
+ assets_base,
369
+ config,
370
+ manifest_data,
371
+ build_dir,
372
+ output_dir,
373
+ service_worker_entry_file,
374
+ service_worker_register
375
+ },
376
+ client
377
+ ) {
378
+ let hooks_file = resolve_entry(config.kit.files.hooks);
379
+ if (!hooks_file || !fs__default.existsSync(hooks_file)) {
380
+ hooks_file = path__default.resolve(cwd, `${SVELTE_KIT}/build/hooks.js`);
381
+ fs__default.writeFileSync(hooks_file, '');
382
+ }
383
+
384
+ /** @type {Record<string, string>} */
385
+ const input = {
386
+ index: `${build_dir}/index.js`
387
+ };
388
+
389
+ // add entry points for every endpoint...
390
+ manifest_data.routes.forEach((route) => {
391
+ const file = route.type === 'endpoint' ? route.file : route.shadow;
392
+
393
+ if (file) {
394
+ const resolved = path__default.resolve(cwd, file);
395
+ const relative = path__default.relative(config.kit.files.routes, resolved);
396
+ const name = posixify(path__default.join('entries/endpoints', relative.replace(/\.js$/, '')));
397
+ input[name] = resolved;
398
+ }
399
+ });
400
+
401
+ // ...and every component used by pages
402
+ manifest_data.components.forEach((file) => {
403
+ const resolved = path__default.resolve(cwd, file);
404
+ const relative = path__default.relative(config.kit.files.routes, resolved);
405
+
406
+ const name = relative.startsWith('..')
407
+ ? posixify(path__default.join('entries/pages', path__default.basename(file)))
408
+ : posixify(path__default.join('entries/pages', relative));
409
+ input[name] = resolved;
410
+ });
411
+
412
+ /** @type {(file: string) => string} */
413
+ const app_relative = (file) => {
414
+ const relative_file = path__default.relative(build_dir, path__default.resolve(cwd, file));
415
+ return relative_file[0] === '.' ? relative_file : `./${relative_file}`;
416
+ };
417
+
418
+ fs__default.writeFileSync(
419
+ input.index,
420
+ server_template({
421
+ config,
422
+ hooks: app_relative(hooks_file),
423
+ has_service_worker: service_worker_register && !!service_worker_entry_file,
424
+ template: load_template(cwd, config)
425
+ })
426
+ );
427
+
428
+ /** @type {import('vite').UserConfig} */
429
+ const vite_config = await config.kit.vite();
430
+
431
+ const default_config = {
432
+ build: {
433
+ target: 'es2020'
434
+ }
435
+ };
436
+
437
+ // don't warn on overriding defaults
438
+ const [modified_vite_config] = deep_merge(default_config, vite_config);
439
+
440
+ /** @type {[any, string[]]} */
441
+ const [merged_config, conflicts] = deep_merge(modified_vite_config, {
442
+ configFile: false,
443
+ root: cwd,
444
+ base: assets_base,
445
+ build: {
446
+ ssr: true,
447
+ outDir: `${output_dir}/server`,
448
+ manifest: true,
449
+ polyfillDynamicImport: false,
450
+ rollupOptions: {
451
+ input,
452
+ output: {
453
+ format: 'esm',
454
+ entryFileNames: '[name].js',
455
+ chunkFileNames: 'chunks/[name]-[hash].js',
456
+ assetFileNames: 'assets/[name]-[hash][extname]'
457
+ },
458
+ preserveEntrySignatures: 'strict'
459
+ }
460
+ },
461
+ plugins: [
462
+ svelte({
463
+ extensions: config.extensions,
464
+ compilerOptions: {
465
+ hydratable: !!config.kit.browser.hydrate
466
+ }
467
+ })
468
+ ],
469
+ resolve: {
470
+ alias: get_aliases(config)
471
+ }
472
+ });
473
+
474
+ print_config_conflicts(conflicts, 'kit.vite.', 'build_server');
475
+
476
+ const { chunks } = await create_build(merged_config);
477
+
478
+ /** @type {import('vite').Manifest} */
479
+ const vite_manifest = JSON.parse(fs__default.readFileSync(`${output_dir}/server/manifest.json`, 'utf-8'));
480
+
481
+ mkdirp(`${output_dir}/server/nodes`);
482
+ mkdirp(`${output_dir}/server/stylesheets`);
483
+
484
+ const stylesheet_lookup = new Map();
485
+
486
+ client.assets.forEach((asset) => {
487
+ if (asset.fileName.endsWith('.css')) {
488
+ if (config.kit.amp || asset.source.length < config.kit.inlineStyleThreshold) {
489
+ const index = stylesheet_lookup.size;
490
+ const file = `${output_dir}/server/stylesheets/${index}.js`;
491
+
492
+ fs__default.writeFileSync(file, `// ${asset.fileName}\nexport default ${s(asset.source)};`);
493
+ stylesheet_lookup.set(asset.fileName, index);
494
+ }
495
+ }
496
+ });
497
+
498
+ manifest_data.components.forEach((component, i) => {
499
+ const file = `${output_dir}/server/nodes/${i}.js`;
500
+
501
+ const js = new Set();
502
+ const css = new Set();
503
+ find_deps(component, client.vite_manifest, js, css);
504
+
505
+ const imports = [`import * as module from '../${vite_manifest[component].file}';`];
506
+
507
+ const exports = [
508
+ 'export { module };',
509
+ `export const entry = '${client.vite_manifest[component].file}';`,
510
+ `export const js = ${s(Array.from(js))};`,
511
+ `export const css = ${s(Array.from(css))};`
512
+ ];
513
+
514
+ /** @type {string[]} */
515
+ const styles = [];
516
+
517
+ css.forEach((file) => {
518
+ if (stylesheet_lookup.has(file)) {
519
+ const index = stylesheet_lookup.get(file);
520
+ const name = `stylesheet_${index}`;
521
+ imports.push(`import ${name} from '../stylesheets/${index}.js';`);
522
+ styles.push(`\t${s(file)}: ${name}`);
523
+ }
524
+ });
525
+
526
+ if (styles.length > 0) {
527
+ exports.push(`export const styles = {\n${styles.join(',\n')}\n};`);
528
+ }
529
+
530
+ fs__default.writeFileSync(file, `${imports.join('\n')}\n\n${exports.join('\n')}\n`);
531
+ });
532
+
533
+ return {
534
+ chunks,
535
+ vite_manifest,
536
+ methods: get_methods(cwd, chunks, manifest_data)
537
+ };
538
+ }
539
+
540
+ /** @type {Record<string, string>} */
541
+ const method_names = {
542
+ get: 'get',
543
+ head: 'head',
544
+ post: 'post',
545
+ put: 'put',
546
+ del: 'delete',
547
+ patch: 'patch'
548
+ };
549
+
550
+ /**
551
+ *
552
+ * @param {string} cwd
553
+ * @param {import('rollup').OutputChunk[]} output
554
+ * @param {import('types').ManifestData} manifest_data
555
+ */
556
+ function get_methods(cwd, output, manifest_data) {
557
+ /** @type {Record<string, string[]>} */
558
+ const lookup = {};
559
+ output.forEach((chunk) => {
560
+ if (!chunk.facadeModuleId) return;
561
+ const id = chunk.facadeModuleId.slice(cwd.length + 1);
562
+ lookup[id] = chunk.exports;
563
+ });
564
+
565
+ /** @type {Record<string, import('types').HttpMethod[]>} */
566
+ const methods = {};
567
+ manifest_data.routes.forEach((route) => {
568
+ const file = route.type === 'endpoint' ? route.file : route.shadow;
569
+
570
+ if (file && lookup[file]) {
571
+ methods[file] = lookup[file]
572
+ .map((x) => /** @type {import('types').HttpMethod} */ (method_names[x]))
573
+ .filter(Boolean);
574
+ }
575
+ });
576
+
577
+ return methods;
578
+ }
579
+
580
+ /**
581
+ * @param {import('types').ValidatedConfig} config
582
+ * @returns {Promise<import('types').BuildData>}
583
+ */
584
+ async function build(config) {
585
+ const cwd = process.cwd(); // TODO is this necessary?
586
+
587
+ const build_dir = path__default.resolve(`${SVELTE_KIT}/build`);
588
+ rimraf(build_dir);
589
+ mkdirp(build_dir);
590
+
591
+ const output_dir = path__default.resolve(`${SVELTE_KIT}/output`);
592
+ rimraf(output_dir);
593
+ mkdirp(output_dir);
594
+
595
+ const options = {
596
+ cwd,
597
+ config,
598
+ build_dir,
599
+ // TODO this is so that Vite's preloading works. Unfortunately, it fails
600
+ // during `svelte-kit preview`, because we use a local asset path. If Vite
601
+ // used relative paths, I _think_ this could get fixed. Issue here:
602
+ // https://github.com/vitejs/vite/issues/2009
603
+ assets_base: `${config.kit.paths.assets || config.kit.paths.base}/${config.kit.appDir}/`,
604
+ manifest_data: create_manifest_data({
605
+ config,
606
+ cwd
607
+ }),
608
+ output_dir,
609
+ client_entry_file: path__default.relative(cwd, `${runtime}/client/start.js`),
610
+ service_worker_entry_file: resolve_entry(config.kit.files.serviceWorker),
611
+ service_worker_register: config.kit.serviceWorker.register
612
+ };
613
+
614
+ const client = await build_client(options);
615
+ const server = await build_server(options, client);
616
+
617
+ if (options.service_worker_entry_file) {
618
+ if (config.kit.paths.assets) {
619
+ throw new Error('Cannot use service worker alongside config.kit.paths.assets');
620
+ }
621
+
622
+ await build_service_worker(options, client.vite_manifest);
623
+ }
624
+
625
+ const build_data = {
626
+ app_dir: config.kit.appDir,
627
+ manifest_data: options.manifest_data,
628
+ service_worker: options.service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
629
+ client,
630
+ server,
631
+ static: options.manifest_data.assets.map((asset) => posixify(asset.file)),
632
+ entries: options.manifest_data.routes
633
+ .map((route) => (route.type === 'page' ? route.path : ''))
634
+ .filter(Boolean)
635
+ };
636
+
637
+ const manifest = `export const manifest = ${generate_manifest(build_data, '.')};\n`;
638
+ fs__default.writeFileSync(`${output_dir}/server/manifest.js`, manifest);
639
+
640
+ return build_data;
641
+ }
642
+
643
+ export { build };