Skip to content

Commit 2cb9e2a

Browse files
bnoordhuisBridgeAR
authored andcommitted
build,tools: check freshness of doc addons
Add a `--check` flag to `tools/doc/addon-verify.js` and use that in the `make test` target to determine if the generated files in `test/addons` are fresh or stale. PR-URL: #17407 Reviewed-By: Richard Lau <[email protected]>
1 parent d9b59de commit 2cb9e2a

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ v8:
225225

226226
.PHONY: test
227227
# This does not run tests of third-party libraries inside deps.
228-
test: all build-addons ## Runs default tests, linters, and builds docs.
228+
test: all check-doc-addons build-addons ## Runs default tests, linters, and builds docs.
229229
$(MAKE) -s doc-only
230230
$(MAKE) -s lint
231231
$(MAKE) -s cctest
@@ -234,6 +234,10 @@ test: all build-addons ## Runs default tests, linters, and builds docs.
234234
$(CI_NATIVE_SUITES) \
235235
$(CI_DOC)
236236

237+
.PHONY: check-doc-addons
238+
check-doc-addons: $(NODE)
239+
$(NODE) tools/doc/addon-verify.js --check
240+
237241
.PHONY: test-only
238242
test-only: all build-addons ## For a quick test, does not run linter or build docs.
239243
$(MAKE) cctest

tools/doc/addon-verify.js

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ const rootDir = path.resolve(__dirname, '..', '..');
1010
const doc = path.resolve(rootDir, 'doc', 'api', 'addons.md');
1111
const verifyDir = path.resolve(rootDir, 'test', 'addons');
1212

13+
const changed = [];
14+
const checkOnly = process.argv.includes('--check');
15+
1316
let id = 0;
1417
let currentHeader;
1518

@@ -76,12 +79,6 @@ for (const header in addons) {
7679
})
7780
});
7881

79-
try {
80-
fs.mkdirSync(dir);
81-
} catch (e) {
82-
strictEqual(e.code, 'EEXIST');
83-
}
84-
8582
for (const file of files) {
8683
let content;
8784
try {
@@ -91,13 +88,29 @@ for (const header in addons) {
9188
}
9289

9390
// Only update when file content has changed to prevent unneeded rebuilds.
94-
if (content !== file.content) {
95-
fs.writeFileSync(file.path, file.content);
96-
console.log('wrote', file.path);
91+
if (content === file.content) continue;
92+
changed.push(file);
93+
94+
if (checkOnly) continue;
95+
96+
try {
97+
fs.mkdirSync(dir);
98+
} catch (e) {
99+
strictEqual(e.code, 'EEXIST');
97100
}
101+
102+
fs.writeFileSync(file.path, file.content);
103+
console.log('wrote', file.path);
98104
}
99105
}
100106

107+
if (checkOnly && changed.length > 0) {
108+
console.error('The following files are out of date:');
109+
for (const { path } of changed) console.error(' ', path);
110+
console.error('Run `node tools/doc/addon-verify.js` to update.');
111+
process.exit(1);
112+
}
113+
101114
function boilerplate(name, content) {
102115
return `'use strict';
103116
const common = require('../../common');

0 commit comments

Comments
 (0)