@sveltejs/kit 1.0.0-next.26 → 1.0.0-next.260

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