[Fix] `nvm_alias`: ensure `lts/-1` returns the one before `lts/*`

Fixes #2461
Rodrigo Espinosa de los Monteros 2021-03-11 16:22:31 -05:00 committed by Jordan Harband
parent 641f86879f
commit 4da7f101a2
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
2 changed files with 6 additions and 3 deletions

1
nvm.sh
View File

@ -994,6 +994,7 @@ nvm_alias() {
if [ "$(expr "${ALIAS}" : '^lts/-[1-9][0-9]*$')" -gt 0 ]; then if [ "$(expr "${ALIAS}" : '^lts/-[1-9][0-9]*$')" -gt 0 ]; then
local N local N
N="$(echo "${ALIAS}" | cut -d '-' -f 2)" N="$(echo "${ALIAS}" | cut -d '-' -f 2)"
N=$((N+1))
local RESULT local RESULT
RESULT="$(command ls "${NVM_ALIAS_DIR}/lts" | command tail -n "${N}" | command head -n 1)" RESULT="$(command ls "${NVM_ALIAS_DIR}/lts" | command tail -n "${N}" | command head -n 1)"
if [ "${RESULT}" != '*' ]; then if [ "${RESULT}" != '*' ]; then

View File

@ -25,10 +25,12 @@ LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
N=0 N=0
while IFS= read -r LTS; do while IFS= read -r LTS; do
if [ $N -gt 0 ]; then
EXPECTED="$(nvm_alias "lts/${LTS}")"
ACTUAL="$(nvm_alias "lts/-${N}")"
[ "${EXPECTED}" = "${ACTUAL}" ] || die "\`nvm_alias lts/-${N}\` was \`${ACTUAL}\`; expected \`${EXPECTED}\`"
fi
N=$(($N+1)) N=$(($N+1))
EXPECTED="$(nvm_alias "lts/${LTS}")"
ACTUAL="$(nvm_alias "lts/-${N}")"
[ "${EXPECTED}" = "${ACTUAL}" ] || die "\`nvm_alias lts/-${N}\` was \`${ACTUAL}\`; expected \`${EXPECTED}\`"
done < "${LTS_NAMES_PATH}" done < "${LTS_NAMES_PATH}"
cleanup cleanup