Skip to content

Commit

Permalink
^0.x.y always equivalent to =0.x.y
Browse files Browse the repository at this point in the history
More in line with specification at http://semver.org
  • Loading branch information
isaacs committed Jul 23, 2014
1 parent 87bcf74 commit 3f676f5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 31 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ The following range styles are supported:
prerelease) will be supported up to, but not including, the next
major version (or its prereleases). `1.5.1` will satisfy `^1.2.3`,
while `1.2.2` and `2.0.0-beta` will not.
* `^0.1.3` := `>=0.1.3-0 <0.2.0-0` "Compatible with `0.1.3`". `0.x.x` versions are
special: the first non-zero component indicates potentially breaking changes,
meaning the caret operator matches any version with the same first non-zero
component starting at the specified version.
* `^0.0.2` := `=0.0.2` "Only the version `0.0.2` is considered compatible"
* `^0.1.3` := `0.1.3` "Compatible with `0.1.3`". `0.x.x` versions are
special: since the semver spec specifies that `0.x.x` versions make
no stability guarantees, only the version specified is considered
valid.
* `^0.0.2` := `0.0.2` "Only the version `0.0.2` is considered compatible"
* `~1.2` := `>=1.2.0-0 <1.3.0-0` "Any version starting with `1.2`"
* `^1.2` := `>=1.2.0-0 <2.0.0-0` "Any version compatible with `1.2`"
* `1.2.x` := `>=1.2.0-0 <1.3.0-0` "Any version starting with `1.2`"
Expand Down
39 changes: 14 additions & 25 deletions semver.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ SemVer.prototype.inc = function(release) {
// If this is already a prerelease, it will bump to the next version
// drop any prereleases that might already exist, since they are not
// relevant at this point.
this.prerelease.length = 0
this.prerelease.length = 0;
this.inc('patch');
this.inc('pre');
break;
Expand Down Expand Up @@ -770,6 +770,11 @@ function replaceCaret(comp, loose) {
return comp.replace(r, function(_, M, m, p, pr) {
debug('caret', comp, _, M, m, p, pr);
var ret;
if (pr) {
if (pr.charAt(0) !== '-')
pr = '-' + pr;
} else
pr = '';

if (isX(M))
ret = '';
Expand All @@ -780,30 +785,14 @@ function replaceCaret(comp, loose) {
ret = '>=' + M + '.' + m + '.0-0 <' + M + '.' + (+m + 1) + '.0-0';
else
ret = '>=' + M + '.' + m + '.0-0 <' + (+M + 1) + '.0.0-0';
} else if (pr) {
debug('replaceCaret pr', pr);
if (pr.charAt(0) !== '-')
pr = '-' + pr;
if (M === '0') {
if (m === '0')
ret = '=' + M + '.' + m + '.' + p + pr;
else
ret = '>=' + M + '.' + m + '.' + p + pr +
' <' + M + '.' + (+m + 1) + '.0-0';
} else
ret = '>=' + M + '.' + m + '.' + p + pr +
' <' + (+M + 1) + '.0.0-0';
} else {
if (M === '0') {
if (m === '0')
ret = '=' + M + '.' + m + '.' + p;
else
ret = '>=' + M + '.' + m + '.' + p + '-0' +
' <' + M + '.' + (+m + 1) + '.0-0';
} else
ret = '>=' + M + '.' + m + '.' + p + '-0' +
' <' + (+M + 1) + '.0.0-0';
}
} else if (M === '0')
ret = '=' + M + '.' + m + '.' + p + pr;
else if (pr)
ret = '>=' + M + '.' + m + '.' + p + pr +
' <' + (+M + 1) + '.0.0-0';
else
ret = '>=' + M + '.' + m + '.' + p + '-0' +
' <' + (+M + 1) + '.0.0-0';

debug('caret return', ret);
return ret;
Expand Down
2 changes: 1 addition & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ test('\nvalid range test', function(t) {
['^1.2', '>=1.2.0-0 <2.0.0-0'],
['^0.0.1', '0.0.1'],
['^0.0.1-beta', '0.0.1-beta'],
['^0.1.2', '>=0.1.2-0 <0.2.0-0'],
['^0.1.2', '0.1.2'],
['^1.2.3', '>=1.2.3-0 <2.0.0-0'],
['^1.2.3-beta.4', '>=1.2.3-beta.4 <2.0.0-0'],
['<1', '<1.0.0-0'],
Expand Down

3 comments on commit 3f676f5

@dylang
Copy link

@dylang dylang commented on 3f676f5 Jul 23, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screen shot 2014-07-23 at 5 27 14 pm

@voxpelli
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saw that this version of semver is used in npm 2.x – which results in eg. many sites using Grunt devDependencies breaking as some big Grunt packages moved to ^0.4.0 for their Grunt peerDependency (like grunt-contrib-uglify) when ^ was introduced rather than keeping with ~0.4.0.

Broken peer dependencies means that eg. all npm install attempts will fail – even when trying to install new unrelated dependencies.

Therefore this change needs to be very clearly documented and communicated – eg in the release notes of npm 2.x – so that the affected packages can update their dependencies to this more strict standard.

@isaacs
Copy link
Contributor Author

@isaacs isaacs commented on 3f676f5 Jul 25, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please post comments on #92 instead of here? Commit comments are less likely to be seen by as many people.

Please sign in to comment.