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 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 +