[Fix] allow `nvm unalias x` when `x` is a default alias, but shadowed

Fixes #2122.
Jordan Harband 2019-11-12 11:16:08 -08:00
parent 04ad1b528c
commit 73a513c389
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
2 changed files with 34 additions and 7 deletions

12
nvm.sh
View File

@ -3372,6 +3372,13 @@ nvm() {
local NVM_NODE_PREFIX local NVM_NODE_PREFIX
NVM_IOJS_PREFIX="$(nvm_iojs_prefix)" NVM_IOJS_PREFIX="$(nvm_iojs_prefix)"
NVM_NODE_PREFIX="$(nvm_node_prefix)" NVM_NODE_PREFIX="$(nvm_node_prefix)"
local NVM_ALIAS_EXISTS
NVM_ALIAS_EXISTS=0
if [ -f "${NVM_ALIAS_DIR}/${1-}" ]; then
NVM_ALIAS_EXISTS=1
fi
if [ $NVM_ALIAS_EXISTS -eq 0 ]; then
case "$1" in case "$1" in
"stable" | "unstable" | "${NVM_IOJS_PREFIX}" | "${NVM_NODE_PREFIX}" | "system") "stable" | "unstable" | "${NVM_IOJS_PREFIX}" | "${NVM_NODE_PREFIX}" | "system")
nvm_err "${1-} is a default (built-in) alias and cannot be deleted." nvm_err "${1-} is a default (built-in) alias and cannot be deleted."
@ -3379,7 +3386,10 @@ nvm() {
;; ;;
esac esac
[ ! -f "${NVM_ALIAS_DIR}/${1-}" ] && nvm_err "Alias ${1-} doesn't exist!" && return nvm_err "Alias ${1-} doesn't exist!"
return
fi
local NVM_ALIAS_ORIGINAL local NVM_ALIAS_ORIGINAL
NVM_ALIAS_ORIGINAL="$(nvm_alias "${1}")" NVM_ALIAS_ORIGINAL="$(nvm_alias "${1}")"
command rm -f "${NVM_ALIAS_DIR}/${1}" command rm -f "${NVM_ALIAS_DIR}/${1}"

View File

@ -0,0 +1,17 @@
#!/bin/sh
\. ../../../nvm.sh
die () { echo "$@" ; exit 1; }
OUTPUT="$(nvm unalias node 2>&1)"
EXPECTED_OUTPUT="node is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"
nvm alias node stable || die '`nvm alias node stable` failed'
nvm unalias node || die '`nvm unalias node` failed'
OUTPUT="$(nvm unalias node 2>&1)"
EXPECTED_OUTPUT="node is a default (built-in) alias and cannot be deleted."
[ "$OUTPUT" = "$EXPECTED_OUTPUT" ] || die "trying to remove a built-in alias should fail with '$EXPECTED_OUTPUT', got '$OUTPUT'"