Skip to content

Commit

Permalink
fix: include aliases in icon type definitions and hash calculation (#250
Browse files Browse the repository at this point in the history
)

* fix: include aliases in icon type definitions and hash calculation

* add changeset

* Update .changeset/chilled-fans-beg.md

---------

Co-authored-by: Nate Moore <[email protected]>
  • Loading branch information
harukats and natemoo-re authored Nov 23, 2024
1 parent 1e6d429 commit 41218fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilled-fans-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-icon": patch
---

Fixes type definitions and hash calculation for aliased icon names
25 changes: 16 additions & 9 deletions packages/core/src/vite-plugin-astro-icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,16 @@ declare module 'virtual:astro-icon' {
collections.length > 0
? collections
.map((collection) =>
Object.keys(collection.icons).map(
(icon) =>
`\n\t\t| "${
collection.prefix === defaultPack
? ""
: `${collection.prefix}:`
}${icon}"`,
),
Object.keys(collection.icons)
.concat(Object.keys(collection.aliases ?? {}))
.map(
(icon) =>
`\n\t\t| "${
collection.prefix === defaultPack
? ""
: `${collection.prefix}:`
}${icon}"`,
),
)
.flat(1)
.join("")
Expand All @@ -127,7 +129,12 @@ function collectionsHash(collections: IconCollection[]): string {
const hash = createHash("sha256");
for (const collection of collections) {
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(","),
);
}
return hash.digest("hex");
}
Expand Down

0 comments on commit 41218fa

Please sign in to comment.