HomePhabricator

Add support for Composer v2

Description

Add support for Composer v2

In Composer v2, packages are solved first (dev and non-dev), then the lock file is written, then packages (dev and/or non-dev) are installed/updated/removed. As such, the closest alternative to the retired PRE_DEPENDENCIES_SOLVING is the new PRE_POOL_CREATE (and not PRE_OPERATIONS_EXEC as has been attempted in various plugins).

The use of PRE_DEPENDENCIES_SOLVING in the merge-plugin is used to inject duplicate requirements (usually with a different version constraints) into the solver (while distinguishing between require and require-dev).

To support Composer v1 and v2 without overcomplicating things, this commit replaces duplicate link tracking in ExtraPackage by back porting Composer 2's new static MultiConstraint::create() method which can be used to resolve complex-constraints early on. In turn, this makes the need for PRE_DEPENDENCIES_SOLVING obsolete.

Bug: T248908

Added:

  • Allow either ^1.1 or ^2.0 composer-plugin-api
  • New PluginInterface methods
  • New MultiConstraint back port from Composer v2 for v1

Changed:

  • Replaced PluginState::$duplicateLinks with MultiConstraint to merge requirements and constraints in ExtraPackage::mergeOrDefer() instead of during PRE_DEPENDENCIES_SOLVING
  • Locking condition on POST_PACKAGE_INSTALL to force update in Composer v2
  • Testing of POST_PACKAGE_INSTALL to reflect forced update in Composer v2
  • Mocking of VcsRepository to support HttpDownloader for Composer v2

Removed:

  • Event PRE_DEPENDENCIES_SOLVING and method MergePlugin::onDependencySolve() since ExtraPackage::mergeOrDefer() handles duplicate package constraints
  • Mocked event PRE_DEPENDENCIES_SOLVING in MergePluginTest::triggerPlugin() since duplicates are no longer tracked
  • Assertions for obsolete $extraInstalls from MergePluginTest::triggerPlugin()

Details

Provenance
Chauncey McAskill <chauncey@mcaskill.ca>Authored on Sep 27 2020, 3:59 PM
Parents
rGCMP679b55df92c7: Revert lock file when extra composer update failed to complete
Branches
Unknown
Tags
Unknown
ChangeId
None

Event Timeline

Chauncey McAskill <chauncey@mcaskill.ca> committed rGCMPca478350dbb8: Add support for Composer v2 (authored by Chauncey McAskill <chauncey@mcaskill.ca>).Feb 5 2021, 2:07 AM