Skip to content

Commit

Permalink
Fix bug with 0.x simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
Suneil Nyamathi committed Jul 19, 2017
1 parent afbe592 commit facff56
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
"lint": "eslint .",
"test": "jenkins-mocha tests/unit --recursive"
},
"version": "1.1.1"
"version": "1.1.2"
}
4 changes: 4 additions & 0 deletions semver-intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ function createShorthand (range) {
}

if (semver.major(min) !== semver.major(max)) {
if (semver.major(min) === 0) {
return '0';
}

return `^${min}`;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/unit/semver-intersect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const expect = require('chai').expect;
const semver = require('semver');
const {
createShorthand,
ensureCompatible,
Expand Down Expand Up @@ -43,6 +44,14 @@ describe('createShorthand', () => {
const result = createShorthand('>=0.0.5 <0.1.0');
expect(result).to.equal('~0.0.5');
});
it('should simplify 0.x', () => {
const result = createShorthand('>=0.0.0 <1.0.0');
expect(result).to.equal('0');
});
it('should simplify ~0.0.x', () => {
const result = createShorthand('>=0.0.0 <0.1.0');
expect(result).to.equal('~0.0.0');
});
it('should simplify to ~0.0.0', () => {
const result = createShorthand('>=0.0.0 <0.1.0');
expect(result).to.equal('~0.0.0');
Expand Down

0 comments on commit facff56

Please sign in to comment.