imliam / cpx

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

Error: cpx laravel new Command Not Recognized on Windows #7

Open spinzar opened 3 days ago

spinzar commented 3 days ago

Environment:

Steps to Reproduce:

  1. Installed cpx globally using composer global require cpx/cpx.
  2. Tried to create a new Laravel project by running cpx laravel new in the terminal.
  3. Got the following error: 'C:\Users\YourUsername/.cpx/laravel/installer/latest/vendor/laravel/installer/bin/laravel' is not recognized as an internal or external command.
piotr-cz commented 3 days ago

I've got similar problem when installing cpx locally.

Project has phpunit installed and contains tests

> composer require --dev cpx/cpx

> php vendor/bin/cpx test
'vendor' is not recognized as an internal or external command,
operable program or batch file.

It's because windows ignores Shebangs (doesn't run vendor/bin commands with php interpreter) and the proc_open command on windows should be either php vendor/bin/phpunit or vendor/bin/phpunit.bat.

Quick workaround is to modify Console::__toString method:

- return trim("{$this->command} {$this->getCommandInput()}");
+ return trim("php {$this->command} {$this->getCommandInput()}");

But above is not enough for packages that are not installed:

> php vendor/bin/cpx friendsofphp/php-cs-fixer fix
'C:\Users\xxx/.cpx/friendsofphp/php-cs-fixer/latest/vendor/friendsofphp/php-cs-fixer/php-cs-fixer' is not recognized as an internal or external command,
operable program or batch file.