Making `nvm install` use the version, even if it's already installed. Fixes #410

master
Jordan Harband 2014-05-05 22:46:46 -07:00
parent 29f582611b
commit ba1be9b4ea
2 changed files with 29 additions and 1 deletions

6
nvm.sh
View File

@ -306,7 +306,11 @@ nvm() {
shift
done
[ -d "$NVM_DIR/$VERSION" ] && echo "$VERSION is already installed." && return
if [ -d "$NVM_DIR/$VERSION" ]; then
echo "$VERSION is already installed."
nvm use "$VERSION"
return $?
fi
if [ "$VERSION" = "N/A" ]; then
echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions."

View File

@ -0,0 +1,24 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
[ "$(nvm install invalid.invalid)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message"
# Remove the stuff we're clobbering.
[ -e ../../../v0.9.7 ] && rm -R ../../../v0.9.7
[ -e ../../../v0.9.12 ] && rm -R ../../../v0.9.12
# Install from binary
nvm install 0.9.7
nvm install 0.9.12
nvm use 0.9.7
node --version | grep v0.9.7 || die "precondition failed: node doesn't start at 0.9.7"
nvm install 0.9.12
node --version | grep v0.9.12 || die "nvm install on already installed version doesn't use it"