Skip to content

Commit 6ba6d22

Browse files
committed
fix: use parent dir name for index.[ext] components without pathPrefix (#178)
1 parent bc01f21 commit 6ba6d22

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

src/scan.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ export async function scanComponents (dirs: ScanDir[], srcDir: string): Promise<
3535
prefix ? splitByCase(prefix) : [],
3636
(pathPrefix !== false) ? splitByCase(relative(path, dirname(filePath))) : []
3737
)
38-
const fileName = basename(filePath, extname(filePath))
39-
const fileNameParts = fileName.toLowerCase() === 'index' ? [] : splitByCase(fileName)
38+
let fileName = basename(filePath, extname(filePath))
39+
if (fileName.toLowerCase() === 'index') {
40+
fileName = pathPrefix === false ? basename(dirname(filePath)) : '' /* inherits from path */
41+
}
42+
const fileNameParts = splitByCase(fileName)
4043

4144
const componentNameParts: string[] = []
4245

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div>
3+
No prefix Foo
4+
</div>
5+
</template>

test/fixture/nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const config: NuxtConfig = {
1111
components: [
1212
'~/components',
1313
{ path: '~/components/global', global: true },
14+
{ path: '~/components/no-prefix', pathPrefix: false },
1415
{ path: '~/components/multifile', extensions: ['vue'] },
1516
'~/non-existent',
1617
{ path: '@/components/base', prefix: 'Base' },

test/unit/scanner.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ test('scanner', async () => {
2121
'FormLayout',
2222
'Header',
2323
'DeepNestedMyComponent',
24-
'UiNotificationWrapper'
24+
'UiNotificationWrapper',
25+
'NoPrefix1'
2526
]
2627

2728
expect(components.map(c => c.pascalName).sort()).toEqual(expectedComponents.sort())

test/unit/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ export function scanFixtureComponents () {
2424
prefix: 'base',
2525
ignore: ignorePatterns
2626
},
27+
{
28+
path: path.resolve(srcDir, 'components/no-prefix'),
29+
pattern: '**/*.{vue,js,ts}',
30+
ignore: ignorePatterns,
31+
pathPrefix: false
32+
},
2733
{
2834
path: path.resolve(srcDir, 'components/global'),
2935
pattern: '**/*.{vue,js,ts}',

0 commit comments

Comments
 (0)