-
Notifications
You must be signed in to change notification settings - Fork 492
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
add minVersion function #208
Conversation
I would really like this too, to be able to derive the minimum supported Node.js version from the range in To easily do this in my own packages I make the assumption the range is always a single semver prefixed with
|
if (!rangeObj.range) { | ||
return '0.0.0'; | ||
} | ||
return rangeObj.set[0][0].semver.version; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will return an incorrect value in the following cases:
minVersion('1.2.3 || 1.0.0') // expect 1.0.0, get 1.2.3
minVersion('<=1.2.3 >1.0.0') // expect 1.0.1, get 1.2.3
minVersion('>1.2.3') // expect 1.2.4, get 1.2.3
minVersion('>1.2.3-alpha') // <-- this one is probably impossible? 1.2.3-alpha is incorrect tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was working on a patch for this before I saw this PR. #241 deals with these edge cases and includes testing for them situations. minVersion('>1.2.3-alpha')
is not impossible, I believe the correct result is 1.2.3-alpha.0
which is less than 1.2.3-beta
.
I think that this might be theoretically impossible. You could get the minimum of a given set of versions that satisfies a given range. But what you can't do is (usually) specify the minimum version that would satisfy a range. Consider |
The |
|
I'm trying to decide which range is "newer" when automatically updating package.json here and here. The scenario is
I want to be smart and say, even though the dep was updated, mine is more recent, so ignore the change. My pseudocode is
if myDepRange < newDepRange then update
.Getting the lowest possible version in a range seems like a good way to compare two ranges for newest. I currently am doing:
But I feel like I'm reaching into too much private API. I would like add this function upstream to this library.