Skip to content

Commit 93e7adc

Browse files
bug #52524 [AssetMapper] Only download a CSS file if it is explicitly advertised (weaverryan)
This PR was merged into the 6.4 branch. Discussion ---------- [AssetMapper] Only download a CSS file if it is explicitly advertised | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | None | License | MIT When we download a JS package, we check to see if that JS package has a CSS file. And if it does, we add that too. This is purely to be helpful. For example, `importmap:require bootstrap` grabs the Bootstrap CSS file. A JavaScript package can explicitly advertise that it has a CSS file or jsdelivr can "guess". It tells us if it's guessing or not: * Not guessing: https://data.jsdelivr.com/v1/packages/npm/bootstrap@5.0.0/entrypoints * Yes guessing: https://data.jsdelivr.com/v1/packages/npm/tom-select@2.3.1/entrypoints I propose we only grab the CSS file if it's a "sure thing". Right now, when you install `tom-select`, it's grabbing a CSS file that... we certainly don't use and I'm not sure if anyone does. It'd be better if it grabbed nothing. And, if needed (probably will be), we an make Flex install any enabled "autoimports" - e.g. https://github.com/symfony/ux/blob/2.x/src/Autocomplete/assets/package.json#L17 Overall, I'm still tweaking with the ideal UX here. I think life will be better if we only install "for sure" CSS files. Thanks! Commits ------- 1f41d673f77 [AssetMapper] Only download a CSS file if it is explicitly advertised
2 parents b932fd6 + 37ee647 commit 93e7adc

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

ImportMap/Resolver/JsDelivrEsmResolver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ public function resolvePackages(array $packagesToRequire): array
129129

130130
$entrypoints = $cssEntrypointResponse->toArray()['entrypoints'] ?? [];
131131
$cssFile = $entrypoints['css']['file'] ?? null;
132+
$guessed = $entrypoints['css']['guessed'] ?? true;
132133

133-
if (!$cssFile) {
134+
if (!$cssFile || $guessed) {
134135
continue;
135136
}
136137

Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public static function provideResolvePackagesTests(): iterable
224224
[
225225
'url' => '/v1/packages/npm/bootstrap@5.2.0/entrypoints',
226226
'response' => ['body' => ['entrypoints' => [
227-
'css' => ['file' => '/dist/css/bootstrap.min.css'],
227+
'css' => ['file' => '/dist/css/bootstrap.min.css', 'guessed' => false],
228228
]]],
229229
],
230230
[

0 commit comments

Comments
 (0)