8000 [AssetMapper] Adding import support for paths without a version · symfony/symfony@d684020 · GitHub
[go: up one dir, main page]

Skip to content

Commit d684020

Browse files
committed
[AssetMapper] Adding import support for paths without a version
1 parent ff8b61d commit d684020

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/Symfony/Component/AssetMapper/ImportMap/Resolver/JsDelivrEsmResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class JsDelivrEsmResolver implements PackageResolverInterface
2626
public const URL_PATTERN_DIST = self::URL_PATTERN_DIST_CSS.'/+esm';
2727
public const URL_PATTERN_ENTRYPOINT = 'https://data.jsdelivr.com/v1/packages/npm/%s@%s/entrypoints';
2828

29-
public const IMPORT_REGEX = '{from"/npm/((?:@[^/]+/)?[^@]+)@([^/]+)((?:/[^/]+)*?)/\+esm"}';
29+
public const IMPORT_REGEX = '{from"/npm/((?:@[^/]+/)?[^@]+?)(?:@([^/]+))?((?:/[^/]+)*?)/\+esm"}';
3030

3131
private HttpClientInterface $httpClient;
3232

@@ -222,7 +222,7 @@ private function fetchPackageRequirementsFromImports(string $content): array
222222
preg_match_all(self::IMPORT_REGEX, $content, $matches);
223223
$dependencies = [];
224224
foreach ($matches[1] as $index => $packageName) {
225-
$version = $matches[2][$index];
225+
$version = $matches[2][$index] ?: null;
226226
$packageName .= $matches[3][$index]; // add the path if any
227227

228228
$dependencies[] = new PackageRequireOptions($packageName, $version);

src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,22 @@ public static function provideImportRegex(): iterable
513513
['locutus/php/strings/vsprintf', '2.0.16'],
514514
],
515515
];
516+
517+
yield 'import statements without a version' => [
518+
'import{ReplaceAroundStep as c,canSplit as d,StepMap as p,liftTarget as f}from"/npm/prosemirror-transform/+esm";import{PluginKey as h,EditorState as m,TextSelection as v,Plugin as g,AllSelection as y,Selection as b,NodeSelection as w,SelectionRange as k}from"/npm/prosemirror-state@1.4.3/+esm";',
519+
[
520+
['prosemirror-transform', ''],
521+
['prosemirror-state', '1.4.3'],
522+
],
523+
];
524+
525+
yield 'import statements without a version and with paths' => [
526+
'import{ReplaceAroundStep as c,canSplit as d,StepMap as p,liftTarget as f}from"/npm/prosemirror-transform/php/strings/vsprintf/+esm";import{PluginKey as h,EditorState as m,TextSelection as v,Plugin as g,AllSelection as y,Selection as b,NodeSelection as w,SelectionRange as k}from"/npm/prosemirror-state@1.4.3/php/strings/sprintf/+esm";',
527+
[
528+
['prosemirror-transform/php/strings/vsprintf', ''],
529+
['prosemirror-state/php/strings/sprintf', '1.4.3'],
530+
],
531+
];
516532
}
517533

518534
private static function createRemoteEntry(string $importName, string $version, ImportMapType $type = ImportMapType::JS, string $packageSpecifier = null): ImportMapEntry

0 commit comments

Comments
 (0)
0