Skip to content
Myr

[Fix] Improve `nvm_is_version_installed` to check for a node executable instead of root dir

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

authored by Joshua Li · committed by Jordan Harband · parent a5f42d9 · Browse files · 6 files+27 added−19 removed
This commit

State

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

Diff stats

6 files+27 added−19 removed

  • tests:+26 added−18 removed
  • other:+1 added−1 removed

6 files+27 added−19 removed

modified:test/fast/Aliases/setup+6 added-3 removed
1#!/bin/sh23\. ../../../nvm.sh4\. ../../common.sh56for i in $(seq 1 10)7 do8 echo 0.0.$i > ../../../alias/test-stable-$i6 mkdir -p ../../../v0.0.$i9 make_fake_node v0.0.$i10 echo 0.1.$i > ../../../alias/test-unstable-$i8 mkdir -p ../../../v0.1.$i11 make_fake_node v0.1.$i12 echo 0.2.$i > ../../../alias/test-iojs-$i10 mkdir -p ../../../versions/io.js/v0.2.$i13 make_fake_iojs v0.2.$i14done
modified:test/fast/Running "nvm deactivate" should unset the nvm environment variables.+5 added-4 removed
1#!/bin/sh23set -ex45mkdir -p ../../v0.2.365die () { echo "$@" ; exit 1; }69[ `expr $PATH : ".*v0.2.3/.*/bin.*"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2107\. ../../nvm.sh8\. ../common.sh910make_fake_node v0.2.31112[ `expr $PATH : ".*v0.2.3/.*/bin.*"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&21314nvm use --delete-prefix v0.2.3 || die "Failed to activate v0.2.3"15[ `expr "$PATH" : ".*v0.2.3/.*/bin.*"` != 0 ] || die "PATH not set up properly"16[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules.*"` = 0 ] || die "NODE_PATH should not contain (npm root -g)"17# ^ note: NODE_PATH should not contain `npm root -g` since globals should not be requireable
6 unmodified lines
modified:test/fast/Running "nvm uninstall" should remove the appropriate directory.+5 added-5 removed
1#!/bin/sh23set -ex45cd ../..6mkdir v0.0.17mkdir src/node-v0.0.15\. ../../nvm.sh6\. ../common.sh79. ./nvm.sh8make_fake_node v0.0.1910nvm uninstall v0.0.11112[ ! -d 'v0.0.1' ] && [ ! -d 'src/node-v0.0.1/files' ]12[ ! -d 'v0.0.1' ]
modified:test/fast/Running "nvm uninstall" with incorrect file permissions fails nicely+4 added-6 removed
1#!/bin/sh23set -ex45cd ../..6mkdir v0.0.17mkdir src/node-v0.0.15\. ../../nvm.sh6\. ../common.sh79sudo touch v0.0.1/sudo8make_fake_node v0.0.19sudo touch ""$(nvm_version_path v0.0.1)"/sudo"1011. ./nvm.sh1211RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1 || echo)"12CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder"1314[ "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" ] || exit 1
modified:test/installation_node/install hook+6 added
17 unmodified lines
18}1920! nvm_is_version_installed "${VERSION}" || nvm uninstall "${VERSION}" || die 'uninstall failed'2122# an existing but empty VERSION_PATH directory should not be enough to satisfy nvm_is_version_installed23rm -rf "${VERSION_PATH}"24mkdir -p "${VERSION_PATH}"25nvm_is_version_installed "${VERSION}" && die 'nvm_is_version_installed check not strict enough'26rmdir "${VERSION_PATH}"2728OUTPUT="$(NVM_INSTALL_THIRD_PARTY_HOOK=succeed nvm install "${VERSION}")"29USE_OUTPUT="$(nvm use "${VERSION}")"30EXPECTED_OUTPUT="${VERSION} node std binary ${VERSION_PATH}31Downloading and installing node ${VERSION}...
14 unmodified lines
modified:nvm.sh+1 added-1 removed
128 unmodified lines
129 [ "$(nvm deactivate >/dev/null 2>&1 && command -v iojs)" != '' ]130}131132nvm_is_version_installed() {133 [ -n "${1-}" ] && [ -d "$(nvm_version_path "${1-}" 2> /dev/null)" ]133 [ -n "${1-}" ] && [ -x "$(nvm_version_path "$1" 2> /dev/null)"/bin/node ]134}135136nvm_print_npm_version() {137 if nvm_has "npm"; then
3519 unmodified lines