Repository navigation
Commit 66464aa
committed
Prefix the Phar's Composer dependency tree
WP-CLI registers its autoloader before WordPress boots, so for any class
shipped both by the Phar and by the site, the Phar's copy wins and is
imposed on the site. A site using monolog/monolog against psr/log v3 gets
the Phar's psr/log 1.1.4 instead and fatals on the incompatible
LoggerInterface signature.
Moving wp-cli/package-command to require-dev fixed this for Composer-based
installations, but the Phar is still built with dev dependencies, so it
continues to ship composer/composer and its tree unprefixed:
symfony/console v5.4.47, psr/log 1.1.4, react/promise, seld/*.
Prefix that tree with php-scoper, with two constraints:
* The `Composer\` namespace itself is left alone. Third-party Composer
plugins are compiled against the real `Composer\Plugin\PluginInterface`,
so prefixing it would break `wp package install` for any package
shipping one. References from inside `Composer\` to the prefixed
vendors are still rewritten, so Composer keeps using its own psr/log.
* Nothing reachable from WP-CLI's public API is touched: php-cli-tools
(`Utils\make_progress_bar()`), Requests (`Utils\http_request()`, plus
RequestsLibrary deliberately sharing the library with Core), and every
wp-cli/* package.
php-scoper needs PHP 8.2 while WP-CLI still targets 7.2.24, so the
toolchain lives in utils/scoper with its own composer.json.
Two things this turned up that are easy to get wrong:
* php-scoper rewrites source files but not Composer's generated autoload
maps. A scoped tree with a stale autoloader still advertises `Psr\Log\`
and the conflict survives with nothing to show for it, so the
autoloader is regenerated and then asserted on.
* Excluding a namespace does not stop php-scoper prefixing string
literals naming classes inside it. Composer compares `$class` against
'Composer\Package\CompletePackage', which the prefix silently breaks;
a patcher restores those.
Refs wp-cli/wp-cli#5920
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RHtjyXkZh8X16sBgmidSQi1 parent 8475849 commit 66464aa
6 files changed
Lines changed: 547 additions & 0 deletions
File tree
- .github/workflows
- features
- utils
- scoper
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
63 | 69 | | |
64 | 70 | | |
65 | 71 | | |
| |||
| 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 | + | |
0 commit comments