Skip to content

Commit 678fede

Browse files
committed
bug #57321 [AssetMapper] fix npm version constraint conversion (Jean-Beru)
This PR was merged into the 6.4 branch. Discussion ---------- [AssetMapper] fix npm version constraint conversion | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #54610 | License | MIT This PR fixes semver conversion when requiring or updating packages. ``` [warning] datatables.net-scroller-bs5 requires datatables.net-bs5@1.11 - 2 but version 2.0.3 is installed. ``` Ranges are now converted to `1.11 - 2` instead of `>=1.11 <=2`. See #54610 Commits ------- 62c2d8d [AssetMapper] fix npm version constraint conversion
2 parents cf4ef92 + 62c2d8d commit 678fede

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/Symfony/Component/AssetMapper/ImportMap/ImportMapVersionChecker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public static function convertNpmConstraint(string $versionConstraint): ?string
137137
if (str_contains($segment, '-') && !preg_match('/-(alpha|beta|rc)\./', $segment)) {
138138
// This is a range
139139
[$start, $end] = explode('-', $segment);
140-
$processedSegments[] = '>='.self::cleanVersionSegment(trim($start)).' <='.self::cleanVersionSegment(trim($end));
140+
$processedSegments[] = self::cleanVersionSegment(trim($start)).' - '.self::cleanVersionSegment(trim($end));
141141
} elseif (preg_match('/^~(\d+\.\d+)$/', $segment, $matches)) {
142142
// Handle the tilde when only major.minor specified
143143
$baseVersion = $matches[1];

src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapVersionCheckerTest.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,26 @@ public static function getCheckVersionsTests()
261261
new PackageVersionProblem('foo', 'bar', 'some/repo', '1.5.0'),
262262
],
263263
];
264+
265+
yield 'single with range constraint but no problem' => [
266+
[
267+
self::createRemoteEntry('foo', version: '1.0'),
268+
self::createRemoteEntry('bar', version: '2.0.3'),
269+
],
270+
[
271+
'foo' => ['bar'],
272+
'bar' => [],
273+
],
274+
[
275+
[
276+
'url' => '/foo/1.0',
277+
'response' => [
278+
'dependencies' => ['bar' => '1.11 - 2'],
279+
],
280+
],
281+
],
282+
[],
283+
];
264284
}
265285

266286
/**
@@ -297,22 +317,22 @@ public static function getNpmSpecificVersionConstraints()
297317
// Hyphen Ranges
298318
yield 'hyphen range simple' => [
299319
'1.0.0 - 2.0.0',
300-
'>=1.0.0 <=2.0.0',
320+
'1.0.0 - 2.0.0',
301321
];
302322

303323
yield 'hyphen range with v prefix' => [
304324
'v1.0.0 - 2.0.0',
305-
'>=1.0.0 <=2.0.0',
325+
'1.0.0 - 2.0.0',
306326
];
307327

308328
yield 'hyphen range without patch' => [
309329
'1.0 - 2.0',
310-
'>=1.0 <=2.0',
330+
'1.0 - 2.0',
311331
];
312332

313333
yield 'hyphen range with no spaces' => [
314334
'1.0-v2.0',
315-
'>=1.0 <=2.0',
335+
'1.0 - 2.0',
316336
];
317337

318338
// .x Wildcards
@@ -386,7 +406,7 @@ public static function getNpmSpecificVersionConstraints()
386406

387407
yield 'multiple constraints with space and or operator' => [
388408
'1.2.7 || 1.2.9- v2.0.0',
389-
'1.2.7 || >=1.2.9 <=2.0.0',
409+
'1.2.7 || 1.2.9 - 2.0.0',
390410
];
391411

392412
yield 'tilde constraint with patch version no change' => [

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy