Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: npm/node-semver
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v5.7.0
Choose a base ref
...
head repository: npm/node-semver
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v6.0.0
Choose a head ref
  • 5 commits
  • 5 files changed
  • 2 contributors

Commits on Mar 26, 2019

  1. fix: Fix Range intersects algorithm

    Max Bittman authored and isaacs committed Mar 26, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    isaacs isaacs
    Copy the full SHA
    8473d65 View commit details
  2. fix: Fix non-satisfiable ranges so they no longer intersect with anyt…

    …hing
    Max Bittman authored and isaacs committed Mar 26, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    isaacs isaacs
    Copy the full SHA
    9b8e961 View commit details
  3. fix: Improve performance of isSatisfiable function

    Max Bittman authored and isaacs committed Mar 26, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    isaacs isaacs
    Copy the full SHA
    673e820 View commit details
  4. changelog for v6

    isaacs committed Mar 26, 2019
    1

    Verified

    This commit was signed with the committer’s verified signature.
    isaacs isaacs
    Copy the full SHA
    3e1d016 View commit details
  5. 6.0.0

    isaacs committed Mar 26, 2019
    2

    Verified

    This commit was signed with the committer’s verified signature.
    isaacs isaacs
    Copy the full SHA
    5fb517b View commit details
Showing with 49 additions and 10 deletions.
  1. +8 −0 CHANGELOG.md
  2. +1 −1 package-lock.json
  3. +1 −1 package.json
  4. +30 −6 semver.js
  5. +9 −2 test/index.js
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# changes log

## 6.0

* Fix `intersects` logic.

This is technically a bug fix, but since it is also a change to behavior
that may require users updating their code, it is marked as a major
version increment.

## 5.7

* Add `minVersion` method
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "semver",
"version": "5.7.0",
"version": "6.0.0",
"description": "The semantic version parser used by npm.",
"main": "semver.js",
"scripts": {
36 changes: 30 additions & 6 deletions semver.js
Original file line number Diff line number Diff line change
@@ -934,16 +934,40 @@ Range.prototype.intersects = function (range, options) {
}

return this.set.some(function (thisComparators) {
return thisComparators.every(function (thisComparator) {
return range.set.some(function (rangeComparators) {
return rangeComparators.every(function (rangeComparator) {
return thisComparator.intersects(rangeComparator, options)
})
return (
isSatisfiable(thisComparators, options) &&
range.set.some(function (rangeComparators) {
return (
isSatisfiable(rangeComparators, options) &&
thisComparators.every(function (thisComparator) {
return rangeComparators.every(function (rangeComparator) {
return thisComparator.intersects(rangeComparator, options)
})
})
)
})
})
)
})
}

// take a set of comparators and determine whether there
// exists a version which can satisfy it
function isSatisfiable (comparators, options) {
var result = true
var remainingComparators = comparators.slice()
var testComparator = remainingComparators.pop()

while (result && remainingComparators.length) {
result = remainingComparators.every(function (otherComparator) {
return testComparator.intersects(otherComparator, options)
})

testComparator = remainingComparators.pop()
}

return result
}

// Mostly just for testing and legacy API reasons
exports.toComparators = toComparators
function toComparators (range, options) {
11 changes: 9 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -875,12 +875,19 @@ test('missing comparator parameter in intersect comparators', function (t) {
test('ranges intersect', function (t) {
[
['1.3.0 || <1.0.0 >2.0.0', '1.3.0 || <1.0.0 >2.0.0', true],
['<1.0.0 >2.0.0', '>0.0.0', true],
['<1.0.0 >2.0.0', '>0.0.0', false],
['>0.0.0', '<1.0.0 >2.0.0', false],
['<1.0.0 >2.0.0', '>1.4.0 <1.6.0', false],
['<1.0.0 >2.0.0', '>1.4.0 <1.6.0 || 2.0.0', false],
['>1.0.0 <=2.0.0', '2.0.0', true],
['<1.0.0 >=2.0.0', '2.1.0', false],
['<1.0.0 >=2.0.0', '>1.4.0 <1.6.0 || 2.0.0', false]
['<1.0.0 >=2.0.0', '>1.4.0 <1.6.0 || 2.0.0', false],
['1.5.x', '<1.5.0 || >=1.6.0', false],
['<1.5.0 || >=1.6.0', '1.5.x', false],
['<1.6.16 || >=1.7.0 <1.7.11 || >=1.8.0 <1.8.2', '>=1.6.16 <1.7.0 || >=1.7.11 <1.8.0 || >=1.8.2', false],
['<=1.6.16 || >=1.7.0 <1.7.11 || >=1.8.0 <1.8.2', '>=1.6.16 <1.7.0 || >=1.7.11 <1.8.0 || >=1.8.2', true],
['>=1.0.0', '<=1.0.0', true],
['>1.0.0 <1.0.0', '<=0.0.0', false]
].forEach(function (v) {
var range1 = new Range(v[0])
var range2 = new Range(v[1])