Composer 2 is almost here, and lots of people would like to try it out. See @ultimike's blog and PHPWatch article
We plan to have Composer 2 in the web container as soon as it's released, but we'd love to have your reports right now about how it works for you, and any information about compatibility issues.
You can already use Composer 2 with DDEV-Local, there are two different ways.
ddev exec: Just try it out (and lose it when you stop the project): ddev exec sudo composer self-update --snapshot - then you can use ddev composer (or composer inside the web container) as long as the session lasts (until you ddev stop or ddev poweroff or whatever. ddev start - you'll have composer 2 every time you start the project:ARG BASE_IMAGE
FROM $BASE_IMAGE
RUN composer self-update --snapshot
hooks:
post-start:
- exec: sudo composer self-update --snapshot
I tested the self-update process recently while developing a v2 composer plugin. Seemed to work fine. But there are still a lot of plugins that don't support it yet. Have we considered having a composer and composer2 command as distinct options for this bridge time?
While I see some benefit to that, it also isn't clear how long we'd have to keep both and its always easy to add something and more difficult to remove it later.
I tried it out with suggestion 1.) but it didn't appear to be fully compatible with cweagans/composer-patches
For example:
ddev composer require drupal/bootstrap
Using version ^3.23 for drupal/bootstrap
./composer.json has been updated
Running composer update drupal/bootstrap
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Root composer.json requires cweagans/composer-patches 9999999-dev, found cweagans/composer-patches[dev-master] but it conflicts with another require.
Use the option --with-all-dependencies to allow upgrades, downgrades and removals for packages currently locked to specific versions.
You are using a snapshot build of Composer 2, which may be the cause of the problem. Run composer self-update --stable and then try again. In case it solves the problem, please report an issue mentioning Composer 2.
The latest cweagans/composer-patches, version 1.6.7 is not compatible with composer 2.
https://packagist.org/packages/cweagans/composer-patches
composer-plugin-api: ^1.0
But the the fix (composer 2 compatibility) is already committed.
https://github.com/cweagans/composer-patches/pull/321/files
So for now, you need "cweagans/composer-patches": "dev-master" in your composer.json file to use it with composer 2.
Have we considered having a
composerandcomposer2command as distinct options for this bridge time?
In that case composer1 command is needed also, as the composer command should default to v2 soon.
I'm assuming that both composer1 and composer2 will need to be bundled. Probably composer2 will have to be a separate option for some time, because there will be many packages that are incompatible for quite some time.
I like the idea of adding an option into .ddev/config.yaml that will install composer 2 if desired (just using the temp Dockerfile technique, same as webimage_extra_packages) and then gradually move it to where composer 2 is the default.
Ooops, the idea in https://github.com/drud/ddev/issues/2383#issuecomment-698557484 would be incompatible with uses of Dockerfile, which wouldn't be acceptable.
Since a new composer version has just dropped people are asking about how to update the version again, see #2563, I should mention these things:
So:
.ddev/web-build/Dockerfile:
ARG BASE_IMAGE
FROM $BASE_IMAGE
RUN composer self-update
That runs only once (on image build), and may result in different versions for your team depending on when they do their first ddev start
so better is
ARG BASE_IMAGE
FROM $BASE_IMAGE
RUN composer self-update 1.10.15
or for composer 2:
ARG BASE_IMAGE
FROM $BASE_IMAGE
RUN composer self-update 2.0.0-RC2
You can also do the same with a post-start hook, but then it runs on every start
Relevant and useful article: Preparing your site for Composer 2
https://www.drupal.org/docs/develop/using-composer/preparing-your-site-for-composer-2
Just a followup note that composer 2 is fully supported in ddev v1.16. ddev config --composer-version=2 for example, followed by ddev start. The default composer version remains v1.
Most helpful comment
I tested the self-update process recently while developing a v2 composer plugin. Seemed to work fine. But there are still a lot of plugins that don't support it yet. Have we considered having a
composerandcomposer2command as distinct options for this bridge time?While I see some benefit to that, it also isn't clear how long we'd have to keep both and its always easy to add something and more difficult to remove it later.