@sveltejs/kit 1.0.0-next.24 → 1.0.0-next.240

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 (84) 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/{runtime/app → app}/stores.js +19 -15
  6. package/assets/chunks/utils.js +13 -0
  7. package/assets/client/singletons.js +21 -0
  8. package/assets/client/start.js +1382 -0
  9. package/assets/components/error.svelte +19 -3
  10. package/assets/env.js +8 -0
  11. package/assets/paths.js +13 -0
  12. package/assets/server/index.js +1842 -0
  13. package/dist/chunks/build.js +658 -0
  14. package/dist/chunks/cert.js +28154 -0
  15. package/dist/chunks/index.js +2202 -0
  16. package/dist/chunks/index2.js +807 -0
  17. package/dist/chunks/index3.js +643 -0
  18. package/dist/chunks/index4.js +109 -0
  19. package/dist/chunks/index5.js +752 -0
  20. package/dist/chunks/index6.js +170 -0
  21. package/dist/chunks/index7.js +15574 -0
  22. package/dist/chunks/index8.js +4207 -0
  23. package/dist/chunks/misc.js +3 -0
  24. package/dist/chunks/multipart-parser.js +449 -0
  25. package/dist/chunks/url.js +119 -0
  26. package/dist/cli.js +1060 -84
  27. package/dist/hooks.js +28 -0
  28. package/dist/install-fetch.js +6518 -0
  29. package/dist/node.js +85 -0
  30. package/package.json +95 -54
  31. package/svelte-kit.js +2 -0
  32. package/types/ambient-modules.d.ts +201 -0
  33. package/types/app.d.ts +31 -0
  34. package/types/config.d.ts +164 -0
  35. package/types/endpoint.d.ts +18 -0
  36. package/types/helper.d.ts +32 -0
  37. package/types/hooks.d.ts +42 -0
  38. package/types/index.d.ts +10 -0
  39. package/types/internal.d.ts +234 -0
  40. package/types/page.d.ts +85 -0
  41. package/CHANGELOG.md +0 -300
  42. package/assets/runtime/app/navigation.js +0 -23
  43. package/assets/runtime/app/navigation.js.map +0 -1
  44. package/assets/runtime/app/paths.js +0 -2
  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 +0 -15
  48. package/assets/runtime/internal/singletons.js.map +0 -1
  49. package/assets/runtime/internal/start.js +0 -591
  50. package/assets/runtime/internal/start.js.map +0 -1
  51. package/assets/runtime/utils-85ebcc60.js +0 -18
  52. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  53. package/dist/api.js +0 -44
  54. package/dist/api.js.map +0 -1
  55. package/dist/build.js +0 -246
  56. package/dist/build.js.map +0 -1
  57. package/dist/cli.js.map +0 -1
  58. package/dist/colors.js +0 -37
  59. package/dist/colors.js.map +0 -1
  60. package/dist/create_app.js +0 -578
  61. package/dist/create_app.js.map +0 -1
  62. package/dist/index.js +0 -367
  63. package/dist/index.js.map +0 -1
  64. package/dist/index2.js +0 -12044
  65. package/dist/index2.js.map +0 -1
  66. package/dist/index3.js +0 -547
  67. package/dist/index3.js.map +0 -1
  68. package/dist/index4.js +0 -73
  69. package/dist/index4.js.map +0 -1
  70. package/dist/index5.js +0 -464
  71. package/dist/index5.js.map +0 -1
  72. package/dist/index6.js +0 -727
  73. package/dist/index6.js.map +0 -1
  74. package/dist/logging.js +0 -43
  75. package/dist/logging.js.map +0 -1
  76. package/dist/package.js +0 -432
  77. package/dist/package.js.map +0 -1
  78. package/dist/renderer.js +0 -2391
  79. package/dist/renderer.js.map +0 -1
  80. package/dist/standard.js +0 -101
  81. package/dist/standard.js.map +0 -1
  82. package/dist/utils.js +0 -54
  83. package/dist/utils.js.map +0 -1
  84. package/svelte-kit +0 -3
