3 Simple patches plugin for Composer. Applies a patch from a local or remote file to any package required with composer.
5 Note that the 1.x versions of Composer Patches are supported on a best-effort
6 basis due to the imminent release of 2.0.0. You may still be interested in
7 using 1.x if you need Composer to cooperate with earlier PHP versions. No new
8 features will be added to 1.x releases, but any security or bug fixes will
13 Example composer.json:
18 "cweagans/composer-patches": "~1.0",
19 "drupal/drupal": "~8.2"
22 "preferred-install": "source"
27 "Add startup configuration for PHP server": "https://www.drupal.org/files/issues/add_a_startup-1543858-30.patch"
35 ## Using an external patch file
37 Instead of a patches key in your root composer.json, use a patches-file key.
42 "cweagans/composer-patches": "~1.0",
43 "drupal/drupal": "~8.2"
46 "preferred-install": "source"
49 "patches-file": "local/path/to/your/composer.patches.json"
55 Then your `composer.patches.json` should look like this:
61 "Patch title": "http://example.com/url/to/patch.patch"
67 ## Allowing patches to be applied from dependencies
69 If you want your project to accept patches from dependencies, you must have the following in your composer file:
74 "cweagans/composer-patches": "^1.5.0"
77 "enable-patching": true
84 There may be situations in which you want to ignore a patch supplied by a dependency. For example:
86 - You use a different more recent version of a dependency, and now a patch isn't applying.
87 - You have a more up to date patch than the dependency, and want to use yours instead of theirs.
88 - A dependency's patch adds a feature to a project that you don't need.
89 - Your patches conflict with a dependency's patches.
94 "cweagans/composer-patches": "~1.0",
95 "drupal/drupal": "~8.2",
96 "drupal/lightning": "~8.1"
99 "preferred-install": "source"
104 "Add startup configuration for PHP server": "https://www.drupal.org/files/issues/add_a_startup-1543858-30.patch"
108 "drupal/lightning": {
109 "drupal/panelizer": {
110 "This patch has known conflicts with our Quick Edit integration": "https://www.drupal.org/files/issues/2664682-49.patch"
118 ## Using patches from HTTP URLs
120 Composer [blocks](https://getcomposer.org/doc/06-config.md#secure-http) you from downloading anything from HTTP URLs, you can disable this for your project by adding a `secure-http` setting in the config section of your `composer.json`. Note that the `config` section should be under the root of your `composer.json`.
130 However, it's always advised to setup HTTPS to prevent MITM code injection.
132 ## Patches containing modifications to composer.json files
134 Because patching occurs _after_ Composer calculates dependencies and installs packages, changes to an underlying dependency's `composer.json` file introduced in a patch will have _no effect_ on installed packages.
136 If you need to modify a dependency's `composer.json` or its underlying dependencies, you cannot use this plugin. Instead, you must do one of the following:
137 - Work to get the underlying issue resolved in the upstream package.
138 - Fork the package and [specify your fork as the package repository](https://getcomposer.org/doc/05-repositories.md#vcs) in your root `composer.json`
139 - Specify compatible package version requirements in your root `composer.json`
143 If a patch cannot be applied (hunk failed, different line endings, etc.) a message will be shown and the patch will be skipped.
145 To enforce throwing an error and stopping package installation/update immediately, you have two available options:
147 1. Add `"composer-exit-on-patch-failure": true` option to the `extra` section of your composer.json file.
148 1. Export `COMPOSER_EXIT_ON_PATCH_FAILURE=1`
150 By default, failed patches are skipped.
152 ## Difference between this and netresearch/composer-patches-plugin
154 - This plugin is much more simple to use and maintain
155 - This plugin doesn't require you to specify which package version you're patching
156 - This plugin is easy to use with Drupal modules (which don't use semantic versioning).
157 - This plugin will gather patches from all dependencies and apply them as if they were in the root composer.json
161 A ton of this code is adapted or taken straight from https://github.com/jpstacey/composer-patcher, which is abandoned in favor of https://github.com/netresearch/composer-patches-plugin, which is (IMHO) overly complex and difficult to use.