Skip to content

Commit cd859c7

Browse files
committed
Add README version check script and npm hook
Introduce scripts/check-readme-version.mjs to verify the "Current version/status" entry in README.md's Repository Snapshot table matches package.json (or a package file set via README_VERSION_PKG_PATH). Add an npm script check:version-sync and run it as part of the composite "check" task so version parity is enforced during prepublish/check flows. The script errors on mismatch and prints an OK message when versions match.
1 parent 02bc88f commit cd859c7

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
"format": "prettier --write \"**/*.{ts,tsx,js,jsx,json,css,md}\"",
4040
"format:md": "prettier --write \"**/*.md\"",
4141
"check:ecosystem": "spectre-manifest-validate spectre.manifest.json && spectre-manifest-check spectre.manifest.json .",
42-
"check": "npm run typecheck && npm run lint && npm run build && npm test -- --run && npm run check:ecosystem",
42+
"check:version-sync": "node scripts/check-readme-version.mjs",
43+
"check": "npm run typecheck && npm run lint && npm run build && npm test -- --run && npm run check:version-sync && npm run check:ecosystem",
4344
"prepublishOnly": "npm run check"
4445
},
4546
"funding": [

scripts/check-readme-version.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { readFileSync } from 'node:fs';
2+
import { resolve } from 'node:path';
3+
4+
const repoRoot = resolve(import.meta.dirname, '..');
5+
6+
const pkgPath = process.env.README_VERSION_PKG_PATH ?? 'package.json';
7+
const pkg = JSON.parse(readFileSync(resolve(repoRoot, pkgPath), 'utf-8'));
8+
const readme = readFileSync(resolve(repoRoot, 'README.md'), 'utf-8');
9+
10+
const match = readme.match(/\|\s*Current version\/status\s*\|\s*([^\s|]+)\s*\|/i);
11+
12+
if (!match) {
13+
throw new Error(
14+
'README.md is missing the "Current version/status" row in the Repository Snapshot table.',
15+
);
16+
}
17+
18+
const readmeVersion = match[1];
19+
20+
if (readmeVersion !== pkg.version) {
21+
throw new Error(
22+
`README.md "Current version/status" is "${readmeVersion}" but ${pkgPath} version is "${pkg.version}". Update README.md to match.`,
23+
);
24+
}
25+
26+
console.log(`README version parity: OK (${pkg.version})`);

0 commit comments

Comments
 (0)