@@ -0,0 +1,752 @@
1
+ import { m as mkdirp, a as SVELTE_KIT, h as rimraf, i as copy, $, j as logger } from '../cli.js';
2
+ import { readFileSync, writeFileSync } from 'fs';
3
+ import { resolve, join, dirname } from 'path';
4
+ import { pathToFileURL, URL } from 'url';
5
+ import { __fetch_polyfill } from '../install-fetch.js';
6
+ import { e as escape_html_attr, r as resolve$1, i as is_root_relative } from './url.js';
7
+ import { g as generate_manifest } from './index4.js';
8
+ import 'sade';
9
+ import 'child_process';
10
+ import 'net';
11
+ import 'os';
12
+ import 'node:http';
13
+ import 'node:https';
14
+ import 'node:zlib';
15
+ import 'node:stream';
16
+ import 'node:util';
17
+ import 'node:url';
18
+ import './misc.js';
19
+
20
+ /** @typedef {{
21
+ * fn: () => Promise<any>,
22
+ * fulfil: (value: any) => void,
23
+ * reject: (error: Error) => void
24
+ * }} Task */
25
+
26
+ /** @param {number} concurrency */
27
+ function queue(concurrency) {
28
+ /** @type {Task[]} */
29
+ const tasks = [];
30
+
31
+ let current = 0;
32
+
33
+ /** @type {(value?: any) => void} */
34
+ let fulfil;
35
+
36
+ /** @type {(error: Error) => void} */
37
+ let reject;
38
+
39
+ let closed = false;
40
+
41
+ const done = new Promise((f, r) => {
42
+ fulfil = f;
43
+ reject = r;
44
+ });
45
+
46
+ done.catch(() => {
47
+ // this is necessary in case a catch handler is never added
48
+ // to the done promise by the user
49
+ });
50
+
51
+ function dequeue() {
52
+ if (current < concurrency) {
53
+ const task = tasks.shift();
54
+
55
+ if (task) {
56
+ current += 1;
57
+ const promise = Promise.resolve(task.fn());
58
+
59
+ promise
60
+ .then(task.fulfil, (err) => {
61
+ task.reject(err);
62
+ reject(err);
63
+ })
64
+ .then(() => {
65
+ current -= 1;
66
+ dequeue();
67
+ });
68
+ } else if (current === 0) {
69
+ closed = true;
70
+ fulfil();
71
+ }
72
+ }
73
+ }
74
+
75
+ return {
76
+ /** @param {() => any} fn */
77
+ add: (fn) => {
78
+ if (closed) throw new Error('Cannot add tasks to a queue that has ended');
79
+
80
+ const promise = new Promise((fulfil, reject) => {
81
+ tasks.push({ fn, fulfil, reject });
82
+ });
83
+
84
+ dequeue();
85
+ return promise;
86
+ },
87
+
88
+ done: () => {
89
+ if (current === 0) {
90
+ closed = true;
91
+ fulfil();
92
+ }
93
+
94
+ return done;
95
+ }
96
+ };
97
+ }
98
+
99
+ const DOCTYPE = 'DOCTYPE';
100
+ const CDATA_OPEN = '[CDATA[';
101
+ const CDATA_CLOSE = ']]>';
102
+ const COMMENT_OPEN = '--';
103
+ const COMMENT_CLOSE = '-->';
104
+
105
+ const TAG_OPEN = /[a-zA-Z]/;
106
+ const TAG_CHAR = /[a-zA-Z0-9]/;
107
+ const ATTRIBUTE_NAME = /[^\t\n\f />"'=]/;
108
+
109
+ const EXTERNAL = /\bexternal\b/;
110
+
111
+ const WHITESPACE = /[\s\n\r]/;
112
+
113
+ /** @param {string} html */
114
+ function crawl(html) {
115
+ /** @type {string[]} */
116
+ const hrefs = [];
117
+
118
+ let i = 0;
119
+ main: while (i < html.length) {
120
+ const char = html[i];
121
+
122
+ if (char === '<') {
123
+ if (html[i + 1] === '!') {
124
+ i += 2;
125
+
126
+ if (html.substr(i, DOCTYPE.length).toUpperCase() === DOCTYPE) {
127
+ i += DOCTYPE.length;
128
+ while (i < html.length) {
129
+ if (html[i++] === '>') {
130
+ continue main;
131
+ }
132
+ }
133
+ }
134
+
135
+ // skip cdata
136
+ if (html.substr(i, CDATA_OPEN.length) === CDATA_OPEN) {
137
+ i += CDATA_OPEN.length;
138
+ while (i < html.length) {
139
+ if (html.substr(i, CDATA_CLOSE.length) === CDATA_CLOSE) {
140
+ i += CDATA_CLOSE.length;
141
+ continue main;
142
+ }
143
+
144
+ i += 1;
145
+ }
146
+ }
147
+
148
+ // skip comments
149
+ if (html.substr(i, COMMENT_OPEN.length) === COMMENT_OPEN) {
150
+ i += COMMENT_OPEN.length;
151
+ while (i < html.length) {
152
+ if (html.substr(i, COMMENT_CLOSE.length) === COMMENT_CLOSE) {
153
+ i += COMMENT_CLOSE.length;
154
+ continue main;
155
+ }
156
+
157
+ i += 1;
158
+ }
159
+ }
160
+ }
161
+
162
+ // parse opening tags
163
+ const start = ++i;
164
+ if (TAG_OPEN.test(html[start])) {
165
+ while (i < html.length) {
166
+ if (!TAG_CHAR.test(html[i])) {
167
+ break;
168
+ }
169
+
170
+ i += 1;
171
+ }
172
+
173
+ const tag = html.slice(start, i).toUpperCase();
174
+
175
+ if (tag === 'SCRIPT' || tag === 'STYLE') {
176
+ while (i < html.length) {
177
+ if (
178
+ html[i] === '<' &&
179
+ html[i + 1] === '/' &&
180
+ html.substr(i + 2, tag.length).toUpperCase() === tag
181
+ ) {
182
+ continue main;
183
+ }
184
+
185
+ i += 1;
186
+ }
187
+ }
188
+
189
+ let rel = '';
190
+ let href = '';
191
+
192
+ while (i < html.length) {
193
+ const start = i;
194
+
195
+ const char = html[start];
196
+ if (char === '>') break;
197
+
198
+ if (ATTRIBUTE_NAME.test(char)) {
199
+ i += 1;
200
+
201
+ while (i < html.length) {
202
+ if (!ATTRIBUTE_NAME.test(html[i])) {
203
+ break;
204
+ }
205
+
206
+ i += 1;
207
+ }
208
+
209
+ const name = html.slice(start, i).toLowerCase();
210
+
211
+ while (WHITESPACE.test(html[i])) i += 1;
212
+
213
+ if (html[i] === '=') {
214
+ i += 1;
215
+ while (WHITESPACE.test(html[i])) i += 1;
216
+
217
+ let value;
218
+
219
+ if (html[i] === "'" || html[i] === '"') {
220
+ const quote = html[i++];
221
+
222
+ const start = i;
223
+ let escaped = false;
224
+
225
+ while (i < html.length) {
226
+ if (!escaped) {
227
+ const char = html[i];
228
+
229
+ if (html[i] === quote) {
230
+ break;
231
+ }
232
+
233
+ if (char === '\\') {
234
+ escaped = true;
235
+ }
236
+ }
237
+
238
+ i += 1;
239
+ }
240
+
241
+ value = html.slice(start, i);
242
+ } else {
243
+ const start = i;
244
+ while (html[i] !== '>' && !WHITESPACE.test(html[i])) i += 1;
245
+ value = html.slice(start, i);
246
+
247
+ i -= 1;
248
+ }
249
+
250
+ if (name === 'rel') {
251
+ rel = value;
252
+ } else if (name === 'href') {
253
+ href = value;
254
+ } else if (name === 'src') {
255
+ hrefs.push(value);
256
+ } else if (name === 'srcset') {
257
+ const candidates = [];
258
+ let insideURL = true;
259
+ value = value.trim();
260
+ for (let i = 0; i < value.length; i++) {
261
+ if (value[i] === ',' && (!insideURL || (insideURL && value[i + 1] === ' '))) {
262
+ candidates.push(value.slice(0, i));
263
+ value = value.substring(i + 1).trim();
264
+ i = 0;
265
+ insideURL = true;
266
+ } else if (value[i] === ' ') {
267
+ insideURL = false;
268
+ }
269
+ }
270
+ candidates.push(value);
271
+ for (const candidate of candidates) {
272
+ const src = candidate.split(WHITESPACE)[0];
273
+ hrefs.push(src);
274
+ }
275
+ }
276
+ }
277
+ }
278
+
279
+ i += 1;
280
+ }
281
+
282
+ if (href && !EXTERNAL.test(rel)) {
283
+ hrefs.push(href);
284
+ }
285
+ }
286
+ }
287
+
288
+ i += 1;
289
+ }
290
+
291
+ return hrefs;
292
+ }
293
+
294
+ /**
295
+ * @typedef {import('types/config').PrerenderErrorHandler} PrerenderErrorHandler
296
+ * @typedef {import('types/config').PrerenderOnErrorValue} OnError
297
+ * @typedef {import('types/internal').Logger} Logger
298
+ */
299
+
300
+ /** @type {(errorDetails: Parameters<PrerenderErrorHandler>[0] ) => string} */
301
+ function errorDetailsToString({ status, path, referrer, referenceType }) {
302
+ return `${status} ${path}${referrer ? ` (${referenceType} from ${referrer})` : ''}`;
303
+ }
304
+
305
+ /** @type {(log: Logger, onError: OnError) => PrerenderErrorHandler} */
306
+ function chooseErrorHandler(log, onError) {
307
+ switch (onError) {
308
+ case 'continue':
309
+ return (errorDetails) => {
310
+ log.error(errorDetailsToString(errorDetails));
311
+ };
312
+ case 'fail':
313
+ return (errorDetails) => {
314
+ throw new Error(errorDetailsToString(errorDetails));
315
+ };
316
+ default:
317
+ return onError;
318
+ }
319
+ }
320
+
321
+ const OK = 2;
322
+ const REDIRECT = 3;
323
+
324
+ /**
325
+ * @param {{
326
+ * cwd: string;
327
+ * out: string;
328
+ * log: Logger;
329
+ * config: import('types/config').ValidatedConfig;
330
+ * build_data: import('types/internal').BuildData;
331
+ * fallback?: string;
332
+ * all: boolean; // disregard `export const prerender = true`
333
+ * }} opts
334
+ * @returns {Promise<{ paths: string[] }>} returns a promise that resolves to an array of paths corresponding to the files that have been prerendered.
335
+ */
336
+ async function prerender({ cwd, out, log, config, build_data, fallback, all }) {
337
+ if (!config.kit.prerender.enabled && !fallback) {
338
+ return { paths: [] };
339
+ }
340
+
341
+ __fetch_polyfill();
342
+
343
+ mkdirp(out);
344
+
345
+ const dir = resolve(cwd, `${SVELTE_KIT}/output`);
346
+
347
+ const seen = new Set();
348
+
349
+ const server_root = resolve(dir);
350
+
351
+ /** @type {import('types/internal').AppModule} */
352
+ const { App, override } = await import(pathToFileURL(`${server_root}/server/app.js`).href);
353
+
354
+ override({
355
+ paths: config.kit.paths,
356
+ prerendering: true,
357
+ read: (file) => readFileSync(join(config.kit.files.assets, file))
358
+ });
359
+
360
+ const { manifest } = await import(pathToFileURL(`${server_root}/server/manifest.js`).href);
361
+
362
+ const app = new App(manifest);
363
+
364
+ const error = chooseErrorHandler(log, config.kit.prerender.onError);
365
+
366
+ const files = new Set([
367
+ ...build_data.static,
368
+ ...build_data.client.chunks.map((chunk) => `${config.kit.appDir}/${chunk.fileName}`),
369
+ ...build_data.client.assets.map((chunk) => `${config.kit.appDir}/${chunk.fileName}`)
370
+ ]);
371
+
372
+ /** @type {string[]} */
373
+ const paths = [];
374
+
375
+ build_data.static.forEach((file) => {
376
+ if (file.endsWith('/index.html')) {
377
+ files.add(file.slice(0, -11));
378
+ }
379
+ });
380
+
381
+ /**
382
+ * @param {string} path
383
+ */
384
+ function normalize(path) {
385
+ if (config.kit.trailingSlash === 'always') {
386
+ return path.endsWith('/') ? path : `${path}/`;
387
+ } else if (config.kit.trailingSlash === 'never') {
388
+ return !path.endsWith('/') || path === '/' ? path : path.slice(0, -1);
389
+ }
390
+
391
+ return path;
392
+ }
393
+
394
+ const q = queue(config.kit.prerender.concurrency);
395
+
396
+ /**
397
+ * @param {string} decoded_path
398
+ * @param {string?} referrer
399
+ */
400
+ function enqueue(decoded_path, referrer) {
401
+ const path = encodeURI(normalize(decoded_path));
402
+
403
+ if (seen.has(path)) return;
404
+ seen.add(path);
405
+
406
+ return q.add(() => visit(path, decoded_path, referrer));
407
+ }
408
+
409
+ /**
410
+ * @param {string} path
411
+ * @param {string} decoded_path
412
+ * @param {string?} referrer
413
+ */
414
+ async function visit(path, decoded_path, referrer) {
415
+ /** @type {Map<string, Response>} */
416
+ const dependencies = new Map();
417
+ const render_path = config.kit.paths?.base
418
+ ? `http://sveltekit-prerender${config.kit.paths.base}${path === '/' ? '' : path}`
419
+ : `http://sveltekit-prerender${path}`;
420
+
421
+ const rendered = await app.render(new Request(render_path), {
422
+ prerender: {
423
+ all,
424
+ dependencies
425
+ }
426
+ });
427
+
428
+ if (rendered) {
429
+ const response_type = Math.floor(rendered.status / 100);
430
+ const type = rendered.headers.get('content-type');
431
+ const is_html = response_type === REDIRECT || type === 'text/html';
432
+
433
+ const parts = decoded_path.split('/');
434
+ if (is_html && parts[parts.length - 1] !== 'index.html') {
435
+ parts.push('index.html');
436
+ }
437
+
438
+ const file = `${out}${parts.join('/')}`;
439
+
440
+ if (response_type === REDIRECT) {
441
+ const location = rendered.headers.get('location');
442
+
443
+ if (location) {
444
+ mkdirp(dirname(file));
445
+
446
+ log.warn(`${rendered.status} ${decoded_path} -> ${location}`);
447
+
448
+ writeFileSync(
449
+ file,
450
+ `<meta http-equiv="refresh" content=${escape_html_attr(`0;url=${location}`)}>`
451
+ );
452
+
453
+ const resolved = resolve$1(path, location);
454
+ if (is_root_relative(resolved)) {
455
+ enqueue(resolved, path);
456
+ }
457
+ } else {
458
+ log.warn(`location header missing on redirect received from ${decoded_path}`);
459
+ }
460
+
461
+ return;
462
+ }
463
+
464
+ const text = await rendered.text();
465
+
466
+ if (rendered.status === 200) {
467
+ mkdirp(dirname(file));
468
+
469
+ log.info(`${rendered.status} ${decoded_path}`);
470
+ writeFileSync(file, text);
471
+ paths.push(normalize(decoded_path));
472
+ } else if (response_type !== OK) {
473
+ error({ status: rendered.status, path, referrer, referenceType: 'linked' });
474
+ }
475
+
476
+ for (const [dependency_path, result] of dependencies) {
477
+ const response_type = Math.floor(result.status / 100);
478
+
479
+ const is_html = result.headers.get('content-type') === 'text/html';
480
+
481
+ const parts = dependency_path.split('/');
482
+ if (is_html && parts[parts.length - 1] !== 'index.html') {
483
+ parts.push('index.html');
484
+ }
485
+
486
+ const file = `${out}${parts.join('/')}`;
487
+ mkdirp(dirname(file));
488
+
489
+ if (result.body) {
490
+ writeFileSync(file, await result.text());
491
+ paths.push(dependency_path);
492
+ }
493
+
494
+ if (response_type === OK) {
495
+ log.info(`${result.status} ${dependency_path}`);
496
+ } else {
497
+ error({
498
+ status: result.status,
499
+ path: dependency_path,
500
+ referrer: path,
501
+ referenceType: 'fetched'
502
+ });
503
+ }
504
+ }
505
+
506
+ if (is_html && config.kit.prerender.crawl) {
507
+ for (const href of crawl(text)) {
508
+ if (href.startsWith('data:') || href.startsWith('#')) continue;
509
+
510
+ const resolved = resolve$1(path, href);
511
+ if (!is_root_relative(resolved)) continue;
512
+
513
+ const parsed = new URL(resolved, 'http://localhost');
514
+
515
+ let pathname = decodeURI(parsed.pathname);
516
+
517
+ if (config.kit.paths.base) {
518
+ if (!pathname.startsWith(config.kit.paths.base)) continue;
519
+ pathname = pathname.slice(config.kit.paths.base.length) || '/';
520
+ }
521
+
522
+ const file = pathname.slice(1);
523
+ if (files.has(file)) continue;
524
+
525
+ if (parsed.search) ;
526
+
527
+ enqueue(pathname, path);
528
+ }
529
+ }
530
+ }
531
+ }
532
+
533
+ if (config.kit.prerender.enabled) {
534
+ for (const entry of config.kit.prerender.entries) {
535
+ if (entry === '*') {
536
+ for (const entry of build_data.entries) {
537
+ enqueue(entry, null);
538
+ }
539
+ } else {
540
+ enqueue(entry, null);
541
+ }
542
+ }
543
+
544
+ await q.done();
545
+ }
546
+
547
+ if (fallback) {
548
+ const rendered = await app.render(new Request('http://sveltekit-prerender/[fallback]'), {
549
+ prerender: {
550
+ fallback,
551
+ all: false,
552
+ dependencies: new Map()
553
+ }
554
+ });
555
+
556
+ const file = join(out, fallback);
557
+ mkdirp(dirname(file));
558
+ writeFileSync(file, await rendered.text());
559
+ }
560
+
561
+ return {
562
+ paths
563
+ };
564
+ }
565
+
566
+ /**
567
+ * @param {{
568
+ * cwd: string;
569
+ * config: import('types/config').ValidatedConfig;
570
+ * build_data: import('types/internal').BuildData;
571
+ * log: import('types/internal').Logger;
572
+ * }} opts
573
+ * @returns {import('types/config').Builder}
574
+ */
575
+ function create_builder({ cwd, config, build_data, log }) {
576
+ /** @type {Set<string>} */
577
+ const prerendered_paths = new Set();
578
+ let generated_manifest = false;
579
+
580
+ /** @param {import('types/internal').RouteData} route */
581
+ function not_prerendered(route) {
582
+ if (route.type === 'page' && route.path) {
583
+ return !prerendered_paths.has(route.path);
584
+ }
585
+
586
+ return true;
587
+ }
588
+
589
+ return {
590
+ log,
591
+ rimraf,
592
+ mkdirp,
593
+ copy,
594
+
595
+ appDir: config.kit.appDir,
596
+
597
+ createEntries(fn) {
598
+ generated_manifest = true;
599
+
600
+ const { routes } = build_data.manifest_data;
601
+
602
+ /** @type {import('types/config').RouteDefinition[]} */
603
+ const facades = routes.map((route) => ({
604
+ type: route.type,
605
+ segments: route.segments,
606
+ pattern: route.pattern,
607
+ methods: route.type === 'page' ? ['get'] : build_data.server.methods[route.file]
608
+ }));
609
+
610
+ const seen = new Set();
611
+
612
+ for (let i = 0; i < routes.length; i += 1) {
613
+ const route = routes[i];
614
+ const { id, filter, complete } = fn(facades[i]);
615
+
616
+ if (seen.has(id)) continue;
617
+ seen.add(id);
618
+
619
+ const group = [route];
620
+
621
+ // figure out which lower priority routes should be considered fallbacks
622
+ for (let j = i + 1; j < routes.length; j += 1) {
623
+ if (filter(facades[j])) {
624
+ group.push(routes[j]);
625
+ }
626
+ }
627
+
628
+ const filtered = new Set(group.filter(not_prerendered));
629
+
630
+ // heuristic: if /foo/[bar] is included, /foo/[bar].json should
631
+ // also be included, since the page likely needs the endpoint
632
+ filtered.forEach((route) => {
633
+ if (route.type === 'page') {
634
+ const length = route.segments.length;
635
+
636
+ const endpoint = routes.find((candidate) => {
637
+ if (candidate.segments.length !== length) return false;
638
+
639
+ for (let i = 0; i < length; i += 1) {
640
+ const a = route.segments[i];
641
+ const b = candidate.segments[i];
642
+
643
+ if (i === length - 1) {
644
+ return b.content === `${a.content}.json`;
645
+ }
646
+
647
+ if (a.content !== b.content) return false;
648
+ }
649
+ });
650
+
651
+ if (endpoint) {
652
+ filtered.add(endpoint);
653
+ }
654
+ }
655
+ });
656
+
657
+ if (filtered.size > 0) {
658
+ complete({
659
+ generateManifest: ({ relativePath, format }) =>
660
+ generate_manifest(build_data, relativePath, Array.from(filtered), format)
661
+ });
662
+ }
663
+ }
664
+ },
665
+
666
+ generateManifest: ({ relativePath, format }) => {
667
+ generated_manifest = true;
668
+ return generate_manifest(
669
+ build_data,
670
+ relativePath,
671
+ build_data.manifest_data.routes.filter(not_prerendered),
672
+ format
673
+ );
674
+ },
675
+
676
+ getBuildDirectory(name) {
677
+ return `${cwd}/${SVELTE_KIT}/${name}`;
678
+ },
679
+
680
+ getClientDirectory() {
681
+ return `${cwd}/${SVELTE_KIT}/output/client`;
682
+ },
683
+
684
+ getServerDirectory() {
685
+ return `${cwd}/${SVELTE_KIT}/output/server`;
686
+ },
687
+
688
+ getStaticDirectory() {
689
+ return config.kit.files.assets;
690
+ },
691
+
692
+ writeClient(dest) {
693
+ return copy(`${cwd}/${SVELTE_KIT}/output/client`, dest, {
694
+ filter: (file) => file[0] !== '.'
695
+ });
696
+ },
697
+
698
+ writeServer(dest) {
699
+ return copy(`${cwd}/${SVELTE_KIT}/output/server`, dest, {
700
+ filter: (file) => file[0] !== '.'
701
+ });
702
+ },
703
+
704
+ writeStatic(dest) {
705
+ return copy(config.kit.files.assets, dest);
706
+ },
707
+
708
+ async prerender({ all = false, dest, fallback }) {
709
+ if (generated_manifest) {
710
+ throw new Error(
711
+ 'Adapters must call prerender(...) before createEntries(...) or generateManifest(...)'
712
+ );
713
+ }
714
+
715
+ const prerendered = await prerender({
716
+ out: dest,
717
+ all,
718
+ cwd,
719
+ config,
720
+ build_data,
721
+ fallback,
722
+ log
723
+ });
724
+
725
+ prerendered.paths.forEach((path) => {
726
+ prerendered_paths.add(path);
727
+ prerendered_paths.add(path + '/');
728
+ });
729
+
730
+ return prerendered;
731
+ }
732
+ };
733
+ }
734
+
735
+ /**
736
+ * @param {import('types/config').ValidatedConfig} config
737
+ * @param {import('types/internal').BuildData} build_data
738
+ * @param {{ cwd?: string, verbose: boolean }} opts
739
+ */
740
+ async function adapt(config, build_data, { cwd = process.cwd(), verbose }) {
741
+ const { name, adapt } = config.kit.adapter;
742
+
743
+ console.log($.bold().cyan(`\n> Using ${name}`));
744
+
745
+ const log = logger({ verbose });
746
+ const builder = create_builder({ cwd, config, build_data, log });
747
+ await adapt(builder);
748
+
749
+ log.success('done');
750
+ }
751
+
752
+ export { adapt };