Skip to content

Commit 2400866

Browse files
authored
Merge pull request #222 from wp-cli/copilot/fix-legacy-package-installation
2 parents 85d9d9a + 8d46738 commit 2400866

2 files changed

Lines changed: 45 additions & 5 deletions

File tree

features/package-install.feature

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,50 @@ 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+
Success: Package installed
86+
"""
87+
And the composer.json file should contain:
88+
"""
89+
"canonical": false
90+
"""
91+
5492
@require-php-5.6
5593
Scenario: Install a package with 'wp-cli/wp-cli' as a dependency
5694
Given a WP install

src/Package_Command.php

Lines changed: 7 additions & 5 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,12 +366,13 @@ 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+
|| ( $composer_backup_decoded['repositories']['wp-cli']['canonical'] ?? true ) !== false ) {
369372
WP_CLI::log( 'Updating package index repository url...' );
370-
$package_args = $this->composer_type_package;
371373
$json_manipulator->addRepository(
372374
'wp-cli',
373-
$package_args
375+
$this->composer_type_package
374376
);
375377
}
376378

0 commit comments

Comments
 (0)