nvm/nvm-exec
Matt Saladna c18cbf4d25
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.
2023-12-09 19:25:43 -05:00

20 lines
435 B
Bash
Executable File

#!/usr/bin/env bash
SOURCE=${BASH_SOURCE[0]}
test -L "$SOURCE" && SOURCE=`readlink "$SOURCE"`
DIR="$(command cd "$( dirname "$SOURCE" )" && pwd )"
unset NVM_CD_FLAGS
# shellcheck disable=SC1090,SC1091
\. "$DIR/nvm.sh" --no-use
if [ -n "$NODE_VERSION" ]; then
nvm use "$NODE_VERSION" > /dev/null || exit 127
elif ! nvm use >/dev/null 2>&1; then
echo "No NODE_VERSION provided; no .nvmrc file found" >&2
exit 127
fi
exec "$@"