Skip to content

Commit 4626d1a

Browse files
committed
[New] add lts/-1 etc, to point to an LTS line relative to "latest"
1 parent c372ff0 commit 4626d1a

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

nvm.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,8 +855,25 @@ nvm_alias() {
855855
return 1
856856
fi
857857

858+
local NVM_ALIAS_DIR
859+
NVM_ALIAS_DIR="$(nvm_alias_path)"
860+
861+
if [ "$(expr "${ALIAS}" : '^lts/-[1-9][0-9]*$')" -gt 0 ]; then
862+
local N
863+
N="$(echo "${ALIAS}" | cut -d '-' -f 2)"
864+
local RESULT
865+
RESULT="$(command ls "${NVM_ALIAS_DIR}/lts" | command tail -n "${N}" | command head -n 1)"
866+
if [ "${RESULT}" != '*' ]; then
867+
nvm_alias "lts/${RESULT}"
868+
return $?
869+
else
870+
nvm_err 'That many LTS releases do not exist yet.'
871+
return 2
872+
fi
873+
fi
874+
858875
local NVM_ALIAS_PATH
859-
NVM_ALIAS_PATH="$(nvm_alias_path)/${ALIAS}"
876+
NVM_ALIAS_PATH="${NVM_ALIAS_DIR}/${ALIAS}"
860877
if [ ! -f "${NVM_ALIAS_PATH}" ]; then
861878
nvm_err 'Alias does not exist.'
862879
return 2
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
erbium
2+
dubnium
3+
carbon
4+
boron
5+
argon

test/fast/Unit tests/nvm_alias LTS-N

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/sh
2+
3+
die () { echo "$@" ; cleanup ; exit 1; }
4+
5+
6+
cleanup() {
7+
unset -f nvm_download
8+
}
9+
10+
\. ../../../nvm.sh
11+
12+
set -ex
13+
14+
MOCKS_DIR="${PWD}/mocks"
15+
16+
# sample output at the time the test was written
17+
TAB_PATH="${MOCKS_DIR}/nodejs.org-dist-index.tab"
18+
nvm_download() {
19+
cat "${TAB_PATH}"
20+
}
21+
22+
nvm_ls_remote >/dev/null || die "nvm_ls_remote_failed?!"
23+
24+
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
25+
26+
N=0
27+
while IFS= read -r LTS; do
28+
N=$(($N+1))
29+
EXPECTED="$(nvm_alias "lts/${LTS}")"
30+
ACTUAL="$(nvm_alias "lts/-${N}")"
31+
[ "${EXPECTED}" = "${ACTUAL}" ] || die "\`nvm_alias lts/-${N}\` was \`${ACTUAL}\`; expected \`${EXPECTED}\`"
32+
done < "${LTS_NAMES_PATH}"
33+
34+
cleanup

update_test_mocks.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,14 @@ set -e
4444

4545
ALIAS_PATH="$MOCKS_DIR/nvm_make_alias LTS alias calls.txt"
4646
: > "$ALIAS_PATH"
47+
LTS_NAMES_PATH="$MOCKS_DIR/LTS_names.txt"
48+
: > "$LTS_NAMES_PATH"
4749
nvm_make_alias() {
4850
# prevent local alias creation, and store arguments
4951
echo "${1}|${2}" >> "$ALIAS_PATH"
52+
if [ "${1}" != 'lts/*' ]; then
53+
echo "${1#lts/}" >> "$LTS_NAMES_PATH"
54+
fi
5055
}
5156
nvm ls-remote --lts > /dev/null
5257

0 commit comments

Comments
 (0)