From 56c40cfa3cd17c37c1c7f56fe19580beb8e35db7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 22 Aug 2014 02:19:56 -0700 Subject: [PATCH 1/5] Don't try to copy `npm` itself with `nvm copy-packages`. Fixes #504. --- nvm.sh | 2 +- test/slow/nvm copy-packages/should work as expected | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nvm.sh b/nvm.sh index 7f734fe..50e2586 100644 --- a/nvm.sh +++ b/nvm.sh @@ -791,7 +791,7 @@ nvm() { # declare local INSTALLS first, otherwise it doesn't work in zsh local INSTALLS - 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) + INSTALLS=$(nvm use $VERSION > /dev/null && npm list --global --parseable --depth=0 2> /dev/null | tail -n +2 | \grep -o -e '/[^/]*$' | cut -c 2- | \grep -v npm | xargs) npm install -g --quiet $INSTALLS ;; diff --git a/test/slow/nvm copy-packages/should work as expected b/test/slow/nvm copy-packages/should work as expected index 21f10df..2ba3efc 100755 --- a/test/slow/nvm copy-packages/should work as expected +++ b/test/slow/nvm copy-packages/should work as expected @@ -6,15 +6,15 @@ die () { echo "$@" ; exit 1; } 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" +EXPECTED_PACKAGES="autoprefixer bower david eslint grunt-cli grunth-cli http-server jshint marked node-gyp 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) +ORIGINAL_PACKAGES=$(npm list --global --parseable --depth=0 2> /dev/null | tail -n +2 | \grep -o -e '/[^/]*$' | cut -c 2- | \grep -v npm | 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=$(npm list --global --parseable --depth=0 2> /dev/null | tail -n +2 | \grep -o -e '/[^/]*$' | cut -c 2- | \grep -v npm | 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)" From 4b3d6f1760b3e3e867d892360cee36622995997c Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 22 Aug 2014 02:44:04 -0700 Subject: [PATCH 2/5] Properly pass a space-separated list of packages to `npm install` Fixes #490. --- nvm.sh | 2 +- test/slow/nvm copy-packages/should work as expected | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index 50e2586..dd4ea74 100644 --- a/nvm.sh +++ b/nvm.sh @@ -793,7 +793,7 @@ nvm() { local INSTALLS INSTALLS=$(nvm use $VERSION > /dev/null && npm list --global --parseable --depth=0 2> /dev/null | tail -n +2 | \grep -o -e '/[^/]*$' | cut -c 2- | \grep -v npm | xargs) - npm install -g --quiet $INSTALLS + echo "$INSTALLS" | xargs npm install -g --quiet ;; "clear-cache" ) rm -f $NVM_DIR/v* "$(nvm_version_dir)" 2>/dev/null diff --git a/test/slow/nvm copy-packages/should work as expected b/test/slow/nvm copy-packages/should work as expected index 2ba3efc..66859eb 100755 --- a/test/slow/nvm copy-packages/should work as expected +++ b/test/slow/nvm copy-packages/should work as expected @@ -8,7 +8,7 @@ nvm use 0.10.28 EXPECTED_PACKAGES="autoprefixer bower david eslint grunt-cli grunth-cli http-server jshint marked node-gyp recursive-blame uglify-js yo" -npm install -g --quiet $EXPECTED_PACKAGES +echo "$EXPECTED_PACKAGES" | xargs npm install -g --quiet 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- | \grep -v npm | sort | uniq | xargs) From 5ee955bb622749e383b9946f365cc12525028fc7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 29 Aug 2014 00:12:02 -0700 Subject: [PATCH 3/5] Remove unused $ROOT variable. --- nvm.sh | 2 -- 1 file changed, 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index dd4ea74..820624e 100644 --- a/nvm.sh +++ b/nvm.sh @@ -786,8 +786,6 @@ nvm() { return 127 fi VERSION=$(nvm_version "$2") - local ROOT - ROOT=$(nvm use $VERSION && npm -g root) # declare local INSTALLS first, otherwise it doesn't work in zsh local INSTALLS From 603253b0cb333f4f8081653bb3223f3fa49158d5 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 29 Aug 2014 00:12:16 -0700 Subject: [PATCH 4/5] Quote the version. --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 820624e..7ed56e0 100644 --- a/nvm.sh +++ b/nvm.sh @@ -785,7 +785,7 @@ nvm() { nvm help return 127 fi - VERSION=$(nvm_version "$2") + VERSION="$(nvm_version "$2")" # declare local INSTALLS first, otherwise it doesn't work in zsh local INSTALLS From 214ce8853bc19dff38a7bb50a3e8b09986903f8b Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 2 Sep 2014 15:04:35 -0700 Subject: [PATCH 5/5] `npm ls` has a bug in some versions when "--parseable --depth=0" is used together. --- nvm.sh | 2 +- test/slow/nvm copy-packages/should work as expected | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nvm.sh b/nvm.sh index 7ed56e0..e45a53e 100644 --- a/nvm.sh +++ b/nvm.sh @@ -789,7 +789,7 @@ nvm() { # declare local INSTALLS first, otherwise it doesn't work in zsh local INSTALLS - INSTALLS=$(nvm use $VERSION > /dev/null && npm list --global --parseable --depth=0 2> /dev/null | tail -n +2 | \grep -o -e '/[^/]*$' | cut -c 2- | \grep -v npm | xargs) + INSTALLS=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | xargs) echo "$INSTALLS" | xargs npm install -g --quiet ;; diff --git a/test/slow/nvm copy-packages/should work as expected b/test/slow/nvm copy-packages/should work as expected index 66859eb..e599609 100755 --- a/test/slow/nvm copy-packages/should work as expected +++ b/test/slow/nvm copy-packages/should work as expected @@ -11,10 +11,10 @@ EXPECTED_PACKAGES="autoprefixer bower david eslint grunt-cli grunth-cli http-ser echo "$EXPECTED_PACKAGES" | xargs npm install -g --quiet 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- | \grep -v npm | sort | uniq | xargs) +ORIGINAL_PACKAGES=$(npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | 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- | \grep -v npm | sort | uniq | xargs) +FINAL_PACKAGES=$(npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | 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)"