Skip to content

Commit

Permalink
fix dev flag
Browse files Browse the repository at this point in the history
  • Loading branch information
stramel committed Nov 25, 2024
1 parent d35385c commit 944b9b8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function createIntegration(): AstroIntegration {
return {
name: "astro-icon",
hooks: {
"astro:config:setup"({ updateConfig, config, logger }) {
"astro:config:setup"({ updateConfig, command, config, logger }) {
updateConfig({
experimental: {
svg: config.experimental?.svg ?? { mode: "inline" },
Expand All @@ -16,6 +16,7 @@ export default function createIntegration(): AstroIntegration {
cacheDir: config.cacheDir,
logger,
experimental: config.experimental,
__DEV__: command === "dev",
}),
],
},
Expand Down
14 changes: 9 additions & 5 deletions packages/core/src/utils/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function getIconifyUrl(collection: string) {

async function fetchCollection(
collection: string,
{ cache }: { cache: FileCache }
{ cache, __DEV__ }: { cache: FileCache; __DEV__: boolean }
): Promise<IconCollection> {
let collectionData = await cache.read<IconCollection>(collection);
if (collectionData) {
Expand All @@ -45,7 +45,7 @@ async function fetchCollection(
const err = new AstroIconError(
`Unable to locate the icon collection "${collection}"`
);
if (import.meta.env.DEV) {
if (__DEV__) {
err.hint = `The "${collection}" icon collection does not exist.\n\nIs this a typo?`;
}
throw err;
Expand All @@ -58,17 +58,21 @@ async function fetchCollection(
export async function getIconData(
collection: string,
name: string,
{ cache, logger }: { cache: FileCache; logger: AstroIntegrationLogger }
{
cache,
logger,
__DEV__,
}: { cache: FileCache; logger: AstroIntegrationLogger; __DEV__: boolean }
): Promise<IconData | undefined> {
const collectionData = await fetchCollection(collection, { cache });
const collectionData = await fetchCollection(collection, { cache, __DEV__ });

const { icons, aliases } = collectionData;
const icon = icons[name] ?? aliases[name];
if (icon === undefined) {
const err = new AstroIconError(
`Unable to locate the icon "${collection}:${name}"`
);
if (import.meta.env.DEV) {
if (__DEV__) {
err.hint = `The "${collection}" icon collection does not include an icon named "${name}".\n\nIs this a typo?`;
}
throw err;
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/vite-plugin-astro-icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { AstroIconError } from "./utils/error.js";

interface PluginOptions extends Pick<AstroConfig, "cacheDir" | "experimental"> {
logger: AstroIntegrationLogger;
__DEV__: boolean;
}

const DEFAULT_ICON_SIZE = 24;
Expand All @@ -17,6 +18,7 @@ export function createPlugin({
cacheDir,
logger,
experimental,
__DEV__,
}: PluginOptions): Plugin {
const cache = new FileCache(new URL("astro-icon/icons/", cacheDir), logger);

Expand All @@ -33,7 +35,11 @@ export function createPlugin({
const [collection, icon] = name.split("/");

try {
const data = await getIconData(collection, icon, { cache, logger });
const data = await getIconData(collection, icon, {
cache,
logger,
__DEV__,
});
if (!data) return;

const {
Expand Down

0 comments on commit 944b9b8

Please sign in to comment.