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