Merge pull request #501 from creationix/fix_copy_packages

Fix nvm copy-packages
master
Jordan Harband 2014-08-16 02:35:15 -07:00
commit 6baa9a0918
4 changed files with 47 additions and 6 deletions

10
nvm.sh
View File

@ -726,17 +726,15 @@ nvm() {
nvm help nvm help
return 127 return 127
fi fi
VERSION=`nvm_version $2` VERSION=$(nvm_version "$2")
local ROOT local ROOT
ROOT=`(nvm use $VERSION && npm -g root)` ROOT=$(nvm use $VERSION && npm -g root)
local ROOTDEPTH
ROOTDEPTH=$((`echo $ROOT | sed 's/[^\/]//g'|wc -m` -1))
# declare local INSTALLS first, otherwise it doesn't work in zsh # declare local INSTALLS first, otherwise it doesn't work in zsh
local INSTALLS 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" ) "clear-cache" )
rm -f $NVM_DIR/v* 2>/dev/null rm -f $NVM_DIR/v* 2>/dev/null

View File

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

View File

@ -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)"

View File

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