Skip to content

Automatically find "PowerShell Daily" at its common path #4331

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 1 commit into from
Dec 19, 2022
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
2 changes: 1 addition & 1 deletion src/features/ShowHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class ShowHelpFeature extends LanguageClientConsumer {
constructor() {
super();
this.command = vscode.commands.registerCommand("PowerShell.ShowHelp", async (item?) => {
if (!item || !item.Name) {
if (!item?.Name) {

const editor = vscode.window.activeTextEditor;
if (editor === undefined) {
Expand Down
39 changes: 39 additions & 0 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,9 @@ export class PowerShellExeFinder {

break;
}

// Look for PSCore daily
yield this.findPSCoreDaily();
}

/**
Expand Down Expand Up @@ -260,6 +263,42 @@ export class PowerShellExeFinder {
}
}

/**
* If the daily was installed via 'https://aka.ms/install-powershell.ps1', then
* this is the default installation location:
*
* if ($IsWinEnv) {
* $Destination = "$env:LOCALAPPDATA\Microsoft\powershell"
* } else {
* $Destination = "~/.powershell"
* }
*
* if ($Daily) {
* $Destination = "${Destination}-daily"
* }
*/
private findPSCoreDaily(): IPossiblePowerShellExe | undefined {
switch (this.platformDetails.operatingSystem) {
case OperatingSystem.Linux:
case OperatingSystem.MacOS: {
const exePath = path.join(os.homedir(), ".powershell-daily", "pwsh");
return new PossiblePowerShellExe(exePath, "PowerShell Daily");
}

case OperatingSystem.Windows: {
// We can't proceed if there's no LOCALAPPDATA path
if (!process.env.LOCALAPPDATA) {
return undefined;
}
const exePath = path.join(process.env.LOCALAPPDATA, "Microsoft", "powershell-daily", "pwsh.exe");
return new PossiblePowerShellExe(exePath, "PowerShell Daily");
}

case OperatingSystem.Unknown:
return undefined;
}
}

private findPSCoreDotnetGlobalTool(): IPossiblePowerShellExe {
const exeName: string = this.platformDetails.operatingSystem === OperatingSystem.Windows
? "pwsh.exe"
Expand Down
37 changes: 31 additions & 6 deletions test/core/platform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as assert from "assert";
import mockFS = require("mock-fs");
import FileSystem = require("mock-fs/lib/filesystem");
import * as os from "os";
import * as path from "path";
import rewire = require("rewire");
import * as sinon from "sinon";
Expand Down Expand Up @@ -61,14 +62,13 @@ interface ITestPlatformSuccessCase extends ITestPlatform {
// Platform configurations where we expect to find a set of PowerShells
let successTestCases: ITestPlatformSuccessCase[];

let msixAppDir: string;
let pwshMsixPath: string;
let pwshPreviewMsixPath: string;

if (process.platform === "win32") {
msixAppDir = path.join(process.env.LOCALAPPDATA!, "Microsoft", "WindowsApps");
pwshMsixPath = path.join(msixAppDir, "Microsoft.PowerShell_8wekyb3d8bbwe", "pwsh.exe");
pwshPreviewMsixPath = path.join(msixAppDir, "Microsoft.PowerShellPreview_8wekyb3d8bbwe", "pwsh.exe");
const msixAppDir = path.join(process.env.LOCALAPPDATA!, "Microsoft", "WindowsApps");
const pwshMsixPath = path.join(msixAppDir, "Microsoft.PowerShell_8wekyb3d8bbwe", "pwsh.exe");
const pwshPreviewMsixPath = path.join(msixAppDir, "Microsoft.PowerShellPreview_8wekyb3d8bbwe", "pwsh.exe");
const pwshDailyDir = path.join(process.env.LOCALAPPDATA!, "Microsoft", "powershell-daily");
const pwshDailyPath = path.join(pwshDailyDir, "pwsh.exe");

successTestCases = [
{
Expand Down Expand Up @@ -124,6 +124,11 @@ if (process.platform === "win32") {
displayName: "Windows PowerShell (x86)",
supportsProperArguments: true
},
{
exePath: pwshDailyPath,
displayName: "PowerShell Daily",
supportsProperArguments: true
}
],
filesystem: {
"C:\\Program Files\\PowerShell": {
Expand Down Expand Up @@ -156,6 +161,9 @@ if (process.platform === "win32") {
"C:\\WINDOWS\\SysWOW64\\WindowsPowerShell\\v1.0": {
"powershell.exe": "",
},
[pwshDailyDir]: {
"pwsh.exe": "",
}
},
},
{
Expand Down Expand Up @@ -436,6 +444,7 @@ if (process.platform === "win32") {
},
];
} else {
const pwshDailyDir = path.join(os.homedir(), ".powershell-daily");
successTestCases = [
{
name: "Linux (all installations)",
Expand Down Expand Up @@ -466,6 +475,11 @@ if (process.platform === "win32") {
displayName: "PowerShell Preview Snap",
supportsProperArguments: true
},
{
exePath: path.join(pwshDailyDir, "pwsh"),
displayName: "PowerShell Daily",
supportsProperArguments: true
}
],
filesystem: {
"/usr/bin": {
Expand All @@ -476,6 +490,9 @@ if (process.platform === "win32") {
"pwsh": "",
"pwsh-preview": "",
},
[pwshDailyDir]: {
"pwsh": ""
}
},
},
{
Expand All @@ -497,12 +514,20 @@ if (process.platform === "win32") {
displayName: "PowerShell Preview",
supportsProperArguments: true
},
{
exePath: path.join(pwshDailyDir, "pwsh"),
displayName: "PowerShell Daily",
supportsProperArguments: true
}
],
filesystem: {
"/usr/local/bin": {
"pwsh": "",
"pwsh-preview": "",
},
[pwshDailyDir]: {
"pwsh": ""
}
},
},
{
Expand Down