diff --git a/src/scan.ts b/src/scan.ts index 3422b95..3d52d4c 100644 --- a/src/scan.ts +++ b/src/scan.ts @@ -12,6 +12,10 @@ function hyphenate (str: string):string { return str.replace(/\B([A-Z])/g, '-$1').toLowerCase() } +function compareCaseInsensitive (str1 = '', str2 = '') { + return str1.toLocaleLowerCase() === str2.toLocaleLowerCase() +} + export async function scanComponents (dirs: ScanDir[], srcDir: string): Promise { const components: Component[] = [] const filePaths = new Set() @@ -38,15 +42,13 @@ export async function scanComponents (dirs: ScanDir[], srcDir: string): Promise< const fileName = basename(filePath, extname(filePath)) const fileNameParts = fileName.toLowerCase() === 'index' ? [] : splitByCase(fileName) - const componentNameParts: string[] = [] - - while (prefixParts.length && - (prefixParts[0] || '').toLowerCase() !== (fileNameParts[0] || '').toLowerCase() - ) { - componentNameParts.push(prefixParts.shift()!) + for (const p of prefixParts) { + if (compareCaseInsensitive(p, fileNameParts[0])) { + fileNameParts.shift() + } } - const componentName = pascalCase(componentNameParts) + pascalCase(fileNameParts) + const componentName = pascalCase(prefixParts) + pascalCase(fileNameParts) if (resolvedNames.has(componentName)) { // eslint-disable-next-line no-console diff --git a/test/fixture/components/my/form/MyFancyButton.vue b/test/fixture/components/my/form/MyFancyButton.vue new file mode 100644 index 0000000..59adfaa --- /dev/null +++ b/test/fixture/components/my/form/MyFancyButton.vue @@ -0,0 +1,3 @@ + diff --git a/test/unit/scanner.test.ts b/test/unit/scanner.test.ts index 81aedaa..efa4f2a 100644 --- a/test/unit/scanner.test.ts +++ b/test/unit/scanner.test.ts @@ -18,10 +18,11 @@ test('scanner', async () => { 'FormInputText', 'FormInputTextArea', 'FormInputRadio', - 'FormLayout', + 'FormLayoutsLayout', 'Header', 'DeepNestedMyComponent', - 'UiNotificationWrapper' + 'UiNotificationWrapper', + 'MyFormFancyButton' ] expect(components.map(c => c.pascalName).sort()).toEqual(expectedComponents.sort())