Skip to content

Commit abd5914

Browse files
committed
Merge branch '6.4' into 7.0
* 6.4: (31 commits) [Messenger] Add call to `gc_collect_cycles()` after each message is handled fix tests fix tests on AppVeyor Hungarian typo fix in validators translation [VarDump] Fix order of dumped properties - parent goes first DX: drop unused import [Validator] updated Latvian translation re-introduce conflict rule with WebProfilerBundle < 6.4 [Validator] Added missing Swedish translations [Mailer] [Notifier] #52264 Update Sendinblue / Brevo API host [Validator] Added missing Estonian translations #51939 fix File constraint tests on 32bit PHP [Form] Skip merging params & files if there are no files in the first place [Translation] Ignore bridges in `.gitattributes` file [AssetMapper] Adding import-parsing case where import contains a path Add missing Hungarian validator translations Added missing Bosnian translations #51929 add return type hints to EntityFactory Update UndefinedCallableHandler with "importmap", "form" and "worflow" filters/functions [FrameworkBundle] Fix CommandDataCollector is always registered ...
2 parents 9bdbd7a + db54d9a commit abd5914

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

ImportMap/Resolver/JsDelivrEsmResolver.php

Lines changed: 3 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

@@ -223,6 +223,7 @@ private function fetchPackageRequirementsFromImports(string $content): array
223223
$dependencies = [];
224224
foreach ($matches[1] as $index => $packageName) {
225225
$version = $matches[2][$index];
226+
$packageName .= $matches[3][$index]; // add the path if any
226227

227228
$dependencies[] = new PackageRequireOptions($packageName, $version);
228229
}
@@ -238,7 +239,7 @@ private function fetchPackageRequirementsFromImports(string $content): array
238239
private function makeImportsBare(string $content, array &$dependencies): string
239240
{
240241
$content = preg_replace_callback(self::IMPORT_REGEX, function ($matches) use (&$dependencies) {
241-
$packageName = $matches[1];
242+
$packageName = $matches[1].$matches[3]; // add the path if any
242243
$dependencies[] = $packageName;
243244

244245
return sprintf('from"%s"', $packageName);

Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,24 @@ public static function provideDownloadPackagesTests()
393393
],
394394
];
395395

396+
yield 'make imports point to file and relative' => [
397+
[
398+
'twig' => self::createRemoteEntry('twig', version: '1.16.0'),
399+
],
400+
[
401+
[
402+
'url' => '/[email protected]/+esm',
403+
'body' => 'import e from"/npm/[email protected]/php/strings/sprintf/+esm";console.log()',
404+
],
405+
],
406+
[
407+
'twig' => [
408+
'content' => 'import e from"locutus/php/strings/sprintf";console.log()',
409+
'dependencies' => ['locutus/php/strings/sprintf'],
410+
],
411+
],
412+
];
413+
396414
yield 'js sourcemap is removed' => [
397415
[
398416
'@chart.js/auto' => self::createRemoteEntry('chart.js/auto', version: '1.2.3'),
@@ -444,7 +462,12 @@ public function testImportRegex(string $subject, array $expectedPackages)
444462
$expectedNames[] = $packageData[0];
445463
$expectedVersions[] = $packageData[1];
446464
}
447-
$this->assertSame($expectedNames, $matches[1]);
465+
$actualNames = [];
466+
foreach ($matches[1] as $i => $name) {
467+
$actualNames[] = $name.$matches[3][$i];
468+
}
469+
470+
$this->assertSame($expectedNames, $actualNames);
448471
$this->assertSame($expectedVersions, $matches[2]);
449472
}
450473

@@ -482,6 +505,14 @@ public static function provideImportRegex(): iterable
482505
['datatables.net', '2.1.1'], // for the export syntax
483506
],
484507
];
508+
509+
yield 'import statements with paths' => [
510+
'import e from"/npm/[email protected]/php/strings/sprintf/+esm";import t from"/npm/[email protected]/php/strings/vsprintf/+esm"',
511+
[
512+
['locutus/php/strings/sprintf', '2.0.16'],
513+
['locutus/php/strings/vsprintf', '2.0.16'],
514+
],
515+
];
485516
}
486517

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

0 commit comments

Comments
 (0)