fix: allow path repos

Temporarily configure cwd while running composer commands so that path repositories can be resolved properly.

Fixes https://github.com/flarum/package-manager/issues/6
This commit is contained in:
Alexander Skvortsov 2022-01-24 01:28:34 -05:00
parent a7535ab20a
commit 919ba129f4
2 changed files with 13 additions and 2 deletions

View File

@ -10,6 +10,7 @@
namespace Flarum\PackageManager\Composer;
use Composer\Console\Application;
use Flarum\Foundation\Paths;
use Flarum\PackageManager\OutputLogger;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\BufferedOutput;
@ -34,10 +35,16 @@ class ComposerAdapter
*/
private $output;
public function __construct(Application $application, OutputLogger $logger)
/**
* @var Paths
*/
private $paths;
public function __construct(Application $application, OutputLogger $logger, Paths $paths)
{
$this->application = $application;
$this->logger = $logger;
$this->paths = $paths;
$this->output = new BufferedOutput();
}
@ -45,7 +52,11 @@ class ComposerAdapter
{
$this->application->resetComposer();
// This hack is necessary so that relative path repositories are resolved properly.
$currDir = getcwd();
chdir($this->paths->base);
$exitCode = $this->application->run($input, $this->output);
chdir($currDir);
$outputContents = $this->output->fetch();

View File

@ -50,7 +50,7 @@ class PackageManagerServiceProvider extends AbstractServiceProvider
@ini_set('memory_limit', '1G');
@set_time_limit(5 * 60);
return new ComposerAdapter($composer, $container->make(OutputLogger::class));
return new ComposerAdapter($composer, $container->make(OutputLogger::class), $container->make(Paths::class));
});
$this->container->alias(ComposerAdapter::class, 'flarum.composer');