1
0
Fork 0

Add support for bumping >=x to >=latest, fixes #11179

pull/11218/head
Jordi Boggiano 2022-12-17 22:58:35 +01:00
parent 7f9638f65a
commit ef7ba73a6a
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 13 additions and 3 deletions

View File

@ -71,7 +71,8 @@ class VersionBumper
} }
$major = Preg::replace('{^(\d+).*}', '$1', $version); $major = Preg::replace('{^(\d+).*}', '$1', $version);
$newPrettyConstraint = '^'.Preg::replace('{(?:\.(?:0|9999999))+(-dev)?$}', '', $version); $versionWithoutSuffix = Preg::replace('{(?:\.(?:0|9999999))+(-dev)?$}', '', $version);
$newPrettyConstraint = '^'.$versionWithoutSuffix;
// not a simple stable version, abort // not a simple stable version, abort
if (!Preg::isMatch('{^\^\d+(\.\d+)*$}', $newPrettyConstraint)) { if (!Preg::isMatch('{^\^\d+(\.\d+)*$}', $newPrettyConstraint)) {
@ -84,17 +85,24 @@ class VersionBumper
\^'.$major.'(?:\.\d+)* # e.g. ^2.anything \^'.$major.'(?:\.\d+)* # e.g. ^2.anything
| ~'.$major.'(?:\.\d+)? # e.g. ~2 or ~2.2 but no more | ~'.$major.'(?:\.\d+)? # e.g. ~2 or ~2.2 but no more
| '.$major.'(?:\.[*x])+ # e.g. 2.* or 2.*.* or 2.x.x.x etc | '.$major.'(?:\.[*x])+ # e.g. 2.* or 2.*.* or 2.x.x.x etc
| >=\d(?:\.\d+)* # e.g. >=2 or >=1.2 etc
) )
(?=,|$|\ |\||@) # trailing separator (?=,|$|\ |\||@) # trailing separator
}x'; }x';
if (Preg::isMatchAllWithOffsets($pattern, $prettyConstraint, $matches)) { if (Preg::isMatchAllWithOffsets($pattern, $prettyConstraint, $matches)) {
$modified = $prettyConstraint; $modified = $prettyConstraint;
foreach (array_reverse($matches['constraint']) as $match) { foreach (array_reverse($matches['constraint']) as $match) {
assert(is_string($match[0]));
$suffix = ''; $suffix = '';
if (substr_count($match[0], '.') === 2 && substr_count($newPrettyConstraint, '.') === 1) { if (substr_count($match[0], '.') === 2 && substr_count($versionWithoutSuffix, '.') === 1) {
$suffix = '.0'; $suffix = '.0';
} }
$modified = substr_replace($modified, $newPrettyConstraint.$suffix, $match[1], Platform::strlen((string) $match[0])); if (str_starts_with($match[0], '>=')) {
$replacement = '>='.$versionWithoutSuffix.$suffix;
} else {
$replacement = $newPrettyConstraint.$suffix;
}
$modified = substr_replace($modified, $replacement, $match[1], Platform::strlen($match[0]));
} }
// if it is strictly equal to the previous one then no need to change anything // if it is strictly equal to the previous one then no need to change anything

View File

@ -64,5 +64,7 @@ class VersionBumperTest extends TestCase
yield 'leave patch wildcard alone' => ['2.4.3.*', '2.4.3.2', '2.4.3.*']; yield 'leave patch wildcard alone' => ['2.4.3.*', '2.4.3.2', '2.4.3.*'];
yield 'upgrade tilde to caret when compatible' => ['~2.2', '2.4.3', '^2.4.3']; yield 'upgrade tilde to caret when compatible' => ['~2.2', '2.4.3', '^2.4.3'];
yield 'leave patch-only-tilde alone' => ['~2.2.3', '2.2.6', '~2.2.3']; yield 'leave patch-only-tilde alone' => ['~2.2.3', '2.2.6', '~2.2.3'];
yield 'upgrade bigger-or-eq to latest' => ['>=3.0', '3.4.5', '>=3.4.5'];
yield 'leave bigger-than untouched' => ['>2.2.3', '2.2.6', '>2.2.3'];
} }
} }