Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Composer 2 plugin autoloading #10413

Closed
bytestream opened this issue Dec 31, 2021 · 6 comments
Closed

Composer 2 plugin autoloading #10413

bytestream opened this issue Dec 31, 2021 · 6 comments

Comments

@bytestream
Copy link

See PHPCSStandards/composer-installer#143

I believe this might be a composer bug as it shouldn't be autoloading application dependencies which is what produces the conflict? The plugin uses composer dependencies, and the stack trace seems to show Composer autoloading the application dependency version of symony/finder?

I've observed the issue in Composer 2.0.6, 2.1.10, 2.1.14. Most of the time it works, sometimes it fails, always in the context of CI docker images.

@Seldaek
Copy link
Member

Seldaek commented Jan 1, 2022

This should be resolved soon as we migrate to Symfony 5.4, but anyway this should only happen if a plugin depends on symfony/finder, or if you have a php script handler in your composer.json. And in those cases we just have to load the application dependencies to avoid all sorts of other problems, but that sometimes does cause glitches with our deps.

You didn't really provide enough info though so I have no idea what the exact cause is. The "sometimes" is weird though, there's probably a pattern you didn't identify yet.

@bytestream
Copy link
Author

bytestream commented Jan 1, 2022

Thanks for the insight @Seldaek

This is composer.json scripts:

    "scripts": {
        "lint:analyse": [
            "Composer\\Config::disableProcessTimeout",
            "@php vendor/bin/phpcs --standard=phpcs.xml --report=json . > storage/phpcs.txt",
            "@php vendor/bin/sarb remove-baseline storage/phpcs.txt phpcs.baseline storage/phpcs-baseline-removed.txt"
        ],
        "lint:fix": [
            "Composer\\Config::disableProcessTimeout",
            "@php artisan lint:fix"
        ],
        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
        ],
        "post-create-project-cmd": [
            "php -r \"copy('.env.example', '.env');\"",
            "php artisan key:generate"
        ],
        "phpstan": [
            "phpstan analyse --memory-limit=-1"
        ]
    },

So the post-autoload-dump script is what is loading the application dependencies, see https://github.com/laravel/framework/blob/3f5d3704507f278ffc1231c32a74f0eb86eb0584/src/Illuminate/Foundation/ComposerScripts.php#L41

@Seldaek
Copy link
Member

Seldaek commented Jan 1, 2022

Ah well yes that definitely looks like the root cause of the problem. Maybe you can run your CI with --no-autoloader to skip that and then run a separate dump-autoload command?

@bytestream
Copy link
Author

I'm pretty sure I don't actually need the dependency. It's coming via slevomat/coding-standard and I'm loading all necessary coding standards manually anyway...

Would using the new allow-plugins option fix it?

"allow-plugins": {
  "dealerdirect/phpcodesniffer-composer-installer": false,
  "composer/package-versions-deprecated": true
}

@Seldaek
Copy link
Member

Seldaek commented Jan 1, 2022

I am not sure if that'll help, as per the above comments the issue is in:

        "post-autoload-dump": [
            "Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
        ],

Nothing to do with the plugin as far as I can tell, the plugin is maybe just a symptom of the problem, so you can try disabling it and see if it helps hide the problem for now..

@bytestream
Copy link
Author

Would using the new allow-plugins option fix it?

I think this seems to have alleviated the issue. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants