I have a composer managed Drupal project based on drupal/recommended-project.
I'm installing a contrib module, domain_group, and I'm seeing that composer is auto-including a required dependency, even though it's not listed in the module's composer.json. (I'm checking some other contrib modules and it seems that this is not specific to this module, but a consistent pattern across many modules.)
I run:
composer require drupal/domain_group
and it installs domain_group and domain_site_settings.
Then when I run:
composer why drupal/domain_site_settings
and it tells me that drupal/domain_group requires it.
While the dependency is not listed in domain_group/composer.json, I do see that it is listed in domain_group.info.yml.
Is composer somehow looking to the .info.yml to check for dependencies? Is this some kind of Drupal magic? What causes this? How does it work?
Update:
It seems that it's not checking the .info.yml, at least not locally. From @Clive, in the comments:
[
composer why
still lists the dependency] even when [the reference to domain_site_settings] is not in domain_group's local composer.json, composer.lock is deleted, the require line in domain_group.info.yml is commented out and composer cache is cleared (just checked). Where is it getting the reference?
I'm now wondering if composer why
checks the remote repositories, e.g. https://packages.drupal.org/8, and if there's something special about the d.o repository that compiles extra package dependencies from .info.yml files.
domain_group/composer.json
{
"name": "drupal/domain_group",
"type": "drupal-module",
"description": "This module provides integration between Domain and Group modules",
"homepage": "http://drupal.org/project/domain_group",
"authors": [], // etc...
"support": {}, // etc...
"license": "GPL-2.0+",
"minimum-stability": "dev",
"require": {
"drupal/core": "^8.8 || ^9",
"drupal/group": "~1.0",
"drupal/domain": "~1.0"
}
}
domain_group/domain_group.info.yml
name: 'Domain Group'
type: module
description: 'This module provides integration between Domain and Group modules.'
core: 8.x
core_version_requirement: ^8 || ^9
package: 'Domain'
dependencies:
- group:group
- domain:domain
- domain_site_settings:domain_site_settings # Is composer somehow respecting this?
Is composer somehow looking to the .info.yml to check for dependencies?
Yes, always.Is this some kind of Drupal magic?
You betcha.composer why
finds that package, even when it's not in domain_group's local composer.json, composer.lock is deleted, the require line in domain_group.info.yml is commented out and composer cache is cleared (just checked). Where is it getting the reference?