@@ -81,6 +81,17 @@ export function getPosixShellArgs(shellPath: string): string[] {
8181 }
8282}
8383
84+ // Windows PowerShell (powershell.exe / pwsh.exe) does not accept POSIX-style
85+ // invocation flags. When a custom shell path points at a PowerShell binary we
86+ // must use the PowerShell CLI flags (-NoProfile -NonInteractive -Command)
87+ // instead of the POSIX default (-c), which PowerShell would reject.
88+ function isPowerShellShell ( shellPath : string ) : boolean {
89+ const base = path . basename ( shellPath ) . toLowerCase ( ) ;
90+ return base === "pwsh.exe" || base === "powershell.exe" || base === "pwsh" || base === "powershell" ;
91+ }
92+
93+ const WINDOWS_POWERSHELL_ARGS = [ "-NoProfile" , "-NonInteractive" , "-Command" ] ;
94+
8495export function resolveWindowsBashPath ( env : NodeJS . ProcessEnv = process . env ) : string | undefined {
8596 const candidates = [ env . ProgramFiles , env [ "ProgramFiles(x86)" ] ]
8697 . filter ( ( dir ) : dir is string => Boolean ( dir ?. trim ( ) ) )
@@ -98,7 +109,9 @@ export function getShellConfig(customShellPath?: string): ShellConfig {
98109 if ( ! fs . existsSync ( customShellPath ) ) {
99110 throw new Error ( `Custom shell path not found: ${ customShellPath } ` ) ;
100111 }
101- return { shell : customShellPath , args : getPosixShellArgs ( customShellPath ) } ;
112+ // A custom PowerShell path must use PowerShell CLI args, not POSIX args.
113+ const args = isPowerShellShell ( customShellPath ) ? WINDOWS_POWERSHELL_ARGS : getPosixShellArgs ( customShellPath ) ;
114+ return { shell : customShellPath , args } ;
102115 }
103116
104117 if ( process . platform === "win32" ) {
@@ -141,7 +154,9 @@ export function getBashShellConfig(customShellPath?: string): ShellConfig {
141154 if ( ! fs . existsSync ( customShellPath ) ) {
142155 throw new Error ( `Custom shell path not found: ${ customShellPath } ` ) ;
143156 }
144- return { shell : customShellPath , args : getPosixShellArgs ( customShellPath ) } ;
157+ // A custom PowerShell path must use PowerShell CLI args, not POSIX args.
158+ const args = isPowerShellShell ( customShellPath ) ? WINDOWS_POWERSHELL_ARGS : getPosixShellArgs ( customShellPath ) ;
159+ return { shell : customShellPath , args } ;
145160 }
146161
147162 if ( process . platform === "win32" ) {
0 commit comments