diff --git a/.changeset/silver-lions-repair.md b/.changeset/silver-lions-repair.md new file mode 100644 index 0000000000..c82d238a98 --- /dev/null +++ b/.changeset/silver-lions-repair.md @@ -0,0 +1,5 @@ +--- +"@pnpm/global-bin-dir": patch +--- + +`npx pnpm install --global pnpm` should not install pnpm to the temporary directory of npx. diff --git a/packages/global-bin-dir/src/index.ts b/packages/global-bin-dir/src/index.ts index 956aaf0327..51c2cc4497 100644 --- a/packages/global-bin-dir/src/index.ts +++ b/packages/global-bin-dir/src/index.ts @@ -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) } diff --git a/packages/global-bin-dir/test/index.ts b/packages/global-bin-dir/test/index.ts index f34bf2955b..f2728cecf1 100644 --- a/packages/global-bin-dir/test/index.ts +++ b/packages/global-bin-dir/test/index.ts @@ -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,