Skip to content

Commit eb3d3d9

Browse files
joyeecheungaduh95
andauthored
fixup! build: make test-addons dependency-free
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 9d62d0b commit eb3d3d9

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

tools/doc/addon-verify.mjs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,40 @@ if (!values.input || !values.output) {
3030
process.exit(1);
3131
}
3232

33-
const src = readFileSync(values.input, 'utf8');
33+
const src = await open(values.input, 'r');
34+
35+
const MARKER_RE = /^<!--\s*addon-verify-file\s+(\S+?)\/(\S+)\s*-->$/;
3436

35-
// Collect files grouped by section directory name.
36-
const MARKER_RE = /^<!--\s*addon-verify-file\s+(\S+?)\/(\S+)\s*-->$/gm;
37-
const FENCE_RE = /```\w*\n([\s\S]*?)\n```/;
3837
const entries = [];
39-
for (const match of src.matchAll(MARKER_RE)) {
40-
const [, dir, name] = match;
41-
const after = src.slice(match.index + match[0].length);
42-
const content = after.match(FENCE_RE)?.[1];
43-
if (content != null) entries.push({ dir, name, content });
38+
let nextBlockIsAddonVerifyFile = false;
39+
let expectedClosingFenceMarker;
40+
for await (const line of src.readLines()) {
41+
if (expectedClosingFenceMarker) {
42+
// We're inside a Addon snippet
43+
if (line === expectedClosingFenceMarker) {
44+
// End of the snippet
45+
expectedClosingFenceMarker = null;
46+
continue;
47+
}
48+
49+
entries.at(-1).content += `${line}\n`;
50+
}
51+
if (nextBlockIsAddonVerifyFile) {
52+
if (line) {
53+
expectedClosingFenceMarker = line.replace(/\w/g, '');
54+
nextBlockIsAddonVerifyFile = false;
55+
}
56+
continue;
57+
}
58+
const match = MARKER_RE.exec(line);
59+
if (match) {
60+
nextBlockIsAddonVerifyFile = true;
61+
const [, dir, name] = match;
62+
entries.push({ dir, name, content: '' });
63+
}
4464
}
65+
66+
// Collect files grouped by section directory name.
4567
const sections = Map.groupBy(entries, (e) => e.dir);
4668

4769
let idx = 0;

0 commit comments

Comments
 (0)