Skip to content

Commit 38b1f82

Browse files
committed
debug
1 parent 7e3c8c4 commit 38b1f82

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/shadow/npm-paths.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import Module from 'node:module'
22
import path from 'node:path'
33
import process from 'node:process'
44

5+
import { globSync } from 'tinyglobby'
6+
57
import constants from '../constants'
68
import { findBinPathDetailsSync, findNpmPathSync } from '../utils/path-resolve'
79

@@ -93,9 +95,14 @@ export function getNpmRequire(): NodeJS.Require {
9395
let _arboristPkgPath: string | undefined
9496
export function getArboristPackagePath() {
9597
if (_arboristPkgPath === undefined) {
98+
try {
9699
const pkgName = '@npmcli/arborist'
97100
const mainPath = getNpmRequire().resolve(pkgName)
98101
_arboristPkgPath = mainPath.slice(0, mainPath.indexOf(pkgName) + pkgName.length)
102+
} catch {
103+
console.error(globSync(['node_modules/**'], { cwd: getNpmPath() }))
104+
throw new Error()
105+
}
99106
}
100107
return _arboristPkgPath
101108
}

src/utils/path-resolve.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ 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)
205204
if (
206205
// npm bin paths may look like:
207206
// /usr/local/share/npm/bin/npm
@@ -210,15 +209,6 @@ export function findNpmPathSync(npmBinPath: string): string | undefined {
210209
// OR
211210
// C:\Program Files\nodejs\npm.cmd
212211
//
213-
// In all cases the npm path contains a node_modules folder:
214-
// /usr/local/share/npm/bin/npm/node_modules
215-
// C:\Program Files\nodejs\node_modules
216-
//
217-
// Use existsSync here because statsSync, even with { throwIfNoEntry: false },
218-
// will throw an ENOTDIR error for paths like ./a-file-that-exists/a-directory-that-does-not.
219-
// See https://github.com/nodejs/node/issues/56993.
220-
existsSync(nmPath) &&
221-
statSync(nmPath, { throwIfNoEntry: false })?.isDirectory() &&
222212
// Optimistically look for the default location.
223213
(path.basename(thePath) === NPM ||
224214
// Chocolatey installs npm bins in the same directory as node bins.

0 commit comments

Comments
 (0)