Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Prevent install/link when no packages found #1750

Merged
merged 1 commit into from Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 18 additions & 10 deletions nvm.sh
Expand Up @@ -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 installed 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 linked global packages found..."
fi
;;
"clear-cache" )
command rm -f "$NVM_DIR/v*" "$(nvm_version_dir)" 2>/dev/null
Expand Down
2 changes: 2 additions & 0 deletions test/slow/nvm reinstall-packages/setup_dir
Expand Up @@ -3,6 +3,8 @@
\. ../../../nvm.sh
nvm install 0.10.28
nvm install 0.10.29
nvm install 4.7.1
nvm install 4.7.2

if [ -f ".nvmrc" ]; then
mv .nvmrc .nvmrc.bak
Expand Down
2 changes: 2 additions & 0 deletions test/slow/nvm reinstall-packages/teardown_dir
Expand Up @@ -3,6 +3,8 @@
\. ../../../nvm.sh
nvm uninstall v0.10.28
nvm uninstall v0.10.29
nvm uninstall v4.7.1
nvm uninstall v4.7.2

rm -f .nvmrc

Expand Down
18 changes: 18 additions & 0 deletions test/slow/nvm reinstall-packages/works with no installs
@@ -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}"