imliam / cpx

Run any command from any composer package, even if it's not installed in your project.
https://cpx.dev
MIT License
286 stars 9 forks source link

Running `cpx tinker` throws fatal error in `cpx/cpx/files/psysh-config.php` #3

Open N-Molham opened 1 month ago

N-Molham commented 1 month ago

Hello,

I love this tool, it is pretty useful and I can see myself using it in multiple ways.

An issue I am facing when trying to run cpx tinker, it leads to Warning: require_once(~/.composer/vendor/cpx/cpx/files/../vendor/autoload.php): Failed to open stream: No such file or directory

I did some debugging and found to resolve the issue, I had to modify the files/psysh-config.php to the adjust the require_once line to be:

- require_once __DIR__ . '/../vendor/autoload.php';
+ require_once __DIR__ . '/../../../../vendor/autoload.php';

Not sure if it because I already had psys installed globally before or not.

For context:

$ cpx --version
cpx version: 1.0.2
php version: 8.2.20
Installed global packages ### Installed global packages ```json { "installed": [ { "name": "beyondcode/expose", "direct-dependency": true, "homepage": "https://sharedwithexpose.com", "source": "https://github.com/beyondcode/expose/tree/2.6.2", "version": "2.6.2", "description": "Create public URLs for local sites through any firewall and VPN.", "abandoned": false }, { "name": "cpx/cpx", "direct-dependency": true, "homepage": null, "source": "https://github.com/imliam/cpx", "version": "1.0.2", "description": "Run any command from any composer package, even if it's not installed in your project.", "abandoned": false }, { "name": "eriktorsner/wp-bootstrap", "direct-dependency": true, "homepage": "https://github.com/eriktorsner/wp-bootstrap/", "source": "https://github.com/eriktorsner/wp-bootstrap/tree/master", "version": "0.5.2", "description": "Utils for bootstrapping a WordPress installation", "abandoned": false }, { "name": "friendsofphp/php-cs-fixer", "direct-dependency": true, "homepage": null, "source": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/v2.19.3", "version": "v2.19.3", "description": "A tool to automatically fix PHP code style", "abandoned": false }, { "name": "laravel/installer", "direct-dependency": true, "homepage": null, "source": "https://github.com/laravel/installer/tree/v4.2.10", "version": "v4.2.10", "description": "Laravel application installer.", "abandoned": false }, { "name": "laravel/valet", "direct-dependency": true, "homepage": null, "source": "https://github.com/laravel/valet/tree/v4.0.0", "version": "v4.0.0", "description": "A more enjoyable local development experience for Mac.", "abandoned": false }, { "name": "psy/psysh", "direct-dependency": true, "homepage": "http://psysh.org", "source": "https://github.com/bobthecow/psysh/tree/v0.12.4", "version": "v0.12.4", "description": "An interactive shell for modern PHP.", "abandoned": false }, { "name": "squizlabs/php_codesniffer", "direct-dependency": true, "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", "source": "https://github.com/squizlabs/PHP_CodeSniffer", "version": "3.6.2", "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", "abandoned": false }, { "name": "wp-cli/wp-cli-bundle", "direct-dependency": true, "homepage": "https://wp-cli.org", "source": "https://github.com/wp-cli/wp-cli-bundle", "version": "v2.11.0", "description": "WP-CLI bundle package with default commands.", "abandoned": false } ] } ```

Update

After trying to fix the require_one path, I am getting different error:

Symfony\Component\ErrorHandler\Error\FatalError^ {#1250
  #message: "Compile Error: Declaration of Symfony\Component\Console\Input\ArrayInput::parse() must be compatible with Symfony\Component\Console\Input\Input::parse(): void"
  #code: 0
  #file: "~/.composer/vendor/symfony/console/Input/ArrayInput.php"
  #line: 130
  -error: array:4 [
    "type" => 64
    "message" => "Declaration of Symfony\Component\Console\Input\ArrayInput::parse() must be compatible with Symfony\Component\Console\Input\Input::parse(): void"
    "file" => "~/.composer/vendor/symfony/console/Input/ArrayInput.php"
    "line" => 130
  ]
}

Appreciate your efforts.

Thanks, Nabeel

conorjmurphy commented 1 month ago

I too have this issue

staabm commented 1 month ago

I think its a bug in psysh-config.php. when the composer autoloader is meant to support both, global installation and regular "in-project" installations, it has to be something like

https://github.com/sabre-io/dav/blob/a6ff5932012d5064b4c04b4543be7c3d119a5199/bin/sabredav.php#L26-L38

thats not related to npx, but something composer "required" for very long

ivanhoe011 commented 1 month ago

Had the same issue as @N-Molham in OP, but for me the fix to require_once path in psysh-config.php file worked. I have only cpx installed globally on this machine, no other composer packages, so probably that's the difference.