diff --git a/src/Command/CheckCommand.php b/src/Command/CheckCommand.php index 39346ff..a2a92f8 100644 --- a/src/Command/CheckCommand.php +++ b/src/Command/CheckCommand.php @@ -14,6 +14,7 @@ namespace Pmu\Command; use Composer\Command\BaseCommand; +use Composer\Console\Input\InputOption; use Pmu\Composer\BaseDirTrait; use Pmu\Config; use Pmu\Dependencies; @@ -26,16 +27,24 @@ final class CheckCommand extends BaseCommand protected function configure(): void { - $this->setName('check-dependencies')->setDescription('Checks the monorepo dependencies.'); + $this->setName('check-dependencies') + ->setDescription('Checks the monorepo dependencies.') + ->setDefinition([ + new InputOption('working-directory', 'wd', InputOption::VALUE_REQUIRED, "Defaults to SERVER['PWD']"), + ]); } protected function execute(InputInterface $input, OutputInterface $output): int { - $autoload = getcwd() . '/vendor/autoload.php'; - if (file_exists($autoload)) { - require_once $autoload; + $wd = $input->getOption('working-directory') ?? $_SERVER['PWD'] ?? null; + $autoload = $wd . '/vendor/autoload.php'; + + if (!file_exists($autoload)) { + $output->writeln(sprintf('No autoload at path "%s".', $autoload)); + return 1; } + require_once $autoload; $composer = $this->requireComposer(); $config = Config::create($composer); $repo = $composer->getRepositoryManager(); diff --git a/src/Command/LinkCommand.php b/src/Command/LinkCommand.php index 15e928a..1d6cbb6 100644 --- a/src/Command/LinkCommand.php +++ b/src/Command/LinkCommand.php @@ -44,6 +44,7 @@ protected function configure(): void ->setDefinition([ new InputArgument('path', InputArgument::OPTIONAL, 'Path to link.'), new InputOption('working-directory', 'wd', InputOption::VALUE_REQUIRED, "Defaults to SERVER['PWD']"), + new InputOption('permanent', 'p', InputOption::VALUE_NONE, "Permanent composer change, does not revert backups."), ]); } @@ -127,6 +128,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int } catch (\Exception $e) { } + if ($input->getOption('permanent')) { + return 0; + } + foreach ($revert as $file => $backup) { rename($backup, $file); } diff --git a/src/Dependencies.php b/src/Dependencies.php index 045c45f..23f5cc3 100644 --- a/src/Dependencies.php +++ b/src/Dependencies.php @@ -90,7 +90,7 @@ public static function collectProjectsData(Config $config, RepositoryManager $re } if ($computeClassMap) { - $classMapGenerator->scanPaths(dirname($composerFile)); + $classMapGenerator->scanPaths(dirname($composerFile), null, 'classmap', null, ['vendor']); foreach ($classMapGenerator->getClassMap()->getMap() as $class => $path) { foreach ($namespaces as $ns) { foreach ($config->exclude as $g) {