mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-10 18:18:56 -04:00
fix: finding global bin directory
When searching for a global bin directory, also look for symlinked commands. close #2888 PR #2889
This commit is contained in:
5
.changeset/smooth-zoos-rush.md
Normal file
5
.changeset/smooth-zoos-rush.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/global-bin-dir": patch
|
||||
---
|
||||
|
||||
When searching for a suitable global bin directory, search for symlinked node, npm, pnpm commands, not only command files.
|
||||
@@ -62,7 +62,8 @@ const NODE_RELATED_COMMANDS = new Set(['pnpm', 'npm', 'node'])
|
||||
function dirHasNodeRelatedCommand (dir: string) {
|
||||
try {
|
||||
return fs.readdirSync(dir, { withFileTypes: true })
|
||||
.filter((entry) => entry.isFile())
|
||||
// We are searching for files or symlinks, not directories
|
||||
.filter((entry) => !entry.isDirectory())
|
||||
.map(({ name }) => name.toLowerCase())
|
||||
.some((file) => NODE_RELATED_COMMANDS.has(file.split('.')[0]))
|
||||
} catch (err) {
|
||||
|
||||
@@ -11,15 +11,15 @@ const makePath =
|
||||
: (...paths: string[]) => `/${path.join(...paths)}`
|
||||
|
||||
let canWriteToDir!: typeof _canWriteToDir
|
||||
let readdirSync = (dir: string) => [] as Array<{ name: string, isFile: () => boolean }>
|
||||
let readdirSync = (dir: string) => [] as Array<{ name: string, isDirectory: () => boolean }>
|
||||
const FAKE_PATH = 'FAKE_PATH'
|
||||
|
||||
function makeFileEntry (name: string) {
|
||||
return { name, isFile: () => true }
|
||||
return { name, isDirectory: () => false }
|
||||
}
|
||||
|
||||
function makeDirEntry (name: string) {
|
||||
return { name, isFile: () => false }
|
||||
return { name, isDirectory: () => true }
|
||||
}
|
||||
|
||||
const globalBinDir = proxiquire('../lib/index.js', {
|
||||
|
||||
Reference in New Issue
Block a user