File tree 1 file changed +12
-10
lines changed
1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change 1
- import { realpathSync } from 'node:fs'
1
+ import { statSync } from 'node:fs'
2
2
import path from 'node:path'
3
3
import process from 'node:process'
4
4
@@ -65,16 +65,18 @@ export function isNpxBinPathShadowed() {
65
65
let _npmPath : string | undefined
66
66
export function getNpmPath ( ) {
67
67
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
70
70
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 )
78
80
// The exit code 127 indicates that the command or binary being executed
79
81
// could not be found.
80
82
process . exit ( 127 )
You can’t perform that action at this time.
0 commit comments