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
Autoloader generation happens too late #7298
Comments
My understanding it is likely a Composer bug or a gap in its workflow. It is also possible that one of the packages: |
FYI: My project is Drupal site and I update from Drupal core |
I'm running the latest stable version of Composer (1.6.4). Plus I'm running the commands in my Travis CI before the $ composer self-update
You are already using composer version 1.6.4 (stable channel).
$ composer validate --no-check-all --ansi
./composer.json is valid |
Further investigation of I can see that the Uninstall operations are being moved before the Installe or Update operations: https://github.com/composer/composer/blob/1.6.4/src/Composer/Installer.php#L498 It would be probably sensible to run the P.S. The workaround having the |
The issue seems related to |
As a workaround I solved the problem by putting the: "scripts": {
"pre-package-install": "composer dump-autoload"
} into the project's From what I observed: When a package is removed or updated, the Autoloader files might get out of sync (containing path that doesn't exist anymore) and the Autloader is not udpated before the What I believe Composer should do is to keep track when a package using Autoloading (defining classes with Autoloader) is removed/updated and rebuild Autoloader in case soma package is going to use Custom Installer or any call that is going to use Autoloader. Thanks @stof for your comment. I've already used a workaround and I do not have a time right now to go back and replicate the problem again, but the best log I have is here (the error happens at the time when the Custom Installer is run by
|
This is still biting us a lot. Can someone help us here? We have troubles even with the workaround of running I believe this is a genuine composer bug. |
Composer does generate an in-memory autoloader for script/plugins when needed, but indeed we don't dump a new on disk autoloader until everything is complete. The only way to fix this here would be to re-dump after every installation like you do, which is really inefficient. The issue here as I understand it is not that you use a custom installer, because that shouldn't load the autoloader from vendor dir, but rather that you are executing php-cs during installation, and php-cs does include the autoloader that's in vendor dir and in a stale state. Could you delay the php-cs execution until after the whole install including autoload dumping was done? |
Hi @Seldaek, Thank you for your reply, it brings some light here. The Do I understand it right that it is a bug in Is there any documentation saying that: "custom installers are not meant to use the autoloader"? It whould help me to stress out that the |
There is no documentation about that, but it breaks the composer lifecycle and as such is a bad idea. You can link them here. That said, from a quick glance at the code it appears to only react to post-install-cmd and post-update-cmd events, which should happen late enough that the autoloader has been dumped. So I am wondering if you're using an outdated version of that plugin, or if you perhaps have done something else in your code to trigger this problem. Maybe I'm just missing something though. |
I'm using the currently latest stable version I do not not understand the EDIT: I've created an issue in |
@Seldaek I found the issue (and commented on the plugin issue). It does not only run phpcs on the |
I have a project with a standard
master
branch and anupdate
feature branch that contains somecomposer.json
andcomposer.lock
changes.The main chagnes in my
update
branch are:ircmaxell/password-compat
(version1.0.4
) is removed (https://github.com/ircmaxell/password_compat).dealerdirect/phpcodesniffer-composer-installer
(version0.4.4
) is added (https://github.com/Dealerdirect/phpcodesniffer-composer-installer).When I preform the following sequence of steps:
master
branch (no updates applied yet) and run thecomposer install
.update
branch and run thecomposer install
.I get the following Symfony exception:
I investigated it and found the cause:
/var/www/my-project/vendor/composer/autoload_files.php
) contains the line with/ircmaxell/password-compat/lib/password.php
requirement as the packageircmaxell/password-compat
is installed.ircmaxell/password-compat
is removed, but because the process is not finished yet, the Autoloader Files (/var/www/my-project/vendor/composer/autoload_files.php
) are not regenerated as yet. Thedealerdirect/phpcodesniffer-composer-installer
package is installed and as it uses a Custom Installer: https://github.com/Dealerdirect/phpcodesniffer-composer-installer/blob/v0.4.4/composer.json#L44 as explained in here: https://getcomposer.org/doc/articles/custom-installers.md#composer-json, it runs the Autoloader that uses Autoloader Files, but the/var/www/sites/my-project/vendor/composer/../ircmaxell/password-compat/lib/password.php
doesn't exists any more.I'm looking for the solution:
This is causing my Travis CI build to fail (I was able to replicate it on my local environement as well) and I can't separate it into more fine grained steps as I need it in one deployment step to PROD.
I understand that the Autoloader regeneration happens at the end of
composer install
run, but it is too late.The
composer dump-autoload
doesn't help as running it beforecomposer install
is no good and I don't know how to inject it into thecomposer install
process after theircmaxell/password-compat
package is removed.I may try some one time workaround by not allowing the
dealerdirect/phpcodesniffer-composer-installer
package to run its Custom Installer or to require theircmaxell/password-compat
and not removing it, even though it is not required any more and remove it later on.None of the workarounds mentioned above is a clean solution that would work all the time.
Output of
composer diagnose
:The text was updated successfully, but these errors were encountered: