flashtrace 0.5.0 → 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 +120 -23
- package/package.json +1 -1
package/dist/flashtrace.mjs
CHANGED
|
@@ -285,7 +285,9 @@ function newItem(id, origin, file, line) {
|
|
|
285
285
|
needs: [],
|
|
286
286
|
covers: [],
|
|
287
287
|
tags: [],
|
|
288
|
-
defects: []
|
|
288
|
+
defects: [],
|
|
289
|
+
forwardsTo: null
|
|
290
|
+
// effective forwarding target, set by analyze
|
|
289
291
|
};
|
|
290
292
|
}
|
|
291
293
|
|
|
@@ -667,6 +669,13 @@ function groupIdsByKey(byId) {
|
|
|
667
669
|
(idsByKey.get(keyOf(id)) ?? idsByKey.set(keyOf(id), []).get(keyOf(id))).push(id);
|
|
668
670
|
return idsByKey;
|
|
669
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
|
+
}
|
|
670
679
|
function splitNeeds(items) {
|
|
671
680
|
const exact = /* @__PURE__ */ new Set();
|
|
672
681
|
const wildcard = [];
|
|
@@ -678,14 +687,10 @@ function splitNeeds(items) {
|
|
|
678
687
|
return { exact, wildcard };
|
|
679
688
|
}
|
|
680
689
|
function analyze(items, forwards = [], problems = []) {
|
|
681
|
-
const byId
|
|
690
|
+
const { byId, matchesOf } = buildResolver(items);
|
|
682
691
|
const revsByKey = /* @__PURE__ */ new Map();
|
|
683
|
-
for (const it of items)
|
|
684
|
-
(byId.get(it.id) ?? byId.set(it.id, []).get(it.id)).push(it);
|
|
692
|
+
for (const it of items)
|
|
685
693
|
(revsByKey.get(it.key) ?? revsByKey.set(it.key, /* @__PURE__ */ new Set()).get(it.key)).add(it.revision);
|
|
686
|
-
}
|
|
687
|
-
const idsByKey = groupIdsByKey(byId);
|
|
688
|
-
const matchesOf = (ref) => (idsByKey.get(keyOf(ref)) ?? []).filter((id) => idMatches(ref, id));
|
|
689
694
|
const { exact: exactNeeds, wildcard: wildcardNeeds } = splitNeeds(items);
|
|
690
695
|
const isNeeded = (id) => exactNeeds.has(id) || wildcardNeeds.some((w) => idMatches(w, id));
|
|
691
696
|
for (const [id, group] of byId) {
|
|
@@ -697,7 +702,10 @@ function analyze(items, forwards = [], problems = []) {
|
|
|
697
702
|
return revs ? ` (revision mismatch: existing revision(s) of ${keyOf(id)}: ${[...revs].sort(compareRev).join(", ")})` : "";
|
|
698
703
|
};
|
|
699
704
|
const fwdTarget = buildForwardMap(forwards, byId, exactNeeds, revHint, problems);
|
|
700
|
-
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
|
+
}
|
|
701
709
|
markDeepCoverage(items, byId, matchesOf, fwdTarget);
|
|
702
710
|
}
|
|
703
711
|
|
|
@@ -716,24 +724,94 @@ function makeStyler() {
|
|
|
716
724
|
bold: wrap("1")
|
|
717
725
|
};
|
|
718
726
|
}
|
|
719
|
-
function
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
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) {
|
|
725
805
|
for (const it of defective) {
|
|
726
806
|
const title = it.title ? " " + c.dim(`"${it.title}"`) : "";
|
|
727
807
|
out.push(
|
|
728
|
-
`${c.
|
|
808
|
+
`${statusOf(it, c).mark} ${c.bold(it.id)}${title} ${dimLoc(it.file, it.line)}`
|
|
729
809
|
);
|
|
730
810
|
for (const d of it.defects) out.push(` ${c.red("\u2022")} ${d}`);
|
|
731
811
|
out.push("");
|
|
732
812
|
}
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
}
|
|
736
|
-
if (problems.length) out.push("");
|
|
813
|
+
}
|
|
814
|
+
function renderSummary(items, defective, problems, out, c) {
|
|
737
815
|
const okCount = items.length - defective.length;
|
|
738
816
|
const notDeep = items.filter((it) => it.defects.length === 0 && !it.deepCovered).length;
|
|
739
817
|
const md = items.filter((i) => i.origin === "markdown").length;
|
|
@@ -747,6 +825,21 @@ function report(items, problems, cwd) {
|
|
|
747
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)`));
|
|
748
826
|
if (problems.length) out.push(` problems ${c.yellow(String(problems.length))}`);
|
|
749
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);
|
|
750
843
|
const clean = defective.length === 0 && problems.length === 0;
|
|
751
844
|
out.push(clean ? c.green(c.bold("ok")) : c.red(c.bold("not ok")));
|
|
752
845
|
console.log(out.join("\n"));
|
|
@@ -763,8 +856,10 @@ by git are excluded.
|
|
|
763
856
|
Options:
|
|
764
857
|
-t, --tags <t1,t2,...> only import markdown items carrying one of these
|
|
765
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
|
|
766
862
|
-h, --help show this help
|
|
767
|
-
-v, --version print the version number
|
|
768
863
|
|
|
769
864
|
Exit codes: 0 clean, 1 defects or problems found, 2 usage error`;
|
|
770
865
|
function packageVersion() {
|
|
@@ -772,13 +867,15 @@ function packageVersion() {
|
|
|
772
867
|
return JSON.parse(readFileSync(pkg, "utf8")).version;
|
|
773
868
|
}
|
|
774
869
|
function parseArgs(argv) {
|
|
775
|
-
const opts = { dirs: [], tags: null };
|
|
870
|
+
const opts = { dirs: [], tags: null, verbose: false };
|
|
776
871
|
for (let i = 0; i < argv.length; i++) {
|
|
777
872
|
const a = argv[i];
|
|
778
873
|
if (a === "-h" || a === "--help") {
|
|
779
874
|
console.log(HELP);
|
|
780
875
|
process3.exit(0);
|
|
781
|
-
} else if (a === "-v" || a === "--
|
|
876
|
+
} else if (a === "-v" || a === "--verbose") {
|
|
877
|
+
opts.verbose = true;
|
|
878
|
+
} else if (a === "-V" || a === "--version") {
|
|
782
879
|
console.log(packageVersion());
|
|
783
880
|
process3.exit(0);
|
|
784
881
|
} else if (a === "-t" || a === "--tags") {
|
|
@@ -814,7 +911,7 @@ async function main() {
|
|
|
814
911
|
);
|
|
815
912
|
}
|
|
816
913
|
analyze(items, forwards, problems);
|
|
817
|
-
const clean = report(items, problems, process3.cwd());
|
|
914
|
+
const clean = report(items, problems, process3.cwd(), { verbose: opts.verbose });
|
|
818
915
|
process3.exit(clean ? 0 : 1);
|
|
819
916
|
}
|
|
820
917
|
function runCli() {
|