Skip to content

Commit 2757c2f

Browse files
bug #50206 [AssetMapper] Fix import map package parsing with an @ namespace (weaverryan)
This PR was merged into the 6.3 branch. Discussion ---------- [AssetMapper] Fix import map package parsing with an @ namespace | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | None | License | MIT | Doc PR | Not needed This method is used with the `importmap:require` command - e.g. ``` ./bin/console importmap:require `@hotwired`/stimulus ``` It parses the string into the package name and potential version (and something called a "registry" which is specific to jspm). The original regex didn't account for namespaced packages. Cheers! Commits ------- 4cc0a8c [AssetMapper] Fix import map package parsing with an @ namespace
2 parents 707245c + 4cc0a8c commit 2757c2f

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ public function update(): array
111111
*/
112112
public static function parsePackageName(string $packageName): ?array
113113
{
114-
// https://regex101.com/r/58bl9L/1
115-
$regex = '/(?:(?P<registry>[^:\n]+):)?(?P<package>[^@\n]+)(?:@(?P<version>[^\s\n]+))?/';
114+
// https://regex101.com/r/d99BEc/1
115+
$regex = '/(?:(?P<registry>[^:\n]+):)?((?P<package>@?[^@\n]+))(?:@(?P<version>[^\s\n]+))?/';
116116

117117
return preg_match($regex, $packageName, $matches) ? $matches : null;
118118
}

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,40 @@ public static function getPackageNameTests(): iterable
422422
'version' => '^1.2.3',
423423
],
424424
];
425+
426+
yield 'namespaced_package_simple' => [
427+
'@hotwired/stimulus',
428+
[
429+
'package' => '@hotwired/stimulus',
430+
'registry' => '',
431+
],
432+
];
433+
434+
yield 'namespaced_package_with_version_constraint' => [
435+
'@hotwired/stimulus@^1.2.3',
436+
[
437+
'package' => '@hotwired/stimulus',
438+
'registry' => '',
439+
'version' => '^1.2.3',
440+
],
441+
];
442+
443+
yield 'namespaced_package_with_registry' => [
444+
'npm:@hotwired/stimulus',
445+
[
446+
'package' => '@hotwired/stimulus',
447+
'registry' => 'npm',
448+
],
449+
];
450+
451+
yield 'namespaced_package_with_registry_and_version' => [
452+
'npm:@hotwired/stimulus@^1.2.3',
453+
[
454+
'package' => '@hotwired/stimulus',
455+
'registry' => 'npm',
456+
'version' => '^1.2.3',
457+
],
458+
];
425459
}
426460

427461
private function createImportMapManager(array $dirs, string $rootDir, string $publicPrefix = '/assets/', string $publicDirName = 'public'): ImportMapManager

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