Error out early if the --copy-packages-from version is invalid.
parent
eddbe15ee8
commit
622fdd2cd0
8
nvm.sh
8
nvm.sh
|
@ -486,6 +486,14 @@ nvm() {
|
||||||
shift
|
shift
|
||||||
done
|
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
|
if [ -d "$(nvm_version_path "$VERSION")" ]; then
|
||||||
echo "$VERSION is already installed." >&2
|
echo "$VERSION is already installed." >&2
|
||||||
nvm use "$VERSION"
|
nvm use "$VERSION"
|
||||||
|
|
|
@ -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"
|
||||||
|
|
Loading…
Reference in New Issue