mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-08-17 19:13:43 +00:00
Compare commits
7 Commits
90ab4fd0b0
...
e7a73dc43c
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e7a73dc43c | ||
![]() |
daad6939a1 | ||
![]() |
96d4d30128 | ||
![]() |
b26552732b | ||
![]() |
59e190d7b4 | ||
![]() |
80c00ad9ba | ||
![]() |
0228613c7e |
17
nvm.sh
17
nvm.sh
@ -1827,7 +1827,6 @@ nvm_print_versions() {
|
|||||||
-v old_lts_color="$DEFAULT_COLOR" -v has_colors="$NVM_HAS_COLORS" '
|
-v old_lts_color="$DEFAULT_COLOR" -v has_colors="$NVM_HAS_COLORS" '
|
||||||
function alen(arr, i, len) { len=0; for(i in arr) len++; return len; }
|
function alen(arr, i, len) { len=0; for(i in arr) len++; return len; }
|
||||||
function v2a(v, a) { sub(/^(iojs-)?v/, "", v); split(v, a, "."); }
|
function v2a(v, a) { sub(/^(iojs-)?v/, "", v); split(v, a, "."); }
|
||||||
function v2m(v, a) { sub(/^(iojs-)?v/, "", v); split(v, a, "."); return a[1]; }
|
|
||||||
function vcmp(v1,v2,a1,a2,i,d) { v2a(v1,a1); v2a(v2,a2); for(i=1;i<4;i++) { d = a1[i] - a2[i]; if(d!=0) return d; } return 0; }
|
function vcmp(v1,v2,a1,a2,i,d) { v2a(v1,a1); v2a(v2,a2); for(i=1;i<4;i++) { d = a1[i] - a2[i]; if(d!=0) return d; } return 0; }
|
||||||
BEGIN {
|
BEGIN {
|
||||||
fmt_installed = has_colors ? (installed_color ? "\033[" installed_color "%15s\033[0m" : "%15s") : "%15s *";
|
fmt_installed = has_colors ? (installed_color ? "\033[" installed_color "%15s\033[0m" : "%15s") : "%15s *";
|
||||||
@ -1844,7 +1843,6 @@ BEGIN {
|
|||||||
split(installed_versions, installed, "|");
|
split(installed_versions, installed, "|");
|
||||||
rows = alen(lines);
|
rows = alen(lines);
|
||||||
filter_on = (vcmp("v0.0.0", min_ver) != 0);
|
filter_on = (vcmp("v0.0.0", min_ver) != 0);
|
||||||
current_major = -1;
|
|
||||||
for (m = n = 1; n <= rows; n++) {
|
for (m = n = 1; n <= rows; n++) {
|
||||||
split(lines[n], fields, "[[:blank:]]+");
|
split(lines[n], fields, "[[:blank:]]+");
|
||||||
cols = alen(fields);
|
cols = alen(fields);
|
||||||
@ -1857,12 +1855,10 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter_on != 0) {
|
if (filter_on && !is_installed) {
|
||||||
if (is_installed != 0) {
|
if (vcmp(version, min_ver) >= 0) {
|
||||||
current_major = v2m(version);
|
|
||||||
} else if (vcmp(version, min_ver) >= 0) {
|
|
||||||
filter_on = 0;
|
filter_on = 0;
|
||||||
} else if (v2m(version) != current_major) {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1872,7 +1868,7 @@ BEGIN {
|
|||||||
fmt_version = fmt_current;
|
fmt_version = fmt_current;
|
||||||
} else if (version == "system") {
|
} else if (version == "system") {
|
||||||
fmt_version = fmt_system;
|
fmt_version = fmt_system;
|
||||||
} else if (is_installed != 0) {
|
} else if (is_installed) {
|
||||||
fmt_version = fmt_installed;
|
fmt_version = fmt_installed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3036,7 +3032,6 @@ nvm() {
|
|||||||
nvm_echo ' nvm ls-remote [<version>] List remote versions available for install, matching a given <version> if provided'
|
nvm_echo ' nvm ls-remote [<version>] List remote versions available for install, matching a given <version> if provided'
|
||||||
nvm_echo ' --lts When listing, only show LTS (long-term support) versions'
|
nvm_echo ' --lts When listing, only show LTS (long-term support) versions'
|
||||||
nvm_echo ' --lts=<LTS name> When listing, only show versions for a specific LTS line'
|
nvm_echo ' --lts=<LTS name> When listing, only show versions for a specific LTS line'
|
||||||
nvm_echo ' --min=<version> When listing, only show versions greater than or equal to <version>, including minor/patch updates for installed versions'
|
|
||||||
nvm_echo ' --no-colors Suppress colored output'
|
nvm_echo ' --no-colors Suppress colored output'
|
||||||
nvm_echo ' nvm version <version> Resolve the given description to a single local version'
|
nvm_echo ' nvm version <version> Resolve the given description to a single local version'
|
||||||
nvm_echo ' nvm version-remote <version> Resolve the given description to a single remote version'
|
nvm_echo ' nvm version-remote <version> Resolve the given description to a single remote version'
|
||||||
@ -4013,7 +4008,6 @@ nvm() {
|
|||||||
;;
|
;;
|
||||||
"ls-remote" | "list-remote")
|
"ls-remote" | "list-remote")
|
||||||
local NVM_LTS
|
local NVM_LTS
|
||||||
local NVM_MIN="${NVM_MIN-}"
|
|
||||||
local PATTERN
|
local PATTERN
|
||||||
local NVM_NO_COLORS
|
local NVM_NO_COLORS
|
||||||
|
|
||||||
@ -4026,9 +4020,6 @@ nvm() {
|
|||||||
--lts=*)
|
--lts=*)
|
||||||
NVM_LTS="${1##--lts=}"
|
NVM_LTS="${1##--lts=}"
|
||||||
;;
|
;;
|
||||||
--min=*)
|
|
||||||
NVM_MIN="${1##--min=}"
|
|
||||||
;;
|
|
||||||
--no-colors) NVM_NO_COLORS="${1}" ;;
|
--no-colors) NVM_NO_COLORS="${1}" ;;
|
||||||
--*)
|
--*)
|
||||||
nvm_err "Unsupported option \"${1}\"."
|
nvm_err "Unsupported option \"${1}\"."
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
die () { echo "$@" ; cleanup ; exit 1; }
|
die () { echo "$@" ; cleanup ; exit 1; }
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
unset -f nvm_remote_versions nvm_ls nvm_ls_current
|
unset -f nvm_remote_versions nvm_ls nvm_ls_current nvm_remote_versions
|
||||||
if [ -n "$TEMP_NVM_MIN" ]; then
|
if [ -n "$TEMP_NVM_MIN" ]; then
|
||||||
export NVM_MIN="$TEMP_NVM_MIN"
|
export NVM_MIN="$TEMP_NVM_MIN"
|
||||||
fi
|
fi
|
||||||
@ -33,8 +33,7 @@ nvm_ls_current() {
|
|||||||
|
|
||||||
nvm_remote_versions() {
|
nvm_remote_versions() {
|
||||||
echo "v16.0.0
|
echo "v16.0.0
|
||||||
v16.20.2 Gallium
|
v16.20.2 Gallium *
|
||||||
v16.20.3 Gallium *
|
|
||||||
v17.0.0
|
v17.0.0
|
||||||
v17.9.1
|
v17.9.1
|
||||||
v18.0.0
|
v18.0.0
|
||||||
@ -54,8 +53,7 @@ v21.1.0"
|
|||||||
# nvm_print_versions should print all versions from nvm_remote_versions
|
# nvm_print_versions should print all versions from nvm_remote_versions
|
||||||
OUTPUT="$(NVM_NO_COLORS=1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
|
OUTPUT="$(NVM_NO_COLORS=1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
|
||||||
EXPECTED_OUTPUT="v16.0.0
|
EXPECTED_OUTPUT="v16.0.0
|
||||||
v16.20.2 * (LTS: Gallium)
|
v16.20.2 * (Latest LTS: Gallium)
|
||||||
v16.20.3 (Latest LTS: Gallium)
|
|
||||||
v17.0.0
|
v17.0.0
|
||||||
v17.9.1
|
v17.9.1
|
||||||
v18.0.0
|
v18.0.0
|
||||||
@ -70,13 +68,12 @@ v20.9.0 (Latest LTS: Iron)
|
|||||||
v21.0.0
|
v21.0.0
|
||||||
v21.1.0"
|
v21.1.0"
|
||||||
|
|
||||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(1) nvm_print_versions did not output all expected versions; got $OUTPUT"
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_versions did not output all expected versions; got $OUTPUT"
|
||||||
|
|
||||||
|
|
||||||
# versions lower than 18 should be filtered out, but v16.20.2 should be kept since it's installed
|
# versions lower than 18 should be filtered out, but v16.20.2 should be kept since it's installed
|
||||||
OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=v18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
|
OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=v18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
|
||||||
EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium)
|
EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium)
|
||||||
v16.20.3 (Latest LTS: Gallium)
|
|
||||||
v18.0.0
|
v18.0.0
|
||||||
v18.1.0
|
v18.1.0
|
||||||
v18.20.2 (LTS: Hydrogen)
|
v18.20.2 (LTS: Hydrogen)
|
||||||
@ -89,13 +86,12 @@ v20.9.0 (Latest LTS: Iron)
|
|||||||
v21.0.0
|
v21.0.0
|
||||||
v21.1.0"
|
v21.1.0"
|
||||||
|
|
||||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(2) NVM_MIN=18 nvm_print_versions did not output all expected versions; got $OUTPUT"
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=18 nvm_print_versions did not output all expected versions; got $OUTPUT"
|
||||||
|
|
||||||
|
|
||||||
# versions lower than 19 should be filtered out
|
# versions lower than 19 should be filtered out
|
||||||
OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=19 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
|
OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=19 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
|
||||||
EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium)
|
EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium)
|
||||||
v16.20.3 (Latest LTS: Gallium)
|
|
||||||
-> v18.20.3 * (Latest LTS: Hydrogen)
|
-> v18.20.3 * (Latest LTS: Hydrogen)
|
||||||
v19.0.0
|
v19.0.0
|
||||||
v19.9.0
|
v19.9.0
|
||||||
@ -105,20 +101,19 @@ v20.9.0 (Latest LTS: Iron)
|
|||||||
v21.0.0
|
v21.0.0
|
||||||
v21.1.0"
|
v21.1.0"
|
||||||
|
|
||||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(3) NVM_MIN=19 nvm_print_versions did not output all expected versions; got $OUTPUT"
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=19 nvm_print_versions did not output all expected versions; got $OUTPUT"
|
||||||
|
|
||||||
|
|
||||||
# versions lower than 20.1 should be filtered out, so v20.0.0 is out
|
# versions lower than 20.1 should be filtered out, so v20.0.0 is out
|
||||||
OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=v20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
|
OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=v20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
|
||||||
EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium)
|
EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium)
|
||||||
v16.20.3 (Latest LTS: Gallium)
|
|
||||||
-> v18.20.3 * (Latest LTS: Hydrogen)
|
-> v18.20.3 * (Latest LTS: Hydrogen)
|
||||||
v20.8.1
|
v20.8.1
|
||||||
v20.9.0 (Latest LTS: Iron)
|
v20.9.0 (Latest LTS: Iron)
|
||||||
v21.0.0
|
v21.0.0
|
||||||
v21.1.0"
|
v21.1.0"
|
||||||
|
|
||||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(4) NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT"
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT"
|
||||||
|
|
||||||
|
|
||||||
# assume v18.20.3 is NOT installed, so now it should be filtered out
|
# assume v18.20.3 is NOT installed, so now it should be filtered out
|
||||||
@ -132,14 +127,13 @@ nvm_ls_current() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
|
OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
|
||||||
EXPECTED_OUTPUT="-> v16.20.2 * (LTS: Gallium)
|
EXPECTED_OUTPUT="-> v16.20.2 * (Latest LTS: Gallium)
|
||||||
v16.20.3 (Latest LTS: Gallium)
|
|
||||||
v20.8.1
|
v20.8.1
|
||||||
v20.9.0 (Latest LTS: Iron)
|
v20.9.0 (Latest LTS: Iron)
|
||||||
v21.0.0
|
v21.0.0
|
||||||
v21.1.0"
|
v21.1.0"
|
||||||
|
|
||||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(5) NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT"
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT"
|
||||||
|
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
Loading…
x
Reference in New Issue
Block a user