Skip to content

Commit 83bd137

Browse files
committed
Search npmEntrypoint without dirname for npm path. [closes #305]
1 parent 37a20bc commit 83bd137

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/shadow/npm-paths.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import path from 'node:path'
33
import process from 'node:process'
44

55
import constants from '../constants'
6-
import { findRoot } from '../utils/path-resolve'
6+
import { findNpmPath } from '../utils/path-resolve'
77

88
const { NODE_MODULES, SOCKET_CLI_ISSUES_URL } = constants
99

1010
const npmEntrypoint = realpathSync.native(process.argv[1]!)
11-
const npmRootPath = findRoot(path.dirname(npmEntrypoint))
12-
if (npmRootPath === undefined) {
11+
const npmPath = findNpmPath(npmEntrypoint)
12+
if (npmPath === undefined) {
1313
console.error(
1414
`Unable to find npm CLI install directory.
1515
Searched parent directories of ${npmEntrypoint}.
@@ -22,7 +22,7 @@ Please report to ${SOCKET_CLI_ISSUES_URL}.`
2222
process.exit(127)
2323
}
2424

25-
export const npmNmPath = path.join(npmRootPath, NODE_MODULES)
25+
export const npmNmPath = path.join(npmPath, NODE_MODULES)
2626
export const arboristPkgPath = path.join(npmNmPath, '@npmcli/arborist')
2727
export const arboristClassPath = path.join(
2828
arboristPkgPath,

src/utils/path-resolve.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function pathsToPatterns(paths: string[]): string[] {
165165
return paths.map(p => (p === '.' ? '**/*' : p))
166166
}
167167

168-
export function findRoot(filepath: string): string | undefined {
168+
export function findNpmPath(filepath: string): string | undefined {
169169
let curPath = filepath
170170
while (true) {
171171
if (path.basename(curPath) === NPM) {

0 commit comments

Comments
 (0)