From a5c91e3029a1da19be95d9f204eeb471f0ebb7e4 Mon Sep 17 00:00:00 2001 From: Michael Stramel Date: Thu, 29 Jun 2023 23:46:35 -0500 Subject: [PATCH] move warning about local directory to on use (#123) Co-authored-by: Michael Stramel --- .changeset/fuzzy-beers-count.md | 5 +++++ packages/core/components/Icon.astro | 10 ++++++++++ packages/core/src/vite-plugin-astro-icon.ts | 4 +--- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 .changeset/fuzzy-beers-count.md diff --git a/.changeset/fuzzy-beers-count.md b/.changeset/fuzzy-beers-count.md new file mode 100644 index 0000000..dca9c11 --- /dev/null +++ b/.changeset/fuzzy-beers-count.md @@ -0,0 +1,5 @@ +--- +"astro-icon": patch +--- + +move warning about local directory to on use diff --git a/packages/core/components/Icon.astro b/packages/core/components/Icon.astro index e464378..2e84082 100644 --- a/packages/core/components/Icon.astro +++ b/packages/core/components/Icon.astro @@ -42,6 +42,16 @@ if (!iconName) { iconName = setName; setName = "local"; + // Check if the local icon set exists + if (!icons[setName]) { + const err = new Error('Unable to load the "local" icon set!'); + if (import.meta.env.DEV) { + err.hint = + 'It looks like the "local" set was not loaded.\n\nDid you forget to create the icon directory or to update your config?'; + } + throw err; + } + // Check if the icon is missing from the local collection if (!(iconName in icons[setName].icons)) { const err = new Error(`Unable to locate "${name}" icon!`); diff --git a/packages/core/src/vite-plugin-astro-icon.ts b/packages/core/src/vite-plugin-astro-icon.ts index 8edd98e..a449955 100644 --- a/packages/core/src/vite-plugin-astro-icon.ts +++ b/packages/core/src/vite-plugin-astro-icon.ts @@ -33,9 +33,7 @@ export async function createPlugin( const local = await loadLocalCollection(iconDir); collections["local"] = local; } catch (ex) { - console.warn( - "Unable to load local collection. Ensure you have your `iconDir` configured properly." - ); + // Failed to load the local collection } await generateIconTypeDefinitions(Object.values(collections), root);