Skip to content

Commit

Permalink
fix: use globs option cannot resolve index.vue (#536)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
satrong and antfu committed Dec 1, 2022
1 parent 48c3374 commit f891820
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/core/utils.ts
Expand Up @@ -111,7 +111,7 @@ export function stringifyComponentImport({ as: name, from: path, name: importNam
}

export function getNameFromFilePath(filePath: string, options: ResolvedOptions): string {
const { resolvedDirs, directoryAsNamespace, globalNamespaces, collapseSamePrefixes } = options
const { resolvedDirs, directoryAsNamespace, globalNamespaces, collapseSamePrefixes, root } = options

const parsedFilePath = parse(slash(filePath))

Expand All @@ -130,6 +130,10 @@ export function getNameFromFilePath(filePath: string, options: ResolvedOptions):

// set parent directory as filename if it is index
if (filename === 'index' && !directoryAsNamespace) {
// when use `globs` option, `resolvedDirs` will always empty, and `folders` will also empty
if (isEmpty(folders))
folders = parsedFilePath.dir.slice(root.length + 1).split('/').filter(Boolean)

filename = `${folders.slice(-1)[0]}`
return filename
}
Expand Down

0 comments on commit f891820

Please sign in to comment.