Copy packages when applicable, whenever `nvm install` would normally `nvm use` and exit.

master
Jordan Harband 2014-09-21 11:14:18 -07:00
parent 622fdd2cd0
commit 486d14f5f8
2 changed files with 45 additions and 3 deletions

14
nvm.sh
View File

@ -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

View File

@ -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"