Repository navigation
Description
Summary
While investigating wp-cli/wp-cli#6469 (tracked for the framework/bootstrap side in wp-cli/wp-cli#6470), two related bugs in wp-cli/package-command surfaced that both cause and trap users in bundled-command version mismatches across WP-CLI upgrades.
Issue 1: wp package update (and uninstall) never syncs "version" in packages/composer.json
Package_Command::install() updates the root package version to match the running WP-CLI Phar:
$json_manipulator->addMainKey( 'name', 'wp-cli/wp-cli' );
$json_manipulator->addMainKey( 'version', self::get_wp_cli_version_composer() );Package_Command::update() (and uninstall()) does not do this.
Steps to reproduce
- Under WP-CLI 2.12.0, install a package (e.g.
wp-cli/doctor-command, which creates~/.wp-cli/packages/composer.jsonwith"name": "wp-cli/wp-cli"and"version": "2.12.0"). - Upgrade the WP-CLI Phar to 3.0.0.
- Run
wp package update(with adev-mainrequirement such aswp-cli/doctor-command: dev-main, the default constraint when installing without a version).
Actual result
Composer rejects the update because the root package version is still stuck at 2.12.0:
Problem 1
- Root composer.json requires wp-cli/doctor-command dev-main -> satisfiable by wp-cli/doctor-command[dev-main].
- wp-cli/doctor-command dev-main requires wp-cli/wp-cli ^3.0 -> satisfiable by wp-cli/wp-cli[v3.0.0] from composer repo (https://repo.packagist.org) but wp-cli/wp-cli 2.12.0 is the root package and cannot be modified.
As a result, users whose installed packages broke after upgrading to WP-CLI 3.0.0 cannot recover via wp package update.
Issue 2: packages/composer.json does not declare bundled wp-cli/*-command packages in replace/provide
Because ~/.wp-cli/packages/composer.json only sets "name": "wp-cli/wp-cli" without declaring the bundled command packages already shipped in WP-CLI, installing packages that depend on bundled commands installs duplicate copies into ~/.wp-cli/packages/vendor/:
wp package install wp-cli/doctor-command(even fresh on WP-CLI 3.0.0) installs duplicate copies ofwp-cli/checksum-command,wp-cli/core-command,wp-cli/cron-command,wp-cli/entity-command,wp-cli/extension-command, andwp-cli/language-command.wp package install wp-cli/scaffold-package-commandinstalls duplicate copies ofwp-cli/package-commandandwp-cli/scaffold-command(along with their dependencies).
Those duplicated copies drift behind the Phar whenever WP-CLI is upgraded, causing class/constant/method version mismatches (as seen in wp-cli/wp-cli#6469 and wp-cli/wp-cli#6470) in addition to wasted disk space and slower installs.
Proposed Fix
- Sync
"name"and"version"in~/.wp-cli/packages/composer.jsontowp-cli/wp-cliandself::get_wp_cli_version_composer()before invoking Composer inupdate()(anduninstall()), matchinginstall(). - Declare bundled
wp-cli/*-commandpackages in"replace"(or"provide") in~/.wp-cli/packages/composer.jsonwith the versions bundled in the running WP-CLI installation — excluding any bundled package explicitly listed inrequire(so users who deliberately install a bundled command viawp package install wp-cli/<name>-commandcan still do so). Refresh this mapping wheneverinstall,update, oruninstallruns.
Activity
schlessera commentedon Dec 1, 2026
Clarification on
wp package uninstall: we intentionally do not force-bump"version"inuninstall()(see #264). If a user upgrades WP-CLI from 2.x to 3.0.0 with two or more incompatible 2.x packages installed, bumping"version"duringuninstallwould cause Composer resolution to fail on the remaining incompatible package(s), trapping the user from uninstalling them one by one. Syncing root metadata oninstallandupdatecovers both installation and upgrade paths while keepinguninstallunblocked.