Skip to content

Commit a53665e

Browse files
committed
Add README version parity check
Add scripts/check-readme-version.mjs to validate that the README.md "Current version/status" entry matches package.json version (pkg path can be overridden via README_VERSION_PKG_PATH). Wire it into package.json as "check:version-sync" and include it in the existing "check" script so version parity is enforced during prepublish checks. The script throws a clear error if the table row is missing or out of sync, and prints a success message when versions match.
1 parent e18ff74 commit a53665e

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
@@ -49,7 +49,8 @@
4949
"lint": "eslint .",
5050
"format": "prettier --write .",
5151
"check:ecosystem": "spectre-manifest-validate spectre.manifest.json && spectre-manifest-check spectre.manifest.json .",
52-
"check": "npm run typecheck && npm run lint && npm run build && npm run check:ecosystem",
52+
"check:version-sync": "node scripts/check-readme-version.mjs",
53+
"check": "npm run typecheck && npm run lint && npm run build && npm run check:version-sync && npm run check:ecosystem",
5354
"prepublishOnly": "npm run check"
5455
},
5556
"dependencies": {

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)