Conversation
The package-manager handling block in main.ts was guarded by `!isExecutedByCorepack()`, which skipped the entire block — including syncEnvLockfile and checkPackageManager — when COREPACK_ROOT was set. The lockfile's packageManagerDependencies entry would drift stale, and devEngines.packageManager mismatches were silently ignored. Move the corepack guard onto switchCliVersion only (corepack owns version selection), so that checkPackageManager and syncEnvLockfile run regardless of how pnpm was invoked. syncEnvLockfile self-gates via shouldPersistLockfile, so projects that only use the legacy packageManager field still won't have the lockfile rewritten. When the check fires under corepack, augment the message and hint to explain that pnpm cannot switch versions under corepack and point to the two ways out (align packageManager with devEngines.packageManager, or invoke pnpm directly). Closes #11397
zkochan
added a commit
that referenced
this pull request
Apr 30, 2026
The package-manager handling block in main.ts was guarded by `!isExecutedByCorepack()`, which skipped the entire block — including syncEnvLockfile and checkPackageManager — when COREPACK_ROOT was set. The lockfile's packageManagerDependencies entry would drift stale, and devEngines.packageManager mismatches were silently ignored. Move the corepack guard onto switchCliVersion only (corepack owns version selection), so that checkPackageManager and syncEnvLockfile run regardless of how pnpm was invoked. syncEnvLockfile self-gates via shouldPersistLockfile, so projects that only use the legacy packageManager field still won't have the lockfile rewritten. When the check fires under corepack, augment the message and hint to explain that pnpm cannot switch versions under corepack and point to the two ways out (align packageManager with devEngines.packageManager, or invoke pnpm directly). Closes #11397
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
!isExecutedByCorepack()guard off the outer pm-handling block inpnpm/src/main.tsand onto theswitchCliVersionbranch only.checkPackageManagerandsyncEnvLockfilenow run regardless of how pnpm was invoked, so the lockfile'spackageManagerDependenciesstays consistent for teams where some developers use corepack and others invoke pnpm directly.switchCliVersionis still skipped under corepack — corepack owns version selection there.onFail: 'download'looks like a silently-failed download contract). Hint points to the two ways out: alignpackageManagerwithdevEngines.packageManager, or invoke pnpm directly.shouldPersistLockfilealready self-gates insidesyncEnvLockfile, so projects that only use the legacypackageManagerfield (withoutdevEngines.packageManager) still won't have the lockfile rewritten.Test plan
pnpm/src/syncEnvLockfile.test.ts— existing 8 unit tests still pass.pnpm/test/packageManagerCheck.test.ts— added 2 e2e tests for corepack-aware behavior; full suite (23 tests) passes.devEngines.packageManager check runs even when pnpm is invoked via corepack—onFail: 'warn'+COREPACK_ROOTset → version warning still printed (was previously bypassed) and includes "Corepack invoked pnpm".devEngines.packageManager onFail=download surfaces a regular error under corepack instead of switching versions—onFail: 'download'+COREPACK_ROOTset → BAD_PM_VERSION error instead of attempted switch, message and hint cite corepack.pnpm/test/configurationalDependencies.test.ts— added an e2e test seeding a stalepackageManagerDependencies.pnpm: 0.0.1and verifying it's rewritten to the running version whenpnpm installruns withCOREPACK_ROOTset.