From c45235647c564ef97a9dce57356d4b2d0d0a4eab Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 22:38:46 +0000 Subject: [PATCH 1/6] Initial plan From 20a6b697492ea7eb2eba1e3f6ea4fafe7b9d3527 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 22:42:35 +0000 Subject: [PATCH 2/6] Fix legacy package index priority by adding canonical: false to prevent it from blocking newer Packagist versions Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/package-install.feature | 42 ++++++++++++++++++++++++++++++++ src/Package_Command.php | 10 +++++--- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/features/package-install.feature b/features/package-install.feature index cafd1e84..5229a8da 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -45,12 +45,54 @@ Feature: Install WP-CLI packages """ "url": "http://wp-cli.org/package-index/" """ + And the composer.json file should contain: + """ + "canonical": false + """ When I run `WP_CLI_PACKAGES_DIR=. wp package is-installed wp-cli/restful` Then the return code should be 0 And STDERR should be empty And STDOUT should be empty + Scenario: Install a package updates the package index repository to be non-canonical + Given an empty directory + And a composer.json file: + """ + { + "repositories": { + "test" : { + "type": "path", + "url": "./dummy-package/" + }, + "wp-cli": { + "type": "composer", + "url": "https://wp-cli.org/package-index/" + } + } + } + """ + And a dummy-package/composer.json file: + """ + { + "name": "wp-cli/restful", + "description": "This is a dummy package we will install instead of actually installing the real package. This prevents the test from hanging indefinitely for some reason, even though it passes. The 'name' must match a real package as it is checked against the package index." + } + """ + When I run `WP_CLI_PACKAGES_DIR=. wp package install wp-cli/restful` + Then STDOUT should contain: + """ + Updating package index repository url... + """ + And STDOUT should contain: + """ + Success: Package installed + """ + And the composer.json file should contain: + """ + "canonical": false + """ + @require-php-5.6 Scenario: Install a package with 'wp-cli/wp-cli' as a dependency Given a WP install diff --git a/src/Package_Command.php b/src/Package_Command.php index 9f04447b..bb21e984 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -92,8 +92,9 @@ class Package_Command extends WP_CLI_Command { * @var array */ private $composer_type_package = [ - 'type' => 'composer', - 'url' => self::PACKAGE_INDEX_URL, + 'type' => 'composer', + 'url' => self::PACKAGE_INDEX_URL, + 'canonical' => false, ]; /** @@ -365,7 +366,10 @@ public function install( $args, $assoc_args ) { ); } // If the composer file does not contain the current package index repository, refresh the repository definition. - if ( empty( $composer_backup_decoded['repositories']['wp-cli']['url'] ) || self::PACKAGE_INDEX_URL !== $composer_backup_decoded['repositories']['wp-cli']['url'] ) { + if ( empty( $composer_backup_decoded['repositories']['wp-cli']['url'] ) + || self::PACKAGE_INDEX_URL !== $composer_backup_decoded['repositories']['wp-cli']['url'] + || ! isset( $composer_backup_decoded['repositories']['wp-cli']['canonical'] ) + || false !== $composer_backup_decoded['repositories']['wp-cli']['canonical'] ) { WP_CLI::log( 'Updating package index repository url...' ); $package_args = $this->composer_type_package; $json_manipulator->addRepository( From 25ad3a7d3fd41255094bdbeee363e3c772ef6901 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 25 Feb 2026 23:49:36 +0100 Subject: [PATCH 3/6] Update src/Package_Command.php --- src/Package_Command.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index bb21e984..53bd4543 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -368,8 +368,7 @@ public function install( $args, $assoc_args ) { // If the composer file does not contain the current package index repository, refresh the repository definition. if ( empty( $composer_backup_decoded['repositories']['wp-cli']['url'] ) || self::PACKAGE_INDEX_URL !== $composer_backup_decoded['repositories']['wp-cli']['url'] - || ! isset( $composer_backup_decoded['repositories']['wp-cli']['canonical'] ) - || false !== $composer_backup_decoded['repositories']['wp-cli']['canonical'] ) { + || ( $composer_backup_decoded['repositories']['wp-cli']['canonical'] ?? true ) !== false ) { WP_CLI::log( 'Updating package index repository url...' ); $package_args = $this->composer_type_package; $json_manipulator->addRepository( From 2c810651a96cdef32718ae84b3711bb66d91f58d Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 25 Feb 2026 23:58:13 +0100 Subject: [PATCH 4/6] Update src/Package_Command.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/Package_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 53bd4543..60ed18f4 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -370,7 +370,7 @@ public function install( $args, $assoc_args ) { || self::PACKAGE_INDEX_URL !== $composer_backup_decoded['repositories']['wp-cli']['url'] || ( $composer_backup_decoded['repositories']['wp-cli']['canonical'] ?? true ) !== false ) { WP_CLI::log( 'Updating package index repository url...' ); - $package_args = $this->composer_type_package; + WP_CLI::log( 'Refreshing package index repository definition...' ); $json_manipulator->addRepository( 'wp-cli', $package_args From 3673151d6a65afd6d3be9e31c55661b37ddbec57 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 25 Feb 2026 23:58:24 +0100 Subject: [PATCH 5/6] Update features/package-install.feature Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- features/package-install.feature | 4 ---- 1 file changed, 4 deletions(-) diff --git a/features/package-install.feature b/features/package-install.feature index 5229a8da..efef40b5 100644 --- a/features/package-install.feature +++ b/features/package-install.feature @@ -81,10 +81,6 @@ Feature: Install WP-CLI packages """ When I run `WP_CLI_PACKAGES_DIR=. wp package install wp-cli/restful` Then STDOUT should contain: - """ - Updating package index repository url... - """ - And STDOUT should contain: """ Success: Package installed """ From 8d467380b0de166e1a06e5d280a735ce4bbea56e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 25 Feb 2026 23:40:12 +0000 Subject: [PATCH 6/6] Fix missing composer_type_package assignment causing empty repository in addRepository call Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- src/Package_Command.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Package_Command.php b/src/Package_Command.php index 60ed18f4..e39dcf68 100644 --- a/src/Package_Command.php +++ b/src/Package_Command.php @@ -370,10 +370,9 @@ public function install( $args, $assoc_args ) { || self::PACKAGE_INDEX_URL !== $composer_backup_decoded['repositories']['wp-cli']['url'] || ( $composer_backup_decoded['repositories']['wp-cli']['canonical'] ?? true ) !== false ) { WP_CLI::log( 'Updating package index repository url...' ); - WP_CLI::log( 'Refreshing package index repository definition...' ); $json_manipulator->addRepository( 'wp-cli', - $package_args + $this->composer_type_package ); }