Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
],
"require": {
"php": "^8.2",
"composer-runtime-api": "^2.0",
"ext-json": "*",
"ext-phar": "*",
"ext-openssl": "*",
Expand Down
8 changes: 5 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/Command/CompileCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down
20 changes: 20 additions & 0 deletions tests/Unit/CompileCommandBoxTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use Parcel\Command\CompileCommand;
use Symfony\Component\Filesystem\Filesystem;

it('runs the Box installed alongside Parcel, not one from the project', function () {
// Box has to load Parcel's compactors, so only the Box from Parcel's
// own vendor/ will do, even when the project has a Box of its own.
$project = sys_get_temp_dir().'/parcel-box-'.uniqid();
(new Filesystem)->dumpFile($project.'/vendor/bin/box', "#!/usr/bin/env php\n<?php\n");

try {
$resolve = new ReflectionMethod(CompileCommand::class, 'resolveBoxBinary');
$box = $resolve->invoke(new CompileCommand, $project);

expect(realpath($box))->toBe(realpath(__DIR__.'/../../vendor/bin/box'));
} finally {
(new Filesystem)->remove($project);
}
});
Loading