Skip to content
Snippets Groups Projects
Unverified Commit 7d4de497 authored by Rhys Arkins's avatar Rhys Arkins Committed by GitHub
Browse files

fix(versioning): strip v prefix when bumping semver ranges (#24357)

parent 496bc19a
No related branches found
No related tags found
No related merge requests found
...@@ -131,6 +131,7 @@ describe('modules/versioning/npm/index', () => { ...@@ -131,6 +131,7 @@ describe('modules/versioning/npm/index', () => {
${'^2.3.4'} | ${'replace'} | ${'2.3.4'} | ${'2.3.5'} | ${'^2.3.4'} ${'^2.3.4'} | ${'replace'} | ${'2.3.4'} | ${'2.3.5'} | ${'^2.3.4'}
${'~2.3.4'} | ${'replace'} | ${'2.3.4'} | ${'2.3.5'} | ${'~2.3.0'} ${'~2.3.4'} | ${'replace'} | ${'2.3.4'} | ${'2.3.5'} | ${'~2.3.0'}
${'^0.0.1'} | ${'replace'} | ${'0.0.1'} | ${'0.0.2'} | ${'^0.0.2'} ${'^0.0.1'} | ${'replace'} | ${'0.0.1'} | ${'0.0.2'} | ${'^0.0.2'}
${'^0.0.1'} | ${'replace'} | ${'v0.0.1'} | ${'v0.0.2'} | ${'^0.0.2'}
${'^1.0.1'} | ${'replace'} | ${'1.0.1'} | ${'2.0.2'} | ${'^2.0.0'} ${'^1.0.1'} | ${'replace'} | ${'1.0.1'} | ${'2.0.2'} | ${'^2.0.0'}
${'^1.2.3'} | ${'replace'} | ${'1.2.3'} | ${'1.2.3'} | ${'^1.2.3'} ${'^1.2.3'} | ${'replace'} | ${'1.2.3'} | ${'1.2.3'} | ${'^1.2.3'}
${'^1.2.3'} | ${'replace'} | ${'1.2.3'} | ${'1.2.2'} | ${'^1.2.2'} ${'^1.2.3'} | ${'replace'} | ${'1.2.3'} | ${'1.2.2'} | ${'^1.2.2'}
...@@ -143,6 +144,7 @@ describe('modules/versioning/npm/index', () => { ...@@ -143,6 +144,7 @@ describe('modules/versioning/npm/index', () => {
${'1.x >2.0.0'} | ${'widen'} | ${'1.0.0'} | ${'2.1.0'} | ${null} ${'1.x >2.0.0'} | ${'widen'} | ${'1.0.0'} | ${'2.1.0'} | ${null}
${'^1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'2.0.0'} | ${'^2.0.0'} ${'^1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'2.0.0'} | ${'^2.0.0'}
${'~1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'2.0.0'} | ${'~2.0.0'} ${'~1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'2.0.0'} | ${'~2.0.0'}
${'~1.0.0'} | ${'bump'} | ${'v1.0.0'} | ${'v2.0.0'} | ${'~2.0.0'}
${'>1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'2.1.0'} | ${null} ${'>1.0.0'} | ${'bump'} | ${'1.0.0'} | ${'2.1.0'} | ${null}
${'^1.0.0-alpha'} | ${'replace'} | ${'1.0.0-alpha'} | ${'1.0.0-beta'} | ${'^1.0.0-beta'} ${'^1.0.0-alpha'} | ${'replace'} | ${'1.0.0-alpha'} | ${'1.0.0-beta'} | ${'^1.0.0-beta'}
${'~1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'1.1.0'} | ${'~1.1.0'} ${'~1.0.0'} | ${'replace'} | ${'1.0.0'} | ${'1.1.0'} | ${'~1.1.0'}
...@@ -150,6 +152,7 @@ describe('modules/versioning/npm/index', () => { ...@@ -150,6 +152,7 @@ describe('modules/versioning/npm/index', () => {
${'<=1.0'} | ${'replace'} | ${'1.0.0'} | ${'1.2.0'} | ${'<=1.2'} ${'<=1.0'} | ${'replace'} | ${'1.0.0'} | ${'1.2.0'} | ${'<=1.2'}
${'<=1'} | ${'replace'} | ${'1.0.0'} | ${'2.0.0'} | ${'<=2'} ${'<=1'} | ${'replace'} | ${'1.0.0'} | ${'2.0.0'} | ${'<=2'}
${'<= 1'} | ${'replace'} | ${'1.0.0'} | ${'2.0.0'} | ${'<= 2'} ${'<= 1'} | ${'replace'} | ${'1.0.0'} | ${'2.0.0'} | ${'<= 2'}
${'>=18.17.0'} | ${'bump'} | ${'v18.17.0'} | ${'v18.17.1'} | ${'>=18.17.1'}
`( `(
'getNewValue("$currentValue", "$rangeStrategy", "$currentVersion", "$newVersion") === "$expected"', 'getNewValue("$currentValue", "$rangeStrategy", "$currentVersion", "$newVersion") === "$expected"',
({ currentValue, rangeStrategy, currentVersion, newVersion, expected }) => { ({ currentValue, rangeStrategy, currentVersion, newVersion, expected }) => {
......
...@@ -57,6 +57,10 @@ function replaceCaretValue(oldValue: string, newValue: string): string { ...@@ -57,6 +57,10 @@ function replaceCaretValue(oldValue: string, newValue: string): string {
return needReplace ? resultTuple.join('.') : oldValue; return needReplace ? resultTuple.join('.') : oldValue;
} }
function stripV(value: string): string {
return value.replace(/^v/, '');
}
// TODO: #22198 // TODO: #22198
export function getNewValue({ export function getNewValue({
currentValue, currentValue,
...@@ -136,18 +140,18 @@ export function getNewValue({ ...@@ -136,18 +140,18 @@ export function getNewValue({
}); });
} }
if (element.operator === '^') { if (element.operator === '^') {
return `^${newVersion}`; return `^${stripV(newVersion)}`;
} }
if (element.operator === '~') { if (element.operator === '~') {
return `~${newVersion}`; return `~${stripV(newVersion)}`;
} }
if (element.operator === '=') { if (element.operator === '=') {
return `=${newVersion}`; return `=${stripV(newVersion)}`;
} }
if (element.operator === '>=') { if (element.operator === '>=') {
return currentValue.includes('>= ') return currentValue.includes('>= ')
? `>= ${newVersion}` ? `>= ${stripV(newVersion)}`
: `>=${newVersion}`; : `>=${stripV(newVersion)}`;
} }
if (element.operator.startsWith('<')) { if (element.operator.startsWith('<')) {
return currentValue; return currentValue;
...@@ -193,7 +197,7 @@ export function getNewValue({ ...@@ -193,7 +197,7 @@ export function getNewValue({
return `^${replaceCaretValue(currentVersion, newVersion)}`; return `^${replaceCaretValue(currentVersion, newVersion)}`;
} }
if (element.operator === '=') { if (element.operator === '=') {
return `=${newVersion}`; return `=${stripV(newVersion)}`;
} }
if (element.operator === '~') { if (element.operator === '~') {
if (suffix.length) { if (suffix.length) {
...@@ -204,7 +208,7 @@ export function getNewValue({ ...@@ -204,7 +208,7 @@ export function getNewValue({
if (element.operator === '<=') { if (element.operator === '<=') {
let res; let res;
if (!!element.patch || suffix.length) { if (!!element.patch || suffix.length) {
res = `<=${newVersion}`; res = `<=${stripV(newVersion)}`;
} else if (element.minor) { } else if (element.minor) {
res = `<=${toVersionMajor}.${toVersionMinor}`; res = `<=${toVersionMajor}.${toVersionMinor}`;
} else { } else {
......
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