From 78a5e3fadf8552d8308e97ec0d3073c0671721fe Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 31 Jul 2014 19:27:58 -0700 Subject: [PATCH 1/2] Attempt to improve `nvm copy-packages` --- nvm.sh | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/nvm.sh b/nvm.sh index aa46581..5389b2d 100644 --- a/nvm.sh +++ b/nvm.sh @@ -726,17 +726,15 @@ nvm() { nvm help return 127 fi - VERSION=`nvm_version $2` + VERSION=$(nvm_version "$2") local ROOT - ROOT=`(nvm use $VERSION && npm -g root)` - local ROOTDEPTH - ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1)) + ROOT=$(nvm use $VERSION && npm -g root) # declare local INSTALLS first, otherwise it doesn't work in zsh local INSTALLS - INSTALLS=`nvm use $VERSION > /dev/null && npm -g -p ll | \grep "$ROOT\/[^/]\+$" | cut -d '/' -f $(($ROOTDEPTH + 2)) | cut -d ":" -f 2 | \grep -v npm | tr "\n" " "` + INSTALLS=$(nvm use $VERSION > /dev/null && npm list --global --parseable --depth=0 2> /dev/null | tail -n +2 | grep -o -e '/[^/]*$' | cut -c 2- | xargs) - npm install -g ${INSTALLS[@]} + npm install -g --quiet $INSTALLS ;; "clear-cache" ) rm -f $NVM_DIR/v* 2>/dev/null From b8fe75e93a58662bd0b548eb3f61b6307a60210a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 31 Jul 2014 19:46:08 -0700 Subject: [PATCH 2/2] Tests for `nvm copy-packages` --- test/slow/nvm copy-packages/setup_dir | 10 +++++++++ .../nvm copy-packages/should work as expected | 21 +++++++++++++++++++ test/slow/nvm copy-packages/teardown_dir | 12 +++++++++++ 3 files changed, 43 insertions(+) create mode 100755 test/slow/nvm copy-packages/setup_dir create mode 100755 test/slow/nvm copy-packages/should work as expected create mode 100755 test/slow/nvm copy-packages/teardown_dir diff --git a/test/slow/nvm copy-packages/setup_dir b/test/slow/nvm copy-packages/setup_dir new file mode 100755 index 0000000..c550f69 --- /dev/null +++ b/test/slow/nvm copy-packages/setup_dir @@ -0,0 +1,10 @@ +#!/bin/sh + +. ../../../nvm.sh +nvm install 0.10.28 +nvm install 0.10.29 + +if [ -f ".nvmrc" ]; then + mv .nvmrc .nvmrc.bak +fi + diff --git a/test/slow/nvm copy-packages/should work as expected b/test/slow/nvm copy-packages/should work as expected new file mode 100755 index 0000000..21f10df --- /dev/null +++ b/test/slow/nvm copy-packages/should work as expected @@ -0,0 +1,21 @@ +#!/bin/sh + +die () { echo "$@" ; exit 1; } + +. ../../../nvm.sh + +nvm use 0.10.28 + +EXPECTED_PACKAGES="autoprefixer bower david eslint grunt-cli grunth-cli http-server jshint marked node-gyp npm recursive-blame uglify-js yo" + +npm install -g --quiet $EXPECTED_PACKAGES + +nvm use 0.10.29 +ORIGINAL_PACKAGES=$(npm list --global --parseable --depth=0 2> /dev/null | tail -n +2 | grep -o -e '/[^/]*$' | cut -c 2- | sort | uniq | xargs) + +nvm copy-packages 0.10.28 +FINAL_PACKAGES=$(npm list --global --parseable --depth=0 2> /dev/null | tail -n +2 | grep -o -e '/[^/]*$' | cut -c 2- | sort | uniq | xargs) + +[ "$FINAL_PACKAGES" = "$EXPECTED_PACKAGES" ] || die "final packages ($FINAL_PACKAGES) did not match expected packages ($EXPECTED_PACKAGES)" +[ "$ORIGINAL_PACKAGES" != "$FINAL_PACKAGES" ] || die "original packages matched final packages ($ORIGINAL_PACKAGES)" + diff --git a/test/slow/nvm copy-packages/teardown_dir b/test/slow/nvm copy-packages/teardown_dir new file mode 100755 index 0000000..1282eb4 --- /dev/null +++ b/test/slow/nvm copy-packages/teardown_dir @@ -0,0 +1,12 @@ +#!/bin/sh + +. ../../../nvm.sh +nvm uninstall v0.10.28 +nvm uninstall v0.10.29 + +rm -f .nvmrc + +if [ -f ".nvmrc.bak" ]; then + mv .nvmrc.bak .nvmrc +fi +