Skip to content

Sync root wp-cli/wp-cli version on package update and avoid vendoring duplicate bundled commands #263

Done

Description

@schlessera

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

  1. Under WP-CLI 2.12.0, install a package (e.g. wp-cli/doctor-command, which creates ~/.wp-cli/packages/composer.json with "name": "wp-cli/wp-cli" and "version": "2.12.0").
  2. Upgrade the WP-CLI Phar to 3.0.0.
  3. Run wp package update (with a dev-main requirement such as wp-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 of wp-cli/checksum-command, wp-cli/core-command, wp-cli/cron-command, wp-cli/entity-command, wp-cli/extension-command, and wp-cli/language-command.
  • wp package install wp-cli/scaffold-package-command installs duplicate copies of wp-cli/package-command and wp-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

  1. Sync "name" and "version" in ~/.wp-cli/packages/composer.json to wp-cli/wp-cli and self::get_wp_cli_version_composer() before invoking Composer in update() (and uninstall()), matching install().
  2. Declare bundled wp-cli/*-command packages in "replace" (or "provide") in ~/.wp-cli/packages/composer.json with the versions bundled in the running WP-CLI installation — excluding any bundled package explicitly listed in require (so users who deliberately install a bundled command via wp package install wp-cli/<name>-command can still do so). Refresh this mapping whenever install, update, or uninstall runs.

Activity

  1. added
    command:package-install
    command:package-update
    on Dec 1, 2026
  2. added
    command:package-uninstall
    on Dec 1, 2026
  3. schlessera commented on Dec 1, 2026

    @schlessera
    MemberAuthor

    Clarification on wp package uninstall: we intentionally do not force-bump "version" in uninstall() (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" during uninstall would cause Composer resolution to fail on the remaining incompatible package(s), trapping the user from uninstalling them one by one. Syncing root metadata on install and update covers both installation and upgrade paths while keeping uninstall unblocked.

  4. added this to the 3.1.1 milestone on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcommand:package-installcommand:package-uninstallcommand:package-update

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions