File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,18 @@ import { Context } from '../context'
6
6
7
7
const debug = Debug ( 'vite-plugin-components:glob' )
8
8
9
+ function getNameFromFilePath ( filePath : string ) : string {
10
+ const parsedFilePath = path . parse ( filePath )
11
+ if ( parsedFilePath . name === 'index' ) {
12
+ const filePathSegments = filePath . split ( path . sep )
13
+ const parentDirName = filePathSegments [ filePathSegments . length - 2 ]
14
+ if ( parentDirName ) {
15
+ return parentDirName
16
+ }
17
+ }
18
+ return parsedFilePath . name
19
+ }
20
+
9
21
function toArray < T > ( arr : T | T [ ] ) : T [ ] {
10
22
if ( Array . isArray ( arr ) )
11
23
return arr
@@ -52,7 +64,7 @@ export async function searchComponents(ctx: Context, force = false) {
52
64
53
65
const nameSets = new Set < string > ( )
54
66
const components = files
55
- . map ( ( f ) : ComponentsInfo => [ path . parse ( f ) . name , `/${ f } ` ] )
67
+ . map ( ( f ) : ComponentsInfo => [ getNameFromFilePath ( f ) , `/${ f } ` ] )
56
68
. filter ( ( [ name , path ] ) => {
57
69
if ( nameSets . has ( name ) ) {
58
70
console . warn ( `[vite-plugin-components] component "${ name } "(${ path } ) has naming conflicts with other components, ignored.` )
You can’t perform that action at this time.
0 commit comments