-
Notifications
You must be signed in to change notification settings - Fork 500
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
WIP: Add support for side-by-side PS Core preview on Linux/macOS #1366
Conversation
This PR supports listing the symlinks for pwsh & pwsh-preview. The preferred default version is pwsh if both are present however, the default will be pwsh-preview if it's installed and pwsh isn't. So this only support side-by-side on Linux/macOS up to two versions: stable and preview.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, Keith 😄 just a small comment.
src/platform.ts
Outdated
versionName: "PowerShell Core Preview", | ||
exePath: linuxPreviewExePath, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored this a bit to define the paths conditionally and then do the logic. I think it's a little DRY-er. Totally, not a blocker but what do you think?
let osExePath, osPreviewExePath;
if (platformDetails.operatingSystem === OperatingSystem.MacOS) {
osExePath = macOSExePath;
osPreviewExePath = macOSPreviewExePath;
} else if (platformDetails.operatingSystem === OperatingSystem.Linux) {
osExePath = linuxExePath;
osPreviewExePath = linuxPreviewExePath;
}
if ((defaultExePath === osExePath) && fs.existsSync(osPreviewExePath)) {
paths.push({
versionName: "PowerShell Core Preview",
exePath: linuxPreviewExePath,
});
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Can you make this change on the PR branch and merge? I think I've allowed it to be edited. If not, I should be able to get to this tonight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Please test on macOS and Linux.
src/platform.ts
Outdated
osPreviewExePath = linuxPreviewExePath; | ||
} | ||
|
||
if ((osExePath === defaultExePath) && fs.existsSync(osPreviewExePath)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's super rare, but isn't it possible for them to have legacy (powershell
) and preview (pwsh-preview
)?
If so, this if check might have to be:
defaultExePath !== osPreviewExePath && ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can fix this by testing for the legacy path here or maybe we should just remove support for the legacy "powershell"on Linux and macOS. This was abandoned somewhere around the transition from 6.0.0 alpha to beta. At this point, I'm not sure why anyone would still be running an alpha of 6.0.0 on Linux/macOS.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
totally on board. We should only support 6.0.0 release and onward.
Is there any work that needs to be done here: I just saw that it had to something with the exe path. |
Those tests still pass for me on Windows. Looks like the tests mainly check to see that we get back the correct 32/64-bit version of Windows PowerShell on Windows. |
Sounds good :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! Thanks @rkeithhill!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have yet to test this btw. Will do this week.
So I was messing with the VSCode & PowerShell snaps... Snap is essentially an attempt at a "universal *nix package manager... more info here. Snap is a Canonical thing Anyway... on all of their supported OS's you should be able to run:
and get VSCode, PowerShell and the extension installed... However the extension fails because the "powershell exe" it is trying to use is
NOTE: the we should probably handle this in the linux case so we can support the Snap build of PowerShell out of the box. @rkeithhill would you be ok adding a check for this in this PR? |
Are those paths on Linux or macOS? Also, is the binary called |
@rkeithhill AFAIK, snap is only linux: |
the binary is called and we should also handle the |
I've been talking to @TravisEz13 about this who has been driving the Snap work |
I can't wait to install VSCode & PowerShell on my OpenWRT based Router lol |
@tylerl0706 Can you test this in a Snap environment? |
gladly :) I'll test now. |
@rkeithhill it works! |
src/platform.ts
Outdated
osExePath = macOSExePath; | ||
osPreviewExePath = macOSPreviewExePath; | ||
} else if (platformDetails.operatingSystem === OperatingSystem.Linux) { | ||
osExePath = linuxExePath; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we not need to do the same ternary op here to check for snap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed here because getDefaultPowerShellPath
already returns just one of: linuxExePath, linuxPreviewExePath, snapExePath, snapPreviewExePath. It searches in that order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW I get the impression (perhaps incorrect impression) that on a Snap system, PowerShell will only be at /snap/bin/pwsh* and that you wouldn't also have PowerShell at /usr/bin/pwsh*. And on a straight (non-Snap) Linux system, there would be no /snap/bin/pwsh*. That is, these two sets are mutually exclusive. Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So snap is really just a package manager that you first install with apt. So you could have installed pwsh
by Snap and Apt on the same system.
Not quite sure why one would do that... but it's physically possible. I guess I could see something along the lines of installing pwsh with apt and pwsh-preview with snap maybe...
So it's physically possible to have a /snap/bin/pwsh
and a /usr/bin/pwsh
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However! I just learned that /snap/bin/powershell
gets created but /usr/bin/powershell
does not. So if you installed PowerShell with Snap and Apt, typing pwsh
at the terminal will get you the apt
version... and typing powershell
at the prompt will get you the Snap version.
This might be TMI but I figured I would share.
You might hate me for saying this... but I've thought about this part of the code for a bit and wonder if there's some opportunity to clean up the code a bit... maybe something like this:
Note that the array is in the order of what we consider the default. if we're super worried about perf (in this case, I don't think we are) we could optionally give I wont block on this, but I feel like it might be worth it... |
Not at all. I have no particularly affinity for this code. :-) We could make that change but we can't get rid of the test against the default PowerShell exe simply because we don't want the same entry to show up twice. Also, I don't think perf is that much of a concern here and we do want to list all the available PowerShell instances that can be used. |
Thanks for putting up with my comments 😄
I don't think I quite follow how we would end up with something showing up twice? Think you could elaborate? |
The issue is that for some reason (I don't remember) in the current impl of |
Updated to simplify per your suggestion. Can you test again on Linux/macOS? |
@rkeithhill no surprise your code works beautifully :) |
* Add support for side-by-side PS Core preview on Linux/macOS This PR supports listing the symlinks for pwsh & pwsh-preview. The preferred default version is pwsh if both are present however, the default will be pwsh-preview if it's installed and pwsh isn't. So this only support side-by-side on Linux/macOS up to two versions: stable and preview. * Adjust name of default PS Core on Linux/macOS * Make a bit DRY-er. Thx @tylerl0706 * Remove support for pre-ship PS Core Linux/macOS binary name - powershell * Add support for PowerShell Core installed in a Snap * Simplify impl of getting available PS on Linux/macOS
PR Summary
This PR supports listing the symlinks for pwsh & pwsh-preview.
Fixes #1361
The preferred default version is pwsh if both are present however, the
default will be pwsh-preview if it's installed and pwsh isn't.
So this only support side-by-side on Linux/macOS up to two versions:
stable and preview.
In the future, we may want to do what we do on Windows and search thru
the install dir for pwsh.
The would be /opt/microsoft/poweshell on LInux.
Not sure what it is on macOS.
Or maybe we should just do that now. Thoughts?
I marked this as WIP because I need someone to test this on Linux and macOS. :-)
PR Checklist
Note: Tick the boxes below that apply to this pull request by putting an
x
between the square brackets.Please mark anything not applicable to this PR
NA
.WIP:
to the beginning of the title and remove the prefix when the PR is ready