fix(icon_pack): listing definitions even if parsing fails

This commit is contained in:
Elian Doran 2025-12-26 19:42:23 +02:00
parent 2c4ac4ba30
commit a26923cc6d
No known key found for this signature in database
2 changed files with 26 additions and 4 deletions

View File

@ -174,4 +174,21 @@ describe("Icon registery", () => {
]
});
});
it("ignores incorrect manifest", () => {
const iconPack = processIconPack(buildNote({
type: "text",
content: JSON.stringify({
name: "Boxicons v2",
prefix: "bx",
icons: {
"bx-ball": "\ue9c2",
"bxs-party": "\uec92"
}
}),
attachments: [ defaultAttachment ]
}));
const registry = generateIconRegistry([ iconPack! ]);
expect(registry.sources).toHaveLength(0);
});
});

View File

@ -43,13 +43,18 @@ export function generateIconRegistry(iconPacks: ProcessResult[]): IconRegistry {
const sources: IconRegistry["sources"] = [];
for (const { manifest } of iconPacks) {
const icons: IconRegistry["sources"][number]["icons"] = Object.entries(manifest.icons)
.map(( [id, { terms }] ) => {
if (!id || !terms) return null;
return { id, terms };
})
.filter(Boolean) as IconRegistry["sources"][number]["icons"];
if (!icons.length) continue;
sources.push({
prefix: manifest.prefix,
name: manifest.name,
icons: Object.entries(manifest.icons).map(( [id, { terms }] ) => ({
id,
terms
}))
icons
});
}