Problems running composer --version on windows
Bug report
| Question | Answer |
|---|---|
| Box version | 4.6.5@0964604 |
| PHP version | 8.2.8 |
| Platform with version | Windows 11 |
| Github Repo | https://github.com/phpactor/phpactor |
I was trying to box the application on Windows and got the error Could not determine the Composer version from the following output:
The last version that worked was 4.5.0.
Running the command with --debug I saw that in 4.5.0 the composer command used was:
? Checking Composer compatibility
> c:\...\zobo\tools\php\composer.BAT --version --no-ansi
> Version detected: 2.4.4 (Box requires ^2.2.0)
> Supported version detected
The output of 4.6.5 was:
? Checking Composer compatibility
> c:\...\zobo\tools\php\composer.phar --version --no-ansi
Naturally windows cannot run a .phar (at least on on my system) so overriding with cli options does work:
php box.phar compile -c ../box.json --debug --composer-bin=c:\...\zobo\tools\php\composer.BAT
...
? Checking Composer compatibility
> c:/.../zobo/tools/php/composer.BAT --version --no-ansi
> Version detected: 2.4.4 (Box requires ^2.2.0)
> Supported version detected
Is there anything that can be done about fixing this detection?
box.json.dist
{
"compression": "GZ",
"directories": [
"templates"
],
"files": [
"LICENSE"
],
"finder": [
{
"exclude": [
"Tests"
],
"in": "lib"
},
{
"name": "{\\.(php|bash|fish|zsh)}",
"exclude": [
"tests",
"test"
],
"in": "vendor"
}
],
"git-tag": "git_tag",
"intercept": true,
"output": "build/phpactor.phar"
} ```
</details>
Is there anything that can be done about fixing this detection?
I am sure something can be done, but I do not know how to fix it (I admit I never really used Windows either).
Most of the logic can be found here in case you take check it out yourself: https://github.com/box-project/box/blob/main/src/Composer/ComposerProcessFactory.php
Thanks. I'll try to take a look... time permitting.
The difference is in Symfony\Component\Process\ExecutableFinder. Box 4.5.0 uses symfony/process:v6.1.3 and Box 4.6.6 uses symfony/process:v7.2.4.
The old one had a list of suffixes where .phar would be appended:
The new one appends some common suffixes when doing the $executableFinder->find('composer') call and ends up with:
Getting the same behaviour one would need to do something like this in ComposerProcessFactory::retrieveComposerExecutable
private static function retrieveComposerExecutable(): string
{
$executableFinder = new ExecutableFinder();
// first add the old hard coded suffixes
if ('\\' === \DIRECTORY_SEPARATOR) {
$executableFinder->setSuffixes(['.exe', '.bat', '.cmd', '.com']);
}
//
$executableFinder->addSuffix('.phar');
if (null === $composer = $executableFinder->find('composer')) {
throw new RuntimeException('Could not find a Composer executable.');
}
return $composer;
}
Ha, I admit I totally expected the Symfony Executable Finder to handle that itself...
Symfony Executable Finder works fine.
The problem is: .phar is not executable on windows, should not look for it.
Update https://github.com/box-project/box/blob/1d46320ee6aac18f494a43b57909e01da59a81a1/src/Composer/ComposerProcessFactory.php#L156 to
if (PHP_OS_FAMILY !== "Windows") {
$executableFinder->addSuffix('.phar');
}
I am experiencing the same issue on Windows using Box v4.6.5 that ships with Laravel Zero v12.
I tested multiple versions and have determined that up to Box v4.6.3 works fine on Windows, while v4.6.4 and above are broken due to this issue with composer.phar vs composer.bat.
I was able to manually replace the version of Box in Laravel Zero with v4.6.3 and Laravel Zero now works again.