feat(compat): declare core independence with core:"none" (INDEPENDENT status, block inheritance, no warning)

This commit is contained in:
kj
2026-10-06 14:12:36 -03:00
parent fc51133d92
commit 901968d0bd
9 changed files with 247 additions and 69 deletions
+37 -35
View File
@@ -1,38 +1,40 @@
{
"name": "commands",
"version": "0.2.2",
"description": "CLI y migraciones para Duckbrain",
"components": {
"cli": {
"files": [
"duckbrain",
"src/Interfaces/CommandInterface.php"
],
"description": "CLI del proyecto (binario duckbrain)"
},
"migration": {
"files": [
"src/Commands/Migration.php",
"src/Libs/Migration.php"
],
"require": {
"commands:cli": "*"
},
"core": {
"requires": ">=0.1",
"tested": "0.1"
},
"description": "Migraciones de base de datos (mysql/pgsql/sqlite)"
},
"toolbox": {
"files": [
"src/Toolbox"
],
"description": "Gestor de addons dentro del propio proyecto"
}
"name": "commands",
"version": "0.2.2",
"description": "CLI y migraciones para Duckbrain",
"components": {
"cli": {
"files": [
"duckbrain",
"src/Interfaces/CommandInterface.php"
],
"description": "CLI del proyecto (binario duckbrain)",
"core": "none"
},
"default": [
"cli",
"migration"
]
"migration": {
"files": [
"src/Commands/Migration.php",
"src/Libs/Migration.php"
],
"require": {
"commands:cli": "*"
},
"core": {
"requires": ">=0.1",
"tested": "0.1"
},
"description": "Migraciones de base de datos (mysql/pgsql/sqlite)"
},
"toolbox": {
"files": [
"src/Toolbox"
],
"description": "Gestor de addons dentro del propio proyecto",
"core": "none"
}
},
"default": [
"cli",
"migration"
]
}
@@ -33,17 +33,19 @@ final class DoctorCommand extends Command
foreach ($lock->components() as $id => $entry) {
[$package, $component] = array_pad(explode(':', $id, 2), 2, null);
$requires = null;
$tested = null;
$requires = null;
$tested = null;
$independent = false;
if ($component !== null && $package !== null && $catalog->has($package)) {
$manifest = $catalog->get($package);
if ($manifest->hasComponent($component)) {
$requires = $manifest->coreRequirement($component);
$tested = $manifest->testedCore($component);
$requires = $manifest->coreRequirement($component);
$tested = $manifest->testedCore($component);
$independent = $manifest->coreIndependent($component);
}
}
$result = Compatibility::evaluateCore($coreVersion, $requires, $tested);
$result = Compatibility::evaluateCore($coreVersion, $requires, $tested, $independent);
$rows[] = [
$id,
@@ -12,6 +12,7 @@ final class Compatibility
public const UNTESTED = 'untested';
public const INSUFFICIENT = 'insufficient';
public const UNKNOWN = 'unknown';
public const INDEPENDENT = 'independent';
/**
* @return array{status:string, message:string}
@@ -19,8 +20,13 @@ final class Compatibility
public static function evaluateCore(
?string $coreVersion,
?string $requires,
?string $tested
?string $tested,
bool $independent = false
): array {
if ($independent) {
return ['status' => self::INDEPENDENT, 'message' => 'independiente del core'];
}
if ($coreVersion === null) {
return ['status' => self::UNKNOWN, 'message' => 'versión del core desconocida (sin tags)'];
}
@@ -68,10 +74,11 @@ final class Compatibility
public static function label(string $status): string
{
return match ($status) {
self::OK => 'OK',
self::UNTESTED => 'NO PROBADO',
self::INSUFFICIENT => 'INSUFICIENTE',
default => 'SIN DATOS',
self::OK => 'OK',
self::UNTESTED => 'NO PROBADO',
self::INSUFFICIENT => 'INSUFICIENTE',
self::INDEPENDENT => 'INDEPENDIENTE',
default => 'SIN DATOS',
};
}
}
+42 -2
View File
@@ -18,6 +18,8 @@ final class Component
public readonly ?string $description = null,
public readonly ?array $destinations = null,
public readonly bool $override = false,
public readonly bool $coreDeclared = false,
public readonly ?bool $coreIndependent = null,
) {
}
@@ -61,15 +63,53 @@ final class Component
$description = $data['description'];
}
$coreDeclared = array_key_exists('core', $data);
$coreIndependent = null;
$coreRequires = null;
$coreTested = null;
if ($coreDeclared) {
[$coreRequires, $coreTested, $coreIndependent] = self::parseCore($data['core'], "el componente '{$name}'");
}
return new self(
name: $name,
files: array_values($data['files']),
requires: $requires,
coreRequires: $data['core']['requires'] ?? null,
coreTested: $data['core']['tested'] ?? null,
coreRequires: $coreRequires,
coreTested: $coreTested,
description: $description,
destinations: $destinations,
override: (bool) ($data['override'] ?? false),
coreDeclared: $coreDeclared,
coreIndependent: $coreIndependent,
);
}
/**
* Bloque `core`: objeto de rango ({requires?, tested?}) o la cadena
* "none" (independencia afirmativa, excluyente con el rango).
*
* @return array{0: ?string, 1: ?string, 2: ?bool}
*/
public static function parseCore(mixed $core, string $origin): array
{
if ($core === 'none') {
return [null, null, true];
}
if (!is_array($core)) {
throw new ToolboxException("{$origin} tiene un 'core' inválido");
}
$requires = $core['requires'] ?? null;
$tested = $core['tested'] ?? null;
foreach (['requires' => $requires, 'tested' => $tested] as $key => $value) {
if ($value !== null && !is_string($value)) {
throw new ToolboxException("{$origin} tiene un 'core.{$key}' inválido");
}
}
return [$requires, $tested, null];
}
}
+3 -2
View File
@@ -111,10 +111,11 @@ final class Installer
$compat = Compatibility::evaluateCore(
$this->coreVersion(),
$manifest->coreRequirement($componentName),
$manifest->testedCore($componentName)
$manifest->testedCore($componentName),
$manifest->coreIndependent($componentName)
);
if ($compat['status'] !== Compatibility::OK) {
if (!in_array($compat['status'], [Compatibility::OK, Compatibility::INDEPENDENT], true)) {
$warnings[] = $id . ': ' . $compat['message'];
$assumeYes = (bool) ($options['yes'] ?? false);
if (!$assumeYes && !$this->console->confirm(" {$id}: {$compat['message']}. ¿Continuar?", false)) {
+32 -9
View File
@@ -18,6 +18,7 @@ final class Manifest
public readonly ?string $coreTested,
public readonly ?string $php,
public readonly array $postInstall,
public readonly ?bool $coreIndependent = null,
) {
}
@@ -83,16 +84,23 @@ final class Manifest
$postInstall[] = $command;
}
$coreRequires = $coreTested = null;
$coreIndependent = null;
if (array_key_exists('core', $data)) {
[$coreRequires, $coreTested, $coreIndependent] = Component::parseCore($data['core'], "el manifiesto '{$origin}'");
}
return new self(
name: $name,
version: $version,
description: is_string($data['description'] ?? null) ? $data['description'] : '',
components: $components,
default: $default,
coreRequires: $data['core']['requires'] ?? null,
coreTested: $data['core']['tested'] ?? null,
coreRequires: $coreRequires,
coreTested: $coreTested,
php: is_string($data['php'] ?? null) ? $data['php'] : null,
postInstall: $postInstall,
coreIndependent: $coreIndependent,
);
}
@@ -140,22 +148,37 @@ final class Manifest
return $this->default;
}
public function coreRequirement(?string $component = null): ?string
/**
* Bloque de core efectivo: si el componente declara `core` (rango o
* "none") ese bloque gana por completo; si no, hereda el del paquete.
*
* @return array{requires: ?string, tested: ?string, independent: ?bool}
*/
private function coreBlock(?string $component): array
{
if ($component !== null) {
return $this->component($component)->coreRequires ?? $this->coreRequires;
$c = $this->component($component);
if ($c->coreDeclared) {
return ['requires' => $c->coreRequires, 'tested' => $c->coreTested, 'independent' => $c->coreIndependent];
}
}
return $this->coreRequires;
return ['requires' => $this->coreRequires, 'tested' => $this->coreTested, 'independent' => $this->coreIndependent];
}
public function coreRequirement(?string $component = null): ?string
{
return $this->coreBlock($component)['requires'];
}
public function testedCore(?string $component = null): ?string
{
if ($component !== null) {
return $this->component($component)->coreTested ?? $this->coreTested;
}
return $this->coreBlock($component)['tested'];
}
return $this->coreTested;
public function coreIndependent(?string $component = null): bool
{
return $this->coreBlock($component)['independent'] === true;
}
/**