Skip to content

Commit

Permalink
[Fix] nvm install -b: when no binary is available, fail and output …
Browse files Browse the repository at this point in the history
…a clear message
  • Loading branch information
ljharb committed Aug 1, 2024
1 parent 423ee82 commit 271720e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
38 changes: 22 additions & 16 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3558,6 +3558,10 @@ nvm() {
EXIT_CODE=$?
else
EXIT_CODE=-1
if [ $nosource -eq 1 ]; then
nvm_err "Binary download is not available for ${VERSION}"
EXIT_CODE=3
fi
fi

if [ $EXIT_CODE -ne 0 ]; then
Expand All @@ -3575,25 +3579,27 @@ nvm() {
fi
fi

if [ $EXIT_CODE -eq 0 ] && nvm_use_if_needed "${VERSION}" && nvm_install_npm_if_needed "${VERSION}"; then
if [ -n "${LTS-}" ]; then
nvm_ensure_default_set "lts/${LTS}"
if [ $EXIT_CODE -eq 0 ]; then
if nvm_use_if_needed "${VERSION}" && nvm_install_npm_if_needed "${VERSION}"; then
if [ -n "${LTS-}" ]; then
nvm_ensure_default_set "lts/${LTS}"
else
nvm_ensure_default_set "${provided_version}"
fi
if [ "${NVM_UPGRADE_NPM}" = 1 ]; then
nvm install-latest-npm
EXIT_CODE=$?
fi
if [ $EXIT_CODE -eq 0 ] && [ -z "${SKIP_DEFAULT_PACKAGES-}" ]; then
nvm_install_default_packages
fi
if [ $EXIT_CODE -eq 0 ] && [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_${REINSTALL_PACKAGES_FROM}" != "_N/A" ]; then
nvm reinstall-packages "${REINSTALL_PACKAGES_FROM}"
EXIT_CODE=$?
fi
else
nvm_ensure_default_set "${provided_version}"
fi
if [ "${NVM_UPGRADE_NPM}" = 1 ]; then
nvm install-latest-npm
EXIT_CODE=$?
fi
if [ $EXIT_CODE -eq 0 ] && [ -z "${SKIP_DEFAULT_PACKAGES-}" ]; then
nvm_install_default_packages
fi
if [ $EXIT_CODE -eq 0 ] && [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_${REINSTALL_PACKAGES_FROM}" != "_N/A" ]; then
nvm reinstall-packages "${REINSTALL_PACKAGES_FROM}"
EXIT_CODE=$?
fi
else
EXIT_CODE=$?
fi

return $EXIT_CODE
Expand Down
16 changes: 16 additions & 0 deletions test/fast/Unit tests/nvm install -b
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh

die () { echo "$@" ; exit 1; }

\. ../../../nvm.sh

VERSION="0.7.0"

EXIT_CODE=$(nvm install -b "${VERSION}" ; echo $?)

[ $EXIT_CODE -eq 3 ] || die "Expected exit code 3, got ${EXIT_CODE}"

ACTUAL="$(nvm install -b "${VERSION}" 2>&1)"
EXPECTED="Binary download is not available for v${VERSION}"

[ "${ACTUAL}" = "${EXPECTED}" ] || die "Expected >${EXPECTED}<, got >${ACTUAL}<"

0 comments on commit 271720e

Please sign in to comment.