Skip to content

Commit

Permalink
Fix totally exclusive ranges (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
snyamathi authored Feb 20, 2018
1 parent 31056c5 commit 4820847
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/semver-intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ function ensureCompatible(range, ...bounds) {
const { prerelease, version } = parseRange(range);

bounds.forEach(bound => {
if (!bound || semver.satisfies(version, bound)) {
if (!bound) {
return;
}

if (semver.satisfies(version, bound) && semver.intersects(range, bound)) {
return;
}

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/semver-intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@ describe('intersect', () => {
const call = intersect.bind(null, '^4.0.0', '~4.3.0', '^4.4.0');
expect(call).to.throw('Range >=4.4.0 is not compatible with <4.4.0');
});
it('should not cross major bounds', () => {
expect(intersect.bind(null, '^5.0.0', '^4.0.1'))
.to.throw('Range <5.0.0 is not compatible with >=5.0.0');
expect(intersect.bind(null, '^5.0.0', '^3.0.0'))
.to.throw('Range <4.0.0 is not compatible with >=5.0.0');
expect(intersect.bind(null, '~5.1.0', '~5.2.0'))
.to.throw('Range >=5.2.0 is not compatible with <5.2.0');
expect(intersect.bind(null, '^0.5.0', '^0.4.0'))
.to.throw('Range <0.5.0 is not compatible with >=0.5.0');
});
});

describe('mergeBounds', () => {
Expand Down

0 comments on commit 4820847

Please sign in to comment.