Skip to content

Set Default PowerShell Version on Windows to Latest Available #2094

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

Merged
merged 43 commits into from
Aug 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
93b9e20
Update platform.ts
SydneyhSmith Jul 18, 2019
f5e99d4
Update session.ts
SydneyhSmith Jul 18, 2019
fc0e83b
Merge pull request #1 from SydneyhSmith/WindowsCoreCheck
SydneyhSmith Jul 18, 2019
8e829bd
Update platform.ts
SydneyhSmith Jul 18, 2019
be41e5b
Update src/platform.ts
SydneyhSmith Jul 19, 2019
962bac7
Update platform.ts
SydneyhSmith Jul 19, 2019
decb0ac
Update platform.test.ts
SydneyhSmith Jul 19, 2019
29cde1b
Update platform.test.ts
SydneyhSmith Jul 19, 2019
df67d6b
Update platform.ts
SydneyhSmith Jul 22, 2019
2ddc9c0
Update platform.ts
SydneyhSmith Jul 22, 2019
a373034
Update platform.test.ts
SydneyhSmith Jul 26, 2019
a7931ae
Update platform.test.ts
SydneyhSmith Jul 26, 2019
38a9cf7
Update platform.test.ts
SydneyhSmith Jul 26, 2019
9981f80
Update src/platform.ts
SydneyhSmith Jul 29, 2019
aea0c5d
Update platform.ts
SydneyhSmith Jul 29, 2019
eb06392
Update platform.ts
SydneyhSmith Jul 29, 2019
faee4a7
Update platform.ts
SydneyhSmith Jul 29, 2019
01657f9
Update platform.test.ts
SydneyhSmith Jul 29, 2019
bd55ee2
Update platform.ts
SydneyhSmith Jul 29, 2019
4dfe7df
Update platform.ts
SydneyhSmith Jul 29, 2019
a09ee3b
Update platform.test.ts
SydneyhSmith Jul 30, 2019
bb7fe4a
Update platform.test.ts
SydneyhSmith Jul 30, 2019
56f4402
Update platform.test.ts
SydneyhSmith Jul 30, 2019
6d8fab8
Update platform.test.ts
SydneyhSmith Jul 31, 2019
6b5e3a9
Update platform.test.ts
SydneyhSmith Jul 31, 2019
b9b93ee
Update platform.test.ts
SydneyhSmith Jul 31, 2019
c70aeca
Update platform.test.ts
SydneyhSmith Jul 31, 2019
ed355ae
Update platform.test.ts
SydneyhSmith Jul 31, 2019
d788bb7
Update platform.test.ts
SydneyhSmith Jul 31, 2019
9efa922
Update platform.test.ts
SydneyhSmith Jul 31, 2019
69f9342
Update platform.test.ts
SydneyhSmith Jul 31, 2019
bd8eeb0
Update src/platform.ts
SydneyhSmith Aug 6, 2019
059c782
Update src/platform.ts
SydneyhSmith Aug 6, 2019
35c5e10
Update platform.ts
SydneyhSmith Aug 6, 2019
aa3f354
Update platform.ts
SydneyhSmith Aug 6, 2019
9c5ca2c
Update platform.ts
SydneyhSmith Aug 6, 2019
b405e00
Update src/platform.ts
SydneyhSmith Aug 22, 2019
40f1649
Update platform.ts
SydneyhSmith Aug 22, 2019
af96894
Update platform.ts
SydneyhSmith Aug 22, 2019
b15caad
Update platform.ts
SydneyhSmith Aug 22, 2019
768bacf
Update platform.ts
SydneyhSmith Aug 22, 2019
b3df4bb
Update platform.ts
SydneyhSmith Aug 22, 2019
1c620bb
Update platform.ts
SydneyhSmith Aug 22, 2019
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
54 changes: 41 additions & 13 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,55 @@ export function getDefaultPowerShellPath(
use32Bit: boolean = false): string | null {

let powerShellExePath;
let psCoreInstallPath;

// Find the path to powershell.exe based on the current platform
// Find the path to the powershell executable based on the current platform
// and the user's desire to run the x86 version of PowerShell
if (platformDetails.operatingSystem === OperatingSystem.Windows) {
if (use32Bit) {
powerShellExePath =
platformDetails.isOS64Bit && platformDetails.isProcess64Bit
? SysWow64PowerShellPath
: System32PowerShellPath;
psCoreInstallPath =
(platformDetails.isProcess64Bit ? process.env["ProgramFiles(x86)"] : process.env.ProgramFiles)
+ "\\PowerShell";
} else {
powerShellExePath =
!platformDetails.isOS64Bit || platformDetails.isProcess64Bit
? System32PowerShellPath
: SysnativePowerShellPath;
psCoreInstallPath =
(platformDetails.isProcess64Bit ? process.env.ProgramFiles : process.env.ProgramW6432) + "\\PowerShell";
}
} else if (platformDetails.operatingSystem === OperatingSystem.MacOS) {

if (fs.existsSync(psCoreInstallPath)) {
const arch = platformDetails.isProcess64Bit ? "(x64)" : "(x86)";
const psCorePaths =
fs.readdirSync(psCoreInstallPath)
.map((item) => path.join(psCoreInstallPath, item))
.filter((item) => {
const exePath = path.join(item, "pwsh.exe");
return fs.lstatSync(item).isDirectory() && fs.existsSync(exePath);
})
.map((item) => ({
versionName: `PowerShell ${path.parse(item).base} ${arch}`,
exePath: path.join(item, "pwsh.exe"),
}));

if (psCorePaths) {
return powerShellExePath = psCorePaths[0].exePath;
}
}

// No PowerShell 6+ detected so use Windows PowerShell.
if (use32Bit) {
return platformDetails.isOS64Bit && platformDetails.isProcess64Bit
? SysWow64PowerShellPath
: System32PowerShellPath;
}
return !platformDetails.isOS64Bit || platformDetails.isProcess64Bit
? System32PowerShellPath
: SysnativePowerShellPath;
}
if (platformDetails.operatingSystem === OperatingSystem.MacOS) {
// Always default to the stable version of PowerShell (if installed) but handle case of only Preview installed
powerShellExePath = macOSExePath;
if (!fs.existsSync(macOSExePath) && fs.existsSync(macOSPreviewExePath)) {
powerShellExePath = macOSPreviewExePath;
}
}
} else if (platformDetails.operatingSystem === OperatingSystem.Linux) {
// Always default to the stable version of PowerShell (if installed) but handle case of only Preview installed
// as well as the Snaps case - https://snapcraft.io/
Expand Down Expand Up @@ -179,7 +207,7 @@ export function getAvailablePowerShellExes(
return fs.lstatSync(item).isDirectory() && fs.existsSync(exePath);
})
.map((item) => ({
versionName: `PowerShell Core ${path.parse(item).base} ${arch}`,
versionName: `PowerShell ${path.parse(item).base} ${arch}`,
exePath: path.join(item, "pwsh.exe"),
}));

