Skip to content

[AssetMapper] [Bugfix] Added packageName and filePath to ImportMapEntry when requiring package #51983

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,15 @@ private function requirePackages(array $packagesToRequire, ImportMapEntries $imp
$resolvedPackages = $this->resolver->resolvePackages($packagesToRequire);
foreach ($resolvedPackages as $resolvedPackage) {
$importName = $resolvedPackage->requireOptions->importName ?: $resolvedPackage->requireOptions->packageName;

[$packageName, $filePath] = ImportMapConfigReader::splitPackageNameAndFilePath($importName);
$newEntry = new ImportMapEntry(
$importName,
path: $resolvedPackage->requireOptions->path,
version: $resolvedPackage->version,
type: $resolvedPackage->type,
isEntrypoint: $resolvedPackage->requireOptions->entrypoint,
packageName: $packageName,
filePath: $filePath,
);
$importMapEntries->add($newEntry);
$addedEntries[] = $newEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ public function downloadPackages(array $importMapEntries, callable $progressCall

foreach ($importMapEntries as $package => $entry) {
$pattern = ImportMapType::CSS === $entry->type ? $this->distUrlCssPattern : $this->distUrlPattern;
if (null === $entry->packageName || null === $entry->version || null === $entry->filePath) {
throw new RuntimeException(sprintf('The package "%s" cannot be downloaded. "packageName", "version" and "filePath" must be defined.', $entry->importName));
}
$url = sprintf($pattern, $entry->packageName, $entry->version, $entry->filePath);

$responses[$package] = $this->httpClient->request('GET', $url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public function testDownloadPackages(array $importMapEntries, array $expectedReq
public static function provideDownloadPackagesTests()
{
yield 'single package' => [
['lodash' => new ImportMapEntry('lodash', version: '1.2.3', packageName: 'lodash')],
['lodash' => new ImportMapEntry('lodash', version: '1.2.3', packageName: 'lodash', filePath: '')],
[
[
'url' => '/lodash@1.2.3/+esm',
Expand Down Expand Up @@ -333,7 +333,7 @@ public static function provideDownloadPackagesTests()

yield 'multiple files' => [
[
'lodash' => new ImportMapEntry('lodash', version: '1.2.3', packageName: 'lodash'),
'lodash' => new ImportMapEntry('lodash', version: '1.2.3', packageName: 'lodash', filePath: ''),
'chart.js/auto' => new ImportMapEntry('chart.js/auto', version: '4.5.6', packageName: 'chart.js', filePath: '/auto'),
'bootstrap/dist/bootstrap.css' => new ImportMapEntry('bootstrap/dist/bootstrap.css', version: '5.0.6', type: ImportMapType::CSS, packageName: 'bootstrap', filePath: '/dist/bootstrap.css'),
],
Expand Down