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
master
Andrew Crites 2015-04-09 02:12:35 -04:00
parent e01bcb740b
commit caa69bc500
2 changed files with 9 additions and 6 deletions

13
nvm.sh
View File

@ -1359,11 +1359,13 @@ nvm() {
fi fi
if [ "_$VERSION" = '_system' ]; then 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 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 return
elif nvm_has_system_iojs && nvm deactivate >/dev/null 2>&1; then 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 return
else else
echo "System version of node not found." >&2 echo "System version of node not found." >&2
@ -1406,12 +1408,13 @@ nvm() {
if [ "$NVM_SYMLINK_CURRENT" = true ]; then if [ "$NVM_SYMLINK_CURRENT" = true ]; then
command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current" command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current"
fi fi
local NPM_VERSION
NPM_VERSION="(npm v$(npm --version 2>/dev/null))"
if nvm_is_iojs_version "$VERSION"; then 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 else
echo -n "Now using node $VERSION" echo "Now using node $VERSION $NPM_VERSION"
fi fi
echo " (npm v$(npm --version 2>/dev/null))"
;; ;;
"run" ) "run" )
local provided_version local provided_version

View File

@ -5,7 +5,7 @@ die () { echo $@ ; exit 1; }
. ../../nvm.sh . ../../nvm.sh
nvm_has_system_node() { return 0; } 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_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" [ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found"