From 5ff09d6936f8fdc5386d34dc52fa84bcb3d9747e Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Sun, 28 Jul 2024 18:45:11 +0300 Subject: [PATCH] chore(utils): use autoInstall only for last cwd in node loader --- packages/utils/src/loader/node-loader.ts | 14 +++++++------- packages/utils/src/loader/types.ts | 2 ++ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/utils/src/loader/node-loader.ts b/packages/utils/src/loader/node-loader.ts index 2109c9f..a6f23af 100644 --- a/packages/utils/src/loader/node-loader.ts +++ b/packages/utils/src/loader/node-loader.ts @@ -17,12 +17,12 @@ export const loadNodeIcon: UniversalIconLoader = async ( const cwds = Array.isArray(options?.cwd) ? options.cwd : [options?.cwd]; - for (const cwd of cwds) { + for (let i = 0; i < cwds.length; i++) { const iconSet = await loadCollectionFromFS( collection, - options?.autoInstall, + i === cwds.length - 1 ? options?.autoInstall : false, undefined, - cwd + cwds[i] ); if (iconSet) { result = await searchForIcon( @@ -31,13 +31,13 @@ export const loadNodeIcon: UniversalIconLoader = async ( getPossibleIconNames(icon), options ); - if (result) break; + if (result) { + return result; + } } } - if (!result && options?.warn) { + if (options?.warn) { warnOnce(`failed to load ${options.warn} icon`); } - - return result; }; diff --git a/packages/utils/src/loader/types.ts b/packages/utils/src/loader/types.ts index 42b8bae..37e45ec 100644 --- a/packages/utils/src/loader/types.ts +++ b/packages/utils/src/loader/types.ts @@ -187,6 +187,8 @@ export type IconifyLoaderOptions = { * * Only used on `node` environment. * + * If value is an array and `autoInstall` is enabled, `autoInstall` will be used only for last entry. + * * @default process.cwd() */ cwd?: string | string[];