Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes #1744.

authored by Peter Dave Hello · committed by Jordan Harband · parent 25b7f26 · Browse files · 4 files+40 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+40 added−10 removed

  • tests:+22 added−0 removed
  • other:+18 added−10 removed

4 files+40 added−10 removed

modified:test/slow/nvm reinstall-packages/setup_dir+2 added
1 unmodified line
23\. ../../../nvm.sh4nvm install 0.10.285nvm install 0.10.296nvm install 4.7.17nvm install 4.7.289if [ -f ".nvmrc" ]; then10 mv .nvmrc .nvmrc.bak11fi
modified:test/slow/nvm reinstall-packages/teardown_dir+2 added
1 unmodified line
23\. ../../../nvm.sh4nvm uninstall v0.10.285nvm uninstall v0.10.296nvm uninstall v4.7.17nvm uninstall v4.7.289rm -f .nvmrc1011if [ -f ".nvmrc.bak" ]; then
2 unmodified lines
added:test/slow/nvm reinstall-packages/works with no installs+18 added
1#!/bin/sh23die () { echo "$@" ; exit 1; }45\. ../../../nvm.sh67get_packages() {8 npm list -g --depth=0 | \sed -e '1 d' -e 's/^.* \(.*\)@.*/\1/' -e '/^npm$/ d' | xargs9}1011nvm use 4.7.212ORIGINAL_PACKAGES=$(get_packages)1314nvm reinstall-packages 4.7.115FINAL_PACKAGES=$(get_packages)1617[ -z "${ORIGINAL_PACKAGES}" ] || die "original packages were not empty: ${ORIGINAL_PACKAGES}"18[ -z "${FINAL_PACKAGES}" ] || die "final packages were not empty: ${FINAL_PACKAGES}"
modified:nvm.sh+18 added-10 removed
3337 unmodified lines
3338 INSTALLS="${NPMLIST%% //// *}"3339 LINKS="${NPMLIST##* //// }"33403341 nvm_echo "Reinstalling global packages from $VERSION..."3342 if [ -n "${INSTALLS}" ]; then3342 nvm_echo "$INSTALLS" | command xargs npm install -g --quiet3343 nvm_echo "$INSTALLS" | command xargs npm install -g --quiet3344 else3345 nvm_echo "No installed global packages found..."3346 fi33473348 nvm_echo "Linking global packages from $VERSION..."3349 if [ -n "${LINKS}" ]; then3345 (3346 set -f; IFS='3350 (3351 set -f; IFS='3352' # necessary to turn off variable expansion except for newlines3348 for LINK in $LINKS; do3349 set +f; unset IFS # restore variable expansion3350 if [ -n "$LINK" ]; then3351 (nvm_cd "$LINK" && npm link)3352 fi3353 done3354 )3353 for LINK in $LINKS; do3354 set +f; unset IFS # restore variable expansion3355 if [ -n "$LINK" ]; then3356 (nvm_cd "$LINK" && npm link)3357 fi3358 done3359 )3360 else3361 nvm_echo "No linked global packages found..."3362 fi3363 ;;3364 "clear-cache" )3365 command rm -f "$NVM_DIR/v*" "$(nvm_version_dir)" 2>/dev/null3366 nvm_echo 'nvm cache cleared.'
184 unmodified lines