Update NODE_PATH on use, run and deactivate

master
Tarcisio Gruppi 2014-01-01 02:04:37 -02:00
parent 4d2faba9af
commit 58dafdaedd
No known key found for this signature in database
GPG Key ID: 36F5005FCAF5C057
1 changed files with 20 additions and 1 deletions

21
nvm.sh
View File

@ -377,6 +377,12 @@ nvm() {
else else
echo "Could not find $NVM_DIR/*/share/man in \$MANPATH" echo "Could not find $NVM_DIR/*/share/man in \$MANPATH"
fi fi
if [[ $NODE_PATH == *$NVM_DIR/*/lib/node_modules* ]]; then
export NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}${NODE_PATH#*$NVM_DIR/*/lib/node_modules:}
echo "$NVM_DIR/*/lib/node_modules removed from \$NODE_PATH"
else
echo "Could not find $NVM_DIR/*/lib/node_modules in \$NODE_PATH"
fi
;; ;;
"use" ) "use" )
if [ $# -eq 0 ]; then if [ $# -eq 0 ]; then
@ -416,12 +422,17 @@ nvm() {
else else
MANPATH="$NVM_DIR/$VERSION/share/man:$MANPATH" MANPATH="$NVM_DIR/$VERSION/share/man:$MANPATH"
fi fi
if [[ $NODE_PATH == *$NVM_DIR/*/lib/node_modules* ]]; then
NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}$NVM_DIR/$VERSION/lib/node_modules${NODE_PATH#*$NVM_DIR/*/lib/node_modules}
else
NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"
fi
export PATH export PATH
hash -r hash -r
export MANPATH export MANPATH
export NODE_PATH
export NVM_PATH="$NVM_DIR/$VERSION/lib/node" export NVM_PATH="$NVM_DIR/$VERSION/lib/node"
export NVM_BIN="$NVM_DIR/$VERSION/bin" export NVM_BIN="$NVM_DIR/$VERSION/bin"
export NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules"
echo "Now using node $VERSION" echo "Now using node $VERSION"
;; ;;
"run" ) "run" )
@ -435,8 +446,16 @@ nvm() {
echo "$VERSION version is not installed yet" echo "$VERSION version is not installed yet"
return; return;
fi fi
PREVIOUS_NODE_PATH=$NODE_PATH
if [[ $NODE_PATH == *$NVM_DIR/*/lib/node_modules* ]]; then
NODE_PATH=${NODE_PATH%$NVM_DIR/*/lib/node_modules*}$NVM_DIR/$VERSION/lib/node_modules${NODE_PATH#*$NVM_DIR/*/lib/node_modules}
else
NODE_PATH="$NVM_DIR/$VERSION/lib/node_modules:$NODE_PATH"
fi
export NODE_PATH
echo "Running node $VERSION" echo "Running node $VERSION"
$NVM_DIR/$VERSION/bin/node "${@:3}" $NVM_DIR/$VERSION/bin/node "${@:3}"
export NODE_PATH=$PREVIOUS_NODE_PATH
;; ;;
"ls" | "list" ) "ls" | "list" )
print_versions "`nvm_ls $2`" print_versions "`nvm_ls $2`"