COMPOSER ADD-ONS FOR DRUPAL DEVELOPERS

As ever-evolving Drupal developers, we've been in the process of moving towards a Composer-based workflow for managing our Drupal project code bases. While it is (usually) an easy leap to move from "drush dl" to "composer require" for Drupal contributed modules and themes, there is another significant opportunity for us to take advantage of during this evolution that should be considered. 

We are all familiar with the concept that modules in Drupal extend the functionality of the Drupal site; we should also accept the fact that there is a whole class of Composer dependencies that extend the functionality of Composer. These are appropriately called "Composer plugins".

Composer Plugins

If your Drupal project is using the  drupal/recommended-project or drupal-composer/drupal-project (or similar), then you are already using Composer plugins. The second part of this article will show some additional Composer add-ins that you may want to consider adding to your Drupal codebase.

Adding a new Composer add-on is usually a two-step process. First, use "composer require" to add the add-on to your project. The second step usually (but not always) involves adding some add-on configuration to the "extra" section of your composer.json project. 

Useful Composer plugins for Drupal projects

You should have

composer/installers

  • Description: This allows you to place dependencies in directories other than /vendor/. 
  • Availability: included as part of the composer template drupal/recommended-project (via drupal/core-recommended), part of the default drupal-composer/drupal-project template.
  • Configuration key: installer-paths

drupal/core-composer-scaffold

  • Description: places the default Drupal scaffold files outside the /core/ directory and allows modifications to the scaffold files.
  • Availability: included as part of the template in drupal/recommended-project, part of default drupal-composer/drupal-project template.
  • Configuration key: drupal-scaffold

cweagans/composer-patches

  • Description: automatically applies patches (both local and remote) to dependencies. 
  • Availability: Included as part of the default drupal-composer/drupal-project template.
  • Configuration keys: patches, patches-file, enable-patching, patches-ignore.

It is worth considering

zaporylie/composer-drupal-optimizations

  • Description: Provides a Composer performance boost for Drupal projects by ignoring legacy Symfony tags. 
  • Availability: Included as part of the default drupal-composer/drupal-project template.
  • Configuration keys: composer-drupal-optimizations.

topfloor/composer-cleanup-vcs-dirs

  • Description: Automatically removes .git directories for cloned dependencies. Only necessary when dependencies are committed to the project's Git repository. 
  • Availability: install as you would any other Composer dependency.
  • Configuration keys: none.

szeidler/composer-patches-cli 

  • Description: Add-on plugin for cweagans/composer-patches that allows adding patches (and other functions) from the command line.
  • Availability: install as you would any other Composer dependency.
  • Configuration keys: none.

oomphinc/composer-installers-extender

  • Description: Add-on plugin for composer/installers that allows any arbitrary package type (such as npm packages) to be defined and then handled by the composer/installers plugin.
  • Availability: install as you would any other Composer dependency.
  • Configuration keys: installer-types.

joachim-n/composer-manifest

  • Description: Creates a simple "composer-manifest.yaml" file at the root of the project that lists all dependencies (and their exact version numbers) currently used in the project.
  • Availability: install as you would any other Composer dependency.
  • Configuration keys: none.

hirak/prestissimo

  • Description: Composer performance enhancement, allows parallel dependency downloads during Composer commands. Will not be required in Composer 2.x.
  • Availability: install as you would any other Composer dependency.
  • Configuration keys: none.

Not required for experienced developers.

drupal/core-project-message

  • Description: Allows text to be displayed after the "composer create" and "composer install" commands have been completed.
  • Availability: Included as part of the drupal/recommended-project template.
  • Configuration key: drupal-core-project-message

Have Any Project in Mind?

If you want to do something in Drupal maybe you can hire me.

Either for consulting, development or maintenance of Drupal websites.