Compare commits

...

8 Commits

Author SHA1 Message Date
Matt Saladna
74bd910bd0
Merge b4ee18be6a1ba1dca0a85fdd796bc33b4984ced6 into d5e2c92a254cc10e95cd960a47515bec2d5c5e81 2024-08-20 10:18:10 -07:00
Jordan Harband
d5e2c92a25
[Fix] nvm_has_colors: avoid an aliased tput
Fixes #3413
2024-08-20 09:23:45 -07:00
Jordan Harband
81f18bc445
[patch] install.sh: fix node capitalization 2024-08-09 13:46:16 +12:00
Matt Saladna
b4ee18be6a
Partial reversion of nvm-sh/nvm#1517. Each alias lookup adds 8 to the pids.current bean counter resulting in 64+ concurrent tids (tasks, w/ threads) thus making it susceptible to hit pids.max. Once reached, subshell behavior is unexpected yielding "retry: Resource temporarily unavailable" errors until cgroup capacity is restored. 2024-03-16 12:26:55 -04:00
Matt Saladna
3b811237cb
Drop same-owner on extraction 2023-12-09 19:30:19 -05:00
Matt Saladna
ad4fa37deb
Add test for NVM_DIR outside nvm.sh
Fix symlink traversal
2023-12-09 19:26:17 -05:00
Matt Saladna
d956279e5a
shellcheck warnings 2023-12-09 19:26:17 -05:00
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
4 changed files with 32 additions and 10 deletions

View File

@ -358,7 +358,7 @@ nvm_check_global_modules() {
command printf %s\\n "$NPM_GLOBAL_MODULES" command printf %s\\n "$NPM_GLOBAL_MODULES"
nvm_echo '=> If you wish to uninstall them at a later point (or re-install them under your' nvm_echo '=> If you wish to uninstall them at a later point (or re-install them under your'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
nvm_echo '=> `nvm` Nodes), you can remove them from the system Node as follows:' nvm_echo '=> `nvm` node installs), you can remove them from the system Node as follows:'
nvm_echo nvm_echo
nvm_echo ' $ nvm use system' nvm_echo ' $ nvm use system'
nvm_echo ' $ npm uninstall -g a_module' nvm_echo ' $ npm uninstall -g a_module'

View File

@ -1,6 +1,9 @@
#!/usr/bin/env bash #!/usr/bin/env bash
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" SOURCE=${BASH_SOURCE[0]}
test -L "$SOURCE" && command cd "$( dirname "$SOURCE" )" && \
SOURCE=$(readlink "$SOURCE")
DIR="$(command cd "$( dirname "$SOURCE" )" && pwd )"
unset NVM_CD_FLAGS unset NVM_CD_FLAGS

17
nvm.sh
View File

@ -81,7 +81,7 @@ nvm_command_info() {
nvm_has_colors() { nvm_has_colors() {
local NVM_NUM_COLORS local NVM_NUM_COLORS
if nvm_has tput; then if nvm_has tput; then
NVM_NUM_COLORS="$(tput -T "${TERM:-vt100}" colors)" NVM_NUM_COLORS="$(command tput -T "${TERM:-vt100}" colors)"
fi fi
[ "${NVM_NUM_COLORS:--1}" -ge 8 ] && [ "${NVM_NO_COLORS-}" != '--no-colors' ] [ "${NVM_NUM_COLORS:--1}" -ge 8 ] && [ "${NVM_NO_COLORS-}" != '--no-colors' ]
} }
@ -1230,10 +1230,9 @@ nvm_list_aliases() {
if [ -n "${LTS_ALIAS}" ]; then if [ -n "${LTS_ALIAS}" ]; then
nvm_echo "${LTS_ALIAS}" nvm_echo "${LTS_ALIAS}"
fi fi
} & }
done done
wait )
) | command sort
return return
} }
@ -2492,12 +2491,12 @@ nvm_extract_tarball() {
if [ "${NVM_OS}" = 'openbsd' ]; then if [ "${NVM_OS}" = 'openbsd' ]; then
if [ "${tar_compression_flag}" = 'J' ]; then if [ "${tar_compression_flag}" = 'J' ]; then
command xzcat "${TARBALL}" | "${tar}" -xf - -C "${TMPDIR}" -s '/[^\/]*\///' || return 1 command xzcat "${TARBALL}" | "${tar}" --no-same-owner -xf - -C "${TMPDIR}" -s '/[^\/]*\///' || return 1
else else
command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" -s '/[^\/]*\///' || return 1 command "${tar}" --no-same-owner -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" -s '/[^\/]*\///' || return 1
fi fi
else else
command "${tar}" -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 || return 1 command "${tar}" --no-same-owner -x${tar_compression_flag}f "${TARBALL}" -C "${TMPDIR}" --strip-components 1 || return 1
fi fi
} }
@ -4016,7 +4015,9 @@ nvm() {
nvm_echo "Running node ${VERSION}$(nvm use --silent "${VERSION}" && nvm_print_npm_version)" nvm_echo "Running node ${VERSION}$(nvm use --silent "${VERSION}" && nvm_print_npm_version)"
fi fi
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") "ls" | "list")
local PATTERN local PATTERN

View File

@ -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"