@@ -20,8 +20,8 @@ export function generate(input: Pattern[], settings: Settings): Task[] {
2020 const staticPatterns = positivePatterns . filter ( ( pattern ) => utils . pattern . isStaticPattern ( pattern , settings ) ) ;
2121 const dynamicPatterns = positivePatterns . filter ( ( pattern ) => utils . pattern . isDynamicPattern ( pattern , settings ) ) ;
2222
23- const staticTasks = convertPatternsToTasks ( staticPatterns , negativePatterns , /* dynamic */ false ) ;
24- const dynamicTasks = convertPatternsToTasks ( dynamicPatterns , negativePatterns , /* dynamic */ true ) ;
23+ const staticTasks = convertPatternsToTasks ( staticPatterns , negativePatterns , settings , /* dynamic */ false ) ;
24+ const dynamicTasks = convertPatternsToTasks ( dynamicPatterns , negativePatterns , settings , /* dynamic */ true ) ;
2525
2626 return staticTasks . concat ( dynamicTasks ) ;
2727}
@@ -52,27 +52,27 @@ function processPatterns(input: Pattern[], settings: Settings): Pattern[] {
5252 * Patterns that can be found inside (`./`) and outside (`../`) the current directory are handled separately.
5353 * This is necessary because directory traversal starts at the base directory and goes deeper.
5454 */
55- export function convertPatternsToTasks ( positive : Pattern [ ] , negative : Pattern [ ] , dynamic : boolean ) : Task [ ] {
55+ export function convertPatternsToTasks ( positive : Pattern [ ] , negative : Pattern [ ] , settings : Settings , dynamic : boolean ) : Task [ ] {
5656 const tasks : Task [ ] = [ ] ;
5757
5858 const patternsOutsideCurrentDirectory = utils . pattern . getPatternsOutsideCurrentDirectory ( positive ) ;
5959 const patternsInsideCurrentDirectory = utils . pattern . getPatternsInsideCurrentDirectory ( positive ) ;
6060
6161 const outsideCurrentDirectoryGroup = groupPatternsByBaseDirectory ( patternsOutsideCurrentDirectory ) ;
62- const insideCurrentDirectoryGroup = groupPatternsByBaseDirectory ( patternsInsideCurrentDirectory ) ;
62+ let insideCurrentDirectoryGroup = groupPatternsByBaseDirectory ( patternsInsideCurrentDirectory ) ;
6363
64- tasks . push ( ...convertPatternGroupsToTasks ( outsideCurrentDirectoryGroup , negative , dynamic ) ) ;
64+ tasks . push ( ...convertPatternGroupsToTasks ( outsideCurrentDirectoryGroup , negative , settings , dynamic ) ) ;
6565
6666 /*
6767 * For the sake of reducing future accesses to the file system, we merge all tasks within the current directory
6868 * into a global task, if at least one pattern refers to the root (`.`). In this case, the global task covers the rest.
6969 */
7070 if ( '.' in insideCurrentDirectoryGroup ) {
71- tasks . push ( convertPatternGroupToTask ( '.' , patternsInsideCurrentDirectory , negative , dynamic ) ) ;
72- } else {
73- tasks . push ( ...convertPatternGroupsToTasks ( insideCurrentDirectoryGroup , negative , dynamic ) ) ;
71+ insideCurrentDirectoryGroup = { '.' : patternsInsideCurrentDirectory } ;
7472 }
7573
74+ tasks . push ( ...convertPatternGroupsToTasks ( insideCurrentDirectoryGroup , negative , settings , dynamic ) ) ;
75+
7676 return tasks ;
7777}
7878
@@ -103,10 +103,22 @@ export function groupPatternsByBaseDirectory(patterns: Pattern[]): PatternsGroup
103103 } , group ) ;
104104}
105105
106- export function convertPatternGroupsToTasks ( positive : PatternsGroup , negative : Pattern [ ] , dynamic : boolean ) : Task [ ] {
107- return Object . keys ( positive ) . map ( ( base ) => {
108- return convertPatternGroupToTask ( base , positive [ base ] , negative , dynamic ) ;
109- } ) ;
106+ export function convertPatternGroupsToTasks ( group : PatternsGroup , negative : Pattern [ ] , settings : Settings , dynamic : boolean ) : Task [ ] {
107+ const tasks : Task [ ] = [ ] ;
108+
109+ for ( const [ base , patterns ] of Object . entries ( group ) ) {
110+ if ( settings . includePatternBaseDirectory && dynamic ) {
111+ tasks . push ( createBaseDirectoryTask ( base , negative ) ) ;
112+ }
113+
114+ tasks . push ( convertPatternGroupToTask ( base , patterns , negative , dynamic ) ) ;
115+ }
116+
117+ return tasks ;
118+ }
119+
120+ function createBaseDirectoryTask ( base : string , negative : Pattern [ ] ) : Task {
121+ return convertPatternGroupToTask ( base , [ base ] , negative , /* dynamic */ false ) ;
110122}
111123
112124export function convertPatternGroupToTask ( base : string , positive : Pattern [ ] , negative : Pattern [ ] , dynamic : boolean ) : Task {
0 commit comments