[Fix] --lts=<name>: match codenames containing the name, not as a regex
`nvm_ls_remote_index_tab` compared the codename with awk's `!~`, so the name was a regex: `--lts=.` matched every LTS line, and `--lts=i.on` or `--lts=(` didn't mean what they say. Use `index()` so a name still matches every codename that contains it, but literally, and do the same in `nvm_filter_lts_versions`, for `--lts=<name>` in an alias. Locally, `--lts=<name>` resolved the `lts/<name>` alias, which only exists for full codenames, so `nvm use --lts=ir` failed where `nvm install --lts=ir` installed Iron. Add `nvm_resolve_lts_name`, which picks the newest codename in `$NVM_DIR/.lts-status` that contains the name, and resolve `lts/<codename>` with it in `nvm use`, `uninstall`, `exec`, `run`, and in `nvm install` for its offline lookup and the default and `--alias=` it writes. Without a recorded status, or when no codename contains the name, the name is used as given. Signed-off-by: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com> Co-authored-by: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com> Co-authored-by: Jordan Harband <ljharb@gmail.com>
This commit is contained in:
1 parent
dbda4b9387
commit
62adf80079
6 files changed
+249
-7
No files matched your search
Executable
+57
@@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
|
||||
ORIG_NVM_DIR="${NVM_DIR}"
|
||||
TMP_DIR=''
|
||||
|
||||
cleanup () {
|
||||
case "${TMP_DIR}" in
|
||||
/*) rm -rf "${TMP_DIR}" ;;
|
||||
esac
|
||||
NVM_DIR="${ORIG_NVM_DIR}"
|
||||
export NVM_DIR
|
||||
}
|
||||
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
: nvm.sh
|
||||
\. ../../../nvm.sh
|
||||
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
NVM_DIR="${TMP_DIR}/nvm"
|
||||
export NVM_DIR
|
||||
mkdir -p "${NVM_DIR}" || die 'could not create NVM_DIR'
|
||||
|
||||
[ "_$(nvm_resolve_lts_name on)" = '_on' ] || die "without recorded LTS status, the name should be kept; got >$(nvm_resolve_lts_name on)<"
|
||||
|
||||
row () {
|
||||
printf '%s\t2024-01-01\tsrc\t-\t-\t-\t-\t-\t-\t%s\t-\n' "$1" "$2"
|
||||
}
|
||||
# not newest first, so the newest codename has to come from the versions
|
||||
{ row v20.19.0 Iron; row v26.12.1 -; row v24.11.0 Krypton; row v4.9.1 Argon; row v24.0.0 -; row v22.11.0 Jod; row v8.17.0 Carbon; } | nvm_record_lts_status || die 'could not record LTS status'
|
||||
|
||||
check () {
|
||||
ACTUAL="$(nvm_resolve_lts_name "$1")"
|
||||
[ "_${ACTUAL}" = "_$2" ] || die "\`nvm_resolve_lts_name '$1'\` should print >$2<; got >${ACTUAL}<"
|
||||
}
|
||||
|
||||
# the newest codename containing the name
|
||||
check on krypton
|
||||
check o krypton
|
||||
check ar carbon
|
||||
check arg argon
|
||||
check ir iron
|
||||
check iron iron
|
||||
check j jod
|
||||
# not a regex, and not a codename yet, so kept as given
|
||||
check . .
|
||||
check 'i.on' 'i.on'
|
||||
check '(' '('
|
||||
check nosuch nosuch
|
||||
# names nvm resolves some other way
|
||||
check '*' '*'
|
||||
check -1 -1
|
||||
check '' ''
|
||||
# LTS names are lowercase; an uppercase one is kept, for `nvm_normalize_lts` to reject
|
||||
check Iron Iron
|
||||
|
||||
cleanup
|
||||
Reference in new issue
Block a user