Composer in Drupal 8.8.0 - First impressions

With the release of the new Drupal 8.8.0 version, a number of new changes are waiting for the community. From a development point of view, the most interesting one is probably the full support of Composer to build Drupal projects.
Pablo López Escobés
Pablo López Escobés
Drupal

With the release of the new Drupal 8.8.0 version, a number of new changes are waiting for the community. From a development point of view, the most interesting one is probably the full support of Composer to build Drupal projects.

Thanks to the Composer Support in Core Initiative, this new Drupal version will integrate multiple Composer tools already in core to make developers’ lives easier. Once these tools are included in core, the community is absolutely covered in case of any change, because this Composer support will be updated and tested accordingly before any new release.

The Drupal and Composer relationship started a long time ago. There were initiatives to include some support in Drupal 7, Composer Manager being the main example. But the actual Composer and Drupal integration came with Drupal 8, when Drupal started to include external dependencies that needed to be managed, and Composer was there to help.

At that point, Drupal opened its doors to the rest of the PHP world and Composer was used to manage internal dependencies. But the way of building Drupal sites was still the traditional one, based on the download of a tarball where all dependencies were already bundled. The next step was then to convert Drupal into a more standard PHP tool, exposing core and contrib modules as Composer packages in order to be managed by a generic composer.json file.

That was probably the biggest game changer in the Drupal development workflow in years. Some different approaches emerged, but one of them, Drupal project, was considered the de facto standard and followed by the majority of the Drupal community. The adoption of the Composer approach for Drupal development brought architecture closer to the PHP standards and the community learned new ways to handle and deploy projects.

With the community being ready and used to work with Composer, it is time to fully adopt this workflow in core itself. Drupal 8.8 will come with multiple Composer plugins and templates that will add to this support. Here is a brief list of the new components:

  1. drupal/core-composer-scaffold: This plugin is mainly the core replacement of the drupal-composer/drupal-scaffold plugin and it is in charge of the automation of the scaffolding of the Drupal core Composer package to the right place. This plugin provides several options to allow different setup approaches and the override of the default scaffolded files out of the box. Here is the reference: Using Drupal's Composer Scaffold.
  2. drupal/core-vendor-hardening: This plugin removes some unnecessary folders from vendor directories like tests or documentation. This process is necessary when the vendor folder is included in the docroot.
  3. drupal/recommended-project: This composer template generates a Drupal project structure as recommended in Drupal 8.8+, having the vendor folder outside of the docroot. This is mostly the core replacement of drupal-composer/drupal-project.
  4. drupal/legacy-project: This Composer template generates a Drupal project following the traditional structure, where the whole project is in a single folder, like downloading the Drupal.org tarball. This is discouraged for 8.8+ projects.

All these Composer specific components can be found in the new /composer folder in Drupal core source code.

But the Composer support initiative is not only working on those projects that will be shipped along with Drupal core. They are currently working on some composer metapackages that will enhance Drupal developer experience among others:

  1. drupal/core-recommended: This is a metapackage that includes the specific versions of Drupal core dependencies for each Drupal version, in order to avoid conflicts and unexpected behaviors due to wrong dependency versions. This package is an official replacement for webflo/drupal-core-strict.
  2. drupal/dev-dependencies: This metapackage bundles all the necessary Drupal dependencies to run Drupal tests, so it is only necessary in case of running the Drupal test suite. This package is an official replacement for webflo/drupal-core-require-dev.

These metapackages and others are automatically generated using the package-generator tool or post-update hooks.
The full list of Drupal related composer packages can be found here: https://github.com/drupal.

Once all the new packages and Composer goodness have been introduced, it is time to see them in action. From now on, it is possible to create a new Drupal project just by typing:

composer -n create-project -s dev drupal/recommended-project my-project

This command generates a new Drupal project using the core-recommended-project template that will include the following components:

  1. drupal/core-recommend metapackage to include the right Drupal core version and all its dependencies
  2. drupal/dev-dependencies metapackage in case of Drupal tests will need to be run including all the necessary dependencies
  3. drupal/core-composer-scaffold plugin to place all the Drupal specific files like index.php in the right place, having vendor outside of the docroot

As you can see, all these new features included in Drupal 8.8 will bring the desired official Composer support in core and many other new improvements in the development cycle, like a better dependency control.

However, Drupal 8.8 is still in alpha phase and some new changes may be included in the list of features and tools above, so we encourage you to stay tuned and follow the Composer related issues in Drupal.org.

Finally we would like to say thank you to everyone who has been involved in this long and hard path to make Drupal development more accessible and open, especially to those involved in Drupal project that provided a route for everyone until Drupal core was ready.

We can’t wait for it. What about you?

References:

  1. https://www.drupal.org/about/strategic-initiatives/composer
  2. https://www.drupal.org/project/issues/search?issue_tags=composer%20initiative
  3. https://www.drupal.org/docs/develop/using-composer/using-drupals-composer-scaffold
  4. https://git.drupalcode.org/project/drupal/tree/8.8.x/composer
  5. https://github.com/drupal

Our expert

Pablo López Escobés

Pablo López Escobés

Any questions or input? Reach out to our experts!

Send e-mail

Drupal developer with more than 10 years of experience focused mainly in Back-end development and architecture definition. Part of the Cocomore team since 2017, he helps clients and team members to success in their goals. Open source enthusiast who enjoys sharing knowledge with the rest of the Drupal community. Sports and family lover when he is not in front of the computer.