Skip to content
Snippets Groups Projects
Commit 6bb76c53 authored by Rhys Arkins's avatar Rhys Arkins
Browse files

fix(cargo): handle * getNewValue

parent 2bc36adc
No related branches found
No related tags found
No related merge requests found
......@@ -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({
......
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);
......
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