box-project / box2

An application for building and managing Phars.
https://box-project.github.io/box2/
MIT License
1.19k stars 80 forks source link

Box as a composer dependency cannot find the correct autoload.php #155

Open tomzx opened 7 years ago

tomzx commented 7 years ago

I'm not sure if this change actually breaks existing behavior, but I think the idea was that if you found a composer.json file, you wanted to exit the do-while loop, not exit only when the while condition is true.

I've added a skip = 1 because we obviously want to skip the composer.json in the box directory (vendor/kerge/box).

kherge commented 7 years ago

Hi @tomzx, are you using a custom vendor directory location in your composer.json file?

tomzx commented 7 years ago

@kherge, Nope, just the default vendor folder.

The structure of my project is

composer.json
vendor
- kherge
-- box

I run box using vendor/bin/box on Windows. I think this might be the source of the issue. It appears that under unix variants the box shell script is copied to the vendor/bin folder, while on Windows it simply creates a script that will call the box script from within its folder (so the current working directory is different).

Thus, while realpath($_SERVER['argv'][0]) will return vendor/bin/box under unix variants, it will return vendor/kherge/box/bin/box. Thus, it seems that my fix would most likely break under unix variants.

One suggestion would be to check if the second directory starting from the right is box. Another one would be to have different behavior based on the platform. A third one would be to search for any composer.json that does not contain kherge/box as its name, starting from the current script execution path. There's probably plenty of other ways, although I'm not sure which one is the most appropriate one.

theofidry commented 6 years ago

Fixed in https://github.com/humbug/box/pull/3