flashtrace 0.1.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/LICENSE +201 -0
- package/README.md +53 -0
- package/dist/flashtrace.mjs +422 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/flashtrace">
|
|
3
|
+
<img src="https://github.com/flashtrace.png" alt="flashtrace logo" width="120">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<h3 align="center">flashtrace</h3>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
Lightning-fast, reference-based requirement tracing that works anywhere.
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://github.com/flashtrace/flashtrace/blob/main/docs/index.md">
|
|
15
|
+
<img src="https://img.shields.io/badge/Spec-Driven-8e4d13.svg?labelColor=1e1e1e" alt="Spec-driven documentation." />
|
|
16
|
+
</a>
|
|
17
|
+
<a href="https://github.com/flashtrace/flashtrace/blob/main/CLAUDE.md">
|
|
18
|
+
<img src="https://img.shields.io/badge/Agent-Native-d97d0e.svg?labelColor=1e1e1e" alt="This repository was created agent-native." />
|
|
19
|
+
</a>
|
|
20
|
+
<a href="https://github.com/flashtrace/flashtrace/blob/main/LICENSE">
|
|
21
|
+
<img src="https://img.shields.io/badge/License-Apache_2.0-f9c21d.svg?labelColor=1e1e1e" alt="Released under the Apache 2.0 license." />
|
|
22
|
+
</a>
|
|
23
|
+
</p>
|
|
24
|
+
|
|
25
|
+
## Getting Started
|
|
26
|
+
|
|
27
|
+
To use flashtrace in your project,
|
|
28
|
+
|
|
29
|
+
- either download `dist/flashtrace.mjs` into your own repository and run `node flashtrace.mjs`
|
|
30
|
+
- or run `npm install flashtrace -D` to add it as a proper dev dependency to your project.
|
|
31
|
+
|
|
32
|
+
You can then execute `npx flashtrace` to run the tracing.
|
|
33
|
+
Read our [Usage Guide](docs/USAGE.md) for more details.
|
|
34
|
+
Node >= 18 is required for flashtrace to work.
|
|
35
|
+
|
|
36
|
+
## About flashtrace
|
|
37
|
+
|
|
38
|
+
Let's be honest: This project started when I needed it myself.
|
|
39
|
+
So on the good side, this thing works.
|
|
40
|
+
On the bad side, it might not yet fit your case perfectly.
|
|
41
|
+
But we are open to adapt and we are actively working on widening our coverage area.
|
|
42
|
+
Tell us about your use case - we are happy to have a look and will try to make flashtrace available to anyone!
|
|
43
|
+
|
|
44
|
+
## Community
|
|
45
|
+
|
|
46
|
+
We are available for any questions, ideas and problems.
|
|
47
|
+
Just search or start a thread in our [GitHub Discussions](https://github.com/flashtrace/flashtrace/discussions).
|
|
48
|
+
|
|
49
|
+
If you want to contribute to this repository, read our [Contributing Guidelines](CONTRIBUTING.md).
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
Licensed under the [Apache 2.0 License](LICENSE).
|
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/main.mjs
|
|
4
|
+
import process3 from "node:process";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
|
|
7
|
+
// src/cli.mjs
|
|
8
|
+
import { promises as fs2 } from "node:fs";
|
|
9
|
+
import path4 from "node:path";
|
|
10
|
+
import process2 from "node:process";
|
|
11
|
+
|
|
12
|
+
// src/errors.mjs
|
|
13
|
+
var UsageError = class extends Error {
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// src/files.mjs
|
|
17
|
+
import { promises as fs } from "node:fs";
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
import { execFileSync } from "node:child_process";
|
|
20
|
+
var MD_EXT = /* @__PURE__ */ new Set([".md", ".markdown"]);
|
|
21
|
+
var CODE_EXT = /* @__PURE__ */ new Set([".ts", ".js", ".mjs", ".sql", ".vue"]);
|
|
22
|
+
async function walk(dir, out) {
|
|
23
|
+
let entries;
|
|
24
|
+
try {
|
|
25
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
26
|
+
} catch {
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
29
|
+
for (const e of entries) {
|
|
30
|
+
if (e.name === ".git" || e.name === "node_modules") continue;
|
|
31
|
+
const p = path.join(dir, e.name);
|
|
32
|
+
if (e.isDirectory()) await walk(p, out);
|
|
33
|
+
else if (e.isFile()) out.push(p);
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
async function collectFiles(dirs) {
|
|
38
|
+
const files = /* @__PURE__ */ new Set();
|
|
39
|
+
for (const dir of dirs) {
|
|
40
|
+
const abs = path.resolve(dir);
|
|
41
|
+
const st = await fs.stat(abs).catch(() => null);
|
|
42
|
+
if (!st) throw new UsageError(`input path does not exist: ${dir}`);
|
|
43
|
+
if (st.isFile()) {
|
|
44
|
+
files.add(abs);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
let list = null;
|
|
48
|
+
try {
|
|
49
|
+
const out = execFileSync(
|
|
50
|
+
"git",
|
|
51
|
+
["-C", abs, "ls-files", "-z", "--cached", "--others", "--exclude-standard"],
|
|
52
|
+
{ encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }
|
|
53
|
+
);
|
|
54
|
+
list = out.split("\0").filter(Boolean).map((f) => path.join(abs, f));
|
|
55
|
+
} catch {
|
|
56
|
+
list = await walk(abs, []);
|
|
57
|
+
}
|
|
58
|
+
for (const f of list) files.add(f);
|
|
59
|
+
}
|
|
60
|
+
return [...files].filter((f) => {
|
|
61
|
+
const ext = path.extname(f).toLowerCase();
|
|
62
|
+
return MD_EXT.has(ext) || CODE_EXT.has(ext);
|
|
63
|
+
}).sort();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/ids.mjs
|
|
67
|
+
var SEG_SRC = String.raw`[A-Za-z][A-Za-z0-9_.-]*`;
|
|
68
|
+
var ID_SRC = String.raw`([A-Za-z]+):(?:((?:${SEG_SRC}\/)*${SEG_SRC})\/)?(${SEG_SRC})#(\d+)`;
|
|
69
|
+
var ID_RE = new RegExp(`^${ID_SRC}$`);
|
|
70
|
+
var mkId = (type, group, name, rev) => `${type}:${group ? group + "/" : ""}${name}#${rev}`;
|
|
71
|
+
var keyOf = (id) => id.slice(0, id.lastIndexOf("#"));
|
|
72
|
+
var revOf = (id) => Number(id.slice(id.lastIndexOf("#") + 1));
|
|
73
|
+
function parseIdEntry(raw) {
|
|
74
|
+
const cleaned = raw.replace(/`/g, "").trim();
|
|
75
|
+
const m = cleaned.match(ID_RE);
|
|
76
|
+
return m ? mkId(m[1], m[2], m[3], m[4]) : null;
|
|
77
|
+
}
|
|
78
|
+
function newItem(id, origin, file, line) {
|
|
79
|
+
return {
|
|
80
|
+
id,
|
|
81
|
+
key: keyOf(id),
|
|
82
|
+
revision: revOf(id),
|
|
83
|
+
origin,
|
|
84
|
+
// 'markdown' | 'code'
|
|
85
|
+
file,
|
|
86
|
+
line,
|
|
87
|
+
title: null,
|
|
88
|
+
description: [],
|
|
89
|
+
needs: [],
|
|
90
|
+
covers: [],
|
|
91
|
+
tags: [],
|
|
92
|
+
defects: []
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/parse-markdown.mjs
|
|
97
|
+
var DEF_RE = new RegExp(String.raw`^\s*\`${ID_SRC}\`\s*$`);
|
|
98
|
+
var HEADING_RE = /^(#{1,6})\s+(.*\S)\s*$/;
|
|
99
|
+
var KEYWORD_RE = /^(Needs|Covers|Tags):\s*(.*)$/;
|
|
100
|
+
var BULLET_RE = /^\s*[-*+]\s+(.*\S)\s*$/;
|
|
101
|
+
function titleAbove(lines, defIndex) {
|
|
102
|
+
for (let k = defIndex - 1; k >= 0; k--) {
|
|
103
|
+
const l = lines[k];
|
|
104
|
+
if (l.trim() === "") continue;
|
|
105
|
+
const h = l.match(HEADING_RE);
|
|
106
|
+
return h ? h[2] : null;
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
function parseMarkdown(file, text, problems) {
|
|
111
|
+
const lines = text.split(/\r?\n/);
|
|
112
|
+
const items = [];
|
|
113
|
+
const isBoundary = (l) => DEF_RE.test(l) || HEADING_RE.test(l);
|
|
114
|
+
for (let i = 0; i < lines.length; i++) {
|
|
115
|
+
const def = lines[i].match(DEF_RE);
|
|
116
|
+
if (!def) continue;
|
|
117
|
+
const item = newItem(mkId(def[1], def[2], def[3], def[4]), "markdown", file, i + 1);
|
|
118
|
+
item.title = titleAbove(lines, i);
|
|
119
|
+
let j = i + 1;
|
|
120
|
+
let descDone = false;
|
|
121
|
+
while (j < lines.length && !isBoundary(lines[j])) {
|
|
122
|
+
const line = lines[j];
|
|
123
|
+
const kw = line.match(KEYWORD_RE);
|
|
124
|
+
if (kw) {
|
|
125
|
+
descDone = true;
|
|
126
|
+
const kwLine = j + 1;
|
|
127
|
+
const entries = [];
|
|
128
|
+
if (kw[2].trim() !== "") {
|
|
129
|
+
entries.push(...kw[2].split(",").map((s) => s.trim()).filter(Boolean));
|
|
130
|
+
} else {
|
|
131
|
+
while (j + 1 < lines.length) {
|
|
132
|
+
const b = lines[j + 1].match(BULLET_RE);
|
|
133
|
+
if (!b) break;
|
|
134
|
+
entries.push(b[1].trim());
|
|
135
|
+
j++;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (kw[1] === "Tags") {
|
|
139
|
+
item.tags.push(...entries);
|
|
140
|
+
} else {
|
|
141
|
+
for (const e of entries) {
|
|
142
|
+
const id = parseIdEntry(e);
|
|
143
|
+
if (id) item[kw[1] === "Needs" ? "needs" : "covers"].push(id);
|
|
144
|
+
else
|
|
145
|
+
problems.push({
|
|
146
|
+
file,
|
|
147
|
+
line: kwLine,
|
|
148
|
+
message: `invalid ID "${e}" in ${kw[1]}: list of ${item.id}`
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
} else if (line.trim() === "") {
|
|
153
|
+
if (item.description.length > 0) descDone = true;
|
|
154
|
+
} else if (!descDone) {
|
|
155
|
+
item.description.push(line.trim());
|
|
156
|
+
}
|
|
157
|
+
j++;
|
|
158
|
+
}
|
|
159
|
+
items.push(item);
|
|
160
|
+
i = j - 1;
|
|
161
|
+
}
|
|
162
|
+
return items;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/parse-code.mjs
|
|
166
|
+
import path2 from "node:path";
|
|
167
|
+
var TAG_RE = new RegExp(String.raw`\[(>>)?\s*${ID_SRC}\s*\]`, "g");
|
|
168
|
+
function parseCode(file, text, problems) {
|
|
169
|
+
const ext = path2.extname(file).toLowerCase();
|
|
170
|
+
const lines = text.split(/\r?\n/);
|
|
171
|
+
const items = [];
|
|
172
|
+
let last = null;
|
|
173
|
+
let block = null;
|
|
174
|
+
const lineMarkers = ext === ".sql" ? ["--"] : ["//"];
|
|
175
|
+
const htmlBlocks = ext === ".vue";
|
|
176
|
+
for (let i = 0; i < lines.length; i++) {
|
|
177
|
+
const s = lines[i];
|
|
178
|
+
let comment = "";
|
|
179
|
+
let pos = 0;
|
|
180
|
+
while (pos < s.length) {
|
|
181
|
+
if (block === "c" || block === "html") {
|
|
182
|
+
const closer = block === "c" ? "*/" : "-->";
|
|
183
|
+
const end = s.indexOf(closer, pos);
|
|
184
|
+
if (end === -1) {
|
|
185
|
+
comment += s.slice(pos) + " ";
|
|
186
|
+
pos = s.length;
|
|
187
|
+
} else {
|
|
188
|
+
comment += s.slice(pos, end) + " ";
|
|
189
|
+
pos = end + closer.length;
|
|
190
|
+
block = null;
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
let best = -1;
|
|
194
|
+
let kind = null;
|
|
195
|
+
let len = 0;
|
|
196
|
+
for (const m of lineMarkers) {
|
|
197
|
+
const idx = s.indexOf(m, pos);
|
|
198
|
+
if (idx !== -1 && (best === -1 || idx < best)) {
|
|
199
|
+
best = idx;
|
|
200
|
+
kind = "line";
|
|
201
|
+
len = m.length;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const cb = s.indexOf("/*", pos);
|
|
205
|
+
if (cb !== -1 && (best === -1 || cb < best)) {
|
|
206
|
+
best = cb;
|
|
207
|
+
kind = "c";
|
|
208
|
+
len = 2;
|
|
209
|
+
}
|
|
210
|
+
if (htmlBlocks) {
|
|
211
|
+
const hb = s.indexOf("<!--", pos);
|
|
212
|
+
if (hb !== -1 && (best === -1 || hb < best)) {
|
|
213
|
+
best = hb;
|
|
214
|
+
kind = "html";
|
|
215
|
+
len = 4;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (best === -1) break;
|
|
219
|
+
pos = best + len;
|
|
220
|
+
if (kind === "line") {
|
|
221
|
+
comment += s.slice(pos) + " ";
|
|
222
|
+
pos = s.length;
|
|
223
|
+
} else {
|
|
224
|
+
block = kind;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
for (const m of comment.matchAll(TAG_RE)) {
|
|
229
|
+
const id = mkId(m[2], m[3], m[4], m[5]);
|
|
230
|
+
if (m[1]) {
|
|
231
|
+
if (!last)
|
|
232
|
+
problems.push({
|
|
233
|
+
file,
|
|
234
|
+
line: i + 1,
|
|
235
|
+
message: `need tag [>>${id}] has no preceding item tag in this file`
|
|
236
|
+
});
|
|
237
|
+
else last.needs.push(id);
|
|
238
|
+
} else {
|
|
239
|
+
last = newItem(id, "code", file, i + 1);
|
|
240
|
+
items.push(last);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return items;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/analyze.mjs
|
|
248
|
+
function analyze(items) {
|
|
249
|
+
const byId = /* @__PURE__ */ new Map();
|
|
250
|
+
const revsByKey = /* @__PURE__ */ new Map();
|
|
251
|
+
for (const it of items) {
|
|
252
|
+
(byId.get(it.id) ?? byId.set(it.id, []).get(it.id)).push(it);
|
|
253
|
+
(revsByKey.get(it.key) ?? revsByKey.set(it.key, /* @__PURE__ */ new Set()).get(it.key)).add(it.revision);
|
|
254
|
+
}
|
|
255
|
+
const neededIds = new Set(items.flatMap((it) => it.needs));
|
|
256
|
+
for (const [id, group] of byId) {
|
|
257
|
+
if (group.length > 1)
|
|
258
|
+
for (const it of group) it.defects.push(`duplicate: ID ${id} is defined ${group.length} times`);
|
|
259
|
+
}
|
|
260
|
+
const revHint = (id) => {
|
|
261
|
+
const revs = revsByKey.get(keyOf(id));
|
|
262
|
+
return revs ? ` (revision mismatch: existing revision(s) of ${keyOf(id)}: ${[...revs].sort((a, b) => a - b).join(", ")})` : "";
|
|
263
|
+
};
|
|
264
|
+
for (const it of items) {
|
|
265
|
+
for (const n of it.needs) {
|
|
266
|
+
if (!byId.has(n)) it.defects.push(`uncovered: needs ${n}, which does not exist${revHint(n)}`);
|
|
267
|
+
}
|
|
268
|
+
for (const c of it.covers) {
|
|
269
|
+
const targets = byId.get(c);
|
|
270
|
+
if (!targets) {
|
|
271
|
+
it.defects.push(`orphaned: covers ${c}, which does not exist${revHint(c)}`);
|
|
272
|
+
} else if (!targets.some((t) => t.needs.includes(it.id))) {
|
|
273
|
+
it.defects.push(`unwanted: covers ${c}, but ${c} does not need ${it.id}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (it.origin === "code" && !neededIds.has(it.id)) {
|
|
277
|
+
it.defects.push(`unwanted: no item needs ${it.id}`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
const memo = /* @__PURE__ */ new Map();
|
|
281
|
+
const deep = (id) => {
|
|
282
|
+
if (memo.has(id)) return memo.get(id);
|
|
283
|
+
memo.set(id, true);
|
|
284
|
+
const group = byId.get(id);
|
|
285
|
+
if (!group) {
|
|
286
|
+
memo.set(id, false);
|
|
287
|
+
return false;
|
|
288
|
+
}
|
|
289
|
+
let ok = true;
|
|
290
|
+
for (const it of group) for (const n of it.needs) if (!deep(n)) ok = false;
|
|
291
|
+
memo.set(id, ok);
|
|
292
|
+
return ok;
|
|
293
|
+
};
|
|
294
|
+
for (const it of items) it.deepCovered = deep(it.id);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// src/report.mjs
|
|
298
|
+
import path3 from "node:path";
|
|
299
|
+
import process from "node:process";
|
|
300
|
+
function makeStyler() {
|
|
301
|
+
const on = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
302
|
+
const wrap = (code) => (s) => on ? `\x1B[${code}m${s}\x1B[0m` : s;
|
|
303
|
+
return {
|
|
304
|
+
red: wrap("31"),
|
|
305
|
+
green: wrap("32"),
|
|
306
|
+
yellow: wrap("33"),
|
|
307
|
+
cyan: wrap("36"),
|
|
308
|
+
dim: wrap("2"),
|
|
309
|
+
bold: wrap("1")
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function report(items, problems, cwd) {
|
|
313
|
+
const c = makeStyler();
|
|
314
|
+
const rel = (f) => path3.relative(cwd, f) || f;
|
|
315
|
+
const defective = items.filter((it) => it.defects.length > 0);
|
|
316
|
+
const out = [];
|
|
317
|
+
for (const it of defective) {
|
|
318
|
+
const title = it.title ? ` ${c.dim(`"${it.title}"`)}` : "";
|
|
319
|
+
out.push(
|
|
320
|
+
`${c.red("\u2718")} ${c.bold(it.id)}${title} ${c.dim(`${rel(it.file)}:${it.line}`)}`
|
|
321
|
+
);
|
|
322
|
+
for (const d of it.defects) out.push(` ${c.red("\u2022")} ${d}`);
|
|
323
|
+
out.push("");
|
|
324
|
+
}
|
|
325
|
+
for (const p of problems) {
|
|
326
|
+
out.push(`${c.yellow("\u26A0")} ${p.message} ${c.dim(`${rel(p.file)}:${p.line}`)}`);
|
|
327
|
+
}
|
|
328
|
+
if (problems.length) out.push("");
|
|
329
|
+
const okCount = items.length - defective.length;
|
|
330
|
+
const notDeep = items.filter((it) => it.defects.length === 0 && !it.deepCovered).length;
|
|
331
|
+
const md = items.filter((i) => i.origin === "markdown").length;
|
|
332
|
+
out.push(c.bold("Summary"));
|
|
333
|
+
out.push(` items ${items.length} ${c.dim(`(${md} from markdown, ${items.length - md} from code)`)}`);
|
|
334
|
+
out.push(` ok ${c.green(String(okCount))}`);
|
|
335
|
+
out.push(` defective ${defective.length ? c.red(String(defective.length)) : "0"}`);
|
|
336
|
+
if (notDeep) out.push(` ${c.dim(`of the ok items, ${notDeep} are only shallow-covered (a needed item is itself defective)`)}`);
|
|
337
|
+
if (problems.length) out.push(` problems ${c.yellow(String(problems.length))}`);
|
|
338
|
+
out.push("");
|
|
339
|
+
const clean = defective.length === 0 && problems.length === 0;
|
|
340
|
+
out.push(clean ? c.green(c.bold("ok")) : c.red(c.bold("not ok")));
|
|
341
|
+
console.log(out.join("\n"));
|
|
342
|
+
return clean;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// src/cli.mjs
|
|
346
|
+
var HELP = `Usage: flashtrace [options] [directory-or-file ...]
|
|
347
|
+
|
|
348
|
+
Traces requirement coverage between Markdown specifications and source code
|
|
349
|
+
(.ts, .js, .mjs, .sql, .vue). Defaults to the current directory. Files ignored
|
|
350
|
+
by git are excluded.
|
|
351
|
+
|
|
352
|
+
Options:
|
|
353
|
+
-t, --tags <t1,t2,...> only import markdown items carrying one of these
|
|
354
|
+
tags; add "_" to also include untagged items
|
|
355
|
+
-h, --help show this help
|
|
356
|
+
|
|
357
|
+
Exit codes: 0 clean, 1 defects or problems found, 2 usage error`;
|
|
358
|
+
function parseArgs(argv) {
|
|
359
|
+
const opts = { dirs: [], tags: null };
|
|
360
|
+
for (let i = 0; i < argv.length; i++) {
|
|
361
|
+
const a = argv[i];
|
|
362
|
+
if (a === "-h" || a === "--help") {
|
|
363
|
+
console.log(HELP);
|
|
364
|
+
process2.exit(0);
|
|
365
|
+
} else if (a === "-t" || a === "--tags") {
|
|
366
|
+
const v = argv[++i];
|
|
367
|
+
if (!v) throw new UsageError(`missing value for ${a}`);
|
|
368
|
+
opts.tags = v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
369
|
+
} else if (a.startsWith("-")) {
|
|
370
|
+
throw new UsageError(`unknown option: ${a}`);
|
|
371
|
+
} else {
|
|
372
|
+
opts.dirs.push(a);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (opts.dirs.length === 0) opts.dirs.push(".");
|
|
376
|
+
return opts;
|
|
377
|
+
}
|
|
378
|
+
async function main() {
|
|
379
|
+
const opts = parseArgs(process2.argv.slice(2));
|
|
380
|
+
const files = await collectFiles(opts.dirs);
|
|
381
|
+
const problems = [];
|
|
382
|
+
let items = [];
|
|
383
|
+
for (const file of files) {
|
|
384
|
+
const text = await fs2.readFile(file, "utf8");
|
|
385
|
+
const ext = path4.extname(file).toLowerCase();
|
|
386
|
+
items.push(
|
|
387
|
+
...MD_EXT.has(ext) ? parseMarkdown(file, text, problems) : parseCode(file, text, problems)
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
if (opts.tags) {
|
|
391
|
+
const wantUntagged = opts.tags.includes("_");
|
|
392
|
+
items = items.filter(
|
|
393
|
+
(it) => it.origin === "code" || it.tags.some((t) => opts.tags.includes(t)) || wantUntagged && it.tags.length === 0
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
analyze(items);
|
|
397
|
+
const clean = report(items, problems, process2.cwd());
|
|
398
|
+
process2.exit(clean ? 0 : 1);
|
|
399
|
+
}
|
|
400
|
+
function runCli() {
|
|
401
|
+
main().catch((err) => {
|
|
402
|
+
if (err instanceof UsageError) {
|
|
403
|
+
console.error(`error: ${err.message}
|
|
404
|
+
|
|
405
|
+
${HELP}`);
|
|
406
|
+
process2.exit(2);
|
|
407
|
+
}
|
|
408
|
+
console.error(err);
|
|
409
|
+
process2.exit(2);
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// src/main.mjs
|
|
414
|
+
var runAsCli = process3.argv[1] && import.meta.url === pathToFileURL(process3.argv[1]).href;
|
|
415
|
+
if (runAsCli) runCli();
|
|
416
|
+
export {
|
|
417
|
+
UsageError,
|
|
418
|
+
analyze,
|
|
419
|
+
collectFiles,
|
|
420
|
+
parseCode,
|
|
421
|
+
parseMarkdown
|
|
422
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "flashtrace",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Lightning-fast, reference-based requirement tracing that works anywhere.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/flashtrace/flashtrace.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/flashtrace/flashtrace#readme",
|
|
11
|
+
"bugs": "https://github.com/flashtrace/flashtrace/issues",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"requirements",
|
|
14
|
+
"traceability",
|
|
15
|
+
"tracing",
|
|
16
|
+
"coverage",
|
|
17
|
+
"markdown",
|
|
18
|
+
"cli"
|
|
19
|
+
],
|
|
20
|
+
"type": "module",
|
|
21
|
+
"packageManager": "pnpm@11.10.0",
|
|
22
|
+
"bin": {
|
|
23
|
+
"flashtrace": "./dist/flashtrace.mjs"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist/"
|
|
27
|
+
],
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=18"
|
|
30
|
+
},
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "esbuild src/main.mjs --bundle --format=esm --platform=node --outfile=dist/flashtrace.mjs",
|
|
33
|
+
"prepack": "pnpm run build",
|
|
34
|
+
"pretest": "pnpm run build",
|
|
35
|
+
"test": "node --test"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"esbuild": "^0.28.1"
|
|
39
|
+
}
|
|
40
|
+
}
|