From 24da84c19d97e07863ef3b4345c4c59018a6d27f Mon Sep 17 00:00:00 2001 From: Phantom Date: Mon, 29 Dec 2025 09:06:31 +0800 Subject: [PATCH] feat(cli): skip package manager check when using --global option (#10368) Add warning when package manager check is skipped due to --global flag close #10367 --- .changeset/global-option-skip-pm-check.md | 5 +++++ pnpm/src/main.ts | 6 +++++- pnpm/test/install/global.ts | 23 +++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 .changeset/global-option-skip-pm-check.md diff --git a/.changeset/global-option-skip-pm-check.md b/.changeset/global-option-skip-pm-check.md new file mode 100644 index 0000000000..991372f5bb --- /dev/null +++ b/.changeset/global-option-skip-pm-check.md @@ -0,0 +1,5 @@ +--- +"pnpm": patch +--- + +Skip the package manager check when running with --global and a project packageManager is configured, and warn that the check is skipped. diff --git a/pnpm/src/main.ts b/pnpm/src/main.ts index 9c72f14b5d..c8175ec773 100644 --- a/pnpm/src/main.ts +++ b/pnpm/src/main.ts @@ -119,7 +119,11 @@ export async function main (inputArgv: string[]): Promise { if (config.managePackageManagerVersions && config.wantedPackageManager?.name === 'pnpm' && cmd !== 'self-update') { await switchCliVersion(config) } else if (!cmd || !skipPackageManagerCheckForCommand.has(cmd)) { - checkPackageManager(config.wantedPackageManager, config) + if (cliOptions.global) { + globalWarn('Using --global skips the package manager check for this project') + } else { + checkPackageManager(config.wantedPackageManager, config) + } } } if (isDlxOrCreateCommand) { diff --git a/pnpm/test/install/global.ts b/pnpm/test/install/global.ts index dddb143609..86c6e85804 100644 --- a/pnpm/test/install/global.ts +++ b/pnpm/test/install/global.ts @@ -34,6 +34,29 @@ test('global installation', async () => { expect(typeof isNegative).toBe('function') }) +test('global install warns when project has packageManager configured', async () => { + prepare({ + name: 'project', + version: '1.0.0', + packageManager: 'yarn@4.0.0', + }) + + const global = path.resolve('..', 'global') + const pnpmHome = path.join(global, 'pnpm') + fs.mkdirSync(global) + + const env = { [PATH_NAME]: pnpmHome, PNPM_HOME: pnpmHome, XDG_DATA_HOME: global } + + const { status } = execPnpmSync([ + 'install', + '--global', + 'is-positive', + '--config.package-manager-strict=true', + ], { env }) + + expect(status).toBe(0) +}) + test('global installation to custom directory with --global-dir', async () => { prepare() const global = path.resolve('..', 'global')