File tree Expand file tree Collapse file tree 2 files changed +7
-10
lines changed
Expand file tree Collapse file tree 2 files changed +7
-10
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import Module from 'node:module'
22import path from 'node:path'
33import process from 'node:process'
44
5+ import { globSync } from 'tinyglobby'
6+
57import constants from '../constants'
68import { findBinPathDetailsSync , findNpmPathSync } from '../utils/path-resolve'
79
@@ -93,9 +95,14 @@ export function getNpmRequire(): NodeJS.Require {
9395let _arboristPkgPath : string | undefined
9496export 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}
Original file line number Diff line number Diff line change @@ -201,7 +201,6 @@ export function findBinPathDetailsSync(binName: string): {
201201export 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.
You can’t perform that action at this time.
0 commit comments