Skip to content

Commit

Permalink
Filter out metapackages from assets builder
Browse files Browse the repository at this point in the history
Package with type metapackage doesn't have installation path, which brings with it a problem finding discovery JSON files in all packages. Filter add for removing "metapackages" and leave only real

Refs: thecodingmachine#17

Refs: https://getcomposer.org/doc/04-schema.md#type
  • Loading branch information
kiironoaki committed Oct 3, 2023
1 parent 1e57e34 commit 978279a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/AssetsBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,30 @@ public function findAssetTypes(RepositoryInterface $repository) : array
{
$unorderedPackagesList = $repository->getPackages();

/**
* Package with type `metapackage` doesn't have installation path, which
* brings with it a problem finding discovery JSON files in all
* packages. This filter removes "metapackages" and leaves only real.
*
* Documentation: https://getcomposer.org/doc/04-schema.md#type
*/
$realPackagesList = array_filter(
$unorderedPackagesList,
function (PackageInterface $package) {
return 'metapackage' !== $package->getType();
}
);

// For some weird reason, some packages can be in double in the repository.
// This has been observed when doing a "composer install" on an empty vendor directory.
// Let's ensure each package is represented only once.
$dedupPackages = [];
foreach($unorderedPackagesList as $package) {
$dedupPackages[$package->getName()] = $package;
$uniquePackages = [];
foreach($realPackagesList as $package) {
$uniquePackages[$package->getName()] = $package;
}
$dedupPackages = array_values($dedupPackages);
$uniquePackages = array_values($uniquePackages);

$orderedPackageList = PackagesOrderer::reorderPackages($dedupPackages);
$orderedPackageList = PackagesOrderer::reorderPackages($uniquePackages);

$packages = array_filter($orderedPackageList, function (PackageInterface $package) {
$packageInstallPath = $this->getInstallPath($package);
Expand Down

0 comments on commit 978279a

Please sign in to comment.