[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.
Jordan Harband 2016-08-23 10:23:21 -07:00
parent 681c81ad30
commit 1ac7e236b1
3 changed files with 60 additions and 15 deletions

View File

@ -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.

53
nvm.sh
View File

@ -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" )

View File

@ -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