flashtrace 0.4.1 → 0.6.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/dist/flashtrace.mjs +366 -53
- package/package.json +1 -1
package/dist/flashtrace.mjs
CHANGED
|
@@ -18,8 +18,145 @@ var UsageError = class extends Error {
|
|
|
18
18
|
import { existsSync, promises as fs } from "node:fs";
|
|
19
19
|
import path from "node:path";
|
|
20
20
|
import { execFileSync } from "node:child_process";
|
|
21
|
+
|
|
22
|
+
// src/languages.mjs
|
|
23
|
+
var cLike = { line: ["//"], block: [["/*", "*/"]] };
|
|
24
|
+
var cLikeNested = { line: ["//"], block: [["/*", "*/", true]] };
|
|
25
|
+
var php = { line: ["//", "#"], block: [["/*", "*/"]] };
|
|
26
|
+
var hash = { line: ["#"], block: [] };
|
|
27
|
+
var powershell = { line: ["#"], block: [["<#", "#>"]] };
|
|
28
|
+
var sql = { line: ["--"], block: [["/*", "*/"]] };
|
|
29
|
+
var lua = { line: ["--"], block: [["--[[", "]]"]] };
|
|
30
|
+
var haskell = { line: ["--"], block: [["{-", "-}", true]] };
|
|
31
|
+
var css = { line: [], block: [["/*", "*/"]] };
|
|
32
|
+
var xml = { line: [], block: [["<!--", "-->"]] };
|
|
33
|
+
var none = { line: [], block: [] };
|
|
34
|
+
var semicolon = { line: [";"], block: [] };
|
|
35
|
+
var percent = { line: ["%"], block: [] };
|
|
36
|
+
var dashLine = { line: ["--"], block: [] };
|
|
37
|
+
var ml = { line: [], block: [["(*", "*)", true]] };
|
|
38
|
+
var fsharp = { line: ["//"], block: [["(*", "*)", true]] };
|
|
39
|
+
var pascal = { line: ["//"], block: [["{", "}"], ["(*", "*)"]] };
|
|
40
|
+
var hcl = { line: ["#", "//"], block: [["/*", "*/"]] };
|
|
41
|
+
function attrOf(tag, name) {
|
|
42
|
+
const m = new RegExp(String.raw`\s${name}\s*=\s*["']?([^"'\s>]+)`, "i").exec(tag);
|
|
43
|
+
return m ? m[1].toLowerCase() : "";
|
|
44
|
+
}
|
|
45
|
+
function scriptGrammar(tag) {
|
|
46
|
+
const type = attrOf(tag, "type");
|
|
47
|
+
if (/json|importmap/.test(type)) return none;
|
|
48
|
+
if (/template|html/.test(type)) return xml;
|
|
49
|
+
if (/coffee/.test(attrOf(tag, "lang"))) return hash;
|
|
50
|
+
return cLike;
|
|
51
|
+
}
|
|
52
|
+
function styleGrammar(tag) {
|
|
53
|
+
return /s[ac]ss|less|stylus|styl/.test(attrOf(tag, "lang")) ? cLike : css;
|
|
54
|
+
}
|
|
55
|
+
var html = {
|
|
56
|
+
default: xml,
|
|
57
|
+
regions: [
|
|
58
|
+
{ enter: /<script\b[^>]*>/gi, exit: /<\/script\s*>/gi, grammar: scriptGrammar },
|
|
59
|
+
{ enter: /<style\b[^>]*>/gi, exit: /<\/style\s*>/gi, grammar: styleGrammar }
|
|
60
|
+
]
|
|
61
|
+
};
|
|
62
|
+
var BY_EXT = {
|
|
63
|
+
// C-family: // line, /* */ block
|
|
64
|
+
".ts": cLike,
|
|
65
|
+
".js": cLike,
|
|
66
|
+
".mjs": cLike,
|
|
67
|
+
".cjs": cLike,
|
|
68
|
+
".jsx": cLike,
|
|
69
|
+
".tsx": cLike,
|
|
70
|
+
".cts": cLike,
|
|
71
|
+
".mts": cLike,
|
|
72
|
+
".c": cLike,
|
|
73
|
+
".h": cLike,
|
|
74
|
+
".cpp": cLike,
|
|
75
|
+
".cc": cLike,
|
|
76
|
+
".hpp": cLike,
|
|
77
|
+
".cs": cLike,
|
|
78
|
+
".java": cLike,
|
|
79
|
+
".go": cLike,
|
|
80
|
+
".dart": cLike,
|
|
81
|
+
".php": php,
|
|
82
|
+
".proto": cLike,
|
|
83
|
+
".scss": cLike,
|
|
84
|
+
".less": cLike,
|
|
85
|
+
// C-family with nested block comments
|
|
86
|
+
".rs": cLikeNested,
|
|
87
|
+
".swift": cLikeNested,
|
|
88
|
+
".kt": cLikeNested,
|
|
89
|
+
".kts": cLikeNested,
|
|
90
|
+
".scala": cLikeNested,
|
|
91
|
+
// hash line comments
|
|
92
|
+
".py": hash,
|
|
93
|
+
".rb": hash,
|
|
94
|
+
".sh": hash,
|
|
95
|
+
".bash": hash,
|
|
96
|
+
".zsh": hash,
|
|
97
|
+
".yaml": hash,
|
|
98
|
+
".yml": hash,
|
|
99
|
+
".toml": hash,
|
|
100
|
+
".r": hash,
|
|
101
|
+
".pm": hash,
|
|
102
|
+
".ex": hash,
|
|
103
|
+
".exs": hash,
|
|
104
|
+
".tcl": hash,
|
|
105
|
+
".jl": hash,
|
|
106
|
+
".nim": hash,
|
|
107
|
+
".graphql": hash,
|
|
108
|
+
".gql": hash,
|
|
109
|
+
".coffee": hash,
|
|
110
|
+
".ps1": powershell,
|
|
111
|
+
".psm1": powershell,
|
|
112
|
+
".tf": hcl,
|
|
113
|
+
".tfvars": hcl,
|
|
114
|
+
".hcl": hcl,
|
|
115
|
+
// semicolon (Lisp family)
|
|
116
|
+
".clj": semicolon,
|
|
117
|
+
".cljs": semicolon,
|
|
118
|
+
".cljc": semicolon,
|
|
119
|
+
".edn": semicolon,
|
|
120
|
+
".el": semicolon,
|
|
121
|
+
".lisp": semicolon,
|
|
122
|
+
".scm": semicolon,
|
|
123
|
+
".ss": semicolon,
|
|
124
|
+
// percent (Erlang, LaTeX)
|
|
125
|
+
".erl": percent,
|
|
126
|
+
".hrl": percent,
|
|
127
|
+
".tex": percent,
|
|
128
|
+
".sty": percent,
|
|
129
|
+
// dash line-only (Ada, VHDL)
|
|
130
|
+
".adb": dashLine,
|
|
131
|
+
".ads": dashLine,
|
|
132
|
+
".vhd": dashLine,
|
|
133
|
+
".vhdl": dashLine,
|
|
134
|
+
// ML-family
|
|
135
|
+
".ml": ml,
|
|
136
|
+
".mli": ml,
|
|
137
|
+
".fs": fsharp,
|
|
138
|
+
".fsi": fsharp,
|
|
139
|
+
".fsx": fsharp,
|
|
140
|
+
".pas": pascal,
|
|
141
|
+
".dpr": pascal,
|
|
142
|
+
// dashes and others
|
|
143
|
+
".sql": sql,
|
|
144
|
+
".lua": lua,
|
|
145
|
+
".hs": haskell,
|
|
146
|
+
".css": css,
|
|
147
|
+
".xml": xml,
|
|
148
|
+
".svg": xml,
|
|
149
|
+
// composite: HTML markup with embedded <script>/<style> regions
|
|
150
|
+
".vue": html,
|
|
151
|
+
".html": html,
|
|
152
|
+
".htm": html,
|
|
153
|
+
".svelte": html
|
|
154
|
+
};
|
|
155
|
+
var CODE_EXT = new Set(Object.keys(BY_EXT));
|
|
156
|
+
var grammarFor = (ext) => BY_EXT[ext] ?? null;
|
|
157
|
+
|
|
158
|
+
// src/files.mjs
|
|
21
159
|
var MD_EXT = /* @__PURE__ */ new Set([".md", ".markdown"]);
|
|
22
|
-
var CODE_EXT = /* @__PURE__ */ new Set([".ts", ".js", ".mjs", ".sql", ".vue"]);
|
|
23
160
|
var GIT_LOCATIONS = process.platform === "win32" ? [
|
|
24
161
|
String.raw`C:\Program Files\Git\cmd\git.exe`,
|
|
25
162
|
String.raw`C:\Program Files (x86)\Git\cmd\git.exe`
|
|
@@ -148,7 +285,9 @@ function newItem(id, origin, file, line) {
|
|
|
148
285
|
needs: [],
|
|
149
286
|
covers: [],
|
|
150
287
|
tags: [],
|
|
151
|
-
defects: []
|
|
288
|
+
defects: [],
|
|
289
|
+
forwardsTo: null
|
|
290
|
+
// effective forwarding target, set by analyze
|
|
152
291
|
};
|
|
153
292
|
}
|
|
154
293
|
|
|
@@ -257,41 +396,121 @@ var TAG_RE = new RegExp(
|
|
|
257
396
|
"g"
|
|
258
397
|
);
|
|
259
398
|
var FORWARD_RE = new RegExp(FORWARD_SRC, "g");
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
399
|
+
function activeLeaf(grammar, state) {
|
|
400
|
+
if (state.region) return state.region.grammar;
|
|
401
|
+
return grammar.regions ? grammar.default : grammar;
|
|
402
|
+
}
|
|
403
|
+
function matchAt(re, s, pos) {
|
|
404
|
+
re.lastIndex = pos;
|
|
405
|
+
return re.exec(s);
|
|
406
|
+
}
|
|
407
|
+
function* regionEvents(s, pos, grammar, state) {
|
|
408
|
+
if (!grammar.regions) return;
|
|
409
|
+
if (state.region) {
|
|
410
|
+
const m = matchAt(state.region.exit, s, pos);
|
|
411
|
+
if (m) yield { idx: m.index, kind: "exit", len: m[0].length };
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
for (const r of grammar.regions) {
|
|
415
|
+
const m = matchAt(r.enter, s, pos);
|
|
416
|
+
if (m) {
|
|
417
|
+
const leaf = typeof r.grammar === "function" ? r.grammar(m[0]) : r.grammar;
|
|
418
|
+
yield { idx: m.index, kind: "enter", len: m[0].length, region: { exit: r.exit, grammar: leaf } };
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
function nextEvent(s, pos, grammar, state) {
|
|
423
|
+
const leaf = activeLeaf(grammar, state);
|
|
265
424
|
let best = null;
|
|
266
|
-
|
|
267
|
-
if (
|
|
425
|
+
const consider = (idx, ev) => {
|
|
426
|
+
if (idx === -1) return;
|
|
427
|
+
if (best === null || idx < best.idx || idx === best.idx && ev.len > best.len) {
|
|
428
|
+
best = { ...ev, idx };
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
for (const marker of leaf.line) {
|
|
432
|
+
consider(s.indexOf(marker, pos), { kind: "line", len: marker.length });
|
|
268
433
|
}
|
|
434
|
+
for (const [open, close, nestable] of leaf.block) {
|
|
435
|
+
consider(s.indexOf(open, pos), {
|
|
436
|
+
kind: "block",
|
|
437
|
+
len: open.length,
|
|
438
|
+
open,
|
|
439
|
+
close,
|
|
440
|
+
nestable: Boolean(nestable)
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
for (const ev of regionEvents(s, pos, grammar, state)) consider(ev.idx, ev);
|
|
269
444
|
return best;
|
|
270
445
|
}
|
|
271
|
-
function readBlockRest(s, pos,
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
446
|
+
function readBlockRest(s, pos, block, limit = s.length) {
|
|
447
|
+
const { open, close, nestable } = block;
|
|
448
|
+
const within = (idx) => idx !== -1 && idx < limit ? idx : -1;
|
|
449
|
+
let i = pos;
|
|
450
|
+
while (i < limit) {
|
|
451
|
+
const closeIdx = within(s.indexOf(close, i));
|
|
452
|
+
const openIdx = within(nestable ? s.indexOf(open, i) : -1);
|
|
453
|
+
if (closeIdx === -1 && openIdx === -1) break;
|
|
454
|
+
if (openIdx !== -1 && (closeIdx === -1 || openIdx < closeIdx)) {
|
|
455
|
+
block.depth++;
|
|
456
|
+
i = openIdx + open.length;
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
block.depth--;
|
|
460
|
+
i = closeIdx + close.length;
|
|
461
|
+
if (block.depth === 0) return { text: s.slice(pos, closeIdx) + " ", pos: i, closed: true };
|
|
462
|
+
}
|
|
463
|
+
return { text: s.slice(pos, limit) + " ", pos: limit, closed: false };
|
|
464
|
+
}
|
|
465
|
+
function regionExitAt(s, pos, region) {
|
|
466
|
+
const m = matchAt(region.exit, s, pos);
|
|
467
|
+
return m ? { idx: m.index, len: m[0].length } : null;
|
|
468
|
+
}
|
|
469
|
+
function consumeBlock(s, pos, state, exit) {
|
|
470
|
+
const rest = readBlockRest(s, pos, state.block, exit ? exit.idx : s.length);
|
|
471
|
+
if (rest.closed) {
|
|
472
|
+
state.block = null;
|
|
473
|
+
return { text: rest.text, pos: rest.pos };
|
|
474
|
+
}
|
|
475
|
+
if (exit) {
|
|
476
|
+
state.block = null;
|
|
477
|
+
state.region = null;
|
|
478
|
+
return { text: rest.text, pos: exit.idx + exit.len };
|
|
479
|
+
}
|
|
480
|
+
return { text: rest.text, pos: rest.pos };
|
|
275
481
|
}
|
|
276
|
-
function
|
|
482
|
+
function consumeLine(s, pos, state, exit) {
|
|
483
|
+
if (exit) {
|
|
484
|
+
state.region = null;
|
|
485
|
+
return { text: s.slice(pos, exit.idx) + " ", pos: exit.idx + exit.len, done: false };
|
|
486
|
+
}
|
|
487
|
+
return { text: s.slice(pos) + " ", pos: s.length, done: true };
|
|
488
|
+
}
|
|
489
|
+
function commentText(s, state, grammar) {
|
|
277
490
|
let comment = "";
|
|
278
491
|
let pos = 0;
|
|
279
492
|
while (pos < s.length) {
|
|
493
|
+
const exit = state.region ? regionExitAt(s, pos, state.region) : null;
|
|
280
494
|
if (state.block) {
|
|
281
|
-
const
|
|
282
|
-
comment +=
|
|
283
|
-
pos =
|
|
284
|
-
|
|
495
|
+
const r = consumeBlock(s, pos, state, exit);
|
|
496
|
+
comment += r.text;
|
|
497
|
+
pos = r.pos;
|
|
498
|
+
continue;
|
|
499
|
+
}
|
|
500
|
+
const ev = nextEvent(s, pos, grammar, state);
|
|
501
|
+
if (!ev) break;
|
|
502
|
+
pos = ev.idx + ev.len;
|
|
503
|
+
if (ev.kind === "line") {
|
|
504
|
+
const r = consumeLine(s, pos, state, exit);
|
|
505
|
+
comment += r.text;
|
|
506
|
+
pos = r.pos;
|
|
507
|
+
if (r.done) break;
|
|
508
|
+
} else if (ev.kind === "block") {
|
|
509
|
+
state.block = { open: ev.open, close: ev.close, nestable: ev.nestable, depth: 1 };
|
|
510
|
+
} else if (ev.kind === "enter") {
|
|
511
|
+
state.region = ev.region;
|
|
285
512
|
} else {
|
|
286
|
-
|
|
287
|
-
if (!start) break;
|
|
288
|
-
pos = start.idx + start.len;
|
|
289
|
-
if (start.kind === "line") {
|
|
290
|
-
comment += s.slice(pos) + " ";
|
|
291
|
-
pos = s.length;
|
|
292
|
-
} else {
|
|
293
|
-
state.block = start.kind;
|
|
294
|
-
}
|
|
513
|
+
state.region = null;
|
|
295
514
|
}
|
|
296
515
|
}
|
|
297
516
|
return comment;
|
|
@@ -331,13 +550,12 @@ function collectTags(comment, file, line, state, items, problems) {
|
|
|
331
550
|
}
|
|
332
551
|
function parseCode(file, text, problems, forwards = []) {
|
|
333
552
|
const ext = path2.extname(file).toLowerCase();
|
|
553
|
+
const grammar = grammarFor(ext) ?? cLike;
|
|
334
554
|
const lines = text.split(/\r?\n/);
|
|
335
555
|
const items = [];
|
|
336
|
-
const
|
|
337
|
-
const htmlBlocks = ext === ".vue";
|
|
338
|
-
const state = { last: null, byId: /* @__PURE__ */ new Map(), block: null };
|
|
556
|
+
const state = { last: null, byId: /* @__PURE__ */ new Map(), block: null, region: null };
|
|
339
557
|
for (let i = 0; i < lines.length; i++) {
|
|
340
|
-
const comment = commentText(lines[i], state,
|
|
558
|
+
const comment = commentText(lines[i], state, grammar);
|
|
341
559
|
for (const m of comment.matchAll(FORWARD_RE)) {
|
|
342
560
|
forwards.push(mkForward(m, 1, file, i + 1));
|
|
343
561
|
}
|
|
@@ -451,6 +669,13 @@ function groupIdsByKey(byId) {
|
|
|
451
669
|
(idsByKey.get(keyOf(id)) ?? idsByKey.set(keyOf(id), []).get(keyOf(id))).push(id);
|
|
452
670
|
return idsByKey;
|
|
453
671
|
}
|
|
672
|
+
function buildResolver(items) {
|
|
673
|
+
const byId = /* @__PURE__ */ new Map();
|
|
674
|
+
for (const it of items) (byId.get(it.id) ?? byId.set(it.id, []).get(it.id)).push(it);
|
|
675
|
+
const idsByKey = groupIdsByKey(byId);
|
|
676
|
+
const matchesOf = (ref) => (idsByKey.get(keyOf(ref)) ?? []).filter((id) => idMatches(ref, id));
|
|
677
|
+
return { byId, matchesOf };
|
|
678
|
+
}
|
|
454
679
|
function splitNeeds(items) {
|
|
455
680
|
const exact = /* @__PURE__ */ new Set();
|
|
456
681
|
const wildcard = [];
|
|
@@ -462,14 +687,10 @@ function splitNeeds(items) {
|
|
|
462
687
|
return { exact, wildcard };
|
|
463
688
|
}
|
|
464
689
|
function analyze(items, forwards = [], problems = []) {
|
|
465
|
-
const byId
|
|
690
|
+
const { byId, matchesOf } = buildResolver(items);
|
|
466
691
|
const revsByKey = /* @__PURE__ */ new Map();
|
|
467
|
-
for (const it of items)
|
|
468
|
-
(byId.get(it.id) ?? byId.set(it.id, []).get(it.id)).push(it);
|
|
692
|
+
for (const it of items)
|
|
469
693
|
(revsByKey.get(it.key) ?? revsByKey.set(it.key, /* @__PURE__ */ new Set()).get(it.key)).add(it.revision);
|
|
470
|
-
}
|
|
471
|
-
const idsByKey = groupIdsByKey(byId);
|
|
472
|
-
const matchesOf = (ref) => (idsByKey.get(keyOf(ref)) ?? []).filter((id) => idMatches(ref, id));
|
|
473
694
|
const { exact: exactNeeds, wildcard: wildcardNeeds } = splitNeeds(items);
|
|
474
695
|
const isNeeded = (id) => exactNeeds.has(id) || wildcardNeeds.some((w) => idMatches(w, id));
|
|
475
696
|
for (const [id, group] of byId) {
|
|
@@ -481,7 +702,10 @@ function analyze(items, forwards = [], problems = []) {
|
|
|
481
702
|
return revs ? ` (revision mismatch: existing revision(s) of ${keyOf(id)}: ${[...revs].sort(compareRev).join(", ")})` : "";
|
|
482
703
|
};
|
|
483
704
|
const fwdTarget = buildForwardMap(forwards, byId, exactNeeds, revHint, problems);
|
|
484
|
-
for (const it of items)
|
|
705
|
+
for (const it of items) {
|
|
706
|
+
it.forwardsTo = fwdTarget.get(it.id) ?? null;
|
|
707
|
+
checkItemReferences(it, byId, matchesOf, isNeeded, revHint, fwdTarget);
|
|
708
|
+
}
|
|
485
709
|
markDeepCoverage(items, byId, matchesOf, fwdTarget);
|
|
486
710
|
}
|
|
487
711
|
|
|
@@ -500,24 +724,94 @@ function makeStyler() {
|
|
|
500
724
|
bold: wrap("1")
|
|
501
725
|
};
|
|
502
726
|
}
|
|
503
|
-
function
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
727
|
+
function statusOf(it, c) {
|
|
728
|
+
if (it.defects.length > 0) return { mark: c.red("\u2718"), tag: c.red("[defective]") };
|
|
729
|
+
if (!it.deepCovered) return { mark: c.yellow("~"), tag: c.yellow("[shallow-covered]") };
|
|
730
|
+
return { mark: c.green("\u2714"), tag: c.green("[deep-covered]") };
|
|
731
|
+
}
|
|
732
|
+
function buildWantedBy(items, byId, matchesOf) {
|
|
733
|
+
const wantedBy = /* @__PURE__ */ new Map();
|
|
734
|
+
for (const it of items)
|
|
735
|
+
for (const n of it.needs)
|
|
736
|
+
for (const id of matchesOf(n))
|
|
737
|
+
for (const m of byId.get(id))
|
|
738
|
+
(wantedBy.get(m) ?? wantedBy.set(m, /* @__PURE__ */ new Set()).get(m)).add(it);
|
|
739
|
+
return wantedBy;
|
|
740
|
+
}
|
|
741
|
+
function byFileLine(a, b) {
|
|
742
|
+
if (a.file !== b.file) return a.file < b.file ? -1 : 1;
|
|
743
|
+
return a.line - b.line;
|
|
744
|
+
}
|
|
745
|
+
function forwardEdge(it, byId, c, dimLoc) {
|
|
746
|
+
const target = byId.get(it.forwardsTo)?.[0];
|
|
747
|
+
if (!target) return ` ${c.cyan("\u2192")} ${it.forwardsTo} ${c.red("\u2718 missing")}`;
|
|
748
|
+
return ` ${c.cyan("\u2192")} ${it.forwardsTo} ${statusOf(target, c).mark} ${dimLoc(target.file, target.line)}`;
|
|
749
|
+
}
|
|
750
|
+
function needEdges(it, byId, matchesOf, c, dimLoc) {
|
|
751
|
+
const lines = [];
|
|
752
|
+
for (const n of it.needs) {
|
|
753
|
+
const ids = matchesOf(n);
|
|
754
|
+
if (ids.length === 0) {
|
|
755
|
+
lines.push(` ${c.dim("needs")} ${n} ${c.red("\u2718 missing")}`);
|
|
756
|
+
continue;
|
|
757
|
+
}
|
|
758
|
+
const wild = isWildcardRev(revOf(n));
|
|
759
|
+
for (const id of ids) {
|
|
760
|
+
const m = byId.get(id)[0];
|
|
761
|
+
const arrow = c.dim(`(\u2192 ${id})`);
|
|
762
|
+
const ref = wild ? `${n} ${arrow}` : n;
|
|
763
|
+
lines.push(` ${c.dim("needs")} ${ref} ${statusOf(m, c).mark} ${dimLoc(m.file, m.line)}`);
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
return lines;
|
|
767
|
+
}
|
|
768
|
+
function coverEdges(it, byId, c, dimLoc) {
|
|
769
|
+
const lines = [];
|
|
770
|
+
for (const cv of it.covers) {
|
|
771
|
+
const target = byId.get(cv)?.[0];
|
|
772
|
+
if (!target) lines.push(` ${c.dim("covers")} ${cv} ${c.red("\u2718 missing")}`);
|
|
773
|
+
else lines.push(` ${c.dim("covers")} ${cv} ${c.green("\u2714")} ${dimLoc(target.file, target.line)}`);
|
|
774
|
+
}
|
|
775
|
+
return lines;
|
|
776
|
+
}
|
|
777
|
+
function edgeLines(it, byId, matchesOf, wantedBy, c, dimLoc) {
|
|
778
|
+
const lines = [];
|
|
779
|
+
if (it.forwardsTo !== null) lines.push(forwardEdge(it, byId, c, dimLoc));
|
|
780
|
+
else if (it.origin === "markdown") lines.push(...needEdges(it, byId, matchesOf, c, dimLoc));
|
|
781
|
+
lines.push(...coverEdges(it, byId, c, dimLoc));
|
|
782
|
+
for (const w of wantedBy.get(it) ?? [])
|
|
783
|
+
lines.push(` ${c.dim("wanted by")} ${w.id} ${dimLoc(w.file, w.line)}`);
|
|
784
|
+
return lines;
|
|
785
|
+
}
|
|
786
|
+
function renderVerbose(items, out, c, dimLoc) {
|
|
787
|
+
const { byId, matchesOf } = buildResolver(items);
|
|
788
|
+
const wantedBy = buildWantedBy(items, byId, matchesOf);
|
|
789
|
+
const sorted = [...items].sort(byFileLine);
|
|
790
|
+
let prevFile = null;
|
|
791
|
+
for (const it of sorted) {
|
|
792
|
+
if (prevFile !== null && it.file !== prevFile) out.push("");
|
|
793
|
+
prevFile = it.file;
|
|
794
|
+
const { mark, tag } = statusOf(it, c);
|
|
795
|
+
const title = it.title ? " " + c.dim(`"${it.title}"`) : "";
|
|
796
|
+
out.push(
|
|
797
|
+
`${mark} ${c.bold(it.id)}${title} ${dimLoc(it.file, it.line)} ${tag}`,
|
|
798
|
+
...edgeLines(it, byId, matchesOf, wantedBy, c, dimLoc)
|
|
799
|
+
);
|
|
800
|
+
for (const d of it.defects) out.push(` ${c.red("\u2022")} ${d}`);
|
|
801
|
+
}
|
|
802
|
+
if (sorted.length) out.push("");
|
|
803
|
+
}
|
|
804
|
+
function renderDefective(defective, out, c, dimLoc) {
|
|
509
805
|
for (const it of defective) {
|
|
510
806
|
const title = it.title ? " " + c.dim(`"${it.title}"`) : "";
|
|
511
807
|
out.push(
|
|
512
|
-
`${c.
|
|
808
|
+
`${statusOf(it, c).mark} ${c.bold(it.id)}${title} ${dimLoc(it.file, it.line)}`
|
|
513
809
|
);
|
|
514
810
|
for (const d of it.defects) out.push(` ${c.red("\u2022")} ${d}`);
|
|
515
811
|
out.push("");
|
|
516
812
|
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
520
|
-
if (problems.length) out.push("");
|
|
813
|
+
}
|
|
814
|
+
function renderSummary(items, defective, problems, out, c) {
|
|
521
815
|
const okCount = items.length - defective.length;
|
|
522
816
|
const notDeep = items.filter((it) => it.defects.length === 0 && !it.deepCovered).length;
|
|
523
817
|
const md = items.filter((i) => i.origin === "markdown").length;
|
|
@@ -531,6 +825,21 @@ function report(items, problems, cwd) {
|
|
|
531
825
|
if (notDeep) out.push(" " + c.dim(`of the ok items, ${notDeep} are only shallow-covered (an item further down the tracing chain is defective)`));
|
|
532
826
|
if (problems.length) out.push(` problems ${c.yellow(String(problems.length))}`);
|
|
533
827
|
out.push("");
|
|
828
|
+
}
|
|
829
|
+
function report(items, problems, cwd, opts = {}) {
|
|
830
|
+
const { verbose = false } = opts;
|
|
831
|
+
const c = makeStyler();
|
|
832
|
+
const rel = (f) => path3.relative(cwd, f) || f;
|
|
833
|
+
const dimLoc = (file, line) => c.dim(`${rel(file)}:${line}`);
|
|
834
|
+
const defective = items.filter((it) => it.defects.length > 0);
|
|
835
|
+
const out = [];
|
|
836
|
+
if (verbose) renderVerbose(items, out, c, dimLoc);
|
|
837
|
+
else renderDefective(defective, out, c, dimLoc);
|
|
838
|
+
for (const p of problems) {
|
|
839
|
+
out.push(`${c.yellow("\u26A0")} ${p.message} ${dimLoc(p.file, p.line)}`);
|
|
840
|
+
}
|
|
841
|
+
if (problems.length) out.push("");
|
|
842
|
+
renderSummary(items, defective, problems, out, c);
|
|
534
843
|
const clean = defective.length === 0 && problems.length === 0;
|
|
535
844
|
out.push(clean ? c.green(c.bold("ok")) : c.red(c.bold("not ok")));
|
|
536
845
|
console.log(out.join("\n"));
|
|
@@ -547,8 +856,10 @@ by git are excluded.
|
|
|
547
856
|
Options:
|
|
548
857
|
-t, --tags <t1,t2,...> only import markdown items carrying one of these
|
|
549
858
|
tags; add "_" to also include untagged items
|
|
859
|
+
-v, --verbose list every item with its coverage status and trace
|
|
860
|
+
edges, not only the defective ones
|
|
861
|
+
-V, --version print the version number
|
|
550
862
|
-h, --help show this help
|
|
551
|
-
-v, --version print the version number
|
|
552
863
|
|
|
553
864
|
Exit codes: 0 clean, 1 defects or problems found, 2 usage error`;
|
|
554
865
|
function packageVersion() {
|
|
@@ -556,13 +867,15 @@ function packageVersion() {
|
|
|
556
867
|
return JSON.parse(readFileSync(pkg, "utf8")).version;
|
|
557
868
|
}
|
|
558
869
|
function parseArgs(argv) {
|
|
559
|
-
const opts = { dirs: [], tags: null };
|
|
870
|
+
const opts = { dirs: [], tags: null, verbose: false };
|
|
560
871
|
for (let i = 0; i < argv.length; i++) {
|
|
561
872
|
const a = argv[i];
|
|
562
873
|
if (a === "-h" || a === "--help") {
|
|
563
874
|
console.log(HELP);
|
|
564
875
|
process3.exit(0);
|
|
565
|
-
} else if (a === "-v" || a === "--
|
|
876
|
+
} else if (a === "-v" || a === "--verbose") {
|
|
877
|
+
opts.verbose = true;
|
|
878
|
+
} else if (a === "-V" || a === "--version") {
|
|
566
879
|
console.log(packageVersion());
|
|
567
880
|
process3.exit(0);
|
|
568
881
|
} else if (a === "-t" || a === "--tags") {
|
|
@@ -598,7 +911,7 @@ async function main() {
|
|
|
598
911
|
);
|
|
599
912
|
}
|
|
600
913
|
analyze(items, forwards, problems);
|
|
601
|
-
const clean = report(items, problems, process3.cwd());
|
|
914
|
+
const clean = report(items, problems, process3.cwd(), { verbose: opts.verbose });
|
|
602
915
|
process3.exit(clean ? 0 : 1);
|
|
603
916
|
}
|
|
604
917
|
function runCli() {
|