From 7a91ffe1762f1794211e561cf893d7627b0445f6 Mon Sep 17 00:00:00 2001 From: roble Date: Thu, 25 Jun 2026 21:35:03 +0100 Subject: [PATCH] feat: optimize module installation process in InstallCommand and DockerEnvironment for improved performance and error handling --- src/Console/Commands/InstallCommand.php | 40 ++++++++----------------- src/Environments/DockerEnvironment.php | 19 +++++------- 2 files changed, 20 insertions(+), 39 deletions(-) diff --git a/src/Console/Commands/InstallCommand.php b/src/Console/Commands/InstallCommand.php index 0a199ef..78739b4 100644 --- a/src/Console/Commands/InstallCommand.php +++ b/src/Console/Commands/InstallCommand.php @@ -314,39 +314,23 @@ protected function setupModules(): void $this->newLine(); - // Phase 1: require all selected packages - $anyFailed = false; - foreach ($selected as $package) { - $ok = false; - $this->components->task("Requiring {$package}", function () use ($package, &$ok) { - $process = new Process(['composer', 'require', $package, '--no-interaction']); - $process->setTimeout(300); - $process->run(); - - return $ok = $process->isSuccessful(); - }); + // Phase 1: require all selected packages in one Composer run + $ok = false; + $this->components->task('Installing modules', function () use ($selected, &$ok) { + $process = new Process(array_merge(['composer', 'require', '--no-interaction'], $selected)); + $process->setTimeout(300); + $process->run(); - if (! $ok) { - $anyFailed = true; - } - } + return $ok = $process->isSuccessful(); + }); - if ($anyFailed) { - $this->components->warn('One or more packages failed to install — skipping module sync and migrations.'); + if (! $ok) { + $this->components->warn('Module installation failed — skipping patches, sync, and migrations.'); return; } - // Phase 2: regenerate autoload once for all new modules - $this->components->task('Dumping autoload', function () { - $process = new Process(['composer', 'dump-autoload', '--no-interaction']); - $process->setTimeout(120); - $process->run(); - - return $process->isSuccessful(); - }); - - // Phase 2.5: apply any patches the modules ship for the host app + // Phase 2: apply any patches the modules ship for the host app $this->applyModulePatches($selected); // Phase 3: sync module configs, then migrate + seed each module individually @@ -370,7 +354,7 @@ protected function setupModules(): void }); $this->components->task("Seeding {$name}", function () use ($name) { - $process = new Process([PHP_BINARY, base_path('artisan'), 'modules:seed', "--module={$name}"]); + $process = new Process([PHP_BINARY, base_path('artisan'), 'db:seed', "--module={$name}", '--force']); $process->setTimeout(60); $process->run(); diff --git a/src/Environments/DockerEnvironment.php b/src/Environments/DockerEnvironment.php index 6e28ca2..2d8d832 100644 --- a/src/Environments/DockerEnvironment.php +++ b/src/Environments/DockerEnvironment.php @@ -236,28 +236,25 @@ protected function installModules(InstallCommand $command): void $command->info('Installing modules...'); - $anyFailed = false; - foreach ($modules as $package) { - $ok = $this->execInContainer($command, ['composer', 'require', $package, '--no-interaction'], timeout: 300); + $ok = $this->execInContainer( + $command, + ['composer', 'require', ...$modules, '--no-interaction'], + timeout: 300, + ); - if (! $ok) { - $command->warn("Failed to require {$package} — skipping."); - $anyFailed = true; - } - } + if (! $ok) { + $command->warn('Failed to install one or more modules — skipping patches, sync, and migrations.'); - if ($anyFailed) { return; } - $this->execInContainer($command, ['composer', 'dump-autoload', '--no-interaction']); $command->applyModulePatches($modules); $this->execInContainer($command, ['php', 'artisan', 'modules:sync']); foreach ($modules as $package) { $name = Str::after($package, '/'); $this->execInContainer($command, ['php', 'artisan', 'modules:migrate', "--module={$name}", '--force'], timeout: 120); - $this->execInContainer($command, ['php', 'artisan', 'modules:seed', "--module={$name}"]); + $this->execInContainer($command, ['php', 'artisan', 'db:seed', "--module={$name}", '--force']); } }