Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix additional PowerShell warning (take two) #5100

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 27 additions & 7 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class PowerShellExeFinder {

// Also show any additionally configured PowerShells
// These may be duplicates of the default installations, but given a different name.
for (const additionalPwsh of this.enumerateAdditionalPowerShellInstallations()) {
for await (const additionalPwsh of this.enumerateAdditionalPowerShellInstallations()) {
if (await additionalPwsh.exists()) {
JustinGrote marked this conversation as resolved.
Show resolved Hide resolved
yield additionalPwsh;
} else if (!additionalPwsh.suppressWarning) {
Expand Down Expand Up @@ -230,7 +230,7 @@ export class PowerShellExeFinder {
* Iterates through the configured additional PowerShell executable locations,
* without checking for their existence.
*/
private *enumerateAdditionalPowerShellInstallations(): Iterable<IPossiblePowerShellExe> {
private async *enumerateAdditionalPowerShellInstallations(): AsyncIterable<IPossiblePowerShellExe> {
for (const versionName in this.additionalPowerShellExes) {
if (Object.prototype.hasOwnProperty.call(this.additionalPowerShellExes, versionName)) {
let exePath: string | undefined = utils.stripQuotePair(this.additionalPowerShellExes[versionName]);
Expand All @@ -245,24 +245,44 @@ export class PowerShellExeFinder {

// Always search for what the user gave us first, but with the warning
// suppressed so we can display it after all possibilities are exhausted
yield new PossiblePowerShellExe(exePath, ...args);
let pwsh = new PossiblePowerShellExe(exePath, ...args);
if (await pwsh.exists()) {
yield pwsh;
continue;
}

// Also search for `pwsh[.exe]` and `powershell[.exe]` if missing
if (this.platformDetails.operatingSystem === OperatingSystem.Windows) {
// Handle Windows where '.exe' and 'powershell' are things
if (!exePath.endsWith("pwsh.exe") && !exePath.endsWith("powershell.exe")) {
if (exePath.endsWith("pwsh") || exePath.endsWith("powershell")) {
// Add extension if that was missing
yield new PossiblePowerShellExe(exePath + ".exe", ...args);
pwsh = new PossiblePowerShellExe(exePath + ".exe", ...args);
if (await pwsh.exists()) {
yield pwsh;
continue;
}
}
// Also add full exe names (this isn't an else just in case
// the folder was named "pwsh" or "powershell")
yield new PossiblePowerShellExe(path.join(exePath, "pwsh.exe"), ...args);
yield new PossiblePowerShellExe(path.join(exePath, "powershell.exe"), ...args);
pwsh = new PossiblePowerShellExe(path.join(exePath, "pwsh.exe"), ...args);
if (await pwsh.exists()) {
yield pwsh;
continue;
}
pwsh = new PossiblePowerShellExe(path.join(exePath, "powershell.exe"), ...args);
if (await pwsh.exists()) {
yield pwsh;
continue;
}
}
} else if (!exePath.endsWith("pwsh")) {
// Always just 'pwsh' on non-Windows
yield new PossiblePowerShellExe(path.join(exePath, "pwsh"), ...args);
pwsh = new PossiblePowerShellExe(path.join(exePath, "pwsh"), ...args);
if (await pwsh.exists()) {
yield pwsh;
continue;
}
}

// If we're still being iterated over, no permutation of the given path existed so yield an object with the warning unsuppressed
Expand Down
Loading