Skip to content
Myr

Merge pull request #408 from creationix/nvm_system_awareness

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

Add `system` awareness to `nvm use`, `nvm ls`, and `nvm current`.

authored by Jordan Harband · committed by Jordan Harband · parents 1c50c5c, e7ada80 · Browse files · 4 files+64 added−3 removed
This commit

State

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

Diff stats

4 files+64 added−3 removed

  • tests:+39 added−1 removed
  • other:+25 added−2 removed

4 files+64 added−3 removed

added:test/fast/Listing versions/Running "nvm ls" should include "system" when appropriate+21 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45. ../../../nvm.sh67mkdir -p ../../../v0.0.18mkdir -p ../../../v0.0.39mkdir -p ../../../v0.0.910mkdir -p ../../../v0.3.111mkdir -p ../../../v0.3.312mkdir -p ../../../v0.3.91314nvm_has_system_node() { return 0; }15nvm ls | grep system 2>&1 > /dev/null16[ $? -eq 0 ] || die '"nvm ls" did not contain "system" when system node is present'1718nvm_has_system_node() { return 1; }19nvm ls | grep system 2>&1 > /dev/null20[ $? -ne 0 ] || die '"nvm ls" contained "system" when system node is not present'21
modified:test/fast/Running "nvm current" should display current nvm environment.+5 added-1 removed
1 unmodified line
23die () { echo $@ ; exit 1; }45. ../../nvm.sh6[ "$(nvm current)" = "$(node -v)" ] || die "Failed to find current version"67nvm deactivate 2>&189[ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated'10
added:test/fast/Running "nvm use system" should work as expected+13 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45. ../../nvm.sh67nvm_has_system_node() { return 0; }8[ "$(nvm use system 2>&1 | tail -n1)" = "Now using system version of node: $(node -v)." ] || die "Could not use system version of node"910nvm_has_system_node() { return 1; }11[ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found"12nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"13
modified:nvm.sh+25 added-2 removed
158 unmodified lines
159 [ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]160}161162nvm_ls_current() {163 local NODE_PATH164 NODE_PATH="$(which node)"165 if [ $? -ne 0 ]; then166 echo 'none'167 elif nvm_tree_contains_path "$NVM_DIR" "$NODE_PATH"; then163 echo `node -v 2>/dev/null`168 echo `node -v 2>/dev/null`169 else170 echo 'system'171 fi172}173174nvm_ls() {175 local PATTERN
25 unmodified lines
201 if [ -z "$VERSIONS" ]; then202 echo "N/A"203 return 3204 fi205 if [ -z "$PATTERN" ] && nvm_has_system_node; then206 VERSIONS="$VERSIONS$(printf '\n%s' 'system')"207 fi208 echo "$VERSIONS"209 return210}211
49 unmodified lines
261 if [ "$VERSION" = "$NVM_CURRENT" ]; then262 FORMAT='\033[0;32m-> %9s\033[0m'263 elif [ -d "$NVM_DIR/$VERSION" ]; then264 FORMAT='\033[0;34m%12s\033[0m'265 elif [ "$VERSION" = "system" ]; then266 FORMAT='\033[0;33m%12s\033[0m'267 else268 FORMAT='%12s'269 fi270 printf "$FORMAT\n" $VERSION
278 unmodified lines
549 if [ -n "$NVM_RC_VERSION" ]; then550 VERSION=`nvm_version $NVM_RC_VERSION`551 fi552 else553 if [ $2 = 'system' ]; then554 if nvm_has_system_node && nvm deactivate; then555 echo "Now using system version of node: $(node -v 2>/dev/null)."556 return557 else558 echo "System version of node not found." >&2559 return 127560 fi561 else540 VERSION=`nvm_version $2`562 VERSION=`nvm_version $2`563 fi564 fi565 if [ -z "$VERSION" ]; then566 nvm help567 return 127
172 unmodified lines