Skip to content

[AssetMapper] fix npm version constraint conversion #57321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static function convertNpmConstraint(string $versionConstraint): ?string
if (str_contains($segment, '-') && !preg_match('/-(alpha|beta|rc)\./', $segment)) {
// This is a range
[$start, $end] = explode('-', $segment);
$processedSegments[] = '>='.self::cleanVersionSegment(trim($start)).' <='.self::cleanVersionSegment(trim($end));
$processedSegments[] = self::cleanVersionSegment(trim($start)).' - '.self::cleanVersionSegment(trim($end));
} elseif (preg_match('/^~(\d+\.\d+)$/', $segment, $matches)) {
// Handle the tilde when only major.minor specified
$baseVersion = $matches[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,26 @@ public static function getCheckVersionsTests()
new PackageVersionProblem('foo', 'bar', 'some/repo', '1.5.0'),
],
];

yield 'single with range constraint but no problem' => [
[
self::createRemoteEntry('foo', version: '1.0'),
self::createRemoteEntry('bar', version: '2.0.3'),
],
[
'foo' => ['bar'],
'bar' => [],
],
[
[
'url' => '/foo/1.0',
'response' => [
'dependencies' => ['bar' => '1.11 - 2'],
],
],
],
[],
];
}

/**
Expand Down Expand Up @@ -297,22 +317,22 @@ public static function getNpmSpecificVersionConstraints()
// Hyphen Ranges
yield 'hyphen range simple' => [
'1.0.0 - 2.0.0',
'>=1.0.0 <=2.0.0',
'1.0.0 - 2.0.0',
];

yield 'hyphen range with v prefix' => [
'v1.0.0 - 2.0.0',
'>=1.0.0 <=2.0.0',
'1.0.0 - 2.0.0',
];

yield 'hyphen range without patch' => [
'1.0 - 2.0',
'>=1.0 <=2.0',
'1.0 - 2.0',
];

yield 'hyphen range with no spaces' => [
'1.0-v2.0',
'>=1.0 <=2.0',
'1.0 - 2.0',
];

// .x Wildcards
Expand Down Expand Up @@ -386,7 +406,7 @@ public static function getNpmSpecificVersionConstraints()

yield 'multiple constraints with space and or operator' => [
'1.2.7 || 1.2.9- v2.0.0',
'1.2.7 || >=1.2.9 <=2.0.0',
'1.2.7 || 1.2.9 - 2.0.0',
];

yield 'tilde constraint with patch version no change' => [
Expand Down
Loading