feat(nodeenv): accept npm-style semver ranges in --node - #393
Merged
Conversation
ekalinin
force-pushed
the
feat/node-version-ranges
branch
from
August 14, 2026 18:30
39dc049 to
13ccc0b
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #152.
--nodecurrently accepts only an exact version or one ofsystem/latest/lts. Getting "the newest 22.x" meant callingnodeenv --list, parsing it and sorting the result by hand.This adds npm-style semver ranges, resolved to the highest matching release:
Ranges work in
.node-versionfiles too, since that file feeds the same option.Notes
No new dependencies.
install_requiresstays empty, so the range parser is implemented in the module rather than pulling inpackagingorsemver.Exact versions still make no network request.
22.11.0is detected up front and passed through untouched, keeping offline installs and current latency intact.Unparseable strings are passed through, not rejected. Nightly and custom-mirror versions such as
23.0.0-nightly20240101abcdefare not valid semver, so erroring on them would be a regression. The change is strictly additive: anything that works today still works.Partial comparators follow npm.
>4.3means>=4.4.0, not>4.3.0- zero-padding would let>4.3match4.3.2.^follows the leftmost-non-zero rule, including the^0.4.3-><0.5.0and^0.0.3-><0.0.4cases, since 0.x versions are still supported.Platform builds are respected. The musl/riscv64 filter in
_get_last_node_version()is extracted into_has_platform_build()and reused by the resolver, so a musl host cannot resolve to a release that ships no build for it and then fail at download time.A range that parses but matches nothing logs an error and exits 1.
Tests
62 new unit tests covering the parser, the matcher, resolution against the existing
nodejs_index.jsonfixture, the platform filter, andmain()dispatch (including assertions that exact/system/unparseable inputs make nourlopencall). Full suite: 192 passed, flake8 clean.Verified end to end against nodejs.org:
--node '^22.11'resolves to 22.23.2, installs, andnode --versionreportsv22.23.2.