Skip to content
Myr

Create `nvm_print_npm_version` and use that when printing the `npm` version.

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jordan Harband · committed by Jordan Harband · parent de93dc4 · Browse files · 3 files+44 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+44 added−14 removed

  • tests:+34 added−2 removed
  • other:+10 added−12 removed

3 files+44 added−14 removed

added:test/fast/Unit tests/nvm_print_npm_version+28 added
1#!/bin/sh23cleanup () {4 alias nvm_has='\nvm_has'5 alias npm='\npm'6 unset -f nvm_has npm7}8die () { echo $@ ; exit 1; }910. ../../../nvm.sh1112nvm_has() { return 1; }13OUTPUT="$(nvm_print_npm_version)"14[ -z "$OUTPUT" ] || die "nvm_print_npm_version did not return empty when nvm_has returns 1, got '$OUTPUT'"1516nvm_has() { return 0; }17npm() {18 if [ "_$@" = "_--version" ]; then19 echo "1.2.3"20 else21 echo "error"22 fi23}24OUTPUT="$(nvm_print_npm_version)"25EXPECTED_OUTPUT=" (npm v1.2.3)"26[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_npm_version did not provided '$EXPECTED_OUTPUT', got '$OUTPUT'"2728cleanup
modified:test/fast/Running "nvm use system" should work as expected+6 added-2 removed
3 unmodified lines
45. ../../nvm.sh67nvm_has_system_node() { return 0; }8nvm_print_npm_version() { return ' (npm v1.2.3)'; }9EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)"8[ "$(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"10[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Could not use system version of node"1112nvm_has_system_node() { return 1; }13nvm_print_npm_version() { return ''; }14EXPECTED_OUTPUT="System version of node not found."11[ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found"15[ "$(nvm use system 2>&1 | tail -n1)" = "$EXPECTED_OUTPUT" ] || die "Did not report error, system node not found"16nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"17
modified:nvm.sh+10 added-12 removed
56 unmodified lines
57nvm_has_system_iojs() {58 [ "$(nvm deactivate >/dev/null 2>&1 && command -v iojs)" != '' ]59}6061nvm_print_npm_version() {62 if nvm_has "npm"; then63 npm --version 2>/dev/null | command xargs printf " (npm v%s)"64 fi65}6667# Make zsh glob matching behave same as bash68# This fixes the "zsh: no matches found" errors69if nvm_has "unsetopt"; then70 unsetopt nomatch 2>/dev/null
1293 unmodified lines
1364 return 1271365 fi13661367 if [ "_$VERSION" = '_system' ]; then1362 local NPM_VERSION1363 if nvm_has "npm"; then1364 NPM_VERSION="(npm v$(npm --version 2>/dev/null))"1365 fi1368 if nvm_has_system_node && nvm deactivate >/dev/null 2>&1; then1367 echo "Now using system version of node: $(node -v 2>/dev/null) $NPM_VERSION"1369 echo "Now using system version of node: $(node -v 2>/dev/null)$(nvm_print_npm_version)"1370 return1371 elif nvm_has_system_iojs && nvm deactivate >/dev/null 2>&1; then1370 echo "Now using system version of io.js: $(iojs --version 2>/dev/null) $NPM_VERSION"1372 echo "Now using system version of io.js: $(iojs --version 2>/dev/null)$(nvm_print_npm_version)"1373 return1374 else1375 echo "System version of node not found." >&21376 return 127
34 unmodified lines
1411 export NVM_BIN="$NVM_VERSION_DIR/bin"1412 if [ "$NVM_SYMLINK_CURRENT" = true ]; then1413 command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current"1414 fi1413 local NPM_VERSION1414 if nvm_has "npm"; then1415 NPM_VERSION="(npm v$(npm --version 2>/dev/null))"1416 fi1415 if nvm_is_iojs_version "$VERSION"; then1418 echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION") $NPM_VERSION"1416 echo "Now using io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"1417 else1420 echo "Now using node $VERSION $NPM_VERSION"1418 echo "Now using node $VERSION$(nvm_print_npm_version)"1419 fi1420 ;;1421 "run" )1422 local provided_version
345 unmodified lines