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

include_prerelease option #76

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pustomytnyk
Copy link
Contributor

@pustomytnyk pustomytnyk commented Mar 6, 2021

Notes:

  • copied current node-semver behavior (including npm/node-semver@059a5ad I have no idea what does that mean).
  • platform-dependent (Rubygems) specs changed too, you need to check if it breaks anything
  • not sure if it make sense to use keyword arguments (gives argument validation) or hash (easier to pass)

@pustomytnyk pustomytnyk marked this pull request as ready for review March 26, 2021 19:02
@pustomytnyk
Copy link
Contributor Author

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
Copy link
Contributor Author

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)
Copy link
Contributor Author

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?
Copy link
Contributor Author

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'],
Copy link
Contributor Author

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?
Copy link
Contributor

@jsonperl jsonperl Apr 7, 2021

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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
first = set.first
first = @set.first

@set = @set.reject { |c| is_null_set(c[0]) }
if @set.empty?
@set = [first]
elsif @set.any?
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
elsif @set.any?
else

@@ -195,14 +206,10 @@
['>=*', '*'],
['', '*'],
['*', '*'],
['*', '*'],
Copy link
Contributor

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'],
Copy link
Contributor

@jsonperl jsonperl Apr 7, 2021

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).

Copy link
Contributor Author

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'],
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants