diff --git a/nvm.sh b/nvm.sh index db07f5e..e3c20f1 100644 --- a/nvm.sh +++ b/nvm.sh @@ -876,6 +876,16 @@ nvm() { fi fi done + + for ALIAS in "stable" "unstable"; do + if [ ! -f "$NVM_DIR/alias/$ALIAS" ]; then + if [ $# -lt 2 ] || [ "~$ALIAS" = "~$2" ]; then + DEST="$(nvm_print_implicit_alias local "$ALIAS")" + VERSION="$(nvm_version "$DEST")" + echo "$ALIAS -> $DEST (-> $VERSION) (default)" + fi + fi + done return fi if [ -z "$3" ]; then diff --git "a/test/fast/Aliases/Running \"nvm alias\" lists implicit aliases when they do not exist" "b/test/fast/Aliases/Running \"nvm alias\" lists implicit aliases when they do not exist" new file mode 100755 index 0000000..da91f11 --- /dev/null +++ "b/test/fast/Aliases/Running \"nvm alias\" lists implicit aliases when they do not exist" @@ -0,0 +1,18 @@ +#!/bin/sh + +. ../../../nvm.sh + +die () { echo $@ ; exit 1; } + +NVM_ALIAS_OUTPUT=$(nvm alias) + +EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" +STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" +echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_STABLE (-> $STABLE_VERSION) (default)$" \ + || die "nvm alias did not contain the default local stable node version" + +EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" +UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" +echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION) (default)$" \ + || die "nvm alias did not contain the default local unstable node version" + diff --git "a/test/fast/Aliases/Running \"nvm alias\" lists manual aliases instead of implicit aliases when present" "b/test/fast/Aliases/Running \"nvm alias\" lists manual aliases instead of implicit aliases when present" new file mode 100755 index 0000000..691ba66 --- /dev/null +++ "b/test/fast/Aliases/Running \"nvm alias\" lists manual aliases instead of implicit aliases when present" @@ -0,0 +1,35 @@ +#!/bin/sh + +. ../../../nvm.sh + +die () { echo $@ ; cleanup ; exit 1; } +cleanup () { + rm -rf ../../../v0.8.1 + rm -rf ../../../v0.9.1 +} + +mkdir ../../../v0.8.1 +mkdir ../../../v0.9.1 + +EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" +STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" + +EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" +UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" + +[ "_$STABLE_VERSION" != "_$UNSTABLE_VERSION" ] \ + || die "stable and unstable versions are the same!" + +nvm alias stable "$EXPECTED_UNSTABLE" +nvm alias unstable "$EXPECTED_STABLE" + +NVM_ALIAS_OUTPUT=$(nvm alias) + +echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION)$" \ + || die "nvm alias did not contain the overridden 'stable' alias" + +echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_STABLE (-> $STABLE_VERSION)$" \ + || die "nvm alias did not contain the overridden 'unstable' alias" + +cleanup + diff --git a/test/fast/Aliases/teardown_dir b/test/fast/Aliases/teardown_dir index 8ea87ce..f6a01c6 100755 --- a/test/fast/Aliases/teardown_dir +++ b/test/fast/Aliases/teardown_dir @@ -6,3 +6,6 @@ for i in $(seq 1 10) rm -rf "../../../v0.0.$i" done +rm -f "../../../alias/stable" +rm -f "../../../alias/unstable" +