Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Feb 19, 2025
1 parent 7e3c8c4 commit 5acef01
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/shadow/npm-paths.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { existsSync } from 'node:fs'
import Module from 'node:module'
import path from 'node:path'
import process from 'node:process'

import { globSync } from 'tinyglobby'

import constants from '../constants'
import { findBinPathDetailsSync, findNpmPathSync } from '../utils/path-resolve'

const { NPM, NPX, SOCKET_CLI_ISSUES_URL } = constants
const { NODE_MODULES, NPM, NPX, SOCKET_CLI_ISSUES_URL } = constants

function exitWithBinPathError(binName: string): never {
console.error(
Expand Down Expand Up @@ -85,17 +88,36 @@ export function getNpmPath() {
let _npmRequire: NodeJS.Require | undefined
export function getNpmRequire(): NodeJS.Require {
if (_npmRequire === undefined) {
_npmRequire = Module.createRequire(path.join(getNpmPath(), '<dummy-basename>'))
const npmPath = getNpmPath()
const npmNmPath = path.join(npmPath, NODE_MODULES, NPM)
_npmRequire = Module.createRequire(
path.join(existsSync(npmNmPath) ? npmNmPath : npmPath, '<dummy-basename>')
)
}
return _npmRequire
}

let _arboristPkgPath: string | undefined
export function getArboristPackagePath() {
if (_arboristPkgPath === undefined) {
const pkgName = '@npmcli/arborist'
const mainPath = getNpmRequire().resolve(pkgName)
_arboristPkgPath = mainPath.slice(0, mainPath.indexOf(pkgName) + pkgName.length)
try {
const pkgName = '@npmcli/arborist'
const mainPath = getNpmRequire().resolve(pkgName)
_arboristPkgPath = mainPath.slice(
0,
mainPath.indexOf(pkgName) + pkgName.length
)
} catch {
console.error(getNpmPath())
console.error(
JSON.stringify(
globSync(['node_modules/**'], { cwd: getNpmPath() }),
null,
2
)
)
throw new Error()
}
}
return _arboristPkgPath
}
Expand Down

0 comments on commit 5acef01

Please sign in to comment.