From 4d044cbacf8d5bc6b8364012d33022cc8b234f3f Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Fri, 11 Jun 2021 16:09:52 +0800 Subject: [PATCH] feat: new allowOverrides options --- src/context.ts | 2 +- src/fs/glob.ts | 1 + src/helpers/libraryResolver.ts | 2 ++ src/types.ts | 7 +++++++ src/utils.ts | 1 - 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/context.ts b/src/context.ts index e91dc1da..cc37f1ed 100644 --- a/src/context.ts +++ b/src/context.ts @@ -129,7 +129,7 @@ export class Context { .from(this._componentPaths) .forEach((path) => { const name = pascalCase(getNameFromFilePath(path, this.options)) - if (this._componentNameMap[name]) { + if (this._componentNameMap[name] && !this.options.allowOverrides) { // eslint-disable-next-line no-console console.warn(`[vite-plugin-components] component "${name}"(${path}) has naming conflicts with other components, ignored.`) return diff --git a/src/fs/glob.ts b/src/fs/glob.ts index 094a9d82..688aee79 100644 --- a/src/fs/glob.ts +++ b/src/fs/glob.ts @@ -16,6 +16,7 @@ export function searchComponents(ctx: Context) { }) if (!files.length && !ctx.options.customComponentResolvers?.length) + // eslint-disable-next-line no-console console.warn('[vite-plugin-components] no components found') debug(`${files.length} components found.`) diff --git a/src/helpers/libraryResolver.ts b/src/helpers/libraryResolver.ts index a321a7cc..b2087af5 100644 --- a/src/helpers/libraryResolver.ts +++ b/src/helpers/libraryResolver.ts @@ -20,6 +20,7 @@ export function tryLoadVeturTags(name: string): string[] | undefined { return Object.keys(tags).map(i => camelCase(i)) } catch (e) { + // eslint-disable-next-line no-console console.error(e) } } @@ -32,6 +33,7 @@ export function LibraryResolver(options: UILibraryOptions): ComponentResolver { } = options if (!entries) { + // eslint-disable-next-line no-console console.warn(`[vite-plugin-components] Failed to load Vetur tags from library "${libraryName}"`) return () => {} } diff --git a/src/types.ts b/src/types.ts index b9800963..da2e3167 100644 --- a/src/types.ts +++ b/src/types.ts @@ -100,6 +100,13 @@ export interface Options { * @default false */ globalComponentsDeclaration?: boolean | string + + /** + * Do not emit warning on component overriding + * + * @default false + */ + allowOverrides?: boolean } export type ResolvedOptions = Omit< diff --git a/src/utils.ts b/src/utils.ts index 7ea15be1..6ce0858f 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -170,7 +170,6 @@ export function getNameFromFilePath(filePath: string, options: ResolvedOptions): filename = [...folders, filename].filter(Boolean).join('-') } - // console.log('!!!', filename) return filename }