Patches are not applied if composer is run with --no-scripts
Running composer with --no-scripts is very common when the dependencies are fetched in a build context (ie: Dockerfile).
The patches are not applied when running composer with --no-scripts, which makes impossible to use patches in these cases.
This may also explain the lots of issues people open in this project about inconsistencies and patches not being applied "randomly".
Hello,
Could you find a workaround to execute patches even with no-script ?
I found myself try to look for event that could dispatch the patching script or use the module https://github.com/szeidler/composer-patches-cli, but i couldn't find a way to do so.
This doesn't seem like a composer patches bug. If composer doesn't call the methods this plugin defines, there's not much we can do..
@cweagans we can open an issue upstream (composer project). From your knowledge, do you know which events are not fired in this context?
We are also concerned by this issue and I will be happy to help finding a solution.
These ones: https://github.com/cweagans/composer-patches/blob/1.x/src/Patches.php#L71-L82
I think the solution here is to just not run composer with --no-scripts, tbh.
FWIW in our deployment pipeline found also these problems:
- Cache/build artifacts contained
vendorfolder with dependency-to-patch. As there was no need to install/update for composer the eventsPRE/POST_PACKAGE_INSTALL/UPDATEare not triggered. - Running with
--no-scriptsas there are more scripts that are not necessary or intended to run in CI.
It would be nice if we could explicitly trigger patching / re-applying a patch by something like composer apply-patches.
Same here.
When we are building to prepare a deploy we don't want to run symfony's cache:clear etc. So we set --no-scripts
However when working locally those script should still fire. I don't want to have each dev go back to running those scripts manually.
Being able to do composer run apply-patches or something would be a great help.
I came across this post which was the solution for me: https://stackoverflow.com/a/53022623
Documentation reads: During a composer install or update process, a variable named COMPOSER_DEV_MODE will be added to the environment. If the command was run with the --no-dev flag, this variable will be set to 0, otherwise it will be set to 1.
An example could look like
"scripts": {
"post-install-cmd": [
"[ $COMPOSER_DEV_MODE -eq 0 ] || <your command>"
]
}
isn't this just "solved" with latest composer-patches (1.7.1) and composer 2.1 ?
This does seem solved at least with the latest versions of composer-patches and composer. Make sure that cweagans/composer-patches is in require and not require-dev. If you got here via simplify/vendor-patches, you need to require composer-patches manually and not use it as a dependency.
This appears to be resolved.