flashtrace 0.11.4 → 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.
Files changed (2) hide show
  1. package/dist/flashtrace.mjs +75 -41
  2. package/package.json +1 -1
@@ -27,6 +27,7 @@ var hash = { line: ["#"], block: [] };
27
27
  var coffee = { line: ["#", "####"], block: [["###", "###"]] };
28
28
  var julia = { line: ["#"], block: [["#=", "=#", true]] };
29
29
  var nim = { line: ["#"], block: [["#[", "]#", true], ["##[", "]##", true]] };
30
+ var cmake = { line: ["#"], block: [["#[[", "]]"]] };
30
31
  var powershell = { line: ["#"], block: [["<#", "#>"]] };
31
32
  var sql = { line: ["--"], block: [["/*", "*/"]] };
32
33
  var lua = { line: ["--"], block: [["--[[", "]]"]] };
@@ -78,9 +79,17 @@ var BY_EXT = {
78
79
  ".cpp": cLike,
79
80
  ".cc": cLike,
80
81
  ".hpp": cLike,
82
+ ".cxx": cLike,
83
+ ".hxx": cLike,
84
+ ".ino": cLike,
85
+ ".inl": cLike,
86
+ ".tpp": cLike,
81
87
  ".cs": cLike,
82
88
  ".java": cLike,
83
89
  ".go": cLike,
90
+ ".groovy": cLike,
91
+ ".gradle": cLike,
92
+ ".sol": cLike,
84
93
  ".dart": cLike,
85
94
  ".php": php,
86
95
  ".proto": cLike,
@@ -106,12 +115,16 @@ var BY_EXT = {
106
115
  ".ex": hash,
107
116
  ".exs": hash,
108
117
  ".tcl": hash,
118
+ ".cr": hash,
119
+ ".gd": hash,
120
+ ".awk": hash,
109
121
  ".graphql": hash,
110
122
  ".gql": hash,
111
123
  // hash line comments plus a block pair of their own
112
124
  ".jl": julia,
113
125
  ".nim": nim,
114
126
  ".coffee": coffee,
127
+ ".cmake": cmake,
115
128
  ".ps1": powershell,
116
129
  ".psm1": powershell,
117
130
  ".tf": hcl,
@@ -150,6 +163,8 @@ var BY_EXT = {
150
163
  ".sql": sql,
151
164
  ".lua": lua,
152
165
  ".hs": haskell,
166
+ ".elm": haskell,
167
+ ".purs": haskell,
153
168
  ".css": css,
154
169
  ".xml": xml,
155
170
  ".svg": xml,
@@ -229,7 +244,7 @@ async function collectFiles(dirs) {
229
244
  // src/ids.mjs
230
245
  var SEGMENT_SRC = "[A-Za-z][A-Za-z0-9_.-]*";
231
246
  var REV_SRC = String.raw`\d+(?:\.\d+){0,2}`;
232
- var WILDCARD_SRC = String.raw`(?:\d+\.\d+\.x|\d+\.x\.y|x\.y\.z|\d+\.x|x\.y|x)`;
247
+ var WILDCARD_SRC = String.raw`(?:\d+\.){0,2}[x*]`;
233
248
  var REV_REF_SRC = `(?:${WILDCARD_SRC}|${REV_SRC})`;
234
249
  var ID_SRC = String.raw`([A-Za-z]+):(?:((?:${SEGMENT_SRC}\/)*${SEGMENT_SRC})\/)?(${SEGMENT_SRC})#(${REV_SRC})`;
235
250
  var ID_RE = new RegExp(`^${ID_SRC}$`);
@@ -250,25 +265,29 @@ var keyOf = (id) => id.slice(0, id.lastIndexOf("#"));
250
265
  var revOf = (id) => id.slice(id.lastIndexOf("#") + 1);
251
266
  var pathOf = (id) => id.slice(id.indexOf(":") + 1, id.lastIndexOf("#"));
252
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))}`;
253
274
  function compareRev(a, b) {
254
- const partsA = a.split(".");
255
- const partsB = b.split(".");
256
- for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) {
257
- if (i >= partsA.length) return -1;
258
- if (i >= partsB.length) return 1;
259
- 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]);
260
279
  }
261
280
  return 0;
262
281
  }
263
- var WILDCARD_LAYERS = /* @__PURE__ */ new Set(["x", "y", "z"]);
264
- var isWildcardRev = (rev) => /[xyz]/.test(rev);
282
+ var isWildcardLayer = (layer) => layer === "x" || layer === "*";
283
+ var isWildcardRev = (rev) => /[x*]/.test(rev);
265
284
  function revMatches(pattern, concrete) {
266
- const patternParts = pattern.split(".");
267
- const concreteParts = concrete.split(".");
268
- if (patternParts.length !== concreteParts.length) return false;
269
- for (let i = 0; i < patternParts.length; i++) {
270
- if (WILDCARD_LAYERS.has(patternParts[i])) continue;
271
- if (patternParts[i] !== concreteParts[i]) return false;
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;
272
291
  }
273
292
  return true;
274
293
  }
@@ -288,6 +307,8 @@ function newItem(id, origin, file, line, character) {
288
307
  id,
289
308
  key: keyOf(id),
290
309
  revision: revOf(id),
310
+ canonicalId: canonicalId(id),
311
+ // the SemVer-equal identity every exact-ID lookup keys on
291
312
  origin,
292
313
  // 'spec' | 'code'
293
314
  file,
@@ -720,7 +741,7 @@ function commentText(line, state, grammar) {
720
741
  }
721
742
  function attachNeed(m, file, line, character, state, problems) {
722
743
  const source = m[1] ? makeId(m[1], m[2], m[3], m[4]) : null;
723
- const anchor = source ? state.byId.get(source) : state.lastItem;
744
+ const anchor = source ? state.byId.get(canonicalId(source)) : state.lastItem;
724
745
  if (!anchor) {
725
746
  const written = m[5] + (m[6] ? `:${m[6]}` : "") + (m[7] ? `#${m[7]}` : "");
726
747
  problems.push({
@@ -739,7 +760,7 @@ function collectTags(comment, file, line, state, items, problems) {
739
760
  if (m[8]) {
740
761
  const item = newItem(makeId(m[8], m[9], m[10], m[11]), "code", file, line, character);
741
762
  state.lastItem = item;
742
- state.byId.set(item.id, item);
763
+ state.byId.set(item.canonicalId, item);
743
764
  items.push(item);
744
765
  } else {
745
766
  attachNeed(m, file, line, character, state, problems);
@@ -810,9 +831,9 @@ var duplicateForwarding = (from, count) => ({
810
831
 
811
832
  // src/analyze.mjs
812
833
  function checkItemReferences(item, byId, matchesOf, isNeeded, withRevisions, forwardTargets) {
813
- const forwardTarget = forwardTargets.get(item.id);
834
+ const forwardTarget = forwardTargets.get(item.canonicalId);
814
835
  if (forwardTarget !== void 0) {
815
- if (!byId.has(forwardTarget))
836
+ if (!byId.has(canonicalId(forwardTarget)))
816
837
  item.defects.push(withRevisions(uncoveredForward(forwardTarget)));
817
838
  } else {
818
839
  for (const need of item.needs) {
@@ -821,17 +842,18 @@ function checkItemReferences(item, byId, matchesOf, isNeeded, withRevisions, for
821
842
  }
822
843
  }
823
844
  for (const coverId of item.covers) {
824
- const targets = byId.get(coverId);
845
+ const targets = byId.get(canonicalId(coverId));
825
846
  if (!targets) {
826
847
  item.defects.push(withRevisions(orphanedCover(coverId)));
827
848
  } else if (!targets.some((target) => target.needs.some((need) => idMatches(need, item.id)))) {
828
849
  item.defects.push(unwantedCover(coverId, item.id));
829
850
  }
830
851
  }
831
- if (item.origin === "code" && !isNeeded(item.id)) {
852
+ if (item.origin === "code" && !isNeeded(item.canonicalId)) {
832
853
  item.defects.push(unwantedItem(item.id));
833
854
  }
834
855
  }
856
+ var displayedDuplicateId = (writtenIds, canonical) => writtenIds.every((id) => id === writtenIds[0]) ? writtenIds[0] : canonical;
835
857
  function dropCyclicForwards(forwardTargets, declarationBySource, problems) {
836
858
  const done = /* @__PURE__ */ new Set();
837
859
  for (const start of forwardTargets.keys()) {
@@ -842,11 +864,11 @@ function dropCyclicForwards(forwardTargets, declarationBySource, problems) {
842
864
  while (forwardTargets.has(current) && !done.has(current) && !seen.has(current)) {
843
865
  seen.set(current, path6.length);
844
866
  path6.push(current);
845
- current = forwardTargets.get(current);
867
+ current = canonicalId(forwardTargets.get(current));
846
868
  }
847
869
  if (seen.has(current)) {
848
870
  const cycle = path6.slice(seen.get(current));
849
- const chain = [...cycle, current].join(" --> ");
871
+ const chain = [...cycle, current].map((id) => declarationBySource.get(id).from).join(" --> ");
850
872
  for (const id of cycle) {
851
873
  const declaration = declarationBySource.get(id);
852
874
  declaration.effective = false;
@@ -868,7 +890,8 @@ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
868
890
  const declarationBySource = /* @__PURE__ */ new Map();
869
891
  const forwardsBySource = /* @__PURE__ */ new Map();
870
892
  for (const forward of forwards) {
871
- (forwardsBySource.get(forward.from) ?? forwardsBySource.set(forward.from, []).get(forward.from)).push(forward);
893
+ const from = canonicalId(forward.from);
894
+ (forwardsBySource.get(from) ?? forwardsBySource.set(from, []).get(from)).push(forward);
872
895
  }
873
896
  for (const [from, group] of forwardsBySource) {
874
897
  const sources = byId.get(from);
@@ -880,13 +903,15 @@ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
880
903
  file: forward.file,
881
904
  line: forward.line,
882
905
  character: forward.character,
883
- message: `forwarding from ${from}, which does not exist${revHint(from)}`
906
+ message: `forwarding from ${forward.from}, which does not exist${revHint(forward.from)}`
884
907
  });
885
908
  }
886
909
  continue;
887
910
  }
888
- if (group.length > 1)
889
- for (const item of sources) item.defects.push(duplicateForwarding(from, group.length));
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
+ }
890
915
  group[0].effective = true;
891
916
  for (let i = 1; i < group.length; i++) {
892
917
  group[i].effective = false;
@@ -896,7 +921,7 @@ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
896
921
  declarationBySource.set(from, group[0]);
897
922
  }
898
923
  dropCyclicForwards(forwardTargets, declarationBySource, problems);
899
- for (const to of forwardTargets.values()) neededIds.add(to);
924
+ for (const to of forwardTargets.values()) neededIds.add(canonicalId(to));
900
925
  return forwardTargets;
901
926
  }
902
927
  function markDeepCoverage(items, byId, matchesOf, forwardTargets) {
@@ -912,7 +937,7 @@ function markDeepCoverage(items, byId, matchesOf, forwardTargets) {
912
937
  const forwardTarget = forwardTargets.get(id);
913
938
  let ok = true;
914
939
  if (forwardTarget !== void 0) {
915
- ok = deep(forwardTarget);
940
+ ok = deep(canonicalId(forwardTarget));
916
941
  } else {
917
942
  for (const item of group) for (const need of item.needs) if (!needDeep(need)) ok = false;
918
943
  }
@@ -920,7 +945,7 @@ function markDeepCoverage(items, byId, matchesOf, forwardTargets) {
920
945
  return ok;
921
946
  };
922
947
  const needDeep = (need) => matchesOf(need).some((id) => deep(id));
923
- for (const item of items) item.deepCovered = deep(item.id);
948
+ for (const item of items) item.deepCovered = deep(item.canonicalId);
924
949
  }
925
950
  function groupIdsByKey(byId) {
926
951
  const idsByKey = /* @__PURE__ */ new Map();
@@ -939,7 +964,9 @@ function buildWantedBy(items, byId, matchesOf) {
939
964
  }
940
965
  function buildResolver(items) {
941
966
  const byId = /* @__PURE__ */ new Map();
942
- for (const item of items) (byId.get(item.id) ?? byId.set(item.id, []).get(item.id)).push(item);
967
+ for (const item of items) {
968
+ (byId.get(item.canonicalId) ?? byId.set(item.canonicalId, []).get(item.canonicalId)).push(item);
969
+ }
943
970
  const idsByKey = groupIdsByKey(byId);
944
971
  const matchesOf = (ref) => (idsByKey.get(keyOf(ref)) ?? []).filter((id) => idMatches(ref, id));
945
972
  return { byId, matchesOf, wantedBy: buildWantedBy(items, byId, matchesOf) };
@@ -971,7 +998,7 @@ function splitNeeds(items) {
971
998
  for (const item of items)
972
999
  for (const need of item.needs) {
973
1000
  if (isWildcardRev(revOf(need))) wildcard.push(need);
974
- else exact.add(need);
1001
+ else exact.add(canonicalId(need));
975
1002
  }
976
1003
  return { exact, wildcard };
977
1004
  }
@@ -981,9 +1008,12 @@ function analyze(items, forwards = [], problems = []) {
981
1008
  for (const item of items)
982
1009
  (revsByKey.get(item.key) ?? revsByKey.set(item.key, /* @__PURE__ */ new Set()).get(item.key)).add(item.revision);
983
1010
  const { exact: exactNeeds, wildcard: wildcardNeeds } = splitNeeds(items);
984
- const isNeeded = (id) => exactNeeds.has(id) || wildcardNeeds.some((wildcard) => idMatches(wildcard, id));
1011
+ const isNeeded = (canonical) => exactNeeds.has(canonical) || wildcardNeeds.some((wildcard) => idMatches(wildcard, canonical));
985
1012
  for (const [id, group] of byId) {
986
- if (group.length > 1) for (const item of group) item.defects.push(duplicateId(id, group.length));
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
+ }
987
1017
  }
988
1018
  const existingRevisionsOf = (id) => {
989
1019
  const revs = revsByKey.get(keyOf(id));
@@ -1005,7 +1035,7 @@ function analyze(items, forwards = [], problems = []) {
1005
1035
  };
1006
1036
  const forwardTargets = buildForwardMap(forwards, byId, exactNeeds, revHint, problems);
1007
1037
  for (const item of items) {
1008
- item.forwardsTo = forwardTargets.get(item.id) ?? null;
1038
+ item.forwardsTo = forwardTargets.get(item.canonicalId) ?? null;
1009
1039
  checkItemReferences(item, byId, matchesOf, isNeeded, withRevisions, forwardTargets);
1010
1040
  }
1011
1041
  markDeepCoverage(items, byId, matchesOf, forwardTargets);
@@ -1041,7 +1071,7 @@ function byFileLine(a, b) {
1041
1071
  return a.line - b.line;
1042
1072
  }
1043
1073
  function forwardEdge(item, byId, style, dimLocation) {
1044
- const target = byId.get(item.forwardsTo)?.[0];
1074
+ const target = byId.get(canonicalId(item.forwardsTo))?.[0];
1045
1075
  if (!target) return ` ${style.cyan("\u2192")} ${item.forwardsTo} ${style.red("\u2718 missing")}`;
1046
1076
  return ` ${style.cyan("\u2192")} ${item.forwardsTo} ${styledStatus(target, style).mark} ${dimLocation(target.file, target.line)}`;
1047
1077
  }
@@ -1056,8 +1086,8 @@ function needEdges(item, byId, matchesOf, style, dimLocation) {
1056
1086
  const wildcard = isWildcardRev(revOf(need));
1057
1087
  for (const id of ids) {
1058
1088
  const covering = byId.get(id)[0];
1059
- const arrow = style.dim(`(\u2192 ${id})`);
1060
- const ref = wildcard ? `${need} ${arrow}` : need;
1089
+ const arrow = style.dim(`(\u2192 ${covering.id})`);
1090
+ const ref = wildcard || covering.id !== need ? `${need} ${arrow}` : need;
1061
1091
  lines.push(` ${style.dim("needs")} ${ref} ${styledStatus(covering, style).mark} ${dimLocation(covering.file, covering.line)}`);
1062
1092
  }
1063
1093
  }
@@ -1066,7 +1096,7 @@ function needEdges(item, byId, matchesOf, style, dimLocation) {
1066
1096
  function coverEdges(item, byId, style, dimLocation) {
1067
1097
  const lines = [];
1068
1098
  for (const coverId of item.covers) {
1069
- const target = byId.get(coverId)?.[0];
1099
+ const target = byId.get(canonicalId(coverId))?.[0];
1070
1100
  if (!target) lines.push(` ${style.dim("covers")} ${coverId} ${style.red("\u2718 missing")}`);
1071
1101
  else lines.push(` ${style.dim("covers")} ${coverId} ${style.green("\u2714")} ${dimLocation(target.file, target.line)}`);
1072
1102
  }
@@ -1157,7 +1187,7 @@ function buildForwardedFrom(items, byId) {
1157
1187
  const forwardedFrom = /* @__PURE__ */ new Map();
1158
1188
  for (const item of items) {
1159
1189
  if (item.forwardsTo === null) continue;
1160
- for (const target of byId.get(item.forwardsTo) ?? [])
1190
+ for (const target of byId.get(canonicalId(item.forwardsTo)) ?? [])
1161
1191
  (forwardedFrom.get(target) ?? forwardedFrom.set(target, []).get(target)).push(item);
1162
1192
  }
1163
1193
  return forwardedFrom;
@@ -1181,7 +1211,11 @@ function buildReportDocument(items, forwards, problems, cwd, opts = {}) {
1181
1211
  };
1182
1212
  const { byId, matchesOf, wantedBy } = buildResolver(items);
1183
1213
  const forwardedFrom = buildForwardedFrom(items, byId);
1184
- const resolvedTo = (ref) => matchesOf(ref).sort((a, b) => compareRev(revOf(a), revOf(b)));
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
+ ];
1185
1219
  const itemRefs = (related) => [...related].map((other) => ({ id: other.id, ...location(other) })).sort(byLocation);
1186
1220
  const itemDocument = (item) => {
1187
1221
  const coverStatus = coverStatusOf(item);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flashtrace",
3
- "version": "0.11.4",
3
+ "version": "0.12.0",
4
4
  "description": "Lightning-fast, reference-based requirement tracing that works anywhere.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {