Compare commits

...

3 Commits

Author SHA1 Message Date
Tiffany Patek
2685f6d5a1
Merge 09c4fcfbed1d52857a4c90fade31f18058f5bf9b into 5dc31ac51b08f910a2de1596b37a6a3dddd5e7b7 2024-10-07 20:13:17 +05:30
Reetik Rajan
5dc31ac51b
[patch] give a more helpful message when lts alias is mistakenly used 2024-10-05 09:21:42 +05:30
Tiffany Patek
09c4fcfbed
Update README.md
Install & Update Script Section

 - Line 96: Added **If you use macOS, you must install Xcode and agree to the Xcode License before you install nvm.**under heading.
 - Line 106: Added **If you don't have a profile file in your home dir, you'll need to add the appropriate one before you run the script.** to the end of the paragraph.
2023-04-19 14:16:50 -06:00
3 changed files with 28 additions and 5 deletions

View File

@ -100,6 +100,8 @@ nvm is a version manager for [node.js](https://nodejs.org/en/), designed to be i
### Install & Update Script ### Install & Update Script
**If you use macOS, you must install Xcode and agree to the Xcode License before you install nvm.**
To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command: To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
```sh ```sh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
@ -108,7 +110,7 @@ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
``` ```
Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`). Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`). **If you don't have a profile file in your home dir, you'll need to add the appropriate one before you run the script.**
<a id="profile_snippet"></a> <a id="profile_snippet"></a>
```sh ```sh

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"