@sveltejs/kit 1.0.0-next.43 → 1.0.0-next.430

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 (104) hide show
  1. package/README.md +12 -9
  2. package/package.json +95 -63
  3. package/src/cli.js +112 -0
  4. package/src/core/adapt/builder.js +207 -0
  5. package/src/core/adapt/index.js +19 -0
  6. package/src/core/config/index.js +86 -0
  7. package/src/core/config/options.js +488 -0
  8. package/src/core/config/types.d.ts +1 -0
  9. package/src/core/constants.js +5 -0
  10. package/src/core/env.js +97 -0
  11. package/src/core/generate_manifest/index.js +99 -0
  12. package/src/core/prerender/crawl.js +194 -0
  13. package/src/core/prerender/prerender.js +378 -0
  14. package/src/core/prerender/queue.js +80 -0
  15. package/src/core/sync/create_manifest_data/index.js +506 -0
  16. package/src/core/sync/create_manifest_data/types.d.ts +40 -0
  17. package/src/core/sync/sync.js +59 -0
  18. package/src/core/sync/utils.js +44 -0
  19. package/src/core/sync/write_ambient.js +27 -0
  20. package/src/core/sync/write_client_manifest.js +82 -0
  21. package/src/core/sync/write_matchers.js +25 -0
  22. package/src/core/sync/write_root.js +91 -0
  23. package/src/core/sync/write_tsconfig.js +195 -0
  24. package/src/core/sync/write_types.js +775 -0
  25. package/src/core/utils.js +70 -0
  26. package/src/hooks.js +26 -0
  27. package/src/index/index.js +45 -0
  28. package/src/index/private.js +33 -0
  29. package/src/node/index.js +145 -0
  30. package/src/node/polyfills.js +40 -0
  31. package/src/runtime/app/env.js +11 -0
  32. package/src/runtime/app/navigation.js +22 -0
  33. package/src/runtime/app/paths.js +1 -0
  34. package/src/runtime/app/stores.js +102 -0
  35. package/src/runtime/client/ambient.d.ts +17 -0
  36. package/src/runtime/client/client.js +1289 -0
  37. package/src/runtime/client/fetcher.js +60 -0
  38. package/src/runtime/client/parse.js +36 -0
  39. package/src/runtime/client/singletons.js +21 -0
  40. package/src/runtime/client/start.js +46 -0
  41. package/src/runtime/client/types.d.ts +105 -0
  42. package/src/runtime/client/utils.js +113 -0
  43. package/src/runtime/components/error.svelte +16 -0
  44. package/{assets → src/runtime}/components/layout.svelte +0 -0
  45. package/src/runtime/env/dynamic/private.js +1 -0
  46. package/src/runtime/env/dynamic/public.js +1 -0
  47. package/src/runtime/env-private.js +7 -0
  48. package/src/runtime/env-public.js +7 -0
  49. package/src/runtime/env.js +6 -0
  50. package/src/runtime/hash.js +16 -0
  51. package/src/runtime/paths.js +11 -0
  52. package/src/runtime/server/endpoint.js +58 -0
  53. package/src/runtime/server/index.js +448 -0
  54. package/src/runtime/server/page/cookie.js +25 -0
  55. package/src/runtime/server/page/crypto.js +239 -0
  56. package/src/runtime/server/page/csp.js +249 -0
  57. package/src/runtime/server/page/fetch.js +266 -0
  58. package/src/runtime/server/page/index.js +416 -0
  59. package/src/runtime/server/page/load_data.js +135 -0
  60. package/src/runtime/server/page/render.js +362 -0
  61. package/src/runtime/server/page/respond_with_error.js +94 -0
  62. package/src/runtime/server/page/types.d.ts +44 -0
  63. package/src/runtime/server/utils.js +116 -0
  64. package/src/utils/error.js +22 -0
  65. package/src/utils/escape.js +104 -0
  66. package/src/utils/filesystem.js +108 -0
  67. package/src/utils/http.js +55 -0
  68. package/src/utils/misc.js +1 -0
  69. package/src/utils/routing.js +108 -0
  70. package/src/utils/url.js +97 -0
  71. package/src/vite/build/build_server.js +337 -0
  72. package/src/vite/build/build_service_worker.js +90 -0
  73. package/src/vite/build/utils.js +160 -0
  74. package/src/vite/dev/index.js +551 -0
  75. package/src/vite/index.js +574 -0
  76. package/src/vite/preview/index.js +186 -0
  77. package/src/vite/types.d.ts +3 -0
  78. package/src/vite/utils.js +345 -0
  79. package/svelte-kit.js +1 -1
  80. package/types/ambient.d.ts +357 -0
  81. package/types/index.d.ts +343 -0
  82. package/types/internal.d.ts +308 -0
  83. package/types/private.d.ts +209 -0
  84. package/CHANGELOG.md +0 -431
  85. package/assets/components/error.svelte +0 -13
  86. package/assets/runtime/app/env.js +0 -5
  87. package/assets/runtime/app/navigation.js +0 -41
  88. package/assets/runtime/app/paths.js +0 -1
  89. package/assets/runtime/app/stores.js +0 -93
  90. package/assets/runtime/chunks/utils.js +0 -19
  91. package/assets/runtime/internal/singletons.js +0 -23
  92. package/assets/runtime/internal/start.js +0 -770
  93. package/assets/runtime/paths.js +0 -12
  94. package/dist/.DS_Store +0 -0
  95. package/dist/chunks/index.js +0 -3521
  96. package/dist/chunks/index2.js +0 -587
  97. package/dist/chunks/index3.js +0 -246
  98. package/dist/chunks/index4.js +0 -538
  99. package/dist/chunks/index5.js +0 -761
  100. package/dist/chunks/index6.js +0 -322
  101. package/dist/chunks/standard.js +0 -99
  102. package/dist/chunks/utils.js +0 -83
  103. package/dist/cli.js +0 -546
  104. package/dist/ssr.js +0 -2581
@@ -1,761 +0,0 @@
1
- import { $ } from '../cli.js';
2
- import { pathToFileURL, URLSearchParams, resolve as resolve$2, parse } from 'url';
3
- import { m as mkdirp, a as copy, l as logger } from './utils.js';
4
- import fs, { readFileSync, writeFileSync, existsSync } from 'fs';
5
- import path, { resolve as resolve$1, sep, join as join$1, dirname } from 'path';
6
- import os from 'os';
7
- import { createRequire } from 'module';
8
- import 'sade';
9
-
10
- const isWin$1 = process.platform === 'win32';
11
- const SEP = isWin$1 ? `\\\\+` : `\\/`;
12
- const SEP_ESC = isWin$1 ? `\\\\` : `/`;
13
- const GLOBSTAR = `((?:[^/]*(?:/|$))*)`;
14
- const WILDCARD = `([^/]*)`;
15
- const GLOBSTAR_SEGMENT = `((?:[^${SEP_ESC}]*(?:${SEP_ESC}|$))*)`;
16
- const WILDCARD_SEGMENT = `([^${SEP_ESC}]*)`;
17
-
18
- /**
19
- * Convert any glob pattern to a JavaScript Regexp object
20
- * @param {String} glob Glob pattern to convert
21
- * @param {Object} opts Configuration object
22
- * @param {Boolean} [opts.extended=false] Support advanced ext globbing
23
- * @param {Boolean} [opts.globstar=false] Support globstar
24
- * @param {Boolean} [opts.strict=true] be laissez faire about mutiple slashes
25
- * @param {Boolean} [opts.filepath=''] Parse as filepath for extra path related features
26
- * @param {String} [opts.flags=''] RegExp globs
27
- * @returns {Object} converted object with string, segments and RegExp object
28
- */
29
- function globrex(glob, {extended = false, globstar = false, strict = false, filepath = false, flags = ''} = {}) {
30
- let regex = '';
31
- let segment = '';
32
- let path = { regex: '', segments: [] };
33
-
34
- // If we are doing extended matching, this boolean is true when we are inside
35
- // a group (eg {*.html,*.js}), and false otherwise.
36
- let inGroup = false;
37
- let inRange = false;
38
-
39
- // extglob stack. Keep track of scope
40
- const ext = [];
41
-
42
- // Helper function to build string and segments
43
- function add(str, {split, last, only}={}) {
44
- if (only !== 'path') regex += str;
45
- if (filepath && only !== 'regex') {
46
- path.regex += (str === '\\/' ? SEP : str);
47
- if (split) {
48
- if (last) segment += str;
49
- if (segment !== '') {
50
- if (!flags.includes('g')) segment = `^${segment}$`; // change it 'includes'
51
- path.segments.push(new RegExp(segment, flags));
52
- }
53
- segment = '';
54
- } else {
55
- segment += str;
56
- }
57
- }
58
- }
59
-
60
- let c, n;
61
- for (let i = 0; i < glob.length; i++) {
62
- c = glob[i];
63
- n = glob[i + 1];
64
-
65
- if (['\\', '$', '^', '.', '='].includes(c)) {
66
- add(`\\${c}`);
67
- continue;
68
- }
69
-
70
- if (c === '/') {
71
- add(`\\${c}`, {split: true});
72
- if (n === '/' && !strict) regex += '?';
73
- continue;
74
- }
75
-
76
- if (c === '(') {
77
- if (ext.length) {
78
- add(c);
79
- continue;
80
- }
81
- add(`\\${c}`);
82
- continue;
83
- }
84
-
85
- if (c === ')') {
86
- if (ext.length) {
87
- add(c);
88
- let type = ext.pop();
89
- if (type === '@') {
90
- add('{1}');
91
- } else if (type === '!') {
92
- add('([^\/]*)');
93
- } else {
94
- add(type);
95
- }
96
- continue;
97
- }
98
- add(`\\${c}`);
99
- continue;
100
- }
101
-
102
- if (c === '|') {
103
- if (ext.length) {
104
- add(c);
105
- continue;
106
- }
107
- add(`\\${c}`);
108
- continue;
109
- }
110
-
111
- if (c === '+') {
112
- if (n === '(' && extended) {
113
- ext.push(c);
114
- continue;
115
- }
116
- add(`\\${c}`);
117
- continue;
118
- }
119
-
120
- if (c === '@' && extended) {
121
- if (n === '(') {
122
- ext.push(c);
123
- continue;
124
- }
125
- }
126
-
127
- if (c === '!') {
128
- if (extended) {
129
- if (inRange) {
130
- add('^');
131
- continue
132
- }
133
- if (n === '(') {
134
- ext.push(c);
135
- add('(?!');
136
- i++;
137
- continue;
138
- }
139
- add(`\\${c}`);
140
- continue;
141
- }
142
- add(`\\${c}`);
143
- continue;
144
- }
145
-
146
- if (c === '?') {
147
- if (extended) {
148
- if (n === '(') {
149
- ext.push(c);
150
- } else {
151
- add('.');
152
- }
153
- continue;
154
- }
155
- add(`\\${c}`);
156
- continue;
157
- }
158
-
159
- if (c === '[') {
160
- if (inRange && n === ':') {
161
- i++; // skip [
162
- let value = '';
163
- while(glob[++i] !== ':') value += glob[i];
164
- if (value === 'alnum') add('(\\w|\\d)');
165
- else if (value === 'space') add('\\s');
166
- else if (value === 'digit') add('\\d');
167
- i++; // skip last ]
168
- continue;
169
- }
170
- if (extended) {
171
- inRange = true;
172
- add(c);
173
- continue;
174
- }
175
- add(`\\${c}`);
176
- continue;
177
- }
178
-
179
- if (c === ']') {
180
- if (extended) {
181
- inRange = false;
182
- add(c);
183
- continue;
184
- }
185
- add(`\\${c}`);
186
- continue;
187
- }
188
-
189
- if (c === '{') {
190
- if (extended) {
191
- inGroup = true;
192
- add('(');
193
- continue;
194
- }
195
- add(`\\${c}`);
196
- continue;
197
- }
198
-
199
- if (c === '}') {
200
- if (extended) {
201
- inGroup = false;
202
- add(')');
203
- continue;
204
- }
205
- add(`\\${c}`);
206
- continue;
207
- }
208
-
209
- if (c === ',') {
210
- if (inGroup) {
211
- add('|');
212
- continue;
213
- }
214
- add(`\\${c}`);
215
- continue;
216
- }
217
-
218
- if (c === '*') {
219
- if (n === '(' && extended) {
220
- ext.push(c);
221
- continue;
222
- }
223
- // Move over all consecutive "*"'s.
224
- // Also store the previous and next characters
225
- let prevChar = glob[i - 1];
226
- let starCount = 1;
227
- while (glob[i + 1] === '*') {
228
- starCount++;
229
- i++;
230
- }
231
- let nextChar = glob[i + 1];
232
- if (!globstar) {
233
- // globstar is disabled, so treat any number of "*" as one
234
- add('.*');
235
- } else {
236
- // globstar is enabled, so determine if this is a globstar segment
237
- let isGlobstar =
238
- starCount > 1 && // multiple "*"'s
239
- (prevChar === '/' || prevChar === undefined) && // from the start of the segment
240
- (nextChar === '/' || nextChar === undefined); // to the end of the segment
241
- if (isGlobstar) {
242
- // it's a globstar, so match zero or more path segments
243
- add(GLOBSTAR, {only:'regex'});
244
- add(GLOBSTAR_SEGMENT, {only:'path', last:true, split:true});
245
- i++; // move over the "/"
246
- } else {
247
- // it's not a globstar, so only match one path segment
248
- add(WILDCARD, {only:'regex'});
249
- add(WILDCARD_SEGMENT, {only:'path'});
250
- }
251
- }
252
- continue;
253
- }
254
-
255
- add(c);
256
- }
257
-
258
-
259
- // When regexp 'g' flag is specified don't
260
- // constrain the regular expression with ^ & $
261
- if (!flags.includes('g')) {
262
- regex = `^${regex}$`;
263
- segment = `^${segment}$`;
264
- if (filepath) path.regex = `^${path.regex}$`;
265
- }
266
-
267
- const result = {regex: new RegExp(regex, flags)};
268
-
269
- // Push the last segment
270
- if (filepath) {
271
- path.segments.push(new RegExp(segment, flags));
272
- path.regex = new RegExp(path.regex, flags);
273
- path.globstar = new RegExp(!flags.includes('g') ? `^${GLOBSTAR_SEGMENT}$` : GLOBSTAR_SEGMENT, flags);
274
- result.path = path;
275
- }
276
-
277
- return result;
278
- }
279
-
280
- var globrex_1 = globrex;
281
-
282
- const isWin = os.platform() === 'win32';
283
-
284
- const CHARS = { '{': '}', '(': ')', '[': ']'};
285
- const STRICT = /\\(.)|(^!|\*|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\)|(\\).|([@?!+*]\(.*\)))/;
286
- const RELAXED = /\\(.)|(^!|[*?{}()[\]]|\(\?)/;
287
-
288
- /**
289
- * Detect if a string cointains glob
290
- * @param {String} str Input string
291
- * @param {Object} [options] Configuration object
292
- * @param {Boolean} [options.strict=true] Use relaxed regex if true
293
- * @returns {Boolean} true if string contains glob
294
- */
295
- function isglob(str, { strict = true } = {}) {
296
- if (str === '') return false;
297
- let match, rgx = strict ? STRICT : RELAXED;
298
-
299
- while ((match = rgx.exec(str))) {
300
- if (match[2]) return true;
301
- let idx = match.index + match[0].length;
302
-
303
- // if an open bracket/brace/paren is escaped,
304
- // set the index to the next closing character
305
- let open = match[1];
306
- let close = open ? CHARS[open] : null;
307
- if (open && close) {
308
- let n = str.indexOf(close, idx);
309
- if (n !== -1) idx = n + 1;
310
- }
311
-
312
- str = str.slice(idx);
313
- }
314
- return false;
315
- }
316
-
317
-
318
- /**
319
- * Find the static part of a glob-path,
320
- * split path and return path part
321
- * @param {String} str Path/glob string
322
- * @returns {String} static path section of glob
323
- */
324
- function parent(str, { strict = false } = {}) {
325
- if (isWin && str.includes('/'))
326
- str = str.split('\\').join('/');
327
-
328
- // special case for strings ending in enclosure containing path separator
329
- if (/[\{\[].*[\/]*.*[\}\]]$/.test(str)) str += '/';
330
-
331
- // preserves full path in case of trailing path separator
332
- str += 'a';
333
-
334
- do {str = path.dirname(str);}
335
- while (isglob(str, {strict}) || /(^|[^\\])([\{\[]|\([^\)]+$)/.test(str));
336
-
337
- // remove escape chars and return result
338
- return str.replace(/\\([\*\?\|\[\]\(\)\{\}])/g, '$1');
339
- }
340
-
341
- /**
342
- * Parse a glob path, and split it by static/glob part
343
- * @param {String} pattern String path
344
- * @param {Object} [opts] Options
345
- * @param {Object} [opts.strict=false] Use strict parsing
346
- * @returns {Object} object with parsed path
347
- */
348
- function globalyzer(pattern, opts = {}) {
349
- let base = parent(pattern, opts);
350
- let isGlob = isglob(pattern, opts);
351
- let glob;
352
-
353
- if (base != '.') {
354
- glob = pattern.substr(base.length);
355
- if (glob.startsWith('/')) glob = glob.substr(1);
356
- } else {
357
- glob = pattern;
358
- }
359
-
360
- if (!isGlob) {
361
- base = path.dirname(pattern);
362
- glob = base !== '.' ? pattern.substr(base.length) : pattern;
363
- }
364
-
365
- if (glob.startsWith('./')) glob = glob.substr(2);
366
- if (glob.startsWith('/')) glob = glob.substr(1);
367
-
368
- return { base, glob, isGlob };
369
- }
370
-
371
-
372
- var src = globalyzer;
373
-
374
- const { join, resolve, relative } = path;
375
- const isHidden = /(^|[\\\/])\.[^\\\/\.]/g;
376
-
377
- let CACHE = {};
378
-
379
- function walk(output, prefix, lexer, opts, dirname='', level=0) {
380
- const rgx = lexer.segments[level];
381
- const dir = resolve(opts.cwd, prefix, dirname);
382
- const files = fs.readdirSync(dir);
383
- const { dot, filesOnly } = opts;
384
-
385
- let i=0, len=files.length, file;
386
- let fullpath, relpath, stats, isMatch;
387
-
388
- for (; i < len; i++) {
389
- fullpath = join(dir, file=files[i]);
390
- relpath = dirname ? join(dirname, file) : file;
391
- if (!dot && isHidden.test(relpath)) continue;
392
- isMatch = lexer.regex.test(relpath);
393
-
394
- if ((stats=CACHE[relpath]) === void 0) {
395
- CACHE[relpath] = stats = fs.lstatSync(fullpath);
396
- }
397
-
398
- if (!stats.isDirectory()) {
399
- isMatch && output.push(relative(opts.cwd, fullpath));
400
- continue;
401
- }
402
-
403
- if (rgx && !rgx.test(file)) continue;
404
- !filesOnly && isMatch && output.push(join(prefix, relpath));
405
-
406
- walk(output, prefix, lexer, opts, relpath, rgx && rgx.toString() !== lexer.globstar && level + 1);
407
- }
408
- }
409
-
410
- /**
411
- * Find files using bash-like globbing.
412
- * All paths are normalized compared to node-glob.
413
- * @param {String} str Glob string
414
- * @param {String} [options.cwd='.'] Current working directory
415
- * @param {Boolean} [options.dot=false] Include dotfile matches
416
- * @param {Boolean} [options.absolute=false] Return absolute paths
417
- * @param {Boolean} [options.filesOnly=false] Do not include folders if true
418
- * @param {Boolean} [options.flush=false] Reset cache object
419
- * @returns {Array} array containing matching files
420
- */
421
- var sync = function (str, opts={}) {
422
- if (!str) return [];
423
-
424
- let glob = src(str);
425
-
426
- opts.cwd = opts.cwd || '.';
427
-
428
- if (!glob.isGlob) {
429
- try {
430
- let resolved = resolve(opts.cwd, str);
431
- let dirent = fs.statSync(resolved);
432
- if (opts.filesOnly && !dirent.isFile()) return [];
433
-
434
- return opts.absolute ? [resolved] : [str];
435
- } catch (err) {
436
- if (err.code != 'ENOENT') throw err;
437
-
438
- return [];
439
- }
440
- }
441
-
442
- if (opts.flush) CACHE = {};
443
-
444
- let matches = [];
445
- const { path } = globrex_1(glob.glob, { filepath:true, globstar:true, extended:true });
446
-
447
- path.globstar = path.globstar.toString();
448
- walk(matches, glob.base, path, opts, '.', 0);
449
-
450
- return opts.absolute ? matches.map(x => resolve(opts.cwd, x)) : matches;
451
- };
452
-
453
- /** @param {string} html */
454
- function clean_html(html) {
455
- return html
456
- .replace(/<!\[CDATA\[[\s\S]*?\]\]>/gm, '')
457
- .replace(/(<script[\s\S]*?>)[\s\S]*?<\/script>/gm, '$1</' + 'script>')
458
- .replace(/(<style[\s\S]*?>)[\s\S]*?<\/style>/gm, '$1</' + 'style>')
459
- .replace(/<!--[\s\S]*?-->/gm, '');
460
- }
461
-
462
- /** @param {string} attrs */
463
- function get_href(attrs) {
464
- const match = /href\s*=\s*(?:"(.*?)"|'(.*?)'|([^\s>]*))/.exec(attrs);
465
- return match && (match[1] || match[2] || match[3]);
466
- }
467
-
468
- /** @param {string} attrs */
469
- function get_src(attrs) {
470
- const match = /src\s*=\s*(?:"(.*?)"|'(.*?)'|([^\s>]*))/.exec(attrs);
471
- return match && (match[1] || match[2] || match[3]);
472
- }
473
-
474
- /** @param {string} attrs */
475
- function get_srcset_urls(attrs) {
476
- const results = [];
477
- // Note that the srcset allows any ASCII whitespace, including newlines.
478
- const match = /srcset\s*=\s*(?:"(.*?)"|'(.*?)'|([^\s>]*))/s.exec(attrs);
479
- if (match) {
480
- const attr_content = match[1] || match[2] || match[3];
481
- // Parse the content of the srcset attribute.
482
- // The regexp is modelled after the srcset specs (https://html.spec.whatwg.org/multipage/images.html#srcset-attribute)
483
- // and should cover most reasonable cases.
484
- const regex = /\s*([^\s,]\S+[^\s,])\s*((?:\d+w)|(?:-?\d+(?:\.\d+)?(?:[eE]-?\d+)?x))?/gm;
485
- let sub_matches;
486
- while ((sub_matches = regex.exec(attr_content))) {
487
- results.push(sub_matches[1]);
488
- }
489
- }
490
- return results;
491
- }
492
-
493
- const OK = 2;
494
- const REDIRECT = 3;
495
-
496
- /** @param {{
497
- * cwd: string;
498
- * out: string;
499
- * log: import('../../types').Logger;
500
- * config: import('../../types').ValidatedConfig;
501
- * force: boolean; // disregard `export const prerender = true`
502
- * }} opts */
503
- async function prerender({ cwd, out, log, config, force }) {
504
- const dir = resolve$1(cwd, '.svelte/output');
505
-
506
- const seen = new Set();
507
- const seen_files = new Set();
508
-
509
- const server_root = resolve$1(dir);
510
-
511
- /** @type {import('../../types').App} */
512
- const app = await import(pathToFileURL(`${server_root}/server/app.js`).href);
513
-
514
- app.init({
515
- paths: config.kit.paths
516
- });
517
-
518
- /** @type {(status: number, path: string) => void} */
519
- const error = config.kit.prerender.force
520
- ? (status, path) => {
521
- log.error(`${status} ${path}`);
522
- }
523
- : (status, path) => {
524
- throw new Error(`${status} ${path}`);
525
- };
526
-
527
- /** @param {string} path */
528
- async function visit(path) {
529
- if (seen.has(path)) return;
530
- seen.add(path);
531
-
532
- const rendered = await app.render(
533
- {
534
- host: config.kit.host,
535
- method: 'GET',
536
- headers: {},
537
- path,
538
- body: null,
539
- query: new URLSearchParams()
540
- },
541
- {
542
- local: true,
543
- only_prerender: !force,
544
- get_static_file: (file) => readFileSync(join$1(config.kit.files.assets, file))
545
- }
546
- );
547
-
548
- if (rendered) {
549
- const response_type = Math.floor(rendered.status / 100);
550
- const headers = rendered.headers;
551
- const type = headers && headers['content-type'];
552
- const is_html = response_type === REDIRECT || type === 'text/html';
553
-
554
- const parts = path.split('/');
555
- if (is_html && parts[parts.length - 1] !== 'index.html') {
556
- parts.push('index.html');
557
- }
558
-
559
- const file = `${out}${parts.join('/')}`;
560
- mkdirp(dirname(file));
561
-
562
- if (response_type === REDIRECT) {
563
- const { location } = headers;
564
-
565
- log.warn(`${rendered.status} ${path} -> ${location}`);
566
- writeFileSync(file, `<meta http-equiv="refresh" content="0;url=${encodeURI(location)}">`);
567
-
568
- return;
569
- }
570
-
571
- if (response_type === OK) {
572
- log.info(`${rendered.status} ${path}`);
573
- writeFileSync(file, rendered.body); // TODO minify where possible?
574
- } else {
575
- error(rendered.status, path);
576
- }
577
-
578
- const { dependencies } = rendered;
579
-
580
- if (dependencies) {
581
- for (const path in dependencies) {
582
- const result = dependencies[path];
583
- const response_type = Math.floor(result.status / 100);
584
-
585
- const is_html = result.headers['content-type'] === 'text/html';
586
-
587
- const parts = path.split('/');
588
- if (is_html && parts[parts.length - 1] !== 'index.html') {
589
- parts.push('index.html');
590
- }
591
-
592
- const file = `${out}${parts.join('/')}`;
593
- mkdirp(dirname(file));
594
-
595
- writeFileSync(file, result.body);
596
-
597
- if (response_type === OK) {
598
- log.info(`${result.status} ${path}`);
599
- } else {
600
- error(result.status, path);
601
- }
602
- }
603
- }
604
-
605
- if (is_html && config.kit.prerender.crawl) {
606
- const cleaned = clean_html(rendered.body);
607
-
608
- let match;
609
- const pattern = /<(a|img|link|source)\s+([\s\S]+?)>/gm;
610
-
611
- while ((match = pattern.exec(cleaned))) {
612
- let hrefs = [];
613
- const element = match[1];
614
- const attrs = match[2];
615
-
616
- if (element === 'a' || element === 'link') {
617
- hrefs.push(get_href(attrs));
618
- } else {
619
- if (element === 'img') {
620
- hrefs.push(get_src(attrs));
621
- }
622
- hrefs.push(...get_srcset_urls(attrs));
623
- }
624
-
625
- hrefs = hrefs.filter(Boolean);
626
-
627
- for (const href of hrefs) {
628
- const resolved = resolve$2(path, href);
629
-
630
- if (resolved[0] !== '/') continue;
631
- if (seen_files.has(resolved)) continue;
632
-
633
- const parsed = parse(resolved);
634
-
635
- const file = parsed.pathname.replace(config.kit.paths.assets, '').slice(1);
636
-
637
- const file_exists =
638
- (file.startsWith(`${config.kit.appDir}/`) && existsSync(`${dir}/client/${file}`)) ||
639
- existsSync(`${out}/${file}`) ||
640
- existsSync(`${config.kit.files.assets}/${file}`) ||
641
- existsSync(`${config.kit.files.assets}/${file}/index.html`);
642
-
643
- if (file_exists) {
644
- seen_files.add(resolved);
645
- continue;
646
- }
647
-
648
- if (parsed.query) ;
649
-
650
- await visit(parsed.pathname.replace(config.kit.paths.base, ''));
651
- }
652
- }
653
- }
654
- }
655
- }
656
-
657
- for (const entry of config.kit.prerender.pages) {
658
- if (entry === '*') {
659
- // remove the prefix '.' from the extensions array
660
- const extensions = config.extensions.map((extension) => extension.slice(1));
661
- const extensions_regex = new RegExp(`\\.(${extensions.join('|')})$`);
662
- const entries = sync(`**/*.{${extensions.join(',')}}`, { cwd: config.kit.files.routes })
663
- .map((file) => {
664
- // support both windows and unix glob results
665
- const parts = file.split(sep);
666
-
667
- if (parts.some((part) => part[0] === '_' || /\[/.test(part))) {
668
- return null;
669
- }
670
-
671
- parts[parts.length - 1] = parts[parts.length - 1].replace(extensions_regex, '');
672
- if (parts[parts.length - 1] === 'index') parts.pop();
673
-
674
- if (parts[parts.length - 1] === '$layout' || parts[parts.length - 1] == '$error') {
675
- return null;
676
- }
677
-
678
- return `/${parts.join('/')}`;
679
- })
680
- .filter(Boolean);
681
-
682
- for (const entry of entries) {
683
- await visit(entry);
684
- }
685
- } else {
686
- await visit(entry);
687
- }
688
- }
689
- }
690
-
691
- class Builder {
692
- #cwd;
693
- #config;
694
-
695
- /** @param {{
696
- * cwd: string;
697
- * config: any; // TODO
698
- * log: import('../../types').Logger
699
- * }} opts */
700
- constructor({ cwd, config, log }) {
701
- this.#cwd = cwd;
702
- this.#config = config;
703
-
704
- this.log = log;
705
- }
706
-
707
- /** @param {string} dest */
708
- copy_client_files(dest) {
709
- copy(`${this.#cwd}/.svelte/output/client`, dest, (file) => file[0] !== '.');
710
- }
711
-
712
- /** @param {string} dest */
713
- copy_server_files(dest) {
714
- copy(`${this.#cwd}/.svelte/output/server`, dest, (file) => file[0] !== '.');
715
- }
716
-
717
- /** @param {string} dest */
718
- copy_static_files(dest) {
719
- copy(this.#config.kit.files.assets, dest);
720
- }
721
-
722
- /** @param {{ force: boolean, dest: string }} opts */
723
- async prerender({ force = false, dest }) {
724
- if (this.#config.kit.prerender.enabled) {
725
- await prerender({
726
- out: dest,
727
- force,
728
- cwd: this.#cwd,
729
- config: this.#config,
730
- log: this.log
731
- });
732
- }
733
- }
734
- }
735
-
736
- /**
737
- * @param {import('../../types').ValidatedConfig} config
738
- * @param {{ cwd?: string, verbose: boolean }} opts
739
- */
740
- async function adapt(config, { cwd = process.cwd(), verbose }) {
741
- if (!config.kit.adapter) {
742
- throw new Error('No adapter specified');
743
- }
744
-
745
- const [adapter, options] = config.kit.adapter;
746
-
747
- const log = logger({ verbose });
748
-
749
- console.log($.bold().cyan(`\n> Using ${adapter}`));
750
-
751
- const builder = new Builder({ cwd, config, log });
752
-
753
- const require = createRequire(import.meta.url);
754
- const resolved = require.resolve(adapter, { paths: [pathToFileURL(process.cwd()).href] });
755
- const fn = (await import(pathToFileURL(resolved).href)).default;
756
- await fn(builder, options);
757
-
758
- log.success('done');
759
- }
760
-
761
- export { adapt };