From f532ae1ba2e99c9ff2c936bbe10e0f2d81f0c061 Mon Sep 17 00:00:00 2001 From: liuqi <70128222+l1uqi@users.noreply.github.com> Date: Mon, 17 Apr 2023 13:29:27 +0800 Subject: [PATCH 1/4] feat(Arco): add ArcoResolver exclude to filter components with the same name --- src/core/resolvers/arco.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/resolvers/arco.ts b/src/core/resolvers/arco.ts index b91a2590..cfcb9c80 100644 --- a/src/core/resolvers/arco.ts +++ b/src/core/resolvers/arco.ts @@ -167,6 +167,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[] /** * import style css or less with components * @@ -216,7 +222,7 @@ export function ArcoResolver( } } } - if (name.match(/^A[A-Z]/)) { + if (name.match(/^A[A-Z]/) && !options?.exclude?.includes(name)) { const importStyle = options.importStyle ?? 'css' const importName = name.slice(1) From 6f4981d02f448be41e8620aed9053aa96186b434 Mon Sep 17 00:00:00 2001 From: liuqi <70128222+l1uqi@users.noreply.github.com> Date: Mon, 17 Apr 2023 18:13:40 +0800 Subject: [PATCH 2/4] feat(ArcoResolver): add exclude option --- src/core/resolvers/arco.ts | 6 +++--- src/core/utils.ts | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/core/resolvers/arco.ts b/src/core/resolvers/arco.ts index cfcb9c80..196bd038 100644 --- a/src/core/resolvers/arco.ts +++ b/src/core/resolvers/arco.ts @@ -1,6 +1,6 @@ import Debug from 'debug' import type { ComponentInfo, ComponentResolver } from '../../types' -import { kebabCase, pascalCase } from '../utils' +import { kebabCase, pascalCase, isExclude } from '../utils' const debug = Debug('unplugin-vue-components:resolvers:arco') const matchComponents = [ @@ -172,7 +172,7 @@ export interface ArcoResolverOptions { * * @default [] */ - exclude?: string[] + exclude?: string | RegExp | (string | RegExp)[] /** * import style css or less with components * @@ -222,7 +222,7 @@ export function ArcoResolver( } } } - if (name.match(/^A[A-Z]/) && !options?.exclude?.includes(name)) { + if (name.match(/^A[A-Z]/) && options.exclude && !isExclude(name, options.exclude)) { const importStyle = options.importStyle ?? 'css' const importName = name.slice(1) diff --git a/src/core/utils.ts b/src/core/utils.ts index 87f69866..e1e88db2 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -225,3 +225,20 @@ export function resolveImportPath(importName: string): string | undefined { preserveSymlinks: false, }) } + + +export function isExclude(name: string, exclude: string | RegExp | (string | RegExp)[] | undefined): boolean { + 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 +} From b497f1964fe2f1f389723af25f8f1b873796f3d4 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 30 May 2023 11:38:34 +0200 Subject: [PATCH 3/4] chore: update --- src/core/resolvers/_utils.ts | 20 ++++++++++++++++++++ src/core/resolvers/arco.ts | 5 +++-- src/core/utils.ts | 17 ----------------- 3 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 src/core/resolvers/_utils.ts diff --git a/src/core/resolvers/_utils.ts b/src/core/resolvers/_utils.ts new file mode 100644 index 00000000..a864870a --- /dev/null +++ b/src/core/resolvers/_utils.ts @@ -0,0 +1,20 @@ + +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 +} diff --git a/src/core/resolvers/arco.ts b/src/core/resolvers/arco.ts index 196bd038..0bee4c2e 100644 --- a/src/core/resolvers/arco.ts +++ b/src/core/resolvers/arco.ts @@ -1,6 +1,7 @@ import Debug from 'debug' import type { ComponentInfo, ComponentResolver } from '../../types' -import { kebabCase, pascalCase, isExclude } from '../utils' +import { kebabCase, pascalCase } from '../utils' +import { isExclude } from './_utils' const debug = Debug('unplugin-vue-components:resolvers:arco') const matchComponents = [ @@ -222,7 +223,7 @@ export function ArcoResolver( } } } - if (name.match(/^A[A-Z]/) && options.exclude && !isExclude(name, options.exclude)) { + if (name.match(/^A[A-Z]/) && !isExclude(name, options.exclude)) { const importStyle = options.importStyle ?? 'css' const importName = name.slice(1) diff --git a/src/core/utils.ts b/src/core/utils.ts index e1e88db2..87f69866 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -225,20 +225,3 @@ export function resolveImportPath(importName: string): string | undefined { preserveSymlinks: false, }) } - - -export function isExclude(name: string, exclude: string | RegExp | (string | RegExp)[] | undefined): boolean { - 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 -} From 1630b89af3babdec9eb5dd16cc1c8b8bcc610f69 Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Tue, 30 May 2023 11:40:59 +0200 Subject: [PATCH 4/4] chore: update --- src/core/resolvers/_utils.ts | 6 ++---- src/core/utils.ts | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/core/resolvers/_utils.ts b/src/core/resolvers/_utils.ts index a864870a..3c907ac3 100644 --- a/src/core/resolvers/_utils.ts +++ b/src/core/resolvers/_utils.ts @@ -1,9 +1,7 @@ - export function isExclude(name: string, exclude?: string | RegExp | (string | RegExp)[] | undefined): boolean { - if (!exclude) { + if (!exclude) return false - } - + if (typeof exclude === 'string') return name === exclude diff --git a/src/core/utils.ts b/src/core/utils.ts index 22ac7adf..5e5ae49f 100644 --- a/src/core/utils.ts +++ b/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 {