[Fix] `reinstall-packages`: Prevent install/link when no packages found

Fixes #1744.
Peter Dave Hello 2018-02-27 14:05:33 +08:00 committed by Jordan Harband
parent 25b7f264d5
commit d6fa67166c
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
4 changed files with 40 additions and 10 deletions

8
nvm.sh
View File

@ -3339,9 +3339,14 @@ nvm() {
LINKS="${NPMLIST##* //// }" LINKS="${NPMLIST##* //// }"
nvm_echo "Reinstalling global packages from $VERSION..." nvm_echo "Reinstalling global packages from $VERSION..."
if [ -n "${INSTALLS}" ]; then
nvm_echo "$INSTALLS" | command xargs npm install -g --quiet nvm_echo "$INSTALLS" | command xargs npm install -g --quiet
else
nvm_echo "No installed global packages found..."
fi
nvm_echo "Linking global packages from $VERSION..." nvm_echo "Linking global packages from $VERSION..."
if [ -n "${LINKS}" ]; then
( (
set -f; IFS=' set -f; IFS='
' # necessary to turn off variable expansion except for newlines ' # necessary to turn off variable expansion except for newlines
@ -3352,6 +3357,9 @@ nvm() {
fi fi
done done
) )
else
nvm_echo "No linked global packages found..."
fi
;; ;;
"clear-cache" ) "clear-cache" )
command rm -f "$NVM_DIR/v*" "$(nvm_version_dir)" 2>/dev/null command rm -f "$NVM_DIR/v*" "$(nvm_version_dir)" 2>/dev/null

View File

@ -3,6 +3,8 @@
\. ../../../nvm.sh \. ../../../nvm.sh
nvm install 0.10.28 nvm install 0.10.28
nvm install 0.10.29 nvm install 0.10.29
nvm install 4.7.1
nvm install 4.7.2
if [ -f ".nvmrc" ]; then if [ -f ".nvmrc" ]; then
mv .nvmrc .nvmrc.bak mv .nvmrc .nvmrc.bak

View File

@ -3,6 +3,8 @@
\. ../../../nvm.sh \. ../../../nvm.sh
nvm uninstall v0.10.28 nvm uninstall v0.10.28
nvm uninstall v0.10.29 nvm uninstall v0.10.29
nvm uninstall v4.7.1
nvm uninstall v4.7.2
rm -f .nvmrc rm -f .nvmrc

View File

@ -0,0 +1,18 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
get_packages() {
npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | xargs
}
nvm use 4.7.2
ORIGINAL_PACKAGES=$(get_packages)
nvm reinstall-packages 4.7.1
FINAL_PACKAGES=$(get_packages)
[ -z "${ORIGINAL_PACKAGES}" ] || die "original packages were not empty: ${ORIGINAL_PACKAGES}"
[ -z "${FINAL_PACKAGES}" ] || die "final packages were not empty: ${FINAL_PACKAGES}"