astro-icon
Advanced tools
Comparing version 1.1.2 to 1.1.4
@@ -19,9 +19,10 @@ import { mkdir, readFile, writeFile } from "node:fs/promises"; | ||
if (id === resolvedVirtualModuleId) { | ||
if (!collections) { | ||
collections = await loadIconifyCollections({ root, include }); | ||
} | ||
try { | ||
// Attempt to create local collection | ||
if (!collections) { | ||
collections = await loadIconifyCollections({ root, include }); | ||
} | ||
const local = await loadLocalCollection(iconDir, svgoOptions); | ||
collections["local"] = local; | ||
logCollections(collections, { ...ctx, iconDir }); | ||
await generateIconTypeDefinitions(Object.values(collections), root); | ||
} | ||
@@ -31,7 +32,25 @@ catch (ex) { | ||
} | ||
logCollections(collections, { ...ctx, iconDir }); | ||
await generateIconTypeDefinitions(Object.values(collections), root); | ||
return `export default ${JSON.stringify(collections)};\nexport const config = ${JSON.stringify({ include })}`; | ||
} | ||
}, | ||
configureServer({ watcher, moduleGraph }) { | ||
watcher.add(`${iconDir}/**/*.svg`); | ||
watcher.on("change", async () => { | ||
console.log(`Local icons changed, reloading`); | ||
try { | ||
if (!collections) { | ||
collections = await loadIconifyCollections({ root, include }); | ||
} | ||
const local = await loadLocalCollection(iconDir, svgoOptions); | ||
collections["local"] = local; | ||
logCollections(collections, { ...ctx, iconDir }); | ||
await generateIconTypeDefinitions(Object.values(collections), root); | ||
moduleGraph.invalidateAll(); | ||
} | ||
catch (ex) { | ||
// Failed to load the local collection | ||
} | ||
return `export default ${JSON.stringify(collections)};\nexport const config = ${JSON.stringify({ include })}`; | ||
}); | ||
}, | ||
}; | ||
@@ -64,3 +83,5 @@ } | ||
? collections | ||
.map((collection) => Object.keys(collection.icons).map((icon) => `\n\t\t| "${collection.prefix === defaultPack | ||
.map((collection) => Object.keys(collection.icons) | ||
.concat(Object.keys(collection.aliases ?? {})) | ||
.map((icon) => `\n\t\t| "${collection.prefix === defaultPack | ||
? "" | ||
@@ -77,3 +98,6 @@ : `${collection.prefix}:`}${icon}"`)) | ||
hash.update(collection.prefix); | ||
hash.update(Object.keys(collection.icons).sort().join(",")); | ||
hash.update(Object.keys(collection.icons) | ||
.concat(Object.keys(collection.aliases ?? {})) | ||
.sort() | ||
.join(",")); | ||
} | ||
@@ -80,0 +104,0 @@ return hash.digest("hex"); |
{ | ||
"name": "astro-icon", | ||
"version": "1.1.2", | ||
"version": "1.1.4", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "types": "./dist/index.d.ts", |
28072
331
38096
4