0

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?

2
  • 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: drupal.org/project/vendor_stream_wrapper
    – Jaypan
    Dec 7, 2021 at 22:11
  • 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
    – Clive
    Dec 7, 2021 at 22:19

1 Answer 1

0

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"],
      ...
    },
  }
...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.