PHP

Composer 2.0 is now available!

Dial 2.0 what's up? The list of changes and improvements is long, check the full changelog if you want to read everything. I will highlight a few key points here. Improving Composer Performance The packagist teams have reworked almost everything, from the protocol used between Composer and packagist.org to the resolution

Laurent LOUIS-THERESE · · 9 min de lecture

What’s new in Composer 2.0?

The list of changes and improvements is long, see changelog complete if you want to read everything. I will highlight a few key points here.

Improving the performance of Composer

Teams packagist reworked almost everything, from the protocol used between Composer and packagist.org to the resolution of dependencies, to the uploading of files in parallel with the help of curl and the optimizations of stress assessment. This leads to massive improvements in speed and memory usage. The difference depends on your use case. Although I have seen reports of improvements of more than 50% in both cases in some projects, I cannot give an exact figure. But I'm sure you'll be pleasantly surprised if you haven't tried Composer 2.

In addition, requests/deletions and partial updates are now much faster because Compose now only loads the metadata of the packages being modified.

The time required for initial update and installation (started project, empty cache) is about 60% lower than that used by Compose 2 with ext-curl enabled.

Architectural changes and determinism

The way dependencies are updated internally has been redesigned, which for you will result in more deterministic updates. The current local status of the vendor directory will no longer interfere with updates.

Once the update is complete, the installation process is started automatically and will now run all network-related operations first – and in parallel if possible. This will avoid leaving you with a half-updated provider directory if a network error occurs in the middle of the installation.

Executing functions

We added a platform check step when initializing seller/autoload.php that checks that the current version of PHP (and possibly extensions) matches what is expected by your dependencies and fails otherwise. This step is enabled by default, so make sure you get to know it to avoid surprises.

There is a new class, Composer\InstalledVersion, which is self-loaded in each project and is available for execution. It allows you to check which packages/versions are present at the time of running your own project.

See Runtime documentation for more details.

If your code is based on one of these running features, you must require "compress-runtime-api": " ^2.0" in your composing.json. This is a virtual package provided by Composer that ensures that users need to use Compose 2.x to install your package.

Improved error reporting

Because things don't always happen as they should, the project's devs have made sure to improve the error ratio that is presented to you when dependencies cannot be solved. It is difficult to give concrete examples here, because there are a million ways that this can fail, but you will notice that the messages are now shorter, clearer and less repetitive.

Partial updates with temporary constraints

Sometimes it may be useful to upgrade or downgrade a single package to a specific version, perhaps temporarily to test something or wait for bug fixes. Good news! You can now run compose update seller/package:1.0.* for example (or 1.0.12 or any other version constraint), to run a vendor/package update only to a version corresponding to this additional constraint. This will not update your requirement in compose.json and will not mark the lock file as outdated.

If you want to add/restrict a constraint while performing a full update of all dependencies, you can use update –with vendor/package:1.0.* that will run the update with this additional constraint.

Is the upgrade to compose 2 easy?

The goal of packagist is that each Composer user can perform a smooth and fast upgrade. The gains are huge and the largest number of developer php You can take advantage of it. In order to achieve this, a number of measures are still needed:

Compose 2.0 always supports PHP 5.3 and more, just like Compose 1.x. The composer.lock files are interoperable between versions, so you can switch to version 2.0 and back easily if necessary. Most commands and arguments remain the same, and most of what you know about Composer remains true in version 2.0. If you run self-update from version 1.x, it will warn you that a new, stable major version of Composer is available and that you can use compose self-update –2 to migrate to it. You can find specific instructions for various frameworks/CMSs/applications on GitHub which can help you perform the upgrade.

If you encounter problems, you can go back at any time using compose self-update –1. I hope that this will allow everyone to feel comfortable to experience the new version.

If you install Compose automatically from the installation script and want to stay on Compose 1.x at the moment, you can also pass it an argument –1 to prevent you from installing Compose 2.0 by default. In this case, don't forget to update in due course, because Composer 1.x will not be maintained for very long.

See "self-update" command is not set. - What? If you have installed Compose via the package manager of your operating system, the self-update command may not be available. Use which composer to find his path (e.g. /usr/bin/compose), then run the installation script by adding –install-dir /usr/bin –filename composer (by adjusting the installation directory to match your path) to the php composer-setup.php line.

Any retrocompatibility problems?

Key elements that may cause problems in the upgrade process include:

  • Plugins: This is probably the main source of problems for most people. Plugins need to be updated to support Composer 2, and some of them are not yet ready. Composing 2 will complain and won't solve dependencies if a plugin doesn't support it, so no need to think too much, you can try it and see how it goes.
  • The new platform verification function means that Compose checks the PHP run version and (possibly) the available extensions to ensure that they match the project dependencies. If an incompatibility is found, the self-loader ends with the error details to ensure that the problems are not overlooked. To avoid problems when deploying in production, it is recommended to run check-platform-reqs with the PHP production process as part of your construction or deployment process.
  • Repository Priority: If a package exists in a higher priority repository, it will now be completely ignored in the lower priority repository. If you seem to miss packages when using Composer 2, see the repository priority documentation for more details.

Invalid PSR-0 / PSR-4 configurations will no longer automatically load in optimized mode, according to the warnings introduced in Composer 1.10. Most of these warnings were about classes that weren't supposed to automatically load anyway, so I don't expect major problems, but it's safer to clean them up before the upgrade. If you would like to know more, I strongly recommend reading the guide UPGRADE which has several sections for end users, plugin authors and those responsible for implementing the Composer repository.

What's the next step?

We no longer have a detailed roadmap of the features, because version 2.0 contains tons of new features, but there is one important thing I want to explain: the support of the PHP version in the future.

As I mentioned above, Composer 2.0 supports PHP 5.3+, which to date is very obsolete and makes the code difficult to maintain in places. We have endeavoured to ensure that each Composer user can switch to Composer 2, but we plan to abandon support for obsolete PHP versions in a future minor version.

Compose 2.1 will continue to support PHP 5.3, but for Compose 2.2, we will remove support for all versions prior to PHP 7.1.3 or PHP 7.2.5 depending on the release date (to be determined). According to our statistics, this allows more than 90% of Composer users to use the latest version, and for others that are blocked on obsolete PHP versions, we will continue to provide bug fixes and critical security in the range 2.0.x or 2.1.x.

As for Composer 1.x, it is now more or less EOL. It will also receive critical fixes in case of problem, but the goal of each should be to migrate to version 2.x as soon as possible.