From 48208473ef40cbd4d80c99cb5095ab0c36408e0c Mon Sep 17 00:00:00 2001 From: Suneil Nyamathi Date: Mon, 19 Feb 2018 23:47:06 -0800 Subject: [PATCH] Fix totally exclusive ranges (#8) --- src/semver-intersect.js | 6 +++++- tests/unit/semver-intersect.js | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/semver-intersect.js b/src/semver-intersect.js index e15997a..17ce818 100644 --- a/src/semver-intersect.js +++ b/src/semver-intersect.js @@ -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; } diff --git a/tests/unit/semver-intersect.js b/tests/unit/semver-intersect.js index c5a28dc..d68b56a 100644 --- a/tests/unit/semver-intersect.js +++ b/tests/unit/semver-intersect.js @@ -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', () => {