Skip to content
Snippets Groups Projects
Commit 781a929d authored by Sergio Zharinov's avatar Sergio Zharinov Committed by Rhys Arkins
Browse files

feat(maven): Support for pin strategy (#4127)

parent 71ade226
No related branches found
No related tags found
No related merge requests found
......@@ -102,13 +102,21 @@ const isStable = version => {
return null;
};
const maxSatisfyingVersion = (versions, range) =>
versions.find(version => matches(version, range));
const maxSatisfyingVersion = (versions, range) => {
return versions.reduce((result, version) => {
if (matches(version, range)) {
if (!result) return version;
if (isGreaterThan(version, result)) return version;
}
return result;
}, null);
};
function getNewValue(currentValue, rangeStrategy, fromVersion, toVersion) {
return isVersion(currentValue)
? toVersion
: autoExtendMavenRange(currentValue, toVersion);
if (isVersion(currentValue) || rangeStrategy === 'pin') {
return toVersion;
}
return autoExtendMavenRange(currentValue, toVersion);
}
module.exports = {
......
......@@ -12,6 +12,7 @@ const {
getMinor,
getPatch,
matches,
getNewValue,
} = require('../../lib/versioning/maven/index');
describe('versioning/maven/compare', () => {
......@@ -326,4 +327,24 @@ describe('versioning/maven/index', () => {
expect(matches('1.0.0.RC9.2', '(,1.0.0.RC9.2),(1.0.0.RC9.2,)')).toBe(false);
expect(matches('1.0.0-RC14', '(,1.0.0.RC9.2),(1.0.0.RC9.2,)')).toBe(true);
});
it('pins maven ranges', () => {
const sample = [
['[1.2.3]', '1.2.3', '1.2.4'],
['[1.0.0,1.2.3]', '1.0.0', '1.2.4'],
['[1.0.0,1.2.23]', '1.0.0', '1.2.23'],
['(,1.0]', '0.0.1', '2.0'],
['],1.0]', '0.0.1', '2.0'],
['(,1.0)', '0.1', '2.0'],
['],1.0[', '2.0', '],2.0['],
['[1.0,1.2],[1.3,1.5)', '1.0', '1.2.4'],
['[1.0,1.2],[1.3,1.5[', '1.0', '1.2.4'],
['[1.2.3,)', '1.2.3', '1.2.4'],
['[1.2.3,[', '1.2.3', '1.2.4'],
];
sample.forEach(([currentValue, fromVersion, toVersion]) => {
expect(getNewValue(currentValue, 'pin', fromVersion, toVersion)).toEqual(
toVersion
);
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment