mirror of
https://github.com/pnpm/pnpm.git
synced 2026-07-04 12:55:22 -04:00
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:
5
.changeset/global-option-skip-pm-check.md
Normal file
5
.changeset/global-option-skip-pm-check.md
Normal 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.
|
||||
@@ -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) {
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user