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
This commit is contained in:
Phantom
2025-12-29 09:06:31 +08:00
committed by GitHub
parent 4f3ad2388c
commit 24da84c19d
3 changed files with 33 additions and 1 deletions

View File

@@ -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.

View File

@@ -119,7 +119,11 @@ export async function main (inputArgv: string[]): Promise<void> {
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) {

View File

@@ -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')