From e01bcb740b4cfcfcd4a3cb4e30d0c3812d579d07 Mon Sep 17 00:00:00 2001 From: Andrew Crites Date: Thu, 9 Apr 2015 01:20:51 -0400 Subject: [PATCH 1/3] Include npm version when displaying results of switch. When running nvm use, successful changing of versions lists the new node version. The npm version may also be switched, but this is not listed. This commit updates nvm to display the npm version that was switched to alongside the node version --- nvm.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/nvm.sh b/nvm.sh index ef9e67e..7b4a3e2 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1360,10 +1360,10 @@ nvm() { if [ "_$VERSION" = '_system' ]; then if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then - echo "Now using system version of node: $(node -v 2>/dev/null)." + echo "Now using system version of node: $(node -v 2>/dev/null) (npm v$(npm --version 2>/dev/null))" return elif nvm_has_system_iojs && nvm deactivate >/dev/null 2>&1; then - echo "Now using system version of io.js: $(iojs --version 2>/dev/null)." + echo "Now using system version of io.js: $(iojs --version 2>/dev/null) (npm v$(npm --version 2>/dev/null))" return else echo "System version of node not found." >&2 @@ -1407,10 +1407,11 @@ nvm() { command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current" fi if nvm_is_iojs_version "$VERSION"; then - echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")" + echo -n "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")" else - echo "Now using node $VERSION" + echo -n "Now using node $VERSION" fi + echo " (npm v$(npm --version 2>/dev/null))" ;; "run" ) local provided_version From caa69bc500e50c946f0b4b4ff5681d1d9abd25cb Mon Sep 17 00:00:00 2001 From: Andrew Crites Date: Thu, 9 Apr 2015 02:12:35 -0400 Subject: [PATCH 2/3] npm version: shell compatibility, test update * Update test string that checks printed node version to pass with additional npm version display * Remove echo -n for compatibility with shells that do not support it --- nvm.sh | 13 ++++++++----- ...ning \"nvm use system\" should work as expected" | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/nvm.sh b/nvm.sh index 7b4a3e2..d6a0e0e 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1359,11 +1359,13 @@ nvm() { fi if [ "_$VERSION" = '_system' ]; then + local NPM_VERSION + NPM_VERSION="(npm v$(npm --version 2>/dev/null))" if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then - echo "Now using system version of node: $(node -v 2>/dev/null) (npm v$(npm --version 2>/dev/null))" + echo "Now using system version of node: $(node -v 2>/dev/null) $NPM_VERSION" return elif nvm_has_system_iojs && nvm deactivate >/dev/null 2>&1; then - echo "Now using system version of io.js: $(iojs --version 2>/dev/null) (npm v$(npm --version 2>/dev/null))" + echo "Now using system version of io.js: $(iojs --version 2>/dev/null) $NPM_VERSION" return else echo "System version of node not found." >&2 @@ -1406,12 +1408,13 @@ nvm() { if [ "$NVM_SYMLINK_CURRENT" = true ]; then command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current" fi + local NPM_VERSION + NPM_VERSION="(npm v$(npm --version 2>/dev/null))" if nvm_is_iojs_version "$VERSION"; then - echo -n "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")" + echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION") $NPM_VERSION" else - echo -n "Now using node $VERSION" + echo "Now using node $VERSION $NPM_VERSION" fi - echo " (npm v$(npm --version 2>/dev/null))" ;; "run" ) local provided_version diff --git "a/test/fast/Running \"nvm use system\" should work as expected" "b/test/fast/Running \"nvm use system\" should work as expected" index 9b4e850..2ed9638 100755 --- "a/test/fast/Running \"nvm use system\" should work as expected" +++ "b/test/fast/Running \"nvm use system\" should work as expected" @@ -5,7 +5,7 @@ die () { echo $@ ; exit 1; } . ../../nvm.sh nvm_has_system_node() { return 0; } -[ "$(nvm use system 2>&1 | tail -n1)" = "Now using system version of node: $(node -v)." ] || die "Could not use system version of node" +[ "$(nvm use system 2>&1 | tail -n1)" = "Now using system version of node: $(node -v) (npm v$(npm -v))" ] || die "Could not use system version of node" nvm_has_system_node() { return 1; } [ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found" From e4149c380b431b279c5a3dc6f7be6c8d47edc387 Mon Sep 17 00:00:00 2001 From: Andrew Crites Date: Thu, 9 Apr 2015 02:31:57 -0400 Subject: [PATCH 3/3] Only print npm version if it exists --- nvm.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index d6a0e0e..3d6f979 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1360,7 +1360,9 @@ nvm() { if [ "_$VERSION" = '_system' ]; then local NPM_VERSION - NPM_VERSION="(npm v$(npm --version 2>/dev/null))" + if nvm_has "npm"; then + NPM_VERSION="(npm v$(npm --version 2>/dev/null))" + fi if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then echo "Now using system version of node: $(node -v 2>/dev/null) $NPM_VERSION" return @@ -1409,7 +1411,9 @@ nvm() { command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current" fi local NPM_VERSION - NPM_VERSION="(npm v$(npm --version 2>/dev/null))" + if nvm_has "npm"; then + NPM_VERSION="(npm v$(npm --version 2>/dev/null))" + fi if nvm_is_iojs_version "$VERSION"; then echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION") $NPM_VERSION" else