Skip to content

Commit 78b2bba

Browse files
committed
debug
1 parent 7e3c8c4 commit 78b2bba

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

src/shadow/npm-paths.ts

Lines changed: 32 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,41 @@ 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+
_npmRequire = Module.createRequire(
93+
path.join(npmPath, '<dummy-basename>')
94+
)
8995
}
9096
return _npmRequire
9197
}
9298

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

src/utils/path-resolve.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, promises as fs, realpathSync, statSync } from 'node:fs'
1+
import { existsSync, promises as fs, realpathSync /*, statSync*/ } from 'node:fs'
22
import path from 'node:path'
33
import process from 'node:process'
44

@@ -19,7 +19,7 @@ type GlobWithGitIgnoreOptions = GlobOptions & {
1919
socketConfig?: SocketYml | undefined
2020
}
2121

22-
const { NODE_MODULES, NPM, shadowBinPath } = constants
22+
const { /*NODE_MODULES,*/ NPM, shadowBinPath } = constants
2323

2424
async function filterGlobResultToSupportedFiles(
2525
entries: string[],
@@ -201,7 +201,7 @@ export function findBinPathDetailsSync(binName: string): {
201201
export function findNpmPathSync(npmBinPath: string): string | undefined {
202202
let thePath = npmBinPath
203203
while (true) {
204-
const nmPath = path.join(thePath, NODE_MODULES)
204+
//const nmPath = path.join(thePath, NODE_MODULES)
205205
if (
206206
// npm bin paths may look like:
207207
// /usr/local/share/npm/bin/npm
@@ -217,8 +217,8 @@ export function findNpmPathSync(npmBinPath: string): string | undefined {
217217
// Use existsSync here because statsSync, even with { throwIfNoEntry: false },
218218
// will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.
219219
// See https://github.com/nodejs/node/issues/56993.
220-
existsSync(nmPath) &&
221-
statSync(nmPath, { throwIfNoEntry: false })?.isDirectory() &&
220+
// existsSync(nmPath) &&
221+
// statSync(nmPath, { throwIfNoEntry: false })?.isDirectory() &&
222222
// Optimistically look for the default location.
223223
(path.basename(thePath) === NPM ||
224224
// Chocolatey installs npm bins in the same directory as node bins.

0 commit comments

Comments
 (0)