Skip to content

Commit a70a499

Browse files
rkeithhilldaviwil
authored andcommitted
Update to handle PS Core binary name change
Fix #1064 Also fixes case where the powerShellExePath setting is no longer valid. This happens when a Windows users installs an updated pre-release version of PS Core. That uninstalls previous versions.
1 parent f944f4e commit a70a499

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/platform.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,15 @@ export function getDefaultPowerShellPath(
7373
}
7474
else if (platformDetails.operatingSystem == OperatingSystem.MacOS) {
7575
powerShellExePath = "/usr/local/bin/powershell";
76+
if (fs.existsSync("/usr/loca/bin/pwsh")) {
77+
powerShellExePath = "/usr/local/bin/pwsh";
78+
}
7679
}
7780
else if (platformDetails.operatingSystem == OperatingSystem.Linux) {
7881
powerShellExePath = "/usr/bin/powershell";
82+
if (fs.existsSync("/usr/bin/pwsh")) {
83+
powerShellExePath = "/usr/bin/pwsh";
84+
}
7985
}
8086

8187
return powerShellExePath;
@@ -146,9 +152,14 @@ export function getAvailablePowerShellExes(platformDetails: PlatformDetails): Po
146152
.map(item => path.join(psCoreInstallPath, item))
147153
.filter(item => fs.lstatSync(item).isDirectory())
148154
.map(item => {
155+
let exePath = path.join(item, "pwsh.exe");
156+
if (!fs.existsSync(exePath)) {
157+
exePath = path.join(item, "powershell.exe");
158+
}
159+
149160
return {
150161
versionName: `PowerShell Core ${path.parse(item).base}`,
151-
exePath: path.join(item, "powershell.exe")
162+
exePath: exePath
152163
};
153164
});
154165

@@ -158,12 +169,10 @@ export function getAvailablePowerShellExes(platformDetails: PlatformDetails): Po
158169
}
159170
}
160171
else {
172+
161173
paths.push({
162174
versionName: "PowerShell Core",
163-
exePath:
164-
os.platform() === "darwin"
165-
? "/usr/local/bin/powershell"
166-
: "/usr/bin/powershell"
175+
exePath: this.getDefaultPowerShellPath(platformDetails)
167176
});
168177
}
169178

src/session.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,14 @@ export class SessionManager implements Middleware {
560560
this.sessionSettings.developer.powerShellExePath ||
561561
"").trim();
562562

563+
// New versions of PS Core uninstall the previous version
564+
// so make sure the path stored in the settings exists.
565+
if (!fs.existsSync(powerShellExePath)) {
566+
this.log.write(
567+
`Path specified by 'powerShellExePath' setting - '${powerShellExePath}' - not found, reverting to default PowerShell path.`);
568+
powerShellExePath = "";
569+
}
570+
563571
if (this.platformDetails.operatingSystem === OperatingSystem.Windows &&
564572
powerShellExePath.length > 0) {
565573

0 commit comments

Comments
 (0)