Expand All @@ -200,7 +228,7 @@ export function getAvailablePowerShellExes(
exePaths.forEach((exePath) => {
if (fs.existsSync(exePath)) {
paths.push({
versionName: "PowerShell Core" + (/-preview/.test(exePath) ? " Preview" : ""),
versionName: "PowerShell" + (/-preview/.test(exePath) ? " Preview" : ""),
exePath,
});
}
Expand Down
28 changes: 0 additions & 28 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,34 +113,6 @@ export class SessionManager implements Middleware {

this.powerShellExePath = this.getPowerShellExePath();

// Check for OpenSSL dependency on macOS when running PowerShell Core alpha. Look for the default
// Homebrew installation path and if that fails check the system-wide library path.
if (os.platform() === "darwin" && this.getPowerShellVersionLabel() === "alpha") {
if (!(utils.checkIfFileExists("/usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib") &&
utils.checkIfFileExists("/usr/local/opt/openssl/lib/libssl.1.0.0.dylib")) &&
!(utils.checkIfFileExists("/usr/local/lib/libcrypto.1.0.0.dylib") &&
utils.checkIfFileExists("/usr/local/lib/libssl.1.0.0.dylib"))) {
const thenable =
vscode.window.showWarningMessage(
"The PowerShell extension will not work without OpenSSL on macOS and OS X when using " +
"PowerShell Core alpha",
"Show Documentation");

thenable.then(
(s) => {
if (s === "Show Documentation") {
cp.exec("open https://github.com/PowerShell/vscode-powershell/blob/master/docs/" +
"troubleshooting.md#1-powershell-intellisense-does-not-work-cant-debug-scripts");
}
});

// Don't continue initializing since Editor Services will not load successfully
this.setSessionFailure(
"Cannot start PowerShell Editor Services due to missing OpenSSL dependency.");
return;
}
}

this.suppressRestartPrompt = false;

if (this.powerShellExePath) {
Expand Down
4 changes: 2 additions & 2 deletions test/platform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ suite("Platform module", () => {

checkDefaultPowerShellPath(
platformDetails,
platform.SysnativePowerShellPath);
"C:\\Program Files\\PowerShell\\6\\pwsh.exe");

checkAvailableWindowsPowerShellPaths(
platformDetails,
Expand Down Expand Up @@ -106,7 +106,7 @@ suite("Platform module", () => {

checkDefaultPowerShellPath(
platformDetails,
platform.System32PowerShellPath);
"C:\\Program Files\\PowerShell\\6\\pwsh.exe");

checkAvailableWindowsPowerShellPaths(
platformDetails,
Expand Down