Compare commits

..

7 Commits

Author SHA1 Message Date
Cheerag Patel
6074cfeb68 Merge f4c7c77fe3 into 6b70c40f15 2024-10-31 06:44:57 +00:00
Cheerag Patel
f4c7c77fe3 [meta] Rename .github/ISSUE_TEMPLATE.md to .github/ISSUE_TEMPLATE/ISSUE_TEMPLATE.md
Moved issue template into ISSUE_TEMPLATE folder
2024-10-30 14:03:05 -07:00
Jordan Harband
84296e5ab8 [Tests] ensure that unit tests use only mocked LTS names 2024-10-30 23:41:50 -07:00
Jordan Harband
6b70c40f15 [Fix] nvm_install_latest_npm: avoid unbound variable
Fixes #3447
2024-10-22 22:02:01 -07:00
Reetik Rajan
5dc31ac51b [patch] give a more helpful message when lts alias is mistakenly used 2024-10-05 09:21:42 +05:30
Jordan Harband
da2720a429 [Fix] nvm ls, nvm alias, nvm install: error when an LTS name is invalid 2024-09-04 13:55:11 -07:00
Jordan Harband
9fb9dec710 [Fix] nvm_normalize_lts: error when an LTS name is not lowercase
Fixes #3417
2024-09-04 13:54:41 -07:00
5 changed files with 59 additions and 14 deletions

9
nvm.sh
View File

@@ -196,6 +196,9 @@ nvm_install_latest_npm() {
nvm_echo 'Attempting to upgrade to the latest working version of npm...' nvm_echo 'Attempting to upgrade to the latest working version of npm...'
local NODE_VERSION local NODE_VERSION
NODE_VERSION="$(nvm_strip_iojs_prefix "$(nvm_ls_current)")" NODE_VERSION="$(nvm_strip_iojs_prefix "$(nvm_ls_current)")"
local NPM_VERSION
NPM_VERSION="$(npm --version 2>/dev/null)"
if [ "${NODE_VERSION}" = 'system' ]; then if [ "${NODE_VERSION}" = 'system' ]; then
NODE_VERSION="$(node --version)" NODE_VERSION="$(node --version)"
elif [ "${NODE_VERSION}" = 'none' ]; then elif [ "${NODE_VERSION}" = 'none' ]; then
@@ -206,8 +209,6 @@ nvm_install_latest_npm() {
nvm_err 'Unable to obtain node version.' nvm_err 'Unable to obtain node version.'
return 1 return 1
fi fi
local NPM_VERSION
NPM_VERSION="$(npm --version 2>/dev/null)"
if [ -z "${NPM_VERSION}" ]; then if [ -z "${NPM_VERSION}" ]; then
nvm_err 'Unable to obtain npm version.' nvm_err 'Unable to obtain npm version.'
return 2 return 2
@@ -700,7 +701,9 @@ 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 '`lts` is not an alias - you may need to run `nvm install --lts` to install and `nvm use --lts` to use it.'
elif [ "${IS_VERSION_FROM_NVMRC}" != '1' ]; then
nvm_err "You need to run \`nvm install ${PROVIDED_VERSION}\` to install and use it." nvm_err "You need to run \`nvm install ${PROVIDED_VERSION}\` to install and use it."
else else
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` to install and use the node version specified in `.nvmrc`.'

View File

@@ -5,14 +5,26 @@ die () { echo "$@" ; cleanup ; exit 1; }
cleanup() { cleanup() {
unset -f nvm_download unset -f nvm_download
rm -rf "${NVM_DIR}/alias/lts"
mv "${NVM_DIR}/alias/lts-backup" "${NVM_DIR}/alias/lts"
} }
\. ../../../nvm.sh \. ../../../nvm.sh
set -ex
MOCKS_DIR="${PWD}/mocks" MOCKS_DIR="${PWD}/mocks"
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)"
mv "${NVM_DIR}/alias/lts" "${NVM_DIR}/alias/lts-backup" ||:
mkdir -p "${NVM_DIR}/alias/lts"
for LTS in $LTS_LIST; do
cp "${NVM_DIR}/alias/lts-backup/${LTS}" "${NVM_DIR}/alias/lts/"
done
set -ex
# sample output at the time the test was written # sample output at the time the test was written
TAB_PATH="${MOCKS_DIR}/nodejs.org-dist-index.tab" TAB_PATH="${MOCKS_DIR}/nodejs.org-dist-index.tab"
nvm_download() { nvm_download() {
@@ -21,8 +33,6 @@ nvm_download() {
nvm_ls_remote >/dev/null || die "nvm_ls_remote_failed?!" nvm_ls_remote >/dev/null || die "nvm_ls_remote_failed?!"
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
N=0 N=0
while IFS= read -r LTS; do while IFS= read -r LTS; do
if [ $N -gt 0 ]; then if [ $N -gt 0 ]; then

View File

@@ -2,12 +2,26 @@
cleanup() { cleanup() {
unset nvm_get_os unset nvm_get_os
rm -rf "${NVM_DIR}/alias/lts"
mv "${NVM_DIR}/alias/lts-backup" "${NVM_DIR}/alias/lts"
} }
die () { cleanup; echo "$@" ; exit 1; } die () { cleanup; echo "$@" ; exit 1; }
\. ../../../nvm.sh \. ../../../nvm.sh
MOCKS_DIR="../Unit tests/mocks"
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)"
mv "${NVM_DIR}/alias/lts" "${NVM_DIR}/alias/lts-backup" ||:
mkdir -p "${NVM_DIR}/alias/lts"
for LTS in $LTS_LIST; do
cp "${NVM_DIR}/alias/lts-backup/${LTS}" "${NVM_DIR}/alias/lts/"
done
ACTUAL="$(nvm_normalize_lts "foo")" ACTUAL="$(nvm_normalize_lts "foo")"
EXPECTED='foo' EXPECTED='foo'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" [ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
@@ -20,15 +34,14 @@ if ACTUAL="$(nvm_normalize_lts lts/ARGON)"; then
die "expected failure, got >${ACTUAL}<" die "expected failure, got >${ACTUAL}<"
fi fi
MOCKS_DIR="../Unit tests/mocks" STAR="$(cat "${MOCKS_DIR}/lts-star.txt")"
STAR="$(cat "$MOCKS_DIR/lts-star.txt")"
ACTUAL="$(nvm_normalize_lts "${STAR}")" ACTUAL="$(nvm_normalize_lts "${STAR}")"
EXPECTED="${STAR}" EXPECTED="${STAR}"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" [ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt" # or, back up LTS aliases, copy backups that are in LTS names
LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)" #
INDEX=1 INDEX=1
printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do

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"