Skip to content

Commit

Permalink
Add special handling for major version 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Suneil Nyamathi committed Jun 19, 2017
1 parent c45c1e6 commit 7982702
Show file tree
Hide file tree
Showing 3 changed files with 38 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.0.0"
"version": "1.1.0"
}
17 changes: 17 additions & 0 deletions semver-intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ function createShorthand (range) {
}

const [ min, max ] = match.slice(1);

// Special handling for major version 0
if (semver.major(min) === 0 && semver.major(max) === 0) {
// ^0.0.5
if (semver.minor(min) === 0 && semver.minor(max) === 0) {
return `^${min}`;
}

// ~0.0.5
if (semver.minor(min) === 0) {
return `~${min}`;
}

// ^0.5.0
return `^${min}`;
}

if (semver.major(min) !== semver.major(max)) {
return `^${min}`;
}
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/semver-intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ describe('createShorthand', () => {
const result = createShorthand('>=4.0.0-beta.1 <4.1.0');
expect(result).to.equal('~4.0.0-beta.1');
});
it('should simplify 0.14.x to ~0.14.0', () => {
const result = createShorthand('>=0.14.0 <0.15.0');
expect(result).to.equal('^0.14.0');
});
it('should simplify ^0.0.5', () => {
const result = createShorthand('>=0.0.5 <0.0.6');
expect(result).to.equal('^0.0.5');
});
it('should simplify ~0.0.5', () => {
const result = createShorthand('>=0.0.5 <0.1.0');
expect(result).to.equal('~0.0.5');
});
it('should simplify to ~0.0.0', () => {
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.0.1');
expect(result).to.equal('^0.0.0');
});
it('should return granular ranges without changes', () => {
[
'>4.0.0',
Expand Down

0 comments on commit 7982702

Please sign in to comment.