Skip to content

Commit 37c4464

Browse files
committed
Improve warning when additional PowerShell isn't found
Since we added logic which searches for possible intended permutations of the given additional PowerShell path, we needed to make the warning show only if none of the permutations were found. This was accomplished by suppressing it in the first iterator and then yielding it again after the permutations were exhausted with the warning unsuppressed.
1 parent 0b61253 commit 37c4464

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/platform.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,17 @@ export class PowerShellExeFinder {
239239
}
240240

241241
exePath = untildify(exePath);
242-
243-
// Always search for what the user gave us first
244-
yield new PossiblePowerShellExe(exePath, versionName);
245-
246-
// Also search for `pwsh[.exe]` and `powershell[.exe]` if missing
247242
const args: [string, undefined, boolean, boolean]
248243
// Must be a tuple type and is suppressing the warning
249244
= [versionName, undefined, true, true];
250245

251-
// Handle Windows where '.exe' and 'powershell' are things
246+
// Always search for what the user gave us first, but with the warning
247+
// suppressed so we can display it after all possibilities are exhausted
248+
yield new PossiblePowerShellExe(exePath, ...args);
249+
250+
// Also search for `pwsh[.exe]` and `powershell[.exe]` if missing
252251
if (this.platformDetails.operatingSystem === OperatingSystem.Windows) {
252+
// Handle Windows where '.exe' and 'powershell' are things
253253
if (!exePath.endsWith("pwsh.exe") && !exePath.endsWith("powershell.exe")) {
254254
if (exePath.endsWith("pwsh") || exePath.endsWith("powershell")) {
255255
// Add extension if that was missing
@@ -260,9 +260,13 @@ export class PowerShellExeFinder {
260260
yield new PossiblePowerShellExe(path.join(exePath, "pwsh.exe"), ...args);
261261
yield new PossiblePowerShellExe(path.join(exePath, "powershell.exe"), ...args);
262262
}
263-
} else if (!exePath.endsWith("pwsh")) { // Always just 'pwsh' on non-Windows
263+
} else if (!exePath.endsWith("pwsh")) {
264+
// Always just 'pwsh' on non-Windows
264265
yield new PossiblePowerShellExe(path.join(exePath, "pwsh"), ...args);
265266
}
267+
268+
// If we're still being iterated over, no permutation of the given path existed so yield an object with the warning unsuppressed
269+
yield new PossiblePowerShellExe(exePath, versionName, false, undefined, false);
266270
}
267271
}
268272
}

0 commit comments

Comments
 (0)