mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-08-20 04:23:43 +00:00
Compare commits
4 Commits
94126c4b12
...
0b7db20872
Author | SHA1 | Date | |
---|---|---|---|
![]() |
0b7db20872 | ||
![]() |
5dc31ac51b | ||
![]() |
cf9beb7f86 | ||
![]() |
9222739d18 |
16
nvm.sh
16
nvm.sh
@ -454,6 +454,12 @@ nvm_tree_contains_path() {
|
|||||||
previous_pathdir="${node_path}"
|
previous_pathdir="${node_path}"
|
||||||
local pathdir
|
local pathdir
|
||||||
pathdir=$(dirname "${previous_pathdir}")
|
pathdir=$(dirname "${previous_pathdir}")
|
||||||
|
|
||||||
|
# get real directory in case of symbolic links
|
||||||
|
if [ -d "${pathdir-}" ]; then
|
||||||
|
pathdir="$(nvm_cd -P "${pathdir}" && pwd)"
|
||||||
|
fi
|
||||||
|
|
||||||
while [ "${pathdir}" != '' ] && [ "${pathdir}" != '.' ] && [ "${pathdir}" != '/' ] &&
|
while [ "${pathdir}" != '' ] && [ "${pathdir}" != '.' ] && [ "${pathdir}" != '/' ] &&
|
||||||
[ "${pathdir}" != "${tree}" ] && [ "${pathdir}" != "${previous_pathdir}" ]; do
|
[ "${pathdir}" != "${tree}" ] && [ "${pathdir}" != "${previous_pathdir}" ]; do
|
||||||
previous_pathdir="${pathdir}"
|
previous_pathdir="${pathdir}"
|
||||||
@ -700,10 +706,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
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
cleanup () {
|
cleanup () {
|
||||||
|
rm tmp3/tmp2
|
||||||
|
rmdir tmp3
|
||||||
rm tmp/node
|
rm tmp/node
|
||||||
rmdir tmp
|
rmdir tmp
|
||||||
rm tmp2/node
|
rm tmp2/node
|
||||||
@ -14,6 +16,8 @@ mkdir -p tmp
|
|||||||
touch tmp/node
|
touch tmp/node
|
||||||
mkdir -p tmp2
|
mkdir -p tmp2
|
||||||
touch tmp2/node
|
touch tmp2/node
|
||||||
|
mkdir -p tmp3
|
||||||
|
ln -s tmp2 tmp3/
|
||||||
|
|
||||||
[ "$(nvm_tree_contains_path 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with no args'
|
[ "$(nvm_tree_contains_path 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with no args'
|
||||||
[ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with no args'
|
[ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with no args'
|
||||||
@ -28,4 +32,6 @@ nvm_tree_contains_path tmp2 tmp2/node || die '"tmp2" should contain "tmp2/node"'
|
|||||||
|
|
||||||
nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"'
|
nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"'
|
||||||
|
|
||||||
|
nvm_tree_contains_path tmp2 tmp3 && die 'no idea'
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
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