4

Is it a good practice to put "drush/drush": "^9 || ^10" in the required section of the composer.json of a contrib module if drush is actually its only interface?

I'm maintaining a contrib module, that can be operated only by using drush, but as far I saw in other similar modules (like: https://www.drupal.org/project/data_fixtures ) - drush doesn't appear in the composer's dependencies. Is there any reason for that other than maybe "crowd psychology"?

I'm just considering putting drush as explicit composer dependency of my contrib module.

1 Answer 1

4

If the module doesn't do anything when Drush isn't installed, for example because it's only implementing Drush commands, adding Drush as dependency in composer.json is perfectly fine.

I don't see any reason for not adding it in the composer.json dependencies. Probably, the users who don't add it as dependency for their modules think that most users download the module from the project page on drupal.org and the dependencies on composer.json wouldn't stop them from installing the module.

I would rather add the dependency from Drush in the composer.json file, in the same way I would add a dependency from a module the Standard profile installs, in the .info.yml file of a module I develop.
Eventually, I would add a hook_requirements() implementation that doesn't allow users to install the module when Drush isn't present, for the users who install the module from the user interface or using the project archive downloaded from drupal.org.

Your Answer

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

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