From 500ef6793e57b11b06e456f114b7cb3333e2bc48 Mon Sep 17 00:00:00 2001 From: _Kerman Date: Wed, 17 Jul 2024 21:29:53 +0800 Subject: [PATCH 1/2] feat(utils): allow provide multiple `cwd` to node loader --- packages/utils/src/loader/node-loader.ts | 31 +++++++++++++++--------- packages/utils/src/loader/types.ts | 5 +++- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/utils/src/loader/node-loader.ts b/packages/utils/src/loader/node-loader.ts index 27eab2b..cac2924 100644 --- a/packages/utils/src/loader/node-loader.ts +++ b/packages/utils/src/loader/node-loader.ts @@ -15,19 +15,28 @@ export const loadNodeIcon: UniversalIconLoader = async ( return result; } - const iconSet = await loadCollectionFromFS( - collection, - options?.autoInstall, - undefined, - options?.cwd - ); - if (iconSet) { - result = await searchForIcon( - iconSet, + const cwds = options?.cwd + ? Array.isArray(options.cwd) + ? options.cwd + : [options.cwd] + : []; + + for (const cwd of cwds) { + const iconSet = await loadCollectionFromFS( collection, - getPossibleIconNames(icon), - options + options?.autoInstall, + undefined, + cwd ); + if (iconSet) { + result = await searchForIcon( + iconSet, + collection, + getPossibleIconNames(icon), + options + ); + if (result) break; + } } if (!result && options?.warn) { diff --git a/packages/utils/src/loader/types.ts b/packages/utils/src/loader/types.ts index a5a5d50..42b8bae 100644 --- a/packages/utils/src/loader/types.ts +++ b/packages/utils/src/loader/types.ts @@ -183,8 +183,11 @@ export type IconifyLoaderOptions = { /** * Current working directory, used to resolve the @iconify-json package. * + * Can be a string or an array of strings, the first existing path will be used. + * * Only used on `node` environment. + * * @default process.cwd() */ - cwd?: string; + cwd?: string | string[]; }; From aba9770517d99b2bd705e2d5e6226904bd0fcfee Mon Sep 17 00:00:00 2001 From: _Kerman Date: Thu, 18 Jul 2024 10:28:21 +0800 Subject: [PATCH 2/2] fix: when `options?.cwd` is undefined --- packages/utils/src/loader/node-loader.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/utils/src/loader/node-loader.ts b/packages/utils/src/loader/node-loader.ts index cac2924..2109c9f 100644 --- a/packages/utils/src/loader/node-loader.ts +++ b/packages/utils/src/loader/node-loader.ts @@ -15,11 +15,7 @@ export const loadNodeIcon: UniversalIconLoader = async ( return result; } - const cwds = options?.cwd - ? Array.isArray(options.cwd) - ? options.cwd - : [options.cwd] - : []; + const cwds = Array.isArray(options?.cwd) ? options.cwd : [options?.cwd]; for (const cwd of cwds) { const iconSet = await loadCollectionFromFS(