[Fix] nvm install -b: when no binary is available, fail and output a clear message

This commit is contained in:
Jordan Harband 2024-08-01 13:57:22 -07:00
parent 423ee82b4c
commit 271720ebfc
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
2 changed files with 38 additions and 16 deletions

8
nvm.sh
View File

@ -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
@ -3575,7 +3579,8 @@ nvm() {
fi
fi
if [ $EXIT_CODE -eq 0 ] && nvm_use_if_needed "${VERSION}" && nvm_install_npm_if_needed "${VERSION}"; then
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
@ -3595,6 +3600,7 @@ nvm() {
else
EXIT_CODE=$?
fi
fi
return $EXIT_CODE
;;

View File

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