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

Broke composer commands when used with wp-cli/package-command #59

Closed
mickaelperrin opened this issue Sep 14, 2018 · 6 comments
Closed
Assignees

Comments

@mickaelperrin
Copy link

Problem/Motivation

When used with wp-cli/package-command, composer fails to execute post-install commands.

note that this issue has been cross-posted to wp-cli/package-command#99

Steps to reproduce

  1. Create a minimal composer.json file:
{
  "require": {
    "php": ">=7.0.0"
  },
	"require-dev": {
		"wp-cli/package-command": "*@stable",
		"dealerdirect/phpcodesniffer-composer-installer": "*"
	},
  "scripts": {
    "post-install-message": [
      "echo 'OK'"
    ],
    "post-install-cmd": [
      "composer run post-install-message"
    ],
    "post-update-cmd": [
      "composer run post-install-message"
    ]
  }
}
  1. Run composer install

Expected behaviour

Displays OK

Actual behaviour

Throws the following error

> post-update-cmd: composer run post-install-message
Executing command (CWD): composer run post-install-message

Fatal error: Uncaught Error: Class 'Symfony\Component\Process\ProcessBuilder' not found in /src/test/vendor/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php:118
Stack trace:
#0 /src/test/vendor/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php(103): Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin->init()
#1 /src/test/vendor/composer/composer/src/Composer/Plugin/PluginManager.php(236): Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin->activate(Object(Composer\Composer), Object(Composer\IO\ConsoleIO))
#2 /src/test/vendor/composer/composer/src/Composer/Plugin/PluginManager.php(205): Composer\Plugin\PluginManager->addPlugin(Object(Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin))
#3 /src/test/vendor/composer/composer/src/Composer/Plugin/PluginManager.php(261): Composer\Plugin\PluginManager->registerPackage(Object(Composer\Package\CompletePackage))
#4 /src/test/vendor/composer/composer/src/Composer/Plugin/PluginManager.php(76): Composer\Plugin\PluginManager->loa in /src/test/vendor/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php on line 118
Script composer run post-install-message handling the post-update-cmd event returned with error code 255
@TravisCarden
Copy link
Contributor

I get the same error just requiring composer/composer (v1.7.2). Since wp-cli/package-command requires that, too, it seems like the likely problem.

@frenck
Copy link
Contributor

frenck commented Oct 25, 2018

These are triggered by the post-install-cmd and post-update-cmd, without those, it just works fine.
Looking for a reason though.

@frenck
Copy link
Contributor

frenck commented Oct 26, 2018

Not yet sure why, but this example works:

{
  "scripts": {
    "post-install-message": [
      "echo 'OK'"
    ],
    "post-install-cmd": [
      "@post-install-message"
    ],
    "post-update-cmd": [
      "@post-install-message"
    ]
  }
}
$ composer update nothing
    1/1:	http://repo.packagist.org/p/provider-latest$561b6908c662cbfac3a452b5f1e49c717a2ddddef2268db65c962aa3de0efd77.json
    Finished: success: 1, skipped: 0, failure: 0, total: 1
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
PHP CodeSniffer Config installed_paths delete
> echo 'OK'
OK

So this problem is isolated to when Composer invokes itself? Investigating a little more.

@frenck
Copy link
Contributor

frenck commented Oct 26, 2018

When running the full command from within the post-install-*, a different composer is used: The one shipped/installed in the vendor.

So this would actually trigger the same error:

$ ./vendor/bin/composer run post-install-message

Fatal error: Uncaught Error: Class 'Symfony\Component\Process\ProcessBuilder' not found in /Volumes/CODE/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php:130
Stack trace:
#0 /Volumes/CODE/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php(110): Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin->init()
#1 /Volumes/CODE/dealerdirect/codesniffer-test2/vendor/composer/composer/src/Composer/Plugin/PluginManager.php(236): Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin->activate(Object(Composer\Composer), Object(Composer\IO\ConsoleIO))
#2 /Volumes/CODE/dealerdirect/codesniffer-test2/vendor/composer/composer/src/Composer/Plugin/PluginManager.php(205): Composer\Plugin\PluginManager->addPlugin(Object(Dealerdirect\Composer\Plugin\Installers\PHPCodeSniffer\Plugin))
#3 /Volumes/CODE/dealerdirect/codesniffer-test2/vendor/composer/composer/src/Composer/Plugin/PluginManager.php(261): Composer\Plugin\PluginManager->registerPackage(Object(Composer\Package\CompletePackage))
#4 /Volumes/CODE in /Volumes/CODE/dealerdirect/phpcodesniffer-composer-installer/src/Plugin.php on line 130

Which seems to use a different autoloader (I've tested and confirmed there is an autoloader present). Continue to look into it..

@frenck
Copy link
Contributor

frenck commented Oct 26, 2018

OK, so the ProcessBuilder no longer exists in the Symfony/Process package >=4.0, which is causing this issue. Looking into rewriting the Plugin the use the Composer\Util\ProcessExecutor.

@frenck
Copy link
Contributor

frenck commented Oct 26, 2018

This has been fixed in the current master branch and will be part of the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants