Skip to content

Commit

Permalink
Support ranges with an inclusive max version (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
snyamathi authored Aug 7, 2018
1 parent 583536f commit d53c643
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
"pretest": "npm run build",
"test": "jenkins-mocha tests/unit --recursive --compilers js:babel-register"
},
"version": "1.3.1"
"version": "1.4.0"
}
5 changes: 5 additions & 0 deletions src/semver-intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ function createShorthand (range) {
return min;
}

// Stable range with an inclusive max version
if (range.includes('<=')) {
return `${min} - ${max}`;
}

// Special handling for major version 0
if (semver.major(min) === 0 && semver.major(max) === 0) {
// ^0.0.5
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/semver-intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ describe('createShorthand', () => {
const result = createShorthand('>=0.0.0 <0.0.1');
expect(result).to.equal('^0.0.0');
});
it('should simplify a range within the same major version', () => {
const result = createShorthand('>=1.0.0 <=1.5.3');
expect(result).to.equal('1.0.0 - 1.5.3');
});
it('should return granular ranges without changes', () => {
[
'>4.0.0',
Expand Down Expand Up @@ -104,6 +108,10 @@ describe('expandRanges', () => {
const result = expandRanges('>=3.0.0 <4.0.0', '>=3.1.0 <4.0.0', '>=3.3.0');
expect(result).to.deep.equal(['>=3.0.0', '<4.0.0', '>=3.1.0', '>=3.3.0']);
});
it('should expand a range between two versions', () => {
const result = expandRanges('1.0.0 - 1.5.3');
expect(result).to.deep.equal(['>=1.0.0', '<=1.5.3']);
});
});

describe('formatIntersection', () => {
Expand Down Expand Up @@ -183,6 +191,10 @@ 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 simplify issue 12', () => {
const result = intersect('1.0.0 - 1.5.3');
expect(result).to.equal('1.0.0 - 1.5.3');
});
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');
Expand Down

0 comments on commit d53c643

Please sign in to comment.