fix: handle array package features
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled

This commit is contained in:
Codex Agent
2026-01-12 12:29:19 +01:00
parent 915aede66e
commit f01a0e823b
3 changed files with 48 additions and 15 deletions

View File

@@ -17,12 +17,30 @@ export type PackageComparisonRow =
featureKey: string;
};
function collectFeatures(pkg: Package | null): Set<string> {
function normalizePackageFeatures(pkg: Package | null): string[] {
if (!pkg?.features) {
return new Set();
return [];
}
return new Set(Object.entries(pkg.features).filter(([, enabled]) => enabled).map(([key]) => key));
if (Array.isArray(pkg.features)) {
return pkg.features.filter((feature): feature is string => typeof feature === 'string' && feature.trim().length > 0);
}
if (typeof pkg.features === 'object') {
return Object.entries(pkg.features)
.filter(([, enabled]) => enabled)
.map(([key]) => key);
}
return [];
}
export function getEnabledPackageFeatures(pkg: Package): string[] {
return normalizePackageFeatures(pkg);
}
function collectFeatures(pkg: Package | null): Set<string> {
return new Set(normalizePackageFeatures(pkg));
}
function compareLimit(candidate: number | null, active: number | null): number {
@@ -88,7 +106,7 @@ export function selectRecommendedPackageId(
return null;
}
const candidates = packages.filter((pkg) => pkg.features?.[feature]);
const candidates = packages.filter((pkg) => normalizePackageFeatures(pkg).includes(feature));
if (candidates.length === 0) {
return null;
}
@@ -109,8 +127,8 @@ export function buildPackageComparisonRows(packages: Package[]): PackageComparis
const featureKeys = new Set<string>();
packages.forEach((pkg) => {
Object.entries(pkg.features ?? {}).forEach(([key, enabled]) => {
if (enabled && key !== 'photos') {
normalizePackageFeatures(pkg).forEach((key) => {
if (key !== 'photos') {
featureKeys.add(key);
}
});