Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow global installation of NVM with individual user .nvm directories for Node installs #3056

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nvm-exec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

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

# shellcheck disable=SC1090,SC1091
\. "$DIR/nvm.sh" --no-use
Expand Down
8 changes: 7 additions & 1 deletion nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3810,8 +3810,14 @@ 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"
if [ ! -f "${NVM_EXEC}" ]; then
NVM_EXEC="$(dirname "${BASH_SOURCE[0]-}")/nvm-exec"
fi
NODE_VERSION="${VERSION}" "${NVM_EXEC}" "$@"
;;

"ls" | "list")
local PATTERN
local NVM_NO_COLORS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh

set -ex

die () { echo "$@" ; exit 1; }

INSTPATH="$(mktemp -p "$(pwd)" -d)"
trap 'test ! -z "${INSTPATH-}" && test -d "$INSTPATH" && rm -rf "$INSTPATH"' EXIT
declare -x NVM_DIR=$INSTPATH
\. ../../../nvm.sh

nvm install --lts || die 'nvm install --lts failed'
nvm exec --lts npm --version || die "`nvm exec` failed to run"
declare -x NODE_VERSION="$(nvm exec --lts --silent node --version)"

ln -s ../../../../nvm-exec "$INSTPATH/nvm-exec" || die "failed to create a symlink to $INSTPATH/"
"$INSTPATH/nvm-exec" npm ls > /dev/null || die "`nvm exec` failed to run using nvm-exec helper"