Skip to content
Snippets Groups Projects
Commit 747c518f authored by Wim Leers's avatar Wim Leers Committed by Adam G-H
Browse files

Issue #3363259 by Wim Leers, tedbow, phenaproxima, omkar.podey: Compatibility with Composer 2.5.7

parent 8a8cbe83
No related branches found
Tags 3.0.0-alpha2
No related merge requests found
......@@ -11,8 +11,8 @@ build:
commands:
# Install rsync.
- DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y rsync
# Update to Composer 2.5.5.
- composer self-update 2.5.5
# Update to latest Composer.
- composer self-update
# @todo Replace in favor of commit-code-check.sh once https://www.drupal.org/project/drupal/issues/3314100 lands.
- modules/contrib/automatic_updates/scripts/commit-code-check.sh --drupalci
halt-on-fail: true
......
......@@ -317,23 +317,35 @@ class ComposerInspector implements LoggerAwareInterface {
$packages_data = $this->getPackageTypes($packages_data, $working_dir);
foreach ($packages_data as $name => $package) {
$path = realpath($package['path']);
$path = $package['path'];
// We expect Composer to report that metapackages' install paths are the
// same as the working directory, in which case InstalledPackage::$path
// should be NULL. For all other package types, we consider it invalid
// if the install path is the same as the working directory.
if ($package['type'] === 'metapackage') {
if ($path === $working_dir) {
$packages_data[$name]['path'] = NULL;
// @todo Remove this handling of metapackage paths when Composer 2.5.7 or
// later is required, in https://drupal.org/i/3365133.
if (isset($package['type']) && $package['type'] === 'metapackage') {
// TRICKY: until Composer 2.5.6, metapackages returned the current
// working directory instead of NULL.
// @see https://github.com/composer/composer/commit/3a48e393756e8b0387925aa327f45a30128b4556
$packages_data[$name]['path'] = NULL;
// @todo Remove the if-branch when the minimum Composer version is raised to >=2.5.6.
if (Semver::satisfies($this->getVersion(), '<2.5.6')) {
if ($path !== $working_dir) {
throw new \UnexpectedValueException("Metapackage '$name' is installed at unexpected path: '$path', expected '$working_dir'");
}
}
else {
throw new \UnexpectedValueException("Metapackage '$name' is installed at unexpected path: '$path', expected '$working_dir'");
elseif ($path !== NULL) {
throw new \UnexpectedValueException("Metapackage '$name' is installed at unexpected path: '$path', expected NULL");
}
}
elseif ($path === $working_dir) {
throw new \UnexpectedValueException("Package '$name' cannot be installed at path: '$path'");
}
else {
$packages_data[$name]['path'] = realpath($path);
}
}
$packages_data = array_map(InstalledPackage::createFromArray(...), $packages_data);
......
......@@ -40,9 +40,12 @@ final class InstalledPackage {
*/
public static function createFromArray(array $data): static {
$path = isset($data['path']) ? realpath($data['path']) : NULL;
assert(($data['type'] === 'metapackage') === is_null($path), 'Metapackage install path must be NULL.');
// Fall back to `library`.
// @see https://getcomposer.org/doc/04-schema.md#type
$type = $data['type'] ?? 'library';
assert(($type === 'metapackage') === is_null($path), 'Metapackage install path must be NULL.');
return new static($data['name'], $data['version'], $path, $data['type']);
return new static($data['name'], $data['version'], $path, $type);
}
/**
......
......@@ -348,8 +348,8 @@ class ComposerInspectorTest extends PackageManagerKernelTestBase {
*
* @covers ::getInstalledPackagesList
*
* @testWith [true, "<PROJECT_ROOT>", null]
* [true, "<PROJECT_ROOT>/another/directory", "Metapackage 'test/package' is installed at unexpected path: '<PROJECT_ROOT>/another/directory', expected '<PROJECT_ROOT>'"]
* @testWith [true, null, null]
* [true, "<PROJECT_ROOT>/another/directory", "Metapackage 'test/package' is installed at unexpected path: '<PROJECT_ROOT>/another/directory', expected NULL"]
* [false, null, null]
* [false, "<PROJECT_ROOT>", "Package 'test/package' cannot be installed at path: '<PROJECT_ROOT>'"]
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment