Skip to content
Myr

[New] maybe support Windows with WSL, MSYS, Cygwin

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by nmarghetti · committed by Jordan Harband · parent d118be8 · Browse files · 6 files+186 added−21 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+186 added−21 removed

  • tests:+17 added−1 removed
  • other:+169 added−20 removed

6 files+186 added−21 removed

added:.github/workflows/windows-npm.yml+106 added
1name: 'Tests on Windows: `nvm install`'23on: [pull_request, push]45env:6 NVM_INSTALL_GITHUB_REPO: ${{ github.repository }}7 NVM_INSTALL_VERSION: ${{ github.sha }}89jobs:10 node_fail_install:11 # Default installation does not work due to npm_config_prefix set to C:\npm\prefix12 name: 'MSYS fail prefix nvm install'13 runs-on: windows-latest14 steps:15 - name: Retrieve nvm16 shell: bash17 run: |18 curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash19 . "$HOME/.nvm/nvm.sh"20 ! nvm install --lts21 nodes:22 name: 'MSYS nvm install'23 runs-on: windows-latest24 strategy:25 matrix:26 npm-node-version:27 - '--lts'28 - '--default 12'29 - '--no-progress 10'30 steps:31 - name: Retrieve nvm32 shell: bash33 run: |34 unset npm_config_prefix35 if [ "${{ matrix.npm-node-version }}" = "--lts" ]; then36 curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash37 else38 curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash39 fi40 . "$HOME/.nvm/nvm.sh"41 nvm install ${{ matrix.npm-node-version }}42 node_cygwin:43 name: 'Cygwin nvm install'44 runs-on: windows-latest45 steps:46 - name: Install Cygwin47 shell: bash48 run: |49 export SITE='https://mirror.clarkson.edu/cygwin/'50 export LOCALDIR="$(pwd)"51 export ROOTDIR="$USERPROFILE\\cygwin"52 export PACKAGES='bash,git,curl'5354 curl -fsSLo setup-x86_64.exe 'https://cygwin.com/setup-x86_64.exe'55 ./setup-x86_64.exe --disable-buggy-antivirus -q -s "$SITE" -l "$LOCALDIR" -R "$ROOTDIR" -P "$PACKAGES"5657 cat >~/setup.sh <<EOM58 unset npm_config_prefix59 export NVM_INSTALL_GITHUB_REPO="$NVM_INSTALL_GITHUB_REPO"60 export NVM_INSTALL_VERSION="$NVM_INSTALL_VERSION"6162 curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash63 . "$HOME/.nvm/nvm.sh"64 nvm install --lts6566 nvm deactivate67 rm -rf "$HOME/.nvm/nvm.sh"6869 curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash70 . "$HOME/.nvm/nvm.sh"71 nvm install 972 EOM73 - name: Retrieve nvm74 shell: cmd75 run: |76 cd %USERPROFILE%\cygwin\bin77 bash.exe "%USERPROFILE%\setup.sh"78 wsl_nodes:79 name: 'WSL nvm install'80 runs-on: windows-latest81 env:82 WSLENV: NVM_INSTALL_GITHUB_REPO:NVM_INSTALL_VERSION:/p83 strategy:84 matrix:85 wsl-distrib:86 - Debian87 - Alpine88 - Ubuntu-18.0489 npm-node-version:90 - '--lts'91 - '11'92 steps:93 - uses: Vampire/setup-wsl@v194 with:95 distribution: ${{ matrix.wsl-distrib }}96 additional-packages: bash git curl ca-certificates97 - name: Retrieve nvm on WSL98 shell: wsl-bash {0}99 run: |100 if [ "${{ matrix.wsl-distrib }}" = "Ubuntu-18.04" ] && [ "${{ matrix.npm-node-version }}" = "--lts" ]; then101 curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | bash102 else103 curl -fsSLo- "https://raw.githubusercontent.com/${NVM_INSTALL_GITHUB_REPO}/${NVM_INSTALL_VERSION}/install.sh" | METHOD=script bash104 fi105 . "$HOME/.nvm/nvm.sh"106 nvm install ${{ matrix.npm-node-version }}
modified:test/fast/Unit tests/nvm_get_artifact_compression+6 added
11 unmodified lines
1213# nvm_get_artifact_compression with xz14[ "$(nvm_get_artifact_compression "14.0.0")" = 'tar.xz' ] || die 'nvm_get_artifact_compression should return "tar.xz" for this version'1516# nvm_get_artifact_compression with zip on Windows17nvm_get_os() {18 nvm_echo 'win'19}20[ "$(nvm_get_artifact_compression)" = 'zip' ] || die 'nvm_get_artifact_compression should return "zip" for Windows'2122cleanup
modified:test/fast/Unit tests/nvm_install_binary_extract+3 added
41 unmodified lines
42if [ -z "$NVM_DIR" ] || [ -z "$tmp_dir" ]; then43 die 'Unable to create temporary folder'44fi4546# Test windows zip47test_archi 'win' 'v15.6.0' 'x64' 'node' 'zip' 'zip' '-qr'4849# Test linux tar.xz50test_archi 'linux' 'v14.15.4' 'x64' 'bin/node' 'tar.xz' 'tar' '-cJf'5152nvm_supports_xz(){
7 unmodified lines
modified:test/fast/Unit tests/nvm_is_version_installed+8 added-1 removed
1#!/bin/sh23cleanup () {4 rm -rf "$NVM_DIR"5 unset -f die cleanup check_version5 unset -f die cleanup nvm_get_os check_version6 unset NVM_DIR NODE_PATH7}8die () { echo "$@" ; cleanup ; exit 1; }9
33 unmodified lines
43! nvm_is_version_installed || die 'nvm_is_version_installed without parameter should fail'4445check_version '12.0.0' 'node'4647# Checking for Windows48nvm_get_os() {49 echo "win"50}51check_version '13.0.0' 'node.exe'525354cleanup
modified:nvm.sh+62 added-19 removed
144 unmodified lines
145 [ "$(nvm deactivate >/dev/null 2>&1 && command -v iojs)" != '' ]146}147148nvm_is_version_installed() {149 [ -n "${1-}" ] && [ -x "$(nvm_version_path "$1" 2>/dev/null)"/bin/node ]149 if [ -z "${1-}" ]; then150 return 1151 fi152 local NVM_NODE_BINARY153 NVM_NODE_BINARY='node'154 if [ "_$(nvm_get_os)" = '_win' ]; then155 NVM_NODE_BINARY='node.exe'156 fi157 if [ -x "$(nvm_version_path "$1" 2>/dev/null)/bin/${NVM_NODE_BINARY}" ]; then158 return 0159 fi160 return 1161}162163nvm_print_npm_version() {164 if nvm_has "npm"; then
171 unmodified lines
336 nvm_err "both the tree and the node path are required"337 return 2338 fi339340 local previous_pathdir341 previous_pathdir="${node_path}"342 local pathdir330 pathdir=$(dirname "${node_path}")331 while [ "${pathdir}" != "" ] && [ "${pathdir}" != "." ] && [ "${pathdir}" != "/" ] && [ "${pathdir}" != "${tree}" ]; do332 pathdir=$(dirname "${pathdir}")343 pathdir=$(dirname "${previous_pathdir}")344 while [ "${pathdir}" != '' ] && [ "${pathdir}" != '.' ] && [ "${pathdir}" != '/' ] &&345 [ "${pathdir}" != "${tree}" ] && [ "${pathdir}" != "${previous_pathdir}" ]; do346 previous_pathdir="${pathdir}"347 pathdir=$(dirname "${previous_pathdir}")348 done349 [ "${pathdir}" = "${tree}" ]350}351
1425 unmodified lines
1777 SunOS\ *) NVM_OS=sunos ;;1778 FreeBSD\ *) NVM_OS=freebsd ;;1779 OpenBSD\ *) NVM_OS=openbsd ;;1780 AIX\ *) NVM_OS=aix ;;1781 CYGWIN* | MSYS* | MINGW*) NVM_OS=win ;;1782 esac1783 nvm_echo "${NVM_OS-}"1784}1785
121 unmodified lines
1907 [ -n "${TMPDIR-}" ] && \1908 command mkdir -p "${TMPDIR}" && \1909 VERSION_PATH="$(nvm_version_path "${PREFIXED_VERSION}")" || return 119101895 local tar_compression_flag1896 tar_compression_flag='z'1897 if nvm_supports_xz "${VERSION}"; then1898 tar_compression_flag='J'1899 fi19001901 local tar1902 if [ "${NVM_OS}" = 'aix' ]; then1903 tar='gtar'1911 # For Windows system (GitBash with MSYS, Cygwin)1912 if [ "${NVM_OS}" = 'win' ]; then1913 VERSION_PATH="${VERSION_PATH}/bin"1914 command unzip -q "${TARBALL}" -d "${TMPDIR}" || return 11915 # For non Windows system (including WSL running on Windows)1916 else1917 local tar_compression_flag1918 tar_compression_flag='z'1919 if nvm_supports_xz "${VERSION}"; then1920 tar_compression_flag='J'1921 fi19221923 local tar1924 if [ "${NVM_OS}" = 'aix' ]; then1925 tar='gtar'1926 else1905 tar='tar'1927 tar='tar'1928 fi1929 command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 || return 11930 fi1907 command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 || return 119311932 command mkdir -p "${VERSION_PATH}" || return 119331934 if [ "${NVM_OS}" = 'win' ]; then1935 command mv "${TMPDIR}/"*/* "${VERSION_PATH}" || return 11936 command chmod +x "${VERSION_PATH}"/node.exe || return 11937 command chmod +x "${VERSION_PATH}"/npm || return 11938 command chmod +x "${VERSION_PATH}"/npx 2>/dev/null1939 else1911 command mv "${TMPDIR}/"* "${VERSION_PATH}" || return 11940 command mv "${TMPDIR}/"* "${VERSION_PATH}" || return 11941 fi19421943 command rm -rf "${TMPDIR}"19441945 return 0
125 unmodified lines
2071 NVM_OS="$(nvm_get_os)"20722073 local COMPRESSION2074 COMPRESSION='tar.gz'2075 if [ "_${NVM_OS}" = '_win' ]; then2076 COMPRESSION='zip'2045 if nvm_supports_xz "${VERSION}"; then2077 elif nvm_supports_xz "${VERSION}"; then2078 COMPRESSION='tar.xz'2079 fi20802081 nvm_echo "${COMPRESSION}"
358 unmodified lines
2440 nvm_err 'Run `unset PREFIX` to unset it.'2441 return 32442 fi24432444 local NVM_OS2445 NVM_OS="$(nvm_get_os)"24462447 # npm normalizes NPM_CONFIG_-prefixed env vars2448 # https://github.com/npm/npmconf/blob/22827e4038d6eebaafeb5c13ed2b92cf97b8fb82/npmconf.js#L331-L3482449 # https://github.com/npm/npm/blob/5e426a78ca02d0044f8dd26e0c5f881217081cbd/lib/config/core.js#L343-L3592450 #
3 unmodified lines
2454 NVM_NPM_CONFIG_PREFIX_ENV="$(command env | nvm_grep -i NPM_CONFIG_PREFIX | command tail -1 | command awk -F '=' '{print $1}')"2455 if [ -n "${NVM_NPM_CONFIG_PREFIX_ENV-}" ]; then2456 local NVM_CONFIG_VALUE2457 eval "NVM_CONFIG_VALUE=\"\$${NVM_NPM_CONFIG_PREFIX_ENV}\""2458 if [ -n "${NVM_CONFIG_VALUE-}" ] && [ "_${NVM_OS}" = "_win" ]; then2459 NVM_CONFIG_VALUE="$(cd "$NVM_CONFIG_VALUE" 2>/dev/null && pwd)"2460 fi2461 if [ -n "${NVM_CONFIG_VALUE-}" ] && ! nvm_tree_contains_path "${NVM_DIR}" "${NVM_CONFIG_VALUE}"; then2462 nvm deactivate >/dev/null 2>&12463 nvm_err "nvm is not compatible with the \"${NVM_NPM_CONFIG_PREFIX_ENV}\" environment variable: currently set to \"${NVM_CONFIG_VALUE}\""2464 nvm_err "Run \`unset ${NVM_NPM_CONFIG_PREFIX_ENV}\` to unset it."
781 unmodified lines
3246 if [ -z "${NVM_MAKE_JOBS-}" ]; then3247 nvm_get_make_jobs3248 fi32493250 if [ "_${NVM_OS}" = "_win" ]; then3251 nvm_err 'Installing from source on non-WSL Windows is not supported'3252 EXIT_CODE=873253 else3212 NVM_NO_PROGRESS="${NVM_NO_PROGRESS:-${noprogress}}" nvm_install_source "${FLAVOR}" std "${VERSION}" "${NVM_MAKE_JOBS}" "${ADDITIONAL_PARAMETERS}"3213 EXIT_CODE=$?3254 NVM_NO_PROGRESS="${NVM_NO_PROGRESS:-${noprogress}}" nvm_install_source "${FLAVOR}" std "${VERSION}" "${NVM_MAKE_JOBS}" "${ADDITIONAL_PARAMETERS}"3255 EXIT_CODE=$?3256 fi3257 fi32583259 fi3260
978 unmodified lines
modified:README.md+1 added-1 removed
150 unmodified lines
151### Important Notes152153If 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.154155**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, a few alternatives exist, which are neither supported nor developed by us:155**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](https://gitforwindows.org/) (MSYS) or [Cygwin](https://cygwin.com). Otherwise, for Windows, afew alternatives exist, which are neither supported nor developed by us:156157 - [nvm-windows](https://github.com/coreybutler/nvm-windows)158 - [nodist](https://github.com/marcelklehr/nodist)159 - [nvs](https://github.com/jasongin/nvs)
779 unmodified lines