How do I apply a patch with Composer workflow?
The issue is that composer is applying patches using git apply which is not working for packages that are not installed from source.

Therefore the solution is to install the packages from source. This way the package will fetch the package along with its repository (when available) thus enabling it to be patched.

So...

How to install/update a package from source

For new packages:

Use

composer require vendor/package --prefer-source


For existing packages

If your package is already installed then you need to delete it so that you can re-fetch it with composer install (there is no composer reinstall command). Do so and then use

composer install vendor/package --prefer-source


Set it as the default behavior

You can also set it up as the default behavior for the project in the config section of composer.json:

"config": {
      "preferred-install": "source"
    },


Update:

Set it as the default behavior for a specific package

In case you don't want to set your entire project to install from source, you can do so for a specific package only. To do so you need to specify the VCS Branch in the Version constrain of the package.

"require": {
        "vendor/package": "dev-branch#branch-hash"
}