fix: npx pnpm install --global pnpm (#3094)

close #2873
This commit is contained in:
Zoltan Kochan
2021-01-23 15:04:02 +02:00
committed by GitHub
parent 1c851f2a6b
commit 941c5e8dee
3 changed files with 9 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/global-bin-dir": patch
---
`npx pnpm install --global pnpm` should not install pnpm to the temporary directory of npx.

View File

@@ -31,14 +31,14 @@ function pickBestGlobalBinDir (
const noWriteAccessDirs = [] as string[]
for (const dir of dirs) {
const lowCaseDir = dir.toLowerCase()
if (
if ((
isUnderDir('node', lowCaseDir) ||
isUnderDir('nodejs', lowCaseDir) ||
isUnderDir('npm', lowCaseDir) ||
isUnderDir('pnpm', lowCaseDir) ||
knownCandidates.some((candidate) => areDirsEqual(candidate, dir)) ||
dirHasNodeRelatedCommand(dir)
) {
) && !isUnderDir('_npx', lowCaseDir)) {
if (canWriteToDirAndExists(dir)) return dir
noWriteAccessDirs.push(dir)
}

View File

@@ -41,10 +41,12 @@ const userGlobalBin = makePath('usr', 'local', 'bin')
const nodeGlobalBin = makePath('home', 'z', '.nvs', 'node', '12.0.0', 'x64', 'bin')
const npmGlobalBin = makePath('home', 'z', '.npm')
const pnpmGlobalBin = makePath('home', 'z', '.pnpm')
const npxGlobalBin = makePath('home', 'z', '.npm', '_npx', '123')
const otherDir = makePath('some', 'dir')
const currentExecDir = makePath('current', 'exec')
const dirWithTrailingSlash = `${makePath('current', 'slash')}${path.sep}`
process.env[FAKE_PATH] = [
npxGlobalBin,
userGlobalBin,
nodeGlobalBin,
npmGlobalBin,