Skip to content

Commit acbd22f

Browse files
msaladnaljharb
authored andcommitted
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 b77fcec commit acbd22f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

nvm-exec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
3+
DIR="$(dirname $(realpath "${BASH_SOURCE[0]}"))"
44

55
unset NVM_CD_FLAGS
66

nvm.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4075,8 +4075,14 @@ nvm() {
40754075
nvm_echo "Running node ${VERSION}$(nvm use --silent "${VERSION}" && nvm_print_npm_version)"
40764076
fi
40774077
fi
4078-
NODE_VERSION="${VERSION}" "${NVM_DIR}/nvm-exec" "$@"
4078+
4079+
NVM_EXEC="${NVM_DIR}/nvm-exec"
4080+
if [ ! -f "${NVM_EXEC}" ]; then
4081+
NVM_EXEC=`dirname ${BASH_SOURCE[0]-}`/nvm-exec
4082+
fi
4083+
NODE_VERSION="${VERSION}" "${NVM_EXEC}" "$@"
40794084
;;
4085+
40804086
"ls" | "list")
40814087
local PATTERN
40824088
local NVM_NO_COLORS

0 commit comments

Comments
 (0)