@@ -148,7 +148,7 @@ export class PowerShellExeFinder {
148
148
149
149
// Also show any additionally configured PowerShells
150
150
// These may be duplicates of the default installations, but given a different name.
151
- for ( const additionalPwsh of this . enumerateAdditionalPowerShellInstallations ( ) ) {
151
+ for await ( const additionalPwsh of this . enumerateAdditionalPowerShellInstallations ( ) ) {
152
152
if ( await additionalPwsh . exists ( ) ) {
153
153
yield additionalPwsh ;
154
154
} else if ( ! additionalPwsh . suppressWarning ) {
@@ -230,7 +230,7 @@ export class PowerShellExeFinder {
230
230
* Iterates through the configured additional PowerShell executable locations,
231
231
* without checking for their existence.
232
232
*/
233
- private * enumerateAdditionalPowerShellInstallations ( ) : Iterable < IPossiblePowerShellExe > {
233
+ private async * enumerateAdditionalPowerShellInstallations ( ) : AsyncIterable < IPossiblePowerShellExe > {
234
234
for ( const versionName in this . additionalPowerShellExes ) {
235
235
if ( Object . prototype . hasOwnProperty . call ( this . additionalPowerShellExes , versionName ) ) {
236
236
let exePath : string | undefined = utils . stripQuotePair ( this . additionalPowerShellExes [ versionName ] ) ;
@@ -245,24 +245,44 @@ export class PowerShellExeFinder {
245
245
246
246
// Always search for what the user gave us first, but with the warning
247
247
// suppressed so we can display it after all possibilities are exhausted
248
- yield new PossiblePowerShellExe ( exePath , ...args ) ;
248
+ let pwsh = new PossiblePowerShellExe ( exePath , ...args ) ;
249
+ if ( await pwsh . exists ( ) ) {
250
+ yield pwsh ;
251
+ continue ;
252
+ }
249
253
250
254
// Also search for `pwsh[.exe]` and `powershell[.exe]` if missing
251
255
if ( this . platformDetails . operatingSystem === OperatingSystem . Windows ) {
252
256
// Handle Windows where '.exe' and 'powershell' are things
253
257
if ( ! exePath . endsWith ( "pwsh.exe" ) && ! exePath . endsWith ( "powershell.exe" ) ) {
254
258
if ( exePath . endsWith ( "pwsh" ) || exePath . endsWith ( "powershell" ) ) {
255
259
// Add extension if that was missing
256
- yield new PossiblePowerShellExe ( exePath + ".exe" , ...args ) ;
260
+ pwsh = new PossiblePowerShellExe ( exePath + ".exe" , ...args ) ;
261
+ if ( await pwsh . exists ( ) ) {
262
+ yield pwsh ;
263
+ continue ;
264
+ }
257
265
}
258
266
// Also add full exe names (this isn't an else just in case
259
267
// the folder was named "pwsh" or "powershell")
260
- yield new PossiblePowerShellExe ( path . join ( exePath , "pwsh.exe" ) , ...args ) ;
261
- yield new PossiblePowerShellExe ( path . join ( exePath , "powershell.exe" ) , ...args ) ;
268
+ pwsh = new PossiblePowerShellExe ( path . join ( exePath , "pwsh.exe" ) , ...args ) ;
269
+ if ( await pwsh . exists ( ) ) {
270
+ yield pwsh ;
271
+ continue ;
272
+ }
273
+ pwsh = new PossiblePowerShellExe ( path . join ( exePath , "powershell.exe" ) , ...args ) ;
274
+ if ( await pwsh . exists ( ) ) {
275
+ yield pwsh ;
276
+ continue ;
277
+ }
262
278
}
263
279
} else if ( ! exePath . endsWith ( "pwsh" ) ) {
264
280
// Always just 'pwsh' on non-Windows
265
- yield new PossiblePowerShellExe ( path . join ( exePath , "pwsh" ) , ...args ) ;
281
+ pwsh = new PossiblePowerShellExe ( path . join ( exePath , "pwsh" ) , ...args ) ;
282
+ if ( await pwsh . exists ( ) ) {
283
+ yield pwsh ;
284
+ continue ;
285
+ }
266
286
}
267
287
268
288
// If we're still being iterated over, no permutation of the given path existed so yield an object with the warning unsuppressed
0 commit comments