Updating the DrupalEasy.com codebase to use Composer 2
After teaching folks how to use Composer effectively over the past couple of years, I figured it was time for me to (finally) update DrupalEasy.com to use Composer 2. I figured it would be a pretty easy process, and I was correct.
I've had a few people ask me about the process, so I thought I'd write up what it took to update this site to Composer 2. First a few facts about this codebase:
- Dependencies are committed to the project Git repository.
- The site is hosted on Pantheon.
- I use DDEV for local development.
So, the first step, prior to updating to Composer 2, is to ensure all plugins are ready for Composer 2. In this case of the DrupalEasy.com codebase, there were three Composer plugins to review:
- composer/installers - compatible with Composer 2 starting with 1.9.0
- cweagans/composer-patches - compatible with Composer 2 starting with 1.7.0
- topfloor/composer-cleanup-vcs-dirs - the "dev-composer-2" branch is compatible with Composer 2
So, while still using Composer 1, I did the following (on my local, of course):
composer update composer/installers
composer update cweagans/composer-patches
Then I manually edited the composer.json file and changed the version constraint for topfloor/composer-cleanup-vcs-dirs to: "topfloor/composer-cleanup-vcs-dirs": "dev-composer-2"
Then,
composer update topfloor/composer-cleanup-vcs-dirs
Once that was done, I updated my .ddev/config.yaml file to use:
composer_version: "2"
After restarting DDEV, I verified that all was well by updating a couple of Drupal modules (non-security related maintenance releases) before committing all changes and pushing up to Pantheon.
Obviously, the most important step is to ensure all of your Composer plugins are compatible with Composer 2 - just remember to do this prior to updating to Composer 2!