Skip to content

Commit

Permalink
Allow nvm-exec to be linked into individual .nvm directories for syst…
Browse files Browse the repository at this point in the history
…em-wide installs with a localized Nodes.

Let's say we have nvm installed in a separate mount, /.socket. NVM_DIR is $HOME/.nvm in /etc/profile.d/nvm.sh. With this setup, users can install Node versions to their home directories without each installing nvm.

nvm install --lts

This works fine as does nvm use --lts. When nvm exec is used though, it fails because it looks for nvm-exec in $NVM_DIR. First fix is to look for nvm-exec in $NVM_DIR. If NVM_DIR does not contain nvm-exec, check $BASH_SOURCE[0]. The second fix is to follow nvm-exec if a symbolic link to determine the proper location of nvm's home. Alternatively we could use a second environment variable, NVM_HOME in exec instead of relying on the directory name of nvm-exec.
  • Loading branch information
msaladna committed Jun 21, 2018
1 parent 41dc421 commit 857fb2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion nvm-exec
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env bash

DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SOURCE=${BASH_SOURCE[0]}
test -L "$SOURCE" && SOURCE=`readlink "$SOURCE"`
DIR="$(command cd "$( dirname "$SOURCE" )" && pwd )"

# shellcheck disable=SC1090
\. "$DIR/nvm.sh" --no-use
Expand Down
4 changes: 3 additions & 1 deletion nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3201,7 +3201,9 @@ nvm() {
nvm_echo "Running node $VERSION$(nvm use --silent "$VERSION" && nvm_print_npm_version)"
fi
fi
NODE_VERSION="$VERSION" "$NVM_DIR/nvm-exec" "$@"
NVM_EXEC="$NVM_DIR/nvm-exec"
test ! -f "$NVM_EXEC" && NVM_EXEC=`dirname ${BASH_SOURCE[0]-}`/nvm-exec
NODE_VERSION="$VERSION" "$NVM_EXEC" "$@"
;;
"ls" | "list" )
local PATTERN
Expand Down

0 comments on commit 857fb2d

Please sign in to comment.