You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
897 B
JavaScript
23 lines
897 B
JavaScript
// Keeps `jsr.json`'s version in step with `package.json`.
|
|
//
|
|
// Wired into the `version` npm lifecycle script, so `npm version <bump>`
|
|
// updates both files and stages `jsr.json` into the same commit/tag. Also
|
|
// runs from `prepublishOnly` as a guard, and can be run by hand
|
|
// (`npm run sync-version`). Exits non-zero only on a real filesystem error;
|
|
// a no-op when the versions already match.
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
|
|
const pkgUrl = new URL('../package.json', import.meta.url);
|
|
const jsrUrl = new URL('../jsr.json', import.meta.url);
|
|
|
|
const pkg = JSON.parse(readFileSync(pkgUrl, 'utf8'));
|
|
const jsr = JSON.parse(readFileSync(jsrUrl, 'utf8'));
|
|
|
|
if (jsr.version === pkg.version) {
|
|
process.exit(0);
|
|
}
|
|
|
|
jsr.version = pkg.version;
|
|
writeFileSync(jsrUrl, `${JSON.stringify(jsr, null, 2)}\n`);
|
|
console.log(`sync-version: jsr.json ${jsr.version} (from package.json)`);
|