fix(cargo): handle * getNewValue

This commit is contained in:
Rhys Arkins 2020-04-27 09:57:02 +02:00
parent 2bc36adcdb
commit 6bb76c53b6
2 changed files with 34 additions and 0 deletions

View file

@ -103,6 +103,24 @@ describe('semver.isSingleVersion()', () => {
});
});
describe('semver.getNewValue()', () => {
it('returns if empty or *', () => {
expect(
semver.getNewValue({
currentValue: null,
rangeStrategy: 'bump',
fromVersion: '1.0.0',
toVersion: '1.1.0',
})
).toEqual(null);
expect(
semver.getNewValue({
currentValue: '*',
rangeStrategy: 'bump',
fromVersion: '1.0.0',
toVersion: '1.1.0',
})
).toEqual('*');
});
it('bumps equals', () => {
expect(
semver.getNewValue({

View file

@ -1,5 +1,6 @@
import { api as npm } from '../npm';
import { VersioningApi, NewValueConfig } from '../common';
import { logger } from '../../logger';
export const id = 'cargo';
export const displayName = 'Cargo';
@ -33,6 +34,10 @@ function notEmpty(s: string): boolean {
}
function npm2cargo(input: string): string {
// istanbul ignore if
if (!input) {
return input;
}
// Note: this doesn't remove the ^
const res = input
.split(' ')
@ -73,6 +78,9 @@ function getNewValue({
fromVersion,
toVersion,
}: NewValueConfig): string {
if (!currentValue || currentValue === '*') {
return currentValue;
}
if (rangeStrategy === 'pin' || isSingleVersion(currentValue)) {
let res = '=';
if (currentValue.startsWith('= ')) {
@ -88,6 +96,14 @@ function getNewValue({
toVersion,
});
let newCargo = npm2cargo(newSemver);
// istanbul ignore if
if (!newCargo) {
logger.info(
{ currentValue, newSemver },
'Could not get cargo version from semver'
);
return currentValue;
}
// Try to reverse any caret we added
if (newCargo.startsWith('^') && !currentValue.startsWith('^')) {
newCargo = newCargo.substring(1);