diff --git a/nvm.sh b/nvm.sh index 0e195986ff1..10bcd3ceafa 100755 --- a/nvm.sh +++ b/nvm.sh @@ -2405,7 +2405,7 @@ nvm() { return $? fi - local NVM_INSTALL_SUCCESS + local NVM_INSTALL_EXIT_CODE if [ -n "${NVM_INSTALL_THIRD_PARTY_HOOK-}" ]; then nvm_err '** $NVM_INSTALL_THIRD_PARTY_HOOK env var set; dispatching to third-party installation method **' local NVM_METHOD_PREFERENCE @@ -2425,7 +2425,7 @@ nvm() { nvm_err '*** Third-party $NVM_INSTALL_THIRD_PARTY_HOOK env var claimed to succeed, but failed to install! ***' return 33 fi - NVM_INSTALL_SUCCESS=true + NVM_INSTALL_EXIT_CODE=0 else if [ "_$NVM_OS" = "_freebsd" ]; then @@ -2442,30 +2442,29 @@ nvm() { # skip binary install if "nobinary" option specified. if [ $nobinary -ne 1 ] && nvm_binary_available "$VERSION"; then - if nvm_install_binary "${FLAVOR}" std "${VERSION}"; then - NVM_INSTALL_SUCCESS=true - fi + nvm_install_binary "${FLAVOR}" std "${VERSION}" + NVM_INSTALL_EXIT_CODE=$? fi - if [ "$NVM_INSTALL_SUCCESS" != true ]; then + if [ "$NVM_INSTALL_EXIT_CODE" != 0 ]; then if [ -z "${NVM_MAKE_JOBS-}" ]; then nvm_get_make_jobs fi - if nvm_install_source "${FLAVOR}" std "${VERSION}" "${NVM_MAKE_JOBS}" "${ADDITIONAL_PARAMETERS}"; then - NVM_INSTALL_SUCCESS=true - fi + nvm_install_source "${FLAVOR}" std "${VERSION}" "${NVM_MAKE_JOBS}" "${ADDITIONAL_PARAMETERS}" + NVM_INSTALL_EXIT_CODE=$? fi fi - if [ "$NVM_INSTALL_SUCCESS" = true ] && nvm use "$VERSION"; then + if [ "$NVM_INSTALL_EXIT_CODE" = 0 ] && nvm use "$VERSION"; then nvm_ensure_default_set "$provided_version" if [ ! -z "$REINSTALL_PACKAGES_FROM" ] \ && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then nvm reinstall-packages "$REINSTALL_PACKAGES_FROM" + NVM_INSTALL_EXIT_CODE=$? fi fi - return $? + return "${NVM_INSTALL_EXIT_CODE}" ;; "uninstall" ) if [ $# -ne 1 ]; then