`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>
107 lines
4.7 KiB
Bash
Executable File
107 lines
4.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
cleanup() {
|
|
[ -n "${NVM_DIR}" ] && [ -d "${NVM_DIR}" ] && rm -rf "${NVM_DIR}"
|
|
rm -f .nvmrc
|
|
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
|
|
unset -f die cleanup reset nvm_remote_version nvm_has_executable nvm_binary_available \
|
|
nvm_get_make_jobs nvm_install_binary nvm_install_source nvm_install_npm_if_needed \
|
|
nvm_install_default_packages
|
|
unset NVM_DIR version OUTPUT
|
|
}
|
|
|
|
die() { echo "$@" ; cleanup ; exit 1; }
|
|
|
|
: nvm.sh
|
|
\. ../../../nvm.sh
|
|
|
|
\. ../../common.sh
|
|
|
|
unset npm_config_prefix NPM_CONFIG_PREFIX
|
|
|
|
if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi
|
|
|
|
NVM_DIR="$(mktemp -d)"
|
|
[ -n "${NVM_DIR}" ] || die 'unable to create temp NVM_DIR'
|
|
version='v20.0.0'
|
|
|
|
# Stay offline: both install methods create a fake node.
|
|
nvm_remote_version() { nvm_echo "${version}"; }
|
|
nvm_has_executable() { return 0; }
|
|
nvm_binary_available() { return 0; }
|
|
nvm_get_make_jobs() { NVM_MAKE_JOBS=1; }
|
|
nvm_install_binary() { make_fake_node "${version}"; }
|
|
nvm_install_source() { make_fake_node "${version}"; }
|
|
nvm_install_npm_if_needed() { return 0; }
|
|
nvm_install_default_packages() { :; }
|
|
|
|
reset() {
|
|
rm -rf "${NVM_DIR:?}/versions" "${NVM_DIR}/alias" .nvmrc
|
|
}
|
|
|
|
reset
|
|
nvm install -s --alias=foo "${version}" > /dev/null 2>&1 || die "\`nvm install -s --alias=foo ${version}\` failed"
|
|
OUTPUT="$(nvm_alias foo)"
|
|
[ "${OUTPUT}" = "${version}" ] || die "expected the foo alias to be ${version} after a source install, got >${OUTPUT}<"
|
|
|
|
reset
|
|
nvm install --alias=foo "${version}" > /dev/null 2>&1 || die "\`nvm install --alias=foo ${version}\` failed"
|
|
OUTPUT="$(nvm_alias foo)"
|
|
[ "${OUTPUT}" = "${version}" ] || die "expected the foo alias to be ${version} after a binary install, got >${OUTPUT}<"
|
|
|
|
reset
|
|
nvm alias default v18.0.0 > /dev/null 2>&1
|
|
nvm install -s --default "${version}" > /dev/null 2>&1 || die "\`nvm install -s --default ${version}\` failed"
|
|
OUTPUT="$(nvm_alias default)"
|
|
[ "${OUTPUT}" = "${version}" ] || die "expected the default alias to be ${version} after a source install, got >${OUTPUT}<"
|
|
|
|
reset
|
|
nvm alias default v18.0.0 > /dev/null 2>&1
|
|
nvm install -s --lts --default > /dev/null 2>&1 || die '`nvm install -s --lts --default` failed'
|
|
OUTPUT="$(nvm_alias default)"
|
|
[ "${OUTPUT}" = 'lts/*' ] || die "expected the default alias to be lts/* after an LTS install, got >${OUTPUT}<"
|
|
|
|
# again, now that the version is installed
|
|
nvm install -s --lts --default > /dev/null 2>&1 || die '`nvm install -s --lts --default` failed for an installed version'
|
|
OUTPUT="$(nvm_alias default)"
|
|
[ "${OUTPUT}" = 'lts/*' ] || die "expected the default alias to stay lts/* for an installed version, got >${OUTPUT}<"
|
|
|
|
# with `--lts` and an explicit version, the alias points at that version
|
|
reset
|
|
nvm install -s --lts --default "${version}" > /dev/null 2>&1 || die "\`nvm install -s --lts --default ${version}\` failed"
|
|
OUTPUT="$(nvm_alias default)"
|
|
[ "${OUTPUT}" = "${version}" ] || die "expected the default alias to be ${version} for \`--lts ${version}\`, got >${OUTPUT}<"
|
|
|
|
# `--lts=<name>` aliases the newest codename containing the name
|
|
reset
|
|
printf 'v22.0.0 jod\n%s iron\nv18.0.0 hydrogen\n' "${version}" > "$(nvm_lts_status_path)"
|
|
nvm install -s --lts=ir --default > /dev/null 2>&1 || die '`nvm install -s --lts=ir --default` failed'
|
|
OUTPUT="$(nvm_alias default)"
|
|
[ "${OUTPUT}" = 'lts/iron' ] || die "expected the default alias to be lts/iron after \`--lts=ir\`, got >${OUTPUT}<"
|
|
|
|
# again, now that the version is installed
|
|
nvm alias default v18.0.0 > /dev/null 2>&1
|
|
nvm install -s --lts=ir --default > /dev/null 2>&1 || die '`nvm install -s --lts=ir --default` failed for an installed version'
|
|
OUTPUT="$(nvm_alias default)"
|
|
[ "${OUTPUT}" = 'lts/iron' ] || die "expected the default alias to be lts/iron for an installed version, got >${OUTPUT}<"
|
|
nvm install -s --lts=ir --alias=foo > /dev/null 2>&1 || die '`nvm install -s --lts=ir --alias=foo` failed for an installed version'
|
|
OUTPUT="$(nvm_alias foo)"
|
|
[ "${OUTPUT}" = 'lts/iron' ] || die "expected the foo alias to be lts/iron for an installed version, got >${OUTPUT}<"
|
|
|
|
reset
|
|
nvm install -s --lts=ir --alias=foo > /dev/null 2>&1 || die '`nvm install -s --lts=ir --alias=foo` failed'
|
|
OUTPUT="$(nvm_alias foo)"
|
|
[ "${OUTPUT}" = 'lts/iron' ] || die "expected the foo alias to be lts/iron after \`--lts=ir\`, got >${OUTPUT}<"
|
|
|
|
# offline, `--lts=<name>` finds the installed version of that codename
|
|
nvm_echo "${version}" > "$(nvm_alias_path)/lts/iron"
|
|
OUTPUT="$(nvm_remote_version() { return 3; }; nvm install --offline --lts=ir 2>&1)" || die "\`nvm install --offline --lts=ir\` failed: >${OUTPUT}<"
|
|
rm -f "$(nvm_lts_status_path)"
|
|
|
|
reset
|
|
nvm install --save "${version}" > /dev/null 2>&1 || die "\`nvm install --save ${version}\` failed"
|
|
OUTPUT="$(cat .nvmrc 2> /dev/null)"
|
|
[ "${OUTPUT}" = "${version}" ] || die "expected \`nvm install --save ${version}\` to write .nvmrc, got >${OUTPUT}<"
|
|
|
|
cleanup
|