Score:0

Installing the dependencies of local modules without composer merge plugin

in flag

Currently I have a composer-based Drupal project with both third-party and custom modules. Third-party modules are managed by composer without any issues. But I would like my custom modules to declare their dependencies in a composer.json within their directories, and also have them install when I run composer install at the root of the project.

composer.json
web/
  modules/
    contrib/
      address/  
      admin_toolbar/
      ...
    custom/
      my_module/
        composer.json
        ...
      my_other_module/
        composer.json

Currently:

  • I have the composer merge plugin which works fine for the most part but would like to avoid using it. It has a nasty habit of calling update and bumping dependency versions when it shouldn't.
  • I've already looked into Composer path repositories. While it does install the dependencies of my custom modules, it also symlinks/copies my custom module into web/modules/contrib which is unnecessary because the custom modules are already in the right place in web/modules/custom.

In the future, I would splinter off these custom modules into their own projects and stored in their own repositories. But for now, they're still housed in the same project as the Drupal site I'm building.

How do I install dependencies declared in the composer.json of my local custom modules together with everything else?

Jaypan avatar
de flag
I created the Vendor Stream Wrapper module to solve the issue I'm guessing you are probably trying to deal with. Maybe it can help you: https://www.drupal.org/project/vendor_stream_wrapper
cn flag
If you set the `type` of your custom modules' composer.json files to `drupal-custom-module`, and you have a setting in your main composer.json under `installer-paths` for `type:drupal-custom-module` to go to `docroot/modules/custom/{$name}` (recent versions of the core recommended project already have this), the composer path repositories method _might_ work? Hopefully it's smart enough not to try to overwrite the source with itself
Score:0
sb flag

This what I have to make it work:

web/modules/custom/my_custom/composer.json

{
    "name": "[provider]/my_custom",
    "type": "drupal-custom-module",
    "description": "My Custom Module.",
    "require": {
        "drupal/core": "^8.9 || ^9",
        "drupal/devel": "^2.1"
    },
    "minimum-stability": "dev",
    "repositories": [
        {
            "type": "composer",
            "url":  "https://packages.drupal.org/8"
        },
        {
            "type": "composer",
            "url": "https://asset-packagist.org"
        }
    ]
}

composer.json

{
...
  "repositories": [
    {
      "type": "path",
      "url": "web/modules/custom/my_custom"
    }
  ],
...
  "require": {
    ...
    "[provider]/my_custom": "*"
    ...
  },
  "extra": {
    "installer-paths": {
      ...
      "web/modules/custom/{$name}":   ["type:drupal-custom-module"],
      ...
    },
  }
...
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.