Skip to content

Commit

Permalink
Ensure "dev" prefix and suffix is used correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed Jan 2, 2024
1 parent d629e29 commit c7c706e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
31 changes: 31 additions & 0 deletions src/Vendor/Composer/VersionConstraintNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private function normalizeVersionConstraint(string $versionConstraint): string
{
$versionConstraint = self::normalizeVersionConstraintSeparators($versionConstraint);
$versionConstraint = self::removeLeadingVersionPrefix($versionConstraint);
$versionConstraint = self::assertDevPrefixSuffixPosition($versionConstraint);
$versionConstraint = self::replaceWildcardWithTilde($versionConstraint);
$versionConstraint = self::replaceTildeWithCaret($versionConstraint);
$versionConstraint = self::removeDuplicateVersionConstraints($versionConstraint);
Expand Down Expand Up @@ -191,6 +192,36 @@ private static function removeLeadingVersionPrefix(string $versionConstraint): s
);
}

private static function assertDevPrefixSuffixPosition(string $versionConstraint): string
{
$split = \explode(
' ',
$versionConstraint,
);

foreach ($split as &$part) {
if (\str_starts_with($part, 'dev-')) {
$branch = \substr($part, 4);
} elseif (\str_ends_with($part, '-dev')) {
$branch = \substr($part, 0, -4);
} else {
continue;
}

// @see https://github.com/composer/semver/blob/3.4.0/src/VersionParser.php#L216
if (\preg_match('{^v?\d+(\.(?:\d+|[xX*]))?(\.(?:\d+|[xX*]))?(\.(?:\d+|[xX*]))?$}i', $branch)) {
$part = $branch . '-dev';
} else {
$part = 'dev-' . $branch;
}
}

return \implode(
' ',
$split,
);
}

private static function removeOverlappingVersionConstraints(string $versionConstraint): string
{
$orConstraints = self::splitIntoOrConstraints($versionConstraint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
"branch/03-main-referencing-commit-trimmed": "dev-main#bf2eeff",
"branch/04-main-referencing-commit-untrimmed": "dev-main#bf2eeff",
"branch/05-my-feature-trimmed": "dev-my-feature",
"branch/06-my-feature-untrimmed": "dev-my-feature"
"branch/06-my-feature-untrimmed": "dev-my-feature",
"branch/07-main-suffix": "dev-main",
"branch/08-numeric-branch-lower-suffix-major": "1.x-dev",
"branch/09-numeric-branch-lower-suffix-major-minor": "1.2.x-dev",
"branch/10-numeric-branch-lower-prefix-major": "1.x-dev",
"branch/11-numeric-branch-lower-prefix-major-minor": "1.2.x-dev",
"branch/12-numeric-branch-upper-suffix-major": "1.X-dev",
"branch/13-numeric-branch-upper-suffix-major-minor": "1.2.X-dev",
"branch/14-numeric-branch-upper-prefix-major": "1.X-dev",
"branch/15-numeric-branch-upper-prefix-major-minor": "1.2.X-dev",
"branch/16-numeric-branch-starts-with-v-lower-suffix-major": "v1.x-dev",
"branch/17-numeric-branch-starts-with-v-lower-suffix-major-minor": "v1.2.x-dev",
"branch/18-numeric-branch-starts-with-v-lower-prefix-major": "v1.x-dev",
"branch/19-numeric-branch-starts-with-v-lower-prefix-major-minor": "v1.2.x-dev",
"branch/20-numeric-branch-starts-with-v-upper-suffix-major": "v1.X-dev",
"branch/21-numeric-branch-starts-with-v-upper-suffix-major-minor": "v1.2.X-dev",
"branch/22-numeric-branch-starts-with-v-upper-prefix-major": "v1.X-dev",
"branch/23-numeric-branch-starts-with-v-upper-prefix-major-minor": "v1.2.X-dev"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@
"branch/03-main-referencing-commit-trimmed": "dev-main#bf2eeff",
"branch/04-main-referencing-commit-untrimmed": " dev-main#bf2eeff ",
"branch/05-my-feature-trimmed": "dev-my-feature",
"branch/06-my-feature-untrimmed": " dev-my-feature "
"branch/06-my-feature-untrimmed": " dev-my-feature ",
"branch/07-main-suffix": "main-dev",
"branch/08-numeric-branch-lower-suffix-major": "1.x-dev",
"branch/09-numeric-branch-lower-suffix-major-minor": "1.2.x-dev",
"branch/10-numeric-branch-lower-prefix-major": "dev-1.x",
"branch/11-numeric-branch-lower-prefix-major-minor": "dev-1.2.x",
"branch/12-numeric-branch-upper-suffix-major": "1.X-dev",
"branch/13-numeric-branch-upper-suffix-major-minor": "1.2.X-dev",
"branch/14-numeric-branch-upper-prefix-major": "dev-1.X",
"branch/15-numeric-branch-upper-prefix-major-minor": "dev-1.2.X",
"branch/16-numeric-branch-starts-with-v-lower-suffix-major": "v1.x-dev",
"branch/17-numeric-branch-starts-with-v-lower-suffix-major-minor": "v1.2.x-dev",
"branch/18-numeric-branch-starts-with-v-lower-prefix-major": "dev-v1.x",
"branch/19-numeric-branch-starts-with-v-lower-prefix-major-minor": "dev-v1.2.x",
"branch/20-numeric-branch-starts-with-v-upper-suffix-major": "v1.X-dev",
"branch/21-numeric-branch-starts-with-v-upper-suffix-major-minor": "v1.2.X-dev",
"branch/22-numeric-branch-starts-with-v-upper-prefix-major": "dev-v1.X",
"branch/23-numeric-branch-starts-with-v-upper-prefix-major-minor": "dev-v1.2.X"
}
}

0 comments on commit c7c706e

Please sign in to comment.