Commit dccf31c
Alexandre Courtiol
Add composer plugin to enforce pub/* worker shims (issue #1 part 2)
Closes the second half of issue #1 ("Ready to use package" → Prevent
magento2-base from overriding pub/index.php on patch-day installs).
Problem
-------
magento/magento-composer-installer hardcodes magento/magento2-base at the
highest deploy priority (DeployManager::$highPriority = 10 + maxPriority).
On a fresh install our package's extra.map runs AFTER magento2-base's, so
our worker shims (pub/index.php, pub/static.php, pub/get.php, pub/worker.php)
win.
But on `composer update magento/magento2-base` alone — typical for the
quarterly Magento patch cycle — our package isn't touched, its extra.map
never runs again, and stock Magento pub/index.php etc. silently come back.
Worker mode breaks until someone notices and reinstalls our package.
Solution
--------
Convert this package from type=magento2-component to type=composer-plugin
and add a small EnforcePubFilesPlugin that:
1. Subscribes to POST_PACKAGE_INSTALL and POST_PACKAGE_UPDATE for ALL
packages (priority -1000 so we run after magento-composer-installer's
own deploy step on the same event).
2. After each operation, compares each pub/*.php in the project root
against the same file under vendor/opengento/magento2-frankenphp-base/pub/
via md5_file().
3. Copies any mismatch back from vendor → project pub/. Idempotent and
cheap (skips when hashes match).
This makes the worker shims durable across every kind of composer operation
including the patch-day update of magento2-base.
Trade-offs of changing to type=composer-plugin
----------------------------------------------
- magento/magento-composer-installer no longer processes our extra.map
(it filters on type ∈ {magento2-module, theme, library, language,
component}). So I've dropped extra.map and let the plugin handle
file copying directly on POST_PACKAGE_INSTALL of our own package
(initial-install path) AND on POST_PACKAGE_UPDATE of anything else
(re-assert path).
- Composer 2.x prompts users to allow the plugin in their
config.allow-plugins on first install. Same UX as any other composer
plugin (e.g., magento/composer-root-update-plugin itself).
Alternative considered: split into two packages
-----------------------------------------------
A separate `opengento/magento2-frankenphp-base-installer` (type=composer-plugin)
that opengento/magento2-frankenphp-base (type=magento2-component) requires.
Cleaner separation of concerns but creates a new package to maintain.
Happy to refactor to that shape if preferred — let me know.
Constraint updates aligned with the Magento 2.4.7+ / PHP 8.3+ support matrix:
- php: (new) ^8.3
- magento/magento2-base: * -> ^2.4.7
- opengento/module-application: >=0.5 -> >=0.7
- composer-plugin-api: (new) ^2.01 parent 631f9e0 commit dccf31c
2 files changed
Lines changed: 174 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
57 | 50 | | |
58 | 51 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
0 commit comments