From 9d8841a46c3d055813f89d3938ec0728497767de Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 18 Apr 2016 01:00:55 -0700 Subject: [PATCH 01/28] Ensure only the version string is printed out in relevant places. --- nvm.sh | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/nvm.sh b/nvm.sh index 2042a2496d..7b4559fc41 100644 --- a/nvm.sh +++ b/nvm.sh @@ -317,7 +317,14 @@ nvm_remote_version() { else VERSION="$(nvm_remote_versions "$PATTERN" | command tail -1)" fi - nvm_echo "$VERSION" + if [ -n "${NVM_VERSION_ONLY-}" ]; then + command awk 'BEGIN { + n = split(ARGV[1], a); + print a[1] + }' "${VERSION}" + else + nvm_echo "${VERSION}" + fi if [ "_$VERSION" = '_N/A' ]; then return 3 fi @@ -1867,7 +1874,7 @@ nvm() { shift fi - VERSION="$(nvm_remote_version "$provided_version")" + VERSION="$(NVM_VERSION_ONLY=true nvm_remote_version "$provided_version")" if [ "_$VERSION" = "_N/A" ]; then nvm_err "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." @@ -2549,7 +2556,7 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')" nvm_version "$2" ;; "version-remote" ) - nvm_remote_version "$2" + NVM_VERSION_ONLY=true nvm_remote_version "$2" ;; "--version" ) nvm_echo '0.31.2' From 865d2fe3d6dacec99cd3d61b87992f9a91c89733 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 17 Apr 2016 23:39:27 -0700 Subject: [PATCH 02/28] Include LTS version in `nvm_ls_remote` output. --- nvm.sh | 10 +++++++--- test/fast/Unit tests/mocks/nvm_ls_remote.txt | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/nvm.sh b/nvm.sh index 7b4559fc41..622ff69832 100644 --- a/nvm.sh +++ b/nvm.sh @@ -903,7 +903,7 @@ nvm_ls_remote_index_tab() { PATTERN="$(nvm_ensure_version_prefix "$PATTERN")" fi else - PATTERN=".*" + unset PATTERN fi ZSH_HAS_SHWORDSPLIT_UNSET=1 if nvm_has "setopt"; then @@ -914,8 +914,12 @@ nvm_ls_remote_index_tab() { | command sed " 1d; s/^/$PREFIX/; - s/[[:blank:]].*//" \ - | nvm_grep -w "$PATTERN" \ + " \ + | command awk -v pattern="${PATTERN-}" '{ + if (!$1) { next } + if (pattern && tolower($1) !~ tolower(pattern)) { next } + if ($10 !~ /^\-?$/ && ! a[$10]++) print $1, $10; else print $1 + }' \ | $SORT_COMMAND)" if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then unsetopt shwordsplit diff --git a/test/fast/Unit tests/mocks/nvm_ls_remote.txt b/test/fast/Unit tests/mocks/nvm_ls_remote.txt index 0c98561390..c6f2e8fd56 100644 --- a/test/fast/Unit tests/mocks/nvm_ls_remote.txt +++ b/test/fast/Unit tests/mocks/nvm_ls_remote.txt @@ -251,7 +251,7 @@ v4.4.3 v4.4.4 v4.4.5 v4.4.6 -v4.4.7 +v4.4.7 Argon v5.0.0 v5.1.0 v5.1.1 From 01c8b04fd5e73c9c39e5b73220b1485d22a56432 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 18 Apr 2016 00:42:56 -0700 Subject: [PATCH 03/28] Format LTS version when present. --- nvm.sh | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/nvm.sh b/nvm.sh index 622ff69832..973ea7a2ba 100644 --- a/nvm.sh +++ b/nvm.sh @@ -979,6 +979,7 @@ nvm_checksum() { nvm_print_versions() { local VERSION + local LTS local FORMAT local NVM_CURRENT NVM_CURRENT=$(nvm_ls_current) @@ -986,7 +987,11 @@ nvm_print_versions() { if nvm_has_colors; then NVM_HAS_COLORS=1 fi - nvm_echo "$1" | while read -r VERSION; do + local LTS_LENGTH + local LTS_FORMAT + nvm_echo "$1" | while read -r VERSION_LINE; do + VERSION="${VERSION_LINE% *}" + LTS="${VERSION_LINE#* }" FORMAT='%15s' if [ "_$VERSION" = "_$NVM_CURRENT" ]; then if [ "${NVM_HAS_COLORS-}" = '1' ]; then @@ -1005,7 +1010,18 @@ nvm_print_versions() { FORMAT='%15s *' fi fi - command printf -- "$FORMAT\n" "$VERSION" + if [ "$LTS" != "$VERSION" ]; then + LTS=" (Latest LTS: $LTS)" + LTS_LENGTH="${#LTS}" + if [ "${NVM_HAS_COLORS-}" = '1' ]; then + LTS_FORMAT="\033[1;32m%${LTS_LENGTH}s\033[0m" + else + LTS_FORMAT="%${LTS_LENGTH}s" + fi + command printf -- "${FORMAT}${LTS_FORMAT}\n" "$VERSION" "$LTS" + else + command printf -- "${FORMAT}\n" "$VERSION" + fi done } From cb326cb19d27f366cd8ba1bc2b18cdb790d1d053 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 22 Apr 2016 10:25:47 -0700 Subject: [PATCH 04/28] For now, keep the grep to do proper filtering --- nvm.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/nvm.sh b/nvm.sh index 973ea7a2ba..4a33cf8f47 100644 --- a/nvm.sh +++ b/nvm.sh @@ -920,6 +920,7 @@ nvm_ls_remote_index_tab() { if (pattern && tolower($1) !~ tolower(pattern)) { next } if ($10 !~ /^\-?$/ && ! a[$10]++) print $1, $10; else print $1 }' \ + | nvm_grep -w "${PATTERN:-.*}" \ | $SORT_COMMAND)" if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then unsetopt shwordsplit From ae07c3c3450586f26c2fee925413e94e6533c392 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 23 Apr 2016 23:47:25 -0700 Subject: [PATCH 05/28] Add support for `nvm ls-remote --lts` --- nvm.sh | 57 +++- .../mocks/nvm_ls_remote LTS argon.txt | 278 ++++++++++++++++++ .../Unit tests/mocks/nvm_ls_remote LTS.txt | 18 ++ test/fast/Unit tests/mocks/nvm_ls_remote.txt | 34 +-- test/fast/Unit tests/nvm_ls_remote | 17 +- update_test_mocks.sh | 2 + 6 files changed, 371 insertions(+), 35 deletions(-) create mode 100644 test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt create mode 100644 test/fast/Unit tests/mocks/nvm_ls_remote LTS.txt diff --git a/nvm.sh b/nvm.sh index 4a33cf8f47..6c72cae33c 100644 --- a/nvm.sh +++ b/nvm.sh @@ -858,14 +858,16 @@ nvm_ls_remote() { else PATTERN=".*" fi - nvm_ls_remote_index_tab node std "$NVM_NODEJS_ORG_MIRROR" "$PATTERN" + NVM_LTS="${NVM_LTS-}" nvm_ls_remote_index_tab node std "$NVM_NODEJS_ORG_MIRROR" "$PATTERN" } nvm_ls_remote_iojs() { - nvm_ls_remote_index_tab iojs std "$NVM_IOJS_ORG_MIRROR" "$1" + NVM_LTS="${NVM_LTS-}" nvm_ls_remote_index_tab iojs std "$NVM_IOJS_ORG_MIRROR" "$1" } nvm_ls_remote_index_tab() { + local LTS + LTS="${NVM_LTS-}" if [ "$#" -lt 4 ]; then nvm_err 'not enough arguments' return 5 @@ -915,10 +917,11 @@ nvm_ls_remote_index_tab() { 1d; s/^/$PREFIX/; " \ - | command awk -v pattern="${PATTERN-}" '{ + | command awk -v pattern="${PATTERN-}" -v lts="${LTS-}" '{ if (!$1) { next } if (pattern && tolower($1) !~ tolower(pattern)) { next } - if ($10 !~ /^\-?$/ && ! a[$10]++) print $1, $10; else print $1 + if (lts == "*" && $10 ~ /^\-?$/) { next } + if ($10 !~ /^\-?$/) print $1, $10; else print $1 }' \ | nvm_grep -w "${PATTERN:-.*}" \ | $SORT_COMMAND)" @@ -1012,7 +1015,7 @@ nvm_print_versions() { fi fi if [ "$LTS" != "$VERSION" ]; then - LTS=" (Latest LTS: $LTS)" + LTS=" (LTS: $LTS)" LTS_LENGTH="${#LTS}" if [ "${NVM_HAS_COLORS-}" = '1' ]; then LTS_FORMAT="\033[1;32m%${LTS_LENGTH}s\033[0m" @@ -1791,9 +1794,11 @@ nvm() { nvm_echo ' nvm run [--silent] [] Run `node` on with as arguments. Uses .nvmrc if available' nvm_echo ' nvm current Display currently activated version' nvm_echo ' nvm ls List installed versions' - nvm_echo ' nvm ls List versions matching a given description' + nvm_echo ' nvm ls List versions matching a given ' nvm_echo ' nvm ls-remote List remote versions available for install' + nvm_echo ' --lts When listing, only show LTS (long-term support) versions' nvm_echo ' nvm ls-remote List remote versions available for install, matching a given ' + nvm_echo ' --lts When listing, only show LTS (long-term support) versions' nvm_echo ' nvm version Resolve the given description to a single local version' nvm_echo ' nvm version-remote Resolve the given description to a single remote version' nvm_echo ' nvm deactivate Undo effects of `nvm` on current shell' @@ -2370,19 +2375,39 @@ nvm() { return $NVM_LS_EXIT_CODE ;; "ls-remote" | "list-remote" ) - local PATTERN - PATTERN="${2-}" + local LTS local NVM_IOJS_PREFIX NVM_IOJS_PREFIX="$(nvm_iojs_prefix)" local NVM_NODE_PREFIX NVM_NODE_PREFIX="$(nvm_node_prefix)" + local PATTERN local NVM_FLAVOR - case "_$PATTERN" in - "_$NVM_IOJS_PREFIX" | "_$NVM_NODE_PREFIX" ) - NVM_FLAVOR="$PATTERN" - PATTERN="$3" - ;; - esac + while [ $# -gt 1 ] + do + case "$2" in + --lts) + LTS='*' + ;; + --*) + nvm_err "Unsupported option \"$2\"." + return 55; + ;; + *) + if [ -z "$PATTERN" ]; then + PATTERN="${2-}" + if [ -z "$NVM_FLAVOR" ]; then + case "_$PATTERN" in + "_$NVM_IOJS_PREFIX" | "_$NVM_NODE_PREFIX") + NVM_FLAVOR="$PATTERN" + PATTERN="" + ;; + esac + fi + fi + ;; + esac + shift + done local NVM_LS_REMOTE_EXIT_CODE NVM_LS_REMOTE_EXIT_CODE=0 @@ -2392,7 +2417,7 @@ nvm() { NVM_LS_REMOTE_POST_MERGED_OUTPUT='' if [ "_$NVM_FLAVOR" != "_$NVM_IOJS_PREFIX" ]; then local NVM_LS_REMOTE_OUTPUT - NVM_LS_REMOTE_OUTPUT=$(nvm_ls_remote "$PATTERN") + NVM_LS_REMOTE_OUTPUT=$(NVM_LTS="${LTS-}" nvm_ls_remote "$PATTERN") # split output into two NVM_LS_REMOTE_PRE_MERGED_OUTPUT="${NVM_LS_REMOTE_OUTPUT%%v4\.0\.0*}" NVM_LS_REMOTE_POST_MERGED_OUTPUT="${NVM_LS_REMOTE_OUTPUT#$NVM_LS_REMOTE_PRE_MERGED_OUTPUT}" @@ -2404,7 +2429,7 @@ nvm() { local NVM_LS_REMOTE_IOJS_OUTPUT NVM_LS_REMOTE_IOJS_OUTPUT='' if [ "_$NVM_FLAVOR" != "_$NVM_NODE_PREFIX" ]; then - NVM_LS_REMOTE_IOJS_OUTPUT=$(nvm_ls_remote_iojs "$PATTERN") + NVM_LS_REMOTE_IOJS_OUTPUT=$(NVM_LTS="${LTS-}" nvm_ls_remote_iojs "$PATTERN") NVM_LS_REMOTE_IOJS_EXIT_CODE=$? fi diff --git a/test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt b/test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt new file mode 100644 index 0000000000..e8c3e5fe9e --- /dev/null +++ b/test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt @@ -0,0 +1,278 @@ +v0.1.14 +v0.1.15 +v0.1.16 +v0.1.17 +v0.1.18 +v0.1.19 +v0.1.20 +v0.1.21 +v0.1.22 +v0.1.23 +v0.1.24 +v0.1.25 +v0.1.26 +v0.1.27 +v0.1.28 +v0.1.29 +v0.1.30 +v0.1.31 +v0.1.32 +v0.1.33 +v0.1.90 +v0.1.91 +v0.1.92 +v0.1.93 +v0.1.94 +v0.1.95 +v0.1.96 +v0.1.97 +v0.1.98 +v0.1.99 +v0.1.100 +v0.1.101 +v0.1.102 +v0.1.103 +v0.1.104 +v0.2.0 +v0.2.1 +v0.2.2 +v0.2.3 +v0.2.4 +v0.2.5 +v0.2.6 +v0.3.0 +v0.3.1 +v0.3.2 +v0.3.3 +v0.3.4 +v0.3.5 +v0.3.6 +v0.3.7 +v0.3.8 +v0.4.0 +v0.4.1 +v0.4.2 +v0.4.3 +v0.4.4 +v0.4.5 +v0.4.6 +v0.4.7 +v0.4.8 +v0.4.9 +v0.4.10 +v0.4.11 +v0.4.12 +v0.5.0 +v0.5.1 +v0.5.2 +v0.5.3 +v0.5.4 +v0.5.5 +v0.5.6 +v0.5.7 +v0.5.8 +v0.5.9 +v0.5.10 +v0.6.0 +v0.6.1 +v0.6.2 +v0.6.3 +v0.6.4 +v0.6.5 +v0.6.6 +v0.6.7 +v0.6.8 +v0.6.9 +v0.6.10 +v0.6.11 +v0.6.12 +v0.6.13 +v0.6.14 +v0.6.15 +v0.6.16 +v0.6.17 +v0.6.18 +v0.6.19 +v0.6.20 +v0.6.21 +v0.7.0 +v0.7.1 +v0.7.2 +v0.7.3 +v0.7.4 +v0.7.5 +v0.7.6 +v0.7.7 +v0.7.8 +v0.7.9 +v0.7.10 +v0.7.11 +v0.7.12 +v0.8.0 +v0.8.1 +v0.8.2 +v0.8.3 +v0.8.4 +v0.8.5 +v0.8.6 +v0.8.7 +v0.8.8 +v0.8.9 +v0.8.10 +v0.8.11 +v0.8.12 +v0.8.13 +v0.8.14 +v0.8.15 +v0.8.16 +v0.8.17 +v0.8.18 +v0.8.19 +v0.8.20 +v0.8.21 +v0.8.22 +v0.8.23 +v0.8.24 +v0.8.25 +v0.8.26 +v0.8.27 +v0.8.28 +v0.9.0 +v0.9.1 +v0.9.2 +v0.9.3 +v0.9.4 +v0.9.5 +v0.9.6 +v0.9.7 +v0.9.8 +v0.9.9 +v0.9.10 +v0.9.11 +v0.9.12 +v0.10.0 +v0.10.1 +v0.10.2 +v0.10.3 +v0.10.4 +v0.10.5 +v0.10.6 +v0.10.7 +v0.10.8 +v0.10.9 +v0.10.10 +v0.10.11 +v0.10.12 +v0.10.13 +v0.10.14 +v0.10.15 +v0.10.16 +v0.10.17 +v0.10.18 +v0.10.19 +v0.10.20 +v0.10.21 +v0.10.22 +v0.10.23 +v0.10.24 +v0.10.25 +v0.10.26 +v0.10.27 +v0.10.28 +v0.10.29 +v0.10.30 +v0.10.31 +v0.10.32 +v0.10.33 +v0.10.34 +v0.10.35 +v0.10.36 +v0.10.37 +v0.10.38 +v0.10.39 +v0.10.40 +v0.10.41 +v0.10.42 +v0.10.43 +v0.10.44 +v0.10.45 +v0.10.46 +v0.11.0 +v0.11.1 +v0.11.2 +v0.11.3 +v0.11.4 +v0.11.5 +v0.11.6 +v0.11.7 +v0.11.8 +v0.11.9 +v0.11.10 +v0.11.11 +v0.11.12 +v0.11.13 +v0.11.14 +v0.11.15 +v0.11.16 +v0.12.0 +v0.12.1 +v0.12.2 +v0.12.3 +v0.12.4 +v0.12.5 +v0.12.6 +v0.12.7 +v0.12.8 +v0.12.9 +v0.12.10 +v0.12.11 +v0.12.12 +v0.12.13 +v0.12.14 +v0.12.15 +v4.0.0 +v4.1.0 +v4.1.1 +v4.1.2 +v4.2.0 Argon +v4.2.1 Argon +v4.2.2 Argon +v4.2.3 Argon +v4.2.4 Argon +v4.2.5 Argon +v4.2.6 Argon +v4.3.0 Argon +v4.3.1 Argon +v4.3.2 Argon +v4.4.0 Argon +v4.4.1 Argon +v4.4.2 Argon +v4.4.3 Argon +v4.4.4 Argon +v4.4.5 Argon +v4.4.6 Argon +v4.4.7 Argon +v5.0.0 +v5.1.0 +v5.1.1 +v5.2.0 +v5.3.0 +v5.4.0 +v5.4.1 +v5.5.0 +v5.6.0 +v5.7.0 +v5.7.1 +v5.8.0 +v5.9.0 +v5.9.1 +v5.10.0 +v5.10.1 +v5.11.0 +v5.11.1 +v5.12.0 +v6.0.0 +v6.1.0 +v6.2.0 +v6.2.1 +v6.2.2 diff --git a/test/fast/Unit tests/mocks/nvm_ls_remote LTS.txt b/test/fast/Unit tests/mocks/nvm_ls_remote LTS.txt new file mode 100644 index 0000000000..f46b35ab9a --- /dev/null +++ b/test/fast/Unit tests/mocks/nvm_ls_remote LTS.txt @@ -0,0 +1,18 @@ +v4.2.0 Argon +v4.2.1 Argon +v4.2.2 Argon +v4.2.3 Argon +v4.2.4 Argon +v4.2.5 Argon +v4.2.6 Argon +v4.3.0 Argon +v4.3.1 Argon +v4.3.2 Argon +v4.4.0 Argon +v4.4.1 Argon +v4.4.2 Argon +v4.4.3 Argon +v4.4.4 Argon +v4.4.5 Argon +v4.4.6 Argon +v4.4.7 Argon diff --git a/test/fast/Unit tests/mocks/nvm_ls_remote.txt b/test/fast/Unit tests/mocks/nvm_ls_remote.txt index c6f2e8fd56..e8c3e5fe9e 100644 --- a/test/fast/Unit tests/mocks/nvm_ls_remote.txt +++ b/test/fast/Unit tests/mocks/nvm_ls_remote.txt @@ -234,23 +234,23 @@ v4.0.0 v4.1.0 v4.1.1 v4.1.2 -v4.2.0 -v4.2.1 -v4.2.2 -v4.2.3 -v4.2.4 -v4.2.5 -v4.2.6 -v4.3.0 -v4.3.1 -v4.3.2 -v4.4.0 -v4.4.1 -v4.4.2 -v4.4.3 -v4.4.4 -v4.4.5 -v4.4.6 +v4.2.0 Argon +v4.2.1 Argon +v4.2.2 Argon +v4.2.3 Argon +v4.2.4 Argon +v4.2.5 Argon +v4.2.6 Argon +v4.3.0 Argon +v4.3.1 Argon +v4.3.2 Argon +v4.4.0 Argon +v4.4.1 Argon +v4.4.2 Argon +v4.4.3 Argon +v4.4.4 Argon +v4.4.5 Argon +v4.4.6 Argon v4.4.7 Argon v5.0.0 v5.1.0 diff --git a/test/fast/Unit tests/nvm_ls_remote b/test/fast/Unit tests/nvm_ls_remote index c824dd4872..52dd1f3e2f 100755 --- a/test/fast/Unit tests/nvm_ls_remote +++ b/test/fast/Unit tests/nvm_ls_remote @@ -8,13 +8,15 @@ cleanup() { . ../../../nvm.sh +MOCKS_DIR="$PWD/mocks" + # sample output at the time the test was written -TAB_PATH="$PWD/mocks/nodejs.org-dist-index.tab" +TAB_PATH="$MOCKS_DIR/nodejs.org-dist-index.tab" nvm_download() { cat "$TAB_PATH" } -EXPECTED_OUTPUT_PATH="$PWD/mocks/nvm_ls_remote.txt" +EXPECTED_OUTPUT_PATH="$MOCKS_DIR/nvm_ls_remote.txt" OUTPUT="$(nvm_ls_remote foo)" EXIT_CODE="$(nvm_ls_remote foo >/dev/null 2>&1 ; echo $?)" @@ -55,4 +57,15 @@ OUTPUT="$(nvm_ls_remote unstable)" EXPECTED_OUTPUT="v0.11.16" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote unstable did not output $EXPECTED_OUTPUT; got $OUTPUT" +EXPECTED_OUTPUT_PATH="$MOCKS_DIR/nvm_ls_remote LTS.txt" +EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH")" +OUTPUT="$(NVM_LTS='*' nvm_ls_remote)" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "\`NVM_LTS='*' nvm_ls_remote\` did not output >$EXPECTED_OUTPUT<; got >$OUTPUT<" + +EXPECTED_OUTPUT_PATH="$MOCKS_DIR/nvm_ls_remote LTS argon.txt" +EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH")" +OUTPUT="$(NVM_LTS=argon nvm_ls_remote)" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "\`NVM_LTS=argon nvm_ls_remote\` did not output >$EXPECTED_OUTPUT<; got >$OUTPUT<" + cleanup diff --git a/update_test_mocks.sh b/update_test_mocks.sh index ee08915b89..571b870d85 100755 --- a/update_test_mocks.sh +++ b/update_test_mocks.sh @@ -13,6 +13,8 @@ mkdir -p "$MOCKS_DIR" nvm_ls_remote > "$MOCKS_DIR/nvm_ls_remote.txt" nvm_ls_remote_iojs > "$MOCKS_DIR/nvm_ls_remote_iojs.txt" +NVM_LTS=* nvm_ls_remote > "$MOCKS_DIR/nvm_ls_remote LTS.txt" +NVM_LTS=argon nvm_ls_remote > "$MOCKS_DIR/nvm_ls_remote LTS argon.txt" nvm_download -L -s "$NVM_NODEJS_ORG_MIRROR/index.tab" -o - > "$MOCKS_DIR/nodejs.org-dist-index.tab" nvm_download -L -s "$NVM_IOJS_ORG_MIRROR/index.tab" -o - > "$MOCKS_DIR/iojs.org-dist-index.tab" From 584bdd8ba31006e5c1153b44d44a7f70e5924f22 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 24 Apr 2016 10:55:30 -0700 Subject: [PATCH 06/28] Print the LTS version on all versions with that info, but put the non-latest in gray. --- nvm.sh | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/nvm.sh b/nvm.sh index 6c72cae33c..9d9f962c35 100644 --- a/nvm.sh +++ b/nvm.sh @@ -993,36 +993,52 @@ nvm_print_versions() { fi local LTS_LENGTH local LTS_FORMAT - nvm_echo "$1" | while read -r VERSION_LINE; do - VERSION="${VERSION_LINE% *}" + nvm_echo "$1" \ + | command sed '1!G;h;$!d' \ + | command awk '{ if ($2 && a[$2]++) { print $1, "(LTS: " $2 ")" } else if ($2) { print $1, "(Latest LTS: " $2 ")" } else { print $0 } }' \ + | command sed '1!G;h;$!d' \ + | while read -r VERSION_LINE; do + VERSION="${VERSION_LINE%% *}" LTS="${VERSION_LINE#* }" - FORMAT='%15s' + FORMAT='%15s ' if [ "_$VERSION" = "_$NVM_CURRENT" ]; then if [ "${NVM_HAS_COLORS-}" = '1' ]; then - FORMAT='\033[0;32m-> %12s\033[0m' + FORMAT='\033[0;32m-> %12s\033[0m ' else FORMAT='-> %12s *' fi elif [ "$VERSION" = "system" ]; then if [ "${NVM_HAS_COLORS-}" = '1' ]; then - FORMAT='\033[0;33m%15s\033[0m' + FORMAT='\033[0;33m%15s\033[0m ' fi elif nvm_is_version_installed "$VERSION"; then if [ "${NVM_HAS_COLORS-}" = '1' ]; then - FORMAT='\033[0;34m%15s\033[0m' + FORMAT='\033[0;34m%15s\033[0m ' else FORMAT='%15s *' fi fi - if [ "$LTS" != "$VERSION" ]; then - LTS=" (LTS: $LTS)" - LTS_LENGTH="${#LTS}" - if [ "${NVM_HAS_COLORS-}" = '1' ]; then - LTS_FORMAT="\033[1;32m%${LTS_LENGTH}s\033[0m" - else - LTS_FORMAT="%${LTS_LENGTH}s" - fi - command printf -- "${FORMAT}${LTS_FORMAT}\n" "$VERSION" "$LTS" + if [ "${LTS}" != "${VERSION}" ]; then + case "${LTS}" in + *Latest*) + LTS="${LTS##Latest }" + LTS_LENGTH="${#LTS}" + if [ "${NVM_HAS_COLORS-}" = '1' ]; then + LTS_FORMAT="\033[1;32m%${LTS_LENGTH}s\033[0m" + else + LTS_FORMAT="%${LTS_LENGTH}s" + fi + ;; + *) + LTS_LENGTH="${#LTS}" + if [ "${NVM_HAS_COLORS-}" = '1' ]; then + LTS_FORMAT="\033[0;37m%${LTS_LENGTH}s\033[0m" + else + LTS_FORMAT="%${LTS_LENGTH}s" + fi + ;; + esac + command printf -- "${FORMAT}${LTS_FORMAT}\n" "$VERSION" " $LTS" else command printf -- "${FORMAT}\n" "$VERSION" fi From 1d908d82568c458ff8d88e80a2068a7957390e00 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 24 Apr 2016 16:26:32 -0700 Subject: [PATCH 07/28] Add `--lts` support to `nvm version-remote` --- nvm.sh | 41 ++++++++++++++++++------- test/fast/Unit tests/nvm_remote_version | 20 ++++++------ 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/nvm.sh b/nvm.sh index 9d9f962c35..97041941d6 100644 --- a/nvm.sh +++ b/nvm.sh @@ -308,14 +308,14 @@ nvm_remote_version() { if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then case "_$PATTERN" in "_$(nvm_iojs_prefix)") - VERSION="$(nvm_ls_remote_iojs | command tail -1)" + VERSION="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote_iojs | command tail -1)" ;; *) - VERSION="$(nvm_ls_remote "$PATTERN")" + VERSION="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote "$PATTERN")" ;; esac else - VERSION="$(nvm_remote_versions "$PATTERN" | command tail -1)" + VERSION="$(NVM_LTS="${NVM_LTS-}" nvm_remote_versions "$PATTERN" | command tail -1)" fi if [ -n "${NVM_VERSION_ONLY-}" ]; then command awk 'BEGIN { @@ -337,18 +337,18 @@ nvm_remote_versions() { PATTERN="$1" case "_$PATTERN" in "_$NVM_IOJS_PREFIX" | "_io.js") - VERSIONS="$(nvm_ls_remote_iojs)" + VERSIONS="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote_iojs)" ;; "_$(nvm_node_prefix)") - VERSIONS="$(nvm_ls_remote)" + VERSIONS="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote)" ;; *) if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then nvm_err 'Implicit aliases are not supported in nvm_remote_versions.' return 1 fi - VERSIONS="$(nvm_echo "$(nvm_ls_remote "$PATTERN") -$(nvm_ls_remote_iojs "$PATTERN")" | nvm_grep -v "N/A" | command sed '/^$/d')" + VERSIONS="$(nvm_echo "$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote "$PATTERN") +$(NVM_LTS=${NVM_LTS-} nvm_ls_remote_iojs "$PATTERN")" | nvm_grep -v "N/A" | command sed '/^$/d')" ;; esac @@ -852,7 +852,7 @@ nvm_ls_remote() { local PATTERN PATTERN="$1" if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then - PATTERN="$(nvm_ls_remote "$(nvm_print_implicit_alias remote "$PATTERN")" | command tail -1)" + PATTERN="$(NVM_LTS="${NVM_LTS-}" nvm_ls_remote "$(nvm_print_implicit_alias remote "$PATTERN")" | command awk '{ print $1 }' | command tail -1)" elif [ -n "$PATTERN" ]; then PATTERN="$(nvm_ensure_version_prefix "$PATTERN")" else @@ -1817,6 +1817,7 @@ nvm() { nvm_echo ' --lts When listing, only show LTS (long-term support) versions' nvm_echo ' nvm version Resolve the given description to a single local version' nvm_echo ' nvm version-remote Resolve the given description to a single remote version' + nvm_echo ' --lts When listing, only select from LTS (long-term support) versions' nvm_echo ' nvm deactivate Undo effects of `nvm` on current shell' nvm_echo ' nvm alias [] Show all aliases beginning with ' nvm_echo ' nvm alias Set an alias named pointing to ' @@ -2444,8 +2445,8 @@ nvm() { NVM_LS_REMOTE_IOJS_EXIT_CODE=0 local NVM_LS_REMOTE_IOJS_OUTPUT NVM_LS_REMOTE_IOJS_OUTPUT='' - if [ "_$NVM_FLAVOR" != "_$NVM_NODE_PREFIX" ]; then - NVM_LS_REMOTE_IOJS_OUTPUT=$(NVM_LTS="${LTS-}" nvm_ls_remote_iojs "$PATTERN") + if [ "_$NVM_FLAVOR" != "_$NVM_NODE_PREFIX" ] && [ -z "${LTS-}" ]; then + NVM_LS_REMOTE_IOJS_OUTPUT=$(nvm_ls_remote_iojs "$PATTERN") NVM_LS_REMOTE_IOJS_EXIT_CODE=$? fi @@ -2618,7 +2619,25 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')" nvm_version "$2" ;; "version-remote" ) - NVM_VERSION_ONLY=true nvm_remote_version "$2" + local NVM_LTS + local PATTERN + while [ $# -gt 1 ] + do + case "$2" in + --lts) + NVM_LTS='*' + ;; + --*) + nvm_err "Unsupported option \"$2\"." + return 55; + ;; + *) + PATTERN="${PATTERN:-$2}" + ;; + esac + shift + done + NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}" ;; "--version" ) nvm_echo '0.31.2' diff --git a/test/fast/Unit tests/nvm_remote_version b/test/fast/Unit tests/nvm_remote_version index 39fa34d494..0c17591d8f 100755 --- a/test/fast/Unit tests/nvm_remote_version +++ b/test/fast/Unit tests/nvm_remote_version @@ -26,34 +26,34 @@ EXIT_CODE="$(nvm_remote_version iojs-foo >/dev/null 2>&1 ; echo $?)" nvm_ls_remote() { - if ! nvm_is_iojs_version "$1"; then - echo "test output" - echo "more test output" - echo "pattern received: _$1_" + if [ -z "$1" ] || ! nvm_is_iojs_version "$1"; then + echo "test_output" + echo "more_test_output" + echo "pattern_received:_$1_" fi } nvm_ls_remote_iojs() { if [ -z "$1" ] || nvm_is_iojs_version "$1"; then - echo "test iojs output" - echo "more iojs test output" - echo "iojs pattern received: _$1_" + echo "test_iojs_output" + echo "more_iojs_test_output" + echo "iojs_pattern_received:_$1_" fi } OUTPUT="$(nvm_remote_version foo)" EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" -[ "_$OUTPUT" = "_pattern received: _foo_" ] \ +[ "_$OUTPUT" = "_pattern_received:_foo_" ] \ || die "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $OUTPUT" [ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version foo did not exit with 0, got $EXIT_CODE" OUTPUT="$(nvm_remote_version iojs-foo)" EXIT_CODE="$(nvm_remote_version iojs-foo >/dev/null 2>&1 ; echo $?)" -[ "_$OUTPUT" = "_iojs pattern received: _iojs-foo_" ] \ +[ "_$OUTPUT" = "_iojs_pattern_received:_iojs-foo_" ] \ || die "nvm_remote_version iojs-foo did not return last line only of nvm_ls_remote_iojs foo; got $OUTPUT" [ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version iojs-foo did not exit with 0, got $EXIT_CODE" OUTPUT="$(nvm_remote_version iojs)" EXIT_CODE="$(nvm_remote_version iojs >/dev/null 2>&1 ; echo $?)" -[ "_$OUTPUT" = "_iojs pattern received: __" ] \ +[ "_$OUTPUT" = "_iojs_pattern_received:__" ] \ || die "nvm_remote_version iojs did not return last line only of nvm_ls_remote_iojs; got $OUTPUT" [ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version iojs did not exit with 0, got $EXIT_CODE" From 4699657e98e55c2127ee2ba2d50e32335e00ffc8 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 25 Apr 2016 00:55:35 -0700 Subject: [PATCH 08/28] Add `--lts=argon` etc, so the LTS line can be targeted. --- nvm.sh | 9 + .../mocks/nvm_ls_remote LTS argon.txt | 260 ------------------ 2 files changed, 9 insertions(+), 260 deletions(-) diff --git a/nvm.sh b/nvm.sh index 97041941d6..5090a5d819 100644 --- a/nvm.sh +++ b/nvm.sh @@ -921,6 +921,7 @@ nvm_ls_remote_index_tab() { if (!$1) { next } if (pattern && tolower($1) !~ tolower(pattern)) { next } if (lts == "*" && $10 ~ /^\-?$/) { next } + if (lts && lts != "*" && tolower($10) !~ tolower(lts)) { next } if ($10 !~ /^\-?$/) print $1, $10; else print $1 }' \ | nvm_grep -w "${PATTERN:-.*}" \ @@ -1815,9 +1816,11 @@ nvm() { nvm_echo ' --lts When listing, only show LTS (long-term support) versions' nvm_echo ' nvm ls-remote List remote versions available for install, matching a given ' nvm_echo ' --lts When listing, only show LTS (long-term support) versions' + nvm_echo ' --lts= When listing, only show versions for a specific LTS line' nvm_echo ' nvm version Resolve the given description to a single local version' nvm_echo ' nvm version-remote Resolve the given description to a single remote version' nvm_echo ' --lts When listing, only select from LTS (long-term support) versions' + nvm_echo ' --lts= When listing, only select from versions for a specific LTS line' nvm_echo ' nvm deactivate Undo effects of `nvm` on current shell' nvm_echo ' nvm alias [] Show all aliases beginning with ' nvm_echo ' nvm alias Set an alias named pointing to ' @@ -2405,6 +2408,9 @@ nvm() { --lts) LTS='*' ;; + --lts=*) + LTS="${2##--lts=}" + ;; --*) nvm_err "Unsupported option \"$2\"." return 55; @@ -2627,6 +2633,9 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')" --lts) NVM_LTS='*' ;; + --lts=*) + NVM_LTS="${2##--lts=}" + ;; --*) nvm_err "Unsupported option \"$2\"." return 55; diff --git a/test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt b/test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt index e8c3e5fe9e..f46b35ab9a 100644 --- a/test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt +++ b/test/fast/Unit tests/mocks/nvm_ls_remote LTS argon.txt @@ -1,239 +1,3 @@ -v0.1.14 -v0.1.15 -v0.1.16 -v0.1.17 -v0.1.18 -v0.1.19 -v0.1.20 -v0.1.21 -v0.1.22 -v0.1.23 -v0.1.24 -v0.1.25 -v0.1.26 -v0.1.27 -v0.1.28 -v0.1.29 -v0.1.30 -v0.1.31 -v0.1.32 -v0.1.33 -v0.1.90 -v0.1.91 -v0.1.92 -v0.1.93 -v0.1.94 -v0.1.95 -v0.1.96 -v0.1.97 -v0.1.98 -v0.1.99 -v0.1.100 -v0.1.101 -v0.1.102 -v0.1.103 -v0.1.104 -v0.2.0 -v0.2.1 -v0.2.2 -v0.2.3 -v0.2.4 -v0.2.5 -v0.2.6 -v0.3.0 -v0.3.1 -v0.3.2 -v0.3.3 -v0.3.4 -v0.3.5 -v0.3.6 -v0.3.7 -v0.3.8 -v0.4.0 -v0.4.1 -v0.4.2 -v0.4.3 -v0.4.4 -v0.4.5 -v0.4.6 -v0.4.7 -v0.4.8 -v0.4.9 -v0.4.10 -v0.4.11 -v0.4.12 -v0.5.0 -v0.5.1 -v0.5.2 -v0.5.3 -v0.5.4 -v0.5.5 -v0.5.6 -v0.5.7 -v0.5.8 -v0.5.9 -v0.5.10 -v0.6.0 -v0.6.1 -v0.6.2 -v0.6.3 -v0.6.4 -v0.6.5 -v0.6.6 -v0.6.7 -v0.6.8 -v0.6.9 -v0.6.10 -v0.6.11 -v0.6.12 -v0.6.13 -v0.6.14 -v0.6.15 -v0.6.16 -v0.6.17 -v0.6.18 -v0.6.19 -v0.6.20 -v0.6.21 -v0.7.0 -v0.7.1 -v0.7.2 -v0.7.3 -v0.7.4 -v0.7.5 -v0.7.6 -v0.7.7 -v0.7.8 -v0.7.9 -v0.7.10 -v0.7.11 -v0.7.12 -v0.8.0 -v0.8.1 -v0.8.2 -v0.8.3 -v0.8.4 -v0.8.5 -v0.8.6 -v0.8.7 -v0.8.8 -v0.8.9 -v0.8.10 -v0.8.11 -v0.8.12 -v0.8.13 -v0.8.14 -v0.8.15 -v0.8.16 -v0.8.17 -v0.8.18 -v0.8.19 -v0.8.20 -v0.8.21 -v0.8.22 -v0.8.23 -v0.8.24 -v0.8.25 -v0.8.26 -v0.8.27 -v0.8.28 -v0.9.0 -v0.9.1 -v0.9.2 -v0.9.3 -v0.9.4 -v0.9.5 -v0.9.6 -v0.9.7 -v0.9.8 -v0.9.9 -v0.9.10 -v0.9.11 -v0.9.12 -v0.10.0 -v0.10.1 -v0.10.2 -v0.10.3 -v0.10.4 -v0.10.5 -v0.10.6 -v0.10.7 -v0.10.8 -v0.10.9 -v0.10.10 -v0.10.11 -v0.10.12 -v0.10.13 -v0.10.14 -v0.10.15 -v0.10.16 -v0.10.17 -v0.10.18 -v0.10.19 -v0.10.20 -v0.10.21 -v0.10.22 -v0.10.23 -v0.10.24 -v0.10.25 -v0.10.26 -v0.10.27 -v0.10.28 -v0.10.29 -v0.10.30 -v0.10.31 -v0.10.32 -v0.10.33 -v0.10.34 -v0.10.35 -v0.10.36 -v0.10.37 -v0.10.38 -v0.10.39 -v0.10.40 -v0.10.41 -v0.10.42 -v0.10.43 -v0.10.44 -v0.10.45 -v0.10.46 -v0.11.0 -v0.11.1 -v0.11.2 -v0.11.3 -v0.11.4 -v0.11.5 -v0.11.6 -v0.11.7 -v0.11.8 -v0.11.9 -v0.11.10 -v0.11.11 -v0.11.12 -v0.11.13 -v0.11.14 -v0.11.15 -v0.11.16 -v0.12.0 -v0.12.1 -v0.12.2 -v0.12.3 -v0.12.4 -v0.12.5 -v0.12.6 -v0.12.7 -v0.12.8 -v0.12.9 -v0.12.10 -v0.12.11 -v0.12.12 -v0.12.13 -v0.12.14 -v0.12.15 -v4.0.0 -v4.1.0 -v4.1.1 -v4.1.2 v4.2.0 Argon v4.2.1 Argon v4.2.2 Argon @@ -252,27 +16,3 @@ v4.4.4 Argon v4.4.5 Argon v4.4.6 Argon v4.4.7 Argon -v5.0.0 -v5.1.0 -v5.1.1 -v5.2.0 -v5.3.0 -v5.4.0 -v5.4.1 -v5.5.0 -v5.6.0 -v5.7.0 -v5.7.1 -v5.8.0 -v5.9.0 -v5.9.1 -v5.10.0 -v5.10.1 -v5.11.0 -v5.11.1 -v5.12.0 -v6.0.0 -v6.1.0 -v6.2.0 -v6.2.1 -v6.2.2 From 44f4817f7db7f22d273074ceea039dee0928d3c4 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 25 Apr 2016 00:44:24 -0700 Subject: [PATCH 09/28] Prevent attempts to `nvm install --lts` --- nvm.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/nvm.sh b/nvm.sh index 5090a5d819..4fa223c6c2 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1902,6 +1902,10 @@ nvm() { nvm_get_make_jobs "$1" shift # consume job count ;; + --lts*) + nvm_err 'installing based on LTS filtering is not yet supported.' + return 12 + ;; *) break # stop parsing args ;; From 9bd743e0be4eaa0effff33e7c2ee4c8bf7f1a528 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 25 Apr 2016 00:44:24 -0700 Subject: [PATCH 10/28] `nvm install`: Add support for `--lts` and `--lts=argon` --- nvm.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 15 deletions(-) diff --git a/nvm.sh b/nvm.sh index 4fa223c6c2..f2918e090a 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1805,6 +1805,8 @@ nvm() { nvm_echo ' nvm --version Print out the latest released version of nvm' nvm_echo ' nvm install [-s] Download and install a , [-s] from source. Uses .nvmrc if available' nvm_echo ' --reinstall-packages-from= When installing, reinstall packages installed in ' + nvm_echo ' --lts When installing, only select from LTS (long-term support) versions' + nvm_echo ' --lts= When installing, only select from versions for a specific LTS line' nvm_echo ' nvm uninstall Uninstall a version' nvm_echo ' nvm use [--silent] Modify PATH to use . Uses .nvmrc if available' nvm_echo ' nvm exec [--silent] [] Run on . Uses .nvmrc if available' @@ -1879,17 +1881,13 @@ nvm() { if [ $# -lt 2 ]; then version_not_provided=1 - nvm_rc_version - if [ -z "$NVM_RC_VERSION" ]; then - >&2 nvm --help - return 127 - fi fi shift local nobinary nobinary=0 + local LTS while [ $# -ne 0 ] do case "$1" in @@ -1902,9 +1900,13 @@ nvm() { nvm_get_make_jobs "$1" shift # consume job count ;; - --lts*) - nvm_err 'installing based on LTS filtering is not yet supported.' - return 12 + --lts) + LTS='*' + shift + ;; + --lts=*) + LTS="${1##--lts=}" + shift ;; *) break # stop parsing args @@ -1913,21 +1915,48 @@ nvm() { done local provided_version - provided_version="$1" + provided_version="${1-}" if [ -z "$provided_version" ]; then - if [ $version_not_provided -ne 1 ]; then + if [ "_${LTS-}" = '_*' ]; then + nvm_echo 'Installing latest LTS version.' + if [ $# -gt 0 ]; then + shift + fi + elif [ "_${LTS-}" != '_' ]; then + nvm_echo "Installing with latest version of LTS line: $LTS" + if [ $# -gt 0 ]; then + shift + fi + else nvm_rc_version + if [ $version_not_provided -eq 1 ]; then + if [ -z "$NVM_RC_VERSION" ]; then + >&2 nvm --help + return 127 + fi + fi + provided_version="$NVM_RC_VERSION" fi - provided_version="$NVM_RC_VERSION" - else + elif [ $# -gt 0 ]; then shift fi - VERSION="$(NVM_VERSION_ONLY=true nvm_remote_version "$provided_version")" + VERSION="$(NVM_VERSION_ONLY=true NVM_LTS="${LTS-}" nvm_remote_version "$provided_version")" if [ "_$VERSION" = "_N/A" ]; then - nvm_err "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." + local LTS_MSG + local REMOTE_CMD + if [ "${LTS-}" = '*' ]; then + LTS_MSG='(with LTS filter) ' + REMOTE_CMD='nvm ls-remote --lts' + elif [ -n "${LTS-}" ]; then + LTS_MSG="(with LTS filter '$LTS') " + REMOTE_CMD="nvm ls-remote --lts=${LTS}" + else + REMOTE_CMD='nvm ls-remote' + fi + nvm_err "Version '$provided_version' ${LTS_MSG-}not found - try \`${REMOTE_CMD}\` to browse available versions." return 3 fi @@ -1974,7 +2003,11 @@ nvm() { if nvm use "$VERSION" && [ ! -z "$REINSTALL_PACKAGES_FROM" ] && [ "_$REINSTALL_PACKAGES_FROM" != "_N/A" ]; then nvm reinstall-packages "$REINSTALL_PACKAGES_FROM" fi - nvm_ensure_default_set "$provided_version" + if [ -n "${LTS-}" ]; then + nvm_ensure_default_set "lts/${LTS}" + else + nvm_ensure_default_set "$provided_version" + fi return $? fi From 17c9bef4aaed746c2acd5b2f14aee2367b575c10 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 26 Apr 2016 23:07:22 -0700 Subject: [PATCH 11/28] `nvm alias`: add `lts/` support. --- nvm.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index f2918e090a..d8d248e2d5 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2558,7 +2558,7 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')" "alias" ) local NVM_ALIAS_DIR NVM_ALIAS_DIR="$(nvm_alias_path)" - command mkdir -p "$NVM_ALIAS_DIR" + command mkdir -p "$NVM_ALIAS_DIR/lts" local NVM_CURRENT NVM_CURRENT="$(nvm_ls_current)" if [ $# -le 2 ]; then @@ -2573,6 +2573,14 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')" NVM_CURRENT="${NVM_CURRENT}" nvm_print_default_alias "$ALIAS" fi done + + local LTS_ALIAS + for ALIAS_PATH in "$NVM_ALIAS_DIR/lts/${2-}"*; do + LTS_ALIAS="$(nvm_print_alias_path "$NVM_ALIAS_DIR" "$ALIAS_PATH")" + if [ -n "$LTS_ALIAS" ]; then + nvm_echo "${LTS_ALIAS-}" + fi + done return fi if [ -z "${3-}" ]; then From c83664960e058ae984617667a56325e1230ec089 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 27 Apr 2016 15:20:22 -0700 Subject: [PATCH 12/28] Automatically create LTS aliases every time we talk to nodejs.org/dist --- nvm.sh | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index d8d248e2d5..541e4e3b5c 100644 --- a/nvm.sh +++ b/nvm.sh @@ -912,11 +912,37 @@ nvm_ls_remote_index_tab() { ZSH_HAS_SHWORDSPLIT_UNSET="$(setopt | nvm_grep shwordsplit > /dev/null && nvm_echo $? || nvm_echo $?)" setopt shwordsplit fi - VERSIONS="$(nvm_download -L -s "$MIRROR/index.tab" -o - \ + local VERSION_LIST + VERSION_LIST="$(nvm_download -L -s "$MIRROR/index.tab" -o - \ | command sed " 1d; s/^/$PREFIX/; " \ + )" + local LTS_ALIAS + local LTS_VERSION + nvm_echo "$VERSION_LIST" \ + | awk '{ + if ($10 ~ /^\-?$/) { next } + if ($10 && !a[tolower($10)]++) { + if (alias) { print alias, version } + alias = "lts/" tolower($10) + version = $1 + } + } + END { + if (alias) { + print alias, version + print "lts/*", alias + } + }' \ + | while read -r LTS_ALIAS_LINE; do + LTS_ALIAS="${LTS_ALIAS_LINE%% *}" + LTS_VERSION="${LTS_ALIAS_LINE#* }" + nvm_make_alias "$LTS_ALIAS" "$LTS_VERSION" >/dev/null 2>&1 + done + + VERSIONS="$(nvm_echo "$VERSION_LIST" \ | command awk -v pattern="${PATTERN-}" -v lts="${LTS-}" '{ if (!$1) { next } if (pattern && tolower($1) !~ tolower(pattern)) { next } From bf683272ea5f4075be1030f460761ac51b653586 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 30 Apr 2016 12:50:59 -0700 Subject: [PATCH 13/28] `nvm alias`: colorize LTS aliases. --- nvm.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nvm.sh b/nvm.sh index 541e4e3b5c..adf79ecf07 100644 --- a/nvm.sh +++ b/nvm.sh @@ -491,11 +491,17 @@ nvm_print_formatted_alias() { DEST_FORMAT='\033[1;31m%s\033[0m' VERSION_FORMAT='\033[1;31m%s\033[0m' fi + if [ "_${NVM_LTS-}" = '_true' ]; then + ALIAS_FORMAT='\033[1;33m%s\033[0m' + fi + if [ "_${DEST%/*}" = "_lts" ]; then + DEST_FORMAT='\033[1;33m%s\033[0m' + fi fi if [ "_$DEST" = "_$VERSION" ]; then - command printf "${ALIAS_FORMAT} ${ARROW} ${VERSION_FORMAT}${NEWLINE}" "$ALIAS" "$DEST" + command printf -- "${ALIAS_FORMAT} ${ARROW} ${VERSION_FORMAT}${NEWLINE}" "$ALIAS" "$DEST" else - command printf "${ALIAS_FORMAT} ${ARROW} ${DEST_FORMAT} (${ARROW} ${VERSION_FORMAT})${NEWLINE}" "$ALIAS" "$DEST" "$VERSION" + command printf -- "${ALIAS_FORMAT} ${ARROW} ${DEST_FORMAT} (${ARROW} ${VERSION_FORMAT})${NEWLINE}" "$ALIAS" "$DEST" "$VERSION" fi } @@ -517,7 +523,7 @@ nvm_print_alias_path() { local DEST DEST="$(nvm_alias "$ALIAS" 2> /dev/null || return 0)" if [ -n "$DEST" ]; then - DEFAULT=false nvm_print_formatted_alias "$ALIAS" "$DEST" + NVM_LTS="${NVM_LTS-}" DEFAULT=false nvm_print_formatted_alias "$ALIAS" "$DEST" fi } @@ -2602,7 +2608,7 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')" local LTS_ALIAS for ALIAS_PATH in "$NVM_ALIAS_DIR/lts/${2-}"*; do - LTS_ALIAS="$(nvm_print_alias_path "$NVM_ALIAS_DIR" "$ALIAS_PATH")" + LTS_ALIAS="$(NVM_LTS=true nvm_print_alias_path "$NVM_ALIAS_DIR" "$ALIAS_PATH")" if [ -n "$LTS_ALIAS" ]; then nvm_echo "${LTS_ALIAS-}" fi From d1e51f361c0b1d9b74d002ef552e6973f1831dbf Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 1 May 2016 23:41:39 -0700 Subject: [PATCH 14/28] `nvm use`: Add `--lts`/`--lts=argon` support --- nvm.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/nvm.sh b/nvm.sh index adf79ecf07..de6ae28348 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1841,6 +1841,8 @@ nvm() { nvm_echo ' --lts= When installing, only select from versions for a specific LTS line' nvm_echo ' nvm uninstall Uninstall a version' nvm_echo ' nvm use [--silent] Modify PATH to use . Uses .nvmrc if available' + nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.' + nvm_echo ' --lts= Uses automatic alias for provided LTS line, if available.' nvm_echo ' nvm exec [--silent] [] Run on . Uses .nvmrc if available' nvm_echo ' nvm run [--silent] [] Run `node` on with as arguments. Uses .nvmrc if available' nvm_echo ' nvm current Display currently activated version' @@ -2202,6 +2204,7 @@ nvm() { NVM_USE_SILENT=0 local NVM_DELETE_PREFIX NVM_DELETE_PREFIX=0 + local NVM_LTS shift # remove "use" while [ $# -ne 0 ] @@ -2209,8 +2212,11 @@ nvm() { case "$1" in --silent) NVM_USE_SILENT=1 ;; --delete-prefix) NVM_DELETE_PREFIX=1 ;; + --lts) NVM_LTS='*' ;; + --lts=*) NVM_LTS="${1##--lts=}" ;; + --*) ;; *) - if [ -n "$1" ]; then + if [ -n "${1-}" ]; then PROVIDED_VERSION="$1" fi ;; @@ -2218,7 +2224,9 @@ nvm() { shift done - if [ -z "$PROVIDED_VERSION" ]; then + if [ -n "${NVM_LTS-}" ]; then + VERSION="$(nvm_match_version "lts/${NVM_LTS:-*}")" + elif [ -z "$PROVIDED_VERSION" ]; then nvm_rc_version if [ -n "$NVM_RC_VERSION" ]; then PROVIDED_VERSION="$NVM_RC_VERSION" @@ -2259,7 +2267,7 @@ nvm() { # This nvm_ensure_version_installed call can be a performance bottleneck # on shell startup. Perhaps we can optimize it away or make it faster. - nvm_ensure_version_installed "$PROVIDED_VERSION" + nvm_ensure_version_installed "${VERSION}" EXIT_CODE=$? if [ "$EXIT_CODE" != "0" ]; then return $EXIT_CODE From 45627d0a40a0974c4eab5cf9372b33160789ee8a Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 3 May 2016 23:18:44 -0700 Subject: [PATCH 15/28] `nvm exec`: add `--lts`/`--lts=argon` support. --- nvm.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/nvm.sh b/nvm.sh index de6ae28348..2140dcc78b 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1844,6 +1844,8 @@ nvm() { nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.' nvm_echo ' --lts= Uses automatic alias for provided LTS line, if available.' nvm_echo ' nvm exec [--silent] [] Run on . Uses .nvmrc if available' + nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.' + nvm_echo ' --lts= Uses automatic alias for provided LTS line, if available.' nvm_echo ' nvm run [--silent] [] Run `node` on with as arguments. Uses .nvmrc if available' nvm_echo ' nvm current Display currently activated version' nvm_echo ' nvm ls List installed versions' @@ -2409,10 +2411,13 @@ nvm() { shift local NVM_SILENT + local NVM_LTS while [ $# -gt 0 ] do case "$1" in --silent) NVM_SILENT='--silent' ; shift ;; + --lts) NVM_LTS='*' ; shift ;; + --lts=*) NVM_LTS="${1##--lts=}" ; shift ;; --) break ;; --*) nvm_err "Unsupported option \"$1\"." @@ -2430,9 +2435,12 @@ nvm() { local provided_version provided_version="$1" - if [ -n "$provided_version" ]; then + if [ "${NVM_LTS-}" != '' ]; then + provided_version="lts/${NVM_LTS:-*}" + VERSION="$provided_version" + elif [ -n "$provided_version" ]; then VERSION="$(nvm_version "$provided_version" || return 0)" - if [ "_$VERSION" = "_N/A" ] && ! nvm_is_valid_version "$provided_version"; then + if [ "_$VERSION" = '_N/A' ] && ! nvm_is_valid_version "$provided_version"; then if [ -n "${NVM_SILENT-}" ]; then nvm_rc_version >/dev/null 2>&1 else @@ -2452,7 +2460,11 @@ nvm() { fi if [ -z "${NVM_SILENT-}" ]; then - if nvm_is_iojs_version "$VERSION"; then + if [ "${NVM_LTS-}" = '*' ]; then + nvm_echo "Running node latest LTS -> $(nvm_version "$VERSION")$(nvm use --silent "$VERSION" && nvm_print_npm_version)" + elif [ -n "${NVM_LTS-}" ]; then + nvm_echo "Running node LTS \"${NVM_LTS-}\" -> $(nvm_version "$VERSION")$(nvm use --silent "$VERSION" && nvm_print_npm_version)" + elif nvm_is_iojs_version "$VERSION"; then nvm_echo "Running io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm use --silent "$VERSION" && nvm_print_npm_version)" else nvm_echo "Running node $VERSION$(nvm use --silent "$VERSION" && nvm_print_npm_version)" From 859be3f6a118858391dbab04dca7f60a1b1b2c70 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 4 May 2016 00:29:37 -0700 Subject: [PATCH 16/28] `nvm run`: add `--lts`/`--lts=argon` support --- nvm.sh | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/nvm.sh b/nvm.sh index 2140dcc78b..9b956c6588 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1847,6 +1847,8 @@ nvm() { nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.' nvm_echo ' --lts= Uses automatic alias for provided LTS line, if available.' nvm_echo ' nvm run [--silent] [] Run `node` on with as arguments. Uses .nvmrc if available' + nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.' + nvm_echo ' --lts= Uses automatic alias for provided LTS line, if available.' nvm_echo ' nvm current Display currently activated version' nvm_echo ' nvm ls List installed versions' nvm_echo ' nvm ls List versions matching a given ' @@ -2332,10 +2334,13 @@ nvm() { shift local NVM_SILENT + local NVM_LTS while [ $# -gt 0 ] do case "$1" in --silent) NVM_SILENT='--silent' ; shift ;; + --lts) NVM_LTS='*' ; shift ;; + --lts=*) NVM_LTS="${1##--lts=}" ; shift ;; *) if [ -n "$1" ]; then break @@ -2346,7 +2351,7 @@ nvm() { esac done - if [ $# -lt 1 ]; then + if [ $# -lt 1 ] && [ -z "${NVM_LTS-}" ]; then if [ -n "${NVM_SILENT-}" ]; then nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1 else @@ -2354,30 +2359,30 @@ nvm() { fi if [ -n "$NVM_RC_VERSION" ]; then VERSION="$(nvm_version "$NVM_RC_VERSION" || return 0)" - else - VERSION='N/A' fi - if [ $VERSION = "N/A" ]; then + if [ "${VERSION:-N/A}" = 'N/A' ]; then >&2 nvm --help return 127 fi fi - provided_version="$1" - if [ -n "$provided_version" ]; then - VERSION="$(nvm_version "$provided_version" || return 0)" - if [ "_$VERSION" = "_N/A" ] && ! nvm_is_valid_version "$provided_version"; then - provided_version='' - if [ $has_checked_nvmrc -ne 1 ]; then + if [ -z "${NVM_LTS-}" ]; then + provided_version="$1" + if [ -n "$provided_version" ]; then + VERSION="$(nvm_version "$provided_version" || return 0)" + if [ "_${VERSION:-N/A}" = '_N/A' ] && ! nvm_is_valid_version "$provided_version"; then + provided_version='' + if [ $has_checked_nvmrc -ne 1 ]; then if [ -n "${NVM_SILENT-}" ]; then - nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1 - else - nvm_rc_version && has_checked_nvmrc=1 + nvm_rc_version >/dev/null 2>&1 && has_checked_nvmrc=1 + else + nvm_rc_version && has_checked_nvmrc=1 + fi fi + VERSION="$(nvm_version "$NVM_RC_VERSION" || return 0)" + else + shift fi - VERSION="$(nvm_version "$NVM_RC_VERSION" || return 0)" - else - shift fi fi @@ -2394,12 +2399,17 @@ nvm() { ZSH_HAS_SHWORDSPLIT_UNSET="$(setopt | nvm_grep shwordsplit > /dev/null && nvm_echo $? || nvm_echo $?)" setopt shwordsplit fi + local LTS_ARG + if [ -n "${NVM_LTS-}" ]; then + LTS_ARG="--lts=${NVM_LTS-}" + VERSION='' + fi if [ "_$VERSION" = "_N/A" ]; then nvm_ensure_version_installed "$provided_version" elif [ "$NVM_IOJS" = true ]; then - nvm exec "${NVM_SILENT-}" "$VERSION" iojs "$@" + nvm exec "${NVM_SILENT-}" "${LTS_ARG-}" "$VERSION" iojs "$@" else - nvm exec "${NVM_SILENT-}" "$VERSION" node "$@" + nvm exec "${NVM_SILENT-}" "${LTS_ARG-}" "$VERSION" node "$@" fi EXIT_CODE="$?" if [ "$ZSH_HAS_SHWORDSPLIT_UNSET" -eq 1 ] && nvm_has "unsetopt"; then From c3b16603c0f91c276595b360172ab0c0cfe7f9cd Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 17 Jul 2016 20:18:05 -0700 Subject: [PATCH 17/28] `nvm uninstall`: add `--lts` support --- nvm.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/nvm.sh b/nvm.sh index 9b956c6588..7005a4411f 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1840,6 +1840,8 @@ nvm() { nvm_echo ' --lts When installing, only select from LTS (long-term support) versions' nvm_echo ' --lts= When installing, only select from versions for a specific LTS line' nvm_echo ' nvm uninstall Uninstall a version' + nvm_echo ' nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.' + nvm_echo ' nvm uninstall --lts= Uninstall using automatic alias for provided LTS line, if available.' nvm_echo ' nvm use [--silent] Modify PATH to use . Uses .nvmrc if available' nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.' nvm_echo ' --lts= Uses automatic alias for provided LTS line, if available.' @@ -2105,22 +2107,27 @@ nvm() { return $? ;; "uninstall" ) - if [ $# -ne 2 ]; then + shift # remove "uninstall" + + if [ $# -ne 1 ]; then >&2 nvm --help return 127 fi local PATTERN - PATTERN="$2" - case "_$PATTERN" in - "_$(nvm_iojs_prefix)" | "_$(nvm_iojs_prefix)-" \ - | "_$(nvm_node_prefix)" | "_$(nvm_node_prefix)-") - VERSION="$(nvm_version "$PATTERN")" + PATTERN="${1-}" + case "${PATTERN-}" in + --lts) + VERSION="$(nvm_match_version lts/*)" + ;; + --lts=*) + VERSION="$(nvm_match_version lts/${PATTERN##--lts=})" ;; *) - VERSION="$(nvm_version "$PATTERN")" + VERSION="$(nvm_version "${PATTERN}")" ;; esac + if [ "_$VERSION" = "_$(nvm_ls_current)" ]; then if nvm_is_iojs_version "$VERSION"; then nvm_err "nvm: Cannot uninstall currently-active io.js version, $VERSION (inferred from $PATTERN)." From bcb1f0b1c7ba6f45a8a15a96d24156cb6a98f016 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 17 Jul 2016 10:54:24 -0700 Subject: [PATCH 18/28] `nvm ls-remote`: skip io.js lookup when LTS is set. --- nvm.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/nvm.sh b/nvm.sh index 7005a4411f..cd0d630854 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2516,6 +2516,7 @@ nvm() { ;; --lts=*) LTS="${2##--lts=}" + NVM_FLAVOR="${NVM_NODE_PREFIX}" ;; --*) nvm_err "Unsupported option \"$2\"." From d2744014df3a5009d7c1cbd67276008543976d31 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 25 Jun 2016 17:00:19 -0700 Subject: [PATCH 19/28] [Tests] add some basic `nvm ls-remote` unit tests. --- .../Unit tests/mocks/nvm ls-remote iojs.txt | 41 +++ .../Unit tests/mocks/nvm ls-remote lts.txt | 18 + .../Unit tests/mocks/nvm ls-remote node.txt | 278 +++++++++++++++ test/fast/Unit tests/mocks/nvm ls-remote.txt | 319 ++++++++++++++++++ test/fast/Unit tests/nvm ls-remote | 32 ++ update_test_mocks.sh | 8 + 6 files changed, 696 insertions(+) create mode 100644 test/fast/Unit tests/mocks/nvm ls-remote iojs.txt create mode 100644 test/fast/Unit tests/mocks/nvm ls-remote lts.txt create mode 100644 test/fast/Unit tests/mocks/nvm ls-remote node.txt create mode 100644 test/fast/Unit tests/mocks/nvm ls-remote.txt create mode 100755 test/fast/Unit tests/nvm ls-remote diff --git a/test/fast/Unit tests/mocks/nvm ls-remote iojs.txt b/test/fast/Unit tests/mocks/nvm ls-remote iojs.txt new file mode 100644 index 0000000000..ff70b025a4 --- /dev/null +++ b/test/fast/Unit tests/mocks/nvm ls-remote iojs.txt @@ -0,0 +1,41 @@ + iojs-v1.0.0 + iojs-v1.0.1 + iojs-v1.0.2 + iojs-v1.0.3 + iojs-v1.0.4 + iojs-v1.1.0 + iojs-v1.2.0 + iojs-v1.3.0 + iojs-v1.4.1 + iojs-v1.4.2 + iojs-v1.4.3 + iojs-v1.5.0 + iojs-v1.5.1 + iojs-v1.6.0 + iojs-v1.6.1 + iojs-v1.6.2 + iojs-v1.6.3 + iojs-v1.6.4 + iojs-v1.7.1 + iojs-v1.8.1 + iojs-v1.8.2 + iojs-v1.8.3 + iojs-v1.8.4 + iojs-v2.0.0 + iojs-v2.0.1 + iojs-v2.0.2 + iojs-v2.1.0 + iojs-v2.2.0 + iojs-v2.2.1 + iojs-v2.3.0 + iojs-v2.3.1 + iojs-v2.3.2 + iojs-v2.3.3 + iojs-v2.3.4 + iojs-v2.4.0 + iojs-v2.5.0 + iojs-v3.0.0 + iojs-v3.1.0 + iojs-v3.2.0 + iojs-v3.3.0 + iojs-v3.3.1 diff --git a/test/fast/Unit tests/mocks/nvm ls-remote lts.txt b/test/fast/Unit tests/mocks/nvm ls-remote lts.txt new file mode 100644 index 0000000000..a6c5b91181 --- /dev/null +++ b/test/fast/Unit tests/mocks/nvm ls-remote lts.txt @@ -0,0 +1,18 @@ + v4.2.0  (LTS: Argon) + v4.2.1  (LTS: Argon) + v4.2.2  (LTS: Argon) + v4.2.3  (LTS: Argon) + v4.2.4  (LTS: Argon) + v4.2.5  (LTS: Argon) + v4.2.6  (LTS: Argon) + v4.3.0  (LTS: Argon) + v4.3.1  (LTS: Argon) + v4.3.2  (LTS: Argon) + v4.4.0  (LTS: Argon) + v4.4.1  (LTS: Argon) + v4.4.2  (LTS: Argon) + v4.4.3  (LTS: Argon) + v4.4.4  (LTS: Argon) + v4.4.5  (LTS: Argon) + v4.4.6  (LTS: Argon) + v4.4.7  (Latest LTS: Argon) diff --git a/test/fast/Unit tests/mocks/nvm ls-remote node.txt b/test/fast/Unit tests/mocks/nvm ls-remote node.txt new file mode 100644 index 0000000000..0b42afb25a --- /dev/null +++ b/test/fast/Unit tests/mocks/nvm ls-remote node.txt @@ -0,0 +1,278 @@ + v0.1.14 + v0.1.15 + v0.1.16 + v0.1.17 + v0.1.18 + v0.1.19 + v0.1.20 + v0.1.21 + v0.1.22 + v0.1.23 + v0.1.24 + v0.1.25 + v0.1.26 + v0.1.27 + v0.1.28 + v0.1.29 + v0.1.30 + v0.1.31 + v0.1.32 + v0.1.33 + v0.1.90 + v0.1.91 + v0.1.92 + v0.1.93 + v0.1.94 + v0.1.95 + v0.1.96 + v0.1.97 + v0.1.98 + v0.1.99 + v0.1.100 + v0.1.101 + v0.1.102 + v0.1.103 + v0.1.104 + v0.2.0 + v0.2.1 + v0.2.2 + v0.2.3 + v0.2.4 + v0.2.5 + v0.2.6 + v0.3.0 + v0.3.1 + v0.3.2 + v0.3.3 + v0.3.4 + v0.3.5 + v0.3.6 + v0.3.7 + v0.3.8 + v0.4.0 + v0.4.1 + v0.4.2 + v0.4.3 + v0.4.4 + v0.4.5 + v0.4.6 + v0.4.7 + v0.4.8 + v0.4.9 + v0.4.10 + v0.4.11 + v0.4.12 + v0.5.0 + v0.5.1 + v0.5.2 + v0.5.3 + v0.5.4 + v0.5.5 + v0.5.6 + v0.5.7 + v0.5.8 + v0.5.9 + v0.5.10 + v0.6.0 + v0.6.1 + v0.6.2 + v0.6.3 + v0.6.4 + v0.6.5 + v0.6.6 + v0.6.7 + v0.6.8 + v0.6.9 + v0.6.10 + v0.6.11 + v0.6.12 + v0.6.13 + v0.6.14 + v0.6.15 + v0.6.16 + v0.6.17 + v0.6.18 + v0.6.19 + v0.6.20 + v0.6.21 + v0.7.0 + v0.7.1 + v0.7.2 + v0.7.3 + v0.7.4 + v0.7.5 + v0.7.6 + v0.7.7 + v0.7.8 + v0.7.9 + v0.7.10 + v0.7.11 + v0.7.12 + v0.8.0 + v0.8.1 + v0.8.2 + v0.8.3 + v0.8.4 + v0.8.5 + v0.8.6 + v0.8.7 + v0.8.8 + v0.8.9 + v0.8.10 + v0.8.11 + v0.8.12 + v0.8.13 + v0.8.14 + v0.8.15 + v0.8.16 + v0.8.17 + v0.8.18 + v0.8.19 + v0.8.20 + v0.8.21 + v0.8.22 + v0.8.23 + v0.8.24 + v0.8.25 + v0.8.26 + v0.8.27 + v0.8.28 + v0.9.0 + v0.9.1 + v0.9.2 + v0.9.3 + v0.9.4 + v0.9.5 + v0.9.6 + v0.9.7 + v0.9.8 + v0.9.9 + v0.9.10 + v0.9.11 + v0.9.12 + v0.10.0 + v0.10.1 + v0.10.2 + v0.10.3 + v0.10.4 + v0.10.5 + v0.10.6 + v0.10.7 + v0.10.8 + v0.10.9 + v0.10.10 + v0.10.11 + v0.10.12 + v0.10.13 + v0.10.14 + v0.10.15 + v0.10.16 + v0.10.17 + v0.10.18 + v0.10.19 + v0.10.20 + v0.10.21 + v0.10.22 + v0.10.23 + v0.10.24 + v0.10.25 + v0.10.26 + v0.10.27 + v0.10.28 + v0.10.29 + v0.10.30 + v0.10.31 + v0.10.32 + v0.10.33 + v0.10.34 + v0.10.35 + v0.10.36 + v0.10.37 + v0.10.38 + v0.10.39 + v0.10.40 + v0.10.41 + v0.10.42 + v0.10.43 + v0.10.44 + v0.10.45 + v0.10.46 + v0.11.0 + v0.11.1 + v0.11.2 + v0.11.3 + v0.11.4 + v0.11.5 + v0.11.6 + v0.11.7 + v0.11.8 + v0.11.9 + v0.11.10 + v0.11.11 + v0.11.12 + v0.11.13 + v0.11.14 + v0.11.15 + v0.11.16 + v0.12.0 + v0.12.1 + v0.12.2 + v0.12.3 + v0.12.4 + v0.12.5 + v0.12.6 + v0.12.7 + v0.12.8 + v0.12.9 + v0.12.10 + v0.12.11 + v0.12.12 + v0.12.13 + v0.12.14 + v0.12.15 + v4.0.0 + v4.1.0 + v4.1.1 + v4.1.2 + v4.2.0  (LTS: Argon) + v4.2.1  (LTS: Argon) + v4.2.2  (LTS: Argon) + v4.2.3  (LTS: Argon) + v4.2.4  (LTS: Argon) + v4.2.5  (LTS: Argon) + v4.2.6  (LTS: Argon) + v4.3.0  (LTS: Argon) + v4.3.1  (LTS: Argon) + v4.3.2  (LTS: Argon) + v4.4.0  (LTS: Argon) + v4.4.1  (LTS: Argon) + v4.4.2  (LTS: Argon) + v4.4.3  (LTS: Argon) + v4.4.4  (LTS: Argon) + v4.4.5  (LTS: Argon) + v4.4.6  (LTS: Argon) + v4.4.7  (Latest LTS: Argon) + v5.0.0 + v5.1.0 + v5.1.1 + v5.2.0 + v5.3.0 + v5.4.0 + v5.4.1 + v5.5.0 + v5.6.0 + v5.7.0 + v5.7.1 + v5.8.0 + v5.9.0 + v5.9.1 + v5.10.0 + v5.10.1 + v5.11.0 + v5.11.1 + v5.12.0 + v6.0.0 + v6.1.0 + v6.2.0 + v6.2.1 + v6.2.2 diff --git a/test/fast/Unit tests/mocks/nvm ls-remote.txt b/test/fast/Unit tests/mocks/nvm ls-remote.txt new file mode 100644 index 0000000000..419d69149d --- /dev/null +++ b/test/fast/Unit tests/mocks/nvm ls-remote.txt @@ -0,0 +1,319 @@ + v0.1.14 + v0.1.15 + v0.1.16 + v0.1.17 + v0.1.18 + v0.1.19 + v0.1.20 + v0.1.21 + v0.1.22 + v0.1.23 + v0.1.24 + v0.1.25 + v0.1.26 + v0.1.27 + v0.1.28 + v0.1.29 + v0.1.30 + v0.1.31 + v0.1.32 + v0.1.33 + v0.1.90 + v0.1.91 + v0.1.92 + v0.1.93 + v0.1.94 + v0.1.95 + v0.1.96 + v0.1.97 + v0.1.98 + v0.1.99 + v0.1.100 + v0.1.101 + v0.1.102 + v0.1.103 + v0.1.104 + v0.2.0 + v0.2.1 + v0.2.2 + v0.2.3 + v0.2.4 + v0.2.5 + v0.2.6 + v0.3.0 + v0.3.1 + v0.3.2 + v0.3.3 + v0.3.4 + v0.3.5 + v0.3.6 + v0.3.7 + v0.3.8 + v0.4.0 + v0.4.1 + v0.4.2 + v0.4.3 + v0.4.4 + v0.4.5 + v0.4.6 + v0.4.7 + v0.4.8 + v0.4.9 + v0.4.10 + v0.4.11 + v0.4.12 + v0.5.0 + v0.5.1 + v0.5.2 + v0.5.3 + v0.5.4 + v0.5.5 + v0.5.6 + v0.5.7 + v0.5.8 + v0.5.9 + v0.5.10 + v0.6.0 + v0.6.1 + v0.6.2 + v0.6.3 + v0.6.4 + v0.6.5 + v0.6.6 + v0.6.7 + v0.6.8 + v0.6.9 + v0.6.10 + v0.6.11 + v0.6.12 + v0.6.13 + v0.6.14 + v0.6.15 + v0.6.16 + v0.6.17 + v0.6.18 + v0.6.19 + v0.6.20 + v0.6.21 + v0.7.0 + v0.7.1 + v0.7.2 + v0.7.3 + v0.7.4 + v0.7.5 + v0.7.6 + v0.7.7 + v0.7.8 + v0.7.9 + v0.7.10 + v0.7.11 + v0.7.12 + v0.8.0 + v0.8.1 + v0.8.2 + v0.8.3 + v0.8.4 + v0.8.5 + v0.8.6 + v0.8.7 + v0.8.8 + v0.8.9 + v0.8.10 + v0.8.11 + v0.8.12 + v0.8.13 + v0.8.14 + v0.8.15 + v0.8.16 + v0.8.17 + v0.8.18 + v0.8.19 + v0.8.20 + v0.8.21 + v0.8.22 + v0.8.23 + v0.8.24 + v0.8.25 + v0.8.26 + v0.8.27 + v0.8.28 + v0.9.0 + v0.9.1 + v0.9.2 + v0.9.3 + v0.9.4 + v0.9.5 + v0.9.6 + v0.9.7 + v0.9.8 + v0.9.9 + v0.9.10 + v0.9.11 + v0.9.12 + v0.10.0 + v0.10.1 + v0.10.2 + v0.10.3 + v0.10.4 + v0.10.5 + v0.10.6 + v0.10.7 + v0.10.8 + v0.10.9 + v0.10.10 + v0.10.11 + v0.10.12 + v0.10.13 + v0.10.14 + v0.10.15 + v0.10.16 + v0.10.17 + v0.10.18 + v0.10.19 + v0.10.20 + v0.10.21 + v0.10.22 + v0.10.23 + v0.10.24 + v0.10.25 + v0.10.26 + v0.10.27 + v0.10.28 + v0.10.29 + v0.10.30 + v0.10.31 + v0.10.32 + v0.10.33 + v0.10.34 + v0.10.35 + v0.10.36 + v0.10.37 + v0.10.38 + v0.10.39 + v0.10.40 + v0.10.41 + v0.10.42 + v0.10.43 + v0.10.44 + v0.10.45 + v0.10.46 + v0.11.0 + v0.11.1 + v0.11.2 + v0.11.3 + v0.11.4 + v0.11.5 + v0.11.6 + v0.11.7 + v0.11.8 + v0.11.9 + v0.11.10 + v0.11.11 + v0.11.12 + v0.11.13 + v0.11.14 + v0.11.15 + v0.11.16 + v0.12.0 + v0.12.1 + v0.12.2 + v0.12.3 + v0.12.4 + v0.12.5 + v0.12.6 + v0.12.7 + v0.12.8 + v0.12.9 + v0.12.10 + v0.12.11 + v0.12.12 + v0.12.13 + v0.12.14 + v0.12.15 + iojs-v1.0.0 + iojs-v1.0.1 + iojs-v1.0.2 + iojs-v1.0.3 + iojs-v1.0.4 + iojs-v1.1.0 + iojs-v1.2.0 + iojs-v1.3.0 + iojs-v1.4.1 + iojs-v1.4.2 + iojs-v1.4.3 + iojs-v1.5.0 + iojs-v1.5.1 + iojs-v1.6.0 + iojs-v1.6.1 + iojs-v1.6.2 + iojs-v1.6.3 + iojs-v1.6.4 + iojs-v1.7.1 + iojs-v1.8.1 + iojs-v1.8.2 + iojs-v1.8.3 + iojs-v1.8.4 + iojs-v2.0.0 + iojs-v2.0.1 + iojs-v2.0.2 + iojs-v2.1.0 + iojs-v2.2.0 + iojs-v2.2.1 + iojs-v2.3.0 + iojs-v2.3.1 + iojs-v2.3.2 + iojs-v2.3.3 + iojs-v2.3.4 + iojs-v2.4.0 + iojs-v2.5.0 + iojs-v3.0.0 + iojs-v3.1.0 + iojs-v3.2.0 + iojs-v3.3.0 + iojs-v3.3.1 + v4.0.0 + v4.1.0 + v4.1.1 + v4.1.2 + v4.2.0  (LTS: Argon) + v4.2.1  (LTS: Argon) + v4.2.2  (LTS: Argon) + v4.2.3  (LTS: Argon) + v4.2.4  (LTS: Argon) + v4.2.5  (LTS: Argon) + v4.2.6  (LTS: Argon) + v4.3.0  (LTS: Argon) + v4.3.1  (LTS: Argon) + v4.3.2  (LTS: Argon) + v4.4.0  (LTS: Argon) + v4.4.1  (LTS: Argon) + v4.4.2  (LTS: Argon) + v4.4.3  (LTS: Argon) + v4.4.4  (LTS: Argon) + v4.4.5  (LTS: Argon) + v4.4.6  (LTS: Argon) + v4.4.7  (Latest LTS: Argon) + v5.0.0 + v5.1.0 + v5.1.1 + v5.2.0 + v5.3.0 + v5.4.0 + v5.4.1 + v5.5.0 + v5.6.0 + v5.7.0 + v5.7.1 + v5.8.0 + v5.9.0 + v5.9.1 + v5.10.0 + v5.10.1 + v5.11.0 + v5.11.1 + v5.12.0 + v6.0.0 + v6.1.0 + v6.2.0 + v6.2.1 + v6.2.2 diff --git a/test/fast/Unit tests/nvm ls-remote b/test/fast/Unit tests/nvm ls-remote new file mode 100755 index 0000000000..449d4af683 --- /dev/null +++ b/test/fast/Unit tests/nvm ls-remote @@ -0,0 +1,32 @@ +#!/bin/sh + +set -ex + +die () { echo $@ ; cleanup ; exit 1; } + +cleanup() { + unset -f nvm_download nvm_ls_remote nvm_ls_remote_iojs +} + +. ../../../nvm.sh + +nvm deactivate 2>/dev/null || die 'unable to deactivate' + +. ../../common.sh + +REMOTE="$PWD/mocks/nvm_ls_remote.txt" +nvm_ls_remote() { + cat "$REMOTE" +} +REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt" +nvm_ls_remote_iojs() { + cat "$REMOTE_IOJS" +} + +EXPECTED_OUTPUT_PATH="$PWD/mocks/nvm ls-remote.txt" + +OUTPUT="$(nvm ls-remote | sed 's/[ \t]*$//')" +EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH" | sed 's/[ \t]*$//' )" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "bare nvm ls-remote did not output expected sorted versions; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")" + +cleanup diff --git a/update_test_mocks.sh b/update_test_mocks.sh index 571b870d85..312a5343de 100755 --- a/update_test_mocks.sh +++ b/update_test_mocks.sh @@ -10,6 +10,10 @@ echo "creating $MOCKS_DIR" mkdir -p "$MOCKS_DIR" . "$NVM_DIR/nvm.sh" --no-use +nvm deactivate 2> /dev/null +nvm_is_version_installed() { + return 1 +} nvm_ls_remote > "$MOCKS_DIR/nvm_ls_remote.txt" nvm_ls_remote_iojs > "$MOCKS_DIR/nvm_ls_remote_iojs.txt" @@ -17,5 +21,9 @@ NVM_LTS=* nvm_ls_remote > "$MOCKS_DIR/nvm_ls_remote LTS.txt" NVM_LTS=argon nvm_ls_remote > "$MOCKS_DIR/nvm_ls_remote LTS argon.txt" nvm_download -L -s "$NVM_NODEJS_ORG_MIRROR/index.tab" -o - > "$MOCKS_DIR/nodejs.org-dist-index.tab" nvm_download -L -s "$NVM_IOJS_ORG_MIRROR/index.tab" -o - > "$MOCKS_DIR/iojs.org-dist-index.tab" +nvm ls-remote > "$MOCKS_DIR/nvm ls-remote.txt" +nvm ls-remote --lts > "$MOCKS_DIR/nvm ls-remote lts.txt" +nvm ls-remote node > "$MOCKS_DIR/nvm ls-remote node.txt" +nvm ls-remote iojs > "$MOCKS_DIR/nvm ls-remote iojs.txt" echo "done! Don't forget to git commit them." From e6606458f7e9c30b3650b25054cd59725b18e051 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 26 Jun 2016 13:01:12 -0700 Subject: [PATCH 20/28] [Tests] add `nvm version-remote` unit tests. --- test/fast/Unit tests/nvm version-remote | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 test/fast/Unit tests/nvm version-remote diff --git a/test/fast/Unit tests/nvm version-remote b/test/fast/Unit tests/nvm version-remote new file mode 100755 index 0000000000..1cb414b145 --- /dev/null +++ b/test/fast/Unit tests/nvm version-remote @@ -0,0 +1,43 @@ +#!/bin/sh + +set -ex + +die () { echo $@ ; cleanup ; exit 1; } + +cleanup() { + unset -f nvm_remote_version +} + +. ../../../nvm.sh + +. ../../common.sh + +nvm_remote_version() { + echo "NVM_VERSION_ONLY:${NVM_VERSION_ONLY-},NVM_LTS:${NVM_LTS-},PATTERN:${PATTERN-}" +} + +OUTPUT="$(nvm version-remote foo)" +EXPECTED_OUTPUT='NVM_VERSION_ONLY:true,NVM_LTS:,PATTERN:foo' +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm version-remote foo\` called nvm_remote_version with >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" + +OUTPUT="$(nvm version-remote --lts foo)" +EXPECTED_OUTPUT='NVM_VERSION_ONLY:true,NVM_LTS:*,PATTERN:foo' +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm version-remote --lts foo\` called nvm_remote_version with >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" + +OUTPUT="$(nvm version-remote foo --lts)" +EXPECTED_OUTPUT='NVM_VERSION_ONLY:true,NVM_LTS:*,PATTERN:foo' +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm version-remote foo --lts\` called nvm_remote_version with >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" + +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}<" + +set +ex # needed for stderr +OUTPUT="$(nvm version-remote --foo bar 2>&1)" +set -ex +EXPECTED_OUTPUT='Unsupported option "--foo".' +EXIT_CODE="$(nvm version-remote --foo bar >/dev/null 2>&1 && echo $? || echo $?)" +[ "${EXIT_CODE}" = 55 ] || die "\`nvm version-remote --foo bar\` did not exit with code 55, got >${EXIT_CODE}<" +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm version-remote --foo bar\` errored with >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" + +cleanup From 655830eb58e4329da63ae6ca7dd360fbfab3b9b7 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 26 Jun 2016 13:57:01 -0700 Subject: [PATCH 21/28] [Tests] `nvm install --lts`: add tests --- test/installation_node/install LTS | 31 +++++++++++++++++++++++++++++ test/installation_node/teardown_dir | 1 + 2 files changed, 32 insertions(+) create mode 100755 test/installation_node/install LTS diff --git a/test/installation_node/install LTS b/test/installation_node/install LTS new file mode 100755 index 0000000000..86aa33da72 --- /dev/null +++ b/test/installation_node/install LTS @@ -0,0 +1,31 @@ +#!/bin/sh + +set -ex + +die () { echo $@ ; exit 1; } + +. ../../nvm.sh + +nvm unalias default >/dev/null 2>&1 || die 'unable to unalias default' + +set +ex # needed for stderr +OUTPUT="$(nvm install --lts 3 2>&1)" +set -ex +EXIT_CODE="$(nvm install --lts 3 >/dev/null 2>&1 && echo $? || echo $?)" +EXPECTED_OUTPUT="Version '3' (with LTS filter) not found - try \`nvm ls-remote --lts\` to browse available versions." +[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts 3\` did not exit with 3, got >${EXIT_CODE}<" +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" + +set +ex # needed for stderr +OUTPUT="$(nvm install --lts=argon 3 2>&1)" +set -ex +EXIT_CODE="$(nvm install --lts=argon 3 >/dev/null 2>&1 && echo $? || echo $?)" +EXPECTED_OUTPUT="Version '3' (with LTS filter 'argon') not found - try \`nvm ls-remote --lts=argon\` to browse available versions." +[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts=argon 3\` did not exit with 3, got >${EXIT_CODE}<" +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts=argon 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" + +set +e # TODO: fix +nvm install --lts 4.2.2 || die 'nvm install --lts 4.2.2 failed' +set -e + +[ "$(nvm current)" = "v4.2.2" ] || die "v4.2.2 not current, got $(nvm_current)" diff --git a/test/installation_node/teardown_dir b/test/installation_node/teardown_dir index 941ca993e7..a37d0e65d5 100755 --- a/test/installation_node/teardown_dir +++ b/test/installation_node/teardown_dir @@ -3,6 +3,7 @@ . ../../nvm.sh nvm deactivate nvm uninstall v0.10.7 +nvm uninstall v4.2.2 if [ -f ".nvmrc" ]; then rm .nvmrc From f0668fd57714979c6bb7747a495e24c4428ec7ec Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 26 Jun 2016 15:11:37 -0700 Subject: [PATCH 22/28] [Tests] `nvm alias --lts`: add tests --- ...m alias\" should ensure LTS alias dir exists" | 16 ++++++++++++++++ test/fast/Aliases/lts/setup_dir | 10 ++++++++++ test/fast/Aliases/lts/teardown_dir | 10 ++++++++++ 3 files changed, 36 insertions(+) create mode 100755 "test/fast/Aliases/lts/\"nvm alias\" should ensure LTS alias dir exists" create mode 100755 test/fast/Aliases/lts/setup_dir create mode 100755 test/fast/Aliases/lts/teardown_dir diff --git "a/test/fast/Aliases/lts/\"nvm alias\" should ensure LTS alias dir exists" "b/test/fast/Aliases/lts/\"nvm alias\" should ensure LTS alias dir exists" new file mode 100755 index 0000000000..eefcf9804e --- /dev/null +++ "b/test/fast/Aliases/lts/\"nvm alias\" should ensure LTS alias dir exists" @@ -0,0 +1,16 @@ +#!/bin/sh + +set -ex + +. ../../../../nvm.sh +. ../../../common.sh + +LTS_ALIAS_PATH="$(nvm_alias_path)/lts" + +die () { echo $@ ; exit 1; } + +[ ! -d "${LTS_ALIAS_PATH}" ] || die "'${LTS_ALIAS_PATH}' exists and should not" + +nvm alias >/dev/null 2>&1 + +[ -d "${LTS_ALIAS_PATH}" ] || die "'${LTS_ALIAS_PATH}' does not exist and should" diff --git a/test/fast/Aliases/lts/setup_dir b/test/fast/Aliases/lts/setup_dir new file mode 100755 index 0000000000..6a99acfd5c --- /dev/null +++ b/test/fast/Aliases/lts/setup_dir @@ -0,0 +1,10 @@ +#!/bin/sh + +. ../../../../nvm.sh + +LTS_ALIAS_PATH="$(nvm_alias_path)/lts" + +if [ -d "${LTS_ALIAS_PATH}" ]; then + mv "${LTS_ALIAS_PATH}" "${LTS_ALIAS_PATH}.bak" + rm -rf "${LTS_ALIAS_PATH}" +fi diff --git a/test/fast/Aliases/lts/teardown_dir b/test/fast/Aliases/lts/teardown_dir new file mode 100755 index 0000000000..a5200efda5 --- /dev/null +++ b/test/fast/Aliases/lts/teardown_dir @@ -0,0 +1,10 @@ +#!/bin/sh + +. ../../../../nvm.sh + +LTS_ALIAS_PATH="$(nvm_alias_path)/lts" + +if [ -d "${LTS_ALIAS_PATH}.bak" ]; then + rm -rf "${LTS_ALIAS_PATH}" + mv "${LTS_ALIAS_PATH}.bak" "${LTS_ALIAS_PATH}" +fi From 4c010f442e6d30594dfbb7eeb5ad0d596a4cabbf Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sat, 2 Jul 2016 21:21:16 -0700 Subject: [PATCH 23/28] [Tests] add tests for auto-creation of LTS aliases on `nvm_ls_remote` --- .gitignore | 1 + .../mocks/nvm_make_alias LTS alias calls.txt | 2 + .../fast/Unit tests/nvm_ls_remote LTS aliases | 50 +++++++++++++++++++ update_test_mocks.sh | 13 +++++ 4 files changed, 66 insertions(+) create mode 100644 test/fast/Unit tests/mocks/nvm_make_alias LTS alias calls.txt create mode 100755 test/fast/Unit tests/nvm_ls_remote LTS aliases diff --git a/.gitignore b/.gitignore index 852b57213d..b44ec8f649 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ alias test/bak .urchin.log .urchin_stdout +test/**/test_output node_modules/ npm-debug.log diff --git a/test/fast/Unit tests/mocks/nvm_make_alias LTS alias calls.txt b/test/fast/Unit tests/mocks/nvm_make_alias LTS alias calls.txt new file mode 100644 index 0000000000..cb38eece11 --- /dev/null +++ b/test/fast/Unit tests/mocks/nvm_make_alias LTS alias calls.txt @@ -0,0 +1,2 @@ +lts/argon|v4.4.7 +lts/*|lts/argon diff --git a/test/fast/Unit tests/nvm_ls_remote LTS aliases b/test/fast/Unit tests/nvm_ls_remote LTS aliases new file mode 100755 index 0000000000..1fdde96014 --- /dev/null +++ b/test/fast/Unit tests/nvm_ls_remote LTS aliases @@ -0,0 +1,50 @@ +#!/bin/sh + +set -ex + +die () { echo $@ ; cleanup ; exit 1; } + +TEST_PATH="$PWD/test_output" +mkdir -p "$TEST_PATH" +CALL_COUNT_PATH="$TEST_PATH/call_count.txt" +: > "$CALL_COUNT_PATH" +ALIAS_ARGS_PATH="$TEST_PATH/nvm_make_alias_args.txt" +: > "$ALIAS_ARGS_PATH" + +cleanup() { + unset -f nvm_download nvm_make_alias + rm -rf "$TEST_PATH" +} + +. ../../../nvm.sh + +set -ex + +MOCKS_DIR="$PWD/mocks" + +# sample output at the time the test was written +TAB_PATH="$MOCKS_DIR/nodejs.org-dist-index.tab" +nvm_download() { + cat "$TAB_PATH" +} + +nvm_make_alias() { + CALL_COUNT="$(cat "$CALL_COUNT_PATH")" + CALL_COUNT="$((CALL_COUNT + 1))" + echo "$CALL_COUNT" > "$CALL_COUNT_PATH" + echo "${1}|${2}" >> "$ALIAS_ARGS_PATH" +} + +nvm_ls_remote >/dev/null || die "nvm_ls_remote_failed?!" + +CALL_COUNT="$(cat "$CALL_COUNT_PATH")" + +EXPECTED_COUNT=2 +[ "$CALL_COUNT" = "$EXPECTED_COUNT" ] || die "nvm_make_alias called $CALL_COUNT times; expected $EXPECTED_COUNT" + +ARGS="$(cat "$ALIAS_ARGS_PATH")" +EXPECTED_ARGS_PATH="$MOCKS_DIR/nvm_make_alias LTS alias calls.txt" +EXPECTED_ARGS="$(cat "$EXPECTED_ARGS_PATH")" +[ "${ARGS}" = "${EXPECTED_ARGS}" ] || die "nvm_make_alias called with >${ARGS}<; expected >${EXPECTED_ARGS}<" + +cleanup diff --git a/update_test_mocks.sh b/update_test_mocks.sh index 312a5343de..dfa87ac1b0 100755 --- a/update_test_mocks.sh +++ b/update_test_mocks.sh @@ -15,6 +15,11 @@ nvm_is_version_installed() { return 1 } +nvm_make_alias() { + # prevent local alias creation + return 0 +} + nvm_ls_remote > "$MOCKS_DIR/nvm_ls_remote.txt" nvm_ls_remote_iojs > "$MOCKS_DIR/nvm_ls_remote_iojs.txt" NVM_LTS=* nvm_ls_remote > "$MOCKS_DIR/nvm_ls_remote LTS.txt" @@ -26,4 +31,12 @@ nvm ls-remote --lts > "$MOCKS_DIR/nvm ls-remote lts.txt" nvm ls-remote node > "$MOCKS_DIR/nvm ls-remote node.txt" nvm ls-remote iojs > "$MOCKS_DIR/nvm ls-remote iojs.txt" +ALIAS_PATH="$MOCKS_DIR/nvm_make_alias LTS alias calls.txt" +: > "$ALIAS_PATH" +nvm_make_alias() { + # prevent local alias creation, and store arguments + echo "${1}|${2}" >> "$ALIAS_PATH" +} +nvm ls-remote --lts + echo "done! Don't forget to git commit them." From 42fedf6bc9b22917325ebff7d57c89d6fa8b1754 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 3 Jul 2016 08:37:03 -0700 Subject: [PATCH 24/28] [Tests] add some basic `nvm use --lts` tests --- nvm.sh | 2 +- ...\"nvm use --lts\" uses latest LTS version" | 22 +++++++++++++++++++ ...lts=foo\" uses latest \"foo\" LTS version" | 22 +++++++++++++++++++ test/slow/nvm use/setup_dir | 7 ++++++ test/slow/nvm use/teardown_dir | 12 +++++++--- 5 files changed, 61 insertions(+), 4 deletions(-) create mode 100755 "test/slow/nvm use/Running \"nvm use --lts\" uses latest LTS version" create mode 100755 "test/slow/nvm use/Running \"nvm use --lts=foo\" uses latest \"foo\" LTS version" diff --git a/nvm.sh b/nvm.sh index cd0d630854..1f5f9be55d 100644 --- a/nvm.sh +++ b/nvm.sh @@ -610,7 +610,7 @@ nvm_resolve_alias() { local SEEN_ALIASES SEEN_ALIASES="$ALIAS" while true; do - ALIAS_TEMP="$(nvm_alias "$ALIAS" 2> /dev/null)" + ALIAS_TEMP="$(nvm_alias "$ALIAS" 2> /dev/null || echo)" if [ -z "$ALIAS_TEMP" ]; then break diff --git "a/test/slow/nvm use/Running \"nvm use --lts\" uses latest LTS version" "b/test/slow/nvm use/Running \"nvm use --lts\" uses latest LTS version" new file mode 100755 index 0000000000..fc82a7b6ca --- /dev/null +++ "b/test/slow/nvm use/Running \"nvm use --lts\" uses latest LTS version" @@ -0,0 +1,22 @@ +#!/bin/sh + +set -ex + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +nvm deactivate >/dev/null 2>&1 || die 'deactivate failed' + +nvm use --lts || die 'nvm use --lts failed' +OUTPUT="$(nvm current)" +EXPECTED_OUTPUT="$(nvm_resolve_alias 'lts/*')" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ + || die "'nvm use --lts' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'" + +OUTPUT="$(nvm use --silent --lts)" +EXPECTED_OUTPUT="" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ + || die "'nvm use --silent --lts' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'" diff --git "a/test/slow/nvm use/Running \"nvm use --lts=foo\" uses latest \"foo\" LTS version" "b/test/slow/nvm use/Running \"nvm use --lts=foo\" uses latest \"foo\" LTS version" new file mode 100755 index 0000000000..73bdd6513b --- /dev/null +++ "b/test/slow/nvm use/Running \"nvm use --lts=foo\" uses latest \"foo\" LTS version" @@ -0,0 +1,22 @@ +#!/bin/sh + +set -ex + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +nvm deactivate 2>&1 >/dev/null || die 'deactivate failed' + +nvm use --lts=testing || die 'nvm use --lts=testing failed' +OUTPUT="$(nvm current)" +EXPECTED_OUTPUT="$(nvm_resolve_alias 'lts/testing')" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ + || die "'nvm use --lts=testing' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'" + +OUTPUT="$(nvm use --silent --lts=testing)" +EXPECTED_OUTPUT="" + +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ + || die "'nvm use --silent --lts=testing' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'" diff --git a/test/slow/nvm use/setup_dir b/test/slow/nvm use/setup_dir index 20fa239128..767ab55813 100755 --- a/test/slow/nvm use/setup_dir +++ b/test/slow/nvm use/setup_dir @@ -6,6 +6,10 @@ mkdir -p "${NVM_DIR}/.nvm_use_bak" if [ -d "${NVM_DIR}/v*" ]; then mv "${NVM_DIR}/v*" "${NVM_DIR}/.nvm_use_bak/" fi +mkdir -p "${NVM_DIR}/.nvm_use_lts_alias_bak" +if [ -d "${NVM_DIR}/alias/lts" ]; then + mv "${NVM_DIR}/alias/lts/*" "${NVM_DIR}/.nvm_use_lts_alias_bak/" +fi for VERSION in "0.8.7" "0.9.1" "0.10.1" "0.11.1"; do nvm install "v$VERSION" @@ -14,3 +18,6 @@ done for VERSION in "1.0.0" "1.0.1"; do nvm install "iojs-v$VERSION" done + +nvm_make_alias lts/testing 0.10.1 +nvm_make_alias 'lts/*' lts/testing diff --git a/test/slow/nvm use/teardown_dir b/test/slow/nvm use/teardown_dir index eeda3372f1..a1543e5d42 100755 --- a/test/slow/nvm use/teardown_dir +++ b/test/slow/nvm use/teardown_dir @@ -10,7 +10,13 @@ for VERSION in "1.0.0" "1.0.1"; do nvm uninstall "iojs-v$VERSION" done -if [ -d ../../../.nvm_use_bak/* ]; then - mv ../../../.nvm_use_bak/* ../../../ +if [ -d "${NVM_DIR}/.nvm_use_bak/*" ]; then + mv "${NVM_DIR}/.nvm_use_bak/*" "${NVM_DIR}" + rmdir "${NVM_DIR}/.nvm_use_bak" +fi + +if [ -d "${NVM_DIR}/.nvm_use_lts_alias_bak" ]; then + rm -rf "${NVM_DIR}/alias/lts/*" + mv "${NVM_DIR}/.nvm_use_lts_alias_bak/*" "${NVM_DIR}/alias/lts/" + rmdir "${NVM_DIR}/.nvm_use_lts_alias_bak" fi -rmdir ../../../.nvm_use_bak From 58a82a1d3128e2b5e7bb9cf662480e5f720b1e07 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 17 Jul 2016 19:54:10 -0700 Subject: [PATCH 25/28] [Tests] add `nvm exec --lts` tests. --- .../Running \"nvm exec --lts\" should work" | 18 ++++++++++++++++++ test/slow/nvm exec/setup_dir | 1 + test/slow/nvm exec/teardown_dir | 1 + 3 files changed, 20 insertions(+) create mode 100755 "test/slow/nvm exec/Running \"nvm exec --lts\" should work" diff --git "a/test/slow/nvm exec/Running \"nvm exec --lts\" should work" "b/test/slow/nvm exec/Running \"nvm exec --lts\" should work" new file mode 100755 index 0000000000..ce8ebaf1aa --- /dev/null +++ "b/test/slow/nvm exec/Running \"nvm exec --lts\" should work" @@ -0,0 +1,18 @@ +#!/bin/sh + +set -ex + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +nvm install --lts || die 'nvm install --lts failed' + +NPM_VERSION_LTS="$(npm --version)" +TEST_STRING="foo bar" + +nvm use 1.0.0 && [ "$(node --version)" = "v1.0.0" ] || die "\`nvm use\` failed!" + +[ "$(nvm exec --lts npm --version | tail -1)" = "$NPM_VERSION_LTS" ] || die "`nvm exec` failed to run with the correct version" + +[ "$(nvm exec --lts bash -c "printf '$TEST_STRING'" | tail -1)" = "$TEST_STRING" ] || die "\`nvm exec\` failed to run with a command including whitespace" diff --git a/test/slow/nvm exec/setup_dir b/test/slow/nvm exec/setup_dir index d858b233de..d6bba73fdb 100755 --- a/test/slow/nvm exec/setup_dir +++ b/test/slow/nvm exec/setup_dir @@ -3,6 +3,7 @@ . ../../../nvm.sh nvm install 0.10.7 nvm install 1.0.0 +nvm install --lts if [ -f ".nvmrc" ]; then mv .nvmrc .nvmrc.bak diff --git a/test/slow/nvm exec/teardown_dir b/test/slow/nvm exec/teardown_dir index d9e0dc68e6..573e91d438 100755 --- a/test/slow/nvm exec/teardown_dir +++ b/test/slow/nvm exec/teardown_dir @@ -4,6 +4,7 @@ nvm deactivate nvm uninstall v0.10.7 nvm uninstall v1.0.0 +nvm uninstall --lts rm .nvmrc From 876d11737618a4be62c3d860f420b66b5f03bcfc Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 18 Jul 2016 00:35:01 -0700 Subject: [PATCH 26/28] [Tests] add `nvm run --lts` tests. --- .../Running \"nvm run --lts\" should work" | 15 +++++++++++++++ test/slow/nvm run/setup_dir | 3 +++ test/slow/nvm run/teardown_dir | 3 +++ 3 files changed, 21 insertions(+) create mode 100755 "test/slow/nvm run/Running \"nvm run --lts\" should work" diff --git "a/test/slow/nvm run/Running \"nvm run --lts\" should work" "b/test/slow/nvm run/Running \"nvm run --lts\" should work" new file mode 100755 index 0000000000..c512887d5c --- /dev/null +++ "b/test/slow/nvm run/Running \"nvm run --lts\" should work" @@ -0,0 +1,15 @@ +#!/bin/sh + +set -ex + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +OUTPUT="$(nvm run --silent --lts --version)" +EXPECTED_OUTPUT="$(nvm_match_version 'lts/*')" +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm run --lts\` failed to run with the correct version; expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<" + +OUTPUT="$(nvm run --silent --lts=argon --version)" +EXPECTED_OUTPUT="$(nvm_match_version 'lts/argon')" +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm run --lts=argon\` failed to run with the correct version; expected >${EXPECTED_OUTPUT}<, got >${OUTPUT}<" diff --git a/test/slow/nvm run/setup_dir b/test/slow/nvm run/setup_dir index 870a22c495..a767a0227b 100755 --- a/test/slow/nvm run/setup_dir +++ b/test/slow/nvm run/setup_dir @@ -1,7 +1,10 @@ #!/bin/sh . ../../../nvm.sh + nvm install 0.10.7 +nvm install --lts=argon +nvm install --lts if [ -f ".nvmrc" ]; then mv .nvmrc .nvmrc.bak diff --git a/test/slow/nvm run/teardown_dir b/test/slow/nvm run/teardown_dir index 55e2a616f2..4290f07628 100755 --- a/test/slow/nvm run/teardown_dir +++ b/test/slow/nvm run/teardown_dir @@ -1,8 +1,11 @@ #!/bin/sh . ../../../nvm.sh + nvm deactivate nvm uninstall v0.10.7 +nvm uninstall --lts=argon +nvm uninstall --lts rm .nvmrc From 28822ff81ef7bec32b54da18643a0039ec7ae240 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 18 Jul 2016 23:39:35 -0700 Subject: [PATCH 27/28] [Docs] update README for LTS. --- README.markdown | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/README.markdown b/README.markdown index afd8c690d9..385cf48459 100644 --- a/README.markdown +++ b/README.markdown @@ -28,7 +28,7 @@ Note: On OS X, if you have/had a "system" node installed and want to install mod - If you have an `~/.npmrc` file, make sure it does not contain any `prefix` settings (which is not compatible with nvm) - You can (but should not?) keep your previous "system" node install, but nvm will only be available to your user account (the one used to install nvm). This might cause version mismatches, as other users will be using `/usr/local/lib/node_modules/*` VS your user account using `~/.nvm/versions/node/vX.X.X/lib/node_modules/*` -Homebrew installation is not supported. +Homebrew installation is not supported. If you have issues with homebrew-installed `nvm`, please `brew uninstall` it, and install it using the instructions below, before filing an issue. Note: If you're using `zsh` you can easily install `nvm` as a zsh plugin. Install [`zsh-nvm`](https://github.com/lukechilds/zsh-nvm) and run `nvm_update` to update. @@ -112,22 +112,22 @@ After upgrading, don't forget to activate the new version: ## Usage -To download, compile, and install the latest v5.0.x release of node, do this: +To download, compile, and install the latest release of node, do this: ```sh -nvm install 5.0 +nvm install node ``` And then in any new shell just use the installed version: ```sh -nvm use 5.0 +nvm use node ``` Or you can just run it: ```sh -nvm run 5.0 --version +nvm run node --version ``` Or, you can run any arbitrary command in a subshell with the desired version of node: @@ -148,6 +148,19 @@ In place of a version pointer like "0.10" or "5.0" or "4.2.1", you can use the f - `stable`: this alias is deprecated, and only truly applies to `node` `v0.12` and earlier. Currently, this is an alias for `node`. - `unstable`: this alias points to `node` `v0.11` - the last "unstable" node release, since post-1.0, all node versions are stable. (in semver, versions communicate breakage, not stability). +### 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` + +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. + +### Migrating global packages while installing If you want to install a new version of Node.js and migrate npm packages from a previous version: ```sh @@ -159,10 +172,11 @@ This will first use "nvm version node" to identify the current version you're mi You can also install and migrate npm packages from specific versions of Node like this: ```sh -nvm install v5.0 --reinstall-packages-from=4.2 +nvm install 6 --reinstall-packages-from=5 nvm install v4.2 --reinstall-packages-from=iojs ``` +### io.js If you want to install [io.js](https://github.com/iojs/io.js/): ```sh @@ -177,6 +191,7 @@ nvm install iojs --reinstall-packages-from=iojs The same guidelines mentioned for migrating npm packages in Node.js are applicable to io.js. +### System version of node If you want to use the system-installed version of node, you can use the special default alias "system": ```sh @@ -184,6 +199,7 @@ nvm use system nvm run system --version ``` +### Listing versions If you want to see what versions are installed: ```sh @@ -217,7 +233,7 @@ nvm install node NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist nvm install 4.2 ``` -To use a mirror of the iojs binaries, set `$NVM_IOJS_ORG_MIRROR`: +To use a mirror of the io.js binaries, set `$NVM_IOJS_ORG_MIRROR`: ```sh export NVM_IOJS_ORG_MIRROR=https://iojs.org/dist @@ -226,7 +242,7 @@ nvm install iojs-v1.0.3 NVM_IOJS_ORG_MIRROR=https://iojs.org/dist nvm install iojs-v1.0.3 ``` -`nvm use` will not, by default, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to "true" to enable this behavior, which is sometimes useful for IDEs. +`nvm use` will not, by default, create a "current" symlink. Set `$NVM_SYMLINK_CURRENT` to "true" to enable this behavior, which is sometimes useful for IDEs. Note that using `nvm` in multiple shell tabs with this environment variable enabled can cause race conditions. ### .nvmrc @@ -237,6 +253,8 @@ For example, to make nvm default to the latest 5.9 release for the current direc ```sh $ echo "5.9" > .nvmrc + +$ echo "lts/*" > .nvmrc # to default to the latest LTS version ``` Then when you run nvm: @@ -280,7 +298,7 @@ load-nvmrc nvm is released under the MIT license. -Copyright (C) 2010-2016 Tim Caswell +Copyright (C) 2010-2016 Tim Caswell and Jordan Harband Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: From fb49bf6f706548fcc33eef4207cfd37a08cb6237 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Mon, 18 Jul 2016 23:40:32 -0700 Subject: [PATCH 28/28] completion: add LTS aliases. --- bash_completion | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bash_completion b/bash_completion index d538388db2..42bd7af4d6 100644 --- a/bash_completion +++ b/bash_completion @@ -57,9 +57,9 @@ __nvm_aliases () declare aliases aliases="" if [ -d $NVM_DIR/alias ]; then - aliases="`cd $NVM_DIR/alias && command ls`" + aliases="$(cd $NVM_DIR/alias && find $PWD -type f | sed "s:$PWD/::")" fi - echo "${aliases}" + echo "${aliases} node stable unstable iojs" } __nvm_alias ()