consortium
Version:
Remote control and session sharing CLI for AI coding agents
56 lines (48 loc) • 2.16 kB
JavaScript
/**
* Publish-hygiene guard: fail if the version the BUILT CLI reports
* (`dist` → currentCliVersion) does not equal package.json's version.
*
* Root-cause context: the daemon decides it's "outdated" by comparing the
* version compiled into dist against package.json on disk. If a package is
* ever published with package.json bumped but dist NOT rebuilt (a version
* skew), every install of it triggers a futile self-restart. This check makes
* that skew a hard build/publish failure instead of a shipped bug.
*
* Runs as part of `prepublishOnly` (after `build`) and is safe to run in CI.
*/
const { execFileSync } = require('child_process');
const fs = require('fs');
const path = require('path');
const pkgPath = path.join(__dirname, '..', 'package.json');
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
const expected = pkg.version;
const distEntry = path.join(__dirname, '..', 'dist', 'index.mjs');
if (!fs.existsSync(distEntry)) {
console.error(`[check-dist-version] dist not built at ${distEntry} — run \`yarn build\` first.`);
process.exit(1);
}
let out = '';
try {
out = execFileSync(process.execPath, [distEntry, '--version'], {
encoding: 'utf8',
timeout: 30_000,
// Keep it headless + offline so --version is a pure print.
env: { ...process.env, CONSORTIUM_SKIP_TUI: '1', CONSORTIUM_SKIP_PREFLIGHT: '1' },
});
} catch (err) {
console.error('[check-dist-version] failed to run the built CLI --version:', err.message);
process.exit(1);
}
// `--version` prints e.g. "v0.8.8" or "0.8.8"; extract the semver.
const m = out.match(/\d+\.\d+\.\d+[^\s]*/);
const reported = m ? m[0] : out.trim();
if (reported !== expected) {
console.error(
`[check-dist-version] VERSION SKEW: package.json is v${expected} but the built dist reports v${reported}.\n` +
` The dist was not rebuilt against the current package.json. Run \`yarn build\` and re-publish.\n` +
` Publishing this skew would put every install into a futile daemon self-restart loop.`
);
process.exit(1);
}
console.log(`[check-dist-version] ok — built dist and package.json agree on v${expected}`);