Skip to content
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

Use in PowerShell for Linux? #190

Closed
rashil2000 opened this issue Mar 6, 2021 · 13 comments
Closed

Use in PowerShell for Linux? #190

rashil2000 opened this issue Mar 6, 2021 · 13 comments

Comments

@rashil2000
Copy link
Contributor

Hi! It's really nice to see a version manager that works consistently across OSes. However, the main reason I'm unable to use nvm.sh is because I use PowerShell everywhere.

So I would like to know how I can source the nvs.sh so that I can use nvs in PowerShell on Linux.

@jasongin
Copy link
Owner

jasongin commented Mar 6, 2021

At the time I originally developed nvs, PowerShell was Windows-only. I haven't investigated what it would take to support PowerShell on Linux now, but I'm guessing sourcing nvs.sh is not going to work, at least not fully. Probably a better approach would be to update the nvs.ps1 script to be cross-platform.

I probably won't have time to work on this anytime soon, but I'd be happy to review a PR if someone else wants to pick it up.

@rashil2000
Copy link
Contributor Author

Is there a way for me to create a binary or a script for nvs (like nvs.exe for Windows) so that I can put it in /usr/bin and call it anywhere on Linux?

@rashil2000
Copy link
Contributor Author

There are tools like pkg and nexe which can package Nodejs apps into standalone binaries, I wonder if it's possible to make use of those.

@jasongin
Copy link
Owner

jasongin commented Mar 7, 2021

Using a separate binary won’t work, for the same reason invoking nvs.sh from powershell doesn’t work: a separate process cannot modify the PATH environment variable in the current shell. That is why nvs requires separate integration scripts for each kind of shell. The part of nvs that modifies the PATH works by sourcing a shell script in-proc from the calling shell.

@rashil2000
Copy link
Contributor Author

Oh, I see. Thanks for the info!

@rashil2000
Copy link
Contributor Author

I have beginner PowerShell knowledge, but looking at nvs.ps1 file, I think we only need to change the node binary's URL (for platforms other than Windows) and subsequent extraction command (7zr.exe). Is this correct?

@jasongin
Copy link
Owner

@rashil2000 That sounds right. And you might also need to change the detection of processor arch, as I don't know whether there is a PROCESSOR_ARCHITECTURE env variable on non-Windows platforms.

@rashil2000
Copy link
Contributor Author

[System.Environment]::Is64BitOperatingSystem gives us the answer for that

@jasongin
Copy link
Owner

That's not enough if you're on an arm cpu.

@rashil2000
Copy link
Contributor Author

rashil2000 commented Mar 12, 2021

For such cases, we can simply fallback to using uname -m | sed -e 's/x86_64/x64/;s/i86pc/x64/;s/i686/x86/;s/aarch64/arm64/', as these commands will always be available on any *nix system

@rashil2000
Copy link
Contributor Author

Hi, sorry for not getting back on this.

I'm wondering if there's a much simpler way to achieve this: for Linux/macOS systems, the nvs.ps1 script can call the script nvs (since it has a shebang it will work), simply as a one-time step to download the bootstrap binary and extract it. We would not need to rewrite all the tar extraction logic. Something like this:

if (-not (Test-Path $bootstrapNodePath)) {
  if (-not ($IsWindows -or $PSVersionTable.PSVersion.Major -eq 5)) {    
    & "$scriptDir/nvs" install
  } else {
  ...
}

Afterwards the nvs.ps1 script can directly be used in Linux PowerShell sessions (some tiny path modifications might be needed in the script still).

If this is okay, I can try sending a PR for this.

@jasongin
Copy link
Owner

jasongin commented Jun 1, 2021

Yes, that's reasonable. As you said, there may still be some additional details to work out.

@rashil2000
Copy link
Contributor Author

I have sent a PR, it's a very minimal change - #207

Tested on Ubuntu 20.04.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants