wikimedia / composer-merge-plugin

Merge one or more additional composer.json files at Composer runtime
MIT License
934 stars 159 forks source link

ignore-packages option #150

Closed soullivaneuh closed 7 years ago

soullivaneuh commented 7 years ago

It would be great to add a ignore-packages option in order to ignore some package from the merge.

Example:

"extra": {
    "merge-plugin": {
        "require": [
            "vendor/prestashop/prestashop/composer.json"
        ],
        "ignore-packages": [
            "dummy/package",
            "vendor-name", // Will ignore all vendor-name/* packages.
            "prestashop/ps_*" // Will ignore all prestashop/ps_* packages.
        ],
        "merge-dev": false,
        "ignore-duplicates": true
    }
}

What do you think? I could work on a PR for this.

bd808 commented 7 years ago

What is the expected use-case for this feature?

soullivaneuh commented 7 years ago

@bd808 I'll give you my concrete case.

I'm merging the Prestashop composer.json file, which provide a bunch of Prestashop modules: https://github.com/PrestaShop/PrestaShop/blob/b4955c65420e65f5dfa6a0a90e8bc27b74f431c8/composer.json#L42-L94

Modules are optional, and there is some I don't need at all.

The goal is to remove them from the merge.

I already made a custom working script for my project:

use Composer\Package\Link;
use Composer\Script\Event;
use Composer\Semver\Constraint\Constraint;
use Composer\Semver\VersionParser;

final class ComposerScripts
{
    const PACKAGES_TO_REMOVE = [
        'prestashop/blockreassurance',
        'prestashop/ps_banner',
        'prestashop/ps_customtext',
        'prestashop/ps_imageslider',
    ];

    /**
     * @param Event $event
     */
    public static function preUpdate(Event $event)
    {
        $versionParser = new VersionParser();
        $lastStableConstraint = $versionParser->parseConstraints('<9999999-dev');

        $composer = $event->getComposer();
        $root = $composer->getPackage();

        /** @var Link[] $requires */
        $requires = $root->getRequires();
        foreach ($requires as $r => $require) {
            // Manage only Prestashop required packages.
            if ('prestashop/prestashop' !== $require->getSource()) {
                continue;
            }

            if (in_array($require->getTarget(), static::PACKAGES_TO_REMOVE, true)) {
                unset($requires[$r]);
                continue;
            }
        }

        $root->setRequires(array_values($requires));
    }
}

But having options like described would be better.

bd808 commented 7 years ago

I'm struggling to see how this is generally applicable functionality. I see how it helps your particular project, but broadly I don't think that using composer-merge-plugin to modify the dependencies declared by project type Composer packages is likely to be a common use-case.

soullivaneuh commented 7 years ago

I understand. I have to do this waiting some improvement from PrestaShop composer management.

As you wish for this issue.

bd808 commented 7 years ago

Declined