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

fix(subset): check any as superset #375

Closed
wants to merge 1 commit into from
Closed

fix(subset): check any as superset #375

wants to merge 1 commit into from

Conversation

jameschensmith
Copy link
Contributor

Summary

Adds short-circuit check if superset is *. This is currently not handled. A non-range semver has been able to get passed this not existing, but ranges came back falsey. This request addresses that shortcoming.

References

Fixes #374.

Adds short-circuit check if superset is `*`.
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 1e625f0 on jameschensmith:jameschensmith/subset-check-any-as-superset into 093b40f on npm:master.

@jameschensmith
Copy link
Contributor Author

@isaacs, when you get a chance could you take a look at this request? If there's any concerns, I'll do my best to address them ASAP. The request for arborist in the References section of this request has a dependency on this being merged. Both of these would also resolve npm/cli#636 (and possibly its referenced tickets as well), so this has potential to resolve a ton of issues for users. Thank you!

Copy link
Contributor

@isaacs isaacs left a comment

Choose a reason for hiding this comment

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

The suggested short-circuit path can only be applied when the includePrerelease flag is set. Otherwise, it returns an incorrect result if the first range includes a prerelease on any of its versions.

// everything is a subset of *
['1.2.3', '*', true],
['^1.2.3', '*', true],
['^1.2.3-pre.0', '*', true],
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 incorrect, though. ^1.2.3-pre.0 is not a subset of * unless includePrerelease is set, because there are versions that satisfy ^1.2.3-pre.0 and do not satisfy *.

> semver.satisfies('1.2.3-pre.0', '^1.2.3-pre.0')
true
> semver.satisfies('1.2.3-pre.0', '*')
false

@isaacs
Copy link
Contributor

isaacs commented Mar 22, 2021

Ah, ok, this is a bug though:

> semver.subset('^1.2.3', '*')
false

I think we need special handling of <1.2.3-0, since that range doesn't include prereleases, maybe?

@isaacs
Copy link
Contributor

isaacs commented Mar 22, 2021

Ahh! This was already a problem, turns out!

> require('./').subset('^1.2.3-pre.0', '>=1')
true

That should return false in non-prerelease mode, because the first set includes 1.2.3-pre.0 and up prereleases, and the second doesn't include any prereleases.

Ok, so the solution looks like this I think:

// - If c is only the ANY comparator
//   - If C is only the ANY comparator, return true
//   - Else return false
// - If C is only the ANY comparator
//   - if in prerelease mode, return true
//   - else replace C with `[>=0.0.0]`
// ... rest of the algorithm
// - handle any prerelease ranges in c, ensuring that they don't pull in prereleases not in C

@isaacs
Copy link
Contributor

isaacs commented Mar 22, 2021

This is also a bug:

> require('./').subset('*', '>=0.0.0-pre.0')
false

Because (in non-prerelease mode) >=0.0.0-pre.0 includes all versions that could possibly match * as well as any versions from 0.0.0-pre.0 through 0.0.1, it should be a superset of *. So that first bit should be:

// - If c is only the ANY comparator
//   - If C is only the ANY comparator, return true
//   - Else if in prerelease mode, return false
//   - else replace c with `[>=0.0.0]`

@jameschensmith
Copy link
Contributor Author

Woah! Thanks for your great feedback! I had no idea about the pre-release matching, but it makes sense 😊 I see you set up another PR, requesting my review, so I'll check that out now. Thanks! 👍

@isaacs isaacs closed this in 15ed208 Mar 23, 2021
@isaacs
Copy link
Contributor

isaacs commented Mar 23, 2021

This is landed in #377.

Thanks for bringing up the issue! Was a pretty significant oversight, which didn't matter until Arborist started making this method load-bearing 😬

@jameschensmith jameschensmith deleted the jameschensmith/subset-check-any-as-superset branch March 23, 2021 01:50
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.

[BUG] Invalid falsey response when checking range is subset of any
3 participants