|
| 1 | +# Rule Matrix & Examples |
| 2 | + |
| 3 | +This page shows concrete, side‑by‑side examples of how each Chorale rule transforms package `composer.json` values using the root `composer.json` as input. |
| 4 | + |
| 5 | +Notes |
| 6 | +- Default is opt‑in: a key does nothing unless a rule is configured. |
| 7 | +- Per‑package overrides win over rules (via `targets[].composer_overrides`). |
| 8 | +- String values support simple template rendering in some cases (e.g., overrides): `{name}`, `{path}`, `{repo_vendor}`. |
| 9 | + |
| 10 | +## mirror |
| 11 | + |
| 12 | +Copies the root value into each package (package value is replaced). |
| 13 | + |
| 14 | +Rule |
| 15 | + |
| 16 | +```yaml |
| 17 | +composer_sync: |
| 18 | + rules: |
| 19 | + authors: mirror |
| 20 | + license: mirror |
| 21 | +``` |
| 22 | +
|
| 23 | +Input → Output |
| 24 | +
|
| 25 | +Root excerpt |
| 26 | +
|
| 27 | +```json |
| 28 | +{ |
| 29 | + "authors": [{ "name": "Sons of PHP" }], |
| 30 | + "license": "MIT" |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +Package before |
| 35 | + |
| 36 | +```json |
| 37 | +{ |
| 38 | + "authors": [{ "name": "Someone Else" }], |
| 39 | + "license": "Proprietary" |
| 40 | +} |
| 41 | +``` |
| 42 | + |
| 43 | +Package after (planned edits) |
| 44 | + |
| 45 | +```json |
| 46 | +{ |
| 47 | + "authors": [{ "name": "Sons of PHP" }], |
| 48 | + "license": "MIT" |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +## mirror-unless-overridden |
| 53 | + |
| 54 | +Uses the root value only when the package does not define the key. |
| 55 | + |
| 56 | +Rule |
| 57 | + |
| 58 | +```yaml |
| 59 | +composer_sync: |
| 60 | + rules: |
| 61 | + homepage: mirror-unless-overridden |
| 62 | + description: mirror-unless-overridden |
| 63 | +``` |
| 64 | +
|
| 65 | +Case A — package missing key (mirrors from root) |
| 66 | +
|
| 67 | +Root excerpt |
| 68 | +
|
| 69 | +```json |
| 70 | +{ "homepage": "https://sonsofphp.com" } |
| 71 | +``` |
| 72 | + |
| 73 | +Package before |
| 74 | + |
| 75 | +```json |
| 76 | +{ } |
| 77 | +``` |
| 78 | + |
| 79 | +Package after |
| 80 | + |
| 81 | +```json |
| 82 | +{ "homepage": "https://sonsofphp.com" } |
| 83 | +``` |
| 84 | + |
| 85 | +Case B — package has key (no change) |
| 86 | + |
| 87 | +Package before |
| 88 | + |
| 89 | +```json |
| 90 | +{ "homepage": "https://example.test/pkg" } |
| 91 | +``` |
| 92 | + |
| 93 | +Package after |
| 94 | + |
| 95 | +```json |
| 96 | +{ "homepage": "https://example.test/pkg" } |
| 97 | +``` |
| 98 | + |
| 99 | +## merge-object |
| 100 | + |
| 101 | +Deep‑merges the root object into the package object. Package values override root on conflicts; nested objects are merged recursively. |
| 102 | + |
| 103 | +Rule |
| 104 | + |
| 105 | +```yaml |
| 106 | +composer_sync: |
| 107 | + rules: |
| 108 | + support: merge-object |
| 109 | + funding: merge-object |
| 110 | + extra: merge-object |
| 111 | +``` |
| 112 | +
|
| 113 | +Input → Output |
| 114 | +
|
| 115 | +Root excerpt |
| 116 | +
|
| 117 | +```json |
| 118 | +{ |
| 119 | + "support": { |
| 120 | + "issues": "https://github.com/sonsofphp/monorepo/issues", |
| 121 | + "docs": "https://docs.sonsofphp.com" |
| 122 | + }, |
| 123 | + "extra": { |
| 124 | + "branch-alias": { "dev-main": "1.x-dev" } |
| 125 | + } |
| 126 | +} |
| 127 | +``` |
| 128 | + |
| 129 | +Package before |
| 130 | + |
| 131 | +```json |
| 132 | +{ |
| 133 | + "support": { "issues": "https://tracker.example/pkg" }, |
| 134 | + "extra": { "branch-alias": { "dev-main": "2.x-dev" }, "mark": true } |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +Package after |
| 139 | + |
| 140 | +```json |
| 141 | +{ |
| 142 | + "support": { |
| 143 | + "issues": "https://tracker.example/pkg", |
| 144 | + "docs": "https://docs.sonsofphp.com" |
| 145 | + }, |
| 146 | + "extra": { |
| 147 | + "branch-alias": { "dev-main": "2.x-dev" }, |
| 148 | + "mark": true |
| 149 | + } |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +## append-unique |
| 154 | + |
| 155 | +Appends unique strings from the root array into the package array, removes empties, de‑duplicates, and sorts the result alphabetically. |
| 156 | + |
| 157 | +Rule |
| 158 | + |
| 159 | +```yaml |
| 160 | +composer_sync: |
| 161 | + rules: |
| 162 | + keywords: append-unique |
| 163 | +``` |
| 164 | +
|
| 165 | +Input → Output |
| 166 | +
|
| 167 | +Root excerpt |
| 168 | +
|
| 169 | +```json |
| 170 | +{ "keywords": ["php", "monorepo", "tooling"] } |
| 171 | +``` |
| 172 | + |
| 173 | +Package before |
| 174 | + |
| 175 | +```json |
| 176 | +{ "keywords": ["cache", "php", ""] } |
| 177 | +``` |
| 178 | + |
| 179 | +Package after (sorted unique) |
| 180 | + |
| 181 | +```json |
| 182 | +{ "keywords": ["cache", "monorepo", "php", "tooling"] } |
| 183 | +``` |
| 184 | + |
| 185 | +## ignore |
| 186 | + |
| 187 | +Does nothing for the key; no planned edits. |
| 188 | + |
| 189 | +Rule |
| 190 | + |
| 191 | +```yaml |
| 192 | +composer_sync: |
| 193 | + rules: |
| 194 | + description: ignore |
| 195 | +``` |
| 196 | +
|
| 197 | +Input → Output |
| 198 | +
|
| 199 | +Root excerpt |
| 200 | +
|
| 201 | +```json |
| 202 | +{ "description": "Shared default description" } |
| 203 | +``` |
| 204 | + |
| 205 | +Package before |
| 206 | + |
| 207 | +```json |
| 208 | +{ "description": "Specific package description" } |
| 209 | +``` |
| 210 | + |
| 211 | +Package after |
| 212 | + |
| 213 | +```json |
| 214 | +{ "description": "Specific package description" } |
| 215 | +``` |
| 216 | + |
| 217 | +## Per‑package overrides (values and rules) |
| 218 | + |
| 219 | +Overrides force values or tweak rules for a single package; overrides take precedence. |
| 220 | + |
| 221 | +Example |
| 222 | + |
| 223 | +```yaml |
| 224 | +targets: |
| 225 | + - path: src/SonsOfPHP/Component/Cache |
| 226 | + composer_overrides: |
| 227 | + values: |
| 228 | + description: "{name} component for Sons of PHP" |
| 229 | + rules: |
| 230 | + homepage: mirror |
| 231 | +``` |
| 232 | +
|
| 233 | +Effect |
| 234 | +- `description`: Always set to the rendered string, regardless of `composer_sync.rules`. |
| 235 | +- `homepage`: Uses `mirror` for this package only, even if globally configured as `mirror-unless-overridden`. |
| 236 | + |
0 commit comments