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
@@ -36,7 +36,12 @@ final class CoreProvider
throw new ToolboxException('No se pudo clonar el core: ' . implode("\n", $out));
}
} else {
exec('git -C ' . escapeshellarg($dir) . ' fetch -q --tags 2>&1');
exec('git -C ' . escapeshellarg($dir) . ' remote set-url origin ' . escapeshellarg($url) . ' 2>&1');
$out = [];
exec('git -C ' . escapeshellarg($dir) . ' fetch -q --tags 2>&1', $out, $code);
if ($code !== 0) {
throw new ToolboxException('No se pudo actualizar el core: ' . implode("\n", $out));
}
}
$provider = new self($dir);
+2 -1
View File
@@ -191,7 +191,8 @@ final class Installer
$manifest->postInstall,
$this->console,
(bool) ($options['yes'] ?? false),
$options['postRunner'] ?? null
$options['postRunner'] ?? null,
$this->root,
);
}
}
+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;