Skip to content

fix: run packageManager check and lockfile sync under corepack#11406

Merged
zkochan merged 1 commit into
mainfrom
fix/11397
Apr 30, 2026
Merged

fix: run packageManager check and lockfile sync under corepack#11406
zkochan merged 1 commit into
mainfrom
fix/11397

Conversation

@zkochan

@zkochan zkochan commented Apr 30, 2026

Copy link
Copy Markdown
Member

Summary

  • Closes syncEnvLockfile skipped when running via corepack, leaving packageManagerDependencies stale #11397.
  • Moves the !isExecutedByCorepack() guard off the outer pm-handling block in pnpm/src/main.ts and onto the switchCliVersion branch only. checkPackageManager and syncEnvLockfile now run regardless of how pnpm was invoked, so the lockfile's packageManagerDependencies stays consistent for teams where some developers use corepack and others invoke pnpm directly. switchCliVersion is still skipped under corepack — corepack owns version selection there.
  • Augments the version-mismatch message and hint when running under corepack to explain that pnpm cannot switch versions in that mode (otherwise onFail: 'download' looks like a silently-failed download contract). Hint points to the two ways out: align packageManager with devEngines.packageManager, or invoke pnpm directly.
  • shouldPersistLockfile already self-gates inside syncEnvLockfile, so projects that only use the legacy packageManager field (without devEngines.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 corepackonFail: 'warn' + COREPACK_ROOT set → 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 versionsonFail: 'download' + COREPACK_ROOT set → BAD_PM_VERSION error instead of attempted switch, message and hint cite corepack.
  • pnpm/test/configurationalDependencies.test.ts — added an e2e test seeding a stale packageManagerDependencies.pnpm: 0.0.1 and verifying it's rewritten to the running version when pnpm install runs with COREPACK_ROOT set.

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 zkochan merged commit 7ab2828 into main Apr 30, 2026
11 of 12 checks passed
@zkochan zkochan deleted the fix/11397 branch April 30, 2026 15:05
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
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.

syncEnvLockfile skipped when running via corepack, leaving packageManagerDependencies stale

1 participant