From 978279aea2ccc2c775cd521c9014effa2435595c Mon Sep 17 00:00:00 2001 From: Serghei Niculaev Date: Tue, 3 Oct 2023 20:18:21 +0300 Subject: [PATCH] Filter out metapackages from assets builder 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: https://github.com/thecodingmachine/discovery/issues/17 Refs: https://getcomposer.org/doc/04-schema.md#type --- src/AssetsBuilder.php | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/AssetsBuilder.php b/src/AssetsBuilder.php index 7cda190..9af36c0 100644 --- a/src/AssetsBuilder.php +++ b/src/AssetsBuilder.php @@ -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);