pnpm/.github/scripts/bump.mjs
Zoltan Kochan 02a751cbc3
chore: rename the pacquet workspace package to pnpm (#18363)
## Summary

The Rust CLI's npm wrapper was named `pacquet` in the workspace so that
it could not collide with the TypeScript CLI package `pnpm`. The
TypeScript CLI now lives on `release/11`, so the wrapper now uses its
published name, `pnpm`.

### Package and release tooling
- `pnpm/npm/pnpm/package.json` is named `pnpm` and no longer sets
`publishConfig.name`. The `@pnpm/exe` generator no longer strips that
rename.
- The `versioning.fixed` group, the bump script and its tests,
`create-release-pr.yml`, `release.yml` (node-gyp bundle filter, the
GitHub release body path `.changeset/changelogs/pnpm@<version>.md`), and
the install filters in `pacquet-ci.yml`, `pacquet-engine-size.yml` and
the `install-crates` action now use `pnpm`.
- The root pnpmfile's `beforePacking` hook is removed. It stripped
dependencies from any package named `pnpm`, which was the TypeScript CLI
and would now be the Rust wrapper.

### Versioning state
- All 335 pending changesets that targeted `pacquet` now target `pnpm`.
- The ledger's `pacquet@<version>` keys and the parked
`pacquet@<version>.md` changelogs are renamed to `pnpm@<version>`. The
ledger is re-sorted in the order the tool writes it. Consumption is
keyed by each entry's `dir`, so the rename does not change which intents
count as released.
- The parked changelogs of the v11 packages are removed. `release/11`
keeps its own copy. One of them, `pnpm@11.29.0.md`, would otherwise sit
next to the Rust CLI's parked changelogs.

### Not renamed
The Rust project keeps the codename pacquet in crate names, workflow
names, benchmark labels and contributor docs. Only the npm workspace
package changes.

### Coordinated change
pnpm.io reads `.changeset/changelogs/pacquet@<version>.md` at the
release commit to build release pages. pnpm/pnpm.io#997 makes it accept
`pnpm@<version>.md` as well. It must merge before the first release cut
after this PR.

### Verification
- `pnpm change status` gives the same release plan as before the rename:
only the two changesets added since the last release are pending, and
the plan is a patch for `pnpm` and `@pnpm/napi`.
- `pnpm run lint` passes. It covers cspell, meta-updater, `pnpm change
check` (592 intents resolve) and ESLint. Vale passes on the changed
docs.
- `node --test .github/scripts/bump.test.mjs` passes.
- The wrapper tests in `pnpm/npm/pnpm/test` pass (91 tests).
- `--filter "pnpm..."` and `--filter pnpm --filter @pnpm/esm-loader`
select the wrapper, get-pnpm and the loader.

## Checklist

- [ ] Added a changeset (`pnpm changeset`) if this PR changes any
published package. Not needed: the published package name does not
change.
- [x] Updated the documentation if needed.

---
Written by an agent (Claude Code, claude-opus-5-5).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- codesmith:footer -->
---
<a
href="https://dashboardbackend.blacksmith.sh/track/run-proof?expires=1797971524&installation_model_id=426870&pr_number=18363&ref=codesmith_pr_footer&repository=pnpm%2Fpnpm&return_to=https%3A%2F%2Fgithub.com%2Fpnpm%2Fpnpm%2Fpull%2F18363&variant=proof_this_pr&signature=fa51b33caf889e45141fe131e099888c912119c8ed1d3896151a80b9564110fb"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-proof-this-pr-v2-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://pr-comments-assets.blacksmith.sh/codesmith/proof-proof-this-pr-v2-light.svg"><img
alt="Proof this PR"
src="https://pr-comments-assets.blacksmith.sh/codesmith/proof-proof-this-pr-v2-dark-3x.png"
width="121" height="28"></picture></a>
<sup><a
href="https://app.blacksmith.sh/pnpm/codesmith/pnpm/pr/18363?autoLogin=true&ref=codesmith_pr_footer">Open
in [code]smith</a> · Need help on this PR? Tag
<code>@codesmith-bot</code> with what you need.</sup>

<!-- codesmith:autofix:disabled -->
<!-- /codesmith:footer -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 21:48:34 +01:00

105 lines
4.6 KiB
JavaScript

// Applies the pending release plan, then runs the meta-updater to mirror the
// bumped npm wrapper versions into the Rust sources the release builds from.
//
// `--release <product>` (repeatable) restricts the run to a subset of the
// releasable products. With no `--release` flag every pending intent is
// consumed, so a bare `pnpm bump` cuts a full release.
import { execFileSync } from 'node:child_process'
import fs from 'node:fs'
import path from 'node:path'
import process from 'node:process'
import { fileURLToPath, pathToFileURL } from 'node:url'
// The workspace packages each product releases, keyed by the product's
// `--release` token. `pnpm` is the Rust CLI with its versioning.fixed
// `@pnpm/napi` sibling.
export const PRODUCT_PACKAGES = {
pnpm: ['pnpm', '@pnpm/napi'],
pnpr: ['@pnpm/pnpr'],
'get-pnpm': ['get-pnpm'],
}
// The Rust products' npm wrappers are `"private": true` in-repo so that a
// workspace-wide `pnpm publish` never ships them; their generate-packages
// scripts drop the flag when they are really published. `pnpm version -r`
// commits a private project's changelog to its CHANGELOG.md, but release.yml
// reads the parked section in `.changeset/changelogs/`, so
// parkPublishedPrivateChangelogs moves it there.
const PUBLISHED_PRIVATE_PROJECT_DIRS = [
'pnpm/npm/pnpm',
'pnpm/npm/napi',
'pnpr/npm/pnpr',
]
function main () {
const repoRoot = findRepoRoot(path.dirname(fileURLToPath(import.meta.url)))
const filterArgs = releaseFilterArgs(parseSelectedProducts(process.argv.slice(2)))
// The release PR branch is dirty here (refreshed trust roots, synthesized
// changesets), so skip the clean-tree check.
execFileSync('pnpm', ['version', '-r', '--no-git-checks', ...filterArgs], { cwd: repoRoot, stdio: 'inherit' })
parkPublishedPrivateChangelogs(repoRoot, PUBLISHED_PRIVATE_PROJECT_DIRS)
execFileSync('pnpm', ['update-manifests'], { cwd: repoRoot, stdio: 'inherit' })
}
/** The products named by `--release`. Fails closed on any other argument. */
export function parseSelectedProducts (argv) {
const selected = new Set()
// `pnpm run bump -- --release ...` forwards the `--` separator to the script.
const start = argv[0] === '--' ? 1 : 0
for (let argIndex = start; argIndex < argv.length; argIndex++) {
if (argv[argIndex] !== '--release') {
throw new Error(`Unexpected bump argument: ${String(argv[argIndex])}. Only "--release <product>" is supported.`)
}
const product = argv[++argIndex]
if (!Object.hasOwn(PRODUCT_PACKAGES, product ?? '')) {
throw new Error(`Unknown --release product: ${String(product)}. Expected one of ${Object.keys(PRODUCT_PACKAGES).join(', ')}.`)
}
selected.add(product)
}
return selected
}
/** `--filter` arguments for `pnpm version -r`. An empty selection releases everything. */
export function releaseFilterArgs (selected) {
return [...selected].flatMap((product) => PRODUCT_PACKAGES[product]).map((pkg) => `--filter=${pkg}`)
}
/**
* Moves the CHANGELOG.md that `pnpm version -r` wrote for each project in
* `projectDirs` to `.changeset/changelogs/<name>@<version>.md`. A project the
* run did not release has no CHANGELOG.md and is skipped.
*/
export function parkPublishedPrivateChangelogs (repoRoot, projectDirs) {
for (const projectDir of projectDirs) {
const changelogPath = path.join(repoRoot, projectDir, 'CHANGELOG.md')
if (!fs.existsSync(changelogPath)) continue
const manifest = JSON.parse(fs.readFileSync(path.join(repoRoot, projectDir, 'package.json'), 'utf8'))
const changelog = fs.readFileSync(changelogPath, 'utf8')
const versionHeadings = changelog.split('\n').filter((line) => line.startsWith('## '))
const sectionStart = changelog.indexOf(`\n## ${manifest.version}\n`) + 1
if (sectionStart === 0 || versionHeadings.length !== 1) {
throw new Error(`${changelogPath} must hold exactly one section, for ${manifest.name}@${manifest.version}`)
}
const parkedPath = path.join(repoRoot, '.changeset', 'changelogs', `${manifest.name}@${manifest.version}`.replaceAll('/', '!') + '.md')
fs.mkdirSync(path.dirname(parkedPath), { recursive: true })
fs.writeFileSync(parkedPath, changelog.slice(sectionStart))
fs.rmSync(changelogPath)
}
}
export function findRepoRoot (startDir) {
let dir = startDir
while (!fs.existsSync(path.join(dir, '.changeset'))) {
const parent = path.dirname(dir)
if (parent === dir) {
throw new Error(`No .changeset directory found above ${startDir}`)
}
dir = parent
}
return dir
}
if (process.argv[1] && import.meta.url === pathToFileURL(fs.realpathSync(process.argv[1])).href) {
main()
}