ssqch 0.7.1 → 0.9.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.
- package/README.md +8 -4
- package/bin/ssqch.js +14 -48
- package/bundled/README.md +1314 -0
- package/bundled/completions/bash +840 -0
- package/bundled/completions/elvish +286 -0
- package/bundled/completions/fish +182 -0
- package/bundled/completions/powershell +318 -0
- package/bundled/completions/zsh +510 -0
- package/bundled/ssqch.d.ts +540 -0
- package/bundled/starter/engines/index.edge +11 -0
- package/bundled/starter/engines/index.ejs +11 -0
- package/bundled/starter/engines/index.hbs +11 -0
- package/bundled/starter/engines/index.liquid +11 -0
- package/bundled/starter/engines/layout.edge +35 -0
- package/bundled/starter/engines/layout.ejs +35 -0
- package/bundled/starter/engines/layout.hbs +35 -0
- package/bundled/starter/engines/layout.liquid +35 -0
- package/bundled/starter/gitignore +3 -0
- package/bundled/starter/jsconfig.json +11 -0
- package/bundled/starter/src/404.md +8 -0
- package/bundled/starter/src/_blueprints/posts.md +5 -0
- package/bundled/starter/src/_data/site.json +4 -0
- package/bundled/starter/src/_includes/layout.jinja +35 -0
- package/bundled/starter/src/index.jinja +11 -0
- package/bundled/starter/src/posts/i-know-what-i-saw.md +11 -0
- package/bundled/starter/src/posts/posts.json +4 -0
- package/bundled/starter/src/posts/raiders-of-the-lost-path.md +27 -0
- package/bundled/starter/src/posts/the-cache-of-the-wild.md +26 -0
- package/bundled/starter/src/posts/the-stump-has-moved.md +15 -0
- package/bundled/starter/src/posts/upon-further-review-a-stump.md +18 -0
- package/bundled/starter/ssqch.config.js +29 -0
- package/bundled/starter-docs/engines/edge/base.edge +41 -0
- package/bundled/starter-docs/engines/edge/containers/details.edge +5 -0
- package/bundled/starter-docs/engines/edge/containers/tab.edge +4 -0
- package/bundled/starter-docs/engines/edge/containers/tabs.edge +5 -0
- package/bundled/starter-docs/engines/edge/doc.edge +59 -0
- package/bundled/starter-docs/engines/edge/hooks/heading.edge +2 -0
- package/bundled/starter-docs/engines/ejs/base.ejs +41 -0
- package/bundled/starter-docs/engines/ejs/containers/details.ejs +5 -0
- package/bundled/starter-docs/engines/ejs/containers/tab.ejs +4 -0
- package/bundled/starter-docs/engines/ejs/containers/tabs.ejs +5 -0
- package/bundled/starter-docs/engines/ejs/doc.ejs +59 -0
- package/bundled/starter-docs/engines/ejs/hooks/heading.ejs +2 -0
- package/bundled/starter-docs/engines/hbs/base.hbs +41 -0
- package/bundled/starter-docs/engines/hbs/containers/details.hbs +5 -0
- package/bundled/starter-docs/engines/hbs/containers/tab.hbs +4 -0
- package/bundled/starter-docs/engines/hbs/containers/tabs.hbs +5 -0
- package/bundled/starter-docs/engines/hbs/doc.hbs +58 -0
- package/bundled/starter-docs/engines/hbs/hooks/heading.hbs +2 -0
- package/bundled/starter-docs/engines/liquid/base.liquid +41 -0
- package/bundled/starter-docs/engines/liquid/containers/details.liquid +5 -0
- package/bundled/starter-docs/engines/liquid/containers/tab.liquid +4 -0
- package/bundled/starter-docs/engines/liquid/containers/tabs.liquid +5 -0
- package/bundled/starter-docs/engines/liquid/doc.liquid +60 -0
- package/bundled/starter-docs/engines/liquid/hooks/heading.liquid +2 -0
- package/bundled/starter-docs/gitignore +4 -0
- package/bundled/starter-docs/src/404.md +12 -0
- package/bundled/starter-docs/src/_blueprints/docs.md +5 -0
- package/bundled/starter-docs/src/_data/nav.yml +10 -0
- package/bundled/starter-docs/src/_data/site.json +5 -0
- package/bundled/starter-docs/src/_includes/base.jinja +41 -0
- package/bundled/starter-docs/src/_includes/containers/details.jinja +5 -0
- package/bundled/starter-docs/src/_includes/containers/tab.jinja +4 -0
- package/bundled/starter-docs/src/_includes/containers/tabs.jinja +5 -0
- package/bundled/starter-docs/src/_includes/doc.jinja +59 -0
- package/bundled/starter-docs/src/_includes/hooks/heading.jinja +2 -0
- package/bundled/starter-docs/src/assets/docs.css +257 -0
- package/bundled/starter-docs/src/assets/docs.js +67 -0
- package/bundled/starter-docs/src/docs/docs.json +1 -0
- package/bundled/starter-docs/src/docs/guides/deploying.md +77 -0
- package/bundled/starter-docs/src/docs/guides/writing.md +65 -0
- package/bundled/starter-docs/src/docs/index.md +29 -0
- package/bundled/starter-docs/src/docs/install.md +42 -0
- package/bundled/starter-docs/src/index.md +13 -0
- package/bundled/starter-docs/ssqch.config.js +40 -0
- package/bundled/trailheads/from-component-frameworks.md +116 -0
- package/bundled/trailheads/from-docusaurus.md +55 -0
- package/bundled/trailheads/from-eleventy.md +140 -0
- package/bundled/trailheads/from-hexo.md +92 -0
- package/bundled/trailheads/from-jekyll.md +79 -0
- package/bundled/trailheads/from-mkdocs.md +45 -0
- package/bundled/trailheads/from-zola.md +71 -0
- package/lib/assets.js +235 -3
- package/lib/chunk-3A647I3N.js +384 -0
- package/lib/chunk-3GYLOC6Y.js +1017 -0
- package/lib/chunk-3K3ANWZ2.js +118 -0
- package/lib/chunk-3NYSSA2C.js +22 -0
- package/lib/chunk-47P4YREZ.js +1287 -0
- package/lib/chunk-4Q6WMTER.js +32 -0
- package/lib/chunk-76NTVE34.js +338 -0
- package/lib/chunk-7PWCYHTJ.js +1350 -0
- package/lib/chunk-7RDRZHJD.js +217 -0
- package/lib/chunk-7SD7K567.js +57 -0
- package/lib/chunk-7XLK2GEG.js +54 -0
- package/lib/chunk-AD3HAW3W.js +10 -0
- package/lib/chunk-BEGC7YP6.js +502 -0
- package/lib/chunk-CMUWRPSQ.js +113 -0
- package/lib/chunk-CZ4XQC56.js +999 -0
- package/lib/chunk-D2XE2GTY.js +71 -0
- package/lib/chunk-DDV6JEC2.js +46 -0
- package/lib/chunk-DELWRJAO.js +37409 -0
- package/lib/chunk-DELWRJAO.js.LEGAL.txt +27 -0
- package/lib/chunk-F65YUXZ7.js +334 -0
- package/lib/chunk-FVZ5JBRI.js +115 -0
- package/lib/chunk-GRWMGC7D.js +4435 -0
- package/lib/chunk-GRWMGC7D.js.LEGAL.txt +41 -0
- package/lib/chunk-GUKSZ2XM.js +207 -0
- package/lib/chunk-HPXAZ2HU.js +251 -0
- package/lib/chunk-HXCLCXRT.js +20 -0
- package/lib/chunk-I3PS26CI.js +48 -0
- package/lib/chunk-IAFM5ITE.js +11 -0
- package/lib/chunk-II5DEH3Q.js +209 -0
- package/lib/chunk-IJWHOFRP.js +44 -0
- package/lib/chunk-LPHNACE4.js +29 -0
- package/lib/chunk-MI6EJWA2.js +175 -0
- package/lib/chunk-NCWFYT74.js +1541 -0
- package/lib/chunk-NKXEPHRZ.js +136 -0
- package/lib/chunk-NNUKIGOO.js +160 -0
- package/lib/chunk-R7K3D5W5.js +3957 -0
- package/lib/chunk-RNJFPFXE.js +29 -0
- package/lib/chunk-SF4I6Z7S.js +25 -0
- package/lib/chunk-SURPOAW7.js +44 -0
- package/lib/chunk-SXMJ52IK.js +572 -0
- package/lib/chunk-TICWN55Z.js +20 -0
- package/lib/chunk-TVU3OPPK.js +146 -0
- package/lib/chunk-UU43WIZG.js +29 -0
- package/lib/chunk-VJWQSYEG.js +119 -0
- package/lib/chunk-XMXBHXZR.js +75 -0
- package/lib/chunk-YTHQBMDJ.js +211 -0
- package/lib/cli.js +547 -0
- package/lib/elements.js +180 -3
- package/lib/image.js +27 -3
- package/lib/links.js +464 -3
- package/lib/minify.js +69 -3
- package/lib/redirects.js +152 -3
- package/lib/rss.js +139 -3
- package/lib/sass.js +256 -3
- package/lib/sitemap.js +113 -3
- package/lib/ssqch.js +28 -0
- package/package.json +83 -80
- package/src/serve/live.js +174 -0
- package/src/serve/not-found.html +31 -0
- package/types/globals.d.ts +3 -2
- package/types/image.d.ts +7 -3
- package/types/index.d.ts +28 -9
- package/types/links.d.ts +1 -1
- package/types/minify.d.ts +1 -1
- package/types/rss.d.ts +1 -1
- package/types/sass.d.ts +1 -1
- package/types/sitemap.d.ts +2 -0
- package/wasm/markdown.wasm +0 -0
- package/wasm/minify.wasm +0 -0
- package/wasm/sass.wasm +0 -0
- package/lib/index.js +0 -3
- package/platforms.json +0 -6
|
@@ -0,0 +1,1350 @@
|
|
|
1
|
+
import { createRequire as __ssqchCreateRequire } from "node:module";
|
|
2
|
+
const require = __ssqchCreateRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
buildFiles,
|
|
5
|
+
urlOf
|
|
6
|
+
} from "./chunk-II5DEH3Q.js";
|
|
7
|
+
import "./chunk-7XLK2GEG.js";
|
|
8
|
+
import {
|
|
9
|
+
bytes,
|
|
10
|
+
count
|
|
11
|
+
} from "./chunk-NKXEPHRZ.js";
|
|
12
|
+
import "./chunk-DDV6JEC2.js";
|
|
13
|
+
import "./chunk-FVZ5JBRI.js";
|
|
14
|
+
import "./chunk-UU43WIZG.js";
|
|
15
|
+
import {
|
|
16
|
+
charCount,
|
|
17
|
+
firstChars,
|
|
18
|
+
quoted
|
|
19
|
+
} from "./chunk-CMUWRPSQ.js";
|
|
20
|
+
import {
|
|
21
|
+
BuildError,
|
|
22
|
+
bail
|
|
23
|
+
} from "./chunk-GRWMGC7D.js";
|
|
24
|
+
import {
|
|
25
|
+
compareText
|
|
26
|
+
} from "./chunk-VJWQSYEG.js";
|
|
27
|
+
import "./chunk-I3PS26CI.js";
|
|
28
|
+
|
|
29
|
+
// src/diff.ts
|
|
30
|
+
import fs from "node:fs";
|
|
31
|
+
import path from "node:path";
|
|
32
|
+
|
|
33
|
+
// src/myers.ts
|
|
34
|
+
function diffOps(old, next) {
|
|
35
|
+
const capture = new Capture();
|
|
36
|
+
const compact = new Compact(new Replace(capture), old, next);
|
|
37
|
+
diff(compact, old, 0, old.length, next, 0, next.length);
|
|
38
|
+
return capture.ops;
|
|
39
|
+
}
|
|
40
|
+
var Capture = class {
|
|
41
|
+
ops = [];
|
|
42
|
+
equal(oldIndex, newIndex, len) {
|
|
43
|
+
this.ops.push({ tag: "equal", oldIndex, oldLen: len, newIndex, newLen: len });
|
|
44
|
+
}
|
|
45
|
+
delete(oldIndex, oldLen, newIndex) {
|
|
46
|
+
this.ops.push({ tag: "delete", oldIndex, oldLen, newIndex, newLen: 0 });
|
|
47
|
+
}
|
|
48
|
+
insert(oldIndex, newIndex, newLen) {
|
|
49
|
+
this.ops.push({ tag: "insert", oldIndex, oldLen: 0, newIndex, newLen });
|
|
50
|
+
}
|
|
51
|
+
replace(oldIndex, oldLen, newIndex, newLen) {
|
|
52
|
+
this.ops.push({ tag: "replace", oldIndex, oldLen, newIndex, newLen });
|
|
53
|
+
}
|
|
54
|
+
finish() {
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var Replace = class {
|
|
58
|
+
d;
|
|
59
|
+
del;
|
|
60
|
+
ins;
|
|
61
|
+
eq;
|
|
62
|
+
constructor(d) {
|
|
63
|
+
this.d = d;
|
|
64
|
+
}
|
|
65
|
+
flushEq() {
|
|
66
|
+
if (this.eq) {
|
|
67
|
+
const [o, n, len] = this.eq;
|
|
68
|
+
this.eq = void 0;
|
|
69
|
+
this.d.equal(o, n, len);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
flushDelIns() {
|
|
73
|
+
if (this.del) {
|
|
74
|
+
const [o, ol, n] = this.del;
|
|
75
|
+
this.del = void 0;
|
|
76
|
+
if (this.ins) {
|
|
77
|
+
const [, insNew, insLen] = this.ins;
|
|
78
|
+
this.ins = void 0;
|
|
79
|
+
this.d.replace(o, ol, insNew, insLen);
|
|
80
|
+
} else this.d.delete(o, ol, n);
|
|
81
|
+
} else if (this.ins) {
|
|
82
|
+
const [o, n, nl] = this.ins;
|
|
83
|
+
this.ins = void 0;
|
|
84
|
+
this.d.insert(o, n, nl);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
equal(oldIndex, newIndex, len) {
|
|
88
|
+
this.flushDelIns();
|
|
89
|
+
this.eq = this.eq ? [this.eq[0], this.eq[1], this.eq[2] + len] : [oldIndex, newIndex, len];
|
|
90
|
+
}
|
|
91
|
+
delete(oldIndex, oldLen, newIndex) {
|
|
92
|
+
this.flushEq();
|
|
93
|
+
this.del = this.del ? [this.del[0], this.del[1] + oldLen, this.del[2]] : [oldIndex, oldLen, newIndex];
|
|
94
|
+
}
|
|
95
|
+
insert(oldIndex, newIndex, newLen) {
|
|
96
|
+
this.flushEq();
|
|
97
|
+
this.ins = this.ins ? [this.ins[0], this.ins[1], this.ins[2] + newLen] : [oldIndex, newIndex, newLen];
|
|
98
|
+
}
|
|
99
|
+
replace(oldIndex, oldLen, newIndex, newLen) {
|
|
100
|
+
this.flushEq();
|
|
101
|
+
this.d.replace(oldIndex, oldLen, newIndex, newLen);
|
|
102
|
+
}
|
|
103
|
+
finish() {
|
|
104
|
+
this.flushEq();
|
|
105
|
+
this.flushDelIns();
|
|
106
|
+
this.d.finish();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
var EQUAL = 0;
|
|
110
|
+
var DELETE = 1;
|
|
111
|
+
var INSERT = 2;
|
|
112
|
+
var oldStart = (op) => op.oldIndex;
|
|
113
|
+
var oldEnd = (op) => op.oldIndex + (op.tag === INSERT ? 0 : op.len);
|
|
114
|
+
var newStart = (op) => op.newIndex;
|
|
115
|
+
var newEnd = (op) => op.newIndex + (op.tag === DELETE ? 0 : op.len);
|
|
116
|
+
var isEmpty = (op) => oldEnd(op) <= oldStart(op) && newEnd(op) <= newStart(op);
|
|
117
|
+
var adjust = (op, offset, len) => {
|
|
118
|
+
op.oldIndex += offset;
|
|
119
|
+
op.newIndex += offset;
|
|
120
|
+
op.len += len;
|
|
121
|
+
};
|
|
122
|
+
var shiftLeft = (op, n) => adjust(op, -n, 0);
|
|
123
|
+
var shiftRight = (op, n) => adjust(op, n, 0);
|
|
124
|
+
var growLeft = (op, n) => adjust(op, -n, n);
|
|
125
|
+
var growRight = (op, n) => adjust(op, 0, n);
|
|
126
|
+
var shrinkLeft = (op, n) => adjust(op, 0, -n);
|
|
127
|
+
var shrinkRight = (op, n) => adjust(op, n, -n);
|
|
128
|
+
var Compact = class {
|
|
129
|
+
d;
|
|
130
|
+
ops = [];
|
|
131
|
+
old;
|
|
132
|
+
next;
|
|
133
|
+
constructor(d, old, next) {
|
|
134
|
+
this.d = d;
|
|
135
|
+
this.old = old;
|
|
136
|
+
this.next = next;
|
|
137
|
+
}
|
|
138
|
+
equal(oldIndex, newIndex, len) {
|
|
139
|
+
this.ops.push({ tag: EQUAL, oldIndex, newIndex, len });
|
|
140
|
+
}
|
|
141
|
+
delete(oldIndex, oldLen, newIndex) {
|
|
142
|
+
this.ops.push({ tag: DELETE, oldIndex, newIndex, len: oldLen });
|
|
143
|
+
}
|
|
144
|
+
insert(oldIndex, newIndex, newLen) {
|
|
145
|
+
this.ops.push({ tag: INSERT, oldIndex, newIndex, len: newLen });
|
|
146
|
+
}
|
|
147
|
+
replace(oldIndex, oldLen, newIndex, newLen) {
|
|
148
|
+
this.delete(oldIndex, oldLen, newIndex);
|
|
149
|
+
this.insert(oldIndex, newIndex, newLen);
|
|
150
|
+
}
|
|
151
|
+
finish() {
|
|
152
|
+
const { ops, old, next } = this;
|
|
153
|
+
shiftAll(ops, old, next);
|
|
154
|
+
normalizeCursors(ops);
|
|
155
|
+
for (const op of ops) {
|
|
156
|
+
if (op.tag === EQUAL) this.d.equal(op.oldIndex, op.newIndex, op.len);
|
|
157
|
+
else if (op.tag === DELETE) this.d.delete(op.oldIndex, op.len, op.newIndex);
|
|
158
|
+
else this.d.insert(op.oldIndex, op.newIndex, op.len);
|
|
159
|
+
}
|
|
160
|
+
this.d.finish();
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
function shiftAll(ops, old, next) {
|
|
164
|
+
for (const tag of [DELETE, INSERT]) {
|
|
165
|
+
let pointer = 0;
|
|
166
|
+
while (pointer < ops.length) {
|
|
167
|
+
if (ops[pointer].tag === tag) {
|
|
168
|
+
pointer = shiftUp(ops, old, next, pointer);
|
|
169
|
+
pointer = shiftDown(ops, old, next, pointer);
|
|
170
|
+
}
|
|
171
|
+
pointer += 1;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
function normalizeCursors(ops) {
|
|
176
|
+
if (!ops.length) return;
|
|
177
|
+
let oldCursor = oldStart(ops[0]);
|
|
178
|
+
let newCursor = newStart(ops[0]);
|
|
179
|
+
for (const op of ops) {
|
|
180
|
+
if (op.tag === EQUAL) {
|
|
181
|
+
oldCursor = op.oldIndex + op.len;
|
|
182
|
+
newCursor = op.newIndex + op.len;
|
|
183
|
+
} else if (op.tag === DELETE) {
|
|
184
|
+
op.newIndex = newCursor;
|
|
185
|
+
oldCursor = op.oldIndex + op.len;
|
|
186
|
+
} else {
|
|
187
|
+
op.oldIndex = oldCursor;
|
|
188
|
+
newCursor = op.newIndex + op.len;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function swapAdjacent(ops, left) {
|
|
193
|
+
const right = left + 1;
|
|
194
|
+
const oStart = oldStart(ops[left]);
|
|
195
|
+
const oEnd = oldEnd(ops[right]);
|
|
196
|
+
const nStart = newStart(ops[left]);
|
|
197
|
+
const nEnd = newEnd(ops[right]);
|
|
198
|
+
[ops[left], ops[right]] = [ops[right], ops[left]];
|
|
199
|
+
if (ops[left].tag === INSERT) ops[left].oldIndex = oStart;
|
|
200
|
+
else ops[left].newIndex = nStart;
|
|
201
|
+
if (ops[right].tag === INSERT) ops[right].oldIndex = oEnd;
|
|
202
|
+
else ops[right].newIndex = nEnd;
|
|
203
|
+
}
|
|
204
|
+
var copy = (op) => ({ ...op });
|
|
205
|
+
function shiftUp(ops, old, next, pointer) {
|
|
206
|
+
while (pointer >= 1 && pointer - 1 < ops.length) {
|
|
207
|
+
const prev = copy(ops[pointer - 1]);
|
|
208
|
+
const self = copy(ops[pointer]);
|
|
209
|
+
if ((self.tag === INSERT || self.tag === DELETE) && prev.tag === EQUAL) {
|
|
210
|
+
if (self.tag === DELETE && !(pointer >= 2 && ops[pointer - 2]?.tag === DELETE)) break;
|
|
211
|
+
const suffix = self.tag === INSERT ? commonSuffixLen(old, oldStart(prev), oldEnd(prev), next, newStart(self), newEnd(self)) : commonSuffixLen(old, oldStart(self), oldEnd(self), next, newStart(prev), newEnd(prev));
|
|
212
|
+
if (suffix > 0) {
|
|
213
|
+
if (ops[pointer + 1]?.tag === EQUAL) growLeft(ops[pointer + 1], suffix);
|
|
214
|
+
else {
|
|
215
|
+
const equalOld = (self.tag === INSERT ? oldEnd(prev) : oldEnd(self)) - suffix;
|
|
216
|
+
const equalNew = (self.tag === INSERT ? newEnd(self) : newEnd(prev)) - suffix;
|
|
217
|
+
ops.splice(pointer + 1, 0, { tag: EQUAL, oldIndex: equalOld, newIndex: equalNew, len: suffix });
|
|
218
|
+
}
|
|
219
|
+
shiftLeft(ops[pointer], suffix);
|
|
220
|
+
shrinkLeft(ops[pointer - 1], suffix);
|
|
221
|
+
if (isEmpty(ops[pointer - 1])) {
|
|
222
|
+
ops.splice(pointer - 1, 1);
|
|
223
|
+
pointer -= 1;
|
|
224
|
+
}
|
|
225
|
+
} else if (isEmpty(ops[pointer - 1])) {
|
|
226
|
+
ops.splice(pointer - 1, 1);
|
|
227
|
+
pointer -= 1;
|
|
228
|
+
} else break;
|
|
229
|
+
} else if (self.tag === INSERT && prev.tag === DELETE || self.tag === DELETE && prev.tag === INSERT) {
|
|
230
|
+
swapAdjacent(ops, pointer - 1);
|
|
231
|
+
pointer -= 1;
|
|
232
|
+
} else if (self.tag === prev.tag && self.tag !== EQUAL) {
|
|
233
|
+
growRight(ops[pointer - 1], self.len);
|
|
234
|
+
ops.splice(pointer, 1);
|
|
235
|
+
pointer -= 1;
|
|
236
|
+
} else throw new Error(`unexpected ops in the diff's cleanup: ${prev.tag} then ${self.tag}`);
|
|
237
|
+
}
|
|
238
|
+
return pointer;
|
|
239
|
+
}
|
|
240
|
+
function shiftDown(ops, old, next, pointer) {
|
|
241
|
+
while (pointer + 1 < ops.length) {
|
|
242
|
+
const following = copy(ops[pointer + 1]);
|
|
243
|
+
const self = copy(ops[pointer]);
|
|
244
|
+
if ((self.tag === INSERT || self.tag === DELETE) && following.tag === EQUAL) {
|
|
245
|
+
if (self.tag === DELETE && ops[pointer + 2]?.tag !== DELETE) break;
|
|
246
|
+
const prefix = self.tag === INSERT ? commonPrefixLen(old, oldStart(following), oldEnd(following), next, newStart(self), newEnd(self)) : commonPrefixLen(old, oldStart(self), oldEnd(self), next, newStart(following), newEnd(following));
|
|
247
|
+
if (prefix > 0) {
|
|
248
|
+
if (pointer >= 1 && ops[pointer - 1].tag === EQUAL) growRight(ops[pointer - 1], prefix);
|
|
249
|
+
else {
|
|
250
|
+
const equalOld = self.tag === INSERT ? oldStart(following) : oldStart(self);
|
|
251
|
+
ops.splice(pointer, 0, { tag: EQUAL, oldIndex: equalOld, newIndex: newStart(self), len: prefix });
|
|
252
|
+
pointer += 1;
|
|
253
|
+
}
|
|
254
|
+
shiftRight(ops[pointer], prefix);
|
|
255
|
+
shrinkRight(ops[pointer + 1], prefix);
|
|
256
|
+
if (isEmpty(ops[pointer + 1])) ops.splice(pointer + 1, 1);
|
|
257
|
+
} else if (isEmpty(ops[pointer + 1])) ops.splice(pointer + 1, 1);
|
|
258
|
+
else break;
|
|
259
|
+
} else if (self.tag === INSERT && following.tag === DELETE || self.tag === DELETE && following.tag === INSERT) {
|
|
260
|
+
swapAdjacent(ops, pointer);
|
|
261
|
+
pointer += 1;
|
|
262
|
+
} else if (self.tag === following.tag && self.tag !== EQUAL) {
|
|
263
|
+
growRight(ops[pointer], following.len);
|
|
264
|
+
ops.splice(pointer + 1, 1);
|
|
265
|
+
} else throw new Error(`unexpected ops in the diff's cleanup: ${self.tag} then ${following.tag}`);
|
|
266
|
+
}
|
|
267
|
+
return pointer;
|
|
268
|
+
}
|
|
269
|
+
function commonPrefixLen(old, os, oe, next, ns, ne) {
|
|
270
|
+
if (os >= oe || ns >= ne) return 0;
|
|
271
|
+
const max = Math.min(oe - os, ne - ns);
|
|
272
|
+
let n = 0;
|
|
273
|
+
while (n < max && next[ns + n] === old[os + n]) n++;
|
|
274
|
+
return n;
|
|
275
|
+
}
|
|
276
|
+
function commonSuffixLen(old, os, oe, next, ns, ne) {
|
|
277
|
+
if (os >= oe || ns >= ne) return 0;
|
|
278
|
+
const max = Math.min(oe - os, ne - ns);
|
|
279
|
+
let n = 0;
|
|
280
|
+
while (n < max && next[ne - 1 - n] === old[oe - 1 - n]) n++;
|
|
281
|
+
return n;
|
|
282
|
+
}
|
|
283
|
+
var DISJOINT_FAST_PATH_MIN_LEN = 512;
|
|
284
|
+
var DISJOINT_FAST_PATH_MIN_WORK = 128 * 1024;
|
|
285
|
+
var DISJOINT_FAST_PATH_BOUNDARY_PROBE = 8;
|
|
286
|
+
var CONFUSING_RECORD_SCAN_WINDOW = 100;
|
|
287
|
+
var CONFUSING_RECORD_RATIO = 4;
|
|
288
|
+
var MAX_MATCH_FREQUENCY_THRESHOLD = 1024;
|
|
289
|
+
var NO_MATCH = -1;
|
|
290
|
+
var DISCARD = 0;
|
|
291
|
+
var KEEP = 1;
|
|
292
|
+
var INVESTIGATE = 2;
|
|
293
|
+
var isqrt = (n) => {
|
|
294
|
+
let r = Math.floor(Math.sqrt(n));
|
|
295
|
+
while (r * r > n) r--;
|
|
296
|
+
while ((r + 1) * (r + 1) <= n) r++;
|
|
297
|
+
return r;
|
|
298
|
+
};
|
|
299
|
+
function diff(d, old, os, oe, next, ns, ne) {
|
|
300
|
+
const pre = reduceForMyers(old, os, oe, next, ns, ne);
|
|
301
|
+
if ("trimmed" in pre) diffReduced(d, pre);
|
|
302
|
+
else diffPretrimmed(d, old, next, pre, HEURISTIC);
|
|
303
|
+
}
|
|
304
|
+
function trim(old, os, oe, next, ns, ne) {
|
|
305
|
+
const prefixLen = commonPrefixLen(old, os, oe, next, ns, ne);
|
|
306
|
+
const suffixLen = commonSuffixLen(old, os + prefixLen, oe, next, ns + prefixLen, ne);
|
|
307
|
+
return { oldStart: os + prefixLen, oldEnd: oe - suffixLen, newStart: ns + prefixLen, newEnd: ne - suffixLen, originalOldStart: os, originalOldEnd: oe, originalNewStart: ns, originalNewEnd: ne, prefixLen, suffixLen };
|
|
308
|
+
}
|
|
309
|
+
function shouldScan(old, os, oe, next, ns, ne) {
|
|
310
|
+
const oldLen = oe - os, newLen = ne - ns;
|
|
311
|
+
if (oldLen < DISJOINT_FAST_PATH_MIN_LEN || newLen < DISJOINT_FAST_PATH_MIN_LEN || oldLen * newLen < DISJOINT_FAST_PATH_MIN_WORK) return false;
|
|
312
|
+
if (next[ns] === old[os] || next[ne - 1] === old[oe - 1]) return false;
|
|
313
|
+
const probe = Math.min(oldLen, newLen, DISJOINT_FAST_PATH_BOUNDARY_PROBE + 1);
|
|
314
|
+
for (let skip = 1; skip < probe; skip++) {
|
|
315
|
+
if (next[ns + skip] === old[os] || next[ns] === old[os + skip] || next[ne - 1 - skip] === old[oe - 1] || next[ne - 1] === old[oe - 1 - skip]) return false;
|
|
316
|
+
}
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
function recordActions(ids2, oppositeCounts) {
|
|
320
|
+
const limit = Math.min(Math.max(isqrt(ids2.length), 1), MAX_MATCH_FREQUENCY_THRESHOLD);
|
|
321
|
+
const out = new Uint8Array(ids2.length);
|
|
322
|
+
ids2.forEach((id, i) => {
|
|
323
|
+
const count2 = id === NO_MATCH ? 0 : oppositeCounts[id];
|
|
324
|
+
out[i] = count2 === 0 ? DISCARD : count2 < limit ? KEEP : INVESTIGATE;
|
|
325
|
+
});
|
|
326
|
+
return out;
|
|
327
|
+
}
|
|
328
|
+
function scanConfusingRun(actions, from, step) {
|
|
329
|
+
let discards = 0, investigates = 0;
|
|
330
|
+
for (let i = from, seen2 = 0; i >= 0 && i < actions.length && seen2 < CONFUSING_RECORD_SCAN_WINDOW; i += step, seen2++) {
|
|
331
|
+
if (actions[i] === DISCARD) discards++;
|
|
332
|
+
else if (actions[i] === INVESTIGATE) investigates++;
|
|
333
|
+
else break;
|
|
334
|
+
}
|
|
335
|
+
return [discards, investigates];
|
|
336
|
+
}
|
|
337
|
+
function keepRecord(actions, index) {
|
|
338
|
+
if (actions[index] === DISCARD) return false;
|
|
339
|
+
if (actions[index] === KEEP) return true;
|
|
340
|
+
const [leftDiscards, leftInvestigates] = scanConfusingRun(actions, index - 1, -1);
|
|
341
|
+
if (leftDiscards === 0) return true;
|
|
342
|
+
const [rightDiscards, rightInvestigates] = scanConfusingRun(actions, index + 1, 1);
|
|
343
|
+
if (rightDiscards === 0) return true;
|
|
344
|
+
const discards = leftDiscards + rightDiscards;
|
|
345
|
+
const investigates = leftInvestigates + rightInvestigates + 1;
|
|
346
|
+
return !(investigates * CONFUSING_RECORD_RATIO < investigates + discards);
|
|
347
|
+
}
|
|
348
|
+
function reduceForMyers(old, os, oe, next, ns, ne) {
|
|
349
|
+
const trimmed = trim(old, os, oe, next, ns, ne);
|
|
350
|
+
const { oldStart: o0, oldEnd: o1, newStart: n0, newEnd: n1 } = trimmed;
|
|
351
|
+
if (!shouldScan(old, o0, o1, next, n0, n1)) return trimmed;
|
|
352
|
+
const ids2 = /* @__PURE__ */ new Map();
|
|
353
|
+
const oldValues = [];
|
|
354
|
+
const newValues = [];
|
|
355
|
+
const oldCounts = [];
|
|
356
|
+
const newCounts = [];
|
|
357
|
+
for (let i = o0; i < o1; i++) {
|
|
358
|
+
let id = ids2.get(old[i]);
|
|
359
|
+
if (id === void 0) {
|
|
360
|
+
id = oldCounts.length;
|
|
361
|
+
ids2.set(old[i], id);
|
|
362
|
+
oldCounts.push(0);
|
|
363
|
+
newCounts.push(0);
|
|
364
|
+
}
|
|
365
|
+
oldCounts[id]++;
|
|
366
|
+
oldValues.push(id);
|
|
367
|
+
}
|
|
368
|
+
for (let i = n0; i < n1; i++) {
|
|
369
|
+
const id = ids2.get(next[i]) ?? NO_MATCH;
|
|
370
|
+
if (id !== NO_MATCH) newCounts[id]++;
|
|
371
|
+
newValues.push(id);
|
|
372
|
+
}
|
|
373
|
+
const reduced = { oldValues: [], oldIndices: [], newValues: [], newIndices: [], trimmed };
|
|
374
|
+
const oldActions = recordActions(oldValues, newCounts);
|
|
375
|
+
oldValues.forEach((id, offset) => {
|
|
376
|
+
if (keepRecord(oldActions, offset)) {
|
|
377
|
+
reduced.oldValues.push(id);
|
|
378
|
+
reduced.oldIndices.push(o0 + offset);
|
|
379
|
+
}
|
|
380
|
+
});
|
|
381
|
+
const newActions = recordActions(newValues, oldCounts);
|
|
382
|
+
newValues.forEach((id, offset) => {
|
|
383
|
+
if (keepRecord(newActions, offset)) {
|
|
384
|
+
reduced.newValues.push(id);
|
|
385
|
+
reduced.newIndices.push(n0 + offset);
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
if (reduced.oldIndices.length === o1 - o0 && reduced.newIndices.length === n1 - n0) return trimmed;
|
|
389
|
+
return reduced;
|
|
390
|
+
}
|
|
391
|
+
var ReducedHook = class {
|
|
392
|
+
d;
|
|
393
|
+
reduced;
|
|
394
|
+
oldCursor;
|
|
395
|
+
newCursor;
|
|
396
|
+
constructor(d, reduced) {
|
|
397
|
+
this.d = d;
|
|
398
|
+
this.reduced = reduced;
|
|
399
|
+
this.oldCursor = reduced.trimmed.oldStart;
|
|
400
|
+
this.newCursor = reduced.trimmed.newStart;
|
|
401
|
+
}
|
|
402
|
+
gaps(oldAnchor, newAnchor) {
|
|
403
|
+
if (this.oldCursor < oldAnchor) {
|
|
404
|
+
this.d.delete(this.oldCursor, oldAnchor - this.oldCursor, this.newCursor);
|
|
405
|
+
this.oldCursor = oldAnchor;
|
|
406
|
+
}
|
|
407
|
+
if (this.newCursor < newAnchor) {
|
|
408
|
+
this.d.insert(this.oldCursor, this.newCursor, newAnchor - this.newCursor);
|
|
409
|
+
this.newCursor = newAnchor;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
equal(oldIndex, newIndex, len) {
|
|
413
|
+
const { oldIndices, newIndices } = this.reduced;
|
|
414
|
+
let offset = 0;
|
|
415
|
+
while (offset < len) {
|
|
416
|
+
const oldAnchor = oldIndices[oldIndex + offset];
|
|
417
|
+
const newAnchor = newIndices[newIndex + offset];
|
|
418
|
+
this.gaps(oldAnchor, newAnchor);
|
|
419
|
+
let run = 1;
|
|
420
|
+
while (offset + run < len && oldIndices[oldIndex + offset + run] === oldAnchor + run && newIndices[newIndex + offset + run] === newAnchor + run) run++;
|
|
421
|
+
this.d.equal(oldAnchor, newAnchor, run);
|
|
422
|
+
this.oldCursor = oldAnchor + run;
|
|
423
|
+
this.newCursor = newAnchor + run;
|
|
424
|
+
offset += run;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
delete() {
|
|
428
|
+
}
|
|
429
|
+
insert() {
|
|
430
|
+
}
|
|
431
|
+
replace() {
|
|
432
|
+
}
|
|
433
|
+
finish() {
|
|
434
|
+
this.gaps(this.reduced.trimmed.oldEnd, this.reduced.trimmed.newEnd);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
function diffReduced(d, reduced) {
|
|
438
|
+
const t = reduced.trimmed;
|
|
439
|
+
if (t.prefixLen > 0) d.equal(t.originalOldStart, t.originalNewStart, t.prefixLen);
|
|
440
|
+
const hook = new ReducedHook(d, reduced);
|
|
441
|
+
const { oldValues, newValues } = reduced;
|
|
442
|
+
diffPretrimmed(hook, oldValues, newValues, trim(oldValues, 0, oldValues.length, newValues, 0, newValues.length), HEURISTIC);
|
|
443
|
+
if (t.suffixLen > 0) d.equal(t.originalOldEnd - t.suffixLen, t.originalNewEnd - t.suffixLen, t.suffixLen);
|
|
444
|
+
d.finish();
|
|
445
|
+
}
|
|
446
|
+
var HEURISTIC = 0;
|
|
447
|
+
var RAW = 1;
|
|
448
|
+
function diffPretrimmed(d, old, next, t, mode) {
|
|
449
|
+
if (t.prefixLen > 0) d.equal(t.originalOldStart, t.originalNewStart, t.prefixLen);
|
|
450
|
+
const oldEmpty = t.oldStart >= t.oldEnd, newEmpty = t.newStart >= t.newEnd;
|
|
451
|
+
if (oldEmpty && newEmpty) {
|
|
452
|
+
} else if (oldEmpty) d.insert(t.oldStart, t.newStart, t.newEnd - t.newStart);
|
|
453
|
+
else if (newEmpty) d.delete(t.oldStart, t.oldEnd - t.oldStart, t.newStart);
|
|
454
|
+
else {
|
|
455
|
+
const maxD = maxDiagonals(t.oldEnd - t.oldStart, t.newEnd - t.newStart);
|
|
456
|
+
conquer(d, old, t.oldStart, t.oldEnd, next, t.newStart, t.newEnd, new V(maxD), new V(maxD), mode);
|
|
457
|
+
}
|
|
458
|
+
if (t.suffixLen > 0) d.equal(t.originalOldEnd - t.suffixLen, t.originalNewEnd - t.suffixLen, t.suffixLen);
|
|
459
|
+
d.finish();
|
|
460
|
+
}
|
|
461
|
+
var V = class {
|
|
462
|
+
offset;
|
|
463
|
+
v;
|
|
464
|
+
constructor(maxD) {
|
|
465
|
+
this.offset = maxD;
|
|
466
|
+
this.v = new Int32Array(2 * maxD);
|
|
467
|
+
}
|
|
468
|
+
get(k) {
|
|
469
|
+
return this.v[k + this.offset];
|
|
470
|
+
}
|
|
471
|
+
set(k, x) {
|
|
472
|
+
this.v[k + this.offset] = x;
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
var maxDiagonals = (n, m) => Math.ceil((n + m) / 2) + 1;
|
|
476
|
+
var SMALL_SIDE_EXACT_MAX = 64;
|
|
477
|
+
var SMALL_SIDE_EXACT_MIN_LARGE = 512;
|
|
478
|
+
var SMALL_SIDE_EXACT_MAX_WORK = 64e6;
|
|
479
|
+
var HEURISTIC_MIN_COST = 256;
|
|
480
|
+
var HEURISTIC_MIN_SNAKE = 20;
|
|
481
|
+
var HEURISTIC_MIN_MAX_COST = 256;
|
|
482
|
+
var HEURISTIC_PROGRESS_FACTOR = 4;
|
|
483
|
+
function conquer(d, old, os, oe, next, ns, ne, vf, vb, mode) {
|
|
484
|
+
const prefix = commonPrefixLen(old, os, oe, next, ns, ne);
|
|
485
|
+
if (prefix > 0) d.equal(os, ns, prefix);
|
|
486
|
+
os += prefix;
|
|
487
|
+
ns += prefix;
|
|
488
|
+
const suffix = commonSuffixLen(old, os, oe, next, ns, ne);
|
|
489
|
+
const suffixOld = oe - suffix, suffixNew = ne - suffix;
|
|
490
|
+
oe -= suffix;
|
|
491
|
+
ne -= suffix;
|
|
492
|
+
while (os < oe && ns < ne) {
|
|
493
|
+
const [o, n] = frontAnchor(d, old, os, oe, next, ns, ne);
|
|
494
|
+
if (o === os && n === ns) break;
|
|
495
|
+
os = o;
|
|
496
|
+
ns = n;
|
|
497
|
+
}
|
|
498
|
+
if (os >= oe && ns >= ne) {
|
|
499
|
+
} else if (ns >= ne) d.delete(os, oe - os, ns);
|
|
500
|
+
else if (os >= oe) d.insert(os, ns, ne - ns);
|
|
501
|
+
else if (smallSideExact(d, old, os, oe, next, ns, ne)) {
|
|
502
|
+
} else {
|
|
503
|
+
const split = middleSnake(old, os, oe, next, ns, ne, vf, vb, mode);
|
|
504
|
+
if (split) {
|
|
505
|
+
conquer(d, old, os, split.oldIndex, next, ns, split.newIndex, vf, vb, split.leftMode);
|
|
506
|
+
conquer(d, old, split.oldIndex, oe, next, split.newIndex, ne, vf, vb, split.rightMode);
|
|
507
|
+
} else {
|
|
508
|
+
d.delete(os, oe - os, ns);
|
|
509
|
+
d.insert(os, ns, ne - ns);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
if (suffix > 0) d.equal(suffixOld, suffixNew, suffix);
|
|
513
|
+
}
|
|
514
|
+
function frontAnchor(d, old, os, oe, next, ns, ne) {
|
|
515
|
+
const MAX_SKIP = 4;
|
|
516
|
+
const MIN_ANCHOR_COMMON = 96;
|
|
517
|
+
const oldLen = oe - os, newLen = ne - ns;
|
|
518
|
+
if (oldLen <= MIN_ANCHOR_COMMON || newLen <= MIN_ANCHOR_COMMON) return [os, ns];
|
|
519
|
+
const small = Math.min(oldLen, newLen), large = Math.max(oldLen, newLen);
|
|
520
|
+
if (large < small * 2) return [os, ns];
|
|
521
|
+
const maxOldSkip = Math.min(oldLen - 1, MAX_SKIP);
|
|
522
|
+
const maxNewSkip = Math.min(newLen - 1, MAX_SKIP);
|
|
523
|
+
const preferInsert = newLen > oldLen;
|
|
524
|
+
const preferDelete = oldLen > newLen;
|
|
525
|
+
let best;
|
|
526
|
+
search: for (let oldSkip2 = 0; oldSkip2 <= maxOldSkip; oldSkip2++) {
|
|
527
|
+
for (let newSkip2 = 0; newSkip2 <= maxNewSkip; newSkip2++) {
|
|
528
|
+
if (oldSkip2 === 0 && newSkip2 === 0) continue;
|
|
529
|
+
if (oldSkip2 !== 0 && newSkip2 !== 0) continue;
|
|
530
|
+
if (preferInsert && oldSkip2 !== 0) continue;
|
|
531
|
+
if (preferDelete && newSkip2 !== 0) continue;
|
|
532
|
+
if (next[ns + newSkip2] !== old[os + oldSkip2]) continue;
|
|
533
|
+
const common2 = commonPrefixLen(old, os + oldSkip2, oe, next, ns + newSkip2, ne);
|
|
534
|
+
if (common2 < MIN_ANCHOR_COMMON) continue;
|
|
535
|
+
if (common2 >= MIN_ANCHOR_COMMON * 8) {
|
|
536
|
+
best = [oldSkip2, newSkip2, common2];
|
|
537
|
+
break search;
|
|
538
|
+
}
|
|
539
|
+
const better2 = best === void 0 || compareTuples([common2, -Math.max(oldSkip2, newSkip2), oldSkip2, newSkip2], [best[2], -Math.max(best[0], best[1]), best[0], best[1]]) > 0;
|
|
540
|
+
if (better2) best = [oldSkip2, newSkip2, common2];
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (!best) return [os, ns];
|
|
544
|
+
const [oldSkip, newSkip, common] = best;
|
|
545
|
+
if (oldSkip === 0) d.insert(os, ns, newSkip);
|
|
546
|
+
else if (newSkip === 0) d.delete(os, oldSkip, ns);
|
|
547
|
+
else d.replace(os, oldSkip, ns, newSkip);
|
|
548
|
+
d.equal(os + oldSkip, ns + newSkip, common);
|
|
549
|
+
return [os + oldSkip + common, ns + newSkip + common];
|
|
550
|
+
}
|
|
551
|
+
function compareTuples(a, b) {
|
|
552
|
+
for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return a[i] - b[i];
|
|
553
|
+
return 0;
|
|
554
|
+
}
|
|
555
|
+
function smallSideExact(d, old, os, oe, next, ns, ne) {
|
|
556
|
+
const oldLen = oe - os, newLen = ne - ns;
|
|
557
|
+
const small = Math.min(oldLen, newLen), large = Math.max(oldLen, newLen);
|
|
558
|
+
if (small === 0 || small > SMALL_SIDE_EXACT_MAX || large < SMALL_SIDE_EXACT_MIN_LARGE || oldLen * newLen > SMALL_SIDE_EXACT_MAX_WORK) return false;
|
|
559
|
+
if (oldLen <= newLen) smallOld(d, old, os, oldLen, next, ns, newLen);
|
|
560
|
+
else smallNew(d, old, os, oldLen, next, ns, newLen);
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
function smallOld(d, old, os, n, next, ns, m) {
|
|
564
|
+
const width = m + 1;
|
|
565
|
+
const dp = new Uint8Array((n + 1) * width);
|
|
566
|
+
for (let i2 = n - 1; i2 >= 0; i2--) {
|
|
567
|
+
const row = i2 * width, below = (i2 + 1) * width;
|
|
568
|
+
for (let j2 = m - 1; j2 >= 0; j2--) dp[row + j2] = next[ns + j2] === old[os + i2] ? dp[below + j2 + 1] + 1 : Math.max(dp[below + j2], dp[row + j2 + 1]);
|
|
569
|
+
}
|
|
570
|
+
const takes = (i2, j2) => next[ns + j2] === old[os + i2] && dp[i2 * width + j2] === dp[(i2 + 1) * width + j2 + 1] + 1;
|
|
571
|
+
let i = 0, j = 0;
|
|
572
|
+
while (i < n && j < m) {
|
|
573
|
+
if (takes(i, j)) {
|
|
574
|
+
const si = i, sj = j;
|
|
575
|
+
while (i < n && j < m && takes(i, j)) {
|
|
576
|
+
i++;
|
|
577
|
+
j++;
|
|
578
|
+
}
|
|
579
|
+
d.equal(os + si, ns + sj, i - si);
|
|
580
|
+
} else if (dp[(i + 1) * width + j] >= dp[i * width + j + 1]) {
|
|
581
|
+
const si = i;
|
|
582
|
+
const at = ns + j;
|
|
583
|
+
while (i < n) {
|
|
584
|
+
if (j >= m) {
|
|
585
|
+
i = n;
|
|
586
|
+
break;
|
|
587
|
+
}
|
|
588
|
+
if (takes(i, j)) break;
|
|
589
|
+
if (dp[(i + 1) * width + j] >= dp[i * width + j + 1]) i++;
|
|
590
|
+
else break;
|
|
591
|
+
}
|
|
592
|
+
d.delete(os + si, i - si, at);
|
|
593
|
+
} else {
|
|
594
|
+
const sj = j;
|
|
595
|
+
const at = os + i;
|
|
596
|
+
while (j < m) {
|
|
597
|
+
if (i >= n) {
|
|
598
|
+
j = m;
|
|
599
|
+
break;
|
|
600
|
+
}
|
|
601
|
+
if (takes(i, j)) break;
|
|
602
|
+
if (dp[(i + 1) * width + j] < dp[i * width + j + 1]) j++;
|
|
603
|
+
else break;
|
|
604
|
+
}
|
|
605
|
+
d.insert(at, ns + sj, j - sj);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
if (i < n) d.delete(os + i, n - i, ns + j);
|
|
609
|
+
if (j < m) d.insert(os + i, ns + j, m - j);
|
|
610
|
+
}
|
|
611
|
+
function smallNew(d, old, os, n, next, ns, m) {
|
|
612
|
+
const width = n + 1;
|
|
613
|
+
const dp = new Uint8Array((m + 1) * width);
|
|
614
|
+
for (let i2 = m - 1; i2 >= 0; i2--) {
|
|
615
|
+
const row = i2 * width, below = (i2 + 1) * width;
|
|
616
|
+
for (let j2 = n - 1; j2 >= 0; j2--) dp[row + j2] = next[ns + i2] === old[os + j2] ? dp[below + j2 + 1] + 1 : Math.max(dp[below + j2], dp[row + j2 + 1]);
|
|
617
|
+
}
|
|
618
|
+
const takes = (i2, j2) => next[ns + i2] === old[os + j2] && dp[i2 * width + j2] === dp[(i2 + 1) * width + j2 + 1] + 1;
|
|
619
|
+
let i = 0, j = 0;
|
|
620
|
+
while (i < m && j < n) {
|
|
621
|
+
if (takes(i, j)) {
|
|
622
|
+
const si = i, sj = j;
|
|
623
|
+
while (i < m && j < n && takes(i, j)) {
|
|
624
|
+
i++;
|
|
625
|
+
j++;
|
|
626
|
+
}
|
|
627
|
+
d.equal(os + sj, ns + si, j - sj);
|
|
628
|
+
} else if (dp[(i + 1) * width + j] >= dp[i * width + j + 1]) {
|
|
629
|
+
const si = i;
|
|
630
|
+
const at = os + j;
|
|
631
|
+
while (i < m) {
|
|
632
|
+
if (j >= n) {
|
|
633
|
+
i = m;
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
if (takes(i, j)) break;
|
|
637
|
+
if (dp[(i + 1) * width + j] >= dp[i * width + j + 1]) i++;
|
|
638
|
+
else break;
|
|
639
|
+
}
|
|
640
|
+
d.insert(at, ns + si, i - si);
|
|
641
|
+
} else {
|
|
642
|
+
const sj = j;
|
|
643
|
+
const at = ns + i;
|
|
644
|
+
while (j < n) {
|
|
645
|
+
if (i >= m) {
|
|
646
|
+
j = n;
|
|
647
|
+
break;
|
|
648
|
+
}
|
|
649
|
+
if (takes(i, j)) break;
|
|
650
|
+
if (dp[(i + 1) * width + j] < dp[i * width + j + 1]) j++;
|
|
651
|
+
else break;
|
|
652
|
+
}
|
|
653
|
+
d.delete(os + sj, j - sj, at);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (j < n) d.delete(os + j, n - j, ns + i);
|
|
657
|
+
if (i < m) d.insert(os + j, ns + i, m - i);
|
|
658
|
+
}
|
|
659
|
+
var better = (best, candidate) => best === void 0 || candidate.progress > best.progress ? candidate : best;
|
|
660
|
+
var isInterior = (o, n, oldLen, newLen) => o <= oldLen && n <= newLen && (o !== 0 || n !== 0) && (o !== oldLen || n !== newLen);
|
|
661
|
+
function clampDiagonal(oldIndex, k, oldLen, newLen) {
|
|
662
|
+
if (k < 0 && -k > newLen) return void 0;
|
|
663
|
+
const min = Math.max(k, 0);
|
|
664
|
+
const max = k >= 0 ? Math.min(oldLen, newLen + k) : Math.min(oldLen, Math.max(0, newLen + k));
|
|
665
|
+
if (min > max) return void 0;
|
|
666
|
+
const o = Math.min(Math.max(oldIndex, min), max);
|
|
667
|
+
return [o, o - k];
|
|
668
|
+
}
|
|
669
|
+
function middleSnake(old, os, oe, next, ns, ne, vf, vb, mode) {
|
|
670
|
+
const n = oe - os, m = ne - ns;
|
|
671
|
+
const delta = n - m;
|
|
672
|
+
const odd = (delta & 1) === 1 || (delta & 1) === -1;
|
|
673
|
+
vf.set(1, 0);
|
|
674
|
+
vb.set(1, 0);
|
|
675
|
+
const dMax = maxDiagonals(n, m);
|
|
676
|
+
const maxCost = mode === HEURISTIC ? Math.max(isqrt(n + m), HEURISTIC_MIN_MAX_COST) : Infinity;
|
|
677
|
+
const heuristic = (c) => ({ oldIndex: os + c.oldIndex, newIndex: ns + c.newIndex, leftMode: c.forward ? RAW : HEURISTIC, rightMode: c.forward ? HEURISTIC : RAW });
|
|
678
|
+
for (let d = 0; d < dMax; d++) {
|
|
679
|
+
let good, forward, backward;
|
|
680
|
+
const trackLimit = mode === HEURISTIC && d >= maxCost;
|
|
681
|
+
const trackGood = mode === HEURISTIC && d > HEURISTIC_MIN_COST;
|
|
682
|
+
for (let k = d; k >= -d; k -= 2) {
|
|
683
|
+
let x = k === -d || k !== d && vf.get(k - 1) < vf.get(k + 1) ? vf.get(k + 1) : vf.get(k - 1) + 1;
|
|
684
|
+
const y = x - k;
|
|
685
|
+
const x0 = x, y0 = y;
|
|
686
|
+
if (x < n && y < m) x += commonPrefixLen(old, os + x, oe, next, ns + y, ne);
|
|
687
|
+
const snake = x - x0;
|
|
688
|
+
vf.set(k, x);
|
|
689
|
+
if (odd && Math.abs(k - delta) <= d - 1 && vf.get(k) + vb.get(-(k - delta)) >= n) return { oldIndex: x0 + os, newIndex: y0 + ns, leftMode: RAW, rightMode: RAW };
|
|
690
|
+
if (trackLimit) {
|
|
691
|
+
const point = clampDiagonal(x, k, n, m);
|
|
692
|
+
if (point && isInterior(point[0], point[1], n, m)) forward = better(forward, { oldIndex: point[0], newIndex: point[1], progress: point[0] + point[1], forward: true });
|
|
693
|
+
}
|
|
694
|
+
if (trackGood && snake >= HEURISTIC_MIN_SNAKE && x < n && y < m) {
|
|
695
|
+
const progress = Math.max(0, x + y - Math.abs(k));
|
|
696
|
+
if (progress > HEURISTIC_PROGRESS_FACTOR * d && isInterior(x0, y0, n, m)) good = better(good, { oldIndex: x0, newIndex: y0, progress, forward: true });
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
for (let k = d; k >= -d; k -= 2) {
|
|
700
|
+
let x = k === -d || k !== d && vb.get(k - 1) < vb.get(k + 1) ? vb.get(k + 1) : vb.get(k - 1) + 1;
|
|
701
|
+
let y = x - k;
|
|
702
|
+
const x0 = x;
|
|
703
|
+
if (x < n && y < m) {
|
|
704
|
+
const advance = commonSuffixLen(old, os, os + n - x, next, ns, ns + m - y);
|
|
705
|
+
x += advance;
|
|
706
|
+
y += advance;
|
|
707
|
+
}
|
|
708
|
+
const snake = x - x0;
|
|
709
|
+
vb.set(k, x);
|
|
710
|
+
if (!odd && Math.abs(k - delta) <= d && vb.get(k) + vf.get(-(k - delta)) >= n) return { oldIndex: n - x + os, newIndex: m - y + ns, leftMode: RAW, rightMode: RAW };
|
|
711
|
+
if (trackLimit) {
|
|
712
|
+
const point = clampDiagonal(x, k, n, m);
|
|
713
|
+
if (point) {
|
|
714
|
+
const splitOld = n - point[0], splitNew = m - point[1];
|
|
715
|
+
if (isInterior(splitOld, splitNew, n, m)) backward = better(backward, { oldIndex: splitOld, newIndex: splitNew, progress: point[0] + point[1], forward: false });
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
if (trackGood && snake >= HEURISTIC_MIN_SNAKE && x <= n && y <= m) {
|
|
719
|
+
const splitOld = n - x, splitNew = m - y;
|
|
720
|
+
const progress = Math.max(0, x + y - Math.abs(k));
|
|
721
|
+
if (splitOld > 0 && splitNew > 0 && progress > HEURISTIC_PROGRESS_FACTOR * d) good = better(good, { oldIndex: splitOld, newIndex: splitNew, progress, forward: false });
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
if (good) return heuristic(good);
|
|
725
|
+
if (d >= maxCost) {
|
|
726
|
+
const split = forward && backward ? forward.progress > backward.progress ? forward : backward : forward ?? backward;
|
|
727
|
+
if (!split) break;
|
|
728
|
+
return heuristic(split);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return void 0;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
// src/diff.ts
|
|
735
|
+
var isSame = (r) => !r.added.length && !r.removed.length && !r.changed.length;
|
|
736
|
+
var WORD = String.raw`[\p{Alphabetic}\p{M}\p{Nd}\p{Pc}\p{Join_Control}]`;
|
|
737
|
+
var START = `(?<!${WORD})`;
|
|
738
|
+
var END = `(?!${WORD})`;
|
|
739
|
+
var FINGERPRINT = new RegExp(String.raw`\.([0-9a-f]{8})\.(css|js|mjs|map|woff2?|ttf|otf|png|jpe?g|gif|svg|webp|avif|ico|json|xml|txt|pdf|wasm)` + END, "gu");
|
|
740
|
+
var INTEGRITY = new RegExp(`\\p{White_Space}+integrity=("[^"]*"|'[^']*'|[^\\p{White_Space}>]+)`, "gu");
|
|
741
|
+
var GENERATOR = new RegExp(String.raw`SiteSquatch v\p{Nd}+\.\p{Nd}+\.\p{Nd}+[\p{Alphabetic}\p{M}\p{Nd}\p{Pc}\p{Join_Control}.+\-]*`, "gu");
|
|
742
|
+
var ID_ATTR = new RegExp(`\\p{White_Space}id=(?:"([^"]*)"|'([^']*)'|([^\\p{White_Space}>]+))`, "u");
|
|
743
|
+
var MONTH = "(?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)";
|
|
744
|
+
var DATE = new RegExp([
|
|
745
|
+
// 2026-03-14T09:05:00Z
|
|
746
|
+
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
|
+
// March 14, 2026
|
|
748
|
+
String.raw`${START}${MONTH}[a-z]*\.?\p{White_Space}+\p{Nd}{1,2}(?:st|nd|rd|th)?,?\p{White_Space}+\p{Nd}{4}${END}`,
|
|
749
|
+
// 14 March 2026
|
|
750
|
+
String.raw`${START}\p{Nd}{1,2}\p{White_Space}+${MONTH}[a-z]*\.?\p{White_Space}+\p{Nd}{4}${END}`,
|
|
751
|
+
// 3/14/2026
|
|
752
|
+
String.raw`${START}\p{Nd}{1,2}/\p{Nd}{1,2}/\p{Nd}{2,4}${END}`,
|
|
753
|
+
// 2026
|
|
754
|
+
String.raw`${START}(?:19|20)\p{Nd}{2}${END}`
|
|
755
|
+
].join("|"), "gu");
|
|
756
|
+
function withoutFingerprints(text) {
|
|
757
|
+
if (!text.includes(".")) return text;
|
|
758
|
+
return text.replace(FINGERPRINT, (whole, hash, ext) => /^(19|20)\d{6}$/.test(hash) ? whole : `.${ext}`);
|
|
759
|
+
}
|
|
760
|
+
var INLINE = /* @__PURE__ */ new Set(["a", "abbr", "b", "bdi", "bdo", "button", "cite", "code", "data", "dfn", "em", "i", "img", "input", "kbd", "label", "mark", "q", "s", "samp", "select", "small", "span", "strong", "sub", "sup", "time", "u", "var", "wbr"]);
|
|
761
|
+
var asciiLower = (text) => text.replace(/[A-Z]/g, (c) => c.toLowerCase());
|
|
762
|
+
function nameAt(text, from) {
|
|
763
|
+
let end = from;
|
|
764
|
+
for (; end < text.length; end++) {
|
|
765
|
+
const c = text.charCodeAt(end);
|
|
766
|
+
if (!(c >= 48 && c <= 57 || c >= 65 && c <= 90 || c >= 97 && c <= 122)) break;
|
|
767
|
+
}
|
|
768
|
+
const name = text.slice(from, end);
|
|
769
|
+
return /[A-Z]/.test(name) ? asciiLower(name) : name;
|
|
770
|
+
}
|
|
771
|
+
function isInline(tag) {
|
|
772
|
+
let i = 0;
|
|
773
|
+
while (i < tag.length && (tag.charCodeAt(i) === 60 || tag.charCodeAt(i) === 47)) i++;
|
|
774
|
+
return INLINE.has(nameAt(tag, i));
|
|
775
|
+
}
|
|
776
|
+
function normalize(text, options) {
|
|
777
|
+
if (options.exact) return text;
|
|
778
|
+
let out = text.replaceAll("\r\n", "\n");
|
|
779
|
+
for (const re of options.ignore) out = out.replace(re, "");
|
|
780
|
+
out = withoutFingerprints(out);
|
|
781
|
+
if (out.includes("integrity=")) out = out.replace(INTEGRITY, "");
|
|
782
|
+
if (out.includes("SiteSquatch v")) out = out.replace(GENERATOR, "SiteSquatch");
|
|
783
|
+
return out;
|
|
784
|
+
}
|
|
785
|
+
async function files(dir) {
|
|
786
|
+
if (!(fs.statSync(dir, { throwIfNoEntry: false })?.isDirectory() ?? false)) bail(`${dir} isn't a folder; give \`ssqch diff\` two build folders, like \`ssqch diff dist-before dist\``);
|
|
787
|
+
return (await buildFiles(dir, false)).map(([file]) => file).sort(compareText);
|
|
788
|
+
}
|
|
789
|
+
function keyed(paths, exact) {
|
|
790
|
+
if (exact) return new Map(paths.map((p) => [p, p]));
|
|
791
|
+
const stripped = paths.map(withoutFingerprints);
|
|
792
|
+
const own = /* @__PURE__ */ new Set();
|
|
793
|
+
for (let changed = true; changed; ) {
|
|
794
|
+
changed = false;
|
|
795
|
+
const counts = /* @__PURE__ */ new Map();
|
|
796
|
+
const keyOf = (i) => own.has(i) ? paths[i] : stripped[i];
|
|
797
|
+
for (let i = 0; i < paths.length; i++) counts.set(keyOf(i), (counts.get(keyOf(i)) ?? 0) + 1);
|
|
798
|
+
for (let i = 0; i < paths.length; i++) {
|
|
799
|
+
if (!own.has(i) && counts.get(stripped[i]) > 1) {
|
|
800
|
+
own.add(i);
|
|
801
|
+
changed = true;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
const pairs = paths.map((p, i) => [own.has(i) ? p : stripped[i], p]);
|
|
806
|
+
return new Map(pairs.sort((a, b) => compareText(a[0], b[0])));
|
|
807
|
+
}
|
|
808
|
+
var isPage = (file) => file.endsWith(".html") || file.endsWith(".htm");
|
|
809
|
+
function isSpace(c) {
|
|
810
|
+
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
|
+
}
|
|
812
|
+
var SPACE_CHARS = "\\t\\n\\v\\f\\r \\u0085\\u00a0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
|
|
813
|
+
var SPACE_RUN = new RegExp(`[${SPACE_CHARS}]+`, "g");
|
|
814
|
+
var ALL_SPACE = new RegExp(`^[${SPACE_CHARS}]*$`);
|
|
815
|
+
var UNCOLLAPSED = new RegExp(`[${SPACE_CHARS.replace(" ", "")}]| |^ | $|^$`);
|
|
816
|
+
var TAG_SPACE = new RegExp(`[${SPACE_CHARS.replace(" ", "")}]| | [>/]`);
|
|
817
|
+
function collapse(s) {
|
|
818
|
+
if (!UNCOLLAPSED.test(s)) return s;
|
|
819
|
+
if (ALL_SPACE.test(s)) return "";
|
|
820
|
+
const t = s.replace(SPACE_RUN, " ");
|
|
821
|
+
const start = t.charCodeAt(0) === 32 ? 1 : 0;
|
|
822
|
+
const end = t.length > start && t.charCodeAt(t.length - 1) === 32 ? t.length - 1 : t.length;
|
|
823
|
+
return start === 0 && end === t.length ? t : t.slice(start, end);
|
|
824
|
+
}
|
|
825
|
+
function collapseTag(tag) {
|
|
826
|
+
if (!TAG_SPACE.test(tag)) return tag;
|
|
827
|
+
let out = "";
|
|
828
|
+
let quote = 0;
|
|
829
|
+
let space = false;
|
|
830
|
+
for (let i = 0; i < tag.length; i++) {
|
|
831
|
+
const c = tag.charCodeAt(i);
|
|
832
|
+
if (quote) {
|
|
833
|
+
out += tag[i];
|
|
834
|
+
if (c === quote) quote = 0;
|
|
835
|
+
} else if (isSpace(c)) space = true;
|
|
836
|
+
else {
|
|
837
|
+
if (space && out !== "" && c !== 62 && c !== 47) out += " ";
|
|
838
|
+
space = false;
|
|
839
|
+
if (c === 34 || c === 39) quote = c;
|
|
840
|
+
out += tag[i];
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
return out;
|
|
844
|
+
}
|
|
845
|
+
var QUOTE_OR_END = /["'>]/g;
|
|
846
|
+
function tagEnd(s, from) {
|
|
847
|
+
QUOTE_OR_END.lastIndex = from;
|
|
848
|
+
const first = QUOTE_OR_END.exec(s);
|
|
849
|
+
if (!first) return void 0;
|
|
850
|
+
if (first[0] === ">") return first.index + 1 - from;
|
|
851
|
+
let quote = 0;
|
|
852
|
+
for (let i = first.index; i < s.length; i++) {
|
|
853
|
+
const b = s.charCodeAt(i);
|
|
854
|
+
if (quote) {
|
|
855
|
+
if (b === quote) quote = 0;
|
|
856
|
+
} else if (b === 34 || b === 39) quote = b;
|
|
857
|
+
else if (b === 62) return i + 1 - from;
|
|
858
|
+
}
|
|
859
|
+
return void 0;
|
|
860
|
+
}
|
|
861
|
+
var RAW2 = /* @__PURE__ */ new Set(["script", "style", "pre", "textarea"]);
|
|
862
|
+
var CLOSING = new Map([...RAW2].map((name) => [name, new RegExp(`</${name}`, "gi")]));
|
|
863
|
+
var startsTag = (c) => c >= 65 && c <= 90 || c >= 97 && c <= 122 || c === 47 || c === 33 || c === 63;
|
|
864
|
+
function tokens(html) {
|
|
865
|
+
const out = [];
|
|
866
|
+
let i = 0;
|
|
867
|
+
let textStart = 0;
|
|
868
|
+
const pushText = (s, nextTag) => {
|
|
869
|
+
if (s === "") return;
|
|
870
|
+
const last = out[out.length - 1];
|
|
871
|
+
const before = isSpace(s.codePointAt(0)) && last !== void 0 && last.tag && isInline(last.text);
|
|
872
|
+
const after = isSpace(s.charCodeAt(s.length - 1)) && nextTag !== void 0 && isInline(nextTag);
|
|
873
|
+
let t = collapse(s);
|
|
874
|
+
if (t === "") {
|
|
875
|
+
if (before && after) out.push({ tag: false, text: " " });
|
|
876
|
+
return;
|
|
877
|
+
}
|
|
878
|
+
if (before) t = ` ${t}`;
|
|
879
|
+
if (after) t = `${t} `;
|
|
880
|
+
out.push({ tag: false, text: t });
|
|
881
|
+
};
|
|
882
|
+
for (; ; ) {
|
|
883
|
+
i = html.indexOf("<", i);
|
|
884
|
+
if (i === -1) break;
|
|
885
|
+
let end;
|
|
886
|
+
if (html.startsWith("<!--", i)) {
|
|
887
|
+
const close = html.indexOf("-->", i);
|
|
888
|
+
end = close === -1 ? void 0 : close - i + 3;
|
|
889
|
+
} else if (i + 1 < html.length && startsTag(html.charCodeAt(i + 1))) end = tagEnd(html, i);
|
|
890
|
+
if (end === void 0) {
|
|
891
|
+
i += 1;
|
|
892
|
+
continue;
|
|
893
|
+
}
|
|
894
|
+
const tag = html.slice(i, i + end);
|
|
895
|
+
pushText(html.slice(textStart, i), tag);
|
|
896
|
+
out.push({ tag: true, text: collapseTag(tag) });
|
|
897
|
+
i += end;
|
|
898
|
+
textStart = i;
|
|
899
|
+
const name = nameAt(tag, 1);
|
|
900
|
+
if (RAW2.has(name) && !tag.endsWith("/>")) {
|
|
901
|
+
const closing = CLOSING.get(name);
|
|
902
|
+
closing.lastIndex = i;
|
|
903
|
+
const found = closing.exec(html);
|
|
904
|
+
const len = (found ? found.index : html.length) - i;
|
|
905
|
+
let raw = html.slice(i, i + len);
|
|
906
|
+
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 });
|
|
908
|
+
i += len;
|
|
909
|
+
textStart = i;
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
pushText(html.slice(textStart), void 0);
|
|
913
|
+
return out;
|
|
914
|
+
}
|
|
915
|
+
function ids(list) {
|
|
916
|
+
const found = /* @__PURE__ */ new Set();
|
|
917
|
+
for (const t of list) {
|
|
918
|
+
if (!t.tag || !t.text.includes("id=")) continue;
|
|
919
|
+
const m = ID_ATTR.exec(t.text);
|
|
920
|
+
if (m) found.add(m[1] ?? m[2] ?? m[3]);
|
|
921
|
+
}
|
|
922
|
+
return [...found].sort(compareText);
|
|
923
|
+
}
|
|
924
|
+
var TITLE = /^<title(?:>$| )/i;
|
|
925
|
+
function title(list) {
|
|
926
|
+
const i = list.findIndex((t) => t.tag && TITLE.test(t.text));
|
|
927
|
+
if (i === -1) return void 0;
|
|
928
|
+
const next = list[i + 1];
|
|
929
|
+
return next && !next.tag ? next.text : void 0;
|
|
930
|
+
}
|
|
931
|
+
function lines(text) {
|
|
932
|
+
if (text === "") return [];
|
|
933
|
+
const out = text.split("\n");
|
|
934
|
+
if (out[out.length - 1] === "") out.pop();
|
|
935
|
+
for (let i = 0; i < out.length; i++) {
|
|
936
|
+
if (out[i].endsWith("\r") && (i < out.length - 1 || text.endsWith("\n"))) out[i] = out[i].slice(0, -1);
|
|
937
|
+
}
|
|
938
|
+
return out;
|
|
939
|
+
}
|
|
940
|
+
function hunks(before, after, kind, show) {
|
|
941
|
+
const numbers = [/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()];
|
|
942
|
+
let count2 = 0;
|
|
943
|
+
const number = (item) => {
|
|
944
|
+
const map = numbers[kind(item)];
|
|
945
|
+
const text = show(item);
|
|
946
|
+
let n = map.get(text);
|
|
947
|
+
if (n === void 0) {
|
|
948
|
+
n = count2++;
|
|
949
|
+
map.set(text, n);
|
|
950
|
+
}
|
|
951
|
+
return n;
|
|
952
|
+
};
|
|
953
|
+
const a = new Int32Array(before.length), b = new Int32Array(after.length);
|
|
954
|
+
for (let i = 0; i < before.length; i++) a[i] = number(before[i]);
|
|
955
|
+
for (let i = 0; i < after.length; i++) b[i] = number(after[i]);
|
|
956
|
+
const out = [];
|
|
957
|
+
const changed = [];
|
|
958
|
+
for (const op of diffOps(a, b)) {
|
|
959
|
+
if (op.tag === "equal") continue;
|
|
960
|
+
for (let i = op.oldIndex; i < op.oldIndex + op.oldLen; i++) changed.push([true, i]);
|
|
961
|
+
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) });
|
|
963
|
+
}
|
|
964
|
+
return [out, changed];
|
|
965
|
+
}
|
|
966
|
+
function firstLines(list, limit) {
|
|
967
|
+
if (limit === 0) return list;
|
|
968
|
+
let left = limit;
|
|
969
|
+
const out = [];
|
|
970
|
+
for (const h of list) {
|
|
971
|
+
if (left === 0) break;
|
|
972
|
+
const removed = h.removed.slice(0, left);
|
|
973
|
+
left -= removed.length;
|
|
974
|
+
const added = h.added.slice(0, left);
|
|
975
|
+
left -= added.length;
|
|
976
|
+
out.push({ removed, added });
|
|
977
|
+
}
|
|
978
|
+
return out;
|
|
979
|
+
}
|
|
980
|
+
var utf8 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
981
|
+
var decode = (data) => {
|
|
982
|
+
try {
|
|
983
|
+
return utf8.decode(data);
|
|
984
|
+
} catch {
|
|
985
|
+
return void 0;
|
|
986
|
+
}
|
|
987
|
+
};
|
|
988
|
+
function comparePair(a, b, pair, options) {
|
|
989
|
+
if (a.equals(b)) return void 0;
|
|
990
|
+
const diff2 = {
|
|
991
|
+
path: pair.key,
|
|
992
|
+
url: urlOf(pair.key),
|
|
993
|
+
renamed: pair.before !== pair.after ? [pair.before, pair.after] : void 0,
|
|
994
|
+
kind: "binary",
|
|
995
|
+
what: [],
|
|
996
|
+
notes: [],
|
|
997
|
+
hunks: [],
|
|
998
|
+
changedLines: 0,
|
|
999
|
+
onlyDates: void 0,
|
|
1000
|
+
sizeBefore: a.length,
|
|
1001
|
+
sizeAfter: b.length
|
|
1002
|
+
};
|
|
1003
|
+
const textA = decode(a), textB = decode(b);
|
|
1004
|
+
if (textA === void 0 || textB === void 0) return diff2;
|
|
1005
|
+
const before = normalize(textA, options), after = normalize(textB, options);
|
|
1006
|
+
if (before === after) return void 0;
|
|
1007
|
+
let found;
|
|
1008
|
+
if (isPage(pair.key) && !options.exact) {
|
|
1009
|
+
diff2.kind = "page";
|
|
1010
|
+
const ta = tokens(before), tb = tokens(after);
|
|
1011
|
+
const [list, changed] = hunks(ta, tb, (t) => t.tag ? 1 : 0, (t) => t.text);
|
|
1012
|
+
if (!list.length) return void 0;
|
|
1013
|
+
const isTag = ([first, i]) => (first ? ta[i] : tb[i]).tag;
|
|
1014
|
+
if (changed.some((c) => !isTag(c))) diff2.what.push("text");
|
|
1015
|
+
if (changed.some(isTag)) diff2.what.push("markup");
|
|
1016
|
+
const [old, now] = [title(ta), title(tb)];
|
|
1017
|
+
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}`);
|
|
1020
|
+
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` : ""}`);
|
|
1021
|
+
diff2.onlyDates = onlyDates(list);
|
|
1022
|
+
if (diff2.onlyDates) diff2.notes.push(`only dates changed (${diff2.onlyDates[0]} -> ${diff2.onlyDates[1]})`);
|
|
1023
|
+
found = list;
|
|
1024
|
+
} else {
|
|
1025
|
+
diff2.kind = isPage(pair.key) ? "page" : "text";
|
|
1026
|
+
const la = lines(before), lb = lines(after);
|
|
1027
|
+
found = hunks(la, lb, () => 0, (l) => l)[0];
|
|
1028
|
+
if (!found.length) found = [{ removed: [`(${Buffer.byteLength(before)} bytes)`], added: [`(${Buffer.byteLength(after)} bytes)`] }];
|
|
1029
|
+
}
|
|
1030
|
+
diff2.changedLines = found.reduce((sum, h) => sum + h.removed.length + h.added.length, 0);
|
|
1031
|
+
diff2.hunks = firstLines(found, options.lines);
|
|
1032
|
+
return diff2;
|
|
1033
|
+
}
|
|
1034
|
+
var READS_AT_ONCE = 32;
|
|
1035
|
+
var Reader = class {
|
|
1036
|
+
buffer = Buffer.allocUnsafe(64 * 1024);
|
|
1037
|
+
read(file) {
|
|
1038
|
+
return new Promise((resolve, reject) => {
|
|
1039
|
+
const failed = (e) => reject(new BuildError(`reading ${file}: ${e.message}`));
|
|
1040
|
+
fs.open(file, "r", (e, fd) => {
|
|
1041
|
+
if (e) return failed(e);
|
|
1042
|
+
const finish = (error, length) => fs.close(fd, () => error ? failed(error) : resolve(this.buffer.subarray(0, length)));
|
|
1043
|
+
fs.fstat(fd, (e2, stat) => {
|
|
1044
|
+
if (e2) return finish(e2, 0);
|
|
1045
|
+
if (this.buffer.length < stat.size + 1) this.buffer = Buffer.allocUnsafe(stat.size + 1);
|
|
1046
|
+
const more = (length) => {
|
|
1047
|
+
if (length === this.buffer.length) {
|
|
1048
|
+
const bigger = Buffer.allocUnsafe(this.buffer.length * 2);
|
|
1049
|
+
this.buffer.copy(bigger);
|
|
1050
|
+
this.buffer = bigger;
|
|
1051
|
+
}
|
|
1052
|
+
fs.read(fd, this.buffer, length, this.buffer.length - length, null, (e3, n) => e3 ? finish(e3, 0) : n === 0 ? finish(null, length) : more(length + n));
|
|
1053
|
+
};
|
|
1054
|
+
more(0);
|
|
1055
|
+
});
|
|
1056
|
+
});
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
async function compare(before, after, options) {
|
|
1061
|
+
const keep = (paths) => options.only ? paths.filter((p) => options.only.some((re) => re.test(p))) : paths;
|
|
1062
|
+
const [walkA, walkB] = await Promise.allSettled([files(before), files(after)]);
|
|
1063
|
+
if (walkA.status === "rejected") throw walkA.reason;
|
|
1064
|
+
if (walkB.status === "rejected") throw walkB.reason;
|
|
1065
|
+
const [listA, listB] = [walkA.value, walkB.value];
|
|
1066
|
+
const a = keyed(keep(listA), options.exact);
|
|
1067
|
+
const b = keyed(keep(listB), options.exact);
|
|
1068
|
+
const report = { before, after, exact: options.exact, added: [], removed: [], changed: [], unchangedPages: 0, unchangedFiles: 0 };
|
|
1069
|
+
for (const key of a.keys()) if (!b.has(key)) report.removed.push(urlOf(key));
|
|
1070
|
+
for (const key of b.keys()) if (!a.has(key)) report.added.push(urlOf(key));
|
|
1071
|
+
const pairs = [];
|
|
1072
|
+
for (const [key, from] of a) {
|
|
1073
|
+
const to = b.get(key);
|
|
1074
|
+
if (to !== void 0) pairs.push({ key, before: from, after: to });
|
|
1075
|
+
}
|
|
1076
|
+
const results = new Array(pairs.length).fill(null);
|
|
1077
|
+
let next = 0;
|
|
1078
|
+
const worker = async () => {
|
|
1079
|
+
const x = new Reader(), y = new Reader();
|
|
1080
|
+
while (next < pairs.length) {
|
|
1081
|
+
const i = next++;
|
|
1082
|
+
const pair = pairs[i];
|
|
1083
|
+
const [one, two] = await Promise.all([x.read(path.join(before, pair.before)), y.read(path.join(after, pair.after))]);
|
|
1084
|
+
results[i] = comparePair(one, two, pair, options);
|
|
1085
|
+
}
|
|
1086
|
+
};
|
|
1087
|
+
await Promise.all(Array.from({ length: Math.min(READS_AT_ONCE, pairs.length) }, worker));
|
|
1088
|
+
pairs.forEach((pair, i) => {
|
|
1089
|
+
const found = results[i];
|
|
1090
|
+
if (found) report.changed.push(found);
|
|
1091
|
+
else if (isPage(pair.key)) report.unchangedPages += 1;
|
|
1092
|
+
else report.unchangedFiles += 1;
|
|
1093
|
+
});
|
|
1094
|
+
return report;
|
|
1095
|
+
}
|
|
1096
|
+
function onlyDates(list) {
|
|
1097
|
+
const blank = (lines2) => lines2.map((l) => l.replace(DATE, "\0"));
|
|
1098
|
+
let first;
|
|
1099
|
+
for (const hunk of list) {
|
|
1100
|
+
if (hunk.removed.length !== hunk.added.length) return void 0;
|
|
1101
|
+
const [x, y] = [blank(hunk.removed), blank(hunk.added)];
|
|
1102
|
+
if (x.some((line, i) => line !== y[i])) return void 0;
|
|
1103
|
+
if (first === void 0) {
|
|
1104
|
+
for (let i = 0; i < hunk.removed.length && first === void 0; i++) {
|
|
1105
|
+
const old = [...hunk.removed[i].matchAll(DATE)].map((m) => m[0]);
|
|
1106
|
+
const now = [...hunk.added[i].matchAll(DATE)].map((m) => m[0]);
|
|
1107
|
+
for (let k = 0; k < Math.min(old.length, now.length); k++) {
|
|
1108
|
+
if (old[k] !== now[k]) {
|
|
1109
|
+
first = [old[k], now[k]];
|
|
1110
|
+
break;
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
}
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1116
|
+
return first;
|
|
1117
|
+
}
|
|
1118
|
+
function clip(line) {
|
|
1119
|
+
const MAX = 200;
|
|
1120
|
+
const n = charCount(line);
|
|
1121
|
+
return n <= MAX ? line : `${firstChars(line, MAX)}\u2026 (${n - MAX} more characters)`;
|
|
1122
|
+
}
|
|
1123
|
+
var plural = (n, one, many) => `${count(n)} ${n === 1 ? one : many}`;
|
|
1124
|
+
function diffText(report, limit, color) {
|
|
1125
|
+
const paint = (code, s) => color ? `\x1B[${code}m${s}\x1B[0m` : s;
|
|
1126
|
+
let out = `Comparing ${report.before} with ${report.after}
|
|
1127
|
+
`;
|
|
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";
|
|
1129
|
+
const unchanged = `${plural(report.unchangedPages, "page", "pages")} and ${plural(report.unchangedFiles, "other file", "other files")}`;
|
|
1130
|
+
if (isSame(report)) return `${out}
|
|
1131
|
+
No differences: ${unchanged} are the same. The stump has not moved.
|
|
1132
|
+
`;
|
|
1133
|
+
if (report.added.length) {
|
|
1134
|
+
out += `
|
|
1135
|
+
Added (${report.added.length})
|
|
1136
|
+
`;
|
|
1137
|
+
for (const url of report.added) out += paint("32", ` + ${url}
|
|
1138
|
+
`);
|
|
1139
|
+
}
|
|
1140
|
+
if (report.removed.length) {
|
|
1141
|
+
out += `
|
|
1142
|
+
Removed (${report.removed.length})
|
|
1143
|
+
`;
|
|
1144
|
+
for (const url of report.removed) out += paint("31", ` - ${url}
|
|
1145
|
+
`);
|
|
1146
|
+
}
|
|
1147
|
+
if (report.changed.length) out += `
|
|
1148
|
+
Changed (${report.changed.length})
|
|
1149
|
+
`;
|
|
1150
|
+
for (const file of report.changed) {
|
|
1151
|
+
const about = [];
|
|
1152
|
+
if (file.what.length) about.push(file.what.join(" and "));
|
|
1153
|
+
if (file.renamed) {
|
|
1154
|
+
const name = (p) => p.slice(p.lastIndexOf("/") + 1);
|
|
1155
|
+
about.push(`${name(file.renamed[0])} -> ${name(file.renamed[1])}`);
|
|
1156
|
+
}
|
|
1157
|
+
if (file.kind === "binary") about.push(`binary, ${bytes(file.sizeBefore)} -> ${bytes(file.sizeAfter)}`);
|
|
1158
|
+
out += ` ~ ${file.url}${about.length ? ` (${about.join("; ")})` : ""}
|
|
1159
|
+
`;
|
|
1160
|
+
for (const note of file.notes) out += ` ${note}
|
|
1161
|
+
`;
|
|
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
|
+
`;
|
|
1175
|
+
}
|
|
1176
|
+
const pageUrl = (url) => url.endsWith("/") || isPage(url);
|
|
1177
|
+
const pages = [...report.added, ...report.removed].filter(pageUrl).length + report.changed.filter((f) => isPage(f.path)).length;
|
|
1178
|
+
const others = report.added.length + report.removed.length + report.changed.length - pages;
|
|
1179
|
+
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")}`;
|
|
1180
|
+
const dated = report.changed.filter((f) => f.onlyDates).length;
|
|
1181
|
+
if (dated > 0) {
|
|
1182
|
+
const which = dated === report.changed.length ? `All ${plural(dated, "changed file", "changed files")}` : `${count(dated)} of the ${plural(report.changed.length, "changed file", "changed files")}`;
|
|
1183
|
+
out += `
|
|
1184
|
+
${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
|
+
`;
|
|
1186
|
+
}
|
|
1187
|
+
out += `
|
|
1188
|
+
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
|
+
`;
|
|
1190
|
+
return out;
|
|
1191
|
+
}
|
|
1192
|
+
function diffJson(report, limit) {
|
|
1193
|
+
const changed = report.changed.map((f) => {
|
|
1194
|
+
const entry = {
|
|
1195
|
+
url: f.url,
|
|
1196
|
+
path: f.path,
|
|
1197
|
+
kind: f.kind,
|
|
1198
|
+
changes: f.what,
|
|
1199
|
+
notes: f.notes,
|
|
1200
|
+
changedLines: f.changedLines,
|
|
1201
|
+
onlyDates: f.onlyDates !== void 0,
|
|
1202
|
+
sizeBefore: f.sizeBefore,
|
|
1203
|
+
sizeAfter: f.sizeAfter,
|
|
1204
|
+
hunks: firstLines(f.hunks, limit)
|
|
1205
|
+
};
|
|
1206
|
+
if (f.renamed) entry.renamed = { before: f.renamed[0], after: f.renamed[1] };
|
|
1207
|
+
return entry;
|
|
1208
|
+
});
|
|
1209
|
+
return {
|
|
1210
|
+
schemaVersion: 1,
|
|
1211
|
+
before: report.before.replaceAll("\\", "/"),
|
|
1212
|
+
after: report.after.replaceAll("\\", "/"),
|
|
1213
|
+
exact: report.exact,
|
|
1214
|
+
same: isSame(report),
|
|
1215
|
+
summary: { added: report.added.length, removed: report.removed.length, changed: report.changed.length, unchangedPages: report.unchangedPages, unchangedFiles: report.unchangedFiles },
|
|
1216
|
+
added: report.added,
|
|
1217
|
+
removed: report.removed,
|
|
1218
|
+
changed
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
async function compareRuns(dirs, options) {
|
|
1222
|
+
const keep = (paths) => options.only ? paths.filter((p) => options.only.some((re) => re.test(p))) : paths;
|
|
1223
|
+
const walks = await Promise.allSettled(dirs.map(files));
|
|
1224
|
+
for (const walk of walks) if (walk.status === "rejected") throw walk.reason;
|
|
1225
|
+
const maps = walks.map((w) => keyed(keep(w.value), options.exact));
|
|
1226
|
+
const keys = [...new Set(maps.flatMap((m) => [...m.keys()]))].sort(compareText);
|
|
1227
|
+
const report = { runs: dirs, exact: options.exact, varies: [], steadyPages: 0, steadyFiles: 0 };
|
|
1228
|
+
const found = new Array(keys.length);
|
|
1229
|
+
let next = 0;
|
|
1230
|
+
const worker = async () => {
|
|
1231
|
+
while (next < keys.length) {
|
|
1232
|
+
const i = next++;
|
|
1233
|
+
const key = keys[i];
|
|
1234
|
+
const buffers = await Promise.all(maps.map(async (m, run) => {
|
|
1235
|
+
const file = m.get(key);
|
|
1236
|
+
return file === void 0 ? void 0 : Buffer.from(await fs.promises.readFile(path.join(dirs[run], file)));
|
|
1237
|
+
}));
|
|
1238
|
+
found[i] = varies(key, buffers, maps, options);
|
|
1239
|
+
}
|
|
1240
|
+
};
|
|
1241
|
+
await Promise.all(Array.from({ length: Math.min(READS_AT_ONCE, keys.length) }, worker));
|
|
1242
|
+
keys.forEach((key, i) => {
|
|
1243
|
+
const v = found[i];
|
|
1244
|
+
if (v) report.varies.push(v);
|
|
1245
|
+
else if (isPage(key)) report.steadyPages += 1;
|
|
1246
|
+
else report.steadyFiles += 1;
|
|
1247
|
+
});
|
|
1248
|
+
return report;
|
|
1249
|
+
}
|
|
1250
|
+
function seen(key, data, options) {
|
|
1251
|
+
const text = decode(data);
|
|
1252
|
+
if (text === void 0) return `b:${data.toString("base64")}`;
|
|
1253
|
+
const normal = normalize(text, options);
|
|
1254
|
+
if (isPage(key) && !options.exact) return `p:${tokens(normal).map((t) => `${t.tag ? 1 : 0}${t.text}`).join("\0")}`;
|
|
1255
|
+
return `t:${normal}`;
|
|
1256
|
+
}
|
|
1257
|
+
function varies(key, buffers, maps, options) {
|
|
1258
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1259
|
+
buffers.forEach((data, run) => {
|
|
1260
|
+
const id = data === void 0 ? "missing" : seen(key, data, options);
|
|
1261
|
+
const list = groups.get(id);
|
|
1262
|
+
if (list) list.push(run);
|
|
1263
|
+
else groups.set(id, [run]);
|
|
1264
|
+
});
|
|
1265
|
+
if (groups.size === 1 && !groups.has("missing")) return void 0;
|
|
1266
|
+
const versions = [...groups].map(([id, runs]) => ({ runs, missing: id === "missing" }));
|
|
1267
|
+
versions.sort((a, b) => b.runs.length - a.runs.length || a.runs[0] - b.runs[0]);
|
|
1268
|
+
const present = versions.filter((v) => !v.missing);
|
|
1269
|
+
let sample;
|
|
1270
|
+
if (present.length >= 2) {
|
|
1271
|
+
const [x, y] = [present[0].runs[0], present[1].runs[0]];
|
|
1272
|
+
sample = comparePair(buffers[x], buffers[y], { key, before: maps[x].get(key), after: maps[y].get(key) }, options);
|
|
1273
|
+
}
|
|
1274
|
+
const first = buffers.find((b) => b !== void 0);
|
|
1275
|
+
const kind = decode(first) === void 0 ? "binary" : isPage(key) ? "page" : "text";
|
|
1276
|
+
return { path: key, url: urlOf(key), kind, versions, sample };
|
|
1277
|
+
}
|
|
1278
|
+
var named = (report, runs) => runs.map((r) => report.runs[r]).join(", ");
|
|
1279
|
+
function runsText(report, limit, color) {
|
|
1280
|
+
const paint = (code, s) => color ? `\x1B[${code}m${s}\x1B[0m` : s;
|
|
1281
|
+
let out = `Comparing ${count(report.runs.length)} builds: ${report.runs.join(", ")}
|
|
1282
|
+
`;
|
|
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";
|
|
1284
|
+
const steady = `${plural(report.steadyPages, "page", "pages")} and ${plural(report.steadyFiles, "other file", "other files")}`;
|
|
1285
|
+
if (!report.varies.length) return `${out}
|
|
1286
|
+
Every build is the same: ${steady}. The tracks match every time.
|
|
1287
|
+
`;
|
|
1288
|
+
out += `
|
|
1289
|
+
Varies (${report.varies.length})
|
|
1290
|
+
`;
|
|
1291
|
+
for (const file of report.varies) {
|
|
1292
|
+
const [most, ...rest] = file.versions;
|
|
1293
|
+
const onlyIn = most.missing && rest.length === 1;
|
|
1294
|
+
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" : ""}`);
|
|
1295
|
+
const agree = most.missing ? `missing from ${named(report, most.runs)}` : `${named(report, most.runs)} agree${most.runs.length === 1 ? "s" : ""}`;
|
|
1296
|
+
out += ` ~ ${file.url} (${file.versions.length} versions: ${agree}; ${others.join("; ")})
|
|
1297
|
+
`;
|
|
1298
|
+
const sample = file.sample;
|
|
1299
|
+
if (!sample) continue;
|
|
1300
|
+
for (const note of sample.notes) out += ` ${note}
|
|
1301
|
+
`;
|
|
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
|
+
`;
|
|
1315
|
+
}
|
|
1316
|
+
out += `
|
|
1317
|
+
${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.
|
|
1318
|
+
`;
|
|
1319
|
+
return out;
|
|
1320
|
+
}
|
|
1321
|
+
function runsJson(report, limit) {
|
|
1322
|
+
const runs = report.runs.map((r) => r.replaceAll("\\", "/"));
|
|
1323
|
+
return {
|
|
1324
|
+
schemaVersion: 1,
|
|
1325
|
+
runs,
|
|
1326
|
+
exact: report.exact,
|
|
1327
|
+
same: report.varies.length === 0,
|
|
1328
|
+
summary: { varies: report.varies.length, steadyPages: report.steadyPages, steadyFiles: report.steadyFiles },
|
|
1329
|
+
varies: report.varies.map((f) => ({
|
|
1330
|
+
url: f.url,
|
|
1331
|
+
path: f.path,
|
|
1332
|
+
kind: f.kind,
|
|
1333
|
+
versions: f.versions.map((v) => ({ runs: v.runs.map((r) => runs[r]), missing: v.missing })),
|
|
1334
|
+
changedLines: f.sample?.changedLines ?? 0,
|
|
1335
|
+
hunks: f.sample ? firstLines(f.sample.hunks, limit) : []
|
|
1336
|
+
}))
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
export {
|
|
1340
|
+
compare,
|
|
1341
|
+
compareRuns,
|
|
1342
|
+
diffJson,
|
|
1343
|
+
diffText,
|
|
1344
|
+
isSame,
|
|
1345
|
+
keyed,
|
|
1346
|
+
runsJson,
|
|
1347
|
+
runsText,
|
|
1348
|
+
tokens,
|
|
1349
|
+
withoutFingerprints
|
|
1350
|
+
};
|