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

Joshua Li 2018-05-31 15:26:30 -07:00 committed by Jordan Harband
parent a5f42d9cea
commit 0cdc184168
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
6 changed files with 27 additions and 19 deletions

2
nvm.sh
View File

@ -130,7 +130,7 @@ nvm_has_system_iojs() {
} }
nvm_is_version_installed() { 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() { nvm_print_npm_version() {

View File

@ -1,11 +1,14 @@
#!/bin/sh #!/bin/sh
\. ../../../nvm.sh
\. ../../common.sh
for i in $(seq 1 10) for i in $(seq 1 10)
do do
echo 0.0.$i > ../../../alias/test-stable-$i 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 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 echo 0.2.$i > ../../../alias/test-iojs-$i
mkdir -p ../../../versions/io.js/v0.2.$i make_fake_iojs v0.2.$i
done done

View File

@ -2,13 +2,14 @@
set -ex set -ex
mkdir -p ../../v0.2.3
die () { echo "$@" ; exit 1; } die () { echo "$@" ; exit 1; }
[ `expr $PATH : ".*v0.2.3/.*/bin.*"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2
\. ../../nvm.sh \. ../../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" 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" [ `expr "$PATH" : ".*v0.2.3/.*/bin.*"` != 0 ] || die "PATH not set up properly"

View File

@ -2,11 +2,11 @@
set -ex set -ex
cd ../.. \. ../../nvm.sh
mkdir v0.0.1 \. ../common.sh
mkdir src/node-v0.0.1
make_fake_node v0.0.1
. ./nvm.sh
nvm uninstall v0.0.1 nvm uninstall v0.0.1
[ ! -d 'v0.0.1' ] && [ ! -d 'src/node-v0.0.1/files' ] [ ! -d 'v0.0.1' ]

View File

@ -2,13 +2,11 @@
set -ex set -ex
cd ../.. \. ../../nvm.sh
mkdir v0.0.1 \. ../common.sh
mkdir src/node-v0.0.1
sudo touch v0.0.1/sudo make_fake_node v0.0.1
sudo touch ""$(nvm_version_path v0.0.1)"/sudo"
. ./nvm.sh
RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1 || echo)" RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1 || echo)"
CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder" CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder"

View File

@ -19,6 +19,12 @@ fail() {
! nvm_is_version_installed "${VERSION}" || nvm uninstall "${VERSION}" || die 'uninstall failed' ! 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}")" OUTPUT="$(NVM_INSTALL_THIRD_PARTY_HOOK=succeed nvm install "${VERSION}")"
USE_OUTPUT="$(nvm use "${VERSION}")" USE_OUTPUT="$(nvm use "${VERSION}")"
EXPECTED_OUTPUT="${VERSION} node std binary ${VERSION_PATH} EXPECTED_OUTPUT="${VERSION} node std binary ${VERSION_PATH}