ssqch 0.10.0 → 0.11.0

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 (95) hide show
  1. package/bundled/completions/bash +62 -16
  2. package/bundled/completions/elvish +28 -12
  3. package/bundled/completions/fish +36 -23
  4. package/bundled/completions/powershell +30 -12
  5. package/bundled/completions/zsh +40 -19
  6. package/bundled/docs/agents.md +12 -1
  7. package/bundled/docs/build-summary.md +31 -1
  8. package/bundled/docs/comparing-builds.md +37 -5
  9. package/bundled/docs/configuring.md +30 -5
  10. package/bundled/docs/field-guide.md +1 -1
  11. package/bundled/docs/github-pages.md +1 -1
  12. package/bundled/docs/index.md +1 -1
  13. package/bundled/docs/known-gaps.md +1 -1
  14. package/bundled/docs/markdown.md +63 -5
  15. package/bundled/docs/multilingual.md +20 -3
  16. package/bundled/docs/nav.yml +1 -0
  17. package/bundled/docs/netlify.md +2 -2
  18. package/bundled/docs/plugins.md +4 -4
  19. package/bundled/docs/seo.md +39 -1
  20. package/bundled/docs/template-languages.md +6 -4
  21. package/bundled/docs/templates.md +3 -3
  22. package/bundled/docs/trailheads/from-eleventy.md +25 -13
  23. package/bundled/docs/trailheads/from-hugo.md +103 -0
  24. package/bundled/docs/trailheads/from-jekyll.md +49 -15
  25. package/bundled/docs/trailheads/from-mkdocs.md +54 -9
  26. package/bundled/docs/trailheads/from-zola.md +2 -2
  27. package/bundled/docs/trailheads.md +22 -5
  28. package/bundled/docs/where-values-come-from.md +1 -1
  29. package/bundled/mkdocs/404.jinja +6 -0
  30. package/bundled/ssqch.d.ts +78 -18
  31. package/lib/assets.js +11 -12
  32. package/lib/{chunk-3HHRKG33.js → chunk-2L3HR67O.js} +71 -19
  33. package/lib/{chunk-LCPSKHAV.js → chunk-2QTJTEBV.js} +1 -1
  34. package/lib/{chunk-RVBNVGZV.js → chunk-3HZZY3Y7.js} +5 -6
  35. package/lib/{chunk-RKFZSVNF.js → chunk-3K237XAX.js} +10 -11
  36. package/lib/{chunk-HXCLCXRT.js → chunk-443ZQLVX.js} +5 -3
  37. package/lib/{chunk-Q4LFTYK2.js → chunk-5ELAUHRL.js} +20 -20
  38. package/lib/{chunk-SA5KSJ4Y.js → chunk-A75EVUJX.js} +10 -12
  39. package/lib/{chunk-BGCBSQ4A.js → chunk-AIMEXBTK.js} +163 -29
  40. package/lib/{chunk-Y2ESFAAD.js → chunk-B5E27PLU.js} +10 -41
  41. package/lib/{chunk-RJFWTW2Y.js → chunk-CMJ7X5WW.js} +3 -3
  42. package/lib/{chunk-NKXEPHRZ.js → chunk-ERAIEV3O.js} +106 -4
  43. package/lib/{chunk-E5UB2YY7.js → chunk-FCM3NYFR.js} +11 -9
  44. package/lib/{chunk-3EPHKJEG.js → chunk-GJNIQAIH.js} +8 -8
  45. package/lib/{chunk-CB6YFUXU.js → chunk-GLJQ4C76.js} +40 -21
  46. package/lib/{chunk-DDV6JEC2.js → chunk-GS5B3CBW.js} +1 -1
  47. package/lib/chunk-H5K2ZE7B.js +219 -0
  48. package/lib/{chunk-NFJJKDRI.js → chunk-HFSWUTXX.js} +1 -1
  49. package/lib/{chunk-4Q6WMTER.js → chunk-HWW5NCVJ.js} +1 -1
  50. package/lib/{chunk-LAV3DEY4.js → chunk-I3HYKEEW.js} +1 -1
  51. package/lib/{chunk-JWCCVTTR.js → chunk-IOBC665M.js} +2 -4
  52. package/lib/chunk-JC54PHIT.js +7992 -0
  53. package/lib/{chunk-2LEOPLTZ.js → chunk-KCF2Z6N7.js} +3 -5
  54. package/lib/{chunk-DMVJ53SM.js → chunk-KZZS4W2V.js} +15 -15
  55. package/lib/{chunk-RM5Q3KFB.js → chunk-LJOURBYT.js} +14 -13
  56. package/lib/chunk-OQGXZYZS.js +45 -0
  57. package/lib/chunk-OSBEH67S.js +6296 -0
  58. package/lib/{chunk-DW7VMJEZ.js → chunk-QJ5ZFTML.js} +14 -13
  59. package/lib/{chunk-NUUEOGLZ.js → chunk-QLUTNR37.js} +11 -11
  60. package/lib/{chunk-HGJ5VWUR.js → chunk-RBNPBTDP.js} +1 -1
  61. package/lib/{chunk-F65YUXZ7.js → chunk-RIAOXEXC.js} +10 -4
  62. package/lib/chunk-RVXGUMFI.js +21 -0
  63. package/lib/{chunk-N4O5MDIB.js → chunk-RYIWYWRQ.js} +5 -7
  64. package/lib/{chunk-EEJDLCD3.js → chunk-RZYAIX2R.js} +12 -11
  65. package/lib/{chunk-7HXCQEGA.js → chunk-V2FSMOFX.js} +3 -3
  66. package/lib/{chunk-HDQ4SRWM.js → chunk-X2GAVYV2.js} +525 -75
  67. package/lib/chunk-XS4EJSEK.js +279 -0
  68. package/lib/chunk-YCOTX2VM.js +37 -0
  69. package/lib/{chunk-QMA7CK7B.js → chunk-Z44IAMNG.js} +137 -32
  70. package/lib/chunk-Z5OP43HU.js +2945 -0
  71. package/lib/{chunk-JXZT5L7W.js → chunk-ZINLHOX4.js} +2 -3
  72. package/lib/{chunk-SRNLKWXL.js → chunk-ZR3JYLFB.js} +893 -12382
  73. package/lib/cli.js +82 -41
  74. package/lib/elements.js +11 -12
  75. package/lib/image.js +11 -11
  76. package/lib/links.js +11 -12
  77. package/lib/minify.js +71 -13
  78. package/lib/redirects.js +11 -12
  79. package/lib/rss.js +13 -11
  80. package/lib/sass.js +13 -245
  81. package/lib/sitemap.js +19 -18
  82. package/lib/ssqch.js +6 -5
  83. package/package.json +1 -1
  84. package/types/index.d.ts +59 -13
  85. package/types/minify.d.ts +15 -3
  86. package/types/sass.d.ts +2 -0
  87. package/types/sitemap.d.ts +2 -2
  88. package/wasm/markdown.wasm +0 -0
  89. package/wasm/minify.wasm +0 -0
  90. package/wasm/sass.wasm +0 -0
  91. package/lib/chunk-5DNDSNTP.js +0 -1541
  92. package/lib/chunk-VJWQSYEG.js +0 -119
  93. package/lib/chunk-ZM6TU2JB.js +0 -1287
  94. /package/lib/{chunk-BGCBSQ4A.js.LEGAL.txt → chunk-AIMEXBTK.js.LEGAL.txt} +0 -0
  95. /package/lib/{chunk-SRNLKWXL.js.LEGAL.txt → chunk-ZR3JYLFB.js.LEGAL.txt} +0 -0
@@ -3,15 +3,11 @@ const require = __ssqchCreateRequire(import.meta.url);
3
3
  import {
4
4
  buildFiles,
5
5
  urlOf
6
- } from "./chunk-N4O5MDIB.js";
7
- import "./chunk-LCPSKHAV.js";
6
+ } from "./chunk-RYIWYWRQ.js";
8
7
  import {
9
8
  bytes,
10
9
  count
11
- } from "./chunk-NKXEPHRZ.js";
12
- import "./chunk-DDV6JEC2.js";
13
- import "./chunk-FVZ5JBRI.js";
14
- import "./chunk-UU43WIZG.js";
10
+ } from "./chunk-ERAIEV3O.js";
15
11
  import {
16
12
  charCount,
17
13
  firstChars,
@@ -19,12 +15,9 @@ import {
19
15
  } from "./chunk-CMUWRPSQ.js";
20
16
  import {
21
17
  BuildError,
22
- bail
23
- } from "./chunk-BGCBSQ4A.js";
24
- import {
18
+ bail,
25
19
  compareText
26
- } from "./chunk-VJWQSYEG.js";
27
- import "./chunk-I3PS26CI.js";
20
+ } from "./chunk-AIMEXBTK.js";
28
21
 
