singularity-forge/scripts/bump-version.mjs
Jeremy eec05b68a8 fix(release): sync all workspace versions and harden release scripts
Two bugs were causing version drift across the repo:

1. Root package.json was silently reverted from 2.74.0 → 2.73.1 during
   commit b03c9401c (a CI optimization rebase). Tag v2.74.0 is already
   published on npm, so the next release would have computed 2.73.2 —
   lower than what's already out — and shipped a broken version.

2. scripts/bump-version.mjs only touches pi-coding-agent + pkg + native
   platform shims. Other workspace packages drift independently:
   - @gsd-build/mcp-server: stuck at 2.52.0 (22 minor versions behind)
   - @gsd-build/rpc-client: stuck at 2.52.0
   - @gsd/pi-ai, pi-tui, pi-agent-core: stuck at 0.57.1
   - @gsd/native, @gsd-build/daemon: stuck at 0.1.0

Changes:

- Bump all non-private workspace packages to 2.74.0 to match the latest
  release tag. Update daemon + mcp-server's internal rpc-client dep
  from ^2.52.0 → ^2.74.0. Regenerate root lockfile.

- scripts/generate-changelog.mjs: compute newVersion from max(latest
  stable tag, package.json) instead of package.json alone. Prevents
  version regressions when package.json is accidentally clobbered by
  rebases or merges.

- scripts/bump-version.mjs: extend to sync all eight non-private
  workspace packages (daemon, mcp-server, native, pi-agent-core, pi-ai,
  pi-coding-agent, pi-tui, rpc-client) including their internal deps
  on each other. Private packages (studio, web) are left alone.

Studio and web remain on their own versioning (private: true, never
published). The native platform shims under native/npm/* are still
synced via native/scripts/sync-platform-versions.cjs from the root
version as before.
2026-04-14 19:35:28 -05:00

77 lines
3 KiB
JavaScript

#!/usr/bin/env node
/**
* Bump version in package.json, then sync platform packages and pkg/package.json.
* Usage: node scripts/bump-version.mjs <new-version>
*/
import { readFileSync, writeFileSync, existsSync } from "fs";
import { resolve, dirname } from "path";
import { execSync } from "child_process";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const root = resolve(__dirname, "..");
const newVersion = process.argv[2];
if (!newVersion || !/^\d+\.\d+\.\d+$/.test(newVersion)) {
console.error("Usage: node scripts/bump-version.mjs <X.Y.Z>");
process.exit(1);
}
// 1. Update root package.json
const pkgPath = resolve(root, "package.json");
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
const oldVersion = pkg.version;
pkg.version = newVersion;
writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n");
console.log(`[bump-version] package.json: ${oldVersion}${newVersion}`);
// 2. Update all non-private workspace packages under packages/
// These share the root version to keep the repo's source of truth coherent
// with what ships. Private packages (studio, web) are skipped — they're not
// published and have their own lifecycle.
const workspacePackages = [
"daemon",
"mcp-server",
"native",
"pi-agent-core",
"pi-ai",
"pi-coding-agent",
"pi-tui",
"rpc-client",
];
for (const name of workspacePackages) {
const wsPath = resolve(root, "packages", name, "package.json");
if (!existsSync(wsPath)) continue;
const ws = JSON.parse(readFileSync(wsPath, "utf-8"));
const wsOld = ws.version;
ws.version = newVersion;
// Bump any internal @gsd-build/* or @gsd/* dep references to match.
for (const field of ["dependencies", "devDependencies", "peerDependencies"]) {
if (!ws[field]) continue;
for (const dep of Object.keys(ws[field])) {
if (workspacePackages.some((n) => dep === `@gsd-build/${n}` || dep === `@gsd/${n}`)) {
ws[field][dep] = `^${newVersion}`;
}
}
}
writeFileSync(wsPath, JSON.stringify(ws, null, 2) + "\n");
console.log(`[bump-version] ${name}: ${wsOld}${newVersion}`);
}
// 3. Sync platform package versions (reads from root package.json)
execSync("node native/scripts/sync-platform-versions.cjs", { cwd: root, stdio: "inherit" });
// 4. Sync pkg/package.json (reads from pi-coding-agent)
execSync("node scripts/sync-pkg-version.cjs", { cwd: root, stdio: "inherit" });
// 5. Regenerate root package-lock.json to match the new version.
// --package-lock-only updates the lockfile in-place without touching node_modules.
execSync("npm install --package-lock-only --ignore-scripts", { cwd: root, stdio: "inherit" });
console.log(`[bump-version] package-lock.json regenerated at ${newVersion}`);
// 6. Regenerate web/package-lock.json if the web app is present.
const webDir = resolve(root, "web");
if (existsSync(webDir)) {
execSync("npm install --package-lock-only --ignore-scripts", { cwd: webDir, stdio: "inherit" });
console.log(`[bump-version] web/package-lock.json regenerated`);
}