Upgrading from Drupal 9 to Drupal 10

Let’s prepare:

composer config -g allow-plugins.mglaman/composer-drupal-lenient true
composer config -g allow-plugins.chx/jump true
composer config -g allow-plugins.chx/drupal-issue-fork true
composer require mglaman/composer-drupal-lenient chx/jump chx/drupal-issue-fork
composer jump
rm composer.lock
git commit -am 'd10 prepare'

Now try composer install.

if you run into errors, some of your contrib is not D10 ready. Note I found composer error messages to be completely useless when the lock file is present, they are somewhat useful when it is not: it will contain the name of the offending module somewhat close to the bottom.

Reset with rm composer.lock and edit composer.json so the module installs. These composer edits can be done by composer itself. Visit the drupal.org home of the project and look around.

  1. Sometimes, there is a D10 compatible version but it’s not marked latest.

    composer require --no-update 'drupal/elasticsearch_connector:^7.0@alpha'
    If this is not the case, continue to the issue queue.
  2. A patch is preferred because it makes updates still possible and so when it no longer applies the patch can simply be removed:

    composer config --merge --json extra.patches.drupal/encryption '{"D10": "patches/encryption/d10.patch"}'
    composer config --merge --json extra.drupal-lenient.allowed-list '["drupal/encryption"]'
  3. Do not use merge diffs from drupal directly like https://git.drupalcode.org/project/encryption/-/merge_requests/4.diff because that leads to a supply change attack. Instead, save the patch locally and apply as above.

  4. Issue forks can be used instead of patches but while patches will self report when they are no longer needed in the future, forks do not. But if the project needs composer.json changes to install with D10 there’s no choice. The composer.json changes are described in the handbook. As noted there, there’s a plugin to automate this too:

    composer drupal-issue-fork https://git.drupalcode.org/issue/brandfolder-3286340/-/tree/3286340-automated-drupal-10

    Later, when the branch has been merged, you can run composer drupal-issue-unfork brandfolder to remove the issue fork and upgrade the version to the latest. This command also merely edits composer.json.

Now commit the new composer.json, I like git commit --amend -a -C HEAD but of course separate commits for each edit also work.

Now repeat the install until success.

If you follow the real best practices, don’t forget to git add vendor/mglaman vendor/chx at prepare and do a git clean -f vendor web/modules web/core web/libraries web/themes after reset.


Date
October 28, 2023