Browse Source

Make `nvm alias` list implicit "stable" and "unstable" aliases when they're not already aliases.

master
Jordan Harband 11 years ago
parent
commit
5dc7af6285
  1. 10
      nvm.sh
  2. 18
      test/fast/Aliases/Running "nvm alias" lists implicit aliases when they do not exist
  3. 35
      test/fast/Aliases/Running "nvm alias" lists manual aliases instead of implicit aliases when present
  4. 3
      test/fast/Aliases/teardown_dir

10
nvm.sh

@ -876,6 +876,16 @@ nvm() {
fi fi
fi fi
done 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 return
fi fi
if [ -z "$3" ]; then if [ -z "$3" ]; then

18
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"

35
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

3
test/fast/Aliases/teardown_dir

@ -6,3 +6,6 @@ for i in $(seq 1 10)
rm -rf "../../../v0.0.$i" rm -rf "../../../v0.0.$i"
done done
rm -f "../../../alias/stable"
rm -f "../../../alias/unstable"

Loading…
Cancel
Save