From e7b53a01fd879f46e6c2dce9b46f4a452fcdffd8 Mon Sep 17 00:00:00 2001 From: Jay Williams Date: Sat, 26 May 2018 23:17:08 +0100 Subject: [PATCH 01/24] Grammar update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 080d4b2..f9ffe0f 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ command -v nvm ``` simply close your current terminal, open a new terminal, and try verifying again. -**Note:** Since OS X 10.9, `/usr/bin/git` was preset by Xcode command line tools, which caused Git can't be properly detected if it's installed or not. You need to manually install the Xcode command line tools before running the install script, otherwise, it'll fail. (see [#1782](https://github.com/creationix/nvm/issues/1782)) +**Note:** Since OS X 10.9, `/usr/bin/git` has been preset by Xcode command line tools, which means we can't properly detect if Git is installed or not. You need to manually install the Xcode command line tools before running the install script, otherwise, it'll fail. (see [#1782](https://github.com/creationix/nvm/issues/1782)) **Note:** On OS X, if you get `nvm: command not found` after running the install script, one of the following might be the reason:- - your system may not have a [`.bash_profile file`] where the command is set up. Simply create one with `touch ~/.bash_profile` and run the install script again From d08d8607f5bc3aed6705a1244b4f39fee61ca71c Mon Sep 17 00:00:00 2001 From: SrHuevo Date: Wed, 30 May 2018 09:02:29 +0200 Subject: [PATCH 02/24] fix for .nvmrc script --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f9ffe0f..96e0782 100644 --- a/README.md +++ b/README.md @@ -378,7 +378,7 @@ load-nvmrc() { if [ "$nvmrc_node_version" = "N/A" ]; then nvm install - elif [ "$nvmrc_node_version" = "$node_version" ]; then + elif [ "$nvmrc_node_version" != "$node_version" ]; then nvm use fi elif [ "$node_version" != "$(nvm version default)" ]; then From 628d4fac8448197444ed39f5bcba481d08cf777b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 31 May 2018 23:49:15 -0700 Subject: [PATCH 03/24] =?UTF-8?q?[shellcheck]=20use=20`{=20=E2=80=A6;=20}`?= =?UTF-8?q?=20instead=20of=20`(=E2=80=A6)`=20to=20group=20test=20commands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nvm.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nvm.sh b/nvm.sh index 8972e2a..96873fa 100644 --- a/nvm.sh +++ b/nvm.sh @@ -533,9 +533,9 @@ nvm_remote_versions() { NVM_LS_REMOTE_IOJS_EXIT_CODE=0 local NVM_LS_REMOTE_IOJS_OUTPUT NVM_LS_REMOTE_IOJS_OUTPUT='' - if [ -z "${NVM_LTS-}" ] && ( \ - [ -z "${NVM_FLAVOR-}" ] || [ "${NVM_FLAVOR-}" = "${NVM_IOJS_PREFIX}" ] \ - ); then + if [ -z "${NVM_LTS-}" ] && { + [ -z "${NVM_FLAVOR-}" ] || [ "${NVM_FLAVOR-}" = "${NVM_IOJS_PREFIX}" ]; + }; then NVM_LS_REMOTE_IOJS_OUTPUT=$(nvm_ls_remote_iojs "${PATTERN-}") &&: NVM_LS_REMOTE_IOJS_EXIT_CODE=$? fi @@ -783,14 +783,14 @@ nvm_list_aliases() { local ALIAS_NAME for ALIAS_NAME in "$(nvm_node_prefix)" "stable" "unstable"; do { - if [ ! -f "${NVM_ALIAS_DIR}/${ALIAS_NAME}" ] && ([ -z "${ALIAS}" ] || [ "${ALIAS_NAME}" = "${ALIAS}" ]); then + if [ ! -f "${NVM_ALIAS_DIR}/${ALIAS_NAME}" ] && { [ -z "${ALIAS}" ] || [ "${ALIAS_NAME}" = "${ALIAS}" ]; }; then NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "${ALIAS_NAME}" fi } & done wait ALIAS_NAME="$(nvm_iojs_prefix)" - if [ ! -f "${NVM_ALIAS_DIR}/${ALIAS_NAME}" ] && ([ -z "${ALIAS}" ] || [ "${ALIAS_NAME}" = "${ALIAS}" ]); then + if [ ! -f "${NVM_ALIAS_DIR}/${ALIAS_NAME}" ] && { [ -z "${ALIAS}" ] || [ "${ALIAS_NAME}" = "${ALIAS}" ]; }; then NVM_NO_COLORS="${NVM_NO_COLORS-}" NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "${ALIAS_NAME}" fi ) | sort From c50ea6f0a387357944e208c7af62f8da717d43a9 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 31 May 2018 23:56:20 -0700 Subject: [PATCH 04/24] [shellcheck] quote variables in for loops to avoid unintentional expansion --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 96873fa..5d488fe 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2316,7 +2316,7 @@ nvm_check_file_permissions() { ZSH_HAS_NONOMATCH_UNSET="$(set +e ; setopt | nvm_grep -q nonomatch ; nvm_echo $?)" setopt nonomatch fi - for FILE in $1/* $1/.[!.]* $1/..?* ; do + for FILE in "$1"/* "$1"/.[!.]* "$1"/..?* ; do if [ -d "$FILE" ]; then if ! nvm_check_file_permissions "$FILE"; then if [ "${ZSH_HAS_NONOMATCH_UNSET}" -eq 1 ] && nvm_has "setopt"; then From 9854928ba9ff6f24360207fa90135574746838f5 Mon Sep 17 00:00:00 2001 From: Spike Grobstein Date: Thu, 3 May 2018 08:22:07 -0700 Subject: [PATCH 05/24] [New] `install.sh`: allow user to explicitly opt out of nvm adding the source string this is done by checking if the user supplies `PROFILE=/dev/null` when running `install.sh`, the `nvm_detect_profile` function will not output any strings, causing `nvm_do_install` to skip adding `SOURCE_STR`. --- install.sh | 5 +++++ test/install_script/nvm_detect_profile | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/install.sh b/install.sh index 77f7f31..7bf62df 100755 --- a/install.sh +++ b/install.sh @@ -212,6 +212,11 @@ nvm_try_profile() { # Otherwise, an empty string is returned # nvm_detect_profile() { + if [ "${PROFILE-}" = '/dev/null' ]; then + # the user has specifically requested NOT to have nvm touch their profile + return + fi + if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then echo "${PROFILE}" return diff --git a/test/install_script/nvm_detect_profile b/test/install_script/nvm_detect_profile index 1044659..54815ec 100755 --- a/test/install_script/nvm_detect_profile +++ b/test/install_script/nvm_detect_profile @@ -28,6 +28,12 @@ setup # Confirm profile detection via $SHELL works and that $PROFILE overrides profile detection # +# setting $PROFILE to /dev/null should return no detected profile +NVM_DETECT_PROFILE="$(PROFILE='/dev/null'; nvm_detect_profile)" +if [ -n "$NVM_DETECT_PROFILE" ]; then + die "nvm_detect_profile still detected a profile even though PROFILE=/dev/null" +fi + # .bashrc should be detected for bash NVM_DETECT_PROFILE="$(BASH_VERSION="1"; unset PROFILE; nvm_detect_profile)" if [ "$NVM_DETECT_PROFILE" != "$HOME/.bashrc" ]; then From b111436fde25e0a0fe2f3392c6199df6c2bc603e Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 6 Jun 2018 22:49:56 -0700 Subject: [PATCH 06/24] [Tests] test `nvm install-latest-npm` on io.js v2 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 4fcfe5e..6c32943 100644 --- a/.travis.yml +++ b/.travis.yml @@ -89,3 +89,4 @@ env: - NODE=4.6 TEST="nvm install-latest-npm" - NODE=4.5 TEST="nvm install-latest-npm" - NODE=4.4 TEST="nvm install-latest-npm" + - NODE=2 TEST="nvm install-latest-npm" From eabd7ab13d4823928fd61629c32c9bf14accdeb2 Mon Sep 17 00:00:00 2001 From: Xandor Schiefer Date: Mon, 14 Nov 2016 19:18:24 +0200 Subject: [PATCH 07/24] Respect previously nvm-loaded node version when sourcing --- nvm.sh | 16 ++++++++++----- ...vm.sh should keep version if one is active | 20 +++++++++++++++++++ ...lt if available and no nvm node is loaded} | 19 ++++++++++++++---- test/sourcing/setup | 1 + test/sourcing/teardown | 1 + 5 files changed, 48 insertions(+), 9 deletions(-) create mode 100755 test/sourcing/Sourcing nvm.sh should keep version if one is active rename test/sourcing/{Sourcing nvm.sh should use the default if available => Sourcing nvm.sh should use the default if available and no nvm node is loaded} (53%) diff --git a/nvm.sh b/nvm.sh index 5d488fe..d854605 100644 --- a/nvm.sh +++ b/nvm.sh @@ -3606,6 +3606,8 @@ nvm_supports_xz() { } nvm_auto() { + local NVM_CURRENT + NVM_CURRENT="$(nvm_ls_current)" local NVM_MODE NVM_MODE="${1-}" local VERSION @@ -3617,11 +3619,15 @@ nvm_auto() { nvm install >/dev/null fi elif [ "_$NVM_MODE" = '_use' ]; then - VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)" - if [ -n "$VERSION" ]; then - nvm use --silent "$VERSION" >/dev/null - elif nvm_rc_version >/dev/null 2>&1; then - nvm use --silent >/dev/null + if [ "_${NVM_CURRENT}" = '_none' ] || [ "_${NVM_CURRENT}" = '_system' ]; then + VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)" + if [ -n "${VERSION}" ]; then + nvm use --silent "${VERSION}" >/dev/null + elif nvm_rc_version >/dev/null 2>&1; then + nvm use --silent >/dev/null + fi + else + nvm use --silent "${NVM_CURRENT}" >/dev/null fi elif [ "_$NVM_MODE" != '_none' ]; then nvm_err 'Invalid auto mode supplied.' diff --git a/test/sourcing/Sourcing nvm.sh should keep version if one is active b/test/sourcing/Sourcing nvm.sh should keep version if one is active new file mode 100755 index 0000000..4254159 --- /dev/null +++ b/test/sourcing/Sourcing nvm.sh should keep version if one is active @@ -0,0 +1,20 @@ +#!/bin/sh + +die () { echo "$@" ; exit 1; } + +echo '0.10.1' > ../../alias/default || die "couldn't create default alias" + +\. ../../nvm.sh || die 'sourcing returned nonzero exit code' + +NVM_TARGET=0.10.3 +NVM_DEFAULT="$(nvm_resolve_local_alias default)" + +[ "_$NVM_DEFAULT" != "_$NVM_TARGET" ] || die "default $NVM_DEFAULT is the same as target $NVM_TARGET" + +nvm use $NVM_TARGET || die "nvm use $NVM_TARGET failed" + +\. ../../nvm.sh || die 'sourcing returned nonzero exit code' + +NVM_CURRENT="$(nvm current)" + +[ "_${NVM_CURRENT#v}" = "_$NVM_TARGET" ] || die "node version not retained after sourcing" diff --git a/test/sourcing/Sourcing nvm.sh should use the default if available b/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded similarity index 53% rename from test/sourcing/Sourcing nvm.sh should use the default if available rename to test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded index 67e3048..fe837f2 100755 --- a/test/sourcing/Sourcing nvm.sh should use the default if available +++ b/test/sourcing/Sourcing nvm.sh should use the default if available and no nvm node is loaded @@ -2,13 +2,24 @@ die () { echo "$@" ; exit 1; } -echo '0.10.1' > ../../alias/default || die 'creation of default alias failed' - -\. ../../nvm.sh || die 'sourcing returned nonzero exit code' \. ../common.sh +# We need to unload nvm again first, as by the time this test is run, +# despite being unloaded in setup, the inherited PATH still contains +# an nvm-installed node version. We have to reset NVM_DIR after the unload. +\. ../../nvm.sh || die 'sourcing returned nonzero exit code' +NVM_DIR_CACHED="$NVM_DIR" +nvm unload || die 'unloading returned nonzero exit code' +NVM_DIR="$NVM_DIR_CACHED" + +echo '0.10.1' > ../../alias/default || die 'creation of default alias failed' + +# Now to begin the real test +\. ../../nvm.sh || die 'sourcing returned nonzero exit code' + +NVM_LS_CURRENT_NOT_GREPPED="$(nvm ls current | strip_colors)" NVM_LS_CURRENT="$(nvm ls current | strip_colors | \grep -o v0.10.1)" -[ "_$NVM_LS_CURRENT" = '_v0.10.1' ] || die "'nvm ls current' did not return '-> v0.10.1', got '$NVM_LS_CURRENT'" +[ "_$NVM_LS_CURRENT" = '_v0.10.1' ] || die "'nvm ls current' did not return '-> v0.10.1', got '$NVM_LS_CURRENT_NOT_GREPPED'" # NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)" diff --git a/test/sourcing/setup b/test/sourcing/setup index 44b688e..a7f6be8 100755 --- a/test/sourcing/setup +++ b/test/sourcing/setup @@ -9,5 +9,6 @@ rm -rf ../../v0.9.12 \. ../../nvm.sh nvm install 0.10.1 || echo >&2 'nvm install 0.10.1 failed' +nvm install 0.10.3 || echo >&2 'nvm install 0.10.3 failed' nvm unalias default || 'removing default alias failed' nvm unload || echo >&2 'nvm unload failed' diff --git a/test/sourcing/teardown b/test/sourcing/teardown index 00a8749..9bb52b0 100755 --- a/test/sourcing/teardown +++ b/test/sourcing/teardown @@ -3,4 +3,5 @@ rm -rf ../../alias rm -rf ../../v0.10.1 rm -rf ../../v0.10.2 +rm -rf ../../v0.10.3 rm -f ../../.nvmrc From a5f42d9cea7f9d13b38a9df9007ec3849483edf1 Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Wed, 13 Jun 2018 10:38:19 -0700 Subject: [PATCH 08/24] [Tests] update most mkdirs to use make_fake_{node,iojs} --- ... instead of implicit aliases when present" | 6 +-- ....0.2\" should display only version 0.0.2." | 7 ++-- ....0.2\" should display only version 0.0.2." | 5 ++- ...0.2\" should display only 0.2.x versions." | 7 ++-- ...uld return the appropriate implicit alias" | 13 ++++--- ...hould include \"system\" when appropriate" | 13 ++++--- ...\" should display all installed versions." | 39 ++++++++++--------- ...ing \"nvm ls\" should filter out \".nvm\"" | 5 ++- ...\"nvm ls\" should filter out \"versions\"" | 6 +-- ...hould include \"system\" when appropriate" | 13 ++++--- ...st versions in the \"versions\" directory" | 5 ++- ...vx.x.x should only list a matched version" | 3 +- .../Using a nonstandard IFS should not break | 21 +++++----- test/fast/Listing versions/teardown | 1 + ...-packages-from\" requires a valid version" | 3 +- ...create and change the \"current\" symlink" | 9 +++-- ... symlink if $NVM_SYMLINK_CURRENT is false" | 5 ++- .../Unit tests/nvm_ensure_version_installed | 3 +- test/fast/Unit tests/nvm_has_system_iojs | 9 ++--- test/fast/Unit tests/nvm_has_system_node | 6 +-- .../nvm_print_implicit_alias success | 18 +++++---- 21 files changed, 107 insertions(+), 90 deletions(-) diff --git "a/test/fast/Aliases/Running \"nvm alias\" lists manual aliases instead of implicit aliases when present" "b/test/fast/Aliases/Running \"nvm alias\" lists manual aliases instead of implicit aliases when present" index 25871fd..1857f44 100755 --- "a/test/fast/Aliases/Running \"nvm alias\" lists manual aliases instead of implicit aliases when present" +++ "b/test/fast/Aliases/Running \"nvm alias\" lists manual aliases instead of implicit aliases when present" @@ -14,9 +14,9 @@ cleanup () { rm -rf "${NVM_DIR}/versions/io.js/v0.2.1" } -mkdir "${NVM_DIR}/v0.8.1" -mkdir "${NVM_DIR}/v0.9.1" -mkdir -p "${NVM_DIR}/versions/io.js/v0.2.1" +make_fake_node v0.8.1 +make_fake_node v0.9.1 +make_fake_iojs v0.2.1 EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" diff --git "a/test/fast/Listing paths/Running \"nvm which 0.0.2\" should display only version 0.0.2." "b/test/fast/Listing paths/Running \"nvm which 0.0.2\" should display only version 0.0.2." index adbdb8c..1f4eb11 100755 --- "a/test/fast/Listing paths/Running \"nvm which 0.0.2\" should display only version 0.0.2." +++ "b/test/fast/Listing paths/Running \"nvm which 0.0.2\" should display only version 0.0.2." @@ -1,10 +1,11 @@ #!/bin/sh \. ../../../nvm.sh +\. ../../common.sh -mkdir -p "${NVM_DIR}/v0.0.2" -mkdir -p "${NVM_DIR}/v0.0.20" -mkdir -p "${NVM_DIR}/versions/node/v0.12.0" +make_fake_node v0.0.2 +make_fake_node v0.0.20 +make_fake_node v0.12.0 die () { echo "$@" ; exit 1; } diff --git "a/test/fast/Listing versions/Running \"nvm ls 0.0.2\" should display only version 0.0.2." "b/test/fast/Listing versions/Running \"nvm ls 0.0.2\" should display only version 0.0.2." index faed0a6..666a3f0 100755 --- "a/test/fast/Listing versions/Running \"nvm ls 0.0.2\" should display only version 0.0.2." +++ "b/test/fast/Listing versions/Running \"nvm ls 0.0.2\" should display only version 0.0.2." @@ -1,9 +1,10 @@ #!/bin/sh \. ../../../nvm.sh +\. ../../common.sh -mkdir "${NVM_DIR}/v0.0.2" -mkdir "${NVM_DIR}/v0.0.20" +make_fake_node v0.0.2 +make_fake_node v0.0.20 die () { echo "$@" ; exit 1; } diff --git "a/test/fast/Listing versions/Running \"nvm ls 0.2\" should display only 0.2.x versions." "b/test/fast/Listing versions/Running \"nvm ls 0.2\" should display only 0.2.x versions." index edddf01..b02efa3 100755 --- "a/test/fast/Listing versions/Running \"nvm ls 0.2\" should display only 0.2.x versions." +++ "b/test/fast/Listing versions/Running \"nvm ls 0.2\" should display only 0.2.x versions." @@ -1,10 +1,11 @@ #!/bin/sh \. ../../../nvm.sh +\. ../../common.sh -mkdir "${NVM_DIR}/v0.1.3" -mkdir "${NVM_DIR}/v0.2.3" -mkdir "${NVM_DIR}/v0.20.3" +make_fake_node v0.1.3 +make_fake_node v0.2.3 +make_fake_node v0.20.3 die () { echo "$@" ; exit 1; } diff --git "a/test/fast/Listing versions/Running \"nvm ls stable\" and \"nvm ls unstable\" should return the appropriate implicit alias" "b/test/fast/Listing versions/Running \"nvm ls stable\" and \"nvm ls unstable\" should return the appropriate implicit alias" index 61e890a..78d0a50 100755 --- "a/test/fast/Listing versions/Running \"nvm ls stable\" and \"nvm ls unstable\" should return the appropriate implicit alias" +++ "b/test/fast/Listing versions/Running \"nvm ls stable\" and \"nvm ls unstable\" should return the appropriate implicit alias" @@ -1,11 +1,12 @@ #!/bin/sh \. ../../../nvm.sh +\. ../../common.sh die () { echo "$@" ; exit 1; } -mkdir "${NVM_DIR}/v0.2.3" -mkdir "${NVM_DIR}/v0.3.3" +make_fake_node v0.2.3 +make_fake_node v0.3.3 EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" @@ -19,10 +20,10 @@ nvm ls stable | \grep "$STABLE_VERSION" >/dev/null \ nvm ls unstable | \grep "$UNSTABLE_VERSION" >/dev/null \ || die "expected 'nvm ls unstable' to give $UNSTABLE_VERSION, got $(nvm ls unstable)" -mkdir "${NVM_DIR}/v0.1.2" +make_fake_node v0.1.4 nvm alias stable 0.1 nvm ls stable | \grep -v "$STABLE_VERSION" >/dev/null \ - || die "'nvm ls stable' contained $STABLE_VERSION instead of v0.1.2" -nvm ls stable | \grep v0.1.2 >/dev/null \ - || die "'nvm ls stable' did not contain v0.1.2" + || die "'nvm ls stable' contained $STABLE_VERSION instead of v0.1.4" +nvm ls stable | \grep v0.1.4 >/dev/null \ + || die "'nvm ls stable' did not contain v0.1.4" diff --git "a/test/fast/Listing versions/Running \"nvm ls system\" should include \"system\" when appropriate" "b/test/fast/Listing versions/Running \"nvm ls system\" should include \"system\" when appropriate" index c858876..1d39a41 100755 --- "a/test/fast/Listing versions/Running \"nvm ls system\" should include \"system\" when appropriate" +++ "b/test/fast/Listing versions/Running \"nvm ls system\" should include \"system\" when appropriate" @@ -3,13 +3,14 @@ die () { echo "$@" ; exit 1; } \. ../../../nvm.sh +\. ../../common.sh -mkdir -p "${NVM_DIR}/v0.0.1" -mkdir -p "${NVM_DIR}/v0.0.3" -mkdir -p "${NVM_DIR}/v0.0.9" -mkdir -p "${NVM_DIR}/v0.3.1" -mkdir -p "${NVM_DIR}/v0.3.3" -mkdir -p "${NVM_DIR}/v0.3.9" +make_fake_node v0.0.1 +make_fake_node v0.0.3 +make_fake_node v0.0.9 +make_fake_node v0.3.1 +make_fake_node v0.3.3 +make_fake_node v0.3.9 nvm_has_system_node() { return 0; } nvm ls system | grep system 2>&1 > /dev/null diff --git "a/test/fast/Listing versions/Running \"nvm ls\" should display all installed versions." "b/test/fast/Listing versions/Running \"nvm ls\" should display all installed versions." index d9fdce0..6b71e1e 100755 --- "a/test/fast/Listing versions/Running \"nvm ls\" should display all installed versions." +++ "b/test/fast/Listing versions/Running \"nvm ls\" should display all installed versions." @@ -1,24 +1,27 @@ #!/bin/sh \. ../../../nvm.sh +\. ../../common.sh -mkdir "${NVM_DIR}/v0.0.1" -mkdir "${NVM_DIR}/v0.0.3" -mkdir "${NVM_DIR}/v0.0.9" -mkdir "${NVM_DIR}/v0.3.1" -mkdir "${NVM_DIR}/v0.3.3" -mkdir "${NVM_DIR}/v0.3.9" -mkdir -p "${NVM_DIR}/versions/node/v0.12.87" -mkdir -p "${NVM_DIR}/versions/node/v0.12.9" -mkdir -p "${NVM_DIR}/versions/io.js/v0.1.2" -mkdir -p "${NVM_DIR}/versions/io.js/v0.10.2" +die () { echo "$@" ; exit 1; } + +make_fake_node v0.0.1 +make_fake_node v0.0.3 +make_fake_node v0.0.9 +make_fake_node v0.3.1 +make_fake_node v0.3.3 +make_fake_node v0.3.9 +make_fake_node v0.12.87 +make_fake_node v0.12.9 +make_fake_iojs v0.1.2 +make_fake_iojs v0.10.2 # The result should contain the version numbers. -nvm ls | grep v0.0.1 >/dev/null && -nvm ls | grep v0.0.3 >/dev/null && -nvm ls | grep v0.0.9 >/dev/null && -nvm ls | grep v0.3.1 >/dev/null && -nvm ls | grep v0.3.3 >/dev/null && -nvm ls | grep v0.3.9 >/dev/null && -nvm ls | grep v0.12.87 >/dev/null && -nvm ls | grep iojs-v0.1.2 >/dev/null +nvm ls | grep v0.0.1 >/dev/null || die "v0.0.1 not found in: $(nvm ls)" +nvm ls | grep v0.0.3 >/dev/null || die "v0.0.3 not found in: $(nvm ls)" +nvm ls | grep v0.0.9 >/dev/null || die "v0.0.9 not found in: $(nvm ls)" +nvm ls | grep v0.3.1 >/dev/null || die "v0.3.1 not found in: $(nvm ls)" +nvm ls | grep v0.3.3 >/dev/null || die "v0.3.3 not found in: $(nvm ls)" +nvm ls | grep v0.3.9 >/dev/null || die "v0.3.9 not found in: $(nvm ls)" +nvm ls | grep v0.12.87 >/dev/null || die "v0.12.87 not found in: $(nvm ls)" +nvm ls | grep iojs-v0.1.2 >/dev/null || die "iojs-v0.1.2 not found in: $(nvm ls)" diff --git "a/test/fast/Listing versions/Running \"nvm ls\" should filter out \".nvm\"" "b/test/fast/Listing versions/Running \"nvm ls\" should filter out \".nvm\"" index 2946ad8..dedb541 100755 --- "a/test/fast/Listing versions/Running \"nvm ls\" should filter out \".nvm\"" +++ "b/test/fast/Listing versions/Running \"nvm ls\" should filter out \".nvm\"" @@ -1,9 +1,10 @@ #!/bin/sh \. ../../../nvm.sh +\. ../../common.sh -mkdir "${NVM_DIR}/v0.1.3" -mkdir "${NVM_DIR}/v0.2.3" +make_fake_node v0.1.3 +make_fake_node v0.2.3 [ -z `nvm ls | grep '^ *\.'` ] # The result should contain only the appropriate version numbers. diff --git "a/test/fast/Listing versions/Running \"nvm ls\" should filter out \"versions\"" "b/test/fast/Listing versions/Running \"nvm ls\" should filter out \"versions\"" index eae526a..bd0c709 100755 --- "a/test/fast/Listing versions/Running \"nvm ls\" should filter out \"versions\"" +++ "b/test/fast/Listing versions/Running \"nvm ls\" should filter out \"versions\"" @@ -1,10 +1,10 @@ #!/bin/sh \. ../../../nvm.sh +\. ../../common.sh -mkdir "${NVM_DIR}/v0.1.3" -mkdir "${NVM_DIR}/v0.2.3" -mkdir -p "${NVM_DIR}/versions/node" +make_fake_node v0.1.3 +make_fake_node v0.2.3 [ -z "$(nvm ls | \grep 'versions')" ] # The result should contain only the appropriate version numbers. diff --git "a/test/fast/Listing versions/Running \"nvm ls\" should include \"system\" when appropriate" "b/test/fast/Listing versions/Running \"nvm ls\" should include \"system\" when appropriate" index 3ab0f2d..9c465c0 100755 --- "a/test/fast/Listing versions/Running \"nvm ls\" should include \"system\" when appropriate" +++ "b/test/fast/Listing versions/Running \"nvm ls\" should include \"system\" when appropriate" @@ -3,13 +3,14 @@ die () { echo "$@" ; exit 1; } \. ../../../nvm.sh +\. ../../common.sh -mkdir -p "${NVM_DIR}/v0.0.1" -mkdir -p "${NVM_DIR}/v0.0.3" -mkdir -p "${NVM_DIR}/v0.0.9" -mkdir -p "${NVM_DIR}/v0.3.1" -mkdir -p "${NVM_DIR}/v0.3.3" -mkdir -p "${NVM_DIR}/v0.3.9" +make_fake_node v0.0.1 +make_fake_node v0.0.3 +make_fake_node v0.0.9 +make_fake_node v0.3.1 +make_fake_node v0.3.3 +make_fake_node v0.3.9 nvm_has_system_node() { return 0; } nvm ls | grep system 2>&1 > /dev/null diff --git "a/test/fast/Listing versions/Running \"nvm ls\" should list versions in the \"versions\" directory" "b/test/fast/Listing versions/Running \"nvm ls\" should list versions in the \"versions\" directory" index 864494a..a2a31e2 100755 --- "a/test/fast/Listing versions/Running \"nvm ls\" should list versions in the \"versions\" directory" +++ "b/test/fast/Listing versions/Running \"nvm ls\" should list versions in the \"versions\" directory" @@ -3,9 +3,10 @@ die () { echo "$@" ; exit 1; } \. ../../../nvm.sh +\. ../../common.sh -mkdir -p "${NVM_DIR}/versions/node/v0.12.1" -mkdir "${NVM_DIR}/v0.1.3" +make_fake_node v0.12.1 +make_fake_node v0.1.3 nvm ls 0.12 | grep v0.12.1 || die '"nvm ls" did not list a version in the versions/ directory' nvm ls 0.1 | grep v0.1.3 || die '"nvm ls" did not list a version not in the versions/ directory' diff --git "a/test/fast/Listing versions/Running \"nvm ls\" with node-like versioning vx.x.x should only list a matched version" "b/test/fast/Listing versions/Running \"nvm ls\" with node-like versioning vx.x.x should only list a matched version" index 2884531..cb54278 100755 --- "a/test/fast/Listing versions/Running \"nvm ls\" with node-like versioning vx.x.x should only list a matched version" +++ "b/test/fast/Listing versions/Running \"nvm ls\" with node-like versioning vx.x.x should only list a matched version" @@ -1,8 +1,9 @@ #!/bin/sh \. ../../../nvm.sh +\. ../../common.sh -mkdir "${NVM_DIR}/v0.1.2" +make_fake_node v0.1.2 nvm ls v0.1 | grep v0.1.2 && nvm ls v0.1.2 | grep v0.1.2 && diff --git a/test/fast/Listing versions/Using a nonstandard IFS should not break b/test/fast/Listing versions/Using a nonstandard IFS should not break index c707dbc..27cf2de 100755 --- a/test/fast/Listing versions/Using a nonstandard IFS should not break +++ b/test/fast/Listing versions/Using a nonstandard IFS should not break @@ -1,17 +1,18 @@ #!/bin/sh \. ../../../nvm.sh +\. ../../common.sh -mkdir "${NVM_DIR}/v0.0.1" -mkdir "${NVM_DIR}/v0.0.3" -mkdir "${NVM_DIR}/v0.0.9" -mkdir "${NVM_DIR}/v0.3.1" -mkdir "${NVM_DIR}/v0.3.3" -mkdir "${NVM_DIR}/v0.3.9" -mkdir -p "${NVM_DIR}/versions/node/v0.12.87" -mkdir -p "${NVM_DIR}/versions/node/v0.12.9" -mkdir -p "${NVM_DIR}/versions/io.js/v0.1.2" -mkdir -p "${NVM_DIR}/versions/io.js/v0.10.2" +make_fake_node v0.0.1 +make_fake_node v0.0.3 +make_fake_node v0.0.9 +make_fake_node v0.3.1 +make_fake_node v0.3.3 +make_fake_node v0.3.9 +make_fake_node v0.12.87 +make_fake_node v0.12.9 +make_fake_iojs v0.1.2 +make_fake_iojs v0.10.2 set -e diff --git a/test/fast/Listing versions/teardown b/test/fast/Listing versions/teardown index 7c965ac..8ae7d96 100755 --- a/test/fast/Listing versions/teardown +++ b/test/fast/Listing versions/teardown @@ -5,6 +5,7 @@ rmdir ../../../v0.0.9 >/dev/null 2>&1 rmdir ../../../v0.0.20 >/dev/null 2>&1 rmdir ../../../v0.1.2 >/dev/null 2>&1 rmdir ../../../v0.1.3 >/dev/null 2>&1 +rmdir ../../../v0.1.4 >/dev/null 2>&1 rmdir ../../../v0.2.3 >/dev/null 2>&1 rmdir ../../../v0.3.1 >/dev/null 2>&1 rmdir ../../../v0.3.3 >/dev/null 2>&1 diff --git "a/test/fast/Running \"nvm install\" with \"--reinstall-packages-from\" requires a valid version" "b/test/fast/Running \"nvm install\" with \"--reinstall-packages-from\" requires a valid version" index 36e1127..41016da 100755 --- "a/test/fast/Running \"nvm install\" with \"--reinstall-packages-from\" requires a valid version" +++ "b/test/fast/Running \"nvm install\" with \"--reinstall-packages-from\" requires a valid version" @@ -8,8 +8,9 @@ cleanup () { } \. ../../nvm.sh +\. ../common.sh -mkdir "${NVM_DIR}/v0.10.4" +make_fake_node v0.10.4 nvm deactivate >/dev/null 2>&1 diff --git "a/test/fast/Running \"nvm use x\" should create and change the \"current\" symlink" "b/test/fast/Running \"nvm use x\" should create and change the \"current\" symlink" index 71f208c..fc1a086 100755 --- "a/test/fast/Running \"nvm use x\" should create and change the \"current\" symlink" +++ "b/test/fast/Running \"nvm use x\" should create and change the \"current\" symlink" @@ -4,11 +4,12 @@ set -ex export NVM_SYMLINK_CURRENT=true \. ../../nvm.sh +\. ../common.sh rm -rf "${NVM_DIR}/v0.10.29" -mkdir "${NVM_DIR}/v0.10.29" +make_fake_node v0.10.29 nvm use --delete-prefix 0.10.29 -rmdir "${NVM_DIR}/v0.10.29" +rm -rf "${NVM_DIR}/v0.10.29" if [ ! -L "${NVM_DIR}/current" ];then echo "Expected 'current' symlink to be created!" @@ -23,9 +24,9 @@ if [ "$(basename "${oldLink}")" != 'v0.10.29' ];then fi rm -rf "${NVM_DIR}/v0.11.13" -mkdir "${NVM_DIR}/v0.11.13" +make_fake_node v0.11.13 nvm use --delete-prefix 0.11.13 -rmdir "${NVM_DIR}/v0.11.13" +rm -rf "${NVM_DIR}/v0.11.13" newLink="$(readlink "${NVM_DIR}/current")" diff --git "a/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" "b/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" index be6284d..1450659 100755 --- "a/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" +++ "b/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" @@ -3,6 +3,7 @@ set -ex \. ../../nvm.sh +\. ../common.sh TEST_NODE_VERSION="v0.10.29" @@ -35,9 +36,9 @@ cleanup() { } runNvmUse() { - mkdir "${NVM_DIR}/${TEST_NODE_VERSION}" + make_fake_node "$TEST_NODE_VERSION" nvm use --delete-prefix "${TEST_NODE_VERSION}" > /dev/null 2>&1 - rmdir "${NVM_DIR}/${TEST_NODE_VERSION}" + rm -rf "${NVM_DIR}/${TEST_NODE_VERSION}" } isCurrentSymlinkPresent() { diff --git a/test/fast/Unit tests/nvm_ensure_version_installed b/test/fast/Unit tests/nvm_ensure_version_installed index e819657..e239e0e 100755 --- a/test/fast/Unit tests/nvm_ensure_version_installed +++ b/test/fast/Unit tests/nvm_ensure_version_installed @@ -7,8 +7,9 @@ cleanup () { } \. ../../../nvm.sh +\. ../../common.sh -mkdir -p "$(nvm_version_path v0.1.2)" +make_fake_node v0.1.2 OUTPUT="$(nvm_ensure_version_installed foo 2>&1)" EXIT_CODE=$? diff --git a/test/fast/Unit tests/nvm_has_system_iojs b/test/fast/Unit tests/nvm_has_system_iojs index 5d3240b..0d4eadb 100755 --- a/test/fast/Unit tests/nvm_has_system_iojs +++ b/test/fast/Unit tests/nvm_has_system_iojs @@ -1,17 +1,14 @@ #!/bin/sh cleanup () { - rm "${NVM_DIR}/versions/io.js/v0.1.2/node" - rm "${NVM_DIR}/versions/io.js/v0.1.2/iojs" - rmdir "${NVM_DIR}/versions/io.js/v0.1.2" + rm -rf "${NVM_DIR}/versions/io.js/v0.1.2" } die () { echo "$@" ; exit 1; } \. ../../../nvm.sh +\. ../../common.sh -mkdir "${NVM_DIR}/versions/io.js/v0.1.2" -touch "${NVM_DIR}/versions/io.js/v0.1.2/node" -touch "${NVM_DIR}/versions/io.js/v0.1.2/iojs" +make_fake_iojs v0.1.2 nvm use iojs-v0.1.2 diff --git a/test/fast/Unit tests/nvm_has_system_node b/test/fast/Unit tests/nvm_has_system_node index 86f6bbc..9a71979 100755 --- a/test/fast/Unit tests/nvm_has_system_node +++ b/test/fast/Unit tests/nvm_has_system_node @@ -1,14 +1,14 @@ #!/bin/sh \. ../../../nvm.sh +\. ../../common.sh cleanup () { - rm -rf "${NVM_DIR}/v0.1.2/node" + rm -rf "${NVM_DIR}/v0.1.2" } die () { echo "$@" ; exit 1; } -mkdir "${NVM_DIR}/v0.1.2" -touch "${NVM_DIR}/v0.1.2/node" +make_fake_node v0.1.2 nvm use 0.1.2 diff --git a/test/fast/Unit tests/nvm_print_implicit_alias success b/test/fast/Unit tests/nvm_print_implicit_alias success index fe99b58..ded8174 100755 --- a/test/fast/Unit tests/nvm_print_implicit_alias success +++ b/test/fast/Unit tests/nvm_print_implicit_alias success @@ -14,13 +14,14 @@ cleanup() { } \. ../../../nvm.sh +\. ../../common.sh -mkdir "${NVM_DIR}/v0.2.3" -mkdir "${NVM_DIR}/v0.3.4" -mkdir "${NVM_DIR}/v0.4.6" -mkdir "${NVM_DIR}/v0.5.7" -mkdir "${NVM_DIR}/v0.7.7" -mkdir -p "${NVM_DIR}/versions/io.js/v0.98.0" +make_fake_node v0.2.3 +make_fake_node v0.3.4 +make_fake_node v0.4.6 +make_fake_node v0.5.7 +make_fake_node v0.7.7 +make_fake_iojs v0.98.0 LATEST_STABLE="$(nvm_print_implicit_alias local stable)" [ "_$LATEST_STABLE" = "_0.4" ] || die "local stable is not latest even minor: expected 0.4, got $LATEST_STABLE" @@ -35,8 +36,9 @@ LATEST_IOJS="$(nvm_print_implicit_alias local iojs)" [ "_$LATEST_IOJS" = "_iojs-v0.98" ] || die "local iojs is not latest iojs: expected iojs-v0.98, got $LATEST_IOJS" ## node post v1.0/io.js merger ## -mkdir -p "${NVM_DIR}/versions/node/v1.0.0" -mkdir -p "${NVM_DIR}/versions/node/v1.1.0" +make_fake_node v1.0.0 +make_fake_node v1.1.0 + LATEST_STABLE="$(nvm_print_implicit_alias local stable)" [ "_$LATEST_STABLE" = "_1.1" ] || die "local stable when post-v1.0 exists is not latest: expected 1.1, got $LATEST_STABLE" From 0cdc1841688eedc28e20489caccd43d0ff03c7eb Mon Sep 17 00:00:00 2001 From: Joshua Li Date: Thu, 31 May 2018 15:26:30 -0700 Subject: [PATCH 09/24] [Fix] Improve `nvm_is_version_installed` to check for a node executable instead of root dir --- nvm.sh | 2 +- test/fast/Aliases/setup | 9 ++++++--- ...vate\" should unset the nvm environment variables." | 9 +++++---- ...install\" should remove the appropriate directory." | 10 +++++----- ...all\" with incorrect file permissions fails nicely" | 10 ++++------ test/installation_node/install hook | 6 ++++++ 6 files changed, 27 insertions(+), 19 deletions(-) diff --git a/nvm.sh b/nvm.sh index d854605..b4da6b3 100644 --- a/nvm.sh +++ b/nvm.sh @@ -130,7 +130,7 @@ nvm_has_system_iojs() { } nvm_is_version_installed() { - [ -n "${1-}" ] && [ -d "$(nvm_version_path "${1-}" 2> /dev/null)" ] + [ -n "${1-}" ] && [ -x "$(nvm_version_path "$1" 2> /dev/null)"/bin/node ] } nvm_print_npm_version() { diff --git a/test/fast/Aliases/setup b/test/fast/Aliases/setup index a28a5c2..7055a4d 100755 --- a/test/fast/Aliases/setup +++ b/test/fast/Aliases/setup @@ -1,11 +1,14 @@ #!/bin/sh +\. ../../../nvm.sh +\. ../../common.sh + for i in $(seq 1 10) do echo 0.0.$i > ../../../alias/test-stable-$i - mkdir -p ../../../v0.0.$i + make_fake_node v0.0.$i echo 0.1.$i > ../../../alias/test-unstable-$i - mkdir -p ../../../v0.1.$i + make_fake_node v0.1.$i echo 0.2.$i > ../../../alias/test-iojs-$i - mkdir -p ../../../versions/io.js/v0.2.$i + make_fake_iojs v0.2.$i done diff --git "a/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." "b/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." index 568f000..5cb5594 100755 --- "a/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." +++ "b/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." @@ -2,13 +2,14 @@ set -ex -mkdir -p ../../v0.2.3 - die () { echo "$@" ; exit 1; } -[ `expr $PATH : ".*v0.2.3/.*/bin.*"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2 - \. ../../nvm.sh +\. ../common.sh + +make_fake_node v0.2.3 + +[ `expr $PATH : ".*v0.2.3/.*/bin.*"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2 nvm use --delete-prefix v0.2.3 || die "Failed to activate v0.2.3" [ `expr "$PATH" : ".*v0.2.3/.*/bin.*"` != 0 ] || die "PATH not set up properly" diff --git "a/test/fast/Running \"nvm uninstall\" should remove the appropriate directory." "b/test/fast/Running \"nvm uninstall\" should remove the appropriate directory." index 5ef1827..9d5fa1b 100755 --- "a/test/fast/Running \"nvm uninstall\" should remove the appropriate directory." +++ "b/test/fast/Running \"nvm uninstall\" should remove the appropriate directory." @@ -2,11 +2,11 @@ set -ex -cd ../.. -mkdir v0.0.1 -mkdir src/node-v0.0.1 +\. ../../nvm.sh +\. ../common.sh + +make_fake_node v0.0.1 -. ./nvm.sh nvm uninstall v0.0.1 -[ ! -d 'v0.0.1' ] && [ ! -d 'src/node-v0.0.1/files' ] +[ ! -d 'v0.0.1' ] diff --git "a/test/fast/Running \"nvm uninstall\" with incorrect file permissions fails nicely" "b/test/fast/Running \"nvm uninstall\" with incorrect file permissions fails nicely" index 5fd2638..23f6f54 100755 --- "a/test/fast/Running \"nvm uninstall\" with incorrect file permissions fails nicely" +++ "b/test/fast/Running \"nvm uninstall\" with incorrect file permissions fails nicely" @@ -2,13 +2,11 @@ set -ex -cd ../.. -mkdir v0.0.1 -mkdir src/node-v0.0.1 +\. ../../nvm.sh +\. ../common.sh -sudo touch v0.0.1/sudo - -. ./nvm.sh +make_fake_node v0.0.1 +sudo touch ""$(nvm_version_path v0.0.1)"/sudo" RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1 || echo)" CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder" diff --git a/test/installation_node/install hook b/test/installation_node/install hook index 896037b..4290bb1 100755 --- a/test/installation_node/install hook +++ b/test/installation_node/install hook @@ -19,6 +19,12 @@ fail() { ! nvm_is_version_installed "${VERSION}" || nvm uninstall "${VERSION}" || die 'uninstall failed' +# an existing but empty VERSION_PATH directory should not be enough to satisfy nvm_is_version_installed +rm -rf "${VERSION_PATH}" +mkdir -p "${VERSION_PATH}" +nvm_is_version_installed "${VERSION}" && die 'nvm_is_version_installed check not strict enough' +rmdir "${VERSION_PATH}" + OUTPUT="$(NVM_INSTALL_THIRD_PARTY_HOOK=succeed nvm install "${VERSION}")" USE_OUTPUT="$(nvm use "${VERSION}")" EXPECTED_OUTPUT="${VERSION} node std binary ${VERSION_PATH} From 90cfb5d7713315f6684c5118977098e1d24ff705 Mon Sep 17 00:00:00 2001 From: Xandor Schiefer Date: Fri, 8 Jun 2018 15:23:02 +0200 Subject: [PATCH 10/24] [Fix] `use`: Prepend instead of changing if shadowed by system dirs (fixes #1652) --- nvm.sh | 11 +++++++++-- test/fast/Unit tests/nvm_change_path | 14 ++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index b4da6b3..d710274 100644 --- a/nvm.sh +++ b/nvm.sh @@ -638,12 +638,19 @@ nvm_change_path() { elif ! nvm_echo "${1-}" | nvm_grep -q "${NVM_DIR}/[^/]*${2-}" \ && ! nvm_echo "${1-}" | nvm_grep -q "${NVM_DIR}/versions/[^/]*/[^/]*${2-}"; then nvm_echo "${3-}${2-}:${1-}" + # if the initial path contains BOTH an nvm path (checked for above) and + # that nvm path is preceded by a system binary path, just prepend the + # supplementary path instead of replacing it. + # https://github.com/creationix/nvm/issues/1652#issuecomment-342571223 + elif nvm_echo "${1-}" | nvm_grep -Eq "(^|:)(/usr(/local)?)?${2-}:.*${NVM_DIR}/[^/]*${2-}" \ + || nvm_echo "${1-}" | nvm_grep -Eq "(^|:)(/usr(/local)?)?${2-}:.*${NVM_DIR}/versions/[^/]*/[^/]*${2-}"; then + nvm_echo "${3-}${2-}:${1-}" # use sed to replace the existing nvm path with the supplementary path. This # preserves the order of the path. else nvm_echo "${1-}" | command sed \ - -e "s#${NVM_DIR}/[^/]*${2-}[^:]*#${3-}${2-}#g" \ - -e "s#${NVM_DIR}/versions/[^/]*/[^/]*${2-}[^:]*#${3-}${2-}#g" + -e "s#${NVM_DIR}/[^/]*${2-}[^:]*#${3-}${2-}#" \ + -e "s#${NVM_DIR}/versions/[^/]*/[^/]*${2-}[^:]*#${3-}${2-}#" fi } diff --git a/test/fast/Unit tests/nvm_change_path b/test/fast/Unit tests/nvm_change_path index 621729f..8c0f937 100755 --- a/test/fast/Unit tests/nvm_change_path +++ b/test/fast/Unit tests/nvm_change_path @@ -41,3 +41,17 @@ NEW_PATH=`nvm_change_path "$EMPTY_PATH" "/bin" "$NVM_DIR/versions/node/v7.1.0"` NEW_PATH=`nvm_change_path "$EMPTY_PATH" "/bin" "$NVM_DIR/v0.1.2"` [ "$NEW_PATH" = "$NVM_DIR/v0.1.2/bin" ] || die "Not correctly prepended: $NEW_PATH " + + +# https://github.com/creationix/nvm/issues/1652#issuecomment-342571223 +MAC_OS_NESTED_SESSION_PATH=/usr/bin:/usr/local/bin:$NVM_DIR/versions/node/v4.5.0/bin + +# New version dir +NEW_PATH=`nvm_change_path "$MAC_OS_NESTED_SESSION_PATH" "/bin" "$NVM_DIR/versions/node/v7.1.0"` + +[ "$NEW_PATH" = "$NVM_DIR/versions/node/v7.1.0/bin:/usr/bin:/usr/local/bin:$NVM_DIR/versions/node/v4.5.0/bin" ] || die "Not correctly changed: $NEW_PATH " + +# Old version dir +NEW_PATH=`nvm_change_path "$MAC_OS_NESTED_SESSION_PATH" "/bin" "$NVM_DIR/v0.1.2"` + +[ "$NEW_PATH" = "$NVM_DIR/v0.1.2/bin:/usr/bin:/usr/local/bin:$NVM_DIR/versions/node/v4.5.0/bin" ] || die "Not correctly changed: $NEW_PATH " From 41dc4218b9ab1ad15ac3cacba2710c1804bb2c51 Mon Sep 17 00:00:00 2001 From: JBallin Date: Sun, 17 Jun 2018 21:31:56 -0700 Subject: [PATCH 11/24] [Docs] add --no-use option to installation --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 96e0782..38771f0 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm ``` +**Note:** You can add `--no-use` to the end of the above script (...`nvm.sh --no-use`) to postpone using `nvm` until you manually [`use`](#usage) it. + You can customize the install source, directory, profile, and version using the `NVM_SOURCE`, `NVM_DIR`, `PROFILE`, and `NODE_VERSION` variables. Eg: `curl ... | NVM_DIR="path/to/nvm"`. Ensure that the `NVM_DIR` does not contain a trailing slash. From e2195b4c357847da2e8e0db71096d34fc10015ce Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Sun, 8 Jul 2018 20:47:46 +0800 Subject: [PATCH 12/24] [Dockerfile] Use LABEL instead of deprecated MAINTAINER command --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 79cb15b..314285e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ # Use Ubuntu Trusty Tahr as base image as we're using on Travis CI # I also tested with Ubuntu 16.04, should be good with it! From ubuntu:14.04 -MAINTAINER Peter Dave Hello +LABEL maintainer="Peter Dave Hello " # Prevent dialog during apt install ENV DEBIAN_FRONTEND noninteractive From 265ec905326df95f4cdb86d78747ff8a3c84e321 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Sun, 8 Jul 2018 21:00:23 +0800 Subject: [PATCH 13/24] [Dockerfile] Add missing name & version LABEL --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 314285e..d972cfd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,8 @@ # I also tested with Ubuntu 16.04, should be good with it! From ubuntu:14.04 LABEL maintainer="Peter Dave Hello " +LABEL name="nvm-dev-env" +LABEL version="latest" # Prevent dialog during apt install ENV DEBIAN_FRONTEND noninteractive From af8038ffecaf1f21315fa1e588126ec5d205e056 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Sun, 8 Jul 2018 21:40:17 +0800 Subject: [PATCH 14/24] [Dockerfile] Update ShellCheck version to v0.5.0 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d972cfd..9695df6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,7 +17,7 @@ LABEL version="latest" ENV DEBIAN_FRONTEND noninteractive # ShellCheck version -ENV SHELLCHECK_VERSION=0.4.7 +ENV SHELLCHECK_VERSION=0.5.0 # Pick a Ubuntu apt mirror site for better speed # ref: https://launchpad.net/ubuntu/+archivemirrors From f121e5ace02638532e8be5bfabf36cc6edb12a74 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Mon, 9 Jul 2018 05:31:20 +0800 Subject: [PATCH 15/24] [Dockerfile] Add missing quotes for variables --- Dockerfile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9695df6..621ac3f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -93,10 +93,10 @@ USER nvm # nvm COPY . /home/nvm/.nvm/ -RUN sudo chown nvm:nvm -R $HOME/.nvm -RUN echo 'export NVM_DIR="$HOME/.nvm"' >> $HOME/.bashrc -RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> $HOME/.bashrc -RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> $HOME/.bashrc +RUN sudo chown nvm:nvm -R "$HOME/.nvm" +RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$HOME/.bashrc" +RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> "$HOME/.bashrc" +RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$HOME/.bashrc" # nodejs and tools RUN bash -c 'source $HOME/.nvm/nvm.sh && \ From aacb0b9b97ea8ca7ca47c465c5d5ba8e549bf4a2 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Mon, 9 Jul 2018 06:07:41 +0800 Subject: [PATCH 16/24] [Dockerfile] Fix command `From` to be `FROM` --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 621ac3f..50c11ee 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,7 +8,7 @@ # Use Ubuntu Trusty Tahr as base image as we're using on Travis CI # I also tested with Ubuntu 16.04, should be good with it! -From ubuntu:14.04 +FROM ubuntu:14.04 LABEL maintainer="Peter Dave Hello " LABEL name="nvm-dev-env" LABEL version="latest" From 04b35b544077d3d7833a788f8d806de085eb9cbf Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Mon, 9 Jul 2018 06:09:30 +0800 Subject: [PATCH 17/24] [Dockerfile] Use arguments JSON notation for ENTRYPOINT --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 50c11ee..49bc3c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -107,4 +107,4 @@ RUN bash -c 'source $HOME/.nvm/nvm.sh && \ # Set WORKDIR to nvm directory WORKDIR /home/nvm/.nvm -ENTRYPOINT /bin/bash +ENTRYPOINT ["/bin/bash"] From cdde74a55d05b7925bb3822e8f31c05789e56968 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Thu, 12 Jul 2018 14:27:20 +0800 Subject: [PATCH 18/24] [Dockerfile] install missing eclint package --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 49bc3c5..22e759a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -101,7 +101,7 @@ RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # Th # nodejs and tools RUN bash -c 'source $HOME/.nvm/nvm.sh && \ nvm install node && \ - npm install -g doctoc urchin && \ + npm install -g doctoc urchin eclint && \ npm install --prefix "$HOME/.nvm/"' # Set WORKDIR to nvm directory From 7ff20855a2b7328ada8049e4570078f7db6d68cc Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Thu, 12 Jul 2018 12:14:06 +0800 Subject: [PATCH 19/24] [Tests] Integrate dockerfile_lint to test Dockerfile --- .travis.yml | 4 +++- Dockerfile | 2 +- package.json | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6c32943..8af8a2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,12 +19,13 @@ before_install: - curl --version - wget --version install: - - if [ -z "${SHELLCHECK-}" ]; then nvm install node && npm install && npm prune && npm ls urchin doctoc eclint; fi + - if [ -z "${SHELLCHECK-}" ]; then nvm install node && npm install && npm prune && npm ls urchin doctoc eclint dockerfile_lint; fi - '[ -z "$WITHOUT_CURL" ] || sudo apt-get remove curl -y' script: - if [ -n "${MAKE_RELEASE-}" ]; then export GIT_EDITOR="sed -i '1 s/^/99.99.99 make release test/'" && git fetch --unshallow --tags && echo proceed | make TAG=99.99.99 release ; fi - if [ -n "${DOCTOCCHECK-}" ]; then cp README.md README.md.orig && npm run doctoc && diff -q README.md README.md.orig ; fi - if [ -n "${ECLINT-}" ]; then npm run eclint ; fi + - if [ -n "${DOCKERFILE_LINT-}" ]; then npm run dockerfile_lint ; fi - if [ -n "${SHELLCHECK-}" ]; then shellcheck -s bash nvm.sh && shellcheck -s sh nvm.sh && shellcheck -s dash nvm.sh && shellcheck -s ksh nvm.sh ; fi - if [ -n "${SHELLCHECK-}" ]; then shellcheck -s bash install.sh bash_completion nvm-exec ; fi - if [ -n "${SHELL-}" ] && [ -n "${TEST_SUITE}" ]; then if [ "${TEST_SUITE}" = 'installation_iojs' ]; then travis_retry make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL ; else make TEST_SUITE=$TEST_SUITE URCHIN="$(npm bin)/urchin" test-$SHELL; fi; fi @@ -42,6 +43,7 @@ env: - DOCTOCCHECK=true - SHELLCHECK=true - ECLINT=true + - DOCKERFILE_LINT=true - SHELL=bash TEST_SUITE=install_script - SHELL=sh TEST_SUITE=fast - SHELL=dash TEST_SUITE=fast diff --git a/Dockerfile b/Dockerfile index 22e759a..22cc068 100644 --- a/Dockerfile +++ b/Dockerfile @@ -101,7 +101,7 @@ RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # Th # nodejs and tools RUN bash -c 'source $HOME/.nvm/nvm.sh && \ nvm install node && \ - npm install -g doctoc urchin eclint && \ + npm install -g doctoc urchin eclint dockerfile_lint && \ npm install --prefix "$HOME/.nvm/"' # Set WORKDIR to nvm directory diff --git a/package.json b/package.json index 5a4fd87..310b802 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "test/installation/iojs": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation_iojs test-$shell", "test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell", "doctoc": "doctoc --title='## Table of Contents' --github README.md", - "eclint": "eclint check $(git ls-tree --name-only HEAD | xargs)" + "eclint": "eclint check $(git ls-tree --name-only HEAD | xargs)", + "dockerfile_lint": "dockerfile_lint" }, "repository": { "type": "git", @@ -35,6 +36,7 @@ }, "homepage": "https://github.com/creationix/nvm", "devDependencies": { + "dockerfile_lint": "^0.3.2", "eclint": "^2.6.0", "replace": "^0.3.0", "semver": "^5.0.1", From 5f9ccaada08940eabe1c95ecdc44d781fce987b0 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Thu, 12 Jul 2018 12:22:41 +0800 Subject: [PATCH 20/24] [Dockerfile] Set the SHELL to bash with pipefail option --- Dockerfile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Dockerfile b/Dockerfile index 22cc068..d2ac044 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,9 @@ LABEL maintainer="Peter Dave Hello " LABEL name="nvm-dev-env" LABEL version="latest" +# Set the SHELL to bash with pipefail option +SHELL ["/bin/bash", "-o", "pipefail", "-c"] + # Prevent dialog during apt install ENV DEBIAN_FRONTEND noninteractive From 4bd99bcfa21a2c83c1958445ea7347439e894309 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Thu, 12 Jul 2018 12:29:46 +0800 Subject: [PATCH 21/24] [Dockerfile] Refactor to prevent using `sudo` during build `sudo` may lead to unpredictable behavior in some cases, and we don't really need to use `sudo` to reach what we need. --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d2ac044..d4b0f1b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -88,6 +88,10 @@ RUN wget --version # Add user "nvm" as non-root user RUN useradd -ms /bin/bash nvm +# Copy and set permission for nvm directory +COPY . /home/nvm/.nvm/ +RUN chown nvm:nvm -R "home/nvm/.nvm" + # Set sudoer for "nvm" RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers @@ -95,8 +99,6 @@ RUN echo 'nvm ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers USER nvm # nvm -COPY . /home/nvm/.nvm/ -RUN sudo chown nvm:nvm -R "$HOME/.nvm" RUN echo 'export NVM_DIR="$HOME/.nvm"' >> "$HOME/.bashrc" RUN echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm' >> "$HOME/.bashrc" RUN echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion" # This loads nvm bash_completion' >> "$HOME/.bashrc" From e7a37f336df425dc178d05fe6874d2171d10343d Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 15 Aug 2018 15:01:47 -0700 Subject: [PATCH 22/24] [Tests] fix failing tests on master due to npm registry SSL changes --- test/installation_node/install latest npm | 3 ++- .../install while reinstalling packages | 22 +++++++++---------- test/installation_node/teardown_dir | 4 ++++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/test/installation_node/install latest npm b/test/installation_node/install latest npm index bb7e57f..8bb7a62 100755 --- a/test/installation_node/install latest npm +++ b/test/installation_node/install latest npm @@ -26,6 +26,8 @@ nvm install-latest-npm || die 'nvm install-latest-npm failed: 3' NPM_VERSION="$(npm --version)" [ "${NPM_VERSION}" = '4.6.1' ] || die "io.js v1.x updates to ${NPM_VERSION}; expected v4.6.1" +export NPM_CONFIG_STRICT_SSL=false # the npm registry tightened up their SSL certs + nvm deactivate >/dev/null 2>&1 || die 'unable to deactivate: 4' nvm install 0.8.27 >/dev/null 2>&1 || die 'install v0.8 failed' nvm install-latest-npm || die 'nvm install-latest-npm failed: 4' @@ -35,7 +37,6 @@ NPM_VERSION="$(npm --version)" ## Commented to work around travis-ci breaking 0,6 installs # nvm deactivate >/dev/null 2>&1 || die 'unable to deactivate: 5' # nvm install 0.6.21 >/dev/null 2>&1 || die 'install v0.6 failed' -# export NPM_CONFIG_STRICT_SSL=false # npm 1 on travis can't handle SSL to npm # nvm install-latest-npm || die 'nvm install-latest-npm failed: 5' # NPM_VERSION="$(npm --version)" # [ "${NPM_VERSION}" = '1.3.26' ] || die "node 0.6.21 updates to ${NPM_VERSION}; expected v1.3.26" diff --git a/test/installation_node/install while reinstalling packages b/test/installation_node/install while reinstalling packages index 0c1046d..5588842 100755 --- a/test/installation_node/install while reinstalling packages +++ b/test/installation_node/install while reinstalling packages @@ -5,29 +5,29 @@ die () { echo "$@" ; exit 1; } \. ../../nvm.sh # Remove the stuff we're clobbering. -[ -e "${NVM_DIR}/v0.9.7" ] && rm -R "${NVM_DIR}/v0.9.7" -[ -e "${NVM_DIR}/v0.9.12" ] && rm -R "${NVM_DIR}/v0.9.12" +[ -e "${NVM_DIR}/versions/node/v9.7.0" ] && rm -R "${NVM_DIR}/versions/node/v9.7.0" +[ -e "${NVM_DIR}/versions/node/v9.10.0" ] && rm -R "${NVM_DIR}/versions/node/v9.10.0" # Install from binary -nvm install 0.9.7 +nvm install 9.7.0 # Check -[ -d "${NVM_DIR}/v0.9.7" ] || die "nvm install 0.9.7 didn't install" +[ -d "${NVM_DIR}/versions/node/v9.7.0" ] || die "nvm install 9.7.0 didn't install" -nvm use 0.9.7 +nvm use 9.7.0 -node --version | grep v0.9.7 > /dev/null || die "nvm use 0.9.7 failed" +node --version | grep v9.7.0 > /dev/null || die "nvm use 9.7.0 failed" npm install -g object-is@0.0.0 || die "npm install -g object-is failed" npm list --global | grep object-is > /dev/null || die "object-is isn't installed" -nvm ls 0.9 | grep v0.9.7 > /dev/null || die "nvm ls 0.9 didn't show v0.9.7" +nvm ls 9 | grep v9.7.0 > /dev/null || die "nvm ls 9 didn't show v9.7.0" -nvm install 0.9.12 --reinstall-packages-from=0.9 || die "nvm install 0.9.12 --reinstall-packages-from=0.9 failed" +nvm install 9.10.0 --reinstall-packages-from=9 || die "nvm install 9.10.0 --reinstall-packages-from=9 failed" -[ -d "${NVM_DIR}/v0.9.12" ] || die "nvm install 0.9.12 didn't install" +[ -d "${NVM_DIR}/versions/node/v9.10.0" ] || die "nvm install 9.10.0 didn't install" -nvm use 0.9 -node --version | grep v0.9.12 > /dev/null || die "nvm ls 0.9 didn't use v0.9.12" +nvm use 9 +node --version | grep v9.10.0 > /dev/null || die "nvm ls 9 didn't use v9.10.0" npm list --global | grep object-is > /dev/null || die "object-is isn't installed" diff --git a/test/installation_node/teardown_dir b/test/installation_node/teardown_dir index 2aad120..adb23c4 100755 --- a/test/installation_node/teardown_dir +++ b/test/installation_node/teardown_dir @@ -4,6 +4,10 @@ nvm deactivate nvm uninstall v0.10.7 nvm uninstall v4.2.2 +nvm uninstall v0.9.7 +nvm uninstall v9.7.0 +nvm uninstall v0.9.12 +nvm uninstall v9.10.0 if [ -f ".nvmrc" ]; then rm .nvmrc From f218a8545406cb45b48f1d1bdc2552b3a4749ca1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 9 Sep 2018 14:56:17 -0700 Subject: [PATCH 23/24] [Tests] eslint 5.5+ seems to not install on node 0.10 --- test/slow/nvm reinstall-packages/should work as expected | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/slow/nvm reinstall-packages/should work as expected b/test/slow/nvm reinstall-packages/should work as expected index f4edca4..68c0fb1 100755 --- a/test/slow/nvm reinstall-packages/should work as expected +++ b/test/slow/nvm reinstall-packages/should work as expected @@ -10,7 +10,7 @@ nvm exec 0.10.29 npm install -g npm@~1.4.11 && nvm install-latest-npm # this is nvm use 0.10.28 (cd test-npmlink && npm link) -EXPECTED_PACKAGES="autoprefixer bower david eslint grunt-cli grunth-cli http-server jshint marked node-gyp npmlist recursive-blame spawn-sync test-npmlink uglify-js" +EXPECTED_PACKAGES="autoprefixer bower david grunt-cli grunth-cli http-server jshint marked node-gyp npmlist recursive-blame spawn-sync test-npmlink uglify-js" echo "$EXPECTED_PACKAGES yo@1" | sed -e 's/test-npmlink //' | xargs npm install -g --quiet From 8542df4ac503b6ee0dd055a67b07a88031e1804f Mon Sep 17 00:00:00 2001 From: Erik Lilja Date: Tue, 14 Aug 2018 21:45:40 +0200 Subject: [PATCH 24/24] [New] add support for `$XDG_CONFIG_HOME` --- README.md | 4 +++- install.sh | 8 +++++++- test/install_script/nvm_install_dir | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 38771f0..2151f8c 100644 --- a/README.md +++ b/README.md @@ -54,8 +54,10 @@ wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`). +**Note:** If the environment variable `$XDG_CONFIG_HOME` is present, it will place the `nvm` files there. + ```sh -export NVM_DIR="$HOME/.nvm" +export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm ``` diff --git a/install.sh b/install.sh index 7bf62df..2115f3f 100755 --- a/install.sh +++ b/install.sh @@ -7,7 +7,13 @@ nvm_has() { } nvm_install_dir() { - command printf %s "${NVM_DIR:-"$HOME/.nvm"}" + if [ ! -z "$NVM_DIR" ]; then + printf %s "${NVM_DIR}" + elif [ ! -z "$XDG_CONFIG_HOME" ]; then + printf %s "${XDG_CONFIG_HOME/nvm}" + else + printf %s "$HOME/.nvm" + fi } nvm_latest_version() { diff --git a/test/install_script/nvm_install_dir b/test/install_script/nvm_install_dir index 1aeea18..78da611 100755 --- a/test/install_script/nvm_install_dir +++ b/test/install_script/nvm_install_dir @@ -16,9 +16,10 @@ install_dir=$(nvm_install_dir) [ "_$install_dir" = "_$NVM_DIR" ] || die "nvm_install_dir should use \$NVM_DIR if it exists. Current output: $install_dir" unset NVM_DIR - # NVM_DIR is not set install_dir=$(nvm_install_dir) -[ "_$install_dir" = "_$HOME/.nvm" ] || die "nvm_install_dir should default to \$HOME/.nvm. Current output: $install_dir" +fallback_dir="" +[ ! -z "$XDG_CONFIG_HOME" ] && fallback_dir="$XDG_CONFIG_HOME/nvm" || fallback_dir="$HOME/.nvm" +[ "_$install_dir" = "_$fallback_dir" ] || die "nvm_install_dir should default to \$XDG_CONFIG_DIR/.nvm. Current output: $install_dir" cleanup