@@ -252,21 +252,32 @@ export function setup(cwd = process.cwd()) {
252252 * @return {Promise<ExecResult> }
253253 */
254254 async npm ( args = [ ] , options = { } ) {
255- // Use node to run npm directly since npm might not be in PATH
255+ // First try to use NPM_PATH from environment (set by CI)
256+ if ( process . env . NPM_PATH ) {
257+ try {
258+ await fs . access ( process . env . NPM_PATH ) ;
259+ console . log ( `Using npm from NPM_PATH: ${ process . env . NPM_PATH } ` ) ;
260+ return exec ( process . env . NPM_PATH , args , options ) ;
261+ } catch ( err ) {
262+ console . log ( `npm at NPM_PATH not accessible: ${ err . message } ` ) ;
263+ }
264+ }
265+
266+ // Try to find npm in the same directory as node
256267 const nodePath = process . execPath ;
257268 const nodeDir = path . dirname ( nodePath ) ;
258269 const npmPath = path . join ( nodeDir , "npm" ) ;
259270
260271 try {
261- // Try to use npm from the same directory as node
262272 await fs . access ( npmPath ) ;
263273 console . log ( `Using npm from Node.js directory: ${ npmPath } ` ) ;
264274 return exec ( npmPath , args , options ) ;
265275 } catch ( err ) {
266276 console . log ( `npm not found in Node.js directory: ${ err . message } ` ) ;
267277 }
268278
269- // Fallback to direct npm execution
279+ // Final fallback to direct npm execution
280+ console . log ( "Falling back to direct npm execution" ) ;
270281 return exec ( "npm" , args , options ) ;
271282 } ,
272283 } ;
0 commit comments