Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with newer Composer versions #183

Merged
merged 1 commit into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 70 additions & 70 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
{
"name": "wp-cli/package-command",
"type": "wp-cli-package",
"description": "Lists, installs, and removes WP-CLI packages.",
"homepage": "https://github.com/wp-cli/package-command",
"license": "MIT",
"authors": [
{
"name": "Daniel Bachhuber",
"email": "daniel@runcommand.io",
"homepage": "https://runcommand.io"
}
],
"require": {
"ext-json": "*",
"composer/composer": "^1.10.23 || ~2.2.17",
"wp-cli/wp-cli": "^2.8"
},
"require-dev": {
"wp-cli/scaffold-command": "^1 || ^2",
"wp-cli/wp-cli-tests": "^4"
},
"config": {
"process-timeout": 7200,
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"johnpbloch/wordpress-core-installer": true
}
},
"extra": {
"branch-alias": {
"dev-main": "2.x-dev"
},
"bundled": true,
"commands": [
"package",
"package browse",
"package install",
"package list",
"package update",
"package uninstall"
]
},
"autoload": {
"classmap": [
"src/"
],
"files": [
"package-command.php"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"behat": "run-behat-tests",
"behat-rerun": "rerun-behat-tests",
"lint": "run-linter-tests",
"phpcs": "run-phpcs-tests",
"phpcbf": "run-phpcbf-cleanup",
"phpunit": "run-php-unit-tests",
"prepare-tests": "install-package-tests",
"test": [
"@lint",
"@phpcs",
"@phpunit",
"@behat"
]
},
"support": {
"issues": "https://github.com/wp-cli/package-command/issues"
"name": "wp-cli/package-command",
"type": "wp-cli-package",
"description": "Lists, installs, and removes WP-CLI packages.",
"homepage": "https://github.com/wp-cli/package-command",
"license": "MIT",
"authors": [
{
"name": "Daniel Bachhuber",
"email": "daniel@runcommand.io",
"homepage": "https://runcommand.io"
}
],
"require": {
"ext-json": "*",
"composer/composer": "^1.10.23 || ^2.2.17",
"wp-cli/wp-cli": "^2.8"
},
"require-dev": {
"wp-cli/scaffold-command": "^1 || ^2",
"wp-cli/wp-cli-tests": "^4"
},
"config": {
"process-timeout": 7200,
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"johnpbloch/wordpress-core-installer": true
}
},
"extra": {
"branch-alias": {
"dev-main": "2.x-dev"
},
"bundled": true,
"commands": [
"package",
"package browse",
"package install",
"package list",
"package update",
"package uninstall"
]
},
"autoload": {
"classmap": [
"src/"
],
"files": [
"package-command.php"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"behat": "run-behat-tests",
"behat-rerun": "rerun-behat-tests",
"lint": "run-linter-tests",
"phpcs": "run-phpcs-tests",
"phpcbf": "run-phpcbf-cleanup",
"phpunit": "run-php-unit-tests",
"prepare-tests": "install-package-tests",
"test": [
"@lint",
"@phpcs",
"@phpunit",
"@behat"
]
},
"support": {
"issues": "https://github.com/wp-cli/package-command/issues"
}
}
2 changes: 1 addition & 1 deletion features/package-install.feature
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Feature: Install WP-CLI packages
When I run `wp package install git@github.com:wp-cli/google-sitemap-generator-cli.git`
Then STDOUT should contain:
"""
Installing package wp-cli/google-sitemap-generator-cli (dev-master)
Installing package wp-cli/google-sitemap-generator-cli (dev-main)
"""
# This path is sometimes changed on Macs to prefix with /private
And STDOUT should contain:
Expand Down
2 changes: 2 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<!-- Ignoring select files/folders.
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-files-and-folders -->
<exclude-pattern>*/src/WP_CLI/JsonManipulator\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_CLI/Package/Compat/Min_Composer_1_10/NullIOMethodsTrait\.php$</exclude-pattern>
<exclude-pattern>*/src/WP_CLI/Package/Compat/Min_Composer_2_3/NullIOMethodsTrait\.php$</exclude-pattern>
<exclude-pattern>*/tests/test-json-manipulator\.php$</exclude-pattern>

<!-- Show progress. -->
Expand Down
8 changes: 1 addition & 7 deletions src/Package_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,18 @@
use Composer\Config;
use Composer\Config\JsonConfigSource;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Request;
use Composer\EventDispatcher\Event;
use Composer\Factory;
use Composer\IO\NullIO;
use Composer\Installer;
use Composer\Json\JsonFile;
use Composer\Package;
use Composer\Package\BasePackage;
use Composer\Package\PackageInterface;
use Composer\Package\Version\VersionParser;
use Composer\Package\Version\VersionSelector;
use Composer\Repository;
use Composer\Repository\CompositeRepository;
use Composer\Repository\ComposerRepository;
use Composer\Repository\RepositoryManager;
use Composer\Util\Filesystem;
use Composer\Util\HttpDownloader;
use WP_CLI\ComposerIO;
use WP_CLI\Package\ComposerIO;
use WP_CLI\Extractor;
use WP_CLI\Utils;
use WP_CLI\JsonManipulator;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace WP_CLI\Package\Compat\Min_Composer_1_10;

use WP_CLI;

trait NullIOMethodsTrait {
/**
* {@inheritDoc}
*/
public function isVerbose() {
return true;
}

/**
* {@inheritDoc}
*/
public function write( $messages, $newline = true, $verbosity = self::NORMAL ) {
self::output_clean_message( $messages );
}

/**
* {@inheritDoc}
*/
public function writeError( $messages, $newline = true, $verbosity = self::NORMAL ) {
self::output_clean_message( $messages );
}

private static function output_clean_message( $messages ) {
$messages = (array) preg_replace( '#<(https?)([^>]+)>#', '$1$2', $messages );
foreach ( $messages as $message ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags
WP_CLI::log( strip_tags( trim( $message ) ) );
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace WP_CLI\Package\Compat\Min_Composer_2_3;

use WP_CLI;

trait NullIOMethodsTrait {
/**
* {@inheritDoc}
*/
public function isVerbose(): bool {
return true;
}

/**
* {@inheritDoc}
*/
public function write( $messages, bool $newline = true, int $verbosity = self::NORMAL ): void {
self::output_clean_message( $messages );
}

/**
* {@inheritDoc}
*/
public function writeError( $messages, bool $newline = true, int $verbosity = self::NORMAL ): void {
self::output_clean_message( $messages );
}

private static function output_clean_message( $messages ) {
$messages = (array) preg_replace( '#<(https?)([^>]+)>#', '$1$2', $messages );
foreach ( $messages as $message ) {
// phpcs:ignore WordPress.WP.AlternativeFunctions.strip_tags_strip_tags
WP_CLI::log( strip_tags( trim( $message ) ) );
}
}
}
29 changes: 29 additions & 0 deletions src/WP_CLI/Package/Compat/NullIOMethodsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace WP_CLI\Package\Compat;

use Composer\InstalledVersions;
use Composer\Semver\VersionParser;

// phpcs:disable Generic.Files.OneObjectStructurePerFile.MultipleFound,Generic.Classes.DuplicateClassName.Found

if (
class_exists( InstalledVersions::class )
&& InstalledVersions::satisfies( new VersionParser(), 'composer/composer', '^2.3' )
) {
require_once __DIR__ . '/Min_Composer_2_3/NullIOMethodsTrait.php';

trait NullIOMethodsTrait {

use Min_Composer_2_3\NullIOMethodsTrait;
}

return;
}

require_once __DIR__ . '/Min_Composer_1_10/NullIOMethodsTrait.php';

trait NullIOMethodsTrait {

use Min_Composer_1_10\NullIOMethodsTrait;
}
18 changes: 18 additions & 0 deletions src/WP_CLI/Package/ComposerIO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* A Composer IO class so we can provide some level of interactivity from WP-CLI.
*
* Due to PHP 5.6 compatibility, we have two different implementations of this class.
* This is implemented via traits to make static analysis easier.
*
* See https://github.com/wp-cli/package-command/issues/172.
*/

namespace WP_CLI\Package;

use Composer\IO\NullIO;
use WP_CLI\Package\Compat\NullIOMethodsTrait;

class ComposerIO extends NullIO {
use NullIOMethodsTrait;
}