import { execa } from 'execa'; import fs from 'fs/promises'; import glob from 'glob'; import path from 'path'; async function run() { const { stdout: branchName } = await execa('git', ['rev-parse', '--abbrev-ref', 'HEAD']); console.log('Current branch:', branchName); // read the current version from ./version.txt const nextVersion = (await fs.readFile('./version.txt', 'utf-8')).trim(); const packages = ['extensions/*', 'platform/*', 'modes/*']; // Track only the files this script writes, so the release commit stages // exactly the version bump and never sweeps in unrelated local edits or // generated artifacts via `git add -A`. const updatedFiles = []; // For each package's package.json file, update: // 1. The package version // 2. Any @ohif/* peerDependencies to the next version // 3. Any @ohif/* dependencies to the next version for (const packagePathPattern of packages) { const matchingDirectories = glob.sync(packagePathPattern); for (const packageDirectory of matchingDirectories) { const packageJsonPath = path.join(packageDirectory, 'package.json'); try { const packageJson = JSON.parse(await fs.readFile(packageJsonPath, 'utf-8')); // Bump only the package's own version. Internal @ohif/* references stay // as workspace:* in the committed manifests (and therefore the lockfile, // which records them as links), so pnpm-lock.yaml never drifts on a // version bump and frozen installs keep working. pnpm publish rewrites // workspace:* to the exact version in the published tarball only. packageJson.version = nextVersion; await fs.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n'); updatedFiles.push(packageJsonPath); console.log(`Updated ${packageJsonPath}`); } catch (err) { console.log("ERROR: Couldn't find package.json in", packageDirectory); continue; } } } // Update root package.json version const rootPackageJson = JSON.parse(await fs.readFile('package.json', 'utf-8')); rootPackageJson.version = nextVersion; await fs.writeFile('package.json', JSON.stringify(rootPackageJson, null, 2) + '\n'); updatedFiles.push('package.json'); console.log('Updated root package.json'); // NOTE: Do not delete .npmrc here. It is tracked and holds pnpm workspace // config (node-linker, workspace linking) with no npm credentials, so // removing it would commit the loss of needed install config. This script // does not publish, so there is no accidental-publish risk to guard against. console.log('Setting the version...'); // Stage only the package.json files this script updated, so the release // commit is deterministic and doesn't pick up unrelated worktree changes. await execa('git', ['add', '--', ...updatedFiles]); // Create the version commit const commitMessage = `chore(version): Update package versions to ${nextVersion} [skip ci]`; await execa('git', ['commit', '-m', commitMessage]); // Create the version tag const tagName = `v${nextVersion}`; await execa('git', ['tag', '-f', tagName]); console.log('Pushing changes...'); await execa('git', ['push', 'origin', branchName]); console.log('Pushing tag...'); await execa('git', ['push', 'origin', tagName]); console.log('Version set successfully'); } run().catch(err => { console.error('Error encountered during version bump:', err); process.exit(1); });