@sveltejs/kit 1.0.0-next.25 → 1.0.0-next.250

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 (86) 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 +18 -2
  10. package/assets/env.js +8 -0
  11. package/assets/paths.js +13 -0
  12. package/assets/server/index.js +2365 -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 +2690 -0
  17. package/dist/chunks/index2.js +806 -0
  18. package/dist/chunks/index3.js +644 -0
  19. package/dist/chunks/index4.js +114 -0
  20. package/dist/chunks/index5.js +765 -0
  21. package/dist/chunks/index6.js +170 -0
  22. package/dist/chunks/index7.js +15582 -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 +119 -0
  27. package/dist/cli.js +1122 -84
  28. package/dist/hooks.js +28 -0
  29. package/dist/install-fetch.js +6518 -0
  30. package/dist/node.js +95 -0
  31. package/package.json +95 -54
  32. package/svelte-kit.js +2 -0
  33. package/types/ambient-modules.d.ts +201 -0
  34. package/types/app.d.ts +35 -0
  35. package/types/config.d.ts +173 -0
  36. package/types/csp.d.ts +115 -0
  37. package/types/endpoint.d.ts +24 -0
  38. package/types/helper.d.ts +32 -0
  39. package/types/hooks.d.ts +38 -0
  40. package/types/index.d.ts +10 -0
  41. package/types/internal.d.ts +252 -0
  42. package/types/page.d.ts +85 -0
  43. package/CHANGELOG.md +0 -306
  44. package/assets/runtime/app/navigation.js +0 -23
  45. package/assets/runtime/app/navigation.js.map +0 -1
  46. package/assets/runtime/app/paths.js +0 -2
  47. package/assets/runtime/app/paths.js.map +0 -1
  48. package/assets/runtime/app/stores.js.map +0 -1
  49. package/assets/runtime/internal/singletons.js +0 -15
  50. package/assets/runtime/internal/singletons.js.map +0 -1
  51. package/assets/runtime/internal/start.js +0 -591
  52. package/assets/runtime/internal/start.js.map +0 -1
  53. package/assets/runtime/utils-85ebcc60.js +0 -18
  54. package/assets/runtime/utils-85ebcc60.js.map +0 -1
  55. package/dist/api.js +0 -44
  56. package/dist/api.js.map +0 -1
  57. package/dist/build.js +0 -246
  58. package/dist/build.js.map +0 -1
  59. package/dist/cli.js.map +0 -1
  60. package/dist/colors.js +0 -37
  61. package/dist/colors.js.map +0 -1
  62. package/dist/create_app.js +0 -578
  63. package/dist/create_app.js.map +0 -1
  64. package/dist/index.js +0 -367
  65. package/dist/index.js.map +0 -1
  66. package/dist/index2.js +0 -12043
  67. package/dist/index2.js.map +0 -1
  68. package/dist/index3.js +0 -550
  69. package/dist/index3.js.map +0 -1
  70. package/dist/index4.js +0 -74
  71. package/dist/index4.js.map +0 -1
  72. package/dist/index5.js +0 -464
  73. package/dist/index5.js.map +0 -1
  74. package/dist/index6.js +0 -727
  75. package/dist/index6.js.map +0 -1
  76. package/dist/logging.js +0 -43
  77. package/dist/logging.js.map +0 -1
  78. package/dist/package.js +0 -432
  79. package/dist/package.js.map +0 -1
  80. package/dist/renderer.js +0 -2403
  81. package/dist/renderer.js.map +0 -1
  82. package/dist/standard.js +0 -101
  83. package/dist/standard.js.map +0 -1
  84. package/dist/utils.js +0 -54
  85. package/dist/utils.js.map +0 -1
  86. package/svelte-kit +0 -3
