Debian Codegraph @

vendor/wikimedia/composer-merge-plugin/README.md

raw
1 [![Latest Stable Version]](https://packagist.org/packages/wikimedia/composer-merge-plugin) [![License]](https://github.com/wikimedia/composer-merge-plugin/blob/master/LICENSE)
2 [![Build Status]](https://github.com/wikimedia/composer-merge-plugin/actions/workflows/CI.yaml)
3 [![Code Coverage]](https://scrutinizer-ci.com/g/wikimedia/composer-merge-plugin/?branch=master)
4
5 Composer Merge Plugin
6 =====================
7
8 Merge multiple composer.json files at [Composer] runtime.
9
10 Composer Merge Plugin is intended to allow easier dependency management for
11 applications which ship a composer.json file and expect some deployments to
12 install additional Composer managed libraries. It does this by allowing the
13 application's top level `composer.json` file to provide a list of optional
14 additional configuration files. When Composer is run it will parse these files
15 and merge their configuration settings into the base configuration. This
16 combined configuration will then be used when downloading additional libraries
17 and generating the autoloader.
18
19 Composer Merge Plugin was created to help with installation of [MediaWiki]
20 which has core library requirements as well as optional libraries and
21 extensions which may be managed via Composer.
22
23
24 Installation
25 ------------
26
27 Composer Merge Plugin 1.4.x (and older) requires Composer 1.x.
28
29 Composer Merge Plugin 2.0.x (and newer) is compatible with both Composer 2.x and 1.x.
30
31 ```
32 $ composer require wikimedia/composer-merge-plugin
33 ```
34
35 ### Upgrading from Composer 1 to 2
36
37 If you are already using Composer Merge Plugin 1.4 (or older) and you are updating the plugin to 2.0 (or newer), it is recommended that you update the plugin first using Composer 1.
38
39 If you update the incompatible plugin using Composer 2, the plugin will be ignored:
40
41 > The "wikimedia/composer-merge-plugin" plugin was skipped because it requires a Plugin API version ("^1.0") that does not match your Composer installation ("2.0.0"). You may need to run composer update with the "--no-plugins" option.
42
43 Consequently, Composer will be unaware of the merged dependencies and will remove them requiring you to run `composer update` again to reinstall merged dependencies.
44
45
46 Usage
47 -----
48
49 ```json
50 {
51 "require": {
52 "wikimedia/composer-merge-plugin": "dev-master"
53 },
54 "extra": {
55 "merge-plugin": {
56 "include": [
57 "composer.local.json",
58 "extensions/*/composer.json"
59 ],
60 "require": [
61 "submodule/composer.json"
62 ],
63 "recurse": true,
64 "replace": false,
65 "ignore-duplicates": false,
66 "merge-dev": true,
67 "merge-extra": false,
68 "merge-extra-deep": false,
69 "merge-replace": true,
70 "merge-scripts": false
71 }
72 }
73 }
74 ```
75
76 ### Updating sub-levels `composer.json` files
77
78
79 In order for Composer Merge Plugin to install dependencies from updated or newly created sub-level `composer.json` files in your project you need to run the command:
80
81 ```
82 $ composer update
83 ```
84
85 This will [instruct Composer to recalculate the file hash](https://getcomposer.org/doc/03-cli.md#update) for the top-level `composer.json` thus triggering Composer Merge Plugin to look for the sub-level configuration files and update your dependencies.
86
87
88 Plugin configuration
89 --------------------
90
91 The plugin reads its configuration from the `merge-plugin` section of your
92 composer.json's `extra` section. An `include` setting is required to tell
93 Composer Merge Plugin which file(s) to merge.
94
95
96 ### include
97
98 The `include` setting can specify either a single value or an array of values.
99 Each value is treated as a PHP `glob()` pattern identifying additional
100 composer.json style configuration files to merge into the root package
101 configuration for the current Composer execution.
102
103 The following sections of the found configuration files will be merged into
104 the Composer root package configuration as though they were directly included
105 in the top-level composer.json file:
106
107 * [autoload](https://getcomposer.org/doc/04-schema.md#autoload)
108 * [autoload-dev](https://getcomposer.org/doc/04-schema.md#autoload-dev)
109 (optional, see [merge-dev](#merge-dev) below)
110 * [conflict](https://getcomposer.org/doc/04-schema.md#conflict)
111 * [provide](https://getcomposer.org/doc/04-schema.md#provide)
112 * [replace](https://getcomposer.org/doc/04-schema.md#replace)
113 (optional, see [merge-replace](#merge-replace) below)
114 * [repositories](https://getcomposer.org/doc/04-schema.md#repositories)
115 * [require](https://getcomposer.org/doc/04-schema.md#require)
116 * [require-dev](https://getcomposer.org/doc/04-schema.md#require-dev)
117 (optional, see [merge-dev](#merge-dev) below)
118 * [suggest](https://getcomposer.org/doc/04-schema.md#suggest)
119 * [extra](https://getcomposer.org/doc/04-schema.md#extra)
120 (optional, see [merge-extra](#merge-extra) below)
121 * [scripts](https://getcomposer.org/doc/04-schema.md#scripts)
122 (optional, see [merge-scripts](#merge-scripts) below)
123
124
125 ### require
126
127 The `require` setting is identical to [`include`](#include) except when
128 a pattern fails to match at least one file then it will cause an error.
129
130 ### recurse
131
132 By default the merge plugin is recursive; if an included file has
133 a `merge-plugin` section it will also be processed. This functionality can be
134 disabled by adding a `"recurse": false` setting.
135
136
137 ### replace
138
139 By default, Composer's conflict resolution engine is used to determine which
140 version of a package should be installed when multiple files specify the same
141 package. A `"replace": true` setting can be provided to change to a "last
142 version specified wins" conflict resolution strategy. In this mode, duplicate
143 package declarations found in merged files will overwrite the declarations
144 made by earlier files. Files are loaded in the order specified by the
145 `include` setting with globbed files being processed in alphabetical order.
146
147 ### ignore-duplicates
148
149 By default, Composer's conflict resolution engine is used to determine which
150 version of a package should be installed when multiple files specify the same
151 package. An `"ignore-duplicates": true` setting can be provided to change to
152 a "first version specified wins" conflict resolution strategy. In this mode,
153 duplicate package declarations found in merged files will be ignored in favor
154 of the declarations made by earlier files. Files are loaded in the order
155 specified by the `include` setting with globbed files being processed in
156 alphabetical order.
157
158 Note: `"replace": true` and `"ignore-duplicates": true` modes are mutually
159 exclusive. If both are set, `"ignore-duplicates": true` will be used.
160
161 ### merge-dev
162
163 By default, `autoload-dev` and `require-dev` sections of included files are
164 merged. A `"merge-dev": false` setting will disable this behavior.
165
166
167 ### merge-extra
168
169 A `"merge-extra": true` setting enables the merging the contents of the
170 `extra` section of included files as well. The normal merge mode for the extra
171 section is to accept the first version of any key found (e.g. a key in the
172 master config wins over the version found in any imported config). If
173 `replace` mode is active ([see above](#replace)) then this behavior changes
174 and the last key found will win (e.g. the key in the master config is replaced
175 by the key in the imported config). If `"merge-extra-deep": true` is specified
176 then, the sections are merged similar to array_merge_recursive() - however
177 duplicate string array keys are replaced instead of merged, while numeric
178 array keys are merged as usual. The usefulness of merging the extra section
179 will vary depending on the Composer plugins being used and the order in which
180 they are processed by Composer.
181
182 Note that `merge-plugin` sections are excluded from the merge process, but are
183 always processed by the plugin unless [recursion](#recurse) is disabled.
184
185 ### merge-replace
186
187 By default, the `replace` section of included files are merged.
188 A `"merge-replace": false` setting will disable this behavior.
189
190 ### merge-scripts
191
192 A `"merge-scripts": true` setting enables merging the contents of the
193 `scripts` section of included files as well. The normal merge mode for the
194 scripts section is to accept the first version of any key found (e.g. a key in
195 the master config wins over the version found in any imported config). If
196 `replace` mode is active ([see above](#replace)) then this behavior changes
197 and the last key found will win (e.g. the key in the master config is replaced
198 by the key in the imported config).
199
200 Note: [custom commands][] added by merged configuration will work when invoked
201 as `composer run-script my-cool-command` but will not be available using the
202 normal `composer my-cool-command` shortcut.
203
204
205 Running tests
206 -------------
207
208 ```
209 $ composer install
210 $ composer test
211 ```
212
213
214 Contributing
215 ------------
216
217 Bug, feature requests and other issues should be reported to the [GitHub
218 project]. We accept code and documentation contributions via Pull Requests on
219 GitHub as well.
220
221 - [PSR-2 Coding Standard][] is used by the project. The included test
222 configuration uses [PHP_CodeSniffer][] to validate the conventions.
223 - Tests are encouraged. Our test coverage isn't perfect but we'd like it to
224 get better rather than worse, so please try to include tests with your
225 changes.
226 - Keep the documentation up to date. Make sure `README.md` and other
227 relevant documentation is kept up to date with your changes.
228 - One pull request per feature. Try to keep your changes focused on solving
229 a single problem. This will make it easier for us to review the change and
230 easier for you to make sure you have updated the necessary tests and
231 documentation.
232
233
234 License
235 -------
236
237 Composer Merge plugin is licensed under the MIT license. See the
238 [`LICENSE`](LICENSE) file for more details.
239
240
241 ---
242 [Composer]: https://getcomposer.org/
243 [MediaWiki]: https://www.mediawiki.org/wiki/MediaWiki
244 [GitHub project]: https://github.com/wikimedia/composer-merge-plugin
245 [PSR-2 Coding Standard]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
246 [PHP_CodeSniffer]: http://pear.php.net/package/PHP_CodeSniffer
247 [Latest Stable Version]: https://img.shields.io/packagist/v/wikimedia/composer-merge-plugin.svg?style=flat
248 [License]: https://img.shields.io/packagist/l/wikimedia/composer-merge-plugin.svg?style=flat
249 [Build Status]: https://github.com/wikimedia/composer-merge-plugin/actions/workflows/CI.yaml/badge.svg
250 [Code Coverage]: https://img.shields.io/scrutinizer/coverage/g/wikimedia/composer-merge-plugin/master.svg?style=flat
251 [custom commands]: https://getcomposer.org/doc/articles/scripts.md#writing-custom-commands