diff --git a/nvm.sh b/nvm.sh index b570c49..ef2eb9f 100755 --- a/nvm.sh +++ b/nvm.sh @@ -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`"