diff --git a/nvm.sh b/nvm.sh index 9e7af08..240e53f 100644 --- a/nvm.sh +++ b/nvm.sh @@ -496,7 +496,9 @@ nvm() { if [ -d "$(nvm_version_path "$VERSION")" ]; then echo "$VERSION is already installed." >&2 - nvm use "$VERSION" + if nvm use "$VERSION" && [ ! -z "$COPY_PACKAGES_FROM" ] && [ "~$COPY_PACKAGES_FROM" != "~N/A" ]; then + nvm copy-packages "$COPY_PACKAGES_FROM" + fi return $? fi @@ -526,7 +528,9 @@ nvm() { mv "$tmpdir" "$(nvm_version_path "$VERSION")" ) then - nvm use $VERSION + if nvm use "$VERSION" && [ ! -z "$COPY_PACKAGES_FROM" ] && [ "~$COPY_PACKAGES_FROM" != "~N/A" ]; then + nvm copy-packages "$COPY_PACKAGES_FROM" + fi return $? else echo "Binary download failed, trying source." >&2 @@ -570,7 +574,9 @@ nvm() { $make $MAKE_CXX install ) then - nvm use $VERSION + if nvm use "$VERSION" && [ ! -z "$COPY_PACKAGES_FROM" ] && [ "~$COPY_PACKAGES_FROM" != "~N/A" ]; then + nvm copy-packages "$COPY_PACKAGES_FROM" + fi if ! nvm_has "npm" ; then echo "Installing npm..." if nvm_version_greater 0.2.0 "$VERSION"; then @@ -589,6 +595,8 @@ nvm() { echo "nvm: install $VERSION failed!" >&2 return 1 fi + + return $? ;; "uninstall" ) [ $# -ne 2 ] && nvm help && return diff --git a/test/installation/install while copying packages b/test/installation/install while copying packages new file mode 100755 index 0000000..45cafb5 --- /dev/null +++ b/test/installation/install while copying packages @@ -0,0 +1,34 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../nvm.sh + +# 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 + +# Check +[ -d ../../v0.9.7 ] || die "nvm install 0.9.7 didn't install" + +nvm use 0.9.7 + +node --version | grep v0.9.7 > /dev/null || die "nvm use 0.9.7 failed" + +npm install -g is-nan@1.0.1 || die "npm install -g is-nan failed" +npm list --global | grep is-nan > /dev/null || die "is-nan 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 install 0.9.12 --copy-packages-from=0.9 || die "nvm install 0.9.12 --copy-packages-from=0.9 failed" + +[ -d ../../v0.9.12 ] || die "nvm install 0.9.12 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" + +npm list --global | grep is-nan > /dev/null || die "is-nan isn't installed" +