@@ -559,25 +559,67 @@ export class ExecuteBash {
559
559
return [ str , false ]
560
560
}
561
561
562
- private static async whichCommand ( logger : Logging , cmd : string ) : Promise < string > {
563
- const { command, args } = IS_WINDOWS_PLATFORM
564
- ? { command : 'where' , args : [ cmd ] }
565
- : { command : 'sh' , args : [ '-c' , `command -v ${ cmd } ` ] }
566
- const cp = new processUtils . ChildProcess ( logger , command , args , {
567
- collect : true ,
568
- waitForStreams : true ,
569
- } )
570
- const result = await cp . run ( )
562
+ private static async whichCommand ( logger : Logging , cmd : string ) : Promise < void > {
563
+ if ( IS_WINDOWS_PLATFORM ) {
564
+ await this . resolveWindowsCommand ( logger , cmd )
565
+ } else {
566
+ await this . resolveUnixCommand ( logger , cmd )
567
+ }
568
+ }
569
+
570
+ private static async resolveWindowsCommand ( logger : Logging , cmd : string ) : Promise < void > {
571
+ // 1. Check for external command or alias
572
+ try {
573
+ const whereProc = new processUtils . ChildProcess ( logger , 'where' , [ cmd ] , {
574
+ collect : true ,
575
+ waitForStreams : true ,
576
+ } )
577
+ const result = await whereProc . run ( )
578
+ const output = result . stdout . trim ( )
579
+
580
+ if ( result . exitCode === 0 && output ) {
581
+ return
582
+ }
583
+ } catch ( err ) {
584
+ logger . debug ( `'where ${ cmd } ' failed: ${ ( err as Error ) . message } ` )
585
+ }
571
586
572
- if ( result . exitCode !== 0 ) {
573
- throw new Error ( `Command '${ cmd } ' not found on PATH.` )
587
+ // 2. Check for built-in command
588
+ try {
589
+ const helpProc = new processUtils . ChildProcess ( logger , 'cmd.exe' , [ '/c' , 'help' , cmd ] , {
590
+ collect : true ,
591
+ waitForStreams : true ,
592
+ } )
593
+ const result = await helpProc . run ( )
594
+ const output = result . stdout . trim ( )
595
+
596
+ if ( output && ! output . includes ( 'This command is not supported by the help utility' ) ) {
597
+ return
598
+ }
599
+ } catch ( err ) {
600
+ logger . debug ( `'help ${ cmd } ' failed: ${ ( err as Error ) . message } ` )
574
601
}
575
602
576
- const output = result . stdout . trim ( )
577
- if ( ! output ) {
578
- throw new Error ( `Command '${ cmd } ' found but '${ command } ${ args . join ( ' ' ) } ' returned empty output.` )
603
+ throw new Error ( `Command '${ cmd } ' not found as executable or Windows built-in command` )
604
+ }
605
+
606
+ private static async resolveUnixCommand ( logger : Logging , cmd : string ) : Promise < void > {
607
+ try {
608
+ const proc = new processUtils . ChildProcess ( logger , 'sh' , [ '-c' , `command -v ${ cmd } ` ] , {
609
+ collect : true ,
610
+ waitForStreams : true ,
611
+ } )
612
+ const result = await proc . run ( )
613
+ const output = result . stdout . trim ( )
614
+
615
+ if ( result . exitCode === 0 && output ) {
616
+ return
617
+ }
618
+ } catch ( err ) {
619
+ logger . debug ( `'command -v ${ cmd } ' failed: ${ ( err as Error ) . message } ` )
579
620
}
580
- return output
621
+
622
+ throw new Error ( `Command '${ cmd } ' not found as executable or shell built-in` )
581
623
}
582
624
583
625
public async queueDescription ( command : string , updates : WritableStream ) {
0 commit comments