fix(commands): surface core fetch errors, run post-install in the project, exit 1 on invalid project command; document compat flow

This commit is contained in:
kj
2026-10-05 17:36:08 -03:00
parent eb5e6eeed4
commit 6925b814e6
6 changed files with 97 additions and 55 deletions
+31 -15
View File
@@ -11,35 +11,51 @@ final class PostInstall
/**
* @param list<string> $commands
* @param callable(string):int|null $runner
* @param string|null $cwd Directorio de trabajo del proyecto: los
* comandos se ejecutan alli, no donde arranco
* el instalador.
* @return list<string> comandos ejecutados
*/
public static function run(
array $commands,
Console $console,
bool $assumeYes = false,
?callable $runner = null
?callable $runner = null,
?string $cwd = null
): array {
$executed = [];
$previous = null;
foreach ($commands as $command) {
$console->out(' post-install: ' . $command);
if ($cwd !== null && is_dir($cwd)) {
$previous = getcwd();
chdir($cwd);
}
if (!$console->confirm(' ¿Ejecutar?', $assumeYes)) {
$console->warn('post-install omitido: ' . $command);
try {
foreach ($commands as $command) {
$console->out(' post-install: ' . $command);
continue;
}
if (!$console->confirm(' ¿Ejecutar?', $assumeYes)) {
$console->warn('post-install omitido: ' . $command);
if ($runner !== null) {
$runner($command);
} else {
passthru($command, $code);
if (($code ?? 0) !== 0) {
throw new ToolboxException("post-install falló: {$command}");
continue;
}
}
$executed[] = $command;
if ($runner !== null) {
$runner($command);
} else {
passthru($command, $code);
if (($code ?? 0) !== 0) {
throw new ToolboxException("post-install falló: {$command}");
}
}
$executed[] = $command;
}
} finally {
if ($previous !== null) {
chdir($previous);
}
}
return $executed;