Do not remove root package from the pool

master
Anton Smirnov 12 months ago
parent 914372109d
commit 0e8da71a6b

@ -1,4 +1,5 @@
{
"name": "sandfox.dev/sandbox",
"repositories": [
{
"type": "path",
@ -10,6 +11,7 @@
"url": "https://asset-packagist.org"
}
],
"license": "0BSD",
"require": {
"arokettu/composer-license-manager": "dev-master",
"laminas/laminas-code": "^4.5",
@ -24,7 +26,7 @@
"extra": {
"arokettu/composer-license-manager": {
"licenses": {
"allowed": ["MIT", "BSD-*", "ISC", "artistic-2.0", "apache-2.0", "(wtfpl*", "*"],
"allowed": ["MIT", "BSD-*", "ISC", "artistic-2.0", "apache-2.0", "(wtfpl*"],
"forbidden": ["BSD-3-Clause"],
"allow-empty": false
},

@ -32,27 +32,35 @@ class PrePoolCreateEventHandler
public function handle(PrePoolCreateEvent $event): void
{
$config = Config::fromComposer($this->composer);
$rootPackage = $this->composer->getPackage()->getName();
/** @var array<string, array<int, string>> $filtered */
$filtered = [];
$packages = array_filter($event->getPackages(), function (PackageInterface $package) use (&$filtered, $config) {
$packageName = $package->getName();
$packages = array_filter(
$event->getPackages(),
function (PackageInterface $package) use (&$filtered, $config, $rootPackage) {
$packageName = $package->getName();
if ($packageName === LicenseManagerPlugin::PACKAGE || !str_contains($packageName, '/')) {
return true;
}
if ($package instanceof CompletePackageInterface) {
if (LicenseHelper::isPermitted($package, $config)) {
if (
$packageName === $rootPackage || // do not block root package
$packageName === LicenseManagerPlugin::PACKAGE || // do not block the manager itself
!str_contains($packageName, '/') // platform and composer packages
) {
return true;
}
if ($package instanceof CompletePackageInterface) {
if (LicenseHelper::isPermitted($package, $config)) {
return true;
} else {
$filtered[$packageName] = $package->getLicense();
return false;
}
} else {
$filtered[$packageName] = $package->getLicense();
return false;
throw new \LogicException('Filtering can work only on complete packages');
}
} else {
throw new \LogicException('Filtering can work only on complete packages');
}
});
);
if ($filtered !== []) {
$this->io->write('<warning>Some packages do not conform to the license policy:</warning>');

Loading…
Cancel
Save