flashtrace 0.11.5 → 0.12.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 +60 -41
- package/package.json +1 -1
package/dist/flashtrace.mjs
CHANGED
|
@@ -244,7 +244,7 @@ async function collectFiles(dirs) {
|
|
|
244
244
|
// src/ids.mjs
|
|
245
245
|
var SEGMENT_SRC = "[A-Za-z][A-Za-z0-9_.-]*";
|
|
246
246
|
var REV_SRC = String.raw`\d+(?:\.\d+){0,2}`;
|
|
247
|
-
var WILDCARD_SRC = String.raw`(?:\d
|
|
247
|
+
var WILDCARD_SRC = String.raw`(?:\d+\.){0,2}[x*]`;
|
|
248
248
|
var REV_REF_SRC = `(?:${WILDCARD_SRC}|${REV_SRC})`;
|
|
249
249
|
var ID_SRC = String.raw`([A-Za-z]+):(?:((?:${SEGMENT_SRC}\/)*${SEGMENT_SRC})\/)?(${SEGMENT_SRC})#(${REV_SRC})`;
|
|
250
250
|
var ID_RE = new RegExp(`^${ID_SRC}$`);
|
|
@@ -265,25 +265,29 @@ var keyOf = (id) => id.slice(0, id.lastIndexOf("#"));
|
|
|
265
265
|
var revOf = (id) => id.slice(id.lastIndexOf("#") + 1);
|
|
266
266
|
var pathOf = (id) => id.slice(id.indexOf(":") + 1, id.lastIndexOf("#"));
|
|
267
267
|
var resolveRef = (type, path6, rev, ownerId) => `${type}:${path6 ?? pathOf(ownerId)}#${rev ?? revOf(ownerId)}`;
|
|
268
|
+
function canonicalRev(rev) {
|
|
269
|
+
const layers = rev.split(".").map((layer) => String(Number(layer)));
|
|
270
|
+
while (layers.length < 3) layers.push("0");
|
|
271
|
+
return layers.join(".");
|
|
272
|
+
}
|
|
273
|
+
var canonicalId = (id) => `${keyOf(id)}#${canonicalRev(revOf(id))}`;
|
|
268
274
|
function compareRev(a, b) {
|
|
269
|
-
const
|
|
270
|
-
const
|
|
271
|
-
for (let i = 0; i <
|
|
272
|
-
if (i
|
|
273
|
-
if (i >= partsB.length) return 1;
|
|
274
|
-
if (partsA[i] !== partsB[i]) return Number(partsA[i]) - Number(partsB[i]);
|
|
275
|
+
const layersA = canonicalRev(a).split(".");
|
|
276
|
+
const layersB = canonicalRev(b).split(".");
|
|
277
|
+
for (let i = 0; i < 3; i++) {
|
|
278
|
+
if (layersA[i] !== layersB[i]) return Number(layersA[i]) - Number(layersB[i]);
|
|
275
279
|
}
|
|
276
280
|
return 0;
|
|
277
281
|
}
|
|
278
|
-
var
|
|
279
|
-
var isWildcardRev = (rev) => /[
|
|
282
|
+
var isWildcardLayer = (layer) => layer === "x" || layer === "*";
|
|
283
|
+
var isWildcardRev = (rev) => /[x*]/.test(rev);
|
|
280
284
|
function revMatches(pattern, concrete) {
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
for (let i = 0; i <
|
|
285
|
-
if (
|
|
286
|
-
if (
|
|
285
|
+
const patternLayers = pattern.split(".");
|
|
286
|
+
while (patternLayers.length < 3) patternLayers.push(isWildcardLayer(patternLayers.at(-1)) ? "x" : "0");
|
|
287
|
+
const concreteLayers = canonicalRev(concrete).split(".");
|
|
288
|
+
for (let i = 0; i < 3; i++) {
|
|
289
|
+
if (isWildcardLayer(patternLayers[i])) continue;
|
|
290
|
+
if (Number(patternLayers[i]) !== Number(concreteLayers[i])) return false;
|
|
287
291
|
}
|
|
288
292
|
return true;
|
|
289
293
|
}
|
|
@@ -303,6 +307,8 @@ function newItem(id, origin, file, line, character) {
|
|
|
303
307
|
id,
|
|
304
308
|
key: keyOf(id),
|
|
305
309
|
revision: revOf(id),
|
|
310
|
+
canonicalId: canonicalId(id),
|
|
311
|
+
// the SemVer-equal identity every exact-ID lookup keys on
|
|
306
312
|
origin,
|
|
307
313
|
// 'spec' | 'code'
|
|
308
314
|
file,
|
|
@@ -735,7 +741,7 @@ function commentText(line, state, grammar) {
|
|
|
735
741
|
}
|
|
736
742
|
function attachNeed(m, file, line, character, state, problems) {
|
|
737
743
|
const source = m[1] ? makeId(m[1], m[2], m[3], m[4]) : null;
|
|
738
|
-
const anchor = source ? state.byId.get(source) : state.lastItem;
|
|
744
|
+
const anchor = source ? state.byId.get(canonicalId(source)) : state.lastItem;
|
|
739
745
|
if (!anchor) {
|
|
740
746
|
const written = m[5] + (m[6] ? `:${m[6]}` : "") + (m[7] ? `#${m[7]}` : "");
|
|
741
747
|
problems.push({
|
|
@@ -754,7 +760,7 @@ function collectTags(comment, file, line, state, items, problems) {
|
|
|
754
760
|
if (m[8]) {
|
|
755
761
|
const item = newItem(makeId(m[8], m[9], m[10], m[11]), "code", file, line, character);
|
|
756
762
|
state.lastItem = item;
|
|
757
|
-
state.byId.set(item.
|
|
763
|
+
state.byId.set(item.canonicalId, item);
|
|
758
764
|
items.push(item);
|
|
759
765
|
} else {
|
|
760
766
|
attachNeed(m, file, line, character, state, problems);
|
|
@@ -825,9 +831,9 @@ var duplicateForwarding = (from, count) => ({
|
|
|
825
831
|
|
|
826
832
|
// src/analyze.mjs
|
|
827
833
|
function checkItemReferences(item, byId, matchesOf, isNeeded, withRevisions, forwardTargets) {
|
|
828
|
-
const forwardTarget = forwardTargets.get(item.
|
|
834
|
+
const forwardTarget = forwardTargets.get(item.canonicalId);
|
|
829
835
|
if (forwardTarget !== void 0) {
|
|
830
|
-
if (!byId.has(forwardTarget))
|
|
836
|
+
if (!byId.has(canonicalId(forwardTarget)))
|
|
831
837
|
item.defects.push(withRevisions(uncoveredForward(forwardTarget)));
|
|
832
838
|
} else {
|
|
833
839
|
for (const need of item.needs) {
|
|
@@ -836,17 +842,18 @@ function checkItemReferences(item, byId, matchesOf, isNeeded, withRevisions, for
|
|
|
836
842
|
}
|
|
837
843
|
}
|
|
838
844
|
for (const coverId of item.covers) {
|
|
839
|
-
const targets = byId.get(coverId);
|
|
845
|
+
const targets = byId.get(canonicalId(coverId));
|
|
840
846
|
if (!targets) {
|
|
841
847
|
item.defects.push(withRevisions(orphanedCover(coverId)));
|
|
842
848
|
} else if (!targets.some((target) => target.needs.some((need) => idMatches(need, item.id)))) {
|
|
843
849
|
item.defects.push(unwantedCover(coverId, item.id));
|
|
844
850
|
}
|
|
845
851
|
}
|
|
846
|
-
if (item.origin === "code" && !isNeeded(item.
|
|
852
|
+
if (item.origin === "code" && !isNeeded(item.canonicalId)) {
|
|
847
853
|
item.defects.push(unwantedItem(item.id));
|
|
848
854
|
}
|
|
849
855
|
}
|
|
856
|
+
var displayedDuplicateId = (writtenIds, canonical) => writtenIds.every((id) => id === writtenIds[0]) ? writtenIds[0] : canonical;
|
|
850
857
|
function dropCyclicForwards(forwardTargets, declarationBySource, problems) {
|
|
851
858
|
const done = /* @__PURE__ */ new Set();
|
|
852
859
|
for (const start of forwardTargets.keys()) {
|
|
@@ -857,11 +864,11 @@ function dropCyclicForwards(forwardTargets, declarationBySource, problems) {
|
|
|
857
864
|
while (forwardTargets.has(current) && !done.has(current) && !seen.has(current)) {
|
|
858
865
|
seen.set(current, path6.length);
|
|
859
866
|
path6.push(current);
|
|
860
|
-
current = forwardTargets.get(current);
|
|
867
|
+
current = canonicalId(forwardTargets.get(current));
|
|
861
868
|
}
|
|
862
869
|
if (seen.has(current)) {
|
|
863
870
|
const cycle = path6.slice(seen.get(current));
|
|
864
|
-
const chain = [...cycle, current].join(" --> ");
|
|
871
|
+
const chain = [...cycle, current].map((id) => declarationBySource.get(id).from).join(" --> ");
|
|
865
872
|
for (const id of cycle) {
|
|
866
873
|
const declaration = declarationBySource.get(id);
|
|
867
874
|
declaration.effective = false;
|
|
@@ -883,7 +890,8 @@ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
|
|
|
883
890
|
const declarationBySource = /* @__PURE__ */ new Map();
|
|
884
891
|
const forwardsBySource = /* @__PURE__ */ new Map();
|
|
885
892
|
for (const forward of forwards) {
|
|
886
|
-
|
|
893
|
+
const from = canonicalId(forward.from);
|
|
894
|
+
(forwardsBySource.get(from) ?? forwardsBySource.set(from, []).get(from)).push(forward);
|
|
887
895
|
}
|
|
888
896
|
for (const [from, group] of forwardsBySource) {
|
|
889
897
|
const sources = byId.get(from);
|
|
@@ -895,13 +903,15 @@ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
|
|
|
895
903
|
file: forward.file,
|
|
896
904
|
line: forward.line,
|
|
897
905
|
character: forward.character,
|
|
898
|
-
message: `forwarding from ${from}, which does not exist${revHint(from)}`
|
|
906
|
+
message: `forwarding from ${forward.from}, which does not exist${revHint(forward.from)}`
|
|
899
907
|
});
|
|
900
908
|
}
|
|
901
909
|
continue;
|
|
902
910
|
}
|
|
903
|
-
if (group.length > 1)
|
|
904
|
-
|
|
911
|
+
if (group.length > 1) {
|
|
912
|
+
const shown = displayedDuplicateId(group.map((forward) => forward.from), from);
|
|
913
|
+
for (const item of sources) item.defects.push(duplicateForwarding(shown, group.length));
|
|
914
|
+
}
|
|
905
915
|
group[0].effective = true;
|
|
906
916
|
for (let i = 1; i < group.length; i++) {
|
|
907
917
|
group[i].effective = false;
|
|
@@ -911,7 +921,7 @@ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
|
|
|
911
921
|
declarationBySource.set(from, group[0]);
|
|
912
922
|
}
|
|
913
923
|
dropCyclicForwards(forwardTargets, declarationBySource, problems);
|
|
914
|
-
for (const to of forwardTargets.values()) neededIds.add(to);
|
|
924
|
+
for (const to of forwardTargets.values()) neededIds.add(canonicalId(to));
|
|
915
925
|
return forwardTargets;
|
|
916
926
|
}
|
|
917
927
|
function markDeepCoverage(items, byId, matchesOf, forwardTargets) {
|
|
@@ -927,7 +937,7 @@ function markDeepCoverage(items, byId, matchesOf, forwardTargets) {
|
|
|
927
937
|
const forwardTarget = forwardTargets.get(id);
|
|
928
938
|
let ok = true;
|
|
929
939
|
if (forwardTarget !== void 0) {
|
|
930
|
-
ok = deep(forwardTarget);
|
|
940
|
+
ok = deep(canonicalId(forwardTarget));
|
|
931
941
|
} else {
|
|
932
942
|
for (const item of group) for (const need of item.needs) if (!needDeep(need)) ok = false;
|
|
933
943
|
}
|
|
@@ -935,7 +945,7 @@ function markDeepCoverage(items, byId, matchesOf, forwardTargets) {
|
|
|
935
945
|
return ok;
|
|
936
946
|
};
|
|
937
947
|
const needDeep = (need) => matchesOf(need).some((id) => deep(id));
|
|
938
|
-
for (const item of items) item.deepCovered = deep(item.
|
|
948
|
+
for (const item of items) item.deepCovered = deep(item.canonicalId);
|
|
939
949
|
}
|
|
940
950
|
function groupIdsByKey(byId) {
|
|
941
951
|
const idsByKey = /* @__PURE__ */ new Map();
|
|
@@ -954,7 +964,9 @@ function buildWantedBy(items, byId, matchesOf) {
|
|
|
954
964
|
}
|
|
955
965
|
function buildResolver(items) {
|
|
956
966
|
const byId = /* @__PURE__ */ new Map();
|
|
957
|
-
for (const item of items)
|
|
967
|
+
for (const item of items) {
|
|
968
|
+
(byId.get(item.canonicalId) ?? byId.set(item.canonicalId, []).get(item.canonicalId)).push(item);
|
|
969
|
+
}
|
|
958
970
|
const idsByKey = groupIdsByKey(byId);
|
|
959
971
|
const matchesOf = (ref) => (idsByKey.get(keyOf(ref)) ?? []).filter((id) => idMatches(ref, id));
|
|
960
972
|
return { byId, matchesOf, wantedBy: buildWantedBy(items, byId, matchesOf) };
|
|
@@ -986,7 +998,7 @@ function splitNeeds(items) {
|
|
|
986
998
|
for (const item of items)
|
|
987
999
|
for (const need of item.needs) {
|
|
988
1000
|
if (isWildcardRev(revOf(need))) wildcard.push(need);
|
|
989
|
-
else exact.add(need);
|
|
1001
|
+
else exact.add(canonicalId(need));
|
|
990
1002
|
}
|
|
991
1003
|
return { exact, wildcard };
|
|
992
1004
|
}
|
|
@@ -996,9 +1008,12 @@ function analyze(items, forwards = [], problems = []) {
|
|
|
996
1008
|
for (const item of items)
|
|
997
1009
|
(revsByKey.get(item.key) ?? revsByKey.set(item.key, /* @__PURE__ */ new Set()).get(item.key)).add(item.revision);
|
|
998
1010
|
const { exact: exactNeeds, wildcard: wildcardNeeds } = splitNeeds(items);
|
|
999
|
-
const isNeeded = (
|
|
1011
|
+
const isNeeded = (canonical) => exactNeeds.has(canonical) || wildcardNeeds.some((wildcard) => idMatches(wildcard, canonical));
|
|
1000
1012
|
for (const [id, group] of byId) {
|
|
1001
|
-
if (group.length > 1)
|
|
1013
|
+
if (group.length > 1) {
|
|
1014
|
+
const shown = displayedDuplicateId(group.map((item) => item.id), id);
|
|
1015
|
+
for (const item of group) item.defects.push(duplicateId(shown, group.length));
|
|
1016
|
+
}
|
|
1002
1017
|
}
|
|
1003
1018
|
const existingRevisionsOf = (id) => {
|
|
1004
1019
|
const revs = revsByKey.get(keyOf(id));
|
|
@@ -1020,7 +1035,7 @@ function analyze(items, forwards = [], problems = []) {
|
|
|
1020
1035
|
};
|
|
1021
1036
|
const forwardTargets = buildForwardMap(forwards, byId, exactNeeds, revHint, problems);
|
|
1022
1037
|
for (const item of items) {
|
|
1023
|
-
item.forwardsTo = forwardTargets.get(item.
|
|
1038
|
+
item.forwardsTo = forwardTargets.get(item.canonicalId) ?? null;
|
|
1024
1039
|
checkItemReferences(item, byId, matchesOf, isNeeded, withRevisions, forwardTargets);
|
|
1025
1040
|
}
|
|
1026
1041
|
markDeepCoverage(items, byId, matchesOf, forwardTargets);
|
|
@@ -1056,7 +1071,7 @@ function byFileLine(a, b) {
|
|
|
1056
1071
|
return a.line - b.line;
|
|
1057
1072
|
}
|
|
1058
1073
|
function forwardEdge(item, byId, style, dimLocation) {
|
|
1059
|
-
const target = byId.get(item.forwardsTo)?.[0];
|
|
1074
|
+
const target = byId.get(canonicalId(item.forwardsTo))?.[0];
|
|
1060
1075
|
if (!target) return ` ${style.cyan("\u2192")} ${item.forwardsTo} ${style.red("\u2718 missing")}`;
|
|
1061
1076
|
return ` ${style.cyan("\u2192")} ${item.forwardsTo} ${styledStatus(target, style).mark} ${dimLocation(target.file, target.line)}`;
|
|
1062
1077
|
}
|
|
@@ -1071,8 +1086,8 @@ function needEdges(item, byId, matchesOf, style, dimLocation) {
|
|
|
1071
1086
|
const wildcard = isWildcardRev(revOf(need));
|
|
1072
1087
|
for (const id of ids) {
|
|
1073
1088
|
const covering = byId.get(id)[0];
|
|
1074
|
-
const arrow = style.dim(`(\u2192 ${id})`);
|
|
1075
|
-
const ref = wildcard ? `${need} ${arrow}` : need;
|
|
1089
|
+
const arrow = style.dim(`(\u2192 ${covering.id})`);
|
|
1090
|
+
const ref = wildcard || covering.id !== need ? `${need} ${arrow}` : need;
|
|
1076
1091
|
lines.push(` ${style.dim("needs")} ${ref} ${styledStatus(covering, style).mark} ${dimLocation(covering.file, covering.line)}`);
|
|
1077
1092
|
}
|
|
1078
1093
|
}
|
|
@@ -1081,7 +1096,7 @@ function needEdges(item, byId, matchesOf, style, dimLocation) {
|
|
|
1081
1096
|
function coverEdges(item, byId, style, dimLocation) {
|
|
1082
1097
|
const lines = [];
|
|
1083
1098
|
for (const coverId of item.covers) {
|
|
1084
|
-
const target = byId.get(coverId)?.[0];
|
|
1099
|
+
const target = byId.get(canonicalId(coverId))?.[0];
|
|
1085
1100
|
if (!target) lines.push(` ${style.dim("covers")} ${coverId} ${style.red("\u2718 missing")}`);
|
|
1086
1101
|
else lines.push(` ${style.dim("covers")} ${coverId} ${style.green("\u2714")} ${dimLocation(target.file, target.line)}`);
|
|
1087
1102
|
}
|
|
@@ -1172,7 +1187,7 @@ function buildForwardedFrom(items, byId) {
|
|
|
1172
1187
|
const forwardedFrom = /* @__PURE__ */ new Map();
|
|
1173
1188
|
for (const item of items) {
|
|
1174
1189
|
if (item.forwardsTo === null) continue;
|
|
1175
|
-
for (const target of byId.get(item.forwardsTo) ?? [])
|
|
1190
|
+
for (const target of byId.get(canonicalId(item.forwardsTo)) ?? [])
|
|
1176
1191
|
(forwardedFrom.get(target) ?? forwardedFrom.set(target, []).get(target)).push(item);
|
|
1177
1192
|
}
|
|
1178
1193
|
return forwardedFrom;
|
|
@@ -1196,7 +1211,11 @@ function buildReportDocument(items, forwards, problems, cwd, opts = {}) {
|
|
|
1196
1211
|
};
|
|
1197
1212
|
const { byId, matchesOf, wantedBy } = buildResolver(items);
|
|
1198
1213
|
const forwardedFrom = buildForwardedFrom(items, byId);
|
|
1199
|
-
const resolvedTo = (ref) =>
|
|
1214
|
+
const resolvedTo = (ref) => [
|
|
1215
|
+
...new Set(
|
|
1216
|
+
matchesOf(ref).sort((a, b) => compareRev(revOf(a), revOf(b))).flatMap((id) => byId.get(id).map((item) => item.id))
|
|
1217
|
+
)
|
|
1218
|
+
];
|
|
1200
1219
|
const itemRefs = (related) => [...related].map((other) => ({ id: other.id, ...location(other) })).sort(byLocation);
|
|
1201
1220
|
const itemDocument = (item) => {
|
|
1202
1221
|
const coverStatus = coverStatusOf(item);
|