Skip to content

Commit 455cf01

Browse files
Merge branch '6.3' into 6.4
* 6.3: [AssetMapper] Fix wiring resolvers, send requests in parallel and use readonly properties in MappedAsset [AssetMapper] Change default importmap "provider" to JsDelivr+esm
2 parents 95567a6 + 5f08efe commit 455cf01

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

DependencyInjection/Compiler/UnusedTagsPass.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class UnusedTagsPass implements CompilerPassInterface
2525
'annotations.cached_reader',
2626
'assets.package',
2727
'asset_mapper.compiler',
28+
'asset_mapper.importmap.resolver',
2829
'auto_alias',
2930
'cache.pool',
3031
'cache.pool.clearer',

DependencyInjection/Configuration.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,8 @@ private function addAssetMapperSection(ArrayNodeDefinition $rootNode, callable $
902902
->defaultValue('%kernel.project_dir%/assets/vendor')
903903
->end()
904904
->scalarNode('provider')
905-
->info('The provider (CDN) to use', class_exists(ImportMapManager::class) ? sprintf(' (e.g.: "%s").', implode('", "', ImportMapManager::PROVIDERS)) : '.')
906-
->defaultValue('jspm')
905+
->info('The provider (CDN) to use'.(class_exists(ImportMapManager::class) ? sprintf(' (e.g.: "%s").', implode('", "', ImportMapManager::PROVIDERS)) : '.'))
906+
->defaultValue('jsdelivr.esm')
907907
->end()
908908
->end()
909909
->end()

DependencyInjection/FrameworkExtension.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use Symfony\Component\AssetMapper\AssetMapper;
3535
use Symfony\Component\AssetMapper\Compiler\AssetCompilerInterface;
3636
use Symfony\Component\AssetMapper\ImportMap\ImportMapManager;
37+
use Symfony\Component\AssetMapper\ImportMap\Resolver\PackageResolverInterface;
3738
use Symfony\Component\BrowserKit\AbstractBrowser;
3839
use Symfony\Component\Cache\Adapter\AdapterInterface;
3940
use Symfony\Component\Cache\Adapter\ArrayAdapter;
@@ -1314,14 +1315,21 @@ private function registerAssetMapperConfiguration(array $config, ContainerBuilde
13141315
->getDefinition('asset_mapper.importmap.manager')
13151316
->replaceArgument(2, $config['importmap_path'])
13161317
->replaceArgument(3, $config['vendor_dir'])
1317-
->replaceArgument(4, $config['provider'])
1318+
;
1319+
1320+
$container
1321+
->getDefinition('asset_mapper.importmap.resolver')
1322+
->replaceArgument(0, $config['provider'])
13181323
;
13191324

13201325
$container
13211326
->getDefinition('asset_mapper.importmap.renderer')
13221327
->replaceArgument(2, $config['importmap_polyfill'] ?? ImportMapManager::POLYFILL_URL)
13231328
->replaceArgument(3, $config['importmap_script_attributes'])
13241329
;
1330+
1331+
$container->registerForAutoconfiguration(PackageResolverInterface::class)
1332+
->addTag('asset_mapper.importmap.resolver');
13251333
}
13261334

13271335
/**

Resources/config/asset_mapper.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
use Symfony\Component\AssetMapper\Factory\MappedAssetFactory;
3030
use Symfony\Component\AssetMapper\ImportMap\ImportMapManager;
3131
use Symfony\Component\AssetMapper\ImportMap\ImportMapRenderer;
32+
use Symfony\Component\AssetMapper\ImportMap\Resolver\JsDelivrEsmResolver;
33+
use Symfony\Component\AssetMapper\ImportMap\Resolver\JspmResolver;
34+
use Symfony\Component\AssetMapper\ImportMap\Resolver\PackageResolver;
3235
use Symfony\Component\AssetMapper\MapperAwareAssetPackage;
3336
use Symfony\Component\AssetMapper\Path\PublicAssetsPathResolver;
3437
use Symfony\Component\HttpKernel\Event\RequestEvent;
@@ -136,10 +139,40 @@
136139
service('asset_mapper.public_assets_path_resolver'),
137140
abstract_arg('importmap.php path'),
138141
abstract_arg('vendor directory'),
139-
abstract_arg('provider'),
142+
service('asset_mapper.importmap.resolver'),
140143
])
141144
->alias(ImportMapManager::class, 'asset_mapper.importmap.manager')
142145

146+
->set('asset_mapper.importmap.resolver', PackageResolver::class)
147+
->args([
148+
abstract_arg('provider'),
149+
tagged_locator('asset_mapper.importmap.resolver'),
150+
])
151+
152+
->set('asset_mapper.importmap.resolver.jsdelivr_esm', JsDelivrEsmResolver::class)
153+
->args([service('http_client')])
154+
->tag('asset_mapper.importmap.resolver', ['resolver' => ImportMapManager::PROVIDER_JSDELIVR_ESM])
155+
156+
->set('asset_mapper.importmap.resolver.jspm', JspmResolver::class)
157+
->args([service('http_client'), ImportMapManager::PROVIDER_JSPM])
158+
->tag('asset_mapper.importmap.resolver', ['resolver' => ImportMapManager::PROVIDER_JSPM])
159+
160+
->set('asset_mapper.importmap.resolver.jspm_system', JspmResolver::class)
161+
->args([service('http_client'), ImportMapManager::PROVIDER_JSPM_SYSTEM])
162+
->tag('asset_mapper.importmap.resolver', ['resolver' => ImportMapManager::PROVIDER_JSPM_SYSTEM])
163+
164+
->set('asset_mapper.importmap.resolver.skypack', JspmResolver::class)
165+
->args([service('http_client'), ImportMapManager::PROVIDER_SKYPACK])
166+
->tag('asset_mapper.importmap.resolver', ['resolver' => ImportMapManager::PROVIDER_SKYPACK])
167+
168+
->set('asset_mapper.importmap.resolver.jsdelivr', JspmResolver::class)
169+
->args([service('http_client'), ImportMapManager::PROVIDER_JSDELIVR])
170+
->tag('asset_mapper.importmap.resolver', ['resolver' => ImportMapManager::PROVIDER_JSDELIVR])
171+
172+
->set('asset_mapper.importmap.resolver.unpkg', JspmResolver::class)
173+
->args([service('http_client'), ImportMapManager::PROVIDER_UNPKG])
174+
->tag('asset_mapper.importmap.resolver', ['resolver' => ImportMapManager::PROVIDER_UNPKG])
175+
143176
->set('asset_mapper.importmap.renderer', ImportMapRenderer::class)
144177
->args([
145178
service('asset_mapper.importmap.manager'),

Tests/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function testAssetMapperCanBeEnabled()
112112
'importmap_path' => '%kernel.project_dir%/importmap.php',
113113
'importmap_polyfill' => null,
114114
'vendor_dir' => '%kernel.project_dir%/assets/vendor',
115-
'provider' => 'jspm',
115+
'provider' => 'jsdelivr.esm',
116116
'importmap_script_attributes' => [],
117117
];
118118

@@ -624,7 +624,7 @@ protected static function getBundleDefaultConfig()
624624
'importmap_path' => '%kernel.project_dir%/importmap.php',
625625
'importmap_polyfill' => null,
626626
'vendor_dir' => '%kernel.project_dir%/assets/vendor',
627-
'provider' => 'jspm',
627+
'provider' => 'jsdelivr.esm',
628628
'importmap_script_attributes' => [],
629629
],
630630
'cache' => [

0 commit comments

Comments
 (0)