Skip to content

Commit

Permalink
feat: support collectionsNodeResolvePath
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 4, 2024
1 parent 2510cc5 commit 0bd2c97
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/core/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ export async function generateComponent({ collection, icon, query }: ResolvedIco
iconCustomizer: providedIconCustomizer,
transform,
autoInstall = false,
collectionsNodeResolvePath,
} = options

const iconifyLoaderOptions: IconifyLoaderOptions = {
addXmlNs: false,
scale,
customCollections,
autoInstall,
defaultClass,
defaultStyle,
cwd: collectionsNodeResolvePath,
// there is no need to warn since we throw an error below
warn: undefined,
customizations: {
Expand Down
5 changes: 4 additions & 1 deletion src/core/options.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -15,6 +16,7 @@ export async function resolveOptions(options: Options): Promise<ResolvedOptions>
iconCustomizer = () => {},
transform,
autoInstall = false,
collectionsNodeResolvePath = process.cwd(),
} = options

const webComponents = Object.assign({
Expand All @@ -35,6 +37,7 @@ export async function resolveOptions(options: Options): Promise<ResolvedOptions>
webComponents,
transform,
autoInstall,
collectionsNodeResolvePath,
}
}

Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export interface Options {
*/
iconCustomizer?: IconCustomizer

/**
* Current working directory for resolving collections from node_modules
*/
collectionsNodeResolvePath?: string

/**
* Transform raw `svg`.
*
Expand Down

0 comments on commit 0bd2c97

Please sign in to comment.