composer-patches icon indicating copy to clipboard operation
composer-patches copied to clipboard

Patches are not applied if composer is run with --no-scripts

Open ghost opened this issue 6 years ago • 9 comments

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".

ghost avatar May 21 '19 13:05 ghost

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.

adrian-salas avatar Jul 23 '19 10:07 adrian-salas

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 avatar Jul 23 '19 14:07 cweagans

@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.

gido avatar Jul 23 '19 18:07 gido

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.

cweagans avatar Jul 23 '19 18:07 cweagans

FWIW in our deployment pipeline found also these problems:

  • Cache/build artifacts contained vendor folder with dependency-to-patch. As there was no need to install/update for composer the events PRE/POST_PACKAGE_INSTALL/UPDATE are not triggered.
  • Running with --no-scripts as 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.

buffcode avatar Feb 05 '21 12:02 buffcode

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.

RobinHoutevelts avatar Feb 25 '21 07:02 RobinHoutevelts

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>"
    ]
}

svanrintel avatar Jun 11 '21 12:06 svanrintel

isn't this just "solved" with latest composer-patches (1.7.1) and composer 2.1 ?

hansbogert avatar Jun 15 '21 14:06 hansbogert

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.

nesl247 avatar Jul 20 '22 15:07 nesl247

This appears to be resolved.

cweagans avatar Feb 07 '23 20:02 cweagans