@sveltejs/kit 1.0.0-next.22 → 1.0.0-next.223

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 (82) hide show
  1. package/README.md +12 -9
  2. package/assets/components/error.svelte +19 -3
  3. package/assets/kit.js +1996 -0
  4. package/assets/runtime/app/env.js +20 -0
  5. package/assets/runtime/app/navigation.js +55 -13
  6. package/assets/runtime/app/paths.js +1 -2
  7. package/assets/runtime/app/stores.js +19 -15
  8. package/assets/runtime/chunks/utils.js +13 -0
  9. package/assets/runtime/env.js +8 -0
  10. package/assets/runtime/internal/singletons.js +12 -9
  11. package/assets/runtime/internal/start.js +1015 -354
  12. package/assets/runtime/paths.js +13 -0
  13. package/dist/chunks/cert.js +29255 -0
  14. package/dist/chunks/constants.js +8 -0
  15. package/dist/chunks/error.js +12 -0
  16. package/dist/chunks/index.js +476 -0
  17. package/dist/chunks/index2.js +817 -0
  18. package/dist/chunks/index3.js +640 -0
  19. package/dist/chunks/index4.js +109 -0
  20. package/dist/chunks/index5.js +635 -0
  21. package/dist/chunks/index6.js +827 -0
  22. package/dist/chunks/index7.js +15575 -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/chunks/url.js +62 -0
  27. package/dist/cli.js +996 -83
  28. package/dist/hooks.js +28 -0
  29. package/dist/install-fetch.js +6514 -0
  30. package/dist/node.js +51 -0
  31. package/dist/ssr.js +1926 -0
  32. package/package.json +96 -54
  33. package/svelte-kit.js +2 -0
  34. package/types/ambient-modules.d.ts +191 -0
  35. package/types/app.d.ts +45 -0
  36. package/types/config.d.ts +168 -0
  37. package/types/endpoint.d.ts +20 -0
  38. package/types/helper.d.ts +53 -0
  39. package/types/hooks.d.ts +55 -0
  40. package/types/index.d.ts +18 -0
  41. package/types/internal.d.ts +237 -0
  42. package/types/page.d.ts +73 -0
  43. package/CHANGELOG.md +0 -288
  44. package/assets/runtime/app/navigation.js.map +0 -1
  45. package/assets/runtime/app/paths.js.map +0 -1
  46. package/assets/runtime/app/stores.js.map +0 -1
  47. package/assets/runtime/internal/singletons.js.map +0 -1
  48. package/assets/runtime/internal/start.js.map +0 -1
  49. package/assets/runtime/utils-85ebcc60.js +0 -18
  50. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  51. package/dist/api.js +0 -44
  52. package/dist/api.js.map +0 -1
  53. package/dist/build.js +0 -246
  54. package/dist/build.js.map +0 -1
  55. package/dist/cli.js.map +0 -1
  56. package/dist/colors.js +0 -37
  57. package/dist/colors.js.map +0 -1
  58. package/dist/create_app.js +0 -578
  59. package/dist/create_app.js.map +0 -1
  60. package/dist/index.js +0 -12042
  61. package/dist/index.js.map +0 -1
  62. package/dist/index2.js +0 -544
  63. package/dist/index2.js.map +0 -1
  64. package/dist/index3.js +0 -71
  65. package/dist/index3.js.map +0 -1
  66. package/dist/index4.js +0 -466
  67. package/dist/index4.js.map +0 -1
  68. package/dist/index5.js +0 -729
  69. package/dist/index5.js.map +0 -1
  70. package/dist/index6.js +0 -730
  71. package/dist/index6.js.map +0 -1
  72. package/dist/logging.js +0 -43
  73. package/dist/logging.js.map +0 -1
  74. package/dist/package.js +0 -432
  75. package/dist/package.js.map +0 -1
  76. package/dist/renderer.js +0 -2391
  77. package/dist/renderer.js.map +0 -1
  78. package/dist/standard.js +0 -101
  79. package/dist/standard.js.map +0 -1
  80. package/dist/utils.js +0 -54
  81. package/dist/utils.js.map +0 -1
  82. package/svelte-kit +0 -3
@@ -0,0 +1,640 @@
1
+ import fs__default from 'fs';
2
+ import path__default from 'path';
3
+ import { p as print_config_conflicts, c as copy_assets, b as posixify, r as resolve_entry, l as load_template, m as mkdirp, a 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 { S as SVELTE_KIT } from './constants.js';
6
+ import { g as generate_manifest } from './index4.js';
7
+ import vite from 'vite';
8
+ import { s } from './misc.js';
9
+ import { svelte } from '@sveltejs/vite-plugin-svelte';
10
+ import 'sade';
11
+ import 'child_process';
12
+ import 'net';
13
+ import 'url';
14
+ import 'os';
15
+ import './error.js';
16
+
17
+ /**
18
+ * @param {{
19
+ * cwd: string;
20
+ * assets_base: string;
21
+ * config: import('types/config').ValidatedConfig
22
+ * manifest_data: import('types/internal').ManifestData
23
+ * build_dir: string;
24
+ * output_dir: string;
25
+ * client_entry_file: string;
26
+ * service_worker_entry_file: string | null;
27
+ * }} options
28
+ * @param {import('vite').Manifest} client_manifest
29
+ */
30
+ async function build_service_worker(
31
+ { cwd, assets_base, config, manifest_data, build_dir, output_dir, service_worker_entry_file },
32
+ client_manifest
33
+ ) {
34
+ // TODO add any assets referenced in template .html file, e.g. favicon?
35
+ const app_files = new Set();
36
+ for (const key in client_manifest) {
37
+ const { file, css } = client_manifest[key];
38
+ app_files.add(file);
39
+ if (css) {
40
+ css.forEach((file) => {
41
+ app_files.add(file);
42
+ });
43
+ }
44
+ }
45
+
46
+ fs__default.writeFileSync(
47
+ `${build_dir}/runtime/service-worker.js`,
48
+ `
49
+ export const timestamp = ${Date.now()};
50
+
51
+ export const build = [
52
+ ${Array.from(app_files)
53
+ .map((file) => `${s(`${config.kit.paths.base}/${config.kit.appDir}/${file}`)}`)
54
+ .join(',\n\t\t\t\t')}
55
+ ];
56
+
57
+ export const files = [
58
+ ${manifest_data.assets
59
+ .map((asset) => `${s(`${config.kit.paths.base}/${asset.file}`)}`)
60
+ .join(',\n\t\t\t\t')}
61
+ ];
62
+ `
63
+ .replace(/^\t{3}/gm, '')
64
+ .trim()
65
+ );
66
+
67
+ /** @type {[any, string[]]} */
68
+ const [merged_config, conflicts] = deep_merge(config.kit.vite(), {
69
+ configFile: false,
70
+ root: cwd,
71
+ base: assets_base,
72
+ build: {
73
+ lib: {
74
+ entry: service_worker_entry_file,
75
+ name: 'app',
76
+ formats: ['es']
77
+ },
78
+ rollupOptions: {
79
+ output: {
80
+ entryFileNames: 'service-worker.js'
81
+ }
82
+ },
83
+ outDir: `${output_dir}/client`,
84
+ emptyOutDir: false
85
+ },
86
+ resolve: {
87
+ alias: {
88
+ '$service-worker': path__default.resolve(`${build_dir}/runtime/service-worker`),
89
+ $lib: config.kit.files.lib
90
+ }
91
+ }
92
+ });
93
+
94
+ print_config_conflicts(conflicts, 'kit.vite.', 'build_service_worker');
95
+
96
+ await vite.build(merged_config);
97
+ }
98
+
99
+ /** @param {import('vite').UserConfig} config */
100
+ async function create_build(config) {
101
+ const { output } = /** @type {import('rollup').RollupOutput} */ (await vite.build(config));
102
+
103
+ const chunks = /** @type {import('rollup').OutputChunk[]} */ (
104
+ output.filter((output) => output.type === 'chunk')
105
+ );
106
+
107
+ const assets = /** @type {import('rollup').OutputAsset[]} */ (
108
+ output.filter((output) => output.type === 'asset')
109
+ );
110
+
111
+ return { chunks, assets };
112
+ }
113
+
114
+ /**
115
+ * @param {string} file
116
+ * @param {import('vite').Manifest} manifest
117
+ * @param {Set<string>} css
118
+ * @param {Set<string>} js
119
+ * @returns
120
+ */
121
+ function find_deps(file, manifest, js, css) {
122
+ const chunk = manifest[file];
123
+
124
+ if (js.has(chunk.file)) return;
125
+ js.add(chunk.file);
126
+
127
+ if (chunk.css) {
128
+ chunk.css.forEach((file) => css.add(file));
129
+ }
130
+
131
+ if (chunk.imports) {
132
+ chunk.imports.forEach((file) => find_deps(file, manifest, js, css));
133
+ }
134
+ }
135
+
136
+ /**
137
+ * @param {{
138
+ * cwd: string;
139
+ * assets_base: string;
140
+ * config: import('types/config').ValidatedConfig
141
+ * manifest_data: import('types/internal').ManifestData
142
+ * build_dir: string;
143
+ * output_dir: string;
144
+ * client_entry_file: string;
145
+ * service_worker_entry_file: string | null;
146
+ * service_worker_register: boolean;
147
+ * }} options
148
+ */
149
+ async function build_client({
150
+ cwd,
151
+ assets_base,
152
+ config,
153
+ manifest_data,
154
+ build_dir,
155
+ output_dir,
156
+ client_entry_file
157
+ }) {
158
+ create_app({
159
+ manifest_data,
160
+ output: build_dir,
161
+ cwd
162
+ });
163
+
164
+ copy_assets(build_dir);
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(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: {
210
+ $app: path__default.resolve(`${build_dir}/runtime/app`),
211
+ $lib: config.kit.files.lib
212
+ }
213
+ },
214
+ plugins: [
215
+ svelte({
216
+ extensions: config.extensions,
217
+ emitCss: !config.kit.amp,
218
+ compilerOptions: {
219
+ hydratable: !!config.kit.hydrate
220
+ }
221
+ })
222
+ ]
223
+ });
224
+
225
+ print_config_conflicts(conflicts, 'kit.vite.', 'build_client');
226
+
227
+ const { chunks, assets } = await create_build(merged_config);
228
+
229
+ /** @type {import('vite').Manifest} */
230
+ const vite_manifest = JSON.parse(fs__default.readFileSync(`${client_out_dir}/manifest.json`, 'utf-8'));
231
+
232
+ const entry_js = new Set();
233
+ const entry_css = new Set();
234
+ find_deps(client_entry_file, vite_manifest, entry_js, entry_css);
235
+
236
+ return {
237
+ assets,
238
+ chunks,
239
+ entry: {
240
+ file: vite_manifest[client_entry_file].file,
241
+ js: Array.from(entry_js),
242
+ css: Array.from(entry_css)
243
+ },
244
+ vite_manifest
245
+ };
246
+ }
247
+
248
+ /**
249
+ * @param {{
250
+ * cwd: string;
251
+ * runtime: string;
252
+ * hooks: string;
253
+ * config: import('types/config').ValidatedConfig;
254
+ * has_service_worker: boolean;
255
+ * }} opts
256
+ * @returns
257
+ */
258
+ const template = ({ cwd, config, hooks, runtime, has_service_worker }) => `
259
+ import { respond } from '${runtime}';
260
+ import root from './generated/root.svelte';
261
+ import { set_paths, assets, base } from './runtime/paths.js';
262
+ import { set_prerendering } from './runtime/env.js';
263
+ import * as user_hooks from ${s(hooks)};
264
+
265
+ const template = ({ head, body, assets }) => ${s(load_template(cwd, config))
266
+ .replace('%svelte.head%', '" + head + "')
267
+ .replace('%svelte.body%', '" + body + "')
268
+ .replace(/%svelte\.assets%/g, '" + assets + "')};
269
+
270
+ let read = null;
271
+
272
+ set_paths(${s(config.kit.paths)});
273
+
274
+ // this looks redundant, but the indirection allows us to access
275
+ // named imports without triggering Rollup's missing import detection
276
+ const get_hooks = hooks => ({
277
+ getSession: hooks.getSession || (() => ({})),
278
+ handle: hooks.handle || (({ request, resolve }) => resolve(request)),
279
+ handleError: hooks.handleError || (({ error }) => console.error(error.stack)),
280
+ externalFetch: hooks.externalFetch || fetch
281
+ });
282
+
283
+ let default_protocol = 'https';
284
+
285
+ // allow paths to be globally overridden
286
+ // in svelte-kit preview and in prerendering
287
+ export function override(settings) {
288
+ default_protocol = settings.protocol || default_protocol;
289
+ set_paths(settings.paths);
290
+ set_prerendering(settings.prerendering);
291
+ read = settings.read;
292
+ }
293
+
294
+ export class App {
295
+ constructor(manifest) {
296
+ const hooks = get_hooks(user_hooks);
297
+
298
+ this.options = {
299
+ amp: ${config.kit.amp},
300
+ dev: false,
301
+ floc: ${config.kit.floc},
302
+ get_stack: error => String(error), // for security
303
+ handle_error: (error, request) => {
304
+ hooks.handleError({ error, request });
305
+ error.stack = this.options.get_stack(error);
306
+ },
307
+ hooks,
308
+ hydrate: ${s(config.kit.hydrate)},
309
+ manifest,
310
+ method_override: ${s(config.kit.methodOverride)},
311
+ paths: { base, assets },
312
+ prefix: assets + '/${config.kit.appDir}/',
313
+ prerender: ${config.kit.prerender.enabled},
314
+ read,
315
+ root,
316
+ service_worker: ${has_service_worker ? "'/service-worker.js'" : 'null'},
317
+ router: ${s(config.kit.router)},
318
+ target: ${s(config.kit.target)},
319
+ template,
320
+ trailing_slash: ${s(config.kit.trailingSlash)}
321
+ };
322
+ }
323
+
324
+ render(request, {
325
+ prerender
326
+ } = {}) {
327
+ // TODO remove this for 1.0
328
+ if (Object.keys(request).sort().join() !== 'headers,method,rawBody,url') {
329
+ throw new Error('Adapters should call app.render({ url, method, headers, rawBody })');
330
+ }
331
+
332
+ const host = ${
333
+ config.kit.host
334
+ ? s(config.kit.host)
335
+ : `request.headers[${s(config.kit.headers.host || 'host')}]`
336
+ };
337
+ const protocol = ${
338
+ config.kit.protocol
339
+ ? s(config.kit.protocol)
340
+ : config.kit.headers.protocol
341
+ ? `request.headers[${s(config.kit.headers.protocol)}] || default_protocol`
342
+ : 'default_protocol'
343
+ };
344
+
345
+ return respond({ ...request, url: new URL(request.url, protocol + '://' + host) }, this.options, { prerender });
346
+ }
347
+ }
348
+ `;
349
+
350
+ /**
351
+ * @param {{
352
+ * cwd: string;
353
+ * assets_base: string;
354
+ * config: import('types/config').ValidatedConfig
355
+ * manifest_data: import('types/internal').ManifestData
356
+ * build_dir: string;
357
+ * output_dir: string;
358
+ * service_worker_entry_file: string | null;
359
+ * service_worker_register: boolean;
360
+ * }} options
361
+ * @param {string} runtime
362
+ * @param {{ vite_manifest: import('vite').Manifest, assets: import('rollup').OutputAsset[] }} client
363
+ */
364
+ async function build_server(
365
+ {
366
+ cwd,
367
+ assets_base,
368
+ config,
369
+ manifest_data,
370
+ build_dir,
371
+ output_dir,
372
+ service_worker_entry_file,
373
+ service_worker_register
374
+ },
375
+ runtime,
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
+ app: `${build_dir}/app.js`
387
+ };
388
+
389
+ // add entry points for every endpoint...
390
+ manifest_data.routes.forEach((route) => {
391
+ if (route.type === 'endpoint') {
392
+ const resolved = path__default.resolve(cwd, route.file);
393
+ const relative = path__default.relative(config.kit.files.routes, resolved);
394
+ const name = posixify(path__default.join('entries/endpoints', relative.replace(/\.js$/, '')));
395
+ input[name] = resolved;
396
+ }
397
+ });
398
+
399
+ // ...and every component used by pages
400
+ manifest_data.components.forEach((file) => {
401
+ const resolved = path__default.resolve(cwd, file);
402
+ const relative = path__default.relative(config.kit.files.routes, resolved);
403
+
404
+ const name = relative.startsWith('..')
405
+ ? posixify(path__default.join('entries/pages', path__default.basename(file)))
406
+ : posixify(path__default.join('entries/pages', relative));
407
+ input[name] = resolved;
408
+ });
409
+
410
+ /** @type {(file: string) => string} */
411
+ const app_relative = (file) => {
412
+ const relative_file = path__default.relative(build_dir, path__default.resolve(cwd, file));
413
+ return relative_file[0] === '.' ? relative_file : `./${relative_file}`;
414
+ };
415
+
416
+ // prettier-ignore
417
+ fs__default.writeFileSync(
418
+ input.app,
419
+ template({
420
+ cwd,
421
+ config,
422
+ hooks: app_relative(hooks_file),
423
+ runtime,
424
+ has_service_worker: service_worker_register && !!service_worker_entry_file
425
+ })
426
+ );
427
+
428
+ /** @type {import('vite').UserConfig} */
429
+ const vite_config = 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.hydrate
466
+ }
467
+ })
468
+ ],
469
+ resolve: {
470
+ alias: {
471
+ $app: path__default.resolve(`${build_dir}/runtime/app`),
472
+ $lib: config.kit.files.lib
473
+ }
474
+ }
475
+ });
476
+
477
+ print_config_conflicts(conflicts, 'kit.vite.', 'build_server');
478
+
479
+ const { chunks } = await create_build(merged_config);
480
+
481
+ /** @type {Record<string, string[]>} */
482
+ const lookup = {};
483
+ chunks.forEach((chunk) => {
484
+ if (!chunk.facadeModuleId) return;
485
+ const id = chunk.facadeModuleId.slice(cwd.length + 1);
486
+ lookup[id] = chunk.exports;
487
+ });
488
+
489
+ /** @type {Record<string, import('types/internal').HttpMethod[]>} */
490
+ const methods = {};
491
+ manifest_data.routes.forEach((route) => {
492
+ if (route.type === 'endpoint' && lookup[route.file]) {
493
+ methods[route.file] = lookup[route.file]
494
+ .map((x) => /** @type {import('types/internal').HttpMethod} */ (method_names[x]))
495
+ .filter(Boolean);
496
+ }
497
+ });
498
+
499
+ /** @type {import('vite').Manifest} */
500
+ const vite_manifest = JSON.parse(fs__default.readFileSync(`${output_dir}/server/manifest.json`, 'utf-8'));
501
+
502
+ const styles_lookup = new Map();
503
+ if (config.kit.amp) {
504
+ client.assets.forEach((asset) => {
505
+ if (asset.fileName.endsWith('.css')) {
506
+ styles_lookup.set(asset.fileName, asset.source);
507
+ }
508
+ });
509
+ }
510
+
511
+ mkdirp(`${output_dir}/server/nodes`);
512
+ manifest_data.components.forEach((component, i) => {
513
+ const file = `${output_dir}/server/nodes/${i}.js`;
514
+
515
+ const js = new Set();
516
+ const css = new Set();
517
+ find_deps(component, client.vite_manifest, js, css);
518
+
519
+ const styles = config.kit.amp && Array.from(css).map((file) => styles_lookup.get(file));
520
+
521
+ const node = `import * as module from '../${vite_manifest[component].file}';
522
+ export { module };
523
+ export const entry = '${client.vite_manifest[component].file}';
524
+ export const js = ${JSON.stringify(Array.from(js))};
525
+ export const css = ${JSON.stringify(Array.from(css))};
526
+ ${styles ? `export const styles = ${s(styles)}` : ''}
527
+ `.replace(/^\t\t\t/gm, '');
528
+
529
+ fs__default.writeFileSync(file, node);
530
+ });
531
+
532
+ return {
533
+ chunks,
534
+ vite_manifest,
535
+ methods: get_methods(cwd, chunks, manifest_data)
536
+ };
537
+ }
538
+
539
+ /** @type {Record<string, string>} */
540
+ const method_names = {
541
+ get: 'get',
542
+ head: 'head',
543
+ post: 'post',
544
+ put: 'put',
545
+ del: 'delete',
546
+ patch: 'patch'
547
+ };
548
+
549
+ /**
550
+ *
551
+ * @param {string} cwd
552
+ * @param {import('rollup').OutputChunk[]} output
553
+ * @param {import('types/internal').ManifestData} manifest_data
554
+ */
555
+ function get_methods(cwd, output, manifest_data) {
556
+ /** @type {Record<string, string[]>} */
557
+ const lookup = {};
558
+ output.forEach((chunk) => {
559
+ if (!chunk.facadeModuleId) return;
560
+ const id = chunk.facadeModuleId.slice(cwd.length + 1);
561
+ lookup[id] = chunk.exports;
562
+ });
563
+
564
+ /** @type {Record<string, import('types/internal').HttpMethod[]>} */
565
+ const methods = {};
566
+ manifest_data.routes.forEach((route) => {
567
+ if (route.type === 'endpoint' && lookup[route.file]) {
568
+ methods[route.file] = lookup[route.file]
569
+ .map((x) => /** @type {import('types/internal').HttpMethod} */ (method_names[x]))
570
+ .filter(Boolean);
571
+ }
572
+ });
573
+
574
+ return methods;
575
+ }
576
+
577
+ /**
578
+ * @param {import('types/config').ValidatedConfig} config
579
+ * @param {{
580
+ * cwd?: string;
581
+ * runtime?: string;
582
+ * }} [opts]
583
+ * @returns {Promise<import('types/internal').BuildData>}
584
+ */
585
+ async function build(config, { cwd = process.cwd(), runtime = './kit.js' } = {}) {
586
+ const build_dir = path__default.resolve(cwd, `${SVELTE_KIT}/build`);
587
+
588
+ rimraf(build_dir);
589
+
590
+ const output_dir = path__default.resolve(cwd, `${SVELTE_KIT}/output`);
591
+
592
+ const options = {
593
+ cwd,
594
+ config,
595
+ build_dir,
596
+ // TODO this is so that Vite's preloading works. Unfortunately, it fails
597
+ // during `svelte-kit preview`, because we use a local asset path. If Vite
598
+ // used relative paths, I _think_ this could get fixed. Issue here:
599
+ // https://github.com/vitejs/vite/issues/2009
600
+ assets_base: `${config.kit.paths.assets || config.kit.paths.base}/${config.kit.appDir}/`,
601
+ manifest_data: create_manifest_data({
602
+ config,
603
+ output: build_dir,
604
+ cwd
605
+ }),
606
+ output_dir,
607
+ client_entry_file: `${SVELTE_KIT}/build/runtime/internal/start.js`,
608
+ service_worker_entry_file: resolve_entry(config.kit.files.serviceWorker),
609
+ service_worker_register: config.kit.serviceWorker.register
610
+ };
611
+
612
+ const client = await build_client(options);
613
+ const server = await build_server(options, runtime, client);
614
+
615
+ if (options.service_worker_entry_file) {
616
+ if (config.kit.paths.assets) {
617
+ throw new Error('Cannot use service worker alongside config.kit.paths.assets');
618
+ }
619
+
620
+ await build_service_worker(options, client.vite_manifest);
621
+ }
622
+
623
+ const build_data = {
624
+ app_dir: config.kit.appDir,
625
+ manifest_data: options.manifest_data,
626
+ client,
627
+ server,
628
+ static: options.manifest_data.assets.map((asset) => posixify(asset.file)),
629
+ entries: options.manifest_data.routes
630
+ .map((route) => (route.type === 'page' ? route.path : ''))
631
+ .filter(Boolean)
632
+ };
633
+
634
+ const manifest = `export const manifest = ${generate_manifest(build_data, '.')};\n`;
635
+ fs__default.writeFileSync(`${output_dir}/server/manifest.js`, manifest);
636
+
637
+ return build_data;
638
+ }
639
+
640
+ export { build };