29
22
  // src/diff.ts
30
23
  import fs from "node:fs";
@@ -742,6 +735,9 @@ var GENERATOR = new RegExp(String.raw`SiteSquatch v\p{Nd}+\.\p{Nd}+\.\p{Nd}+[\p{
742
735
  var ID_ATTR = new RegExp(`\\p{White_Space}id=(?:"([^"]*)"|'([^']*)'|([^\\p{White_Space}>]+))`, "u");
743
736
  var MONTH = "(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
744
737
  var DATE = new RegExp([
738
+ // Mon Mar 08 2021 00:00:00 GMT+0000 (Coordinated Universal Time): JavaScript's Date.toString(),
739
+ // as Eleventy's Nunjucks printed a date (a11yproject.com's JSON-LD, against ssqch's ISO 8601).
740
+ String.raw`${START}(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun)\p{White_Space}+${MONTH}\p{White_Space}+\p{Nd}{2}\p{White_Space}+\p{Nd}{4}\p{White_Space}+\p{Nd}{2}:\p{Nd}{2}:\p{Nd}{2}\p{White_Space}+GMT[+\-]\p{Nd}{4}(?:\p{White_Space}+\([^)]*\))?`,
745
741
  // 2026-03-14T09:05:00Z
746
742
  String.raw`\p{Nd}{4}-\p{Nd}{2}-\p{Nd}{2}(?:[T ]\p{Nd}{2}:\p{Nd}{2}(?::\p{Nd}{2}(?:\.\p{Nd}+)?)?(?:Z|[+\-]\p{Nd}{2}:?\p{Nd}{2})?)?`,
747
743
  // March 14, 2026
@@ -753,6 +749,13 @@ var DATE = new RegExp([
753
749
  // 2026
754
750
  String.raw`${START}(?:19|20)\p{Nd}{2}${END}`
755
751
  ].join("|"), "gu");
752
+ var IMAGE_ID = new RegExp(`(?<=[/"'=,\\p{White_Space}]|^)([A-Za-z0-9_-]{10})(?=-\\p{Nd}{1,5}\\.(?:avif|webp|jpe?g|png|gif|svg)(?![A-Za-z0-9]))`, "gu");
753
+ var isImageId = (id) => !/^(?:[a-z]+|[0-9]+)$/.test(id);
754
+ var isHashedImage = (file) => [...file.slice(file.lastIndexOf("/") + 1).matchAll(IMAGE_ID)].some((m) => m.index === 0 && isImageId(m[1]));
755
+ function withoutImageIds(text) {
756
+ if (!text.includes("-")) return text;
757
+ return text.replace(IMAGE_ID, (id) => isImageId(id) ? "{id}" : id);
758
+ }
756
759
  function withoutFingerprints(text) {
757
760
  if (!text.includes(".")) return text;
758
761
  return text.replace(FINGERPRINT, (whole, hash, ext) => /^(19|20)\d{6}$/.test(hash) ? whole : `.${ext}`);
@@ -774,10 +777,11 @@ function isInline(tag) {
774
777
  return INLINE.has(nameAt(tag, i));
775
778
  }
776
779
  function normalize(text, options) {
777
- if (options.exact) return text;
778
- let out = text.replaceAll("\r\n", "\n");
780
+ let out = options.exact ? text : text.replaceAll("\r\n", "\n");
779
781
  for (const re of options.ignore) out = out.replace(re, "");
782
+ if (options.exact) return out;
780
783
  out = withoutFingerprints(out);
784
+ out = withoutImageIds(out);
781
785
  if (out.includes("integrity=")) out = out.replace(INTEGRITY, "");
782
786
  if (out.includes("SiteSquatch v")) out = out.replace(GENERATOR, "SiteSquatch");
783
787
  return out;
@@ -806,6 +810,22 @@ function keyed(paths, exact) {
806
810
  return new Map(pairs.sort((a, b) => compareText(a[0], b[0])));
807
811
  }
808
812
  var isPage = (file) => file.endsWith(".html") || file.endsWith(".htm");
813
+ var isXml = (file) => /\.(?:xml|rss|atom|xsl)$/.test(file);
814
+ var CDATA = /<!\[CDATA\[([\s\S]*?)\]\]>/g;
815
+ var ESCAPED_TEXT = /(?<=>)([^<]*&lt;[^<]*)(?=<)/g;
816
+ function xmlWithMarkup(text) {
817
+ let out = text.includes("<![CDATA[") ? text.replace(CDATA, (_, inside) => inside) : text;
818
+ if (out.includes("&lt;")) out = out.replace(ESCAPED_TEXT, (escaped) => decodeEntitiesOnce(escaped));
819
+ return out;
820
+ }
821
+ function decodeEntitiesOnce(s) {
822
+ return s.replace(/&(lt|gt|quot|apos|amp|#[0-9]{1,7}|#[xX][0-9A-Fa-f]{1,6});/g, (whole, name) => {
823
+ const named2 = { lt: "<", gt: ">", quot: '"', apos: "'", amp: "&" };
824
+ if (Object.hasOwn(named2, name)) return named2[name];
825
+ const code = name[1] === "x" || name[1] === "X" ? Number.parseInt(name.slice(2), 16) : Number.parseInt(name.slice(1), 10);
826
+ return code > 0 && code <= 1114111 && !(code >= 55296 && code <= 57343) ? String.fromCodePoint(code) : whole;
827
+ });
828
+ }
809
829
  function isSpace(c) {
810
830
  return c === 32 || c >= 9 && c <= 13 || c >= 128 && (c === 133 || c === 160 || c === 5760 || c >= 8192 && c <= 8202 || c === 8232 || c === 8233 || c === 8239 || c === 8287 || c === 12288);
811
831
  }
@@ -858,19 +878,110 @@ function tagEnd(s, from) {
858
878
  }
859
879
  return void 0;
860
880
  }
881
+ var BOOLEAN = /* @__PURE__ */ new Set(["allowfullscreen", "async", "autofocus", "autoplay", "checked", "controls", "default", "defer", "disabled", "formnovalidate", "hidden", "inert", "ismap", "itemscope", "loop", "multiple", "muted", "nomodule", "novalidate", "open", "playsinline", "readonly", "required", "reversed", "selected"]);
882
+ var SPACED = /* @__PURE__ */ new Set(["class", "rel", "sizes", "srcset"]);
883
+ var VOID = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr"]);
884
+ var ENTITY_OR_AMP = /&(?:(#[0-9]{1,7}|#[xX][0-9A-Fa-f]{1,6}|[A-Za-z][A-Za-z0-9]*);)?/g;
885
+ var NAMED_ENTITIES = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'" };
886
+ function entityChar(name) {
887
+ if (name[0] !== "#") return Object.hasOwn(NAMED_ENTITIES, name) ? NAMED_ENTITIES[name] : void 0;
888
+ const code = name[1] === "x" || name[1] === "X" ? Number.parseInt(name.slice(2), 16) : Number.parseInt(name.slice(1), 10);
889
+ if (code === 160) return void 0;
890
+ return code > 0 && code <= 1114111 && !(code >= 55296 && code <= 57343) ? String.fromCodePoint(code) : void 0;
891
+ }
892
+ function canonicalText(text) {
893
+ if (!text.includes("&") && !text.includes(">")) return text;
894
+ return text.replace(ENTITY_OR_AMP, (whole, name) => {
895
+ if (name === void 0) return "&amp;";
896
+ if (name === "#160" || /^#[xX]0*[aA]0$/.test(name)) return "&nbsp;";
897
+ const c = entityChar(name);
898
+ return c === void 0 ? whole : c === "&" ? "&amp;" : c === "<" ? "&lt;" : c;
899
+ }).replaceAll("&gt;", ">");
900
+ }
901
+ function attributeValue(raw) {
902
+ if (!raw.includes("&")) return raw;
903
+ return raw.replace(ENTITY_OR_AMP, (whole, name) => name === void 0 ? whole : name === "nbsp" ? "\xA0" : entityChar(name) ?? whole);
904
+ }
905
+ var NO_ATTRIBUTES = /^<\/?[a-z][a-z0-9-]*>$/;
906
+ function canonicalTag(tag, foreign, xml = false) {
907
+ if (NO_ATTRIBUTES.test(tag)) return [tag, false];
908
+ const lower = xml ? (t) => t : asciiLower;
909
+ if (tag.startsWith("<!--")) return [tag, false];
910
+ if (/^<!doctype/i.test(tag)) return [asciiLower(tag), false];
911
+ const closing = tag.charCodeAt(1) === 47;
912
+ let i = closing ? 2 : 1;
913
+ const name = nameAt(tag, i);
914
+ if (name === "") return [tag, false];
915
+ i += name.length;
916
+ while (i < tag.length && /[A-Za-z0-9_:.-]/.test(tag[i])) i++;
917
+ const element = lower(tag.slice(closing ? 2 : 1, i));
918
+ const attrs = /* @__PURE__ */ new Map();
919
+ let selfClosing = false;
920
+ const end = tag.length - 1;
921
+ while (i < end) {
922
+ const c = tag.charCodeAt(i);
923
+ if (isSpace(c)) {
924
+ i++;
925
+ continue;
926
+ }
927
+ if (c === 47) {
928
+ let j2 = i + 1;
929
+ while (j2 < end && isSpace(tag.charCodeAt(j2))) j2++;
930
+ if (j2 === end) selfClosing = true;
931
+ i++;
932
+ continue;
933
+ }
934
+ let j = i;
935
+ while (j < end && !isSpace(tag.charCodeAt(j)) && tag[j] !== "=" && tag[j] !== ">" && !(tag[j] === "/" && j > i)) j++;
936
+ if (j === i) j++;
937
+ const attr2 = lower(tag.slice(i, j));
938
+ if (/["'<]/.test(attr2)) return [tag, false];
939
+ i = j;
940
+ while (i < end && isSpace(tag.charCodeAt(i))) i++;
941
+ let value;
942
+ if (tag[i] === "=") {
943
+ i++;
944
+ while (i < end && isSpace(tag.charCodeAt(i))) i++;
945
+ const q = tag[i];
946
+ if (q === '"' || q === "'") {
947
+ const close = tag.indexOf(q, i + 1);
948
+ if (close === -1) return [tag, false];
949
+ value = attributeValue(tag.slice(i + 1, close));
950
+ i = close + 1;
951
+ } else {
952
+ let k = i;
953
+ while (k < end && !isSpace(tag.charCodeAt(k))) k++;
954
+ value = attributeValue(tag.slice(i, k));
955
+ i = k;
956
+ }
957
+ }
958
+ if (attrs.has(attr2)) continue;
959
+ if (value !== void 0 && BOOLEAN.has(attr2) && !foreign && (value === "" || asciiLower(value) === attr2)) value = void 0;
960
+ if (value !== void 0 && SPACED.has(attr2)) value = collapse(value).replace(/ ?, ?/g, ", ");
961
+ attrs.set(attr2, value);
962
+ }
963
+ if (closing) return [`</${element}>`, false];
964
+ let out = `<${element}`;
965
+ for (const attr2 of [...attrs.keys()].sort()) {
966
+ const value = attrs.get(attr2);
967
+ out += value === void 0 ? ` ${attr2}` : ` ${attr2}="${value.replace(/&/g, "&amp;").replace(/"/g, "&quot;")}"`;
968
+ }
969
+ return [`${out}>`, selfClosing && (xml || foreign || element === "svg" || element === "math") && !VOID.has(element)];
970
+ }
861
971
  var RAW2 = /* @__PURE__ */ new Set(["script", "style", "pre", "textarea"]);
862
972
  var CLOSING = new Map([...RAW2].map((name) => [name, new RegExp(`</${name}`, "gi")]));
863
973
  var startsTag = (c) => c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 47 || c === 33 || c === 63;
864
- function tokens(html) {
974
+ function tokens(html, xml = false) {
865
975
  const out = [];
866
976
  let i = 0;
867
977
  let textStart = 0;
978
+ let foreign = 0;
868
979
  const pushText = (s, nextTag) => {
869
980
  if (s === "") return;
870
981
  const last = out[out.length - 1];
871
982
  const before = isSpace(s.codePointAt(0)) && last !== void 0 && last.tag && isInline(last.text);
872
983
  const after = isSpace(s.charCodeAt(s.length - 1)) && nextTag !== void 0 && isInline(nextTag);
873
- let t = collapse(s);
984
+ let t = canonicalText(collapse(s));
874
985
  if (t === "") {
875
986
  if (before && after) out.push({ tag: false, text: " " });
876
987
  return;
@@ -893,10 +1004,15 @@ function tokens(html) {
893
1004
  }
894
1005
  const tag = html.slice(i, i + end);
895
1006
  pushText(html.slice(textStart, i), tag);
896
- out.push({ tag: true, text: collapseTag(tag) });
1007
+ const [text, closes] = canonicalTag(collapseTag(tag), foreign > 0, xml);
1008
+ out.push({ tag: true, text });
1009
+ const name = xml ? "" : nameAt(tag, 1);
1010
+ if (name === "svg" || name === "math") {
1011
+ if (!closes) foreign++;
1012
+ } else if (tag.charCodeAt(1) === 47 && (nameAt(tag, 2) === "svg" || nameAt(tag, 2) === "math")) foreign = Math.max(0, foreign - 1);
1013
+ if (closes) out.push({ tag: true, text: `</${text.slice(1, text.search(/[ >]/))}>` });
897
1014
  i += end;
898
1015
  textStart = i;
899
- const name = nameAt(tag, 1);
900
1016
  if (RAW2.has(name) && !tag.endsWith("/>")) {
901
1017
  const closing = CLOSING.get(name);
902
1018
  closing.lastIndex = i;
@@ -904,7 +1020,13 @@ function tokens(html) {
904
1020
  const len = (found ? found.index : html.length) - i;
905
1021
  let raw = html.slice(i, i + len);
906
1022
  if (name === "pre" || name === "textarea") raw = raw.startsWith("\r\n") ? raw.slice(2) : raw.startsWith("\n") ? raw.slice(1) : raw;
907
- if (raw !== "") for (const line of raw.split("\n")) out.push({ tag: false, text: line.endsWith("\r") ? line.slice(0, -1) : line });
1023
+ const entities = name === "pre" || name === "textarea";
1024
+ if (raw !== "") {
1025
+ for (const line of raw.split("\n")) {
1026
+ const text2 = line.endsWith("\r") ? line.slice(0, -1) : line;
1027
+ out.push({ tag: false, text: entities ? canonicalText(text2) : text2 });
1028
+ }
1029
+ }
908
1030
  i += len;
909
1031
  textStart = i;
910
1032
  }
@@ -928,6 +1050,62 @@ function title(list) {
928
1050
  const next = list[i + 1];
929
1051
  return next && !next.tag ? next.text : void 0;
930
1052
  }
1053
+ function headingAbove(list) {
1054
+ const found = /* @__PURE__ */ new Map();
1055
+ return (index) => {
1056
+ for (let i = Math.min(index, list.length) - 1; i >= 0; i--) {
1057
+ const t = list[i];
1058
+ if (!t.tag || !/^<h[1-6][\s>]/i.test(t.text)) continue;
1059
+ if (found.has(i)) return found.get(i);
1060
+ const id = attr(t.text, "id");
1061
+ let text = "";
1062
+ for (let j = i + 1; j < list.length && !/^<\/h[1-6]>/i.test(list[j].text); j++) if (!list[j].tag) text += list[j].text;
1063
+ const at = id ? `#${id}` : text.trim() ? `"${clip(text.trim())}"` : void 0;
1064
+ found.set(i, at);
1065
+ return at;
1066
+ }
1067
+ return void 0;
1068
+ };
1069
+ }
1070
+ function attr(tag, name) {
1071
+ const m = new RegExp(`\\s${name}="([^"]*)"`, "i").exec(tag);
1072
+ return m?.[1];
1073
+ }
1074
+ function wayfinding(list) {
1075
+ const out = {};
1076
+ for (const t of list) {
1077
+ if (!t.tag) continue;
1078
+ if (out.canonical === void 0 && /^<link\s/i.test(t.text) && /\srel="canonical"/i.test(t.text)) out.canonical = attr(t.text, "href");
1079
+ if (out.redirect === void 0 && /^<meta\s/i.test(t.text) && /\shttp-equiv="refresh"/i.test(t.text)) out.redirect = /url=\s*['"]?([^'"\s>]+)/i.exec(attr(t.text, "content") ?? "")?.[1];
1080
+ }
1081
+ return out;
1082
+ }
1083
+ function feedEntries(list) {
1084
+ const out = [];
1085
+ let inEntry = false;
1086
+ let id;
1087
+ let link;
1088
+ for (let i = 0; i < list.length; i++) {
1089
+ const t = list[i];
1090
+ if (!t.tag) continue;
1091
+ if (/^<(item|entry)[\s>]/i.test(t.text)) {
1092
+ inEntry = true;
1093
+ id = link = void 0;
1094
+ continue;
1095
+ }
1096
+ if (/^<\/(item|entry)>/i.test(t.text)) {
1097
+ if (inEntry) out.push(id ?? link ?? `(entry ${out.length + 1})`);
1098
+ inEntry = false;
1099
+ continue;
1100
+ }
1101
+ if (!inEntry) continue;
1102
+ const next = list[i + 1];
1103
+ const text = next && !next.tag ? next.text.trim() : void 0;
1104
+ if (/^<(guid|id)[\s>]/i.test(t.text) && text) id ??= text;
1105
+ else if (/^<link[\s>]/i.test(t.text)) link ??= attr(t.text, "href") ?? text;
1106
+ }
1107
+ return out;
1108
+ }
931
1109
  function lines(text) {
932
1110
  if (text === "") return [];
933
1111
  const out = text.split("\n");
@@ -937,7 +1115,7 @@ function lines(text) {
937
1115
  }
938
1116
  return out;
939
1117
  }
940
- function hunks(before, after, kind, show) {
1118
+ function hunks(before, after, kind, show, where) {
941
1119
  const numbers = [/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()];
942
1120
  let count2 = 0;
943
1121
  const number = (item) => {
@@ -959,7 +1137,10 @@ function hunks(before, after, kind, show) {
959
1137
  if (op.tag === "equal") continue;
960
1138
  for (let i = op.oldIndex; i < op.oldIndex + op.oldLen; i++) changed.push([true, i]);
961
1139
  for (let i = op.newIndex; i < op.newIndex + op.newLen; i++) changed.push([false, i]);
962
- out.push({ removed: before.slice(op.oldIndex, op.oldIndex + op.oldLen).map(show), added: after.slice(op.newIndex, op.newIndex + op.newLen).map(show) });
1140
+ const hunk = { removed: before.slice(op.oldIndex, op.oldIndex + op.oldLen).map(show), added: after.slice(op.newIndex, op.newIndex + op.newLen).map(show) };
1141
+ const at = where?.(op.oldIndex);
1142
+ if (at !== void 0) hunk.at = at;
1143
+ out.push(hunk);
963
1144
  }
964
1145
  return [out, changed];
965
1146
  }
@@ -973,7 +1154,7 @@ function firstLines(list, limit) {
973
1154
  left -= removed.length;
974
1155
  const added = h.added.slice(0, left);
975
1156
  left -= added.length;
976
- out.push({ removed, added });
1157
+ out.push(h.at === void 0 ? { removed, added } : { removed, added, at: h.at });
977
1158
  }
978
1159
  return out;
979
1160
  }
@@ -998,7 +1179,10 @@ function comparePair(a, b, pair, options) {
998
1179
  changedLines: 0,
999
1180
  onlyDates: void 0,
1000
1181
  sizeBefore: a.length,
1001
- sizeAfter: b.length
1182
+ sizeAfter: b.length,
1183
+ groups: [],
1184
+ ownHunks: [],
1185
+ ownLines: 0
1002
1186
  };
1003
1187
  const textA = decode(a), textB = decode(b);
1004
1188
  if (textA === void 0 || textB === void 0) return diff2;
@@ -1008,29 +1192,80 @@ function comparePair(a, b, pair, options) {
1008
1192
  if (isPage(pair.key) && !options.exact) {
1009
1193
  diff2.kind = "page";
1010
1194
  const ta = tokens(before), tb = tokens(after);
1011
- const [list, changed] = hunks(ta, tb, (t) => t.tag ? 1 : 0, (t) => t.text);
1195
+ const [list, changed] = hunks(ta, tb, (t) => t.tag ? 1 : 0, (t) => t.text, headingAbove(ta));
1012
1196
  if (!list.length) return void 0;
1013
1197
  const isTag = ([first, i]) => (first ? ta[i] : tb[i]).tag;
1014
1198
  if (changed.some((c) => !isTag(c))) diff2.what.push("text");
1015
1199
  if (changed.some(isTag)) diff2.what.push("markup");
1016
1200
  const [old, now] = [title(ta), title(tb)];
1017
1201
  if (old !== void 0 && now !== void 0 && old !== now) diff2.notes.push(`title: ${quoted(old)} -> ${quoted(now)}`);
1018
- const kept = new Set(ids(tb));
1019
- const gone = ids(ta).filter((id) => !kept.has(id)).map((id) => `#${id}`);
1202
+ const kept2 = new Set(ids(tb));
1203
+ const gone = ids(ta).filter((id) => !kept2.has(id)).map((id) => `#${id}`);
1020
1204
  if (gone.length) diff2.notes.push(`ids removed (links to them break): ${gone.slice(0, 8).join(", ")}${gone.length > 8 ? ` and ${gone.length - 8} more` : ""}`);
1205
+ const [wa, wb] = [wayfinding(ta), wayfinding(tb)];
1206
+ if (wa.canonical !== wb.canonical) diff2.notes.push(`canonical link: ${wa.canonical ?? "none"} -> ${wb.canonical ?? "none"}`);
1207
+ if (wa.redirect !== wb.redirect) diff2.notes.push(`redirects to: ${wa.redirect ?? "nowhere"} -> ${wb.redirect ?? "nowhere"}`);
1021
1208
  diff2.onlyDates = onlyDates(list);
1022
1209
  if (diff2.onlyDates) diff2.notes.push(`only dates changed (${diff2.onlyDates[0]} -> ${diff2.onlyDates[1]})`);
1023
1210
  found = list;
1211
+ } else if (isXml(pair.key) && !options.exact) {
1212
+ diff2.kind = "text";
1213
+ const ta = tokens(xmlWithMarkup(before), true), tb = tokens(xmlWithMarkup(after), true);
1214
+ found = hunks(ta, tb, (t) => t.tag ? 1 : 0, (t) => t.text)[0];
1215
+ if (!found.length) return void 0;
1216
+ const [ea, eb] = [feedEntries(ta), feedEntries(tb)];
1217
+ if (ea.length || eb.length) {
1218
+ const kept2 = new Set(eb), had = new Set(ea);
1219
+ const gone = ea.filter((e) => !kept2.has(e)), came = eb.filter((e) => !had.has(e));
1220
+ const some = (list) => `${list.slice(0, 3).join(", ")}${list.length > 3 ? ` and ${list.length - 3} more` : ""}`;
1221
+ if (gone.length) diff2.notes.push(`feed entries removed (readers see them go): ${some(gone)}`);
1222
+ if (came.length) diff2.notes.push(`feed entries added (readers see them as new): ${some(came)}`);
1223
+ }
1224
+ diff2.onlyDates = onlyDates(found);
1225
+ if (diff2.onlyDates) diff2.notes.push(`only dates changed (${diff2.onlyDates[0]} -> ${diff2.onlyDates[1]})`);
1024
1226
  } else {
1025
1227
  diff2.kind = isPage(pair.key) ? "page" : "text";
1026
1228
  const la = lines(before), lb = lines(after);
1027
1229
  found = hunks(la, lb, () => 0, (l) => l)[0];
1028
1230
  if (!found.length) found = [{ removed: [`(${Buffer.byteLength(before)} bytes)`], added: [`(${Buffer.byteLength(after)} bytes)`] }];
1231
+ else if (!isPage(pair.key)) {
1232
+ diff2.onlyDates = onlyDates(found);
1233
+ if (diff2.onlyDates) diff2.notes.push(`only dates changed (${diff2.onlyDates[0]} -> ${diff2.onlyDates[1]})`);
1234
+ }
1029
1235
  }
1236
+ if (!diff2.onlyDates && sameLines(found)) diff2.notes.push("the same lines, in another order");
1237
+ diff2.allHunks = found;
1030
1238
  diff2.changedLines = found.reduce((sum, h) => sum + h.removed.length + h.added.length, 0);
1031
1239
  diff2.hunks = firstLines(found, options.lines);
1032
1240
  return diff2;
1033
1241
  }
1242
+ async function linkTarget(file) {
1243
+ try {
1244
+ return (await fs.promises.readlink(file)).replaceAll("\\", "/");
1245
+ } catch {
1246
+ return void 0;
1247
+ }
1248
+ }
1249
+ function compareLinks(a, b, pair) {
1250
+ if (a === b) return void 0;
1251
+ const side = (target) => target === void 0 ? "(a file, not a link)" : `-> ${target}`;
1252
+ return {
1253
+ path: pair.key,
1254
+ url: urlOf(pair.key),
1255
+ renamed: pair.before !== pair.after ? [pair.before, pair.after] : void 0,
1256
+ kind: "text",
1257
+ what: [],
1258
+ notes: [a !== void 0 && b !== void 0 ? "a link, to somewhere else" : "a link in one build and a file in the other"],
1259
+ hunks: [{ removed: [side(a)], added: [side(b)] }],
1260
+ changedLines: 2,
1261
+ onlyDates: void 0,
1262
+ sizeBefore: 0,
1263
+ sizeAfter: 0,
1264
+ groups: [],
1265
+ ownHunks: [],
1266
+ ownLines: 0
1267
+ };
1268
+ }
1034
1269
  var READS_AT_ONCE = 32;
1035
1270
  var Reader = class {
1036
1271
  buffer = Buffer.allocUnsafe(64 * 1024);
@@ -1057,15 +1292,25 @@ var Reader = class {
1057
1292
  });
1058
1293
  }
1059
1294
  };
1295
+ function kept(paths, options) {
1296
+ const { only, exclude } = options;
1297
+ return paths.filter((p) => (!only || only.some((re) => re.test(p))) && !(exclude ?? []).some((re) => re.test(p)));
1298
+ }
1299
+ function checkOnly(lists, options) {
1300
+ if (!options.only || lists.some((list) => list.some((p) => options.only.some((re) => re.test(p))))) return;
1301
+ const given = (options.onlyGiven ?? []).map((g) => `"${g}"`).join(", ");
1302
+ bail(`--only ${given || "(its globs)"} matched no file in ${lists.length === 2 ? "either build" : "any of the builds"}: it's a glob of paths in the build folder, like \`posts/pine/index.html\`, \`posts/**\` or \`/posts/pine/\` (a folder: everything in it)`);
1303
+ }
1060
1304
  async function compare(before, after, options) {
1061
- const keep = (paths) => options.only ? paths.filter((p) => options.only.some((re) => re.test(p))) : paths;
1305
+ const keep = (paths) => kept(paths, options);
1062
1306
  const [walkA, walkB] = await Promise.allSettled([files(before), files(after)]);
1063
1307
  if (walkA.status === "rejected") throw walkA.reason;
1064
1308
  if (walkB.status === "rejected") throw walkB.reason;
1065
1309
  const [listA, listB] = [walkA.value, walkB.value];
1310
+ checkOnly([listA, listB], options);
1066
1311
  const a = keyed(keep(listA), options.exact);
1067
1312
  const b = keyed(keep(listB), options.exact);
1068
- const report = { before, after, exact: options.exact, added: [], removed: [], changed: [], unchangedPages: 0, unchangedFiles: 0 };
1313
+ const report = { before, after, exact: options.exact, added: [], removed: [], changed: [], groups: [], unchangedPages: 0, unchangedFiles: 0 };
1069
1314
  for (const key of a.keys()) if (!b.has(key)) report.removed.push(urlOf(key));
1070
1315
  for (const key of b.keys()) if (!a.has(key)) report.added.push(urlOf(key));
1071
1316
  const pairs = [];
@@ -1080,6 +1325,11 @@ async function compare(before, after, options) {
1080
1325
  while (next < pairs.length) {
1081
1326
  const i = next++;
1082
1327
  const pair = pairs[i];
1328
+ const [fromLink, toLink] = await Promise.all([linkTarget(path.join(before, pair.before)), linkTarget(path.join(after, pair.after))]);
1329
+ if (fromLink !== void 0 || toLink !== void 0) {
1330
+ results[i] = compareLinks(fromLink, toLink, pair);
1331
+ continue;
1332
+ }
1083
1333
  const [one, two] = await Promise.all([x.read(path.join(before, pair.before)), y.read(path.join(after, pair.after))]);
1084
1334
  results[i] = comparePair(one, two, pair, options);
1085
1335
  }
@@ -1091,8 +1341,136 @@ async function compare(before, after, options) {
1091
1341
  else if (isPage(pair.key)) report.unchangedPages += 1;
1092
1342
  else report.unchangedFiles += 1;
1093
1343
  });
1344
+ report.groups = options.ungrouped ? [] : groupChanges(report.changed);
1345
+ for (const file of report.changed) {
1346
+ if (!report.groups.length) file.ownHunks = file.allHunks ?? file.hunks;
1347
+ file.ownLines = file.ownHunks.reduce((sum, h) => sum + h.removed.length + h.added.length, 0);
1348
+ file.ownHunks = firstLines(file.ownHunks, options.lines);
1349
+ delete file.allHunks;
1350
+ }
1094
1351
  return report;
1095
1352
  }
1353
+ var hunkKey = (h) => JSON.stringify([h.removed, h.added]);
1354
+ var lineShape = (line) => line.startsWith("<") ? line.replace(/="[^"]*"/g, '="\u2026"') : line;
1355
+ var shapeKeyOf = (h) => JSON.stringify([h.removed.map(lineShape), h.added.map(lineShape)]);
1356
+ function changedDates(h) {
1357
+ if (!onlyDates([h])) return void 0;
1358
+ const pairs = /* @__PURE__ */ new Set();
1359
+ h.removed.forEach((line, i) => {
1360
+ const old = [...line.matchAll(DATE)].map((m) => m[0]);
1361
+ const now = [...h.added[i].matchAll(DATE)].map((m) => m[0]);
1362
+ old.forEach((d, k) => {
1363
+ if (d !== now[k]) pairs.add(`${d}>${now[k]}`);
1364
+ });
1365
+ });
1366
+ return [...pairs].sort();
1367
+ }
1368
+ var shapeKey = (h) => {
1369
+ const dates = changedDates(h);
1370
+ return dates ? `dates:${JSON.stringify([...new Set(dates.map((pair) => pair.split(">")[0].replace(new RegExp("\\p{Nd}", "gu"), "0").replace(new RegExp("\\p{L}", "gu"), "a")))].sort())}` : shapeKeyOf(h);
1371
+ };
1372
+ var tagLine = (line) => line.startsWith("<") ? (/^<\/?[^\s>]+/.exec(line)?.[0] ?? line) + ">" : line;
1373
+ var once = (lines2) => lines2.filter((line, i) => i === 0 || line !== lines2[i - 1]);
1374
+ var tagKey = (h) => JSON.stringify([once(h.removed.map(tagLine)), once(h.added.map(tagLine))]);
1375
+ function kindOf(h) {
1376
+ if (onlyDates([h])) return "dates";
1377
+ if (sameLines([h])) return "order";
1378
+ const lines2 = [...h.removed, ...h.added];
1379
+ const tags = lines2.filter((l) => l.startsWith("<")).length;
1380
+ return tags === lines2.length ? "markup" : tags === 0 ? "text" : "markup and text";
1381
+ }
1382
+ function groupChanges(changed) {
1383
+ const found = /* @__PURE__ */ new Map();
1384
+ changed.forEach((f, i) => {
1385
+ for (const h of f.allHunks ?? f.hunks) {
1386
+ if (!h.removed.length && !h.added.length) continue;
1387
+ const k = shapeKey(h);
1388
+ const entry = found.get(k);
1389
+ if (!entry) found.set(k, { files: /* @__PURE__ */ new Set([i]), hunk: h, first: i, same: true });
1390
+ else {
1391
+ entry.files.add(i);
1392
+ if (entry.same && hunkKey(h) !== hunkKey(entry.hunk)) entry.same = false;
1393
+ }
1394
+ }
1395
+ });
1396
+ const drafts = [];
1397
+ const byShape = /* @__PURE__ */ new Map();
1398
+ for (const [k, e] of found) {
1399
+ if (e.files.size < 2) continue;
1400
+ byShape.set(k, drafts.length);
1401
+ drafts.push({ files: new Set(e.files), hunk: e.hunk, first: e.first, match: e.same ? "lines" : k.startsWith("dates:") ? "dates" : "values" });
1402
+ }
1403
+ const byTags = /* @__PURE__ */ new Map();
1404
+ const merged = /* @__PURE__ */ new Map();
1405
+ const hasTags = (h) => h.removed.length + h.added.length >= 3 && h.removed.concat(h.added).some((l) => l.startsWith("<"));
1406
+ [...drafts.keys()].sort((a, b) => drafts[b].files.size - drafts[a].files.size || drafts[a].first - drafts[b].first).forEach((i) => {
1407
+ const k = tagKey(drafts[i].hunk);
1408
+ const into = hasTags(drafts[i].hunk) ? byTags.get(k) : void 0;
1409
+ if (into === void 0) {
1410
+ byTags.set(k, i);
1411
+ return;
1412
+ }
1413
+ for (const f of drafts[i].files) drafts[into].files.add(f);
1414
+ drafts[into].match = "tags";
1415
+ merged.set(i, into);
1416
+ });
1417
+ for (const [shape, i] of byShape) if (merged.has(i)) byShape.set(shape, merged.get(i));
1418
+ const placed = /* @__PURE__ */ new Map();
1419
+ const loose = /* @__PURE__ */ new Map();
1420
+ changed.forEach((f, i) => {
1421
+ const at = /* @__PURE__ */ new Map();
1422
+ placed.set(f, at);
1423
+ for (const h of f.allHunks ?? f.hunks) {
1424
+ if (!h.removed.length && !h.added.length) continue;
1425
+ const shaped = byShape.get(shapeKey(h));
1426
+ if (shaped !== void 0) {
1427
+ at.set(h, shaped);
1428
+ continue;
1429
+ }
1430
+ const tags = byTags.get(tagKey(h));
1431
+ if (tags !== void 0 && hasTags(h)) {
1432
+ drafts[tags].files.add(i);
1433
+ drafts[tags].match = "tags";
1434
+ at.set(h, tags);
1435
+ continue;
1436
+ }
1437
+ const k = tagKey(h);
1438
+ const entry = loose.get(k) ?? { files: /* @__PURE__ */ new Set(), hunk: h, first: i, hunks: [] };
1439
+ entry.files.add(i);
1440
+ entry.hunks.push([i, h]);
1441
+ loose.set(k, entry);
1442
+ }
1443
+ });
1444
+ for (const e of loose.values()) {
1445
+ if (e.files.size < 2 || !hasTags(e.hunk)) continue;
1446
+ const index = drafts.length;
1447
+ drafts.push({ files: e.files, hunk: e.hunk, first: e.first, match: "tags" });
1448
+ for (const [i, h] of e.hunks) placed.get(changed[i]).set(h, index);
1449
+ }
1450
+ const order = drafts.map((_, i) => i).filter((i) => !merged.has(i)).sort((a, b) => drafts[b].files.size - drafts[a].files.size || drafts[a].first - drafts[b].first);
1451
+ const number = new Map(order.map((old, i) => [old, i]));
1452
+ const groups = order.map((i) => {
1453
+ const d = drafts[i];
1454
+ return { urls: [...d.files].sort((a, b) => a - b).map((f) => changed[f].url), same: d.match === "lines", match: d.match, kind: kindOf(d.hunk), hunk: d.hunk };
1455
+ });
1456
+ for (const f of changed) {
1457
+ const at = placed.get(f);
1458
+ const all = f.allHunks ?? f.hunks;
1459
+ f.groups = [...new Set(all.map((h) => at.get(h)).filter((g) => g !== void 0).map((g) => number.get(g)))].sort((a, b) => a - b);
1460
+ f.ownHunks = all.filter((h) => !at.has(h));
1461
+ }
1462
+ return groups;
1463
+ }
1464
+ function sameLines(list) {
1465
+ const counts = /* @__PURE__ */ new Map();
1466
+ let lines2 = 0;
1467
+ for (const hunk of list) {
1468
+ for (const line of hunk.removed) counts.set(line, (counts.get(line) ?? 0) + 1);
1469
+ for (const line of hunk.added) counts.set(line, (counts.get(line) ?? 0) - 1);
1470
+ lines2 += hunk.removed.length;
1471
+ }
1472
+ return lines2 > 0 && [...counts.values()].every((n) => n === 0);
1473
+ }
1096
1474
  function onlyDates(list) {
1097
1475
  const blank = (lines2) => lines2.map((l) => l.replace(DATE, "\0"));
1098
1476
  let first;
@@ -1115,17 +1493,66 @@ function onlyDates(list) {
1115
1493
  }
1116
1494
  return first;
1117
1495
  }
1496
+ var IGNORING = "Ignoring asset fingerprints, image ids, integrity hashes, the generator's version, whitespace between tags, and how tags are written where browsers read them the same (attribute order, quotes, entities, `<br/>`) (--exact compares bytes).\n";
1497
+ var IMAGES_LISTED = 5;
1498
+ function listed(urls, sign) {
1499
+ const images = urls.filter(isHashedImage);
1500
+ if (images.length <= IMAGES_LISTED) return urls.map((url) => ` ${sign} ${url}
1501
+ `);
1502
+ const out = urls.filter((url) => !isHashedImage(url)).map((url) => ` ${sign} ${url}
1503
+ `);
1504
+ out.push(` ${sign} ${plural(images.length, "image", "images")} named by an id (${images[0].replace(IMAGE_ID, "{id}")} and the like): two builds that hash images differently name them differently, so they're counted here (--format json lists them)
1505
+ `);
1506
+ return out;
1507
+ }
1118
1508
  function clip(line) {
1119
1509
  const MAX = 200;
1120
1510
  const n = charCount(line);
1121
1511
  return n <= MAX ? line : `${firstChars(line, MAX)}\u2026 (${n - MAX} more characters)`;
1122
1512
  }
1123
1513
  var plural = (n, one, many) => `${count(n)} ${n === 1 ? one : many}`;
1514
+ function linesText(hunks2, total, limit, paint, indent = " ") {
1515
+ let shown = 0;
1516
+ let text = "";
1517
+ let place;
1518
+ done: for (const hunk of hunks2) {
1519
+ if (hunk.at !== void 0 && hunk.at !== place && !(limit > 0 && shown >= limit)) text += paint("2", `${indent}@ under ${hunk.at}
1520
+ `);
1521
+ place = hunk.at;
1522
+ for (const [sign, code, side] of [["-", "31", hunk.removed], ["+", "32", hunk.added]]) {
1523
+ for (const line of side) {
1524
+ if (limit > 0 && shown >= limit) break done;
1525
+ text += paint(code, `${indent}${sign} ${clip(line)}
1526
+ `);
1527
+ shown += 1;
1528
+ }
1529
+ }
1530
+ }
1531
+ if (total > shown) text += `${indent}... ${count(total - shown)} more changed ${total - shown === 1 ? "line" : "lines"} (--lines 0 shows all)
1532
+ `;
1533
+ return text;
1534
+ }
1535
+ var isPageUrl = (url) => url.endsWith("/") || isPage(url);
1536
+ function groupsText(groups, limit, paint, heading) {
1537
+ let out = ` ${heading}, the most files first (--ungrouped lists each file with all of it):
1538
+ `;
1539
+ for (const group of groups) {
1540
+ const n = group.urls.length;
1541
+ const what = group.urls.every(isPageUrl) ? n === 1 ? "page" : "pages" : n === 1 ? "file" : "files";
1542
+ const some = group.urls.slice(0, 3).join(", ");
1543
+ const alike = group.match === "lines" ? "" : group.match === "values" ? ", the same but for attribute values" : group.match === "dates" ? ", the same dates in other text" : ", the same tags with other attributes";
1544
+ out += ` ~ ${count(n)} ${what}${alike}: ${some}${n > 3 ? ` and ${count(n - 3)} more` : ""}
1545
+ `;
1546
+ out += linesText([group.hunk], group.hunk.removed.length + group.hunk.added.length, limit, paint);
1547
+ }
1548
+ return out;
1549
+ }
1124
1550
  function diffText(report, limit, color) {
1125
1551
  const paint = (code, s) => color ? `\x1B[${code}m${s}\x1B[0m` : s;
1126
1552
  let out = `Comparing ${report.before} with ${report.after}
1127
1553
  `;
1128
- out += report.exact ? "Comparing bytes (--exact).\n" : "Ignoring asset fingerprints, integrity hashes, the generator's version, and whitespace between tags (--exact compares bytes).\n";
1554
+ out += report.exact ? "Comparing bytes (--exact).\n" : IGNORING;
1555
+ const pageUrl = isPageUrl;
1129
1556
  const unchanged = `${plural(report.unchangedPages, "page", "pages")} and ${plural(report.unchangedFiles, "other file", "other files")}`;
1130
1557
  if (isSame(report)) return `${out}
1131
1558
  No differences: ${unchanged} are the same. The stump has not moved.
@@ -1134,20 +1561,26 @@ No differences: ${unchanged} are the same. The stump has not moved.
1134
1561
  out += `
1135
1562
  Added (${report.added.length})
1136
1563
  `;
1137
- for (const url of report.added) out += paint("32", ` + ${url}
1138
- `);
1564
+ for (const line of listed(report.added, "+")) out += paint("32", line);
1139
1565
  }
1140
1566
  if (report.removed.length) {
1141
1567
  out += `
1142
1568
  Removed (${report.removed.length})
1143
1569
  `;
1144
- for (const url of report.removed) out += paint("31", ` - ${url}
1145
- `);
1570
+ for (const line of listed(report.removed, "-")) out += paint("31", line);
1146
1571
  }
1147
1572
  if (report.changed.length) out += `
1148
1573
  Changed (${report.changed.length})
1149
1574
  `;
1575
+ const grouped = report.groups.length > 0;
1576
+ if (grouped) {
1577
+ out += groupsText(report.groups, limit, paint, "The same change on more than one file");
1578
+ const rest = report.changed.filter((f) => f.ownLines > 0);
1579
+ if (rest.length) out += ` And what's left on ${plural(rest.length, "file", "files")}:
1580
+ `;
1581
+ }
1150
1582
  for (const file of report.changed) {
1583
+ if (grouped && file.ownLines === 0) continue;
1151
1584
  const about = [];
1152
1585
  if (file.what.length) about.push(file.what.join(" and "));
1153
1586
  if (file.renamed) {
@@ -1159,21 +1592,8 @@ Changed (${report.changed.length})
1159
1592
  `;
1160
1593
  for (const note of file.notes) out += ` ${note}
1161
1594
  `;
1162
- let shown = 0;
1163
- done: for (const hunk of file.hunks) {
1164
- for (const [sign, code, side] of [["-", "31", hunk.removed], ["+", "32", hunk.added]]) {
1165
- for (const line of side) {
1166
- if (limit > 0 && shown >= limit) break done;
1167
- out += paint(code, ` ${sign} ${clip(line)}
1168
- `);
1169
- shown += 1;
1170
- }
1171
- }
1172
- }
1173
- if (file.changedLines > shown) out += ` ... ${count(file.changedLines - shown)} more changed ${file.changedLines - shown === 1 ? "line" : "lines"} (--lines 0 shows all)
1174
- `;
1595
+ out += grouped ? linesText(file.ownHunks, file.ownLines, limit, paint) : linesText(file.hunks, file.changedLines, limit, paint);
1175
1596
  }
1176
- const pageUrl = (url) => url.endsWith("/") || isPage(url);
1177
1597
  const pages = [...report.added, ...report.removed].filter(pageUrl).length + report.changed.filter((f) => isPage(f.path)).length;
1178
1598
  const others = report.added.length + report.removed.length + report.changed.length - pages;
1179
1599
  const found = others === 0 ? plural(pages, "page", "pages") : pages === 0 ? plural(others, "other file", "other files") : `${plural(pages, "page", "pages")} and ${plural(others, "other file", "other files")}`;
@@ -1184,6 +1604,7 @@ Changed (${report.changed.length})
1184
1604
  ${which} differ only in dates or years. See \`ssqch docs "dates that changed"\`: a page with no date of its own gets its file's modification time.
1185
1605
  `;
1186
1606
  }
1607
+ if (report.added.length || report.removed.length) out += "\nIf a folder held an earlier build, its leftover files are among the added and removed: to rule that out, build each side into an empty folder.\n";
1187
1608
  out += `
1188
1609
  Changes found: ${found} (${count(report.changed.length)} changed, ${count(report.added.length)} added, ${count(report.removed.length)} removed); ${unchanged} are the same. The stump has moved.
1189
1610
  `;
@@ -1201,7 +1622,8 @@ function diffJson(report, limit) {
1201
1622
  onlyDates: f.onlyDates !== void 0,
1202
1623
  sizeBefore: f.sizeBefore,
1203
1624
  sizeAfter: f.sizeAfter,
1204
- hunks: firstLines(f.hunks, limit)
1625
+ hunks: firstLines(f.hunks, limit),
1626
+ groups: f.groups
1205
1627
  };
1206
1628
  if (f.renamed) entry.renamed = { before: f.renamed[0], after: f.renamed[1] };
1207
1629
  return entry;
@@ -1215,16 +1637,19 @@ function diffJson(report, limit) {
1215
1637
  summary: { added: report.added.length, removed: report.removed.length, changed: report.changed.length, unchangedPages: report.unchangedPages, unchangedFiles: report.unchangedFiles },
1216
1638
  added: report.added,
1217
1639
  removed: report.removed,
1218
- changed
1640
+ changed,
1641
+ // Each change on more than one file, the most files first; a file's `groups` are places in this list.
1642
+ groups: report.groups.map((g) => ({ files: g.urls.length, urls: g.urls, same: g.same, match: g.match, kind: g.kind, hunk: g.hunk }))
1219
1643
  };
1220
1644
  }
1221
1645
  async function compareRuns(dirs, options) {
1222
- const keep = (paths) => options.only ? paths.filter((p) => options.only.some((re) => re.test(p))) : paths;
1646
+ const keep = (paths) => kept(paths, options);
1223
1647
  const walks = await Promise.allSettled(dirs.map(files));
1224
1648
  for (const walk of walks) if (walk.status === "rejected") throw walk.reason;
1649
+ checkOnly(walks.map((w) => w.value), options);
1225
1650
  const maps = walks.map((w) => keyed(keep(w.value), options.exact));
1226
1651
  const keys = [...new Set(maps.flatMap((m) => [...m.keys()]))].sort(compareText);
1227
- const report = { runs: dirs, exact: options.exact, varies: [], steadyPages: 0, steadyFiles: 0 };
1652
+ const report = { runs: dirs, exact: options.exact, varies: [], groups: [], steadyPages: 0, steadyFiles: 0, typical: 0 };
1228
1653
  const found = new Array(keys.length);
1229
1654
  let next = 0;
1230
1655
  const worker = async () => {
@@ -1245,6 +1670,17 @@ async function compareRuns(dirs, options) {
1245
1670
  else if (isPage(key)) report.steadyPages += 1;
1246
1671
  else report.steadyFiles += 1;
1247
1672
  });
1673
+ const typical = dirs.map(() => 0);
1674
+ for (const v of report.varies) if (!v.versions[0].missing) for (const run of v.versions[0].runs) typical[run] += 1;
1675
+ report.typical = typical.indexOf(Math.max(...typical));
1676
+ const samples = report.varies.map((v) => v.sample).filter((s) => s !== void 0);
1677
+ report.groups = options.ungrouped ? [] : groupChanges(samples);
1678
+ for (const sample of samples) {
1679
+ if (!report.groups.length) sample.ownHunks = sample.allHunks ?? sample.hunks;
1680
+ sample.ownLines = sample.ownHunks.reduce((sum, h) => sum + h.removed.length + h.added.length, 0);
1681
+ sample.ownHunks = firstLines(sample.ownHunks, options.lines);
1682
+ delete sample.allHunks;
1683
+ }
1248
1684
  return report;
1249
1685
  }
1250
1686
  function seen(key, data, options) {
@@ -1252,6 +1688,7 @@ function seen(key, data, options) {
1252
1688
  if (text === void 0) return `b:${data.toString("base64")}`;
1253
1689
  const normal = normalize(text, options);
1254
1690
  if (isPage(key) && !options.exact) return `p:${tokens(normal).map((t) => `${t.tag ? 1 : 0}${t.text}`).join("\0")}`;
1691
+ if (isXml(key) && !options.exact) return `x:${tokens(xmlWithMarkup(normal), true).map((t) => `${t.tag ? 1 : 0}${t.text}`).join("\0")}`;
1255
1692
  return `t:${normal}`;
1256
1693
  }
1257
1694
  function varies(key, buffers, maps, options) {
@@ -1273,14 +1710,14 @@ function varies(key, buffers, maps, options) {
1273
1710
  }
1274
1711
  const first = buffers.find((b) => b !== void 0);
1275
1712
  const kind = decode(first) === void 0 ? "binary" : isPage(key) ? "page" : "text";
1276
- return { path: key, url: urlOf(key), kind, versions, sample };
1713
+ return { path: key, url: urlOf(key), kind, versions, sample, files: maps.map((m) => m.get(key)) };
1277
1714
  }
1278
- var named = (report, runs) => runs.map((r) => report.runs[r]).join(", ");
1715
+ var named = (report, runs) => runs.length > 4 ? `${runs.length} of ${report.runs.length} builds (${runs.slice(0, 3).map((r) => report.runs[r]).join(", ")}, ...)` : runs.map((r) => report.runs[r]).join(", ");
1279
1716
  function runsText(report, limit, color) {
1280
1717
  const paint = (code, s) => color ? `\x1B[${code}m${s}\x1B[0m` : s;
1281
1718
  let out = `Comparing ${count(report.runs.length)} builds: ${report.runs.join(", ")}
1282
1719
  `;
1283
- out += report.exact ? "Comparing bytes (--exact).\n" : "Ignoring asset fingerprints, integrity hashes, the generator's version, and whitespace between tags (--exact compares bytes).\n";
1720
+ out += report.exact ? "Comparing bytes (--exact).\n" : IGNORING;
1284
1721
  const steady = `${plural(report.steadyPages, "page", "pages")} and ${plural(report.steadyFiles, "other file", "other files")}`;
1285
1722
  if (!report.varies.length) return `${out}
1286
1723
  Every build is the same: ${steady}. The tracks match every time.
@@ -1288,7 +1725,15 @@ Every build is the same: ${steady}. The tracks match every time.
1288
1725
  out += `
1289
1726
  Varies (${report.varies.length})
1290
1727
  `;
1728
+ const grouped = report.groups.length > 0;
1729
+ if (grouped) {
1730
+ out += groupsText(report.groups, limit, paint, "The same difference on more than one file");
1731
+ const rest = report.varies.filter((f) => !f.sample || f.sample.ownLines > 0);
1732
+ if (rest.length) out += ` And each file, with what's left:
1733
+ `;
1734
+ }
1291
1735
  for (const file of report.varies) {
1736
+ if (grouped && file.sample && file.sample.ownLines === 0) continue;
1292
1737
  const [most, ...rest] = file.versions;
1293
1738
  const onlyIn = most.missing && rest.length === 1;
1294
1739
  const others = rest.map((v) => v.missing ? `missing from ${named(report, v.runs)}` : onlyIn ? `only in ${named(report, v.runs)}` : `${named(report, v.runs)} differ${v.runs.length === 1 ? "s" : ""}`);
@@ -1299,22 +1744,16 @@ Varies (${report.varies.length})
1299
1744
  if (!sample) continue;
1300
1745
  for (const note of sample.notes) out += ` ${note}
1301
1746
  `;
1302
- let shown = 0;
1303
- done: for (const hunk of sample.hunks) {
1304
- for (const [sign, code, side] of [["-", "31", hunk.removed], ["+", "32", hunk.added]]) {
1305
- for (const line of side) {
1306
- if (limit > 0 && shown >= limit) break done;
1307
- out += paint(code, ` ${sign} ${clip(line)}
1308
- `);
1309
- shown += 1;
1310
- }
1311
- }
1312
- }
1313
- if (sample.changedLines > shown) out += ` ... ${count(sample.changedLines - shown)} more changed ${sample.changedLines - shown === 1 ? "line" : "lines"} (--lines 0 shows all)
1314
- `;
1747
+ out += grouped ? linesText(sample.ownHunks, sample.ownLines, limit, paint) : linesText(sample.hunks, sample.changedLines, limit, paint);
1315
1748
  }
1316
1749
  out += `
1317
1750
  ${plural(report.varies.length, "file varies", "files vary")} between builds made the same way; ${steady} are the same in all of them. Pin what changes (the build's time, random ids) before comparing another build with these, or leave it out with --ignore.
1751
+ `;
1752
+ const common = report.varies.filter((v) => !v.versions[0].missing && v.versions[0].runs.includes(report.typical)).length;
1753
+ out += `The build most like the others: ${report.runs[report.typical]}, with the most common version of ${common} of the ${plural(report.varies.length, "file", "files")} that vary.
1754
+ `;
1755
+ const unsettled = report.varies.filter((v) => v.versions[0].runs.length < 2).length;
1756
+ if (unsettled) out += `${unsettled === 1 ? "1 file has" : `${unsettled} files have`} no most common version: each build has its own. More builds (--runs 20) show whether one is usual.
1318
1757
  `;
1319
1758
  return out;
1320
1759
  }
@@ -1326,25 +1765,36 @@ function runsJson(report, limit) {
1326
1765
  exact: report.exact,
1327
1766
  same: report.varies.length === 0,
1328
1767
  summary: { varies: report.varies.length, steadyPages: report.steadyPages, steadyFiles: report.steadyFiles },
1768
+ // The build with the most common version of the most files that vary.
1769
+ typical: runs[report.typical],
1329
1770
  varies: report.varies.map((f) => ({
1330
1771
  url: f.url,
1331
1772
  path: f.path,
1332
1773
  kind: f.kind,
1333
1774
  versions: f.versions.map((v) => ({ runs: v.runs.map((r) => runs[r]), missing: v.missing })),
1334
1775
  changedLines: f.sample?.changedLines ?? 0,
1335
- hunks: f.sample ? firstLines(f.sample.hunks, limit) : []
1336
- }))
1776
+ hunks: f.sample ? firstLines(f.sample.hunks, limit) : [],
1777
+ groups: f.sample?.groups ?? []
1778
+ })),
1779
+ // Each difference on more than one varying file, the most files first; a file's `groups` are places in this list.
1780
+ groups: report.groups.map((g) => ({ files: g.urls.length, urls: g.urls, same: g.same, match: g.match, kind: g.kind, hunk: g.hunk }))
1337
1781
  };
1338
1782
  }
1783
+
1339
1784
  export {
1340
- compare,
1341
- compareRuns,
1342
- diffJson,
1343
- diffText,
1344
1785
  isSame,
1786
+ isHashedImage,
1787
+ withoutImageIds,
1788
+ withoutFingerprints,
1345
1789
  keyed,
1346
- runsJson,
1347
- runsText,
1790
+ canonicalText,
1791
+ canonicalTag,
1348
1792
  tokens,
1349
- withoutFingerprints
1793
+ compare,
1794
+ groupChanges,
1795
+ diffText,
1796
+ diffJson,
1797
+ compareRuns,
1798
+ runsText,
1799
+ runsJson
1350
1800
  };