@@ -0,0 +1,765 @@
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} path
398
+ * @param {boolean} is_html
399
+ */
400
+ function output_filename(path, is_html) {
401
+ if (path === '/') {
402
+ return '/index.html';
403
+ }
404
+ const parts = path.split('/');
405
+ if (is_html && parts[parts.length - 1] !== 'index.html') {
406
+ if (config.kit.prerender.createIndexFiles) {
407
+ parts.push('index.html');
408
+ } else {
409
+ parts[parts.length - 1] += '.html';
410
+ }
411
+ }
412
+ return parts.join('/');
413
+ }
414
+
415
+ /**
416
+ * @param {string} decoded_path
417
+ * @param {string?} referrer
418
+ */
419
+ function enqueue(decoded_path, referrer) {
420
+ const path = encodeURI(normalize(decoded_path));
421
+
422
+ if (seen.has(path)) return;
423
+ seen.add(path);
424
+
425
+ return q.add(() => visit(path, decoded_path, referrer));
426
+ }
427
+
428
+ /**
429
+ * @param {string} path
430
+ * @param {string} decoded_path
431
+ * @param {string?} referrer
432
+ */
433
+ async function visit(path, decoded_path, referrer) {
434
+ /** @type {Map<string, import('types/internal').PrerenderDependency>} */
435
+ const dependencies = new Map();
436
+
437
+ const render_path = config.kit.paths?.base
438
+ ? `http://sveltekit-prerender${config.kit.paths.base}${path === '/' ? '' : path}`
439
+ : `http://sveltekit-prerender${path}`;
440
+
441
+ const rendered = await app.render(new Request(render_path), {
442
+ prerender: {
443
+ all,
444
+ dependencies
445
+ }
446
+ });
447
+
448
+ if (rendered) {
449
+ const response_type = Math.floor(rendered.status / 100);
450
+ const type = rendered.headers.get('content-type');
451
+ const is_html = response_type === REDIRECT || type === 'text/html';
452
+
453
+ const file = `${out}${output_filename(decoded_path, is_html)}`;
454
+
455
+ if (response_type === REDIRECT) {
456
+ const location = rendered.headers.get('location');
457
+
458
+ if (location) {
459
+ mkdirp(dirname(file));
460
+
461
+ log.warn(`${rendered.status} ${decoded_path} -> ${location}`);
462
+
463
+ writeFileSync(
464
+ file,
465
+ `<meta http-equiv="refresh" content=${escape_html_attr(`0;url=${location}`)}>`
466
+ );
467
+
468
+ const resolved = resolve$1(path, location);
469
+ if (is_root_relative(resolved)) {
470
+ enqueue(resolved, path);
471
+ }
472
+ } else {
473
+ log.warn(`location header missing on redirect received from ${decoded_path}`);
474
+ }
475
+
476
+ return;
477
+ }
478
+
479
+ const text = await rendered.text();
480
+
481
+ if (rendered.status === 200) {
482
+ mkdirp(dirname(file));
483
+
484
+ log.info(`${rendered.status} ${decoded_path}`);
485
+ writeFileSync(file, text);
486
+ paths.push(normalize(decoded_path));
487
+ } else if (response_type !== OK) {
488
+ error({ status: rendered.status, path, referrer, referenceType: 'linked' });
489
+ }
490
+
491
+ for (const [dependency_path, result] of dependencies) {
492
+ const { status, headers } = result.response;
493
+
494
+ const response_type = Math.floor(status / 100);
495
+
496
+ const is_html = headers.get('content-type') === 'text/html';
497
+
498
+ const file = `${out}${output_filename(dependency_path, is_html)}`;
499
+ mkdirp(dirname(file));
500
+
501
+ writeFileSync(
502
+ file,
503
+ result.body === null ? new Uint8Array(await result.response.arrayBuffer()) : result.body
504
+ );
505
+ paths.push(dependency_path);
506
+
507
+ if (response_type === OK) {
508
+ log.info(`${status} ${dependency_path}`);
509
+ } else {
510
+ error({
511
+ status,
512
+ path: dependency_path,
513
+ referrer: path,
514
+ referenceType: 'fetched'
515
+ });
516
+ }
517
+ }
518
+
519
+ if (is_html && config.kit.prerender.crawl) {
520
+ for (const href of crawl(text)) {
521
+ if (href.startsWith('data:') || href.startsWith('#')) continue;
522
+
523
+ const resolved = resolve$1(path, href);
524
+ if (!is_root_relative(resolved)) continue;
525
+
526
+ const parsed = new URL(resolved, 'http://localhost');
527
+
528
+ let pathname = decodeURI(parsed.pathname);
529
+
530
+ if (config.kit.paths.base) {
531
+ if (!pathname.startsWith(config.kit.paths.base)) continue;
532
+ pathname = pathname.slice(config.kit.paths.base.length) || '/';
533
+ }
534
+
535
+ const file = pathname.slice(1);
536
+ if (files.has(file)) continue;
537
+
538
+ if (parsed.search) ;
539
+
540
+ enqueue(pathname, path);
541
+ }
542
+ }
543
+ }
544
+ }
545
+
546
+ if (config.kit.prerender.enabled) {
547
+ for (const entry of config.kit.prerender.entries) {
548
+ if (entry === '*') {
549
+ for (const entry of build_data.entries) {
550
+ enqueue(entry, null);
551
+ }
552
+ } else {
553
+ enqueue(entry, null);
554
+ }
555
+ }
556
+
557
+ await q.done();
558
+ }
559
+
560
+ if (fallback) {
561
+ const rendered = await app.render(new Request('http://sveltekit-prerender/[fallback]'), {
562
+ prerender: {
563
+ fallback,
564
+ all: false,
565
+ dependencies: new Map()
566
+ }
567
+ });
568
+
569
+ const file = join(out, fallback);
570
+ mkdirp(dirname(file));
571
+ writeFileSync(file, await rendered.text());
572
+ }
573
+
574
+ return {
575
+ paths
576
+ };
577
+ }
578
+
579
+ /**
580
+ * @param {{
581
+ * cwd: string;
582
+ * config: import('types/config').ValidatedConfig;
583
+ * build_data: import('types/internal').BuildData;
584
+ * log: import('types/internal').Logger;
585
+ * }} opts
586
+ * @returns {import('types/config').Builder}
587
+ */
588
+ function create_builder({ cwd, config, build_data, log }) {
589
+ /** @type {Set<string>} */
590
+ const prerendered_paths = new Set();
591
+ let generated_manifest = false;
592
+
593
+ /** @param {import('types/internal').RouteData} route */
594
+ function not_prerendered(route) {
595
+ if (route.type === 'page' && route.path) {
596
+ return !prerendered_paths.has(route.path);
597
+ }
598
+
599
+ return true;
600
+ }
601
+
602
+ return {
603
+ log,
604
+ rimraf,
605
+ mkdirp,
606
+ copy,
607
+
608
+ appDir: config.kit.appDir,
609
+
610
+ createEntries(fn) {
611
+ generated_manifest = true;
612
+
613
+ const { routes } = build_data.manifest_data;
614
+
615
+ /** @type {import('types/config').RouteDefinition[]} */
616
+ const facades = routes.map((route) => ({
617
+ type: route.type,
618
+ segments: route.segments,
619
+ pattern: route.pattern,
620
+ methods: route.type === 'page' ? ['get'] : build_data.server.methods[route.file]
621
+ }));
622
+
623
+ const seen = new Set();
624
+
625
+ for (let i = 0; i < routes.length; i += 1) {
626
+ const route = routes[i];
627
+ const { id, filter, complete } = fn(facades[i]);
628
+
629
+ if (seen.has(id)) continue;
630
+ seen.add(id);
631
+
632
+ const group = [route];
633
+
634
+ // figure out which lower priority routes should be considered fallbacks
635
+ for (let j = i + 1; j < routes.length; j += 1) {
636
+ if (filter(facades[j])) {
637
+ group.push(routes[j]);
638
+ }
639
+ }
640
+
641
+ const filtered = new Set(group.filter(not_prerendered));
642
+
643
+ // heuristic: if /foo/[bar] is included, /foo/[bar].json should
644
+ // also be included, since the page likely needs the endpoint
645
+ filtered.forEach((route) => {
646
+ if (route.type === 'page') {
647
+ const length = route.segments.length;
648
+
649
+ const endpoint = routes.find((candidate) => {
650
+ if (candidate.segments.length !== length) return false;
651
+
652
+ for (let i = 0; i < length; i += 1) {
653
+ const a = route.segments[i];
654
+ const b = candidate.segments[i];
655
+
656
+ if (i === length - 1) {
657
+ return b.content === `${a.content}.json`;
658
+ }
659
+
660
+ if (a.content !== b.content) return false;
661
+ }
662
+ });
663
+
664
+ if (endpoint) {
665
+ filtered.add(endpoint);
666
+ }
667
+ }
668
+ });
669
+
670
+ if (filtered.size > 0) {
671
+ complete({
672
+ generateManifest: ({ relativePath, format }) =>
673
+ generate_manifest(build_data, relativePath, Array.from(filtered), format)
674
+ });
675
+ }
676
+ }
677
+ },
678
+
679
+ generateManifest: ({ relativePath, format }) => {
680
+ generated_manifest = true;
681
+ return generate_manifest(
682
+ build_data,
683
+ relativePath,
684
+ build_data.manifest_data.routes.filter(not_prerendered),
685
+ format
686
+ );
687
+ },
688
+
689
+ getBuildDirectory(name) {
690
+ return `${cwd}/${SVELTE_KIT}/${name}`;
691
+ },
692
+
693
+ getClientDirectory() {
694
+ return `${cwd}/${SVELTE_KIT}/output/client`;
695
+ },
696
+
697
+ getServerDirectory() {
698
+ return `${cwd}/${SVELTE_KIT}/output/server`;
699
+ },
700
+
701
+ getStaticDirectory() {
702
+ return config.kit.files.assets;
703
+ },
704
+
705
+ writeClient(dest) {
706
+ return copy(`${cwd}/${SVELTE_KIT}/output/client`, dest, {
707
+ filter: (file) => file[0] !== '.'
708
+ });
709
+ },
710
+
711
+ writeServer(dest) {
712
+ return copy(`${cwd}/${SVELTE_KIT}/output/server`, dest, {
713
+ filter: (file) => file[0] !== '.'
714
+ });
715
+ },
716
+
717
+ writeStatic(dest) {
718
+ return copy(config.kit.files.assets, dest);
719
+ },
720
+
721
+ async prerender({ all = false, dest, fallback }) {
722
+ if (generated_manifest) {
723
+ throw new Error(
724
+ 'Adapters must call prerender(...) before createEntries(...) or generateManifest(...)'
725
+ );
726
+ }
727
+
728
+ const prerendered = await prerender({
729
+ out: dest,
730
+ all,
731
+ cwd,
732
+ config,
733
+ build_data,
734
+ fallback,
735
+ log
736
+ });
737
+
738
+ prerendered.paths.forEach((path) => {
739
+ prerendered_paths.add(path);
740
+ prerendered_paths.add(path + '/');
741
+ });
742
+
743
+ return prerendered;
744
+ }
745
+ };
746
+ }
747
+
748
+ /**
749
+ * @param {import('types/config').ValidatedConfig} config
750
+ * @param {import('types/internal').BuildData} build_data
751
+ * @param {{ cwd?: string, verbose: boolean }} opts
752
+ */
753
+ async function adapt(config, build_data, { cwd = process.cwd(), verbose }) {
754
+ const { name, adapt } = config.kit.adapter;
755
+
756
+ console.log($.bold().cyan(`\n> Using ${name}`));
757
+
758
+ const log = logger({ verbose });
759
+ const builder = create_builder({ cwd, config, build_data, log });
760
+ await adapt(builder);
761
+
762
+ log.success('done');
763
+ }
764
+
765
+ export { adapt };