Skip to content

Commit 20a6b69

Browse files
Copilotswissspidy
andcommitted
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>
1 parent c452356 commit 20a6b69

2 files changed

Lines changed: 49 additions & 3 deletions

File tree

features/package-install.feature

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,54 @@ Feature: Install WP-CLI packages
4545
"""
4646
"url": "http://wp-cli.org/package-index/"
4747
"""
48+
And the composer.json file should contain:
49+
"""
50+
"canonical": false
51+
"""
4852

4953
When I run `WP_CLI_PACKAGES_DIR=. wp package is-installed wp-cli/restful`
5054
Then the return code should be 0
5155
And STDERR should be empty
5256
And STDOUT should be empty
5357

58+
Scenario: Install a package updates the package index repository to be non-canonical
59+
Given an empty directory
60+
And a composer.json file:
61+
"""
62+
{
63+
"repositories": {
64+
"test" : {
65+
"type": "path",
66+
"url": "./dummy-package/"
67+
},
68+
"wp-cli": {
69+
"type": "composer",
70+
"url": "https://wp-cli.org/package-index/"
71+
}
72+
}
73+
}
74+
"""
75+
And a dummy-package/composer.json file:
76+
"""
77+
{
78+
"name": "wp-cli/restful",
79+
"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."
80+
}
81+
"""
82+
When I run `WP_CLI_PACKAGES_DIR=. wp package install wp-cli/restful`
83+
Then STDOUT should contain:
84+
"""
85+
Updating package index repository url...
86+
"""
87+
And STDOUT should contain:
88+
"""
89+
Success: Package installed
90+
"""
91+
And the composer.json file should contain:
92+
"""
93+
"canonical": false
94+
"""
95+
5496
@require-php-5.6
5597
Scenario: Install a package with 'wp-cli/wp-cli' as a dependency
5698
Given a WP install

src/Package_Command.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ class Package_Command extends WP_CLI_Command {
9292
* @var array
9393
*/
9494
private $composer_type_package = [
95-
'type' => 'composer',
96-
'url' => self::PACKAGE_INDEX_URL,
95+
'type' => 'composer',
96+
'url' => self::PACKAGE_INDEX_URL,
97+
'canonical' => false,
9798
];
9899

99100
/**
@@ -365,7 +366,10 @@ public function install( $args, $assoc_args ) {
365366
);
366367
}
367368
// If the composer file does not contain the current package index repository, refresh the repository definition.
368-
if ( empty( $composer_backup_decoded['repositories']['wp-cli']['url'] ) || self::PACKAGE_INDEX_URL !== $composer_backup_decoded['repositories']['wp-cli']['url'] ) {
369+
if ( empty( $composer_backup_decoded['repositories']['wp-cli']['url'] )
370+
|| self::PACKAGE_INDEX_URL !== $composer_backup_decoded['repositories']['wp-cli']['url']
371+
|| ! isset( $composer_backup_decoded['repositories']['wp-cli']['canonical'] )
372+
|| false !== $composer_backup_decoded['repositories']['wp-cli']['canonical'] ) {
369373
WP_CLI::log( 'Updating package index repository url...' );
370374
$package_args = $this->composer_type_package;
371375
$json_manipulator->addRepository(

0 commit comments

Comments
 (0)