From 89944c4835db705e5e998d8dc328aeba90349b94 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 1 Apr 2021 12:27:47 +0200 Subject: [PATCH 1/2] test: add fixture --- test/fixture/components/my/form/MyFancyButton.vue | 3 +++ test/unit/scanner.test.ts | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/fixture/components/my/form/MyFancyButton.vue 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..92dbfff 100644 --- a/test/unit/scanner.test.ts +++ b/test/unit/scanner.test.ts @@ -21,7 +21,8 @@ test('scanner', async () => { 'FormLayout', 'Header', 'DeepNestedMyComponent', - 'UiNotificationWrapper' + 'UiNotificationWrapper', + 'MyFancyButton' ] expect(components.map(c => c.pascalName).sort()).toEqual(expectedComponents.sort()) From 3a8296ac245f28320dccadb86eccecacbbca55e8 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Thu, 1 Apr 2021 12:38:20 +0200 Subject: [PATCH 2/2] update scan for desired behavior --- src/scan.ts | 16 +++++++++------- test/unit/scanner.test.ts | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) 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/unit/scanner.test.ts b/test/unit/scanner.test.ts index 92dbfff..efa4f2a 100644 --- a/test/unit/scanner.test.ts +++ b/test/unit/scanner.test.ts @@ -18,11 +18,11 @@ test('scanner', async () => { 'FormInputText', 'FormInputTextArea', 'FormInputRadio', - 'FormLayout', + 'FormLayoutsLayout', 'Header', 'DeepNestedMyComponent', 'UiNotificationWrapper', - 'MyFancyButton' + 'MyFormFancyButton' ] expect(components.map(c => c.pascalName).sort()).toEqual(expectedComponents.sort())