Compare commits

...

3 Commits

3 changed files with 27 additions and 6 deletions

View File

@ -422,10 +422,10 @@ nvm_do_install() {
local PROFILE_INSTALL_DIR local PROFILE_INSTALL_DIR
PROFILE_INSTALL_DIR="$(nvm_install_dir | command sed "s:^$HOME:\$HOME:")" PROFILE_INSTALL_DIR="$(nvm_install_dir | command sed "s:^$HOME:\$HOME:")"
SOURCE_STR="\\nexport NVM_DIR=\"${PROFILE_INSTALL_DIR}\"\\n[ -s \"\$NVM_DIR/nvm.sh\" ] && \\. \"\$NVM_DIR/nvm.sh\" # This loads nvm\\n" SOURCE_STR="\\nexport NVM_DIR=\"${PROFILE_INSTALL_DIR}\"\\n[ ! -s \"\$NVM_DIR/nvm.sh\" ] || \\. \"\$NVM_DIR/nvm.sh\" # This loads nvm\\n"
# shellcheck disable=SC2016 # shellcheck disable=SC2016
COMPLETION_STR='[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion\n' COMPLETION_STR='[ ! -s "$NVM_DIR/bash_completion" ] || \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion\n'
BASH_OR_ZSH=false BASH_OR_ZSH=false
if [ -z "${NVM_PROFILE-}" ] ; then if [ -z "${NVM_PROFILE-}" ] ; then

10
nvm.sh
View File

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

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