@@ -8,7 +8,7 @@ import * as path from 'path';
88import getFs from '../../fs/getFs' ;
99import { FOLDER_CHARACTERS_REGEX_STRING } from '../../tags/calc-tags-for-module' ;
1010import { flattenModules } from './flatten-modules' ;
11- import { matchGlob } from '../../util/match-glob' ;
11+ import { GlobMatcher } from '../../util/match-glob' ;
1212
1313/**
1414 * The current criterion for finding modules is via
@@ -20,11 +20,15 @@ import { matchGlob } from '../../util/match-glob';
2020export function findModulePathsWithoutBarrel (
2121 moduleConfig : ModuleConfig ,
2222 rootDir : FsPath ,
23- barrelFileNames : string [ ]
23+ isBarrelMatch : GlobMatcher ,
2424) : Set < FsPath > {
2525 const paths = flattenModules ( moduleConfig , '' ) ;
2626 const modulePathsPatternTree = createModulePathPatternsTree ( paths ) ;
27- const modules = traverseAndMatch ( modulePathsPatternTree , rootDir , barrelFileNames ) ;
27+ const modules = traverseAndMatch (
28+ modulePathsPatternTree ,
29+ rootDir ,
30+ isBarrelMatch ,
31+ ) ;
2832 return new Set < FsPath > ( modules ) ;
2933}
3034
@@ -34,14 +38,14 @@ export function findModulePathsWithoutBarrel(
3438function traverseAndMatch (
3539 groupedPatterns : ModulePathPatternsTree ,
3640 basePath : FsPath ,
37- barrelFileNames : string [ ]
41+ isBarrelMatch : GlobMatcher ,
3842) : FsPath [ ] {
3943 const fs = getFs ( ) ;
4044 const matchedDirectories : FsPath [ ] = [ ] ;
4145
4246 // Check if the current directory should be matched
4347 if ( '' in groupedPatterns ) {
44- addAsModuleIfWithoutBarrel ( matchedDirectories , basePath , barrelFileNames ) ;
48+ addAsModuleIfWithoutBarrel ( matchedDirectories , basePath , isBarrelMatch ) ;
4549 }
4650
4751 const subDirectories = fs . readDirectory ( basePath , 'directory' ) ;
@@ -55,11 +59,23 @@ function traverseAndMatch(
5559
5660 if ( matchingPattern ) {
5761 if ( Object . keys ( groupedPatterns [ matchingPattern ] ) . length === 0 ) {
58- addAsModuleIfWithoutBarrel ( matchedDirectories , subDirectory , barrelFileNames ) ;
62+ addAsModuleIfWithoutBarrel (
63+ matchedDirectories ,
64+ subDirectory ,
65+ isBarrelMatch ,
66+ ) ;
5967 } else {
60- const newDirectories = traverseAndMatch ( groupedPatterns [ matchingPattern ] , subDirectory , barrelFileNames ) ;
68+ const newDirectories = traverseAndMatch (
69+ groupedPatterns [ matchingPattern ] ,
70+ subDirectory ,
71+ isBarrelMatch ,
72+ ) ;
6173 for ( const newDirectory of newDirectories ) {
62- addAsModuleIfWithoutBarrel ( matchedDirectories , newDirectory , barrelFileNames ) ;
74+ addAsModuleIfWithoutBarrel (
75+ matchedDirectories ,
76+ newDirectory ,
77+ isBarrelMatch ,
78+ ) ;
6379 }
6480 }
6581 }
@@ -91,22 +107,21 @@ function matchPattern(pattern: string, pathSegment: string): boolean {
91107function addAsModuleIfWithoutBarrel (
92108 modulePaths : FsPath [ ] ,
93109 directory : FsPath ,
94- barrelFileNames : string [ ] ,
110+ isBarrelMatch : GlobMatcher ,
95111) {
96- if ( hasBarrelFile ( directory , barrelFileNames ) ) {
112+ if ( hasBarrelFile ( directory , isBarrelMatch ) ) {
97113 return ;
98114 }
99115
100116 modulePaths . push ( directory ) ;
101117}
102118
103- function hasBarrelFile ( directory : FsPath , barrelFileNames : string [ ] ) : boolean {
119+ function hasBarrelFile ( directory : FsPath , isBarrelMatch : GlobMatcher ) : boolean {
104120 const fs = getFs ( ) ;
105121 const children = fs . readDirectory ( directory ) ;
106122 return children . some ( ( child ) => {
107123 if ( fs . isFile ( child ) ) {
108- const fileName = path . basename ( child ) ;
109- return barrelFileNames . some ( ( pattern ) => matchGlob ( pattern , fileName ) ) ;
124+ return isBarrelMatch ( path . basename ( child ) ) ;
110125 }
111126 return false ;
112127 } ) ;
0 commit comments