@@ -69,11 +69,29 @@ export function setup(cwd = process.cwd()) {
6969 const stdoutChunks = [ ] ;
7070 const stderrChunks = [ ] ;
7171
72+ // build env and clean PATH
73+ const env = options . env
74+ ? { ...process . env , ...options . env }
75+ : { ...process . env } ;
76+ if ( env . PATH ) {
77+ const parts = env . PATH . split ( ":" ) . filter ( Boolean ) ;
78+ const valid = [ ] ;
79+ for ( const p of parts ) {
80+ try {
81+ const stat = await fs . stat ( p ) ;
82+ if ( stat . isDirectory ( ) ) valid . push ( p ) ;
83+ } catch {
84+ // ignore non‑existent dirs
85+ }
86+ }
87+ env . PATH = valid . join ( ":" ) ;
88+ }
89+
7290 const subprocess = child_process . spawn ( command , args , {
7391 cwd,
7492 shell : process . platform === "win32" ,
7593 stdio : [ "ignore" , "pipe" , "pipe" ] ,
76- env : options . env ? { ... process . env , ... options . env } : process . env ,
94+ env,
7795 ...options ,
7896 } ) ;
7997
@@ -268,10 +286,7 @@ export function setup(cwd = process.cwd()) {
268286 * @return {Promise<ExecResult> }
269287 */
270288 npm ( args = [ ] , options = { } ) {
271- return exec ( npmBin , args , {
272- ...options ,
273- shell : process . platform !== "win32" || options . shell ,
274- } ) ;
289+ return exec ( "npm" , args , options ) ;
275290 } ,
276291 } ;
277292}
0 commit comments