deployer
deployer copied to clipboard
Use `--classmap-authoritative` on `composer install`
We had a recent discussion on Twitter, read the complete thread, it is interesting for non-Magento folks as well: https://twitter.com/PeterJaap/status/1481166381332807680?s=20
https://getcomposer.org/doc/articles/autoloader-optimization.md#optimization-level-2-a-authoritative-class-maps
This option says that if something is not found in the classmap, then it does not exist and the autoloader should not attempt to look on the filesystem according to PSR-4 rules.
This option makes the autoloader always return very quickly. On the flipside it also means that in case a class is generated at runtime for some reason, it will not be allowed to be autoloaded. If your project or any of your dependencies does that then you might experience "class not found" issues in production. Enable this with care.
I think "generating classes on runtime" is an edge case, were (as @peterjaap wrote on Twitter) "typos or wrong casing in class names vs file names." is not an edge case.
So what I think we should implement at least is an option to use optimization level 2/A or 2/B as per composer documentation and/or even set it as default.
Make sense. Let’s add it before v7 release.
Wanted to leave my vote for making option 2/A (authoritative class maps) the default :hand:
When this is implemented, the respective option should also be added to the dump-autoload calls in the Magento 2 recipe:
https://github.com/deployphp/deployer/blob/fb6f2154ef36f03e4e4b0644206b06722ee09fd8/recipe/magento2.php#L75-L77
Any volunteers to implement?
@peterjaap @sprankhub If you have time, feel free. I'm currently drowning and don't see light.
When this is implemented, the respective option should also be added to the
--dump-autoloadcalls in the Magento 2 recipe:https://github.com/deployphp/deployer/blob/fb6f2154ef36f03e4e4b0644206b06722ee09fd8/recipe/magento2.php#L75-L77
Checked the rest of the codebase, Magento 2 is the only recipe we need to edit!
Checked the rest of the codebase, Magento 2 is the only recipe we need to edit!
You only checked for composer dump-autoload calls, right? However, this would also need to be added to composer install calls (and theoretically to composer update commands, but they should not be present here ^^).
Any volunteers to implement?
I could have a look when I have some time, but I will need some help with testing. Plus, it should be clear how exactly this should be implemented before we start: Will we make --classmap-authoritative the new default? Should it be possible to disable it? Or should it be the other way round, so that you need to enable it if you want to use it?
Users already can override composer_options. Let’s just add it as new default.
You only checked for composer dump-autoload calls, right? However, this would also need to be added to composer install calls (and theoretically to composer update commands, but they should not be present here ^^).
Nope, I searched for {{bin/composer}} ^^
https://twitter.com/IvanChepurnyi/status/1481279298057162755?s=20
Can we check wether apcu is installed? If it is, we better use it 🙈 And if not we use classmaps?
Yeah the question is how willing @antonmedv is to potentially break other peoples' systems :stuck_out_tongue: --classmap-authoritative can indeed break systems. The issue with this is that it cannot be detected during the deployment, but only on the (potentially live) system after the deployment. Hence, maybe the solution suggested by @Schrank makes sense? If APCu is enabled, use it and if it is not, we use --classmap-authoritative (or nothing). What do you think, @antonmedv?
By the way, many in the Magento community used a deployer-based recipe by @jalogut before and there, --apcu is used:
https://github.com/jalogut/magento2-deployer-plus/blob/a8c4432a68a4ac442541f250577e6049abaed52b/recipe/magento_2_1/files.php#L17
+1 for making --classmap-authoritative the default.