Skip to content
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

show only versions newer than NVM_MIN if set #3277

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ryenus
Copy link
Contributor

@ryenus ryenus commented Jan 29, 2024

This is to fix #3250.

@ryenus
Copy link
Contributor Author

ryenus commented Jan 29, 2024

For example, running NVM_MIN_VER=18 nvm ls-remote --lts when v14 and v16 are installed:

image

@ryenus ryenus force-pushed the minver branch 2 times, most recently from a81e16a to b10554a Compare January 29, 2024 15:22
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that it's done in awk :-) it'd be great to benchmark the difference to make sure this isn't slowing anything down meaningfully.

this will need tests, and also it'd be good to add a --min option to all the things that talk to the mirror (nvm ls-remote, nvm install, nvm version-remote) and then maybe nvm ls for good measure (altho that can be a follow-on if you like)

@ljharb ljharb added installing node Issues with installing node/io.js versions. feature requests I want a new feature in nvm! labels Jan 29, 2024
@ryenus
Copy link
Contributor Author

ryenus commented Jan 29, 2024

Performance-wise there's not really much change or overhead, you can trust that awk is fast :-) Sometimes it might even run faster, esp. when many older versions are skipped.

Meanwhile the other sibling functions and even the tests are something I'm not really familiar with, may you can chime in here? @ljharb

@ljharb
Copy link
Member

ljharb commented Jan 29, 2024

Sure - for the tests, there's existing tests for nvm ls-remote that employ mocks for the remote data, and a test that uses the env var, and asserts that it matches the mock minus the first N lines (since older versions aren't going to change, that number won't break over time), that would be sufficient. Similar approaches will work for the others.

For adding an option, if you grep for "ls-remote" you'll find the chunk of code where top-level commands are defined, and there's a bunch of existing examples that process the arguments.

@ryenus ryenus force-pushed the minver branch 2 times, most recently from abde015 to 132b9fb Compare June 29, 2024 05:54
@ryenus
Copy link
Contributor Author

ryenus commented Jun 29, 2024

@ljharb just added a test, however Travis CI seems stuck, any insight?

@ryenus
Copy link
Contributor Author

ryenus commented Jun 29, 2024

BTW, I had to adjust the travis job a bit, due to the error

pyenv: /opt/pyenv/versions/2.7.18 already exists

See the screenshot below (https://app.travis-ci.com/github/nvm-sh/nvm/jobs/623514514):

image

show only versions newer than NVM_MIN_VER if set
@ryenus ryenus changed the title show only versions newer than NVM_MIN_VER if set show only versions newer than NVM_MIN if set Jun 29, 2024
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It occurs to me that

@@ -1820,12 +1820,14 @@ nvm_print_versions() {
fi

command awk \
-v remote_versions="$(printf '%s' "${1-}" | tr '\n' '|')" \
-v remote_versions="$(printf '%s' "${1-}" | tr '\n' '|')" -v min_ver="${NVM_MIN:-v0}" \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is defaulting it to v0 the right choice, as opposed to skipping the logic entirely?

Copy link
Contributor Author

@ryenus ryenus Jun 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely we could do that, meanwhile versions like v0, v0.0, and 0.0.0 (without the prefix v), are all legit, therefore, we have the filter_on flag which is deduced with this:

filter_on = (vcmp("v0.0.0", min_ver) != 0);

And given that the versions list is already sorted, once we encounter the version greater or equal to the min version specified, we turn off the filtering logic and show all versions onward.

@@ -1863,8 +1872,7 @@ BEGIN {
fmt_version = fmt_installed;
}
padding = (!has_colors && is_installed) ? "" : " ";
padding = (is_installed && !has_colors) ? "" : " ";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nbd, but why flip these conditions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really flipping, just swapping the LHS and RHS of the && operator. This slightly improves the clarity and makes it clear that only !has_colors is the negating part. This is something I should have done in the first place.

Comment on lines 74 to 75
# 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=18 nvm_print_versions "$(nvm_remote_versions)" | sed -r 's/^[ \t]+//')"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if you have v16.20.1 installed, for example, and you still want to see that v16.20.2 is both available, and the latest LTS from that line?

maybe anything that's installed plus ^ of it should still be shown?

or maybe, we should skip the "keep if installed" logic entirely?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the chosen behavior is slightly more preferable, due to the fact that nvm ls-remote has always been highlighting the installed versions, so that people can intuitively compare the versions they installed, to the newer versions available. And that kind of intuition is needed for people to decide whether or when to install a new version, which is much nicer than having to run both nvm ls-remote and nvm ls.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok - in that case, setting a MIN_VER of 18, with 16.20.1 installed as the only 16, should still show 16.20.2 as an installable version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, isn't that a bit too far? If we do that then it means the min version is effectively the oldest installed version, hence defeating the point of specifying a min version. Nevertheless I agree it's a bit tricky to decide on which is the sweet spot.

Another option could be that we first let it out and see the user perception from the community.

@ryenus ryenus force-pushed the minver branch 2 times, most recently from 46690fd to daad693 Compare June 30, 2024 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature requests I want a new feature in nvm! installing node Issues with installing node/io.js versions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ls-remote] only list active and/or maintained versions
2 participants