Skip to content

Commit 1a3889d

Browse files
committed
Don't dirname the npm path in getNpmPath
1 parent 24ec928 commit 1a3889d

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Diff for: src/shadow/npm-paths.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { realpathSync } from 'node:fs'
1+
import { statSync } from 'node:fs'
22
import path from 'node:path'
33
import process from 'node:process'
44

@@ -65,16 +65,18 @@ export function isNpxBinPathShadowed() {
6565
let _npmPath: string | undefined
6666
export function getNpmPath() {
6767
if (_npmPath === undefined) {
68-
const npmEntrypoint = path.dirname(realpathSync.native(getNpmBinPath()))
69-
_npmPath = findNpmPathSync(npmEntrypoint)
68+
const npmBinPath = getNpmBinPath()
69+
_npmPath = npmBinPath ? findNpmPathSync(npmBinPath) : undefined
7070
if (!_npmPath) {
71-
console.error(
72-
`Unable to find npm CLI install directory.
73-
Searched parent directories of ${npmEntrypoint}.
74-
75-
This is may be a bug with socket-npm related to changes to the npm CLI.
76-
Please report to ${SOCKET_CLI_ISSUES_URL}.`
77-
)
71+
let message = 'Unable to find npm CLI install directory.'
72+
if (npmBinPath) {
73+
const npmBinDirname = statSync(npmBinPath).isDirectory()
74+
? npmBinPath
75+
: path.dirname(npmBinPath)
76+
message += `\nSearched parent directories of ${npmBinDirname}.`
77+
}
78+
message += `\n\nThis is may be a bug with socket-npm related to changes to the npm CLI.\nPlease report to ${SOCKET_CLI_ISSUES_URL}.`
79+
console.error(message)
7880
// The exit code 127 indicates that the command or binary being executed
7981
// could not be found.
8082
process.exit(127)

0 commit comments

Comments
 (0)