diff --git a/composer.json b/composer.json index 0851154..5e75184 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ ], "require": { "php": "^8.2", + "composer-runtime-api": "^2.0", "ext-json": "*", "ext-phar": "*", "ext-openssl": "*", diff --git a/composer.lock b/composer.lock index c95b469..b826693 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8d7a5147f44ab9843f2caa627bed1695", + "content-hash": "769e1b0f2d46118ea7eb263b4d794b8c", "packages": [ { "name": "amphp/amp", @@ -5169,7 +5169,8 @@ "type": "github" } ], - "time": "2025-11-11T15:18:17+00:00" + "time": "2025-11-11T15:18:17+00:00", + "published-time": "2025-11-11T15:18:29+00:00" }, { "name": "phpunit/php-code-coverage", @@ -6596,10 +6597,11 @@ "prefer-lowest": false, "platform": { "php": "^8.2", + "composer-runtime-api": "^2.0", "ext-json": "*", "ext-phar": "*", "ext-openssl": "*" }, "platform-dev": {}, - "plugin-api-version": "2.9.0" + "plugin-api-version": "2.11.0" } diff --git a/src/Command/CompileCommand.php b/src/Command/CompileCommand.php index 115853d..abc2e9c 100644 --- a/src/Command/CompileCommand.php +++ b/src/Command/CompileCommand.php @@ -4,6 +4,7 @@ namespace Parcel\Command; +use Composer\InstalledVersions; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -160,6 +161,24 @@ private function formatBytes(int $bytes): string private function resolveBoxBinary(string $workingDir): string { + // Box loads Parcel's compactors, so it has to run with an autoloader + // that has Parcel in it: the one from the vendor/ Composer installed + // this copy of Parcel into. In a checkout that's Parcel's own vendor/. + // Installed as a package (globally, say) Box sits next to Parcel in + // the shared vendor/, and Parcel has no vendor/ of its own. A Box + // from anywhere else can't find Parcel\Compactor\RealPathMod. + if (InstalledVersions::isInstalled('humbug/box')) { + $installPath = InstalledVersions::getInstallPath('humbug/box'); + + if ($installPath !== null) { + $boxBinary = Path::canonicalize(Path::join(dirname($installPath, 2), 'bin', 'box')); + + if ($this->filesystem->exists($boxBinary)) { + return $boxBinary; + } + } + } + // When in local development, prefer the vendor/bin/box binary $localBoxBinary = Path::join($workingDir, 'vendor/bin/box'); if ($this->filesystem->exists($localBoxBinary)) { diff --git a/tests/Unit/CompileCommandBoxTest.php b/tests/Unit/CompileCommandBoxTest.php new file mode 100644 index 0000000..6e4acba --- /dev/null +++ b/tests/Unit/CompileCommandBoxTest.php @@ -0,0 +1,20 @@ +dumpFile($project.'/vendor/bin/box', "#!/usr/bin/env php\ninvoke(new CompileCommand, $project); + + expect(realpath($box))->toBe(realpath(__DIR__.'/../../vendor/bin/box')); + } finally { + (new Filesystem)->remove($project); + } +});