flashtrace 0.3.0 → 0.4.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 +70 -15
- package/package.json +1 -1
package/dist/flashtrace.mjs
CHANGED
|
@@ -84,8 +84,13 @@ async function collectFiles(dirs) {
|
|
|
84
84
|
|
|
85
85
|
// src/ids.mjs
|
|
86
86
|
var SEG_SRC = "[A-Za-z][A-Za-z0-9_.-]*";
|
|
87
|
-
var
|
|
87
|
+
var REV_SRC = String.raw`\d+(?:\.\d+){0,2}`;
|
|
88
|
+
var WILD_SRC = String.raw`(?:\d+\.\d+\.x|\d+\.x\.y|x\.y\.z|\d+\.x|x\.y|x)`;
|
|
89
|
+
var REVREF_SRC = `(?:${WILD_SRC}|${REV_SRC})`;
|
|
90
|
+
var ID_SRC = String.raw`([A-Za-z]+):(?:((?:${SEG_SRC}\/)*${SEG_SRC})\/)?(${SEG_SRC})#(${REV_SRC})`;
|
|
88
91
|
var ID_RE = new RegExp(`^${ID_SRC}$`);
|
|
92
|
+
var NEED_ID_SRC = String.raw`([A-Za-z]+):(?:((?:${SEG_SRC}\/)*${SEG_SRC})\/)?(${SEG_SRC})#(${REVREF_SRC})`;
|
|
93
|
+
var NEED_ID_RE = new RegExp(`^${NEED_ID_SRC}$`);
|
|
89
94
|
var FORWARD_SRC = String.raw`\[\s*${ID_SRC}\s*-->\s*${ID_SRC}\s*\]`;
|
|
90
95
|
var mkId = (type, group, name, rev) => `${type}:${group ? group + "/" : ""}${name}#${rev}`;
|
|
91
96
|
var mkForward = (m, base, file, line) => ({
|
|
@@ -95,12 +100,40 @@ var mkForward = (m, base, file, line) => ({
|
|
|
95
100
|
line
|
|
96
101
|
});
|
|
97
102
|
var keyOf = (id) => id.slice(0, id.lastIndexOf("#"));
|
|
98
|
-
var revOf = (id) =>
|
|
103
|
+
var revOf = (id) => id.slice(id.lastIndexOf("#") + 1);
|
|
104
|
+
function compareRev(a, b) {
|
|
105
|
+
const pa = a.split(".");
|
|
106
|
+
const pb = b.split(".");
|
|
107
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
108
|
+
if (i >= pa.length) return -1;
|
|
109
|
+
if (i >= pb.length) return 1;
|
|
110
|
+
if (pa[i] !== pb[i]) return Number(pa[i]) - Number(pb[i]);
|
|
111
|
+
}
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
var WILD_LAYER = /* @__PURE__ */ new Set(["x", "y", "z"]);
|
|
115
|
+
var isWildcardRev = (rev) => /[xyz]/.test(rev);
|
|
116
|
+
function revMatches(pattern, concrete) {
|
|
117
|
+
const pp = pattern.split(".");
|
|
118
|
+
const cp = concrete.split(".");
|
|
119
|
+
if (pp.length !== cp.length) return false;
|
|
120
|
+
for (let i = 0; i < pp.length; i++) {
|
|
121
|
+
if (WILD_LAYER.has(pp[i])) continue;
|
|
122
|
+
if (pp[i] !== cp[i]) return false;
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
var idMatches = (need, id) => keyOf(need) === keyOf(id) && revMatches(revOf(need), revOf(id));
|
|
99
127
|
function parseIdEntry(raw) {
|
|
100
128
|
const cleaned = raw.replaceAll("`", "").trim();
|
|
101
129
|
const m = cleaned.match(ID_RE);
|
|
102
130
|
return m ? mkId(m[1], m[2], m[3], m[4]) : null;
|
|
103
131
|
}
|
|
132
|
+
function parseNeedEntry(raw) {
|
|
133
|
+
const cleaned = raw.replaceAll("`", "").trim();
|
|
134
|
+
const m = cleaned.match(NEED_ID_RE);
|
|
135
|
+
return m ? mkId(m[1], m[2], m[3], m[4]) : null;
|
|
136
|
+
}
|
|
104
137
|
function newItem(id, origin, file, line) {
|
|
105
138
|
return {
|
|
106
139
|
id,
|
|
@@ -159,8 +192,9 @@ function applyKeyword(item, keyword, entries, file, kwLine, problems) {
|
|
|
159
192
|
return;
|
|
160
193
|
}
|
|
161
194
|
const target = keyword === "Needs" ? "needs" : "covers";
|
|
195
|
+
const parse = keyword === "Needs" ? parseNeedEntry : parseIdEntry;
|
|
162
196
|
for (const e of entries) {
|
|
163
|
-
const id =
|
|
197
|
+
const id = parse(e);
|
|
164
198
|
if (id) item[target].push(id);
|
|
165
199
|
else
|
|
166
200
|
problems.push({
|
|
@@ -219,7 +253,7 @@ function parseMarkdown(file, text, problems, forwards = []) {
|
|
|
219
253
|
// src/parse-code.mjs
|
|
220
254
|
import path2 from "node:path";
|
|
221
255
|
var TAG_RE = new RegExp(
|
|
222
|
-
String.raw`\[(?:\s*${ID_SRC}\s*)?>>\s*${
|
|
256
|
+
String.raw`\[(?:\s*${ID_SRC}\s*)?>>\s*${NEED_ID_SRC}\s*\]|\[\s*${ID_SRC}\s*\]`,
|
|
223
257
|
"g"
|
|
224
258
|
);
|
|
225
259
|
var FORWARD_RE = new RegExp(FORWARD_SRC, "g");
|
|
@@ -313,25 +347,26 @@ function parseCode(file, text, problems, forwards = []) {
|
|
|
313
347
|
}
|
|
314
348
|
|
|
315
349
|
// src/analyze.mjs
|
|
316
|
-
function checkItemReferences(it, byId,
|
|
350
|
+
function checkItemReferences(it, byId, matchesOf, isNeeded, revHint, fwdTarget) {
|
|
317
351
|
const fwd = fwdTarget.get(it.id);
|
|
318
352
|
if (fwd !== void 0) {
|
|
319
353
|
if (!byId.has(fwd))
|
|
320
354
|
it.defects.push(`uncovered: forwards to ${fwd}, which does not exist${revHint(fwd)}`);
|
|
321
355
|
} else {
|
|
322
356
|
for (const n of it.needs) {
|
|
323
|
-
if (
|
|
357
|
+
if (matchesOf(n).length === 0)
|
|
358
|
+
it.defects.push(`uncovered: needs ${n}, which does not exist${revHint(n)}`);
|
|
324
359
|
}
|
|
325
360
|
}
|
|
326
361
|
for (const c of it.covers) {
|
|
327
362
|
const targets = byId.get(c);
|
|
328
363
|
if (!targets) {
|
|
329
364
|
it.defects.push(`orphaned: covers ${c}, which does not exist${revHint(c)}`);
|
|
330
|
-
} else if (!targets.some((t) => t.needs.
|
|
365
|
+
} else if (!targets.some((t) => t.needs.some((n) => idMatches(n, it.id)))) {
|
|
331
366
|
it.defects.push(`unwanted: covers ${c}, but ${c} does not need ${it.id}`);
|
|
332
367
|
}
|
|
333
368
|
}
|
|
334
|
-
if (it.origin === "code" && !
|
|
369
|
+
if (it.origin === "code" && !isNeeded(it.id)) {
|
|
335
370
|
it.defects.push(`unwanted: no item needs ${it.id}`);
|
|
336
371
|
}
|
|
337
372
|
}
|
|
@@ -387,7 +422,7 @@ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
|
|
|
387
422
|
for (const to of fwdTarget.values()) neededIds.add(to);
|
|
388
423
|
return fwdTarget;
|
|
389
424
|
}
|
|
390
|
-
function markDeepCoverage(items, byId, fwdTarget) {
|
|
425
|
+
function markDeepCoverage(items, byId, matchesOf, fwdTarget) {
|
|
391
426
|
const memo = /* @__PURE__ */ new Map();
|
|
392
427
|
const deep = (id) => {
|
|
393
428
|
if (memo.has(id)) return memo.get(id);
|
|
@@ -402,13 +437,30 @@ function markDeepCoverage(items, byId, fwdTarget) {
|
|
|
402
437
|
if (fwd !== void 0) {
|
|
403
438
|
ok = deep(fwd);
|
|
404
439
|
} else {
|
|
405
|
-
for (const it of group) for (const n of it.needs) if (!
|
|
440
|
+
for (const it of group) for (const n of it.needs) if (!needDeep(n)) ok = false;
|
|
406
441
|
}
|
|
407
442
|
memo.set(id, ok);
|
|
408
443
|
return ok;
|
|
409
444
|
};
|
|
445
|
+
const needDeep = (n) => matchesOf(n).some((id) => deep(id));
|
|
410
446
|
for (const it of items) it.deepCovered = deep(it.id);
|
|
411
447
|
}
|
|
448
|
+
function groupIdsByKey(byId) {
|
|
449
|
+
const idsByKey = /* @__PURE__ */ new Map();
|
|
450
|
+
for (const id of byId.keys())
|
|
451
|
+
(idsByKey.get(keyOf(id)) ?? idsByKey.set(keyOf(id), []).get(keyOf(id))).push(id);
|
|
452
|
+
return idsByKey;
|
|
453
|
+
}
|
|
454
|
+
function splitNeeds(items) {
|
|
455
|
+
const exact = /* @__PURE__ */ new Set();
|
|
456
|
+
const wildcard = [];
|
|
457
|
+
for (const it of items)
|
|
458
|
+
for (const n of it.needs) {
|
|
459
|
+
if (isWildcardRev(revOf(n))) wildcard.push(n);
|
|
460
|
+
else exact.add(n);
|
|
461
|
+
}
|
|
462
|
+
return { exact, wildcard };
|
|
463
|
+
}
|
|
412
464
|
function analyze(items, forwards = [], problems = []) {
|
|
413
465
|
const byId = /* @__PURE__ */ new Map();
|
|
414
466
|
const revsByKey = /* @__PURE__ */ new Map();
|
|
@@ -416,18 +468,21 @@ function analyze(items, forwards = [], problems = []) {
|
|
|
416
468
|
(byId.get(it.id) ?? byId.set(it.id, []).get(it.id)).push(it);
|
|
417
469
|
(revsByKey.get(it.key) ?? revsByKey.set(it.key, /* @__PURE__ */ new Set()).get(it.key)).add(it.revision);
|
|
418
470
|
}
|
|
419
|
-
const
|
|
471
|
+
const idsByKey = groupIdsByKey(byId);
|
|
472
|
+
const matchesOf = (ref) => (idsByKey.get(keyOf(ref)) ?? []).filter((id) => idMatches(ref, id));
|
|
473
|
+
const { exact: exactNeeds, wildcard: wildcardNeeds } = splitNeeds(items);
|
|
474
|
+
const isNeeded = (id) => exactNeeds.has(id) || wildcardNeeds.some((w) => idMatches(w, id));
|
|
420
475
|
for (const [id, group] of byId) {
|
|
421
476
|
if (group.length > 1)
|
|
422
477
|
for (const it of group) it.defects.push(`duplicate: ID ${id} is defined ${group.length} times`);
|
|
423
478
|
}
|
|
424
479
|
const revHint = (id) => {
|
|
425
480
|
const revs = revsByKey.get(keyOf(id));
|
|
426
|
-
return revs ? ` (revision mismatch: existing revision(s) of ${keyOf(id)}: ${[...revs].sort(
|
|
481
|
+
return revs ? ` (revision mismatch: existing revision(s) of ${keyOf(id)}: ${[...revs].sort(compareRev).join(", ")})` : "";
|
|
427
482
|
};
|
|
428
|
-
const fwdTarget = buildForwardMap(forwards, byId,
|
|
429
|
-
for (const it of items) checkItemReferences(it, byId,
|
|
430
|
-
markDeepCoverage(items, byId, fwdTarget);
|
|
483
|
+
const fwdTarget = buildForwardMap(forwards, byId, exactNeeds, revHint, problems);
|
|
484
|
+
for (const it of items) checkItemReferences(it, byId, matchesOf, isNeeded, revHint, fwdTarget);
|
|
485
|
+
markDeepCoverage(items, byId, matchesOf, fwdTarget);
|
|
431
486
|
}
|
|
432
487
|
|
|
433
488
|
// src/report.mjs
|