-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
show only versions newer than NVM_MIN if set #3277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ryenus
wants to merge
16
commits into
nvm-sh:master
Choose a base branch
from
ryenus:minver
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
48fe276
show only versions newer than NVM_MIN_VER if set
ryenus 37811e0
always list installed versions
ryenus c390144
add test for NVM_MIN_VER support
ryenus 9f4dd64
trim leading space in mock output due to eclint errors
ryenus b16b4ee
rename NVM_MIN_VER to NVM_MIN
ryenus f2b7583
prefixed versions like v18 also work
ryenus 858eda5
remove function ref duplication
ryenus 54a5777
always show updates for installed versions
ryenus 594f8c0
ls-remote: add CLI option --min=<version>
ryenus e71918e
avoid inline initialization for ksh compatibility
ryenus c029641
ls-remote: introduce temp var for env inheritance
ryenus f99c9f3
[test] avoid leaking temp variable
ryenus 206a142
rename min_ver to min for consistency
ryenus dd28eb4
set NVM_NO_COLORS to --no-colors to disable color
ryenus fc4a98b
display a hint when version filtering is in effect
ryenus f28584c
indent awk script properly
ryenus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
#!/bin/sh | ||
|
||
# shellcheck disable=SC2317 | ||
|
||
die () { echo "$@" ; cleanup ; exit 1; } | ||
|
||
cleanup() { | ||
unset -f nvm_remote_versions nvm_ls nvm_ls_current | ||
if [ -n "$TEMP_NVM_MIN" ]; then | ||
export NVM_MIN="$TEMP_NVM_MIN" | ||
unset TEMP_NVM_MIN | ||
fi | ||
} | ||
|
||
\. ../../../nvm.sh | ||
|
||
|
||
if [ -n "$NVM_MIN" ]; then | ||
TEMP_NVM_MIN="$NVM_MIN" | ||
unset NVM_MIN | ||
fi | ||
|
||
# mock currently installed versions | ||
nvm_ls() { | ||
echo "v16.20.2 | ||
v18.20.3 | ||
system" | ||
} | ||
|
||
# mock currently active version | ||
nvm_ls_current() { | ||
echo "v18.20.3" | ||
} | ||
|
||
nvm_remote_versions() { | ||
echo "v16.0.0 | ||
v16.20.2 Gallium | ||
v16.20.3 Gallium * | ||
v17.0.0 | ||
v17.9.1 | ||
v18.0.0 | ||
v18.1.0 | ||
v18.20.2 Hydrogen | ||
v18.20.3 Hydrogen * | ||
v19.0.0 | ||
v19.9.0 | ||
v20.0.0 | ||
v20.8.1 | ||
v20.9.0 Iron * | ||
v21.0.0 | ||
v21.1.0" | ||
} | ||
|
||
|
||
# nvm_print_versions should print all versions from nvm_remote_versions | ||
OUTPUT="$(NVM_NO_COLORS='--no-colors' nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" | ||
EXPECTED_OUTPUT="v16.0.0 | ||
v16.20.2 * (LTS: Gallium) | ||
v16.20.3 (Latest LTS: Gallium) | ||
v17.0.0 | ||
v17.9.1 | ||
v18.0.0 | ||
v18.1.0 | ||
v18.20.2 (LTS: Hydrogen) | ||
-> v18.20.3 * (Latest LTS: Hydrogen) | ||
v19.0.0 | ||
v19.9.0 | ||
v20.0.0 | ||
v20.8.1 | ||
v20.9.0 (Latest LTS: Iron) | ||
v21.0.0 | ||
v21.1.0" | ||
|
||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(1) 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 | ||
OUTPUT="$(NVM_NO_COLORS='--no-colors' NVM_MIN=v18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" | ||
EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium) | ||
v16.20.3 (Latest LTS: Gallium) | ||
v18.0.0 | ||
v18.1.0 | ||
v18.20.2 (LTS: Hydrogen) | ||
-> v18.20.3 * (Latest LTS: Hydrogen) | ||
v19.0.0 | ||
v19.9.0 | ||
v20.0.0 | ||
v20.8.1 | ||
v20.9.0 (Latest LTS: Iron) | ||
v21.0.0 | ||
v21.1.0" | ||
|
||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(2) NVM_MIN=18 nvm_print_versions did not output all expected versions; got $OUTPUT" | ||
|
||
|
||
# versions lower than 19 should be filtered out | ||
OUTPUT="$(NVM_NO_COLORS='--no-colors' NVM_MIN=19 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" | ||
EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium) | ||
v16.20.3 (Latest LTS: Gallium) | ||
-> v18.20.3 * (Latest LTS: Hydrogen) | ||
v19.0.0 | ||
v19.9.0 | ||
v20.0.0 | ||
v20.8.1 | ||
v20.9.0 (Latest LTS: Iron) | ||
v21.0.0 | ||
v21.1.0" | ||
|
||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(3) 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 | ||
OUTPUT="$(NVM_NO_COLORS='--no-colors' NVM_MIN=v20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" | ||
EXPECTED_OUTPUT="v16.20.2 * (LTS: Gallium) | ||
v16.20.3 (Latest LTS: Gallium) | ||
-> v18.20.3 * (Latest LTS: Hydrogen) | ||
v20.8.1 | ||
v20.9.0 (Latest LTS: Iron) | ||
v21.0.0 | ||
v21.1.0" | ||
|
||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(4) 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 | ||
nvm_ls() { | ||
echo "v16.20.2 | ||
system" | ||
} | ||
|
||
nvm_ls_current() { | ||
echo "v16.20.2" | ||
} | ||
|
||
OUTPUT="$(NVM_NO_COLORS='--no-colors' NVM_MIN=20.1 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')" | ||
EXPECTED_OUTPUT="-> v16.20.2 * (LTS: Gallium) | ||
v16.20.3 (Latest LTS: Gallium) | ||
v20.8.1 | ||
v20.9.0 (Latest LTS: Iron) | ||
v21.0.0 | ||
v21.1.0" | ||
|
||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "(5) NVM_MIN=20.1 nvm_print_versions did not output all expected versions; got $OUTPUT" | ||
|
||
|
||
cleanup |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.