Skip to content

Commit 3de27ff

Browse files
committed
fix: use hyphenate instead of kebabCase (fixes #165)
1 parent f396cfa commit 3de27ff

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

src/scan.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
import { basename, extname, join, dirname, relative } from 'upath'
22
import globby from 'globby'
3-
import { kebabCase, pascalCase, splitByCase } from 'scule'
3+
import { pascalCase, splitByCase } from 'scule'
44
import type { ScanDir, Component } from './types'
55

66
export function sortDirsByPathLength ({ path: pathA }: ScanDir, { path: pathB }: ScanDir): number {
77
return pathB.split(/[\\/]/).filter(Boolean).length - pathA.split(/[\\/]/).filter(Boolean).length
88
}
99

10+
// vue@2 src/shared/util.js
11+
function hyphenate (str: string):string {
12+
return str.replace(/\B([A-Z])/g, '-$1').toLowerCase()
13+
}
14+
1015
export async function scanComponents (dirs: ScanDir[], srcDir: string): Promise<Component[]> {
1116
const components: Component[] = []
1217
const filePaths = new Set<string>()
@@ -54,7 +59,7 @@ export async function scanComponents (dirs: ScanDir[], srcDir: string): Promise<
5459
resolvedNames.set(componentName, filePath)
5560

5661
const pascalName = pascalCase(componentName)
57-
const kebabName = kebabCase(componentName)
62+
const kebabName = hyphenate(componentName)
5863
const shortPath = relative(srcDir, filePath)
5964
const chunkName = 'components/' + kebabName
6065

File renamed without changes.

test/fixture/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
<IconHome />
88
<MAwesome />
99
<Functional />
10-
<PAScal />
10+
<NComponent />
1111
</div>
1212
</template>

test/unit/scanner.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ test('scanner', async () => {
1111
'Bar',
1212
'Big',
1313
'Mouse',
14-
'PAScal',
14+
'NComponent',
1515
'Foo',
1616
'Functional',
1717
'FunctionalChild',

test/unit/tagExtractor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { extractTags } from '../../src/tagExtractor'
44
test('with template', async () => {
55
const tags = await extractTags(path.resolve('test/fixture/pages/index.vue'))
66

7-
expect(tags).toEqual(['Header', 'Foo', 'LazyBar', 'BaseButton', 'IconHome', 'MAwesome', 'Functional', 'PAScal', 'div'])
7+
expect(tags).toEqual(['Header', 'Foo', 'LazyBar', 'BaseButton', 'IconHome', 'MAwesome', 'Functional', 'NComponent', 'div'])
88
})
99

1010
test('without template', async () => {

0 commit comments

Comments
 (0)