@@ -254,29 +254,44 @@ const ttyServerPromise = chalkPromise.then(async (chalk) => {
254254const npmEntrypoint = fs . realpathSync ( `${ process . argv [ 1 ] } ` )
255255/**
256256 * @param {string } filepath
257- * @returns {string }
257+ * @returns {string | null }
258258 */
259259function findRoot ( filepath ) {
260260 if ( path . basename ( filepath ) === 'npm' ) {
261261 return filepath
262262 }
263263 const parent = path . dirname ( filepath )
264264 if ( parent === filepath ) {
265- process . exit ( 127 )
265+ return null
266266 }
267267 return findRoot ( parent )
268268}
269269const npmDir = findRoot ( path . dirname ( npmEntrypoint ) )
270- const arboristLibClassPath = path . join ( npmDir , 'node_modules' , '@npmcli' , 'arborist' , 'lib' , 'arborist' , 'index.js' )
270+ if ( npmDir === null ) {
271+ console . error ( 'Unable to find npm cli install directory, this is potentiall a bug with socket-npm caused by changes to npm cli.' )
272+ console . error ( `Searched parent directories of ${ npmEntrypoint } ` )
273+ process . exit ( 127 )
274+ }
275+ let arboristLibClassPath
276+ try {
277+ arboristLibClassPath = path . join ( npmDir , 'node_modules' , '@npmcli' , 'arborist' , 'lib' , 'arborist' , 'index.js' )
278+ } catch ( e ) {
279+ console . error ( 'Unable to integrate with npm cli internals, this is potentially a bug with socket-npm caused by changes to npm cli.' )
280+ process . exit ( 127 ) ;
281+ }
271282
272- const npmVersion = process . env . NPM_VERSION . split ( '.' )
273283let npmlog
274284
275- if ( npmVersion [ 0 ] === '10' && npmVersion [ 1 ] >= '6' ) {
276- const { log } = require ( path . join ( npmDir , 'node_modules' , 'proc-log' , 'lib' , 'index.js' ) )
277- npmlog = log
278- } else {
285+ try {
279286 npmlog = require ( path . join ( npmDir , 'node_modules' , 'npmlog' , 'lib' , 'log.js' ) )
287+ } catch {
288+ try {
289+ const { log } = require ( path . join ( npmDir , 'node_modules' , 'proc-log' , 'lib' , 'index.js' ) )
290+ npmlog = log
291+ } catch {
292+ console . error ( 'Unable to integrate with npm cli logging infrastructure, this is potentially a bug with socket-npm caused by changes to npm cli.' )
293+ process . exit ( 127 ) ;
294+ }
280295}
281296
282297/**
0 commit comments