From 0bd2c977f271d97bf194c6a19df9ff8c44f9d0e1 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Sun, 4 Feb 2024 11:48:26 +0100 Subject: [PATCH] feat: support `collectionsNodeResolvePath` --- src/core/loader.ts | 3 +++ src/core/options.ts | 5 ++++- src/types.ts | 5 +++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/core/loader.ts b/src/core/loader.ts index 2acde023..5be3f1e8 100644 --- a/src/core/loader.ts +++ b/src/core/loader.ts @@ -63,7 +63,9 @@ export async function generateComponent({ collection, icon, query }: ResolvedIco iconCustomizer: providedIconCustomizer, transform, autoInstall = false, + collectionsNodeResolvePath, } = options + const iconifyLoaderOptions: IconifyLoaderOptions = { addXmlNs: false, scale, @@ -71,6 +73,7 @@ export async function generateComponent({ collection, icon, query }: ResolvedIco autoInstall, defaultClass, defaultStyle, + cwd: collectionsNodeResolvePath, // there is no need to warn since we throw an error below warn: undefined, customizations: { diff --git a/src/core/options.ts b/src/core/options.ts index 1d091300..5e8928f9 100644 --- a/src/core/options.ts +++ b/src/core/options.ts @@ -1,3 +1,4 @@ +import process from 'node:process' import { getPackageInfo, isPackageExists } from 'local-pkg' import createDebugger from 'debug' import type { Options, ResolvedOptions } from '../types' @@ -15,6 +16,7 @@ export async function resolveOptions(options: Options): Promise iconCustomizer = () => {}, transform, autoInstall = false, + collectionsNodeResolvePath = process.cwd(), } = options const webComponents = Object.assign({ @@ -35,6 +37,7 @@ export async function resolveOptions(options: Options): Promise webComponents, transform, autoInstall, + collectionsNodeResolvePath, } } @@ -53,7 +56,7 @@ async function getVueVersion() { const result = await getPackageInfo('vue') if (!result) return null - return result.version.startsWith('2.') ? 'vue2' : 'vue3' + return result.version?.startsWith('2.') ? 'vue2' : 'vue3' } catch { return null diff --git a/src/types.ts b/src/types.ts index bd1a8377..d4ff3767 100644 --- a/src/types.ts +++ b/src/types.ts @@ -38,6 +38,11 @@ export interface Options { */ iconCustomizer?: IconCustomizer + /** + * Current working directory for resolving collections from node_modules + */ + collectionsNodeResolvePath?: string + /** * Transform raw `svg`. *