From 1ac7e236b13ff21c8eaa7f6e66dc3c0085639fb2 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 23 Aug 2016 10:23:21 -0700 Subject: [PATCH] [New] Add `lts/foo` support to remote commands. - `nvm ls-remote` - `nvm version-remote` - `nvm install` - `nvm uninstall` Document existing support: - `nvm use` - `nvm exec` - `nvm run` Fixes #1208. --- README.markdown | 14 +++---- nvm.sh | 53 +++++++++++++++++++++---- test/fast/Unit tests/nvm version-remote | 8 ++++ 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/README.markdown b/README.markdown index 64c6cb2..da6077c 100644 --- a/README.markdown +++ b/README.markdown @@ -160,13 +160,13 @@ In place of a version pointer like "0.10" or "5.0" or "4.2.1", you can use the f ### Long-term support Node has a [schedule](https://github.com/nodejs/LTS#lts_schedule) for long-term support (LTS) You can reference LTS versions in aliases and `.nvmrc` files with the notation `lts/*` for the latest LTS, and `lts/argon` for LTS releases from the "argon" line, for example. In addition, the following commands support LTS arguments: - - `nvm install --lts` / `nvm install --lts=argon` - - `nvm uninstall --lts` / `nvm uninstall --lts=argon` - - `nvm use --lts` / `nvm use --lts=argon` - - `nvm exec --lts` / `nvm exec --lts=argon` - - `nvm run --lts` / `nvm run --lts=argon` - - `nvm ls-remote --lts` / `nvm ls-remote --lts=argon` - - `nvm version-remote --lts` / `nvm version-remote --lts=argon` + - `nvm install --lts` / `nvm install --lts=argon` / `nvm install 'lts/*'` / `nvm install lts/argon` + - `nvm uninstall --lts` / `nvm uninstall --lts=argon` / `nvm uninstall 'lts/*'` / `nvm uninstall lts/argon` + - `nvm use --lts` / `nvm use --lts=argon` / `nvm use 'lts/*'` / `nvm use lts/argon` + - `nvm exec --lts` / `nvm exec --lts=argon` / `nvm exec 'lts/*'` / `nvm exec lts/argon` + - `nvm run --lts` / `nvm run --lts=argon` / `nvm run 'lts/*'` / `nvm run lts/argon` + - `nvm ls-remote --lts` / `nvm ls-remote --lts=argon` `nvm ls-remote 'lts/*'` / `nvm ls-remote lts/argon` + - `nvm version-remote --lts` / `nvm version-remote --lts=argon` / `nvm version-remote 'lts/*'` / `nvm version-remote lts/argon` Any time your local copy of `nvm` connects to https://nodejs.org, it will re-create the appropriate local aliases for all available LTS lines. These aliases (stored under `$NVM_DIR/alias/lts`), are managed by `nvm`, and you should not modify, remove, or create these files - expect your changes to be undone, and expect meddling with these files to cause bugs that will likely not be supported. diff --git a/nvm.sh b/nvm.sh index 876863c..9eefd27 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2066,7 +2066,18 @@ nvm() { shift fi - VERSION="$(NVM_VERSION_ONLY=true NVM_LTS="${LTS-}" nvm_remote_version "$provided_version")" + case "${provided_version}" in + 'lts/*') + LTS='*' + provided_version='' + ;; + lts/*) + LTS="${provided_version##lts/}" + provided_version='' + ;; + esac + + VERSION="$(NVM_VERSION_ONLY=true NVM_LTS="${LTS-}" nvm_remote_version "${provided_version}")" if [ "_$VERSION" = "_N/A" ]; then local LTS_MSG @@ -2200,9 +2211,12 @@ nvm() { PATTERN="${1-}" case "${PATTERN-}" in --) ;; - --lts) + --lts | 'lts/*') VERSION="$(nvm_match_version "lts/*")" ;; + lts/*) + VERSION="$(nvm_match_version "lts/${PATTERN##lts/}")" + ;; --lts=*) VERSION="$(nvm_match_version "lts/${PATTERN##--lts=}")" ;; @@ -2614,7 +2628,10 @@ nvm() { do case "${1-}" in --) ;; - --lts) LTS='*' ;; + --lts) + LTS='*' + NVM_FLAVOR="${NVM_NODE_PREFIX}" + ;; --lts=*) LTS="${1##--lts=}" NVM_FLAVOR="${NVM_NODE_PREFIX}" @@ -2625,14 +2642,24 @@ nvm() { return 55; ;; *) - if [ -z "$PATTERN" ]; then + if [ -z "${PATTERN-}" ]; then PATTERN="${1-}" - if [ -z "$NVM_FLAVOR" ]; then - case "_$PATTERN" in - "_$NVM_IOJS_PREFIX" | "_$NVM_NODE_PREFIX") - NVM_FLAVOR="$PATTERN" + if [ -z "${NVM_FLAVOR-}" ]; then + case "${PATTERN}" in + "${NVM_IOJS_PREFIX}" | "${NVM_NODE_PREFIX}") + NVM_FLAVOR="${PATTERN}" PATTERN="" ;; + 'lts/*') + LTS='*' + PATTERN='' + NVM_FLAVOR="${NVM_NODE_PREFIX}" + ;; + lts/*) + LTS="${PATTERN##lts/}" + PATTERN='' + NVM_FLAVOR="${NVM_NODE_PREFIX}" + ;; esac fi fi @@ -2879,6 +2906,16 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')" esac shift done + case "${PATTERN}" in + 'lts/*') + NVM_LTS='*' + unset PATTERN + ;; + lts/*) + NVM_LTS="${PATTERN##lts/}" + unset PATTERN + ;; + esac NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}" ;; "--version" ) diff --git a/test/fast/Unit tests/nvm version-remote b/test/fast/Unit tests/nvm version-remote index 1cb414b..dd587dc 100755 --- a/test/fast/Unit tests/nvm version-remote +++ b/test/fast/Unit tests/nvm version-remote @@ -32,6 +32,14 @@ OUTPUT="$(nvm version-remote --lts=argon foo)" EXPECTED_OUTPUT='NVM_VERSION_ONLY:true,NVM_LTS:argon,PATTERN:foo' [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm version-remote --lts=argon foo\` called nvm_remote_version with >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" +OUTPUT="$(nvm version-remote lts/foo)" +EXPECTED_OUTPUT='NVM_VERSION_ONLY:true,NVM_LTS:foo,PATTERN:' +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm version-remote lts/foo\` called nvm_remote_version with >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" + +OUTPUT="$(nvm version-remote 'lts/*')" +EXPECTED_OUTPUT='NVM_VERSION_ONLY:true,NVM_LTS:*,PATTERN:' +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm version-remote lts/*\` called nvm_remote_version with >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" + set +ex # needed for stderr OUTPUT="$(nvm version-remote --foo bar 2>&1)" set -ex