* Bumps the version of all workspace packages and their internal dependencies. * This replicates the behavior of: * lerna version --force-publish --exact --no-git-tag-version --no-push --include-merged-tags --yes * * Specifically: * - Updates `version` in every workspace package.
(rootDir, newVersion)
| 47 | * - No git tags, commits, or pushes are made |
| 48 | */ |
| 49 | function bumpVersions(rootDir, newVersion) { |
| 50 | const rootPkgPath = path.join(rootDir, 'package.json'); |
| 51 | const rootPkg = JSON.parse(fs.readFileSync(rootPkgPath, 'utf-8')); |
| 52 | const workspaces = rootPkg.workspaces; |
| 53 | |
| 54 | if (!workspaces || !Array.isArray(workspaces)) { |
| 55 | throw new Error('Could not find workspaces in root package.json'); |
| 56 | } |
| 57 | |
| 58 | // Read all workspace package.json files upfront. |
| 59 | // This ensures we fail early if any workspace is unreadable, |
| 60 | // before writing any changes (no partial updates). |
| 61 | const workspaceNames = new Set(); |
| 62 | const workspacePkgPaths = []; |
| 63 | for (const workspace of workspaces) { |
| 64 | const pkgPath = path.join(rootDir, workspace, 'package.json'); |
| 65 | const pkg = readJson(pkgPath); |
| 66 | workspaceNames.add(pkg.name); |
| 67 | workspacePkgPaths.push(pkgPath); |
| 68 | } |
| 69 | |
| 70 | // Apply version bumps |
| 71 | for (const pkgPath of workspacePkgPaths) { |
| 72 | updateWorkspaceDeps(pkgPath, workspaceNames, newVersion, { bumpVersion: true }); |
| 73 | } |
| 74 | |
| 75 | // Update bundler-plugin integration test fixtures. |
| 76 | // These are standalone pnpm projects (not workspaces) that reference local tarballs |
| 77 | // with version-stamped filenames, so they need explicit patching. |
| 78 | const fixturesDir = path.join(rootDir, 'dev-packages', 'bundler-plugin-integration-tests', 'fixtures'); |
| 79 | |
| 80 | if (fs.existsSync(fixturesDir)) { |
| 81 | for (const entry of fs.readdirSync(fixturesDir, { withFileTypes: true })) { |
| 82 | if (!entry.isDirectory()) continue; |
| 83 | |
| 84 | const fixturePkgPath = path.join(fixturesDir, entry.name, 'package.json'); |
| 85 | |
| 86 | if (!fs.existsSync(fixturePkgPath)) continue; |
| 87 | |
| 88 | updateWorkspaceDeps(fixturePkgPath, workspaceNames, newVersion); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return workspacePkgPaths.length; |
| 93 | } |
| 94 | |
| 95 | // CLI entry point |
| 96 | if (require.main === module) { |
no test coverage detected