Skip to content

Commit 857fb2d

Browse files
committed
Allow nvm-exec to be linked into individual .nvm directories for system-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.
1 parent 41dc421 commit 857fb2d

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Diff for: nvm-exec

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/usr/bin/env bash
22

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

57
# shellcheck disable=SC1090
68
\. "$DIR/nvm.sh" --no-use

Diff for: nvm.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -3201,7 +3201,9 @@ nvm() {
32013201
nvm_echo "Running node $VERSION$(nvm use --silent "$VERSION" && nvm_print_npm_version)"
32023202
fi
32033203
fi
3204-
NODE_VERSION="$VERSION" "$NVM_DIR/nvm-exec" "$@"
3204+
NVM_EXEC="$NVM_DIR/nvm-exec"
3205+
test ! -f "$NVM_EXEC" && NVM_EXEC=`dirname ${BASH_SOURCE[0]-}`/nvm-exec
3206+
NODE_VERSION="$VERSION" "$NVM_EXEC" "$@"
32053207
;;
32063208
"ls" | "list" )
32073209
local PATTERN

0 commit comments

Comments
 (0)