mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-08-20 04:23:43 +00:00
Compare commits
7 Commits
89bf666ef2
...
54d1154c0f
Author | SHA1 | Date | |
---|---|---|---|
![]() |
54d1154c0f | ||
![]() |
5dc31ac51b | ||
![]() |
b4ee18be6a | ||
![]() |
3b811237cb | ||
![]() |
ad4fa37deb | ||
![]() |
d956279e5a | ||
![]() |
c18cbf4d25 |
5
nvm-exec
5
nvm-exec
@ -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
|
||||||
|
|
||||||
|
25
nvm.sh
25
nvm.sh
@ -700,10 +700,12 @@ nvm_ensure_version_installed() {
|
|||||||
nvm_err "N/A: version \"${PREFIXED_VERSION:-$PROVIDED_VERSION}\" is not yet installed."
|
nvm_err "N/A: version \"${PREFIXED_VERSION:-$PROVIDED_VERSION}\" is not yet installed."
|
||||||
fi
|
fi
|
||||||
nvm_err ""
|
nvm_err ""
|
||||||
if [ "${IS_VERSION_FROM_NVMRC}" != '1' ]; then
|
if [ "${PROVIDED_VERSION}" = 'lts' ]; then
|
||||||
nvm_err "You need to run \`nvm install ${PROVIDED_VERSION}\` to install and use it."
|
nvm_err '`lts` is not an alias - you may need to run `nvm install --lts` to install and `nvm use --lts` to use it.'
|
||||||
else
|
elif [ "${IS_VERSION_FROM_NVMRC}" != '1' ]; then
|
||||||
nvm_err 'You need to run `nvm install` to install and use the node version specified in `.nvmrc`.'
|
nvm_err "You need to run \`nvm install ${PROVIDED_VERSION}\` to install and use it."
|
||||||
|
else
|
||||||
|
nvm_err 'You need to run `nvm install` to install and use the node version specified in `.nvmrc`.'
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -1239,10 +1241,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2505,12 +2506,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
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4051,7 +4052,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
|
||||||
|
@ -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"
|
||||||
|
|
19
test/slow/nvm use/Running 'nvm use lts' shows actionable error
Executable file
19
test/slow/nvm use/Running 'nvm use lts' shows actionable error
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
die () { echo "$@" ; exit 1; }
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
# Deactivate any active node version
|
||||||
|
nvm deactivate >/dev/null 2>&1 || die 'deactivate failed'
|
||||||
|
|
||||||
|
# Attempt to use 'lts' without '--' and capture the error message
|
||||||
|
ERROR_OUTPUT=$(nvm use lts 2>&1) || true
|
||||||
|
|
||||||
|
EXPECTED_ERROR='`lts` is not an alias - you may need to run `nvm install --lts` to install and `nvm use --lts` to use it.'
|
||||||
|
|
||||||
|
# Check if the error message matches the expected output
|
||||||
|
echo "$ERROR_OUTPUT" | grep -q "$EXPECTED_ERROR" \
|
||||||
|
|| die "Expected error message not found. Got: $ERROR_OUTPUT"
|
Loading…
x
Reference in New Issue
Block a user