From 3b29d893bbb385c8e6e8fa51b421fefa17b050ac Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Tue, 5 Apr 2022 17:34:15 -0500 Subject: [PATCH] fix: do not throw error when no sprites are found --- .changeset/gorgeous-pots-drive.md | 5 +++++ packages/core/lib/context.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .changeset/gorgeous-pots-drive.md diff --git a/.changeset/gorgeous-pots-drive.md b/.changeset/gorgeous-pots-drive.md new file mode 100644 index 00000000..831b1773 --- /dev/null +++ b/.changeset/gorgeous-pots-drive.md @@ -0,0 +1,5 @@ +--- +"astro-icon": patch +--- + +Improve warning when no sprites are found rather than throwing an error diff --git a/packages/core/lib/context.ts b/packages/core/lib/context.ts index 299d79ea..88f7eacf 100644 --- a/packages/core/lib/context.ts +++ b/packages/core/lib/context.ts @@ -10,11 +10,15 @@ export function trackSprite(result: any, name: string) { } } +const warned = new Set(); export async function getUsedSprites(result: any) { if (typeof result[AstroIcon] !== "undefined") { return Array.from(result[AstroIcon]["sprites"]); } - throw new Error( - `[astro-icon] should be the very last child of the page's !\nIs it currently placed before any components?` - ); + const pathname = result._metadata.pathname; + if (!warned.has(pathname)) { + console.log(`[astro-icon] No sprites found while rendering "${pathname}"`); + warned.add(pathname); + } + return [] }