Merge pull request #1029 from sheerun/semver

Ignore prerelease versions if possible, fixes #1017
This commit is contained in:
Mat Scales
2014-01-20 13:52:41 -08:00
2 changed files with 53 additions and 4 deletions

View File

@@ -20,11 +20,11 @@ function maxSatisfying(versions, range, strictMatch) {
}
}
// When strict match is enabled and range is *,
// give priority to non-pre-releases
// We do this by filtering every pre-release version
range = typeof range === 'string' ? range.trim() : range;
if (strictMatch && (!range || range === '*')) {
// When strict match is enabled give priority to non-pre-releases
// We do this by filtering every pre-release version
if (strictMatch) {
filteredVersions = versions.map(function (version) {
return !isPreRelease(version) ? version : null;
});

View File

@@ -481,6 +481,31 @@ describe('GitResolver', function () {
.done();
});
it('should resolve "0.1.*" to the latest version if a repository has valid semver tags, ignoring pre-releases', function (next) {
var resolver;
GitResolver.refs = function () {
return Q.resolve([
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa refs/heads/master',
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb refs/tags/0.1.0',
'cccccccccccccccccccccccccccccccccccccccc refs/tags/v0.1.1',
'dddddddddddddddddddddddddddddddddddddddd refs/tags/0.1.2-rc.1' // Should ignore release candidates
]);
};
resolver = create('foo');
resolver._findResolution('0.1.*')
.then(function (resolution) {
expect(resolution).to.eql({
type: 'version',
tag: 'v0.1.1',
commit: 'cccccccccccccccccccccccccccccccccccccccc'
});
next();
})
.done();
});
it('should resolve "*" to the latest version if a repository has valid semver tags, not ignoring pre-releases if they are the only versions', function (next) {
var resolver;
@@ -505,6 +530,30 @@ describe('GitResolver', function () {
.done();
});
it('should resolve "0.1.*" to the latest version if a repository has valid semver tags, not ignoring pre-releases if they are the only versions', function (next) {
var resolver;
GitResolver.refs = function () {
return Q.resolve([
'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa refs/heads/master',
'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb refs/tags/0.1.0-rc.1',
'cccccccccccccccccccccccccccccccccccccccc refs/tags/0.1.0-rc.2'
]);
};
resolver = create('foo');
resolver._findResolution('0.1.*')
.then(function (resolution) {
expect(resolution).to.eql({
type: 'version',
tag: '0.1.0-rc.2',
commit: 'cccccccccccccccccccccccccccccccccccccccc'
});
next();
})
.done();
});
it('should resolve to the latest version that matches a range/version', function (next) {
var resolver;