flashtrace 0.1.1 → 0.2.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 +275 -158
  2. package/package.json +1 -1
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/main.mjs
4
+ import { realpathSync } from "node:fs";
4
5
  import process4 from "node:process";
5
- import { pathToFileURL } from "node:url";
6
+ import { fileURLToPath, pathToFileURL } from "node:url";
6
7
 
7
8
  // src/cli.mjs
8
9
  import { promises as fs2 } from "node:fs";
@@ -30,6 +31,11 @@ function findGit() {
30
31
  }
31
32
  return gitBin;
32
33
  }
34
+ function compareStrings(a, b) {
35
+ if (a < b) return -1;
36
+ if (a > b) return 1;
37
+ return 0;
38
+ }
33
39
  async function walk(dir, out) {
34
40
  let entries;
35
41
  try {
@@ -73,18 +79,25 @@ async function collectFiles(dirs) {
73
79
  return [...files].filter((f) => {
74
80
  const ext = path.extname(f).toLowerCase();
75
81
  return MD_EXT.has(ext) || CODE_EXT.has(ext);
76
- }).sort();
82
+ }).sort(compareStrings);
77
83
  }
78
84
 
79
85
  // src/ids.mjs
80
- var SEG_SRC = String.raw`[A-Za-z][A-Za-z0-9_.-]*`;
86
+ var SEG_SRC = "[A-Za-z][A-Za-z0-9_.-]*";
81
87
  var ID_SRC = String.raw`([A-Za-z]+):(?:((?:${SEG_SRC}\/)*${SEG_SRC})\/)?(${SEG_SRC})#(\d+)`;
82
88
  var ID_RE = new RegExp(`^${ID_SRC}$`);
89
+ var FORWARD_SRC = String.raw`\[\s*${ID_SRC}\s*-->\s*${ID_SRC}\s*\]`;
83
90
  var mkId = (type, group, name, rev) => `${type}:${group ? group + "/" : ""}${name}#${rev}`;
91
+ var mkForward = (m, base, file, line) => ({
92
+ from: mkId(m[base], m[base + 1], m[base + 2], m[base + 3]),
93
+ to: mkId(m[base + 4], m[base + 5], m[base + 6], m[base + 7]),
94
+ file,
95
+ line
96
+ });
84
97
  var keyOf = (id) => id.slice(0, id.lastIndexOf("#"));
85
98
  var revOf = (id) => Number(id.slice(id.lastIndexOf("#") + 1));
86
99
  function parseIdEntry(raw) {
87
- const cleaned = raw.replace(/`/g, "").trim();
100
+ const cleaned = raw.replaceAll("`", "").trim();
88
101
  const m = cleaned.match(ID_RE);
89
102
  return m ? mkId(m[1], m[2], m[3], m[4]) : null;
90
103
  }
@@ -108,9 +121,16 @@ function newItem(id, origin, file, line) {
108
121
 
109
122
  // src/parse-markdown.mjs
110
123
  var DEF_RE = new RegExp(String.raw`^\s*\`${ID_SRC}\`\s*$`);
111
- var HEADING_RE = /^(#{1,6})\s+(.*\S)\s*$/;
112
- var KEYWORD_RE = /^(Needs|Covers|Tags):\s*(.*)$/;
113
- var BULLET_RE = /^\s*[-*+]\s+(.*\S)\s*$/;
124
+ var HEADING_RE = /^(#{1,6})\s+(\S(?:.*\S)?)\s*$/;
125
+ var KEYWORD_RE = /^(Needs|Covers|Tags):\s*((?:\S.*)?)$/;
126
+ var BULLET_RE = /^\s*[-*+]\s+(\S(?:.*\S)?)\s*$/;
127
+ var FORWARD_LINE_RE = new RegExp(String.raw`^\s*(\`?)${FORWARD_SRC}\1\s*$`);
128
+ var isBoundary = (l) => DEF_RE.test(l) || HEADING_RE.test(l);
129
+ function takeForward(line, file, n, forwards) {
130
+ const f = line.match(FORWARD_LINE_RE);
131
+ if (f) forwards.push(mkForward(f, 2, file, n + 1));
132
+ return !!f;
133
+ }
114
134
  function titleAbove(lines, defIndex) {
115
135
  for (let k = defIndex - 1; k >= 0; k--) {
116
136
  const l = lines[k];
@@ -120,57 +140,78 @@ function titleAbove(lines, defIndex) {
120
140
  }
121
141
  return null;
122
142
  }
123
- function parseMarkdown(file, text, problems) {
143
+ function keywordEntries(lines, j, inline) {
144
+ if (inline.trim() !== "") {
145
+ return { entries: inline.split(",").map((s) => s.trim()).filter(Boolean), j };
146
+ }
147
+ const entries = [];
148
+ while (j + 1 < lines.length) {
149
+ const b = lines[j + 1].match(BULLET_RE);
150
+ if (!b) break;
151
+ entries.push(b[1].trim());
152
+ j++;
153
+ }
154
+ return { entries, j };
155
+ }
156
+ function applyKeyword(item, keyword, entries, file, kwLine, problems) {
157
+ if (keyword === "Tags") {
158
+ item.tags.push(...entries);
159
+ return;
160
+ }
161
+ const target = keyword === "Needs" ? "needs" : "covers";
162
+ for (const e of entries) {
163
+ const id = parseIdEntry(e);
164
+ if (id) item[target].push(id);
165
+ else
166
+ problems.push({
167
+ file,
168
+ line: kwLine,
169
+ message: `invalid ID "${e}" in ${keyword}: list of ${item.id}`
170
+ });
171
+ }
172
+ }
173
+ function parseItemBody(lines, start, item, file, problems, forwards) {
174
+ let j = start;
175
+ let descDone = false;
176
+ while (j < lines.length && !isBoundary(lines[j])) {
177
+ const line = lines[j];
178
+ if (takeForward(line, file, j, forwards)) {
179
+ j++;
180
+ continue;
181
+ }
182
+ const kw = line.match(KEYWORD_RE);
183
+ if (kw) {
184
+ descDone = true;
185
+ const collected = keywordEntries(lines, j, kw[2]);
186
+ applyKeyword(item, kw[1], collected.entries, file, j + 1, problems);
187
+ j = collected.j;
188
+ } else if (line.trim() === "") {
189
+ if (item.description.length > 0) descDone = true;
190
+ } else if (!descDone) {
191
+ item.description.push(line.trim());
192
+ }
193
+ j++;
194
+ }
195
+ return j;
196
+ }
197
+ function parseMarkdown(file, text, problems, forwards = []) {
124
198
  const lines = text.split(/\r?\n/);
125
199
  const items = [];
126
- const isBoundary = (l) => DEF_RE.test(l) || HEADING_RE.test(l);
127
- for (let i = 0; i < lines.length; i++) {
200
+ let i = 0;
201
+ while (i < lines.length) {
202
+ if (takeForward(lines[i], file, i, forwards)) {
203
+ i++;
204
+ continue;
205
+ }
128
206
  const def = lines[i].match(DEF_RE);
129
- if (!def) continue;
207
+ if (!def) {
208
+ i++;
209
+ continue;
210
+ }
130
211
  const item = newItem(mkId(def[1], def[2], def[3], def[4]), "markdown", file, i + 1);
131
212
  item.title = titleAbove(lines, i);
132
- let j = i + 1;
133
- let descDone = false;
134
- while (j < lines.length && !isBoundary(lines[j])) {
135
- const line = lines[j];
136
- const kw = line.match(KEYWORD_RE);
137
- if (kw) {
138
- descDone = true;
139
- const kwLine = j + 1;
140
- const entries = [];
141
- if (kw[2].trim() !== "") {
142
- entries.push(...kw[2].split(",").map((s) => s.trim()).filter(Boolean));
143
- } else {
144
- while (j + 1 < lines.length) {
145
- const b = lines[j + 1].match(BULLET_RE);
146
- if (!b) break;
147
- entries.push(b[1].trim());
148
- j++;
149
- }
150
- }
151
- if (kw[1] === "Tags") {
152
- item.tags.push(...entries);
153
- } else {
154
- for (const e of entries) {
155
- const id = parseIdEntry(e);
156
- if (id) item[kw[1] === "Needs" ? "needs" : "covers"].push(id);
157
- else
158
- problems.push({
159
- file,
160
- line: kwLine,
161
- message: `invalid ID "${e}" in ${kw[1]}: list of ${item.id}`
162
- });
163
- }
164
- }
165
- } else if (line.trim() === "") {
166
- if (item.description.length > 0) descDone = true;
167
- } else if (!descDone) {
168
- item.description.push(line.trim());
169
- }
170
- j++;
171
- }
213
+ i = parseItemBody(lines, i + 1, item, file, problems, forwards);
172
214
  items.push(item);
173
- i = j - 1;
174
215
  }
175
216
  return items;
176
217
  }
@@ -178,118 +219,156 @@ function parseMarkdown(file, text, problems) {
178
219
  // src/parse-code.mjs
179
220
  import path2 from "node:path";
180
221
  var TAG_RE = new RegExp(String.raw`\[(>>)?\s*${ID_SRC}\s*\]`, "g");
181
- function parseCode(file, text, problems) {
222
+ var FORWARD_RE = new RegExp(FORWARD_SRC, "g");
223
+ var BLOCK_CLOSERS = { c: "*/", html: "-->" };
224
+ function findCommentStart(s, pos, lineMarkers, htmlBlocks) {
225
+ const candidates = lineMarkers.map((m) => ({ idx: s.indexOf(m, pos), kind: "line", len: m.length }));
226
+ candidates.push({ idx: s.indexOf("/*", pos), kind: "c", len: 2 });
227
+ if (htmlBlocks) candidates.push({ idx: s.indexOf("<!--", pos), kind: "html", len: 4 });
228
+ let best = null;
229
+ for (const cand of candidates) {
230
+ if (cand.idx !== -1 && (best === null || cand.idx < best.idx)) best = cand;
231
+ }
232
+ return best;
233
+ }
234
+ function readBlockRest(s, pos, closer) {
235
+ const end = s.indexOf(closer, pos);
236
+ if (end === -1) return { text: s.slice(pos) + " ", pos: s.length, closed: false };
237
+ return { text: s.slice(pos, end) + " ", pos: end + closer.length, closed: true };
238
+ }
239
+ function commentText(s, state, lineMarkers, htmlBlocks) {
240
+ let comment = "";
241
+ let pos = 0;
242
+ while (pos < s.length) {
243
+ if (state.block) {
244
+ const rest = readBlockRest(s, pos, BLOCK_CLOSERS[state.block]);
245
+ comment += rest.text;
246
+ pos = rest.pos;
247
+ if (rest.closed) state.block = null;
248
+ } else {
249
+ const start = findCommentStart(s, pos, lineMarkers, htmlBlocks);
250
+ if (!start) break;
251
+ pos = start.idx + start.len;
252
+ if (start.kind === "line") {
253
+ comment += s.slice(pos) + " ";
254
+ pos = s.length;
255
+ } else {
256
+ state.block = start.kind;
257
+ }
258
+ }
259
+ }
260
+ return comment;
261
+ }
262
+ function collectTags(comment, file, line, state, items, problems) {
263
+ for (const m of comment.matchAll(TAG_RE)) {
264
+ const id = mkId(m[2], m[3], m[4], m[5]);
265
+ if (!m[1]) {
266
+ state.last = newItem(id, "code", file, line);
267
+ items.push(state.last);
268
+ } else if (state.last) {
269
+ state.last.needs.push(id);
270
+ } else {
271
+ problems.push({
272
+ file,
273
+ line,
274
+ message: `need tag [>>${id}] has no preceding item tag in this file`
275
+ });
276
+ }
277
+ }
278
+ }
279
+ function parseCode(file, text, problems, forwards = []) {
182
280
  const ext = path2.extname(file).toLowerCase();
183
281
  const lines = text.split(/\r?\n/);
184
282
  const items = [];
185
- let last = null;
186
- let block = null;
187
283
  const lineMarkers = ext === ".sql" ? ["--"] : ["//"];
188
284
  const htmlBlocks = ext === ".vue";
285
+ const state = { last: null, block: null };
189
286
  for (let i = 0; i < lines.length; i++) {
190
- const s = lines[i];
191
- let comment = "";
192
- let pos = 0;
193
- while (pos < s.length) {
194
- if (block === "c" || block === "html") {
195
- const closer = block === "c" ? "*/" : "-->";
196
- const end = s.indexOf(closer, pos);
197
- if (end === -1) {
198
- comment += s.slice(pos) + " ";
199
- pos = s.length;
200
- } else {
201
- comment += s.slice(pos, end) + " ";
202
- pos = end + closer.length;
203
- block = null;
204
- }
205
- } else {
206
- let best = -1;
207
- let kind = null;
208
- let len = 0;
209
- for (const m of lineMarkers) {
210
- const idx = s.indexOf(m, pos);
211
- if (idx !== -1 && (best === -1 || idx < best)) {
212
- best = idx;
213
- kind = "line";
214
- len = m.length;
215
- }
216
- }
217
- const cb = s.indexOf("/*", pos);
218
- if (cb !== -1 && (best === -1 || cb < best)) {
219
- best = cb;
220
- kind = "c";
221
- len = 2;
222
- }
223
- if (htmlBlocks) {
224
- const hb = s.indexOf("<!--", pos);
225
- if (hb !== -1 && (best === -1 || hb < best)) {
226
- best = hb;
227
- kind = "html";
228
- len = 4;
229
- }
230
- }
231
- if (best === -1) break;
232
- pos = best + len;
233
- if (kind === "line") {
234
- comment += s.slice(pos) + " ";
235
- pos = s.length;
236
- } else {
237
- block = kind;
238
- }
239
- }
240
- }
241
- for (const m of comment.matchAll(TAG_RE)) {
242
- const id = mkId(m[2], m[3], m[4], m[5]);
243
- if (m[1]) {
244
- if (!last)
245
- problems.push({
246
- file,
247
- line: i + 1,
248
- message: `need tag [>>${id}] has no preceding item tag in this file`
249
- });
250
- else last.needs.push(id);
251
- } else {
252
- last = newItem(id, "code", file, i + 1);
253
- items.push(last);
254
- }
287
+ const comment = commentText(lines[i], state, lineMarkers, htmlBlocks);
288
+ for (const m of comment.matchAll(FORWARD_RE)) {
289
+ forwards.push(mkForward(m, 1, file, i + 1));
255
290
  }
291
+ collectTags(comment, file, i + 1, state, items, problems);
256
292
  }
257
293
  return items;
258
294
  }
259
295
 
260
296
  // src/analyze.mjs
261
- function analyze(items) {
262
- const byId = /* @__PURE__ */ new Map();
263
- const revsByKey = /* @__PURE__ */ new Map();
264
- for (const it of items) {
265
- (byId.get(it.id) ?? byId.set(it.id, []).get(it.id)).push(it);
266
- (revsByKey.get(it.key) ?? revsByKey.set(it.key, /* @__PURE__ */ new Set()).get(it.key)).add(it.revision);
267
- }
268
- const neededIds = new Set(items.flatMap((it) => it.needs));
269
- for (const [id, group] of byId) {
270
- if (group.length > 1)
271
- for (const it of group) it.defects.push(`duplicate: ID ${id} is defined ${group.length} times`);
272
- }
273
- const revHint = (id) => {
274
- const revs = revsByKey.get(keyOf(id));
275
- return revs ? ` (revision mismatch: existing revision(s) of ${keyOf(id)}: ${[...revs].sort((a, b) => a - b).join(", ")})` : "";
276
- };
277
- for (const it of items) {
297
+ function checkItemReferences(it, byId, neededIds, revHint, fwdTarget) {
298
+ const fwd = fwdTarget.get(it.id);
299
+ if (fwd !== void 0) {
300
+ if (!byId.has(fwd))
301
+ it.defects.push(`uncovered: forwards to ${fwd}, which does not exist${revHint(fwd)}`);
302
+ } else {
278
303
  for (const n of it.needs) {
279
304
  if (!byId.has(n)) it.defects.push(`uncovered: needs ${n}, which does not exist${revHint(n)}`);
280
305
  }
281
- for (const c of it.covers) {
282
- const targets = byId.get(c);
283
- if (!targets) {
284
- it.defects.push(`orphaned: covers ${c}, which does not exist${revHint(c)}`);
285
- } else if (!targets.some((t) => t.needs.includes(it.id))) {
286
- it.defects.push(`unwanted: covers ${c}, but ${c} does not need ${it.id}`);
306
+ }
307
+ for (const c of it.covers) {
308
+ const targets = byId.get(c);
309
+ if (!targets) {
310
+ it.defects.push(`orphaned: covers ${c}, which does not exist${revHint(c)}`);
311
+ } else if (!targets.some((t) => t.needs.includes(it.id))) {
312
+ it.defects.push(`unwanted: covers ${c}, but ${c} does not need ${it.id}`);
313
+ }
314
+ }
315
+ if (it.origin === "code" && !neededIds.has(it.id)) {
316
+ it.defects.push(`unwanted: no item needs ${it.id}`);
317
+ }
318
+ }
319
+ function dropCyclicForwards(fwdTarget, declBySource, problems) {
320
+ const done = /* @__PURE__ */ new Set();
321
+ for (const start of fwdTarget.keys()) {
322
+ if (done.has(start)) continue;
323
+ const seen = /* @__PURE__ */ new Map();
324
+ const path5 = [];
325
+ let cur = start;
326
+ while (fwdTarget.has(cur) && !done.has(cur) && !seen.has(cur)) {
327
+ seen.set(cur, path5.length);
328
+ path5.push(cur);
329
+ cur = fwdTarget.get(cur);
330
+ }
331
+ if (seen.has(cur)) {
332
+ const cycle = path5.slice(seen.get(cur));
333
+ const chain = [...cycle, cur].join(" --> ");
334
+ for (const id of cycle) {
335
+ const f = declBySource.get(id);
336
+ problems.push({ file: f.file, line: f.line, message: `cyclic forwarding: ${chain}` });
337
+ fwdTarget.delete(id);
287
338
  }
288
339
  }
289
- if (it.origin === "code" && !neededIds.has(it.id)) {
290
- it.defects.push(`unwanted: no item needs ${it.id}`);
340
+ for (const id of path5) done.add(id);
341
+ }
342
+ }
343
+ function buildForwardMap(forwards, byId, neededIds, revHint, problems) {
344
+ const fwdTarget = /* @__PURE__ */ new Map();
345
+ const declBySource = /* @__PURE__ */ new Map();
346
+ const fwdBySource = /* @__PURE__ */ new Map();
347
+ for (const f of forwards) {
348
+ (fwdBySource.get(f.from) ?? fwdBySource.set(f.from, []).get(f.from)).push(f);
349
+ }
350
+ for (const [from, group] of fwdBySource) {
351
+ const sources = byId.get(from);
352
+ if (!sources) {
353
+ for (const f of group)
354
+ problems.push({
355
+ file: f.file,
356
+ line: f.line,
357
+ message: `forwarding from ${from}, which does not exist${revHint(from)}`
358
+ });
359
+ continue;
291
360
  }
361
+ if (group.length > 1)
362
+ for (const it of sources)
363
+ it.defects.push(`duplicate: forwarding for ${from} is declared ${group.length} times`);
364
+ fwdTarget.set(from, group[0].to);
365
+ declBySource.set(from, group[0]);
292
366
  }
367
+ dropCyclicForwards(fwdTarget, declBySource, problems);
368
+ for (const to of fwdTarget.values()) neededIds.add(to);
369
+ return fwdTarget;
370
+ }
371
+ function markDeepCoverage(items, byId, fwdTarget) {
293
372
  const memo = /* @__PURE__ */ new Map();
294
373
  const deep = (id) => {
295
374
  if (memo.has(id)) return memo.get(id);
@@ -299,13 +378,38 @@ function analyze(items) {
299
378
  memo.set(id, false);
300
379
  return false;
301
380
  }
381
+ const fwd = fwdTarget.get(id);
302
382
  let ok = true;
303
- for (const it of group) for (const n of it.needs) if (!deep(n)) ok = false;
383
+ if (fwd !== void 0) {
384
+ ok = deep(fwd);
385
+ } else {
386
+ for (const it of group) for (const n of it.needs) if (!deep(n)) ok = false;
387
+ }
304
388
  memo.set(id, ok);
305
389
  return ok;
306
390
  };
307
391
  for (const it of items) it.deepCovered = deep(it.id);
308
392
  }
393
+ function analyze(items, forwards = [], problems = []) {
394
+ const byId = /* @__PURE__ */ new Map();
395
+ const revsByKey = /* @__PURE__ */ new Map();
396
+ for (const it of items) {
397
+ (byId.get(it.id) ?? byId.set(it.id, []).get(it.id)).push(it);
398
+ (revsByKey.get(it.key) ?? revsByKey.set(it.key, /* @__PURE__ */ new Set()).get(it.key)).add(it.revision);
399
+ }
400
+ const neededIds = new Set(items.flatMap((it) => it.needs));
401
+ for (const [id, group] of byId) {
402
+ if (group.length > 1)
403
+ for (const it of group) it.defects.push(`duplicate: ID ${id} is defined ${group.length} times`);
404
+ }
405
+ const revHint = (id) => {
406
+ const revs = revsByKey.get(keyOf(id));
407
+ return revs ? ` (revision mismatch: existing revision(s) of ${keyOf(id)}: ${[...revs].sort((a, b) => a - b).join(", ")})` : "";
408
+ };
409
+ const fwdTarget = buildForwardMap(forwards, byId, neededIds, revHint, problems);
410
+ for (const it of items) checkItemReferences(it, byId, neededIds, revHint, fwdTarget);
411
+ markDeepCoverage(items, byId, fwdTarget);
412
+ }
309
413
 
310
414
  // src/report.mjs
311
415
  import path3 from "node:path";
@@ -325,28 +429,32 @@ function makeStyler() {
325
429
  function report(items, problems, cwd) {
326
430
  const c = makeStyler();
327
431
  const rel = (f) => path3.relative(cwd, f) || f;
432
+ const dimLoc = (file, line) => c.dim(`${rel(file)}:${line}`);
328
433
  const defective = items.filter((it) => it.defects.length > 0);
329
434
  const out = [];
330
435
  for (const it of defective) {
331
- const title = it.title ? ` ${c.dim(`"${it.title}"`)}` : "";
436
+ const title = it.title ? " " + c.dim(`"${it.title}"`) : "";
332
437
  out.push(
333
- `${c.red("\u2718")} ${c.bold(it.id)}${title} ${c.dim(`${rel(it.file)}:${it.line}`)}`
438
+ `${c.red("\u2718")} ${c.bold(it.id)}${title} ${dimLoc(it.file, it.line)}`
334
439
  );
335
440
  for (const d of it.defects) out.push(` ${c.red("\u2022")} ${d}`);
336
441
  out.push("");
337
442
  }
338
443
  for (const p of problems) {
339
- out.push(`${c.yellow("\u26A0")} ${p.message} ${c.dim(`${rel(p.file)}:${p.line}`)}`);
444
+ out.push(`${c.yellow("\u26A0")} ${p.message} ${dimLoc(p.file, p.line)}`);
340
445
  }
341
446
  if (problems.length) out.push("");
342
447
  const okCount = items.length - defective.length;
343
448
  const notDeep = items.filter((it) => it.defects.length === 0 && !it.deepCovered).length;
344
449
  const md = items.filter((i) => i.origin === "markdown").length;
345
- out.push(c.bold("Summary"));
346
- out.push(` items ${items.length} ${c.dim(`(${md} from markdown, ${items.length - md} from code)`)}`);
347
- out.push(` ok ${c.green(String(okCount))}`);
348
- out.push(` defective ${defective.length ? c.red(String(defective.length)) : "0"}`);
349
- if (notDeep) out.push(` ${c.dim(`of the ok items, ${notDeep} are only shallow-covered (a needed item is itself defective)`)}`);
450
+ const originBreakdown = c.dim(`(${md} from markdown, ${items.length - md} from code)`);
451
+ out.push(
452
+ c.bold("Summary"),
453
+ ` items ${items.length} ${originBreakdown}`,
454
+ ` ok ${c.green(String(okCount))}`,
455
+ ` defective ${defective.length ? c.red(String(defective.length)) : "0"}`
456
+ );
457
+ if (notDeep) out.push(" " + c.dim(`of the ok items, ${notDeep} are only shallow-covered (an item further down the tracing chain is defective)`));
350
458
  if (problems.length) out.push(` problems ${c.yellow(String(problems.length))}`);
351
459
  out.push("");
352
460
  const clean = defective.length === 0 && problems.length === 0;
@@ -392,12 +500,13 @@ async function main() {
392
500
  const opts = parseArgs(process3.argv.slice(2));
393
501
  const files = await collectFiles(opts.dirs);
394
502
  const problems = [];
503
+ const forwards = [];
395
504
  let items = [];
396
505
  for (const file of files) {
397
506
  const text = await fs2.readFile(file, "utf8");
398
507
  const ext = path4.extname(file).toLowerCase();
399
508
  items.push(
400
- ...MD_EXT.has(ext) ? parseMarkdown(file, text, problems) : parseCode(file, text, problems)
509
+ ...MD_EXT.has(ext) ? parseMarkdown(file, text, problems, forwards) : parseCode(file, text, problems, forwards)
401
510
  );
402
511
  }
403
512
  if (opts.tags) {
@@ -406,7 +515,7 @@ async function main() {
406
515
  (it) => it.origin === "code" || it.tags.some((t) => opts.tags.includes(t)) || wantUntagged && it.tags.length === 0
407
516
  );
408
517
  }
409
- analyze(items);
518
+ analyze(items, forwards, problems);
410
519
  const clean = report(items, problems, process3.cwd());
411
520
  process3.exit(clean ? 0 : 1);
412
521
  }
@@ -424,8 +533,16 @@ ${HELP}`);
424
533
  }
425
534
 
426
535
  // src/main.mjs
427
- var runAsCli = process4.argv[1] && import.meta.url === pathToFileURL(process4.argv[1]).href;
428
- if (runAsCli) runCli();
536
+ function runAsCli() {
537
+ const argvPath = process4.argv[1];
538
+ if (!argvPath) return false;
539
+ try {
540
+ return realpathSync(argvPath) === realpathSync(fileURLToPath(import.meta.url));
541
+ } catch {
542
+ return import.meta.url === pathToFileURL(argvPath).href;
543
+ }
544
+ }
545
+ if (runAsCli()) runCli();
429
546
  export {
430
547
  UsageError,
431
548
  analyze,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flashtrace",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Lightning-fast, reference-based requirement tracing that works anywhere.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {