[Fix] `nvm alias`/`nvm_list_aliases`: support `lts/` aliases

See #2692
Jordan Harband 2021-12-16 15:54:38 -08:00
parent 2459d17741
commit 430860a8be
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
4 changed files with 30 additions and 0 deletions

5
nvm.sh
View File

@ -988,6 +988,11 @@ nvm_list_aliases() {
NVM_ALIAS_DIR="$(nvm_alias_path)" NVM_ALIAS_DIR="$(nvm_alias_path)"
command mkdir -p "${NVM_ALIAS_DIR}/lts" command mkdir -p "${NVM_ALIAS_DIR}/lts"
if [ "${ALIAS}" != "${ALIAS#lts/}" ]; then
nvm_alias "${ALIAS}"
return $?
fi
nvm_is_zsh && unsetopt local_options nomatch nvm_is_zsh && unsetopt local_options nomatch
( (
local ALIAS_PATH local ALIAS_PATH

View File

@ -0,0 +1,23 @@
#!/bin/sh
\. ../../../nvm.sh
die () {
echo "$@"
exit 1
}
set -e
nvm_alias_path() {
nvm_echo "../../../alias"
}
MOCKS_DIR="../Unit tests/mocks"
EXPECTED_OUTPUT="$(cat "$MOCKS_DIR/lts-star.txt")"
STDOUT_OUTPUT="$(nvm_list_aliases "lts/*")"
STDERR_OUTPUT="$(nvm_list_aliases "lts/*" 2>&1 >/dev/null)"
[ -z "${STDERR_OUTPUT}" ] || die "expected no stderr output, got >${STDERR_OUTPUT}<"
[ "${STDOUT_OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "expected ${EXPECTED_OUTPUT}, got >${STDOUT_OUTPUT}<"

View File

@ -0,0 +1 @@
lts/gallium

View File

@ -32,6 +32,7 @@ nvm ls-remote node > "$MOCKS_DIR/nvm ls-remote node.txt"
nvm ls-remote iojs > "$MOCKS_DIR/nvm ls-remote iojs.txt" nvm ls-remote iojs > "$MOCKS_DIR/nvm ls-remote iojs.txt"
nvm_print_implicit_alias remote stable > "$MOCKS_DIR/nvm_print_implicit_alias remote stable.txt" nvm_print_implicit_alias remote stable > "$MOCKS_DIR/nvm_print_implicit_alias remote stable.txt"
nvm_ls_remote stable > "$MOCKS_DIR/nvm_ls_remote stable.txt" nvm_ls_remote stable > "$MOCKS_DIR/nvm_ls_remote stable.txt"
nvm alias "lts/*" > "$MOCKS_DIR/lts-star.txt"
set +e set +e
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly/ nvm_ls_remote > "$MOCKS_DIR/nvm_ls_remote nightly.txt" NVM_NODEJS_ORG_MIRROR=https://nodejs.org/download/nightly/ nvm_ls_remote > "$MOCKS_DIR/nvm_ls_remote nightly.txt"