mirror of
https://github.com/iconify/iconify.git
synced 2024-11-17 01:55:09 +00:00
fix: combine files and iconSets options in Tailwind plugin
This commit is contained in:
parent
981feb9c53
commit
2b0ca8f685
@ -10,12 +10,9 @@ type IconifyJSONLoaderCallback = () => IconifyJSON;
|
|||||||
* Options for icon set loaders
|
* Options for icon set loaders
|
||||||
*/
|
*/
|
||||||
export interface IconifyPluginLoaderOptions {
|
export interface IconifyPluginLoaderOptions {
|
||||||
// Location of icon set files. Key is icon set prefix
|
|
||||||
files?: Record<string, string>;
|
|
||||||
|
|
||||||
// Custom icon sets
|
// Custom icon sets
|
||||||
// Value can be loaded icon set or callback that loads icon set
|
// Value can be loaded icon set or callback that loads icon set
|
||||||
iconSets?: Record<string, IconifyJSON | IconifyJSONLoaderCallback>;
|
iconSets?: Record<string, IconifyJSON | string | IconifyJSONLoaderCallback>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,15 +22,7 @@ interface LocatedIconSet {
|
|||||||
main: string;
|
main: string;
|
||||||
info?: string;
|
info?: string;
|
||||||
}
|
}
|
||||||
export function locateIconSet(
|
export function locateIconSet(prefix: string): LocatedIconSet | undefined {
|
||||||
prefix: string,
|
|
||||||
options: IconifyPluginLoaderOptions
|
|
||||||
): LocatedIconSet | undefined {
|
|
||||||
if (options.files?.[prefix]) {
|
|
||||||
return {
|
|
||||||
main: options.files?.[prefix],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
const main = require.resolve(`@iconify-json/${prefix}/icons.json`);
|
const main = require.resolve(`@iconify-json/${prefix}/icons.json`);
|
||||||
const info = require.resolve(`@iconify-json/${prefix}/info.json`);
|
const info = require.resolve(`@iconify-json/${prefix}/info.json`);
|
||||||
@ -67,19 +56,35 @@ export function loadIconSet(
|
|||||||
prefix: string,
|
prefix: string,
|
||||||
options: IconifyPluginLoaderOptions
|
options: IconifyPluginLoaderOptions
|
||||||
): IconifyJSON | undefined {
|
): IconifyJSON | undefined {
|
||||||
|
let filename: LocatedIconSet;
|
||||||
|
|
||||||
// Check for custom icon set
|
// Check for custom icon set
|
||||||
const customIconSet = options.iconSets?.[prefix];
|
const customIconSet = options.iconSets?.[prefix];
|
||||||
if (customIconSet) {
|
if (customIconSet) {
|
||||||
if (typeof customIconSet === 'function') {
|
switch (typeof customIconSet) {
|
||||||
// Callback. Store result in options to avoid loading it again
|
case 'function': {
|
||||||
const result = customIconSet();
|
// Callback. Store result in options to avoid loading it again
|
||||||
options.iconSets[prefix] = result;
|
const result = customIconSet();
|
||||||
return result;
|
options.iconSets[prefix] = result;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
case 'string': {
|
||||||
|
// Filename to load it from
|
||||||
|
filename = {
|
||||||
|
main: customIconSet,
|
||||||
|
};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return customIconSet;
|
||||||
}
|
}
|
||||||
return customIconSet;
|
} else {
|
||||||
|
// Find icon set
|
||||||
|
filename = locateIconSet(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
const filename = options.files?.[prefix] || locateIconSet(prefix, options);
|
|
||||||
if (!filename) {
|
if (!filename) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user