Skip to content

Commit

Permalink
Make it work on Windows with WSL, MSYS, Cygwin
Browse files Browse the repository at this point in the history
  • Loading branch information
nmarghetti committed Jan 1, 2021
1 parent f3fa157 commit 6c5456c
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 46 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/windows-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: 'Tests on Windows: `nvm install`'

on: [pull_request, push]

env:
NVM_INSTALL_GITHUB_USER: ${{ github.repository }}
NVM_INSTALL_VERSION: ${{ github.sha }}

jobs:
node:
name: 'MSYS fail prefix nvm install'
runs-on: windows-latest
steps:
- name: Retrieve nvm
shell: bash
run: |
curl -sSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_USER}/${NVM_INSTALL_VERSION}/nvm.sh" | METHOD=script bash
. "$HOME/.nvm/nvm.sh"
! nvm install --lts
nodes:
name: 'MSYS nvm install'
runs-on: windows-latest
strategy:
matrix:
npm-node-version:
- '--lts'
- '--default 12'
- '--no-progress 10'

steps:
- name: Retrieve nvm
shell: bash
run: |
unset npm_config_prefix
curl -sSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_USER}/${NVM_INSTALL_VERSION}/nvm.sh" | METHOD=script bash
. "$HOME/.nvm/nvm.sh"
nvm install ${{ matrix.npm-node-version }}
wsl_nodes:
name: 'WSL nvm install'
runs-on: windows-latest
strategy:
matrix:
wsl-distrib:
- Debian
- Alpine
- Ubuntu-18.04
npm-node-version:
- '--lts'
- '11'
steps:
- uses: Vampire/setup-wsl@v1
with:
distribution: ${{ matrix.wsl-distrib }}
additional-packages: bash curl ca-certificates
wsl-shell-command: WSLENV=NVM_INSTALL_GITHUB_USER:NVM_INSTALL_VERSION/p bash -c "sudo -u test bash --noprofile --norc -euo pipefail "
- name: Retrieve nvm on WSL
shell: wsl-bash {0}
run: |
env | sort
export NVM_INSTALL_GITHUB_USER=${{ github.repository }}
export NVM_INSTALL_VERSION=${{ github.sha }}
curl -sSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_USER}/${NVM_INSTALL_VERSION}/nvm.sh" | METHOD=script bash
. "$HOME/.nvm/nvm.sh"
nvm install ${{ matrix.npm-node-version }}
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ env:
- NVM_DIR="${TRAVIS_BUILD_DIR}"
matrix:
- SHELL=bash TEST_SUITE=install_script
- SHELL=sh TEST_SUITE=nvm
- SHELL=dash TEST_SUITE=nvm
- SHELL=bash TEST_SUITE=nvm
- SHELL=zsh TEST_SUITE=nvm
# - SHELL=ksh TEST_SUITE=nvm
- SHELL=sh TEST_SUITE=fast
- SHELL=dash TEST_SUITE=fast
- SHELL=bash TEST_SUITE=fast
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,17 @@ which should output `nvm` if the installation was successful. Please note that `

If you're running a system without prepackaged binary available, which means you're going to install nodejs or io.js from its source code, you need to make sure your system has a C++ compiler. For OS X, Xcode will work, for Debian/Ubuntu based GNU/Linux, the `build-essential` and `libssl-dev` packages work.

**Note:** `nvm` does not support Windows (see [#284](https://github.com/nvm-sh/nvm/issues/284)), but may work in WSL (Windows Subsystem for Linux) depending on the version of WSL. For Windows, two alternatives exist, which are neither supported nor developed by us:
**Note:** `nvm` also support Windows in some cases. It should work through WSL (Windows Subsystem for Linux) depending on the version of WSL. It should also work with GitBash (MSYS) or Cygwin. Otherwise, for Windows, two alternatives exist, which are neither supported nor developed by us:

- [nvm-windows](https://github.com/coreybutler/nvm-windows)
- [nodist](https://github.com/marcelklehr/nodist)

**Note:** `nvm` should work with [GitBash](https://gitforwindows.org/) if installed with script method (the git repository contains filenames with characters not supported on Windows):

```sh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | METHOD=script bash
```

**Note:** `nvm` does not support [Fish] either (see [#303](https://github.com/nvm-sh/nvm/issues/303)). Alternatives exist, which are neither supported nor developed by us:

- [bass](https://github.com/edc/bass) allows you to use utilities written for Bash in fish shell
Expand Down
18 changes: 14 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,29 @@ nvm_profile_is_bash_or_zsh() {
# NVM_SOURCE always takes precedence unless the method is "script-nvm-exec"
#
nvm_source() {
local NVM_GITHUB_USER
NVM_GITHUB_USER="$NVM_INSTALL_GITHUB_USER"
if [ -z "${NVM_GITHUB_USER-}" ]; then
NVM_GITHUB_USER="nvm-sh"
fi
local NVM_VERSION
NVM_VERSION="$NVM_INSTALL_VERSION"
if [ -z "${NVM_INSTALL_VERSION-}" ]; then
NVM_VERSION="$(nvm_latest_version)"
fi
local NVM_METHOD
NVM_METHOD="$1"
local NVM_SOURCE_URL
NVM_SOURCE_URL="$NVM_SOURCE"
if [ "_$NVM_METHOD" = "_script-nvm-exec" ]; then
NVM_SOURCE_URL="https://raw.githubusercontent.com/nvm-sh/nvm/$(nvm_latest_version)/nvm-exec"
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_USER}/nvm/${NVM_VERSION}/nvm-exec"
elif [ "_$NVM_METHOD" = "_script-nvm-bash-completion" ]; then
NVM_SOURCE_URL="https://raw.githubusercontent.com/nvm-sh/nvm/$(nvm_latest_version)/bash_completion"
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_USER}/nvm/${NVM_VERSION}/bash_completion"
elif [ -z "$NVM_SOURCE_URL" ]; then
if [ "_$NVM_METHOD" = "_script" ]; then
NVM_SOURCE_URL="https://raw.githubusercontent.com/nvm-sh/nvm/$(nvm_latest_version)/nvm.sh"
NVM_SOURCE_URL="https://raw.githubusercontent.com/${NVM_GITHUB_USER}/nvm/${NVM_VERSION}/nvm.sh"
elif [ "_$NVM_METHOD" = "_git" ] || [ -z "$NVM_METHOD" ]; then
NVM_SOURCE_URL="https://github.com/nvm-sh/nvm.git"
NVM_SOURCE_URL="https://github.com/${NVM_GITHUB_USER}/nvm.git"
else
echo >&2 "Unexpected value \"$NVM_METHOD\" for \$NVM_METHOD"
return 1
Expand Down
Loading

0 comments on commit 6c5456c

Please sign in to comment.