Skip to content

Commit

Permalink
Bug fix: composer ScriptHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
SindlaXYZ committed Oct 29, 2023
1 parent b5871fa commit d79fc52
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/Composer/ScriptHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static function postInstall(Event $event)
$options = static::getOptions($event);

// Run the ComposerCommand [composer:run]
static::executeCommand($event, 'bin', 'aurora:composer --action=postInstall', $options['process-timeout']);
static::executeCommand($event, 'bin', 'aurora:composer', ['--action=postInstall'], $options['process-timeout']);
}

/**
Expand All @@ -64,7 +64,7 @@ public static function postUpdate(Event $event)
$options = static::getOptions($event);

// Run the ComposerCommand [composer:run]
static::executeCommand($event, 'bin', 'aurora:composer --action=postUpdate', $options['process-timeout']);
static::executeCommand($event, 'bin', 'aurora:composer', ['--action=postUpdate'], $options['process-timeout']);
}

protected static function getPhp($includeArgs = true)
Expand Down Expand Up @@ -101,21 +101,33 @@ protected static function getPhpArguments()
return $arguments;
}

protected static function executeCommand(Event $event, $consoleDir, $cmd, $timeout = 300)
protected static function executeCommand(Event $event, $consoleDir, $cmd, array $commandArguments = [], $timeout = 300)
{
$php = escapeshellarg(static::getPhp(false));
$phpArgs = implode(' ', array_map('escapeshellarg', static::getPhpArguments()));
$console = escapeshellarg($consoleDir . '/console');
$processCommand[] = static::getPhp(false);
foreach (static::getPhpArguments() as $phpArgument) {
$processCommand[] = $phpArgument;
}
$processCommand[] = $consoleDir . '/console';
$processCommand[] = $cmd;
foreach ($commandArguments as $commandArgument) {
$processCommand[] = $commandArgument;
}
if ($event->getIO()->isDecorated()) {
$console .= ' --ansi';
$processCommand[] = '--ansi';
}

$process = new Process($php . ($phpArgs ? ' ' . $phpArgs : '') . ' ' . $console . ' ' . $cmd, null, null, null, $timeout);
$process = new Process($processCommand, null, null, null, $timeout);
$process->run(function ($type, $buffer) use ($event) {
$event->getIO()->write($buffer, false);
});
if (!$process->isSuccessful()) {
throw new \RuntimeException(sprintf("An error occurred when executing the \"%s\" command:\n\n%s\n\n%s", escapeshellarg($cmd), self::removeDecoration($process->getOutput()), self::removeDecoration($process->getErrorOutput())));
throw new \RuntimeException(sprintf(
"An error occurred when executing the \"%s\" command.\n%s\nError:\n\n%s\n\n%s",
$cmd,
trim(implode(' ', array_map('trim', $processCommand))),
self::removeDecoration($process->getOutput()),
self::removeDecoration($process->getErrorOutput())
));
}
}

Expand Down

0 comments on commit d79fc52

Please sign in to comment.