Merge pull request #530 from creationix/copy_packages_from_on_install
nvm install: Add --copy-packages-from optionmaster
commit
ddb25ed5a3
29
nvm.sh
29
nvm.sh
|
@ -472,16 +472,33 @@ nvm() {
|
|||
|
||||
VERSION=`nvm_remote_version $provided_version`
|
||||
ADDITIONAL_PARAMETERS=''
|
||||
local PROVIDED_COPY_PACKAGES_FROM
|
||||
local COPY_PACKAGES_FROM
|
||||
|
||||
while [ $# -ne 0 ]
|
||||
do
|
||||
if [ "~$(echo "$1" | cut -c 1-21)" = "~--copy-packages-from=" ]; then
|
||||
PROVIDED_COPY_PACKAGES_FROM="$(echo "$1" | cut -c 22-)"
|
||||
COPY_PACKAGES_FROM="$(nvm_version "$PROVIDED_COPY_PACKAGES_FROM")"
|
||||
else
|
||||
ADDITIONAL_PARAMETERS="$ADDITIONAL_PARAMETERS $1"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
if [ "~$(nvm_format_version "$PROVIDED_COPY_PACKAGES_FROM")" = "~$VERSION" ]; then
|
||||
echo "You can't copy global packages from the same version of node you're installing." >&2
|
||||
return 4
|
||||
elif [ ! -z "$PROVIDED_COPY_PACKAGES_FROM" ] && [ "~$COPY_PACKAGES_FROM" = "~N/A" ]; then
|
||||
echo "If --copy-packages-from is provided, it must point to an installed version of node." >&2
|
||||
return 5
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
|
@ -511,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
|
||||
|
@ -555,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
|
||||
|
@ -574,6 +595,8 @@ nvm() {
|
|||
echo "nvm: install $VERSION failed!" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
return $?
|
||||
;;
|
||||
"uninstall" )
|
||||
[ $# -ne 2 ] && nvm help && return
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; cleanup ; exit 1; }
|
||||
cleanup () {
|
||||
rm -rf ../../v0.10.4
|
||||
}
|
||||
|
||||
mkdir ../../v0.10.4
|
||||
|
||||
. ../../nvm.sh
|
||||
|
||||
nvm deactivate >/dev/null 2>&1
|
||||
|
||||
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --copy-packages-from=0.11 2>&1)"
|
||||
EXPECTED_ERROR_MSG="If --copy-packages-from is provided, it must point to an installed version of node."
|
||||
[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \
|
||||
|| die ""nvm install --copy-packages" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'"
|
||||
|
||||
INSTALL_EXIT_CODE="$(nvm install v0.10.5 --copy-packages-from=0.11 >/dev/null 2>&1; echo $?)"
|
||||
[ "~$INSTALL_EXIT_CODE" = "~5" ] \
|
||||
|| die ""nvm install --copy-packages" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE"
|
||||
|
||||
INSTALL_ERROR_MSG="$(nvm install v0.10.5 --copy-packages-from=0.10.5 2>&1)"
|
||||
EXPECTED_ERROR_MSG="You can't copy global packages from the same version of node you're installing."
|
||||
[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \
|
||||
|| die ""nvm install --copy-packages" should fail when given the same version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'"
|
||||
|
||||
INSTALL_EXIT_CODE="$(nvm install v0.10.5 --copy-packages-from=0.10.5 >/dev/null 2>&1; echo $?)"
|
||||
[ "~$INSTALL_EXIT_CODE" = "~4" ] \
|
||||
|| die ""nvm install --copy-packages" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE"
|
||||
|
|
@ -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"
|
||||
|
Loading…
Reference in New Issue