Merge pull request #408 from creationix/nvm_system_awareness
Add `system` awareness to `nvm use`, `nvm ls`, and `nvm current`.master
commit
8cbf149558
27
nvm.sh
27
nvm.sh
|
@ -160,7 +160,15 @@ nvm_binary_available() {
|
|||
}
|
||||
|
||||
nvm_ls_current() {
|
||||
echo `node -v 2>/dev/null`
|
||||
local NODE_PATH
|
||||
NODE_PATH="$(which node)"
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 'none'
|
||||
elif nvm_tree_contains_path "$NVM_DIR" "$NODE_PATH"; then
|
||||
echo `node -v 2>/dev/null`
|
||||
else
|
||||
echo 'system'
|
||||
fi
|
||||
}
|
||||
|
||||
nvm_ls() {
|
||||
|
@ -194,6 +202,9 @@ nvm_ls() {
|
|||
echo "N/A"
|
||||
return 3
|
||||
fi
|
||||
if [ -z "$PATTERN" ] && nvm_has_system_node; then
|
||||
VERSIONS="$VERSIONS$(printf '\n%s' 'system')"
|
||||
fi
|
||||
echo "$VERSIONS"
|
||||
return
|
||||
}
|
||||
|
@ -251,6 +262,8 @@ nvm_print_versions() {
|
|||
FORMAT='\033[0;32m-> %9s\033[0m'
|
||||
elif [ -d "$NVM_DIR/$VERSION" ]; then
|
||||
FORMAT='\033[0;34m%12s\033[0m'
|
||||
elif [ "$VERSION" = "system" ]; then
|
||||
FORMAT='\033[0;33m%12s\033[0m'
|
||||
else
|
||||
FORMAT='%12s'
|
||||
fi
|
||||
|
@ -537,7 +550,17 @@ nvm() {
|
|||
VERSION=`nvm_version $NVM_RC_VERSION`
|
||||
fi
|
||||
else
|
||||
VERSION=`nvm_version $2`
|
||||
if [ $2 = 'system' ]; then
|
||||
if nvm_has_system_node && nvm deactivate; then
|
||||
echo "Now using system version of node: $(node -v 2>/dev/null)."
|
||||
return
|
||||
else
|
||||
echo "System version of node not found." >&2
|
||||
return 127
|
||||
fi
|
||||
else
|
||||
VERSION=`nvm_version $2`
|
||||
fi
|
||||
fi
|
||||
if [ -z "$VERSION" ]; then
|
||||
nvm help
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/sh
|
||||
|
||||
die () { echo $@ ; exit 1; }
|
||||
|
||||
. ../../../nvm.sh
|
||||
|
||||
mkdir -p ../../../v0.0.1
|
||||
mkdir -p ../../../v0.0.3
|
||||
mkdir -p ../../../v0.0.9
|
||||
mkdir -p ../../../v0.3.1
|
||||
mkdir -p ../../../v0.3.3
|
||||
mkdir -p ../../../v0.3.9
|
||||
|
||||
nvm_has_system_node() { return 0; }
|
||||
nvm ls | grep system 2>&1 > /dev/null
|
||||
[ $? -eq 0 ] || die '"nvm ls" did not contain "system" when system node is present'
|
||||
|
||||
nvm_has_system_node() { return 1; }
|
||||
nvm ls | grep system 2>&1 > /dev/null
|
||||
[ $? -ne 0 ] || die '"nvm ls" contained "system" when system node is not present'
|
||||
|
|
@ -3,4 +3,8 @@
|
|||
die () { echo $@ ; exit 1; }
|
||||
|
||||
. ../../nvm.sh
|
||||
[ "$(nvm current)" = "$(node -v)" ] || die "Failed to find current version"
|
||||
|
||||
nvm deactivate 2>&1
|
||||
|
||||
[ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated'
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/sh
|
||||
|
||||
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_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 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"
|
||||
|
Loading…
Reference in New Issue