Skip to content

Commit 3e2d9e4

Browse files
committed
debug
1 parent 7e3c8c4 commit 3e2d9e4

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

src/shadow/npm-paths.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import { existsSync } from 'node:fs'
12
import Module from 'node:module'
23
import path from 'node:path'
34
import process from 'node:process'
45

6+
import { globSync } from 'tinyglobby'
7+
58
import constants from '../constants'
69
import { findBinPathDetailsSync, findNpmPathSync } from '../utils/path-resolve'
710

8-
const { NPM, NPX, SOCKET_CLI_ISSUES_URL } = constants
11+
const { NODE_MODULES, NPM, NPX, SOCKET_CLI_ISSUES_URL } = constants
912

1013
function exitWithBinPathError(binName: string): never {
1114
console.error(
@@ -85,17 +88,40 @@ export function getNpmPath() {
8588
let _npmRequire: NodeJS.Require | undefined
8689
export function getNpmRequire(): NodeJS.Require {
8790
if (_npmRequire === undefined) {
88-
_npmRequire = Module.createRequire(path.join(getNpmPath(), '<dummy-basename>'))
91+
const npmPath = getNpmPath()
92+
const npmNmPath = path.join(npmPath, NODE_MODULES, NPM)
93+
_npmRequire = Module.createRequire(
94+
path.join(existsSync(npmNmPath) ? npmNmPath : npmPath, '<dummy-basename>')
95+
)
8996
}
9097
return _npmRequire
9198
}
9299

93100
let _arboristPkgPath: string | undefined
94101
export function getArboristPackagePath() {
95102
if (_arboristPkgPath === undefined) {
96-
const pkgName = '@npmcli/arborist'
97-
const mainPath = getNpmRequire().resolve(pkgName)
98-
_arboristPkgPath = mainPath.slice(0, mainPath.indexOf(pkgName) + pkgName.length)
103+
try {
104+
const pkgName = '@npmcli/arborist'
105+
const mainPath = getNpmRequire().resolve(pkgName)
106+
_arboristPkgPath = mainPath.slice(
107+
0,
108+
mainPath.indexOf(pkgName) + pkgName.length
109+
)
110+
} catch {
111+
console.error(getNpmPath())
112+
113+
const npmPath = getNpmPath()
114+
const npmNmPath = path.join(npmPath, NODE_MODULES, NPM)
115+
console.error(path.join(existsSync(npmNmPath) ? npmNmPath : npmPath, '<dummy-basename>'))
116+
console.error(
117+
JSON.stringify(
118+
globSync(['node_modules/**'], { cwd: getNpmPath() }),
119+
null,
120+
2
121+
)
122+
)
123+
throw new Error()
124+
}
99125
}
100126
return _arboristPkgPath
101127
}

0 commit comments

Comments
 (0)