8000 Simplifying algorithm, which allows us to throw an exception with the… · symfony/symfony@467dea6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 467dea6

Browse files
committed
Simplifying algorithm, which allows us to throw an exception with the specific entry name
1 parent 2465fdc commit 467dea6

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

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

+23-15
Original file line numberDiff line numberDiff line change
@@ -76,24 +76,28 @@ public function __construct(
7676
public function getImportMapData(array $entrypointNames): array
7777
{
7878
$rawImportMapData = $this->buildRawImportMapData();
79-
$eagerImports = [];
79+
$finalImportMapData = [];
8080
foreach ($entrypointNames as $entry) {
81-
$eagerImports[] = $entry;
82-
$eagerImports = array_merge($eagerImports, $this->findEagerEntrypointImports($entry));
83-
}
84-
$eagerImports = array_unique($eagerImports);
81+
$finalImportMapData[$entry] = $rawImportMapData[$entry];
82+
foreach ($this->findEagerEntrypointImports($entry) as $dependency) {
83+
if (isset($finalImportMapData[$dependency])) {
84+
continue;
85+
}
8586

86-
$finalImportMapData = [];
87-
foreach ($eagerImports as $dependency) {
88-
if (!isset($rawImportMapData[$dependency])) {
89-
throw new \InvalidArgumentException(sprintf('The entrypoint "%s" depends on "%s", but that package is not in the importmap.', implode('", "', $entrypointNames), $dependency));
90-
}
87+
if (!isset($rawImportMapData[$dependency])) {
88+
throw new \InvalidArgumentException(sprintf('The entrypoint "%s" depends on "%s", but that package is not in the importmap.', $entry, $dependency));
89+
}
9190

92-
// re-order the final array by order of dependencies
93-
$finalImportMapData[$dependency] = $rawImportMapData[$dependency];
94-
// and mark for preloading
95-
$finalImportMapData[$dependency]['preload'] = true;
96-
unset($rawImportMapData[$dependency]);
91+
if (false === ($rawImportMapData[$dependency]['preload'] ?? null)) {
92+
continue;
93+
}
94+
95+
// re-order the final array by order of dependencies
96+
$finalImportMapData[$dependency] = $rawImportMapData[$dependency];
97+
// and mark for preloading
98+
$finalImportMapData[$dependency]['preload'] = true;
99+
unset($rawImportMapData[$dependency]);
100+
}
97101
}
98102

99103
return array_merge($finalImportMapData, $rawImportMapData);
@@ -497,6 +501,10 @@ private function findEagerEntrypointImports(string $entryName): array
497501
throw new \InvalidArgumentException(sprintf('The entrypoint "%s" is not an entry point in "importmap.php". Set "entrypoint" => true to make it available as an entrypoint.', $entryName));
498502
}
499503

504+
if ($rootImportEntries->get($entryName)->isRemote()) {
505+
throw new \InvalidArgumentException(sprintf('The entrypoint "%s" is a remote package and cannot be used as an entrypoint.', $entryName));
506+
}
507+
500508
$asset = $this->assetMapper->getAsset($rootImportEntries->get($entryName)->path);
501509
if (!$asset) {
502510
throw new \InvalidArgumentException(sprintf('The path "%s" of the entrypoint "%s" mentioned in "importmap.php" cannot be found in any asset map paths.', $rootImportEntries->get($entryName)->path, $entryName));

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

-2
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,6 @@ public function testGetImportMapData()
490490
'entry1' => [
491491
'path' => '/assets/entry1-d1g35t.js',
492492
'type' => 'js',
493-
'preload' => true,
494493
],
495494
'/assets/imported_file1.js' => [
496495
'path' => '/assets/imported_file1-d1g35t.js',
@@ -500,7 +499,6 @@ public function testGetImportMapData()
500499
'entry2' => [
501500
'path' => '/assets/entry2-d1g35t.js',
502501
'type' => 'js',
503-
'preload' => true,
504502
],
505503
'/assets/imported_file2.js' => [
506504
'path' => '/assets/imported_file2-d1g35t.js',

0 commit comments

Comments
 (0)
0