From 941c5e8dee984a7cae6fa98bbbc9f3f4e14e1b24 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 23 Jan 2021 15:04:02 +0200 Subject: [PATCH] fix: npx pnpm install --global pnpm (#3094) close #2873 --- .changeset/silver-lions-repair.md | 5 +++++ packages/global-bin-dir/src/index.ts | 4 ++-- packages/global-bin-dir/test/index.ts | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/silver-lions-repair.md 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,