From 8b4cca6c2fb8c457672b6b5d2cf75cd7da44bd69 Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Fri, 20 Nov 2026 00:30:15 +0000 Subject: [PATCH] Run the Box that was installed alongside Parcel Box has to load Parcel's compactors, so it needs an autoloader with Parcel in it. compile looked for Box in the project, then in Parcel's own vendor/, then on the PATH. Parcel only has its own vendor/ in a checkout. Installed from Packagist, Box sits next to it in the shared vendor/, so compile fell through to whatever box was on the PATH and failed with "The compactor class Parcel\Compactor\RealPathMod does not exist" unless that happened to be the right one. Ask Composer where it installed humbug/box for this copy of Parcel and run the vendor/bin/box beside it first. Co-Authored-By: Claude Opus 5.5 --- composer.json | 1 + composer.lock | 8 +++++--- src/Command/CompileCommand.php | 19 +++++++++++++++++++ tests/Unit/CompileCommandBoxTest.php | 20 ++++++++++++++++++++ 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tests/Unit/CompileCommandBoxTest.php 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); + } +});