Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 14 additions & 5 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ export function getDefaultPowerShellPath(
}
else if (platformDetails.operatingSystem == OperatingSystem.MacOS) {
powerShellExePath = "/usr/local/bin/powershell";
if (fs.existsSync("/usr/loca/bin/pwsh")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed an 'l' in 'local' in the path

powerShellExePath = "/usr/local/bin/pwsh";
}
}
else if (platformDetails.operatingSystem == OperatingSystem.Linux) {
powerShellExePath = "/usr/bin/powershell";
if (fs.existsSync("/usr/bin/pwsh")) {
powerShellExePath = "/usr/bin/pwsh";
}
}

return powerShellExePath;
Expand Down Expand Up @@ -146,9 +152,14 @@ export function getAvailablePowerShellExes(platformDetails: PlatformDetails): Po
.map(item => path.join(psCoreInstallPath, item))
.filter(item => fs.lstatSync(item).isDirectory())
.map(item => {
let exePath = path.join(item, "pwsh.exe");
if (!fs.existsSync(exePath)) {
exePath = path.join(item, "powershell.exe");
}

return {
versionName: `PowerShell Core ${path.parse(item).base}`,
exePath: path.join(item, "powershell.exe")
exePath: exePath
};
});

Expand All @@ -158,12 +169,10 @@ export function getAvailablePowerShellExes(platformDetails: PlatformDetails): Po
}
}
else {

paths.push({
versionName: "PowerShell Core",
exePath:
os.platform() === "darwin"
? "/usr/local/bin/powershell"
: "/usr/bin/powershell"
exePath: this.getDefaultPowerShellPath(platformDetails)
});
}

Expand Down
8 changes: 8 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,14 @@ export class SessionManager implements Middleware {
this.sessionSettings.developer.powerShellExePath ||
"").trim();

// New versions of PS Core uninstall the previous version
// so make sure the path stored in the settings exists.
if (!fs.existsSync(powerShellExePath)) {
this.log.write(
`Path specified by 'powerShellExePath' setting - '${powerShellExePath}' - not found, reverting to default PowerShell path.`);
powerShellExePath = "";
}

if (this.platformDetails.operatingSystem === OperatingSystem.Windows &&
powerShellExePath.length > 0) {

Expand Down