Skip to content

Commit 78175b9

Browse files
committed
Add README version parity check
Introduce scripts/check-readme-version.mjs to verify the README's "Current version/status" entry matches package.json. Add a new npm script check:version-sync and wire it into the overall check pipeline so CI/prepublish fails if the README and package version drift. The script supports overriding the package path via README_VERSION_PKG_PATH and prints a success message when versions match.
1 parent c029478 commit 78175b9

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
@@ -55,7 +55,8 @@
5555
"lint": "eslint src tests",
5656
"test": "vitest run",
5757
"check:ecosystem": "spectre-manifest-validate spectre.manifest.json && spectre-manifest-check spectre.manifest.json .",
58-
"check": "npm run typecheck && npm run lint && npm run build && npm run test && npm run check:ecosystem",
58+
"check:version-sync": "node scripts/check-readme-version.mjs",
59+
"check": "npm run typecheck && npm run lint && npm run build && npm run test && npm run check:version-sync && npm run check:ecosystem",
5960
"prepublishOnly": "npm run check"
6061
},
6162
"devDependencies": {

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)