Skip to content

Commit

Permalink
feat: new allowOverrides options
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jun 11, 2021
1 parent d1f8e0d commit 4d044cb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/fs/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`)
Expand Down
2 changes: 2 additions & 0 deletions src/helpers/libraryResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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 () => {}
}
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
1 change: 0 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export function getNameFromFilePath(filePath: string, options: ResolvedOptions):
filename = [...folders, filename].filter(Boolean).join('-')
}

// console.log('!!!', filename)
return filename
}

Expand Down

1 comment on commit 4d044cb

@guohuihot
Copy link

@guohuihot guohuihot commented on 4d044cb Aug 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

globs时,allowOverrides = true 不能用吗?

Please sign in to comment.