Skip to content

Commit b376bff

Browse files
author
Dmytro Lukianenko
committed
[ADD] Replace isComposerVendorHealthy checks with verifyComposerVendor method for improved dependency verification.
1 parent e08d314 commit b376bff

1 file changed

Lines changed: 23 additions & 9 deletions

File tree

src/Commands/InstallCommand.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,14 +1370,14 @@ protected function setupComposer(string $projectPath): void
13701370

13711371
$installArgs = ['install', '--no-dev', '--prefer-dist', '--no-scripts', '--no-cache'];
13721372
$process = $this->runComposer($composerCommand, $installArgs, $composerWorkDir);
1373-
if ($process->isSuccessful() && !$this->isComposerVendorHealthy($composerWorkDir)) {
1373+
if ($process->isSuccessful() && !$this->verifyComposerVendor($composerWorkDir)) {
13741374
$this->tui->addLog('Composer install finished but vendor is incomplete. Retrying with clean vendor and --prefer-source (this can happen due to GitHub rate limits)...', 'warning');
13751375
if (is_dir($vendorDir)) {
13761376
$this->removeDirectory($vendorDir);
13771377
}
13781378
$process = $this->runComposer($composerCommand, ['install', '--no-dev', '--prefer-source', '--no-scripts', '--no-cache'], $composerWorkDir);
13791379
}
1380-
if ($process->isSuccessful() && $this->isComposerVendorHealthy($composerWorkDir)) {
1380+
if ($process->isSuccessful() && $this->verifyComposerVendor($composerWorkDir)) {
13811381
$this->tui->addLog('Dependencies installed successfully.', 'success');
13821382
return;
13831383
}
@@ -1403,15 +1403,15 @@ protected function setupComposer(string $projectPath): void
14031403

14041404
// Reinstall with prefer-dist
14051405
$reinstall = $this->runComposer($composerCommand, $installArgs, $composerWorkDir);
1406-
if ($reinstall->isSuccessful() && $this->isComposerVendorHealthy($composerWorkDir)) {
1406+
if ($reinstall->isSuccessful() && $this->verifyComposerVendor($composerWorkDir)) {
14071407
$this->tui->addLog('Dependencies reinstalled successfully.', 'success');
14081408
return;
14091409
}
14101410

14111411
// If install fails, try update as fallback
14121412
$this->tui->addLog('Install failed. Trying composer update...', 'warning');
14131413
$update = $this->runComposer($composerCommand, ['update', '--no-dev', '--prefer-dist', '--no-scripts'], $composerWorkDir);
1414-
if ($update->isSuccessful() && $this->isComposerVendorHealthy($composerWorkDir)) {
1414+
if ($update->isSuccessful() && $this->verifyComposerVendor($composerWorkDir)) {
14151415
$this->tui->addLog('Dependencies updated successfully.', 'success');
14161416
return;
14171417
}
@@ -1425,7 +1425,7 @@ protected function setupComposer(string $projectPath): void
14251425
|| str_contains($fullOutput, 'requires php >=8.4')) {
14261426
$this->tui->addLog('composer.lock is not compatible with current PHP. Running composer update...', 'warning');
14271427
$update = $this->runComposer($composerCommand, ['update', '--no-dev', '--prefer-dist', '--no-scripts'], $composerWorkDir);
1428-
if ($update->isSuccessful() && $this->isComposerVendorHealthy($composerWorkDir)) {
1428+
if ($update->isSuccessful() && $this->verifyComposerVendor($composerWorkDir)) {
14291429
$this->tui->addLog('Dependencies updated successfully.', 'success');
14301430
return;
14311431
}
@@ -1450,7 +1450,7 @@ protected function setupComposer(string $projectPath): void
14501450

14511451
// Reinstall with prefer-dist
14521452
$reinstall = $this->runComposer($composerCommand, $installArgs, $composerWorkDir);
1453-
if ($reinstall->isSuccessful() && $this->isComposerVendorHealthy($composerWorkDir)) {
1453+
if ($reinstall->isSuccessful() && $this->verifyComposerVendor($composerWorkDir)) {
14541454
$this->tui->addLog('Dependencies reinstalled successfully.', 'success');
14551455
return;
14561456
}
@@ -1492,6 +1492,20 @@ protected function isComposerVendorHealthy(string $composerWorkDir): bool
14921492
return true;
14931493
}
14941494

1495+
protected function verifyComposerVendor(string $composerWorkDir, int $attempts = 3, int $sleepMs = 400): bool
1496+
{
1497+
$this->tui->addLog('Verifying Composer dependencies...');
1498+
for ($i = 0; $i < $attempts; $i++) {
1499+
if ($this->isComposerVendorHealthy($composerWorkDir)) {
1500+
return true;
1501+
}
1502+
if ($i < $attempts - 1) {
1503+
usleep($sleepMs * 1000);
1504+
}
1505+
}
1506+
return false;
1507+
}
1508+
14951509
protected function isNonEmptyFile(string $path): bool
14961510
{
14971511
$size = @filesize($path);
@@ -1522,7 +1536,7 @@ protected function ensureArtisanDependencies(string $projectPath): void
15221536
{
15231537
$composerWorkDir = is_file($projectPath . '/core/composer.json') ? ($projectPath . '/core') : $projectPath;
15241538

1525-
if ($this->isComposerVendorHealthy($composerWorkDir)) {
1539+
if ($this->verifyComposerVendor($composerWorkDir)) {
15261540
return;
15271541
}
15281542

@@ -1537,7 +1551,7 @@ protected function ensureArtisanDependencies(string $projectPath): void
15371551

15381552
$installArgs = ['install', '--no-dev', '--prefer-dist', '--no-scripts', '--no-cache'];
15391553
$process = $this->runComposer($composerCommand, $installArgs, $composerWorkDir);
1540-
if ($process->isSuccessful() && $this->isComposerVendorHealthy($composerWorkDir)) {
1554+
if ($process->isSuccessful() && $this->verifyComposerVendor($composerWorkDir)) {
15411555
$this->tui->addLog('Dependencies reinstalled successfully.', 'success');
15421556
return;
15431557
}
@@ -1549,7 +1563,7 @@ protected function ensureArtisanDependencies(string $projectPath): void
15491563
$this->removeDirectory($vendorDir);
15501564
}
15511565
$process = $this->runComposer($composerCommand, ['install', '--no-dev', '--prefer-source', '--no-scripts', '--no-cache'], $composerWorkDir);
1552-
if ($process->isSuccessful() && $this->isComposerVendorHealthy($composerWorkDir)) {
1566+
if ($process->isSuccessful() && $this->verifyComposerVendor($composerWorkDir)) {
15531567
$this->tui->addLog('Dependencies installed successfully (prefer-source).', 'success');
15541568
return;
15551569
}

0 commit comments

Comments
 (0)