From 86708833c911dd01597d43f2dc4570b35f1d9aaa Mon Sep 17 00:00:00 2001 From: Keith Lazuka Date: Tue, 8 Dec 2020 12:28:24 -0500 Subject: [PATCH 1/4] [Fix] Use local variable when looping over args When the `nvm` function is called by a script which itself uses a variable named `i`, `nvm` clobbers the caller's variable. This happens even if the caller has declared its variable as local. See note 1 on https://tldp.org/LDP/abs/html/localvar.html#FTN.AEN18568 --- nvm.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/nvm.sh b/nvm.sh index 5a27ae6..2e85e6a 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2554,6 +2554,7 @@ nvm() { return $? fi + local i for i in "$@" do case $i in From e48cb858a69e7a62f6b9230d0c9ce916339e12cd Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Wed, 2 Oct 2019 15:05:36 -0400 Subject: [PATCH 2/4] [Tests] `.npm` is now cached by default --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a04fac1..7e991ed 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,6 @@ addons: cache: ccache: true directories: - - $HOME/.npm - $TRAVIS_BUILD_DIR/.cache - $TRAVIS_BUILD_DIR/node_modules before_install: From e76b2945c59727ed69edcdb5d2830af96c630b07 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 21 Dec 2020 23:03:30 -0800 Subject: [PATCH 3/4] [Fix] relax `$PREFIX` checking, to accomodate `npm exec` Fixes #2379. --- nvm.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 2e85e6a..4646dd9 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2338,7 +2338,8 @@ nvm_die_on_prefix() { # npm first looks at $PREFIX (case-sensitive) # we do not bother to test the value here; if this env var is set, unset it to continue. - if [ -n "${PREFIX-}" ]; then + # however, `npm exec` in npm v7.2+ sets $PREFIX; if set, inherit it + if [ -n "${PREFIX-}" ] && [ "$(nvm_version_path $(node -v))" != "${PREFIX}" ]; then nvm deactivate >/dev/null 2>&1 nvm_err "nvm is not compatible with the \"PREFIX\" environment variable: currently set to \"${PREFIX}\"" nvm_err 'Run `unset PREFIX` to unset it.' From 3c079f16c7f4721c13e97a35c4a7faf3cfcf2d8d Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 21 Dec 2020 23:47:25 -0800 Subject: [PATCH 4/4] [shellcheck] fix silly shellcheck complaint --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 4646dd9..2f59708 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2339,7 +2339,7 @@ nvm_die_on_prefix() { # npm first looks at $PREFIX (case-sensitive) # we do not bother to test the value here; if this env var is set, unset it to continue. # however, `npm exec` in npm v7.2+ sets $PREFIX; if set, inherit it - if [ -n "${PREFIX-}" ] && [ "$(nvm_version_path $(node -v))" != "${PREFIX}" ]; then + if [ -n "${PREFIX-}" ] && [ "$(nvm_version_path "$(node -v)")" != "${PREFIX}" ]; then nvm deactivate >/dev/null 2>&1 nvm_err "nvm is not compatible with the \"PREFIX\" environment variable: currently set to \"${PREFIX}\"" nvm_err 'Run `unset PREFIX` to unset it.'