From fb4538b360a4ddd5d390442f3bfde9b3239b4413 Mon Sep 17 00:00:00 2001 From: lsfxz <1813007-ohfp@users.noreply.gitlab.com> Date: Wed, 17 Nov 2021 16:59:53 +0100 Subject: [PATCH 01/15] [Fix] add missing `local` (handle nonexisting /sbin/init a bit more cleanly) --- nvm.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/nvm.sh b/nvm.sh index 1a811f7..e3098b8 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1871,6 +1871,7 @@ nvm_get_arch() { esac # If running a 64bit ARM kernel but a 32bit ARM userland, change ARCH to 32bit ARM (armv7l) + local L L=$(ls -dl /sbin/init 2>/dev/null) # if /sbin/init is 32bit executable if [ "$(uname)" = "Linux" ] && [ "${NVM_ARCH}" = arm64 ] && [ "$(od -An -t x1 -j 4 -N 1 "${L#*-> }")" = ' 01' ]; then NVM_ARCH=armv7l From 81f0f3ec19e08ca782f8a5bb29823a70b8f41177 Mon Sep 17 00:00:00 2001 From: Luke Arms Date: Mon, 27 Dec 2021 16:02:25 +1100 Subject: [PATCH 02/15] [Fix] `set -E`: Add test for `node install` on Bash with an ERR trap and `set -E` --- nvm.sh | 9 ++++ .../install on bash with ERR trap and set -E | 50 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100755 test/installation_node/install on bash with ERR trap and set -E diff --git a/nvm.sh b/nvm.sh index e3098b8..f40a9f3 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2742,6 +2742,15 @@ nvm() { EXIT_CODE="$?" set -a return "$EXIT_CODE" + elif [ -n "${BASH-}" ] && [ "${-#*E}" != "$-" ]; then + # shellcheck disable=SC3041 + set +E + local EXIT_CODE + IFS="${DEFAULT_IFS}" nvm "$@" + EXIT_CODE="$?" + # shellcheck disable=SC3041 + set -E + return "$EXIT_CODE" elif [ "${IFS}" != "${DEFAULT_IFS}" ]; then IFS="${DEFAULT_IFS}" nvm "$@" return "$?" diff --git a/test/installation_node/install on bash with ERR trap and set -E b/test/installation_node/install on bash with ERR trap and set -E new file mode 100755 index 0000000..edfad0c --- /dev/null +++ b/test/installation_node/install on bash with ERR trap and set -E @@ -0,0 +1,50 @@ +#!/bin/sh + +set -e + +cleanup() { + nvm cache clear + nvm deactivate + rm -rf "${NVM_DIR}"/v* + nvm unalias default +} + +die() { + echo "$@" + cleanup || true + exit 1 +} + +\. ../../nvm.sh + +if [ -z "${BASH-}" ]; then + echo "This test only applies to Bash; skipping" + exit +fi + +cleanup || true +trap 'echo "==> EXIT signal received (status: $?)"; cleanup' EXIT + +# shellcheck disable=SC3047 +trap 'echo "==> ERR signal received"; exit 1' ERR +# shellcheck disable=SC3041 +set -E + +# shellcheck disable=SC3045,SC3047 +ERR_TRAP_EXPECTED="$(trap -p ERR)" + +# Adding ` || die 'install failed'` implicitly disables error handling and +# prevents ERR trap execution, so for the purposes of this test, `nvm install` +# can't be part of another command or statement +nvm install node + +case "$-" in +*E*) + # shellcheck disable=SC3045,SC3047 + [ "$(trap -p ERR)" = "$ERR_TRAP_EXPECTED" ] || + die "ERR trap not restored after \"nvm install $VERSION\"" + ;; +*) + die "errtrace not restored after \"nvm install $VERSION\"" + ;; +esac From 1875fe8b40dbe69e2c5f7e6175cdc82a167eb072 Mon Sep 17 00:00:00 2001 From: Luke Arms Date: Sun, 26 Dec 2021 15:31:53 +1100 Subject: [PATCH 03/15] [Fix] avoid OpenBSD `nvm install` error when /sbin/init doesn't exist `nvm install` fails with "Binary download failed, trying source" when - running on Bash; - errtrace (`set -E`) is enabled; - an ERR trap uses `exit` to return a non-zero status; and - /sbin/init doesn't exist. Resolved by moving `ls -dl /sbin/init` to the following `if` statement. In this context, returning non-zero isn't an error and the ERR trap isn't executed. --- nvm.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nvm.sh b/nvm.sh index f40a9f3..bb61a71 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1870,10 +1870,12 @@ nvm_get_arch() { *) NVM_ARCH="${HOST_ARCH}" ;; esac - # If running a 64bit ARM kernel but a 32bit ARM userland, change ARCH to 32bit ARM (armv7l) + # If running a 64bit ARM kernel but a 32bit ARM userland, + # change ARCH to 32bit ARM (armv7l) if /sbin/init is 32bit executable local L - L=$(ls -dl /sbin/init 2>/dev/null) # if /sbin/init is 32bit executable - if [ "$(uname)" = "Linux" ] && [ "${NVM_ARCH}" = arm64 ] && [ "$(od -An -t x1 -j 4 -N 1 "${L#*-> }")" = ' 01' ]; then + if [ "$(uname)" = "Linux" ] && [ "${NVM_ARCH}" = arm64 ] && + L="$(ls -dl /sbin/init 2>/dev/null)" && + [ "$(od -An -t x1 -j 4 -N 1 "${L#*-> }")" = ' 01' ]; then NVM_ARCH=armv7l HOST_ARCH=armv7l fi From 6cfaede5a03cd4aa5d374d4c199bc1c18defa2e5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 27 Nov 2021 22:16:14 -0800 Subject: [PATCH 04/15] [Fix] `install`: better error message when xcode command line tools are needed Fixes #2697. Fixes #2663. --- install.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/install.sh b/install.sh index c3dc782..359d2de 100755 --- a/install.sh +++ b/install.sh @@ -356,6 +356,12 @@ nvm_do_install() { exit 1 fi fi + if nvm_has xcode-select && [ "$(xcode-select -p >/dev/null 2>/dev/null ; echo $?)" = '2' ] && [ "$(which git)" = '/usr/bin/git' ] && [ "$(which curl)" = '/usr/bin/curl' ]; then + nvm_echo >&2 'You may be on a Mac, and need to install the Xcode Command Line Developer Tools.' + # shellcheck disable=SC2016 + nvm_echo >&2 'If so, run `xcode-select --install` and try again. If not, please report this!' + exit 1 + fi if [ -z "${METHOD}" ]; then # Autodetect install method if nvm_has git; then From c2f740ab384a16f6ce8b50b2d545881beeedefe0 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 18 Jan 2022 12:49:57 -0800 Subject: [PATCH 05/15] [patch] HTTP -> HTTPS --- nvm.sh | 6 +++--- test/slow/nvm_get_latest/nvm_get_latest | 4 ++-- test/slow/nvm_get_latest/nvm_get_latest failed redirect | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/nvm.sh b/nvm.sh index bb61a71..e769fa5 100644 --- a/nvm.sh +++ b/nvm.sh @@ -101,15 +101,15 @@ nvm_get_latest() { if nvm_curl_use_compression; then CURL_COMPRESSED_FLAG="--compressed" fi - NVM_LATEST_URL="$(curl ${CURL_COMPRESSED_FLAG:-} -q -w "%{url_effective}\\n" -L -s -S http://latest.nvm.sh -o /dev/null)" + NVM_LATEST_URL="$(curl ${CURL_COMPRESSED_FLAG:-} -q -w "%{url_effective}\\n" -L -s -S https://latest.nvm.sh -o /dev/null)" elif nvm_has "wget"; then - NVM_LATEST_URL="$(wget -q http://latest.nvm.sh --server-response -O /dev/null 2>&1 | command awk '/^ Location: /{DEST=$2} END{ print DEST }')" + NVM_LATEST_URL="$(wget -q https://latest.nvm.sh --server-response -O /dev/null 2>&1 | command awk '/^ Location: /{DEST=$2} END{ print DEST }')" else nvm_err 'nvm needs curl or wget to proceed.' return 1 fi if [ -z "${NVM_LATEST_URL}" ]; then - nvm_err "http://latest.nvm.sh did not redirect to the latest release on GitHub" + nvm_err "https://latest.nvm.sh did not redirect to the latest release on GitHub" return 2 fi nvm_echo "${NVM_LATEST_URL##*/}" diff --git a/test/slow/nvm_get_latest/nvm_get_latest b/test/slow/nvm_get_latest/nvm_get_latest index 5311360..32b85e7 100755 --- a/test/slow/nvm_get_latest/nvm_get_latest +++ b/test/slow/nvm_get_latest/nvm_get_latest @@ -10,8 +10,8 @@ cleanup() { EXPECTED_VERSION="v12.3.456" URL="https://github.com/nvm-sh/nvm/releases/tag/$EXPECTED_VERSION" -EXPECTED_CURL_ARGS="--compressed -q -w %{url_effective}\n -L -s -S http://latest.nvm.sh -o /dev/null" -EXPECTED_WGET_ARGS="-q http://latest.nvm.sh --server-response -O /dev/null" +EXPECTED_CURL_ARGS="--compressed -q -w %{url_effective}\n -L -s -S https://latest.nvm.sh -o /dev/null" +EXPECTED_WGET_ARGS="-q https://latest.nvm.sh --server-response -O /dev/null" curl() { if [ $# -eq 1 ] && [ "$1" = "-V" ]; then diff --git a/test/slow/nvm_get_latest/nvm_get_latest failed redirect b/test/slow/nvm_get_latest/nvm_get_latest failed redirect index 97534e9..2548b06 100755 --- a/test/slow/nvm_get_latest/nvm_get_latest failed redirect +++ b/test/slow/nvm_get_latest/nvm_get_latest failed redirect @@ -17,7 +17,7 @@ wget() { OUTPUT="$(nvm_get_latest 2>&1)" EXIT_CODE="$(nvm_get_latest >/dev/null 2>&1 ; echo $?)" -[ "_$OUTPUT" = "_http://latest.nvm.sh did not redirect to the latest release on GitHub" ] \ +[ "_$OUTPUT" = "_https://latest.nvm.sh did not redirect to the latest release on GitHub" ] \ || die "failed redirect did not report correct error message, got '$OUTPUT'" [ "_$EXIT_CODE" = "_2" ] \ || die "failed redirect did not exit with code 2, got $EXIT_CODE" From 2c0c34f10e6f415d1c6f60c54fcbf53a7670dec6 Mon Sep 17 00:00:00 2001 From: Kai Date: Sun, 16 Jan 2022 14:25:11 +0100 Subject: [PATCH 06/15] [Docs] HTTP => HTTPS --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8346f0b..386481b 100644 --- a/README.md +++ b/README.md @@ -203,7 +203,7 @@ If you're running a system without prepackaged binary available, which means you **Note:** On OS X, if you do not have Xcode installed and you do not wish to download the ~4.3GB file, you can install the `Command Line Tools`. You can check out this blog post on how to just that: - - [How to Install Command Line Tools in OS X Mavericks & Yosemite (Without Xcode)](http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/) + - [How to Install Command Line Tools in OS X Mavericks & Yosemite (Without Xcode)](https://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x/) **Note:** On OS X, if you have/had a "system" node installed and want to install modules globally, keep in mind that: @@ -890,7 +890,7 @@ To change the user directory and/or account name follow the instructions [here]( [3]: https://travis-ci.org/nvm-sh/nvm [4]: https://github.com/nvm-sh/nvm/releases/tag/v0.39.1 [Urchin]: https://github.com/scraperwiki/urchin -[Fish]: http://fishshell.com +[Fish]: https://fishshell.com **Homebrew makes zsh directories unsecure** From 39d9a42c359df5dbf37c5000af8192f14a280b94 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 8 Feb 2022 10:40:11 -0800 Subject: [PATCH 07/15] [Fix] `install.sh`: error out if the install instructions are not followed --- install.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/install.sh b/install.sh index 359d2de..2bf513a 100755 --- a/install.sh +++ b/install.sh @@ -10,6 +10,12 @@ nvm_echo() { command printf %s\\n "$*" 2>/dev/null } +if [ -z "${BASH_VERSION}" ] || [ -n "${ZSH_VERSION}" ]; then + # shellcheck disable=SC2016 + nvm_echo >&2 'Error: the install instructions explicitly say to pipe the install script to `bash`; please follow them' + exit 1 +fi + nvm_grep() { GREP_OPTIONS='' command grep "$@" } From d157cac6891372df8d23b4c1d49ca1028d9c418e Mon Sep 17 00:00:00 2001 From: Antony Tse Date: Wed, 9 Mar 2022 09:41:48 +0000 Subject: [PATCH 08/15] [readme] Correct typos in "Macs with M1 chip" section --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 386481b..d16abce 100644 --- a/README.md +++ b/README.md @@ -931,7 +931,7 @@ Here's what you will need to do: If that's the case, make sure to source `nvm`. ```sh - $ source "${NVM_DIR}/.nvm/nvm.sh" + $ source "${NVM_DIR}/nvm.sh" ``` - Install whatever older version of node you are interested in. Let's use 12.22.1 as an example. From c367d7daa04ff86137205b80dab4b66c271515fa Mon Sep 17 00:00:00 2001 From: legendecas Date: Mon, 28 Mar 2022 23:28:53 +0800 Subject: [PATCH 09/15] [Docs] fix fish load_nvm variable interpolations --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d16abce..462e524 100644 --- a/README.md +++ b/README.md @@ -655,7 +655,7 @@ function load_nvm --on-variable="PWD" set -l nvmrc_node_version (nvm version (cat $nvmrc_path)) if test "$nvmrc_node_version" = "N/A" nvm install (cat $nvmrc_path) - else if test nvmrc_node_version != node_version + else if test "$nvmrc_node_version" != "$node_version" nvm use $nvmrc_node_version end else if test "$node_version" != "$default_node_version" From 7d86701067319c6ce866caa87c29ecd84ee9c864 Mon Sep 17 00:00:00 2001 From: Ponder Date: Fri, 1 Apr 2022 13:00:58 -0400 Subject: [PATCH 10/15] [readme] `fish`: send output from `load_nvm` to `/dev/stderr` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 462e524..22afcd8 100644 --- a/README.md +++ b/README.md @@ -666,7 +666,7 @@ end # ~/.config/fish/config.fish # You must call it on initialization or listening to directory switching won't work -load_nvm +load_nvm > /dev/stderr ``` ## Running Tests From 9e884b8d7b41a9245ae6e42d5ea56db7576b2784 Mon Sep 17 00:00:00 2001 From: deepakchethan Date: Tue, 22 Mar 2022 18:58:18 +0530 Subject: [PATCH 11/15] [Fix] `nvm install`: show proper version in `.nvmrc` install instructions --- nvm.sh | 23 +++++++++++---- .../Unit tests/nvm_ensure_version_installed | 13 +++++++-- ...ror out sensibly when 0.x is not installed | 4 +-- ...ng 'nvm run' should pick up .nvmrc version | 13 +++++++++ ...with nvmrc containing not intalled version | 28 +++++++++++++++++++ 5 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 test/slow/nvm use/Running 'nvm use' with nvmrc containing not intalled version diff --git a/nvm.sh b/nvm.sh index e769fa5..2d53d36 100644 --- a/nvm.sh +++ b/nvm.sh @@ -506,6 +506,8 @@ nvm_version_path() { nvm_ensure_version_installed() { local PROVIDED_VERSION PROVIDED_VERSION="${1-}" + local IS_VERSION_FROM_NVMRC + IS_VERSION_FROM_NVMRC="${2-}" if [ "${PROVIDED_VERSION}" = 'system' ]; then if nvm_has_system_iojs || nvm_has_system_node; then return 0 @@ -527,7 +529,11 @@ nvm_ensure_version_installed() { nvm_err "N/A: version \"${PREFIXED_VERSION:-$PROVIDED_VERSION}\" is not yet installed." fi nvm_err "" - nvm_err "You need to run \"nvm install ${PROVIDED_VERSION}\" to install it before using it." + if [ "${IS_VERSION_FROM_NVMRC}" != '1' ]; then + nvm_err "You need to run \`nvm install ${PROVIDED_VERSION}\` to install and use it." + else + nvm_err 'You need to run `nvm install` to install and use the node version specified in `.nvmrc`.' + fi return 1 fi } @@ -3522,6 +3528,8 @@ nvm() { local NVM_DELETE_PREFIX NVM_DELETE_PREFIX=0 local NVM_LTS + local IS_VERSION_FROM_NVMRC + IS_VERSION_FROM_NVMRC=0 while [ $# -ne 0 ]; do case "$1" in @@ -3549,6 +3557,7 @@ nvm() { NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version if [ -n "${NVM_RC_VERSION-}" ]; then PROVIDED_VERSION="${NVM_RC_VERSION}" + IS_VERSION_FROM_NVMRC=1 VERSION="$(nvm_version "${PROVIDED_VERSION}")" fi unset NVM_RC_VERSION @@ -3588,14 +3597,12 @@ nvm() { fi if [ "${VERSION}" = 'N/A' ]; then if [ "${NVM_SILENT:-0}" -ne 1 ]; then - nvm_err "N/A: version \"${PROVIDED_VERSION} -> ${VERSION}\" is not yet installed." - nvm_err "" - nvm_err "You need to run \"nvm install ${PROVIDED_VERSION}\" to install it before using it." + nvm_ensure_version_installed "${PROVIDED_VERSION}" "${IS_VERSION_FROM_NVMRC}" fi return 3 # This nvm_ensure_version_installed call can be a performance bottleneck # on shell startup. Perhaps we can optimize it away or make it faster. - elif ! nvm_ensure_version_installed "${VERSION}"; then + elif ! nvm_ensure_version_installed "${VERSION}" "${IS_VERSION_FROM_NVMRC}"; then return $? fi @@ -3650,6 +3657,8 @@ nvm() { local provided_version local has_checked_nvmrc has_checked_nvmrc=0 + local IS_VERSION_FROM_NVMRC + IS_VERSION_FROM_NVMRC=0 # run given version of node local NVM_SILENT @@ -3695,6 +3704,8 @@ nvm() { if [ $has_checked_nvmrc -ne 1 ]; then NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version && has_checked_nvmrc=1 fi + provided_version="${NVM_RC_VERSION}" + IS_VERSION_FROM_NVMRC=1 VERSION="$(nvm_version "${NVM_RC_VERSION}")" ||: unset NVM_RC_VERSION else @@ -3717,7 +3728,7 @@ nvm() { VERSION='' fi if [ "_${VERSION}" = "_N/A" ]; then - nvm_ensure_version_installed "${provided_version}" + nvm_ensure_version_installed "${provided_version}" "${IS_VERSION_FROM_NVMRC}" elif [ "${NVM_IOJS}" = true ]; then nvm exec "${NVM_SILENT_ARG-}" "${LTS_ARG-}" "${VERSION}" iojs "$@" else diff --git a/test/fast/Unit tests/nvm_ensure_version_installed b/test/fast/Unit tests/nvm_ensure_version_installed index e239e0e..4c51508 100755 --- a/test/fast/Unit tests/nvm_ensure_version_installed +++ b/test/fast/Unit tests/nvm_ensure_version_installed @@ -15,7 +15,16 @@ OUTPUT="$(nvm_ensure_version_installed foo 2>&1)" EXIT_CODE=$? EXPECTED_OUTPUT='N/A: version "foo" is not yet installed. -You need to run "nvm install foo" to install it before using it.' +You need to run `nvm install foo` to install and use it.' +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed foo' to give $EXPECTED_OUTPUT, got $OUTPUT" +[ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm_ensure_version_installed foo' to exit with 1, got $EXIT_CODE" + +# Case when .nvmrc file is opened, we should be skip showing the version +OUTPUT="$(nvm_ensure_version_installed foo 1 2>&1)" +EXIT_CODE=$? +EXPECTED_OUTPUT='N/A: version "foo" is not yet installed. + +You need to run `nvm install` to install and use the node version specified in `.nvmrc`.' [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed foo' to give $EXPECTED_OUTPUT, got $OUTPUT" [ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm_ensure_version_installed foo' to exit with 1, got $EXIT_CODE" @@ -29,7 +38,7 @@ OUTPUT="$(nvm_ensure_version_installed iojs 2>&1)" EXIT_CODE=$? EXPECTED_OUTPUT='N/A: version "iojs" is not yet installed. -You need to run "nvm install iojs" to install it before using it.' +You need to run `nvm install iojs` to install and use it.' [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed iojs' to give $EXPECTED_OUTPUT, got $OUTPUT" [ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm_ensure_version_installed iojs' to exit with 1, got $EXIT_CODE" diff --git a/test/slow/nvm run/Running 'nvm run 0.x' should error out sensibly when 0.x is not installed b/test/slow/nvm run/Running 'nvm run 0.x' should error out sensibly when 0.x is not installed index b9a2c2c..c38b428 100755 --- a/test/slow/nvm run/Running 'nvm run 0.x' should error out sensibly when 0.x is not installed +++ b/test/slow/nvm run/Running 'nvm run 0.x' should error out sensibly when 0.x is not installed @@ -7,10 +7,10 @@ die () { echo "$@" ; exit 1; } EXPECTED_OUTPUT='N/A: version "v0.2" is not yet installed. -You need to run "nvm install 0.2" to install it before using it.' +You need to run `nvm install 0.2` to install and use it.' [ "_$(nvm run 0.2 --version 2>&1)" = "_$EXPECTED_OUTPUT" ] || die "\`nvm run\` with an uninstalled node version failed to error out correctly" EXPECTED_OUTPUT='N/A: version "iojs-v0.2" is not yet installed. -You need to run "nvm install iojs-0.2" to install it before using it.' +You need to run `nvm install iojs-0.2` to install and use it.' [ "_$(nvm run iojs-0.2 --version 2>&1)" = "_$EXPECTED_OUTPUT" ] || die "\`nvm run\` with an uninstalled iojs version failed to error out correctly" diff --git a/test/slow/nvm run/Running 'nvm run' should pick up .nvmrc version b/test/slow/nvm run/Running 'nvm run' should pick up .nvmrc version index 3273ea0..a349689 100755 --- a/test/slow/nvm run/Running 'nvm run' should pick up .nvmrc version +++ b/test/slow/nvm run/Running 'nvm run' should pick up .nvmrc version @@ -10,3 +10,16 @@ echo "0.10.7" > .nvmrc [ "$(nvm run --version | tail -1)" = "v0.10.7" ] || die "\`nvm run\` failed to run with the .nvmrc version" [ "$(nvm run --version | head -1)" = "Found '$PWD/.nvmrc' with version <0.10.7>" ] || die "\`nvm run\` failed to print out the \"found in .nvmrc\" message" + + +echo "foo" > .nvmrc + +# running nvm run with .nvmrc should not print the version information when not installed +OUTPUT="$(nvm run --version 2>&1)" +EXIT_CODE=$? +EXPECTED_OUTPUT="Found '$PWD/.nvmrc' with version +N/A: version \"foo\" is not yet installed. + +You need to run \`nvm install\` to install and use the node version specified in \`.nvmrc\`." +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm use' with nvmrc to give $EXPECTED_OUTPUT, got $OUTPUT" +[ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm use' with nvmrc to exit with 1, got $EXIT_CODE" diff --git a/test/slow/nvm use/Running 'nvm use' with nvmrc containing not intalled version b/test/slow/nvm use/Running 'nvm use' with nvmrc containing not intalled version new file mode 100644 index 0000000..122aa96 --- /dev/null +++ b/test/slow/nvm use/Running 'nvm use' with nvmrc containing not intalled version @@ -0,0 +1,28 @@ +#!/bin/sh + +die () { echo "$@" ; exit 1; } + +\. ../../../nvm.sh + +nvm deactivate 2>&1 >/dev/null || die 'deactivate failed' + +echo "foo" > .nvmrc + +# running nvm use with .nvmrc should not print the version information +OUTPUT="$(nvm use 2>&1)" +EXIT_CODE=$? +EXPECTED_OUTPUT="Found '$PWD/.nvmrc' with version +N/A: version \"foo\" is not yet installed. + +You need to run \`nvm install\` to install and use the node version specified in \`.nvmrc\`." +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm use' with nvmrc to give $EXPECTED_OUTPUT, got $OUTPUT" +[ "_$EXIT_CODE" = "_3" ] || die "expected 'nvm use' with nvmrc to exit with 3, got $EXIT_CODE" + +# --silent should not print anything +OUTPUT=$(nvm use --silent) +EXPECTED_OUTPUT="" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ + || die "'nvm use --silent' output was not silenced to '$EXPECTED_OUTPUT'; got '$OUTPUT'" + +rm .nvmrc From bd083ff367002bbfe526f434bc2698a1850c1d47 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 11 Apr 2022 14:09:37 -0700 Subject: [PATCH 12/15] [readme] minor cleanup --- README.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 22afcd8..dd449ab 100644 --- a/README.md +++ b/README.md @@ -459,7 +459,7 @@ nvm set-colors rgBcm #### Persisting custom colors -If you want the custom colors to persist after terminating the shell, export the NVM_COLORS variable in your shell profile. For example, if you want to use cyan, magenta, green, bold red and bold yellow, add the following line: +If you want the custom colors to persist after terminating the shell, export the `NVM_COLORS` variable in your shell profile. For example, if you want to use cyan, magenta, green, bold red and bold yellow, add the following line: ```sh export NVM_COLORS='cmgRY' @@ -718,36 +718,36 @@ Put the above sourcing line just below the sourcing line for nvm in your profile ### Usage nvm: -> $ nvm Tab -``` +> `$ nvm` Tab +```sh alias deactivate install list-remote reinstall-packages uninstall version cache exec install-latest-npm ls run unload version-remote current help list ls-remote unalias use which ``` nvm alias: -> $ nvm alias Tab -``` +> `$ nvm alias` Tab +```sh default iojs lts/* lts/argon lts/boron lts/carbon lts/dubnium lts/erbium node stable unstable ``` -> $ nvm alias my_alias Tab -``` +> `$ nvm alias my_alias` Tab +```sh v10.22.0 v12.18.3 v14.8.0 ``` nvm use: -> $ nvm use Tab +> `$ nvm use` Tab ``` my_alias default v10.22.0 v12.18.3 v14.8.0 ``` nvm uninstall: -> $ nvm uninstall Tab +> `$ nvm uninstall` Tab ``` my_alias default v10.22.0 v12.18.3 v14.8.0 @@ -779,7 +779,7 @@ set -e ## Installing nvm on Alpine Linux -In order to provide the best performance (and other optimisations), nvm will download and install pre-compiled binaries for Node (and npm) when you run `nvm install X`. The Node project compiles, tests and hosts/provides these pre-compiled binaries which are built for mainstream/traditional Linux distributions (such as Debian, Ubuntu, CentOS, RedHat et al). +In order to provide the best performance (and other optimizations), nvm will download and install pre-compiled binaries for Node (and npm) when you run `nvm install X`. The Node project compiles, tests and hosts/provides these pre-compiled binaries which are built for mainstream/traditional Linux distributions (such as Debian, Ubuntu, CentOS, RedHat et al). Alpine Linux, unlike mainstream/traditional Linux distributions, is based on [BusyBox](https://www.busybox.net/), a very compact (~5MB) Linux distribution. BusyBox (and thus Alpine Linux) uses a different C/C++ stack to most mainstream/traditional Linux distributions - [musl](https://www.musl-libc.org/). This makes binary programs built for such mainstream/traditional incompatible with Alpine Linux, thus we cannot simply `nvm install X` on Alpine Linux and expect the downloaded binary to run correctly - you'll likely see "...does not exist" errors if you try that. @@ -906,7 +906,7 @@ Homebrew causes insecure directories like `/usr/local/share/zsh/site-functions` Experimental support for the M1 architecture was added in node.js v15.3 and full support was added in v16.0. Because of this, if you try to install older versions of node as usual, you will probably experience either compilation errors when installing node or out-of-memory errors while running your code. -So, if you want to run a version prior to v16.0 on an M1 Mac, it may be best to compile node targeting the x86_64 Intel architecture so that Rosetta 2 can translate the x86_64 processor instructions to ARM-based Apple Silicon instructions. +So, if you want to run a version prior to v16.0 on an M1 Mac, it may be best to compile node targeting the `x86_64` Intel architecture so that Rosetta 2 can translate the `x86_64` processor instructions to ARM-based Apple Silicon instructions. Here's what you will need to do: - Install Rosetta, if you haven't already done so @@ -959,7 +959,7 @@ Here's what you will need to do: Note: If you selected the box labeled "Open using Rosetta" rather than running the CLI command in the second step, you will see `i386` here. Unless you have another reason to have that box selected, you can deselect it now. -- Check to make sure the architecture is correct. `x64` is the abbreviation for x86_64, which is what you want to see. +- Check to make sure the architecture is correct. `x64` is the abbreviation for `x86_64`, which is what you want to see. ```sh $ node -p process.arch From 01886b4243531c78360cafd0e938888a58c570fa Mon Sep 17 00:00:00 2001 From: Dani Schuhman Date: Fri, 15 Apr 2022 10:56:26 -0400 Subject: [PATCH 13/15] [meta] Update CODE_OF_CONDUCT to current version --- CODE_OF_CONDUCT.md | 133 ++++++++++++++++++++++++++------------------- 1 file changed, 76 insertions(+), 57 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index cad8e65..e531bd4 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,9 +1,9 @@ # Code of Conduct -`nvm`, as a member project of the OpenJS Foundation, uses [Contributor Covenant v1.4](https://www.contributor-covenant.org/version/1/4/code-of-conduct) as their code of conduct. The full text is included [below](#contributor-covenant-code-of-conduct) in English, and translations are available from the Contributor Covenant organisation: +`nvm`, as a member project of the OpenJS Foundation, uses [Contributor Covenant v2.1](https://www.contributor-covenant.org/version/2/1/code_of_conduct/) as their code of conduct. The full text is included [below](#contributor-covenant-code-of-conduct) in English, and translations are available from the Contributor Covenant organisation: - [contributor-covenant.org/translations](https://www.contributor-covenant.org/translations) -- [github.com/ContributorCovenant](https://github.com/ContributorCovenant/contributor_covenant/tree/release/content/version/1/4) +- [github.com/ContributorCovenant](https://github.com/ContributorCovenant/contributor_covenant/tree/release/content/version/2/1) Refer to the sections on reporting and escalation in this document for the specific emails that can be used to report and escalate issues. @@ -14,93 +14,112 @@ Refer to the sections on reporting and escalation in this document for the speci For reporting issues in spaces related to `nvm` please use the email `ljharb@gmail.com`. `nvm` handles CoC issues related to the spaces that it maintains. Projects maintainers commit to: - maintain the confidentiality with regard to the reporter of an incident -- to participate in the path for escalation as outlined in - the section on Escalation when required. +- to participate in the path for escalation as outlined in the section on Escalation when required. ### Foundation Spaces -For reporting issues in spaces managed by the OpenJS Foundation, for example, repositories within the OpenJS organization, use the email `report@lists.openjsf.org`. The Cross Project Council (CPC) is responsible for managing these reports and commits to: +For reporting issues in spaces managed by the OpenJS Foundation, for example, repositories within the OpenJS organization, use the email `report@lists.openjsf.org`. +The Cross Project Council (CPC) is responsible for managing these reports and commits to: - maintain the confidentiality with regard to the reporter of an incident -- to participate in the path for escalation as outlined in - the section on Escalation when required. +- to participate in the path for escalation as outlined in the section on Escalation when required. ## Escalation -The OpenJS Foundation maintains a Code of Conduct Panel (CoCP). This is a foundation-wide team established to manage escalation when a reporter believes that a report to a member project or the CPC has not been properly handled. In order to escalate to the CoCP send an email to `coc-escalation@lists.openjsf.org`. +The OpenJS Foundation maintains a Code of Conduct Panel (CoCP). +This is a foundation-wide team established to manage escalation when a reporter believes that a report to a member project or the CPC has not been properly handled. +In order to escalate to the CoCP send an email to `coc-escalation@lists.openjsf.org`. For more information, refer to the full [Code of Conduct governance document](https://github.com/openjs-foundation/cross-project-council/blob/master/CODE_OF_CONDUCT.md). --- -## Contributor Covenant Code of Conduct +# Contributor Covenant Code of Conduct -### Our Pledge +## Our Pledge -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation. -### Our Standards +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. -Examples of behavior that contributes to creating a positive environment include: +## Our Standards -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members +Examples of behavior that contributes to a positive environment for our community include: -Examples of unacceptable behavior by participants include: +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall community -* The use of sexualized language or imagery and unwelcome sexual attention or advances -* Trolling, insulting/derogatory comments, and personal or political attacks +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment -* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Publishing others' private information, such as a physical or email address, without their explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting -### Our Responsibilities +## Enforcement Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions -that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. -### Scope +## Scope -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. -### Enforcement +## Enforcement -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at the email addresses listed above in -the [Reporting](#reporting) and [Escalation](#escalation) sections. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an -incident. Further details of specific enforcement policies may be posted -separately. +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at [@ljharb](ljharb@gmail.com). +All complaints will be reviewed and investigated promptly and fairly. -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. +All community leaders are obligated to respect the privacy and security of the reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of actions. + +**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the community. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [https://www.contributor-covenant.org/version/1/4/code-of-conduct/](https://www.contributor-covenant.org/version/1/4/code-of-conduct/) +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at +[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. + +Community Impact Guidelines were inspired by +[Mozilla's code of conduct enforcement ladder][Mozilla CoC]. + +For answers to common questions about this code of conduct, see the FAQ at +[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at +[https://www.contributor-covenant.org/translations][translations]. [homepage]: https://www.contributor-covenant.org +[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html +[Mozilla CoC]: https://github.com/mozilla/diversity +[FAQ]: https://www.contributor-covenant.org/faq +[translations]: https://www.contributor-covenant.org/translations From ef3b20c21ec6e88a3f979994d1ca16dcdb9efb0a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 22 Apr 2022 16:53:49 -0700 Subject: [PATCH 14/15] [readme] add logo --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index dd449ab..c653c50 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +nvm project logo + # Node Version Manager [![Build Status](https://travis-ci.org/nvm-sh/nvm.svg?branch=master)][3] [![nvm version](https://img.shields.io/badge/version-v0.39.1-yellow.svg)][4] [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/684/badge)](https://bestpractices.coreinfrastructure.org/projects/684) From a82edf40ba72a15b1d40822735942141547f38e2 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 2 Jun 2022 12:25:55 -0700 Subject: [PATCH 15/15] [Robustness] avoid a clobbered `ls` Fixes #2824 --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 2d53d36..ede616e 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1880,7 +1880,7 @@ nvm_get_arch() { # change ARCH to 32bit ARM (armv7l) if /sbin/init is 32bit executable local L if [ "$(uname)" = "Linux" ] && [ "${NVM_ARCH}" = arm64 ] && - L="$(ls -dl /sbin/init 2>/dev/null)" && + L="$(command ls -dl /sbin/init 2>/dev/null)" && [ "$(od -An -t x1 -j 4 -N 1 "${L#*-> }")" = ' 01' ]; then NVM_ARCH=armv7l HOST_ARCH=armv7l