Recipe Composer plugin: support wikimedia/composer-merge-plugin

Created on 21 May 2025, 12 days ago

Problem/Motivation

If you are using wikimedia/composer-merge-plugin on a project, then the new Recipe unpack Composer plugin will not work because in RootComposer.php

In RootComposer.php line 142:

  [AssertionError (1)]
  Composer root package and composer.json match
  private static function checkRootPackage(string $composer_content, RootPackageInterface $root_package): bool {
    $composer = JsonFile::parseJson($composer_content);
    return empty(array_diff_key($root_package->getRequires(), $composer['require'] ?? [])) && empty(array_diff_key($root_package->getDevRequires(), $composer['require-dev'] ?? []));
  }

In $composer the result of the merge from wikimedia/composer-merge-plugin are present.

Steps to reproduce

- Use wikimedia/composer-merge-plugin
- Have some composer.json with require and/or required-dev merged.

Proposed resolution

- Remove this check?
- Execute the unpack plugin before Composer merge plugin?

Remaining tasks

Determine solution.

Release notes snippet

Feature request
Status

Active

Version

11.0 🔥

Component

recipe system

Created by

🇫🇷France Grimreaper France 🇫🇷

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @Grimreaper
  • 🇬🇧United Kingdom alexpott 🇪🇺🌍

    Ugh... the merge plugin is super complex. I think we should do the quick thing first and add a conflict to the composer.json. That will stop existing projects from breaking if they require this. Then we can open up an issue to try to deal with the root cause. I do not think it will be pleasant because the merge plugin is really icky. Why are you using it? Hopefully it is just a legacy of what Drupal used to do.

  • 🇭🇺Hungary mxr576 Hungary

    I ran into the same issue yesterday with a Recipe that depends on BEF. BEF includes a composer.libraries.json file in its package, which you can see here:
    https://git.drupalcode.org/project/better_exposed_filters/-/blob/7.0.x/c...

    I agree that Wikimedia’s setup is quite complex. In our monorepo, we also treat it as a necessary evil rather than something to optimize around, so I don’t think compatibility with it should be a primary concern.

    To avoid this issue in our setup, we updated our include rule from the broad composer.*.json to something more specific like composer.dev.json, which prevents BEF’s composer.libraries.json from being picked up unintentionally.

    That said, I’d recommend opening a follow-up issue to improve the error reporting in the assertion logic, so it provides clearer feedback when Composer’s actual state doesn’t match the expected configuration.

  • 🇫🇷France Grimreaper France 🇫🇷

    Hi,

    Thanks for the quick feedbacks.

    Webform also provides a composer.libraries.json: https://git.drupalcode.org/project/webform/-/blob/6.3.x/composer.librari... which I suggested in #2974114: Composer merge plugin support long time ago to ease updates.

    So for projects providing additional libraries, it can be/is useful.

    the merge plugin is super complex

    I agree that it can have side effects depending on your configuration and what is merged.

    Why are you using it? Hopefully it is just a legacy of what Drupal used to do.

    Unfortunately no ^^. It is by default in my project stack: https://gitlab.com/florenttorregrosa-drupal/docker-drupal-project/-/blob...

    - to merge custom modules/profiles/themes composer.json: 1) in case I want to split dependencies into the module using it, mainly for documentation purpose in case a custom modules is extracted from the project. 2) when developing install profiles like https://www.drupal.org/project/sobki_profile_bootstrap .
    - and like mentioned above for modules with external libraries

  • 🇺🇸United States thejimbirch Cape Cod, Massachusetts
  • 🇺🇸United States phenaproxima Massachusetts

    For the record, I generally land closer to @alexpott's position here. The merge plugin is ridiculously complicated and adds enormous complexity, and is likely to significantly increase the number of bugs and edge cases. I'd prefer to conflict with it, at least initially, and then later we can figure out how and if to support it.

  • Merge request !12192Temporarily conflict with the merge plugin → (Open) created by phenaproxima
  • Pipeline finished with Success
    12 days ago
    Total: 515s
    #502967
Production build 0.71.5 2024