Skip to content

fix: sync packageManager and devEngines.packageManager on self-update#11395

Merged
zkochan merged 3 commits into
mainfrom
fix/11388
Apr 29, 2026
Merged

fix: sync packageManager and devEngines.packageManager on self-update#11395
zkochan merged 3 commits into
mainfrom
fix/11388

Conversation

@zkochan

@zkochan zkochan commented Apr 29, 2026

Copy link
Copy Markdown
Member

Summary

  • When package.json declares both packageManager and devEngines.packageManager, pnpm self-update previously bumped only the latter — leaving Corepack (which reads packageManager) pinned to the old version until a manual edit.
  • Now, when packageManager pins pnpm, both fields are rewritten to the new exact version on update: packageManager to pnpm@<version> (without an integrity hash) and devEngines.packageManager.version to the same exact <version> (dropping any range operator).
  • When only devEngines.packageManager is declared, the existing range-preserving behavior is unchanged. When packageManager pins something other than pnpm (e.g. yarn), it is left alone.

Closes #11388

Test plan

  • New test: both fields with same exact version → both bumped.
  • New test: legacy field with +sha512… integrity hash → both bumped, hash dropped.
  • New test: both fields disagree → both forced to new exact version.
  • New test: legacy exact + devEngines range → both forced to new exact version.
  • New test: legacy pins yarn + devEngines pnpm range → yarn untouched, range preserved.
  • All 32 tests in selfUpdate.test.ts pass.

zkochan added 3 commits April 29, 2026 21:47
When `package.json` declares both `packageManager` and
`devEngines.packageManager`, `pnpm self-update` previously bumped only
the latter — leaving Corepack (which reads `packageManager`) pinned to
the old version until a manual edit.

Now, when `packageManager` pins pnpm, both fields are rewritten to the
new exact version on update: `packageManager` to `pnpm@<version>`
(without an integrity hash) and `devEngines.packageManager.version` to
the same exact `<version>` (dropping any range operator). When only
`devEngines.packageManager` is declared, the existing range-preserving
behavior is unchanged.

Closes #11388
Drop the inline duplicate in self-updater and use the existing
parser from config.reader. Same parsing rules (strips integrity
hash, rejects URL-style refs).
Resolve to the underlying pnpm entry first (whether the field is an
array or an object) and run the version-update logic once, instead of
duplicating it across both branches.
@zkochan zkochan marked this pull request as ready for review April 29, 2026 20:25
@zkochan zkochan added this to the v11.0 milestone Apr 29, 2026
@zkochan zkochan merged commit 490a97e into main Apr 29, 2026
12 checks passed
@zkochan zkochan deleted the fix/11388 branch April 29, 2026 20:56
zkochan added a commit that referenced this pull request Apr 29, 2026
…#11395)

* fix: sync packageManager and devEngines.packageManager on self-update

When `package.json` declares both `packageManager` and
`devEngines.packageManager`, `pnpm self-update` previously bumped only
the latter — leaving Corepack (which reads `packageManager`) pinned to
the old version until a manual edit.

Now, when `packageManager` pins pnpm, both fields are rewritten to the
new exact version on update: `packageManager` to `pnpm@<version>`
(without an integrity hash) and `devEngines.packageManager.version` to
the same exact `<version>` (dropping any range operator). When only
`devEngines.packageManager` is declared, the existing range-preserving
behavior is unchanged.

Closes #11388

* refactor: export and reuse parsePackageManager from @pnpm/config.reader

Drop the inline duplicate in self-updater and use the existing
parser from config.reader. Same parsing rules (strips integrity
hash, rejects URL-style refs).

* refactor: collapse devEngines.packageManager array/object branches

Resolve to the underlying pnpm entry first (whether the field is an
array or an object) and run the version-update logic once, instead of
duplicating it across both branches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid package manager specification in package.json (pnpm@^11.0.0); expected a semver version

1 participant