@johnhenry/sitefile 0.0.2 → 0.0.4
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.
- package/CHANGELOG.md +516 -0
- package/README.md +59 -9
- package/lib/src/archive-writers.d.ts +12 -2
- package/lib/src/archive-writers.js +53 -10
- package/lib/src/bake.d.ts +2 -0
- package/lib/src/bake.js +30 -1
- package/lib/src/bcrypt.d.ts +25 -0
- package/lib/src/bcrypt.js +201 -0
- package/lib/src/canonical.d.ts +19 -0
- package/lib/src/canonical.js +60 -0
- package/lib/src/car.d.ts +34 -0
- package/lib/src/car.js +203 -0
- package/lib/src/checklinks.js +8 -2
- package/lib/src/cli/bake.js +4 -3
- package/lib/src/cli/build-image.d.ts +1 -0
- package/lib/src/cli/build-image.js +1 -0
- package/lib/src/cli/common.js +4 -1
- package/lib/src/cli/hosts.d.ts +5 -0
- package/lib/src/cli/hosts.js +78 -0
- package/lib/src/cli/images.js +23 -5
- package/lib/src/cli/import-config.d.ts +2 -0
- package/lib/src/cli/import-config.js +56 -0
- package/lib/src/cli/index.d.ts +6 -1
- package/lib/src/cli/index.js +34 -2
- package/lib/src/cli/integrity.d.ts +2 -0
- package/lib/src/cli/integrity.js +77 -0
- package/lib/src/cli/network.d.ts +7 -0
- package/lib/src/cli/network.js +14 -3
- package/lib/src/cli/serve-keys.d.ts +39 -0
- package/lib/src/cli/serve-keys.js +106 -0
- package/lib/src/cli/serve-worker.js +119 -8
- package/lib/src/cli/servers.d.ts +130 -1
- package/lib/src/cli/servers.js +754 -72
- package/lib/src/cli/up.d.ts +2 -0
- package/lib/src/cli/up.js +193 -0
- package/lib/src/cli/watch.d.ts +14 -1
- package/lib/src/cli/watch.js +20 -3
- package/lib/src/cli.js +138 -18
- package/lib/src/csp.d.ts +17 -0
- package/lib/src/csp.js +52 -0
- package/lib/src/dictionary.d.ts +16 -0
- package/lib/src/dictionary.js +89 -0
- package/lib/src/epub.d.ts +5 -0
- package/lib/src/epub.js +113 -0
- package/lib/src/errors.d.ts +22 -9
- package/lib/src/errors.js +20 -1
- package/lib/src/executor.d.ts +31 -1
- package/lib/src/executor.js +231 -24
- package/lib/src/explain.js +33 -3
- package/lib/src/export-for.d.ts +42 -0
- package/lib/src/export-for.js +466 -0
- package/lib/src/export-formats.d.ts +2 -2
- package/lib/src/export-formats.js +52 -2
- package/lib/src/fingerprint.d.ts +3 -1
- package/lib/src/fingerprint.js +32 -5
- package/lib/src/host-config.d.ts +34 -0
- package/lib/src/host-config.js +645 -0
- package/lib/src/hosts.d.ts +47 -0
- package/lib/src/hosts.js +106 -0
- package/lib/src/hreflang.d.ts +25 -0
- package/lib/src/hreflang.js +72 -0
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/integrity.d.ts +115 -0
- package/lib/src/integrity.js +273 -0
- package/lib/src/language/ast.d.ts +126 -3
- package/lib/src/language/ast.js +7 -1
- package/lib/src/language/parser.js +189 -7
- package/lib/src/language/validate.js +24 -0
- package/lib/src/links.d.ts +47 -0
- package/lib/src/links.js +289 -3
- package/lib/src/lint.d.ts +1 -1
- package/lib/src/lint.js +26 -1
- package/lib/src/mime-data.d.ts +2 -0
- package/lib/src/mime-data.js +92 -0
- package/lib/src/oci.d.ts +20 -2
- package/lib/src/oci.js +70 -28
- package/lib/src/outdated.d.ts +3 -0
- package/lib/src/outdated.js +4 -4
- package/lib/src/planner.d.ts +87 -2
- package/lib/src/planner.js +189 -8
- package/lib/src/plugins/cache.d.ts +11 -0
- package/lib/src/plugins/cache.js +29 -0
- package/lib/src/plugins/host.d.ts +51 -2
- package/lib/src/plugins/host.js +141 -16
- package/lib/src/plugins/wasm.js +1 -3
- package/lib/src/portable.d.ts +8 -0
- package/lib/src/portable.js +47 -0
- package/lib/src/precache.d.ts +33 -0
- package/lib/src/precache.js +75 -0
- package/lib/src/precompress.d.ts +19 -0
- package/lib/src/precompress.js +35 -0
- package/lib/src/qr.d.ts +18 -0
- package/lib/src/qr.js +372 -0
- package/lib/src/registry-ops.js +4 -2
- package/lib/src/reload-client.d.ts +2 -0
- package/lib/src/reload-client.js +419 -0
- package/lib/src/resources/archive.d.ts +37 -1
- package/lib/src/resources/archive.js +353 -71
- package/lib/src/resources/convert.js +3 -1
- package/lib/src/resources/https.d.ts +9 -1
- package/lib/src/resources/https.js +36 -0
- package/lib/src/resources/network.d.ts +25 -3
- package/lib/src/resources/network.js +77 -6
- package/lib/src/secrets.d.ts +12 -3
- package/lib/src/secrets.js +18 -5
- package/lib/src/serve-auth.d.ts +33 -0
- package/lib/src/serve-auth.js +120 -0
- package/lib/src/serve-rules.d.ts +83 -7
- package/lib/src/serve-rules.js +264 -53
- package/lib/src/server.d.ts +529 -11
- package/lib/src/server.js +1439 -57
- package/lib/src/servers-file.d.ts +36 -0
- package/lib/src/servers-file.js +101 -0
- package/lib/src/servers.d.ts +115 -7
- package/lib/src/servers.js +151 -29
- package/lib/src/single-file.d.ts +12 -0
- package/lib/src/single-file.js +147 -0
- package/lib/src/site.d.ts +58 -0
- package/lib/src/site.js +216 -5
- package/lib/src/store.js +9 -5
- package/lib/src/swbn.d.ts +10 -0
- package/lib/src/swbn.js +86 -0
- package/lib/src/toml.d.ts +17 -0
- package/lib/src/toml.js +323 -0
- package/lib/src/wacz.d.ts +6 -0
- package/lib/src/wacz.js +96 -0
- package/lib/src/warc.d.ts +28 -0
- package/lib/src/warc.js +252 -0
- package/lib/src/watch.d.ts +12 -1
- package/lib/src/watch.js +67 -1
- package/lib/src/wbn.d.ts +9 -1
- package/lib/src/wbn.js +23 -33
- package/lib/src/zstd.d.ts +4 -0
- package/lib/src/zstd.js +328 -0
- package/package.json +1 -1
package/lib/src/links.js
CHANGED
|
@@ -137,7 +137,7 @@ function lineIndex(text) {
|
|
|
137
137
|
}
|
|
138
138
|
function collector(text, out) {
|
|
139
139
|
const lineAt = lineIndex(text);
|
|
140
|
-
return (start, end, url, css) => out.push({ start, end, raw: text.slice(start, end), url, line: lineAt(start), css });
|
|
140
|
+
return (start, end, url, css, element) => out.push({ start, end, raw: text.slice(start, end), url, line: lineAt(start), css, ...(element !== undefined ? { element } : {}) });
|
|
141
141
|
}
|
|
142
142
|
// ---------------------------------------------------------------- CSS
|
|
143
143
|
/** The end of a CSS string starting at the quote `at`: the index of its closing quote, or undefined (newline or end of input). */
|
|
@@ -314,14 +314,14 @@ export function scanHtml(text) {
|
|
|
314
314
|
}
|
|
315
315
|
if (name === 'srcset' || name === 'imagesrcset') {
|
|
316
316
|
for (const [a, b] of srcsetUrls(value))
|
|
317
|
-
push(start + a, start + b, decodeHtmlText(value.slice(a, b)), false);
|
|
317
|
+
push(start + a, start + b, decodeHtmlText(value.slice(a, b)), false, `${tag} ${name}`);
|
|
318
318
|
return;
|
|
319
319
|
}
|
|
320
320
|
const url = name === 'src' || name === 'poster' || name === 'xlink:href' || (name === 'href' && tag !== 'base') || (name === 'data' && tag === 'object');
|
|
321
321
|
if (!url)
|
|
322
322
|
return;
|
|
323
323
|
const [a, b] = trimWs(value);
|
|
324
|
-
push(start + a, start + b, trimmed(decodeHtmlText(value.slice(a, b))), false);
|
|
324
|
+
push(start + a, start + b, trimmed(decodeHtmlText(value.slice(a, b))), false, `${tag} ${name}`);
|
|
325
325
|
};
|
|
326
326
|
let i = 0;
|
|
327
327
|
while (i < n) {
|
|
@@ -398,6 +398,292 @@ export function scanHtml(text) {
|
|
|
398
398
|
}
|
|
399
399
|
return out;
|
|
400
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* The start tags of an HTML text that load a script or stylesheet SRI applies to: `<script src>` and
|
|
403
|
+
* `<link href>` whose `rel` has the token `stylesheet` or `modulepreload` (ASCII case-insensitive).
|
|
404
|
+
* Tags that already have an `integrity` attribute are left out. Comments, declarations and raw text are
|
|
405
|
+
* skipped as in {@link scanHtml}; when an attribute is given twice, the first one counts.
|
|
406
|
+
*/
|
|
407
|
+
export function integrityTags(text) {
|
|
408
|
+
const out = [];
|
|
409
|
+
const n = text.length;
|
|
410
|
+
let i = 0;
|
|
411
|
+
while (i < n) {
|
|
412
|
+
const lt = text.indexOf('<', i);
|
|
413
|
+
if (lt === -1)
|
|
414
|
+
break;
|
|
415
|
+
i = lt;
|
|
416
|
+
const next = text[i + 1];
|
|
417
|
+
if (text.startsWith('<!--', i)) {
|
|
418
|
+
const j = text.indexOf('-->', i + 4);
|
|
419
|
+
i = j === -1 ? n : j + 3;
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (next === '!' || next === '?' || next === '/') {
|
|
423
|
+
const j = text.indexOf('>', i + 2);
|
|
424
|
+
i = j === -1 ? n : j + 1;
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
if (!isAlpha(next)) {
|
|
428
|
+
i++;
|
|
429
|
+
continue;
|
|
430
|
+
}
|
|
431
|
+
let j = i + 1;
|
|
432
|
+
while (j < n && !isWs(text[j]) && text[j] !== '/' && text[j] !== '>')
|
|
433
|
+
j++;
|
|
434
|
+
const tag = lowerAscii(text.slice(i + 1, j));
|
|
435
|
+
const at = j;
|
|
436
|
+
i = j;
|
|
437
|
+
const attrs = new Map();
|
|
438
|
+
for (;;) {
|
|
439
|
+
while (i < n && (isWs(text[i]) || text[i] === '/'))
|
|
440
|
+
i++;
|
|
441
|
+
if (i >= n)
|
|
442
|
+
break;
|
|
443
|
+
if (text[i] === '>') {
|
|
444
|
+
i++;
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
const nameStart = i;
|
|
448
|
+
i++;
|
|
449
|
+
while (i < n && !isWs(text[i]) && text[i] !== '/' && text[i] !== '>' && text[i] !== '=')
|
|
450
|
+
i++;
|
|
451
|
+
const name = lowerAscii(text.slice(nameStart, i));
|
|
452
|
+
let k = i;
|
|
453
|
+
while (k < n && isWs(text[k]))
|
|
454
|
+
k++;
|
|
455
|
+
if (text[k] !== '=') {
|
|
456
|
+
if (!attrs.has(name))
|
|
457
|
+
attrs.set(name, '');
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
i = k + 1;
|
|
461
|
+
while (i < n && isWs(text[i]))
|
|
462
|
+
i++;
|
|
463
|
+
const q = text[i];
|
|
464
|
+
let start;
|
|
465
|
+
let end;
|
|
466
|
+
if (q === '"' || q === "'") {
|
|
467
|
+
start = i + 1;
|
|
468
|
+
const close = text.indexOf(q, start);
|
|
469
|
+
end = close === -1 ? n : close;
|
|
470
|
+
i = close === -1 ? n : close + 1;
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
start = i;
|
|
474
|
+
while (i < n && !isWs(text[i]) && text[i] !== '>')
|
|
475
|
+
i++;
|
|
476
|
+
end = i;
|
|
477
|
+
}
|
|
478
|
+
if (!attrs.has(name))
|
|
479
|
+
attrs.set(name, text.slice(start, end));
|
|
480
|
+
}
|
|
481
|
+
if (!attrs.has('integrity')) {
|
|
482
|
+
let raw;
|
|
483
|
+
if (tag === 'script')
|
|
484
|
+
raw = attrs.get('src');
|
|
485
|
+
else if (tag === 'link') {
|
|
486
|
+
const rel = lowerAscii(decodeHtmlText(attrs.get('rel') ?? '')).split(/[ \t\n\r\f]+/);
|
|
487
|
+
if (rel.includes('stylesheet') || rel.includes('modulepreload'))
|
|
488
|
+
raw = attrs.get('href');
|
|
489
|
+
}
|
|
490
|
+
if (raw !== undefined) {
|
|
491
|
+
const [a, b] = trimWs(raw);
|
|
492
|
+
const url = trimmed(decodeHtmlText(raw.slice(a, b)));
|
|
493
|
+
if (url !== '')
|
|
494
|
+
out.push({ at, url });
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
if (RAW_TEXT.has(tag))
|
|
498
|
+
i = indexOfCloseTag(text, tag, i);
|
|
499
|
+
}
|
|
500
|
+
return out;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Where a canonical link goes in an HTML text: the offset of its first `</head` end tag, `'has'` when a
|
|
504
|
+
* `<link>` whose `rel` has the token `canonical` (ASCII case-insensitive) comes before it, or undefined when
|
|
505
|
+
* there is no `</head>`. Comments, declarations and raw text are skipped as in {@link scanHtml}.
|
|
506
|
+
*/
|
|
507
|
+
export function canonicalSlot(text) {
|
|
508
|
+
const h = headLinks(text);
|
|
509
|
+
return h.canonical ? 'has' : h.at;
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* Where links go in a page's head and which it already has (ASCII case-insensitive `rel` tokens). Comments,
|
|
513
|
+
* declarations and raw text are skipped as in {@link scanHtml}.
|
|
514
|
+
*/
|
|
515
|
+
export function headLinks(text) {
|
|
516
|
+
let canonical = false;
|
|
517
|
+
let hreflang = false;
|
|
518
|
+
const n = text.length;
|
|
519
|
+
let i = 0;
|
|
520
|
+
while (i < n) {
|
|
521
|
+
const lt = text.indexOf('<', i);
|
|
522
|
+
if (lt === -1)
|
|
523
|
+
break;
|
|
524
|
+
i = lt;
|
|
525
|
+
const next = text[i + 1];
|
|
526
|
+
if (text.startsWith('<!--', i)) {
|
|
527
|
+
const j = text.indexOf('-->', i + 4);
|
|
528
|
+
i = j === -1 ? n : j + 3;
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
if (next === '/') {
|
|
532
|
+
const end = i + 6;
|
|
533
|
+
if (lowerAscii(text.slice(i + 2, end)) === 'head' && (end >= n || isWs(text[end]) || text[end] === '/' || text[end] === '>'))
|
|
534
|
+
return { at: i, canonical, hreflang };
|
|
535
|
+
}
|
|
536
|
+
if (next === '!' || next === '?' || next === '/') {
|
|
537
|
+
const j = text.indexOf('>', i + 2);
|
|
538
|
+
i = j === -1 ? n : j + 1;
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
if (!isAlpha(next)) {
|
|
542
|
+
i++;
|
|
543
|
+
continue;
|
|
544
|
+
}
|
|
545
|
+
let j = i + 1;
|
|
546
|
+
while (j < n && !isWs(text[j]) && text[j] !== '/' && text[j] !== '>')
|
|
547
|
+
j++;
|
|
548
|
+
const tag = lowerAscii(text.slice(i + 1, j));
|
|
549
|
+
i = j;
|
|
550
|
+
let rel;
|
|
551
|
+
let lang = false;
|
|
552
|
+
for (;;) {
|
|
553
|
+
while (i < n && (isWs(text[i]) || text[i] === '/'))
|
|
554
|
+
i++;
|
|
555
|
+
if (i >= n)
|
|
556
|
+
break;
|
|
557
|
+
if (text[i] === '>') {
|
|
558
|
+
i++;
|
|
559
|
+
break;
|
|
560
|
+
}
|
|
561
|
+
const nameStart = i;
|
|
562
|
+
i++;
|
|
563
|
+
while (i < n && !isWs(text[i]) && text[i] !== '/' && text[i] !== '>' && text[i] !== '=')
|
|
564
|
+
i++;
|
|
565
|
+
const name = lowerAscii(text.slice(nameStart, i));
|
|
566
|
+
if (name === 'hreflang')
|
|
567
|
+
lang = true;
|
|
568
|
+
let k = i;
|
|
569
|
+
while (k < n && isWs(text[k]))
|
|
570
|
+
k++;
|
|
571
|
+
if (text[k] !== '=')
|
|
572
|
+
continue;
|
|
573
|
+
i = k + 1;
|
|
574
|
+
while (i < n && isWs(text[i]))
|
|
575
|
+
i++;
|
|
576
|
+
const q = text[i];
|
|
577
|
+
let start;
|
|
578
|
+
let end;
|
|
579
|
+
if (q === '"' || q === "'") {
|
|
580
|
+
start = i + 1;
|
|
581
|
+
const close = text.indexOf(q, start);
|
|
582
|
+
end = close === -1 ? n : close;
|
|
583
|
+
i = close === -1 ? n : close + 1;
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
start = i;
|
|
587
|
+
while (i < n && !isWs(text[i]) && text[i] !== '>')
|
|
588
|
+
i++;
|
|
589
|
+
end = i;
|
|
590
|
+
}
|
|
591
|
+
if (name === 'rel' && rel === undefined)
|
|
592
|
+
rel = text.slice(start, end);
|
|
593
|
+
}
|
|
594
|
+
if (tag === 'link' && rel !== undefined) {
|
|
595
|
+
const tokens = lowerAscii(decodeHtmlText(rel)).split(/[ \t\n\r\f]+/);
|
|
596
|
+
if (tokens.includes('canonical'))
|
|
597
|
+
canonical = true;
|
|
598
|
+
if (lang && tokens.includes('alternate'))
|
|
599
|
+
hreflang = true;
|
|
600
|
+
}
|
|
601
|
+
if (RAW_TEXT.has(tag))
|
|
602
|
+
i = indexOfCloseTag(text, tag, i);
|
|
603
|
+
}
|
|
604
|
+
return { at: undefined, canonical, hreflang };
|
|
605
|
+
}
|
|
606
|
+
/** The inline scripts and styles of an HTML text (comments and other raw text skipped as in {@link scanHtml}). */
|
|
607
|
+
export function inlineBlocks(text) {
|
|
608
|
+
const scripts = [];
|
|
609
|
+
const styles = [];
|
|
610
|
+
let headEnd;
|
|
611
|
+
const n = text.length;
|
|
612
|
+
let i = 0;
|
|
613
|
+
while (i < n) {
|
|
614
|
+
const lt = text.indexOf('<', i);
|
|
615
|
+
if (lt === -1)
|
|
616
|
+
break;
|
|
617
|
+
i = lt;
|
|
618
|
+
const next = text[i + 1];
|
|
619
|
+
if (text.startsWith('<!--', i)) {
|
|
620
|
+
const j = text.indexOf('-->', i + 4);
|
|
621
|
+
i = j === -1 ? n : j + 3;
|
|
622
|
+
continue;
|
|
623
|
+
}
|
|
624
|
+
if (next === '!' || next === '?' || next === '/') {
|
|
625
|
+
const j = text.indexOf('>', i + 2);
|
|
626
|
+
i = j === -1 ? n : j + 1;
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
if (!isAlpha(next)) {
|
|
630
|
+
i++;
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
let j = i + 1;
|
|
634
|
+
while (j < n && !isWs(text[j]) && text[j] !== '/' && text[j] !== '>')
|
|
635
|
+
j++;
|
|
636
|
+
const tag = lowerAscii(text.slice(i + 1, j));
|
|
637
|
+
i = j;
|
|
638
|
+
let src = false;
|
|
639
|
+
let closed = false;
|
|
640
|
+
for (;;) {
|
|
641
|
+
while (i < n && (isWs(text[i]) || text[i] === '/'))
|
|
642
|
+
i++;
|
|
643
|
+
if (i >= n)
|
|
644
|
+
break;
|
|
645
|
+
if (text[i] === '>') {
|
|
646
|
+
i++;
|
|
647
|
+
closed = true;
|
|
648
|
+
break;
|
|
649
|
+
}
|
|
650
|
+
const nameStart = i;
|
|
651
|
+
i++;
|
|
652
|
+
while (i < n && !isWs(text[i]) && text[i] !== '/' && text[i] !== '>' && text[i] !== '=')
|
|
653
|
+
i++;
|
|
654
|
+
if (lowerAscii(text.slice(nameStart, i)) === 'src')
|
|
655
|
+
src = true;
|
|
656
|
+
let k = i;
|
|
657
|
+
while (k < n && isWs(text[k]))
|
|
658
|
+
k++;
|
|
659
|
+
if (text[k] !== '=')
|
|
660
|
+
continue;
|
|
661
|
+
i = k + 1;
|
|
662
|
+
while (i < n && isWs(text[i]))
|
|
663
|
+
i++;
|
|
664
|
+
const q = text[i];
|
|
665
|
+
if (q === '"' || q === "'") {
|
|
666
|
+
const close = text.indexOf(q, i + 1);
|
|
667
|
+
i = close === -1 ? n : close + 1;
|
|
668
|
+
}
|
|
669
|
+
else {
|
|
670
|
+
while (i < n && !isWs(text[i]) && text[i] !== '>')
|
|
671
|
+
i++;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
if (tag === 'head' && headEnd === undefined && closed)
|
|
675
|
+
headEnd = i;
|
|
676
|
+
if (RAW_TEXT.has(tag)) {
|
|
677
|
+
const close = indexOfCloseTag(text, tag, i);
|
|
678
|
+
if (closed && tag === 'script' && !src)
|
|
679
|
+
scripts.push(text.slice(i, close));
|
|
680
|
+
if (closed && tag === 'style')
|
|
681
|
+
styles.push(text.slice(i, close));
|
|
682
|
+
i = close;
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
return { scripts, styles, ...(headEnd !== undefined ? { headEnd } : {}) };
|
|
686
|
+
}
|
|
401
687
|
/** Where `</tag` (ASCII case-insensitive, followed by whitespace, `/` or `>`) starts at or after `from`; the end of the text if nowhere. */
|
|
402
688
|
function indexOfCloseTag(text, tag, from) {
|
|
403
689
|
let i = from;
|
package/lib/src/lint.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Program } from './language/ast.js';
|
|
2
2
|
import { type Plan } from './planner.js';
|
|
3
3
|
/** Every rule, in the order warnings of one line are reported. */
|
|
4
|
-
export declare const LINT_RULES: readonly ['unused-name', 'unpinned-import', 'unpinned-image', 'render-escape', 'sitemap-order', 'shadowed-write'];
|
|
4
|
+
export declare const LINT_RULES: readonly ['unused-name', 'unpinned-import', 'unpinned-image', 'render-escape', 'sitemap-order', 'shadowed-write', 'serve-ignored'];
|
|
5
5
|
export type LintRule = (typeof LINT_RULES)[number];
|
|
6
6
|
/**
|
|
7
7
|
* Lint a validated program and its plan. `source` is the Sitefile text (for comments),
|
package/lib/src/lint.js
CHANGED
|
@@ -5,8 +5,9 @@ import { templateNames } from './executor.js';
|
|
|
5
5
|
import { importedStageRefs } from './planner.js';
|
|
6
6
|
import { parseRenderTemplate } from './render.js';
|
|
7
7
|
import { parseRef } from './ref.js';
|
|
8
|
+
import { parseHeaders, parseRedirects } from './serve-rules.js';
|
|
8
9
|
/** Every rule, in the order warnings of one line are reported. */
|
|
9
|
-
export const LINT_RULES = ['unused-name', 'unpinned-import', 'unpinned-image', 'render-escape', 'sitemap-order', 'shadowed-write'];
|
|
10
|
+
export const LINT_RULES = ['unused-name', 'unpinned-import', 'unpinned-image', 'render-escape', 'sitemap-order', 'shadowed-write', 'serve-ignored'];
|
|
10
11
|
/** Import kinds a RENDER template can read (so a template file may use them). */
|
|
11
12
|
const VALUE_KINDS = new Set(['text', 'json', 'yaml', 'csv', 'markdown', 'wbn', 'html']);
|
|
12
13
|
/** `# sitefile-lint: …` (name ASCII case-insensitive): group 1 is the rest of the comment. */
|
|
@@ -215,6 +216,30 @@ export function lint(program, plan, source, disabled = []) {
|
|
|
215
216
|
last.set(path, op.span.line);
|
|
216
217
|
}
|
|
217
218
|
}
|
|
219
|
+
// ---- serve-ignored: a REDIRECT or HEADER line `sitefile serve` would ignore (operands with ${…} are skipped).
|
|
220
|
+
const literal = (op) => (op.parts.every((p) => p.kind === 'text') ? written(op) : undefined);
|
|
221
|
+
for (const ins of program.instructions) {
|
|
222
|
+
let text;
|
|
223
|
+
let what = '';
|
|
224
|
+
let ignored;
|
|
225
|
+
if (ins.kind === 'REDIRECT') {
|
|
226
|
+
const [from, to] = [literal(ins.from), literal(ins.to)];
|
|
227
|
+
if (from === undefined || to === undefined)
|
|
228
|
+
continue;
|
|
229
|
+
[text, what] = [`${from} ${to} ${ins.status}`, `REDIRECT ${from} ${to}`];
|
|
230
|
+
ignored = parseRedirects(text).ignored[0]?.reason;
|
|
231
|
+
}
|
|
232
|
+
else if (ins.kind === 'HEADER') {
|
|
233
|
+
const parts = [ins.pattern, ins.name, ...ins.value].map(literal);
|
|
234
|
+
if (parts.some((p) => p === undefined))
|
|
235
|
+
continue;
|
|
236
|
+
const [pattern, name, ...value] = parts;
|
|
237
|
+
what = `HEADER ${pattern} ${name}`;
|
|
238
|
+
ignored = parseHeaders(`${pattern}\n ${name}: ${value.join(' ')}\n`).ignored[0]?.reason;
|
|
239
|
+
}
|
|
240
|
+
if (ignored !== undefined)
|
|
241
|
+
report(ins.span.line, 'serve-ignored', `sitefile serve ignores the line ${what} writes: ${ignored}`);
|
|
242
|
+
}
|
|
218
243
|
const kept = found.filter((f) => f.rule === 'lint-comment' || !(off.has('all') || off.has(f.rule) || offPerLine.get(f.line)?.has('all') || offPerLine.get(f.line)?.has(f.rule)));
|
|
219
244
|
// Stable: by line, then in the order the rules ran.
|
|
220
245
|
const sorted = kept.map((f, i) => ({ f, i })).sort((a, b) => a.f.line - b.f.line || a.i - b.i);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// GENERATED by tools/gen-mime.mjs; do not edit.
|
|
2
|
+
// Content types for serve and Web Bundle export: exact well-known paths without an extension first, then
|
|
3
|
+
// the lowercase file extension (7 + 75 entries, each list sorted).
|
|
4
|
+
// prettier-ignore
|
|
5
|
+
export const WELL_KNOWN_TYPES = [
|
|
6
|
+
["/.well-known/apple-app-site-association", "application/json; charset=utf-8"],
|
|
7
|
+
["/.well-known/host-meta", "application/xrd+xml; charset=utf-8"],
|
|
8
|
+
["/.well-known/nodeinfo", "application/json; charset=utf-8"],
|
|
9
|
+
["/.well-known/oauth-authorization-server", "application/json; charset=utf-8"],
|
|
10
|
+
["/.well-known/openid-configuration", "application/json; charset=utf-8"],
|
|
11
|
+
["/.well-known/webfinger", "application/jrd+json; charset=utf-8"],
|
|
12
|
+
["/apple-app-site-association", "application/json; charset=utf-8"],
|
|
13
|
+
];
|
|
14
|
+
// prettier-ignore
|
|
15
|
+
export const MIME_TYPES = [
|
|
16
|
+
["aac", "audio/aac"],
|
|
17
|
+
["apng", "image/apng"],
|
|
18
|
+
["atom", "application/atom+xml; charset=utf-8"],
|
|
19
|
+
["avif", "image/avif"],
|
|
20
|
+
["bmp", "image/bmp"],
|
|
21
|
+
["cjs", "text/javascript; charset=utf-8"],
|
|
22
|
+
["css", "text/css; charset=utf-8"],
|
|
23
|
+
["csv", "text/csv; charset=utf-8"],
|
|
24
|
+
["eot", "application/vnd.ms-fontobject"],
|
|
25
|
+
["epub", "application/epub+zip"],
|
|
26
|
+
["flac", "audio/flac"],
|
|
27
|
+
["geojson", "application/geo+json; charset=utf-8"],
|
|
28
|
+
["gif", "image/gif"],
|
|
29
|
+
["glb", "model/gltf-binary"],
|
|
30
|
+
["gltf", "model/gltf+json; charset=utf-8"],
|
|
31
|
+
["gz", "application/gzip"],
|
|
32
|
+
["heic", "image/heic"],
|
|
33
|
+
["heif", "image/heif"],
|
|
34
|
+
["htm", "text/html; charset=utf-8"],
|
|
35
|
+
["html", "text/html; charset=utf-8"],
|
|
36
|
+
["ico", "image/x-icon"],
|
|
37
|
+
["ics", "text/calendar; charset=utf-8"],
|
|
38
|
+
["jpeg", "image/jpeg"],
|
|
39
|
+
["jpg", "image/jpeg"],
|
|
40
|
+
["js", "text/javascript; charset=utf-8"],
|
|
41
|
+
["json", "application/json; charset=utf-8"],
|
|
42
|
+
["jsonld", "application/ld+json; charset=utf-8"],
|
|
43
|
+
["jxl", "image/jxl"],
|
|
44
|
+
["m3u8", "application/vnd.apple.mpegurl"],
|
|
45
|
+
["m4a", "audio/mp4"],
|
|
46
|
+
["m4v", "video/mp4"],
|
|
47
|
+
["map", "application/json; charset=utf-8"],
|
|
48
|
+
["markdown", "text/markdown; charset=utf-8"],
|
|
49
|
+
["md", "text/markdown; charset=utf-8"],
|
|
50
|
+
["mjs", "text/javascript; charset=utf-8"],
|
|
51
|
+
["mkv", "video/x-matroska"],
|
|
52
|
+
["mov", "video/quicktime"],
|
|
53
|
+
["mp3", "audio/mpeg"],
|
|
54
|
+
["mp4", "video/mp4"],
|
|
55
|
+
["mpd", "application/dash+xml; charset=utf-8"],
|
|
56
|
+
["ndjson", "application/x-ndjson; charset=utf-8"],
|
|
57
|
+
["oga", "audio/ogg"],
|
|
58
|
+
["ogg", "audio/ogg"],
|
|
59
|
+
["ogv", "video/ogg"],
|
|
60
|
+
["opus", "audio/ogg"],
|
|
61
|
+
["otf", "font/otf"],
|
|
62
|
+
["pdf", "application/pdf"],
|
|
63
|
+
["png", "image/png"],
|
|
64
|
+
["rss", "application/rss+xml; charset=utf-8"],
|
|
65
|
+
["svg", "image/svg+xml; charset=utf-8"],
|
|
66
|
+
["tar", "application/x-tar"],
|
|
67
|
+
["tif", "image/tiff"],
|
|
68
|
+
["tiff", "image/tiff"],
|
|
69
|
+
["toml", "application/toml; charset=utf-8"],
|
|
70
|
+
["tsv", "text/tab-separated-values; charset=utf-8"],
|
|
71
|
+
["ttc", "font/collection"],
|
|
72
|
+
["ttf", "font/ttf"],
|
|
73
|
+
["txt", "text/plain; charset=utf-8"],
|
|
74
|
+
["vtt", "text/vtt; charset=utf-8"],
|
|
75
|
+
["wasm", "application/wasm"],
|
|
76
|
+
["wav", "audio/wav"],
|
|
77
|
+
["wbn", "application/webbundle"],
|
|
78
|
+
["weba", "audio/webm"],
|
|
79
|
+
["webm", "video/webm"],
|
|
80
|
+
["webmanifest", "application/manifest+json; charset=utf-8"],
|
|
81
|
+
["webp", "image/webp"],
|
|
82
|
+
["woff", "font/woff"],
|
|
83
|
+
["woff2", "font/woff2"],
|
|
84
|
+
["xhtml", "application/xhtml+xml; charset=utf-8"],
|
|
85
|
+
["xml", "application/xml; charset=utf-8"],
|
|
86
|
+
["xsl", "application/xml; charset=utf-8"],
|
|
87
|
+
["xslt", "application/xslt+xml; charset=utf-8"],
|
|
88
|
+
["yaml", "application/yaml; charset=utf-8"],
|
|
89
|
+
["yml", "application/yaml; charset=utf-8"],
|
|
90
|
+
["zip", "application/zip"],
|
|
91
|
+
];
|
|
92
|
+
//# sourceMappingURL=mime-data.js.map
|
package/lib/src/oci.d.ts
CHANGED
|
@@ -39,7 +39,11 @@ export declare const ANN: {
|
|
|
39
39
|
readonly files: 'dev.sitefile.files';
|
|
40
40
|
readonly size: 'dev.sitefile.size';
|
|
41
41
|
readonly stored: 'dev.sitefile.created';
|
|
42
|
+
/** The number of site layers (`--oci-layers`, issue #214); absent means one. */
|
|
43
|
+
readonly layers: 'dev.sitefile.layers';
|
|
42
44
|
};
|
|
45
|
+
/** Most site layers `--oci-layers` accepts. */
|
|
46
|
+
export declare const MAX_OCI_LAYERS = 64;
|
|
43
47
|
export interface OciOptions {
|
|
44
48
|
/** Where the files live inside the layer. Default /srv/www. */
|
|
45
49
|
readonly root?: string | undefined;
|
|
@@ -60,6 +64,11 @@ export interface OciOptions {
|
|
|
60
64
|
readonly base?: BaseImage | undefined;
|
|
61
65
|
/** Site layer encoding: gzip (default, `tar+gzip`) or none (plain `tar`). Base layers are kept as they are. */
|
|
62
66
|
readonly compression?: OciCompression | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Split the site's files over this many layers (default 1, at most {@link MAX_OCI_LAYERS}), by a hash
|
|
69
|
+
* of each path, so a push after a small change uploads only the layers that changed (issue #214).
|
|
70
|
+
*/
|
|
71
|
+
readonly layers?: number | undefined;
|
|
63
72
|
}
|
|
64
73
|
/** A resolved base image: one platform manifest, its config and layers. */
|
|
65
74
|
export interface BaseImage {
|
|
@@ -89,7 +98,11 @@ export interface OciImage {
|
|
|
89
98
|
readonly root: string;
|
|
90
99
|
/** Layers below the site layer (from BASE), already normalized to OCI media types. Empty otherwise. */
|
|
91
100
|
readonly baseLayers: readonly Descriptor[];
|
|
101
|
+
/** With `layers` > 1: the site layers after the first (`layerBytes`), by digest, in layer order. */
|
|
102
|
+
readonly extraLayers?: ReadonlyMap<string, Uint8Array>;
|
|
92
103
|
}
|
|
104
|
+
/** The site layer (0-based, of `n`) a file belongs to: the first 4 bytes of SHA-256 of its path, mod n. */
|
|
105
|
+
export declare function layerOf(path: string, n: number): number;
|
|
93
106
|
/** JSON with sorted keys and no whitespace. */
|
|
94
107
|
export declare function canonicalJson(v: unknown): string;
|
|
95
108
|
export declare function parsePlatform(p: string | undefined): {
|
|
@@ -128,7 +141,7 @@ export declare function blobPathOf(digest: string): string;
|
|
|
128
141
|
* `referrers` (attestations, `build --provenance/--sbom`) are listed in index.json after the image,
|
|
129
142
|
* without a name, and their blobs are included.
|
|
130
143
|
*/
|
|
131
|
-
export declare function layoutTree(img: Pick<OciImage, 'manifestBytes' | 'manifestDigest' | 'configBytes' | 'configDigest' | 'layerBytes' | 'layerDigest'>, refName?: string,
|
|
144
|
+
export declare function layoutTree(img: Pick<OciImage, 'manifestBytes' | 'manifestDigest' | 'configBytes' | 'configDigest' | 'layerBytes' | 'layerDigest' | 'extraLayers'>, refName?: string,
|
|
132
145
|
/** Blobs of the layers below the site layer (digest -> bytes), for images built on a BASE. */
|
|
133
146
|
baseBlobs?: ReadonlyMap<string, Uint8Array>, referrers?: readonly Referrer[]): Tree;
|
|
134
147
|
/** Deterministic tar of {@link layoutTree}: an "OCI archive" (`.oci.tar`). */
|
|
@@ -152,12 +165,17 @@ export declare function parseConfig(bytes: Uint8Array): ParsedConfig;
|
|
|
152
165
|
* carries the `dev.sitefile.root` label (built with BASE). -1 when the image is not a Sitefile image.
|
|
153
166
|
*/
|
|
154
167
|
export declare function siteLayerIndex(m: ParsedManifest, cfg: ParsedConfig): number;
|
|
168
|
+
/**
|
|
169
|
+
* Indices of every layer holding site files: the last `dev.sitefile.layers` layers (`--oci-layers`),
|
|
170
|
+
* else the one {@link siteLayerIndex} names; empty when the image is not a Sitefile image.
|
|
171
|
+
*/
|
|
172
|
+
export declare function siteLayerIndices(m: ParsedManifest, cfg: ParsedConfig): number[];
|
|
155
173
|
/**
|
|
156
174
|
* Decode a site image's files, verifying the layer digest and diff_id.
|
|
157
175
|
* `layerBytes` are the compressed blob bytes. Returns the tree under the image's root (its
|
|
158
176
|
* `dev.sitefile.root` label, else `/`), or under `rootOverride` (`FROM image … AT <dir>`).
|
|
159
177
|
*/
|
|
160
|
-
export declare function extractImageFiles(m: ParsedManifest, cfg: ParsedConfig, layerBytes: Uint8Array, origin: string, rootOverride?: string): Promise<Tree>;
|
|
178
|
+
export declare function extractImageFiles(m: ParsedManifest, cfg: ParsedConfig, layerBytes: Uint8Array | readonly Uint8Array[], origin: string, rootOverride?: string): Promise<Tree>;
|
|
161
179
|
/**
|
|
162
180
|
* Label values for an image built from `contextDir`: the title (directory name),
|
|
163
181
|
* extra `--label`s, and, only with `--git-labels`, source/revision from a git
|