-
Notifications
You must be signed in to change notification settings - Fork 15
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
include_prerelease option #76
base: main
Are you sure you want to change the base?
Conversation
Ping @jsonperl. Just checking if this PR make sense. |
XRANGELOOSE = /^#{GTLT.source}\s*#{XRANGEPLAINLOOSE.source}$/.freeze | ||
COMPARATOR = /^#{GTLT.source}\s*(#{FULLPLAIN.source})$|^$/.freeze | ||
COMPARATORLOOSE = /^#{GTLT.source}\s*(#{LOOSEPLAIN.source})$|^$/.freeze | ||
GTE0 = /^\s*>=\s*0\.0\.0\s*$/.freeze |
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.
GTE0 consts added
@@ -50,12 +52,12 @@ class InvalidVersion < StandardError; end | |||
class InvalidComparator < StandardError; end | |||
class InvalidRange < StandardError; end | |||
|
|||
def self.ltr?(version, range, loose: false, platform: nil) | |||
outside?(version, range, '<', loose: loose, platform: platform) | |||
def self.ltr?(version, range, loose: false, platform: nil, include_prerelease: false) |
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.
This copy-pasting of options sucks, but I like it validates argument names 🤔
@@ -19,6 +20,21 @@ def initialize(range, loose: false, platform: nil) | |||
|
|||
raise InvalidRange.new(range) if @set.empty? || @set == [[]] | |||
|
|||
if @set.any? |
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.
All these changes are copied behaviour from node-semver
['<=2.0.0', '<=2.0.0'], | ||
['<=2.0.0', '<=2.0.0'], | ||
['<2.0.0', '<2.0.0'], | ||
['1', '>=1.0.0 <2.0.0-0'], |
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.
Copied test cases from node-semver too.
@@ -19,6 +20,21 @@ def initialize(range, loose: false, platform: nil) | |||
|
|||
raise InvalidRange.new(range) if @set.empty? || @set == [[]] | |||
|
|||
if @set.any? |
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.
We shouldn't be able to get here since line 21 checks the set right?
@@ -19,6 +20,21 @@ def initialize(range, loose: false, platform: nil) | |||
|
|||
raise InvalidRange.new(range) if @set.empty? || @set == [[]] | |||
|
|||
if @set.any? | |||
first = set.first |
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.
first = set.first | |
first = @set.first |
@set = @set.reject { |c| is_null_set(c[0]) } | ||
if @set.empty? | ||
@set = [first] | ||
elsif @set.any? |
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.
elsif @set.any? | |
else |
@@ -195,14 +206,10 @@ | |||
['>=*', '*'], | |||
['', '*'], | |||
['*', '*'], | |||
['*', '*'], |
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.
😆
['~>1', '>=1.0.0 <2.0.0'], | ||
['~> 1', '>=1.0.0 <2.0.0'], | ||
['~>3.2.1', '>=3.2.1 <3.3.0-0'], | ||
['~1', '>=1.0.0 <2.0.0-0'], |
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.
It looks like some of the stuff above was duplicated, but some test cases here are changed. I'd feel more comfortable if the cases were in addition to the existing ones (obviously removing dupes is fine).
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.
@jsonperl As I understand, the existing ones were created in a similar way: copied from node-semver. I assume copy-paste-replace is the only way to keep them in sync with node-semver 🙄
expect(SemanticRange.ltr?('1.0.0-beta', '^1.0.0-alpha')).to eq(false) | ||
expect(SemanticRange.ltr?('1.0.0-beta', '~1.0.0-alpha')).to eq(false) | ||
expect(SemanticRange.ltr?('1.0.0', '=0.1.0')).to eq(false) | ||
[['~ 1.0', '1.1.0'], |
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.
This is pretty tough to grok the changes on, maybe do the cleanup and changes as separate commits?
Notes: