Skip to content

Commit

Permalink
feat(arco): add ArcoResolver exclude to filter components with the sa… (
Browse files Browse the repository at this point in the history
#628)

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
l1uqi and antfu committed May 30, 2023
1 parent 56f98aa commit 4729f3a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/core/resolvers/_utils.ts
@@ -0,0 +1,18 @@
export function isExclude(name: string, exclude?: string | RegExp | (string | RegExp)[] | undefined): boolean {
if (!exclude)
return false

if (typeof exclude === 'string')
return name === exclude

if (exclude instanceof RegExp)
return !!name.match(exclude)

if (Array.isArray(exclude)) {
for (const item of exclude) {
if (name === item || name.match(item))
return true
}
}
return false
}
9 changes: 8 additions & 1 deletion src/core/resolvers/arco.ts
@@ -1,6 +1,7 @@
import Debug from 'debug'
import type { ComponentInfo, ComponentResolver } from '../../types'
import { kebabCase, pascalCase } from '../utils'
import { isExclude } from './_utils'

const debug = Debug('unplugin-vue-components:resolvers:arco')

Expand Down Expand Up @@ -168,6 +169,12 @@ export type AllowResolveIconOption = true | { enable: true; iconPrefix?: string
export type ResolveIconsOption = DisallowResolveIconOption | AllowResolveIconOption

export interface ArcoResolverOptions {
/**
* exclude components that do not require automatic import
*
* @default []
*/
exclude?: string | RegExp | (string | RegExp)[]
/**
* import style css or less with components
*
Expand Down Expand Up @@ -217,7 +224,7 @@ export function ArcoResolver(
}
}
}
if (name.match(/^A[A-Z]/)) {
if (name.match(/^A[A-Z]/) && !isExclude(name, options.exclude)) {
const importStyle = options.importStyle ?? 'css'

const importName = name.slice(1)
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils.ts
@@ -1,5 +1,5 @@
import { parse } from 'node:path'
import {minimatch} from 'minimatch'
import { minimatch } from 'minimatch'
import resolve from 'resolve'
import { slash, toArray } from '@antfu/utils'
import {
Expand Down

0 comments on commit 4729f3a

Please sign in to comment.