Skip to content

Commit 477d229

Browse files
committed
always show updates for installed versions
even if they're older than $NVM_MIN
1 parent ce329fb commit 477d229

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

nvm.sh

+8-4
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,7 @@ nvm_print_versions() {
18271827
-v old_lts_color="$DEFAULT_COLOR" -v has_colors="$NVM_HAS_COLORS" '
18281828
function alen(arr, i, len) { len=0; for(i in arr) len++; return len; }
18291829
function v2a(v, a) { sub(/^(iojs-)?v/, "", v); split(v, a, "."); }
1830+
function v2m(v, a) { sub(/^(iojs-)?v/, "", v); split(v, a, "."); return a[1]; }
18301831
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; }
18311832
BEGIN {
18321833
fmt_installed = has_colors ? (installed_color ? "\033[" installed_color "%15s\033[0m" : "%15s") : "%15s *";
@@ -1843,6 +1844,7 @@ BEGIN {
18431844
split(installed_versions, installed, "|");
18441845
rows = alen(lines);
18451846
filter_on = (vcmp("v0.0.0", min_ver) != 0);
1847+
current_major = -1;
18461848
for (m = n = 1; n <= rows; n++) {
18471849
split(lines[n], fields, "[[:blank:]]+");
18481850
cols = alen(fields);
@@ -1855,10 +1857,12 @@ BEGIN {
18551857
}
18561858
}
18571859
1858-
if (filter_on && !is_installed) {
1859-
if (vcmp(version, min_ver) >= 0) {
1860+
if (filter_on != 0) {
1861+
if (is_installed != 0) {
1862+
current_major = v2m(version);
1863+
} else if (vcmp(version, min_ver) >= 0) {
18601864
filter_on = 0;
1861-
} else {
1865+
} else if (v2m(version) != current_major) {
18621866
continue;
18631867
}
18641868
}
@@ -1868,7 +1872,7 @@ BEGIN {
18681872
fmt_version = fmt_current;
18691873
} else if (version == "system") {
18701874
fmt_version = fmt_system;
1871-
} else if (is_installed) {
1875+
} else if (is_installed != 0) {
18721876
fmt_version = fmt_installed;
18731877
}
18741878

test/fast/Unit tests/nvm_print_versions

+17-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ nvm_ls_current() {
3333

3434
nvm_remote_versions() {
3535
echo "v16.0.0
36-
v16.20.2 Gallium *
36+
v16.20.2 Gallium
37+
v16.20.3 Gallium *
3738
v17.0.0
3839
v17.9.1
3940
v18.0.0
@@ -53,7 +54,8 @@ v21.1.0"
5354
# nvm_print_versions should print all versions from nvm_remote_versions
5455
OUTPUT="$(NVM_NO_COLORS=1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
5556
EXPECTED_OUTPUT="v16.0.0
56-
v16.20.2 * (Latest LTS: Gallium)
57+
v16.20.2 * (LTS: Gallium)
58+
v16.20.3 (Latest LTS: Gallium)
5759
v17.0.0
5860
v17.9.1
5961
v18.0.0
@@ -68,12 +70,13 @@ v20.9.0 (Latest LTS: Iron)
6870
v21.0.0
6971
v21.1.0"
7072

71-
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_versions did not output all expected versions; got $OUTPUT"
73+
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(1) nvm_print_versions did not output all expected versions; got $OUTPUT"
7274

7375

7476
# versions lower than 18 should be filtered out, but v16.20.2 should be kept since it's installed
7577
OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=v18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
76-
EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium)
78+
EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium)
79+
v16.20.3 (Latest LTS: Gallium)
7780
v18.0.0
7881
v18.1.0
7982
v18.20.2 (LTS: Hydrogen)
@@ -86,12 +89,13 @@ v20.9.0 (Latest LTS: Iron)
8689
v21.0.0
8790
v21.1.0"
8891

89-
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=18 nvm_print_versions did not output all expected versions; got $OUTPUT"
92+
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(2) NVM_MIN=18 nvm_print_versions did not output all expected versions; got $OUTPUT"
9093

9194

9295
# versions lower than 19 should be filtered out
9396
OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=19 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
94-
EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium)
97+
EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium)
98+
v16.20.3 (Latest LTS: Gallium)
9599
-> v18.20.3 * (Latest LTS: Hydrogen)
96100
v19.0.0
97101
v19.9.0
@@ -101,19 +105,20 @@ v20.9.0 (Latest LTS: Iron)
101105
v21.0.0
102106
v21.1.0"
103107

104-
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=19 nvm_print_versions did not output all expected versions; got $OUTPUT"
108+
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(3) NVM_MIN=19 nvm_print_versions did not output all expected versions; got $OUTPUT"
105109

106110

107111
# versions lower than 20.1 should be filtered out, so v20.0.0 is out
108112
OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=v20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
109-
EXPECTED_OUTPUT="v16.20.2 * (Latest LTS: Gallium)
113+
EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium)
114+
v16.20.3 (Latest LTS: Gallium)
110115
-> v18.20.3 * (Latest LTS: Hydrogen)
111116
v20.8.1
112117
v20.9.0 (Latest LTS: Iron)
113118
v21.0.0
114119
v21.1.0"
115120

116-
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT"
121+
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(4) NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT"
117122

118123

119124
# assume v18.20.3 is NOT installed, so now it should be filtered out
@@ -127,13 +132,14 @@ nvm_ls_current() {
127132
}
128133

129134
OUTPUT="$(NVM_NO_COLORS=1 NVM_MIN=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
130-
EXPECTED_OUTPUT="-> v16.20.2 * (Latest LTS: Gallium)
135+
EXPECTED_OUTPUT="-> v16.20.2 * (LTS: Gallium)
136+
v16.20.3 (Latest LTS: Gallium)
131137
v20.8.1
132138
v20.9.0 (Latest LTS: Iron)
133139
v21.0.0
134140
v21.1.0"
135141

136-
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT"
142+
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(5) NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT"
137143

138144

139145
cleanup

0 commit comments

Comments
 (0)