Add `nvm_has_system_iojs`

master
Jordan Harband 2015-01-18 20:55:48 -06:00
parent ed22d3de2d
commit 3cf68dc18d
2 changed files with 42 additions and 4 deletions

15
nvm.sh
View File

@ -49,6 +49,10 @@ nvm_has_system_node() {
[ "$(nvm deactivate >/dev/null 2>&1 && command -v node)" != '' ] [ "$(nvm deactivate >/dev/null 2>&1 && command -v node)" != '' ]
} }
nvm_has_system_iojs() {
[ "$(nvm deactivate >/dev/null 2>&1 && command -v iojs)" != '' ]
}
# Make zsh glob matching behave same as bash # Make zsh glob matching behave same as bash
# This fixes the "zsh: no matches found" errors # This fixes the "zsh: no matches found" errors
if nvm_has "unsetopt"; then if nvm_has "unsetopt"; then
@ -463,7 +467,7 @@ nvm_ls() {
fi fi
fi fi
if nvm_has_system_node; then if nvm_has_system_node || nvm_has_system_iojs; then
if [ -z "$PATTERN" ] || [ "_$PATTERN" = "_v" ]; then if [ -z "$PATTERN" ] || [ "_$PATTERN" = "_v" ]; then
VERSIONS="$VERSIONS$(command printf '\n%s' 'system')" VERSIONS="$VERSIONS$(command printf '\n%s' 'system')"
elif [ "$PATTERN" = 'system' ]; then elif [ "$PATTERN" = 'system' ]; then
@ -1095,6 +1099,9 @@ nvm() {
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)." echo "Now using system version of node: $(node -v 2>/dev/null)."
return 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)."
return
else else
echo "System version of node not found." >&2 echo "System version of node not found." >&2
return 127 return 127
@ -1274,7 +1281,7 @@ nvm() {
fi fi
if [ "_$VERSION" = '_system' ]; then if [ "_$VERSION" = '_system' ]; then
if nvm_has_system_node >/dev/null 2>&1; then if nvm_has_system_iojs >/dev/null 2>&1 || nvm_has_system_node >/dev/null 2>&1; then
local NVM_BIN local NVM_BIN
NVM_BIN="$(nvm use system >/dev/null 2>&1 && command which node)" NVM_BIN="$(nvm use system >/dev/null 2>&1 && command which node)"
if [ -n "$NVM_BIN" ]; then if [ -n "$NVM_BIN" ]; then
@ -1373,8 +1380,8 @@ nvm() {
local INSTALLS local INSTALLS
if [ "_$PROVIDED_VERSION" = "_system" ]; then if [ "_$PROVIDED_VERSION" = "_system" ]; then
if ! nvm_has_system_node; then if ! nvm_has_system_node && ! nvm_has_system_iojs; then
echo 'No system version of node detected.' >&2 echo 'No system version of node or io.js detected.' >&2
return 3 return 3
fi fi
INSTALLS=$(nvm deactivate > /dev/null && npm list -g --depth=0 | command tail -n +2 | command grep -o -e ' [^@]*' | command cut -c 2- | command grep -v npm | command xargs) INSTALLS=$(nvm deactivate > /dev/null && npm list -g --depth=0 | command tail -n +2 | command grep -o -e ' [^@]*' | command cut -c 2- | command grep -v npm | command xargs)

View File

@ -0,0 +1,31 @@
#!/bin/sh
cleanup () {
rm ../../../versions/io.js/v0.1.2/node
rm ../../../versions/io.js/v0.1.2/iojs
rmdir ../../../versions/io.js/v0.1.2
}
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
mkdir ../../../versions/io.js/v0.1.2
touch ../../../versions/io.js/v0.1.2/node
touch ../../../versions/io.js/v0.1.2/iojs
nvm use iojs-v0.1.2
if command -v iojs; then
nvm_has_system_iojs
else
! nvm_has_system_iojs
fi
nvm deactivate /dev/null 2>&1
if command -v iojs; then
nvm_has_system_iojs
else
! nvm_has_system_iojs
fi