From 4d524df191e28fe8321e2eb7f68b230e8a92e2e1 Mon Sep 17 00:00:00 2001 From: Peter Dave Hello Date: Tue, 27 Feb 2018 14:05:33 +0800 Subject: [PATCH] [Fix] Prevent install/link when no packages found, fix #1744 --- nvm.sh | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/nvm.sh b/nvm.sh index 4db2e0521f..5651dbfa5f 100644 --- a/nvm.sh +++ b/nvm.sh @@ -3339,19 +3339,27 @@ nvm() { LINKS="${NPMLIST##* //// }" nvm_echo "Reinstalling global packages from $VERSION..." - nvm_echo "$INSTALLS" | command xargs npm install -g --quiet + if [ -n "${INSTALLS}" ]; then + nvm_echo "$INSTALLS" | command xargs npm install -g --quiet + else + nvm_echo "No global packages found..." + fi nvm_echo "Linking global packages from $VERSION..." - ( - set -f; IFS=' + if [ -n "${LINKS}" ]; then + ( + set -f; IFS=' ' # necessary to turn off variable expansion except for newlines - for LINK in $LINKS; do - set +f; unset IFS # restore variable expansion - if [ -n "$LINK" ]; then - (nvm_cd "$LINK" && npm link) - fi - done - ) + for LINK in $LINKS; do + set +f; unset IFS # restore variable expansion + if [ -n "$LINK" ]; then + (nvm_cd "$LINK" && npm link) + fi + done + ) + else + nvm_echo "No global packages found..." + fi ;; "clear-cache" ) command rm -f "$NVM_DIR/v*" "$(nvm_version_dir)" 2>/dev/null