info('๐Ÿ“ฆ Starting composer update process...'); // Check if composer.json exists if (! File::exists(base_path('composer.json'))) { $this->error('composer.json not found'); return Command::FAILURE; } // Check if composer.lock exists to determine install vs update $hasLockFile = File::exists(base_path('composer.lock')); if ($hasLockFile) { $this->info('๐Ÿ”„ Installing dependencies from lock file...'); $this->composerInstall(); } else { $this->info('๐Ÿ†• Creating new lock file and installing dependencies...'); $this->composerUpdate(); } // Clear autoloader cache $this->info('๐Ÿงน Clearing autoloader cache...'); $this->clearAutoloaderCache(); $this->info('โœ… Composer update completed successfully'); return Command::SUCCESS; } catch (\Exception $e) { $this->error('โŒ Composer update failed: '.$e->getMessage()); return Command::FAILURE; } } /** * Run composer install */ private function composerInstall(): void { $command = $this->buildComposerCommand('install'); $process = Process::timeout(600) ->path(base_path()) ->run($command); if (! $process->successful()) { throw new \Exception('Composer install failed: '.$process->errorOutput()); } $this->line(' โœ“ Dependencies installed successfully'); } /** * Run composer update */ private function composerUpdate(): void { $command = $this->buildComposerCommand('update'); $process = Process::timeout(600) ->path(base_path()) ->run($command); if (! $process->successful()) { throw new \Exception('Composer update failed: '.$process->errorOutput()); } $this->line(' โœ“ Dependencies updated successfully'); } /** * Build composer command with options */ private function buildComposerCommand(string $action): string { $command = "composer $action"; // Add common flags for performance $command .= ' --no-interaction --no-progress'; if ($this->option('no-dev')) { $command .= ' --no-dev'; } if ($this->option('prefer-dist')) { $command .= ' --prefer-dist'; } if ($this->option('optimize') || app()->environment('production')) { $command .= ' --optimize-autoloader --classmap-authoritative'; } return $command; } /** * Clear autoloader cache */ private function clearAutoloaderCache(): void { $process = Process::timeout(30) ->path(base_path()) ->run('composer dump-autoload --optimize'); if (! $process->successful()) { $this->warn(' โš  Failed to optimize autoloader'); } else { $this->line(' โœ“ Autoloader optimized'); } } }