wikimedia / composer-merge-plugin

Merge one or more additional composer.json files at Composer runtime
MIT License
923 stars 160 forks source link

Double inclusion of certain files which throws errors. #250

Closed KvngRicky closed 1 year ago

KvngRicky commented 1 year ago

Using { "extra": { "merge-plugin": { "include": [ "extensions/*/composer.json" ] } } sometimes gives error of the form

Fatal error: Cannot redeclare <some function/class> (previously declared in /extensions//:) in /extensions// on line when optimize-autoloader is true. EDIT: Also when optimize-autoloader is false.

I stripped down my MW-installation to the following MWE to demonstrate the issue:

EDIT: Here is an even more minimal example:

composer.json:

{ "name": "test/test", "require": { "wikimedia/composer-merge-plugin": "2.0.1", "test/dependency": "@dev" }, "repositories": [{ "type": "path", "url": "./test-dependency" }], "extra": { "merge-plugin": { "include": [ "extensions/*/composer.json" ] } } } test-dependency/composer.json:

{ "name": "test/dependency", "type": "mediawiki-extension", "require": { "composer/installers": "^2.0" }, "autoload": { "files": [ "Test.php" ] } } test-dependency/Test.php:

<?php

class Foo {}; END OF EDIT

composer.json:

{ "name": "test/test", "prefer-stable": true, "require": { "wikimedia/composer-merge-plugin": "2.0.1" }, "config": { "allow-plugins": { "wikimedia/composer-merge-plugin": true, "composer/installers": true } }, "extra": { "merge-plugin": { "include": [ "composer.local.json" ], "recursive": true, "merge-dev": false } } } composer.local.json:

{ "require": { "mediawiki/user-functions": "dev-REL1_35" }, "extra": { "merge-plugin": { "include": [ "extensions/*/composer.json" ] } } } index.php:

<?php define('MEDIAWIKI', '1.35'); define('NS_MEDIAWIKI', 2);

require_once DIR . '/vendor/autoload.php';

echo "When this is shown, the page is working"; With these files set up, reproduce the issue as follows:

Run composer update twice. Either run php -S localhost:8000 and then go to localhost:8000 in your browser, or just run php index.php. When you run composer update once, everything works, but when done twice it does not.

In this case the files ./vendor/composer/autoload_static.php and ./vendor/composer/autoload_files.php look something like

$vendorDir = dirname(DIR); $baseDir = dirname($vendorDir);

return array( '7bb4d66942ef8c1728c8f742a0d5639d' => $baseDir . '/extensions/UserFunctions/UserFunctions.php', '3661fc4b5b3581d0c7a3aa2f63bb491b' => $baseDir . '/extensions/UserFunctions/UserFunctions.php', ); and

class ComposerStaticInit722b29a9c891bd933c9e56337f7bb753 { public static $files = array ( '7bb4d66942ef8c1728c8f742a0d5639d' => DIR . '/../..' . '/extensions/UserFunctions/UserFunctions.php', '3661fc4b5b3581d0c7a3aa2f63bb491b' => DIR . '/../..' . '/extensions/UserFunctions/UserFunctions.php', ); / A lot more that I ommitted / } respectively. This forces composer to load these files two times, resulting in the error described above.

I use php version 7.4.30 and composer version 2.4.1.

wgevaert commented 1 year ago

Seems to be a duplicate/copy of this issue, I suggest this one should be closed

bd808 commented 1 year ago

Duplicate of #247