@@ -2,6 +2,7 @@ const os = require('os');
22const fs = require ( 'fs' ) ;
33const fsPromises = fs . promises ;
44const path = require ( 'path' ) ;
5+ const glob = require ( 'glob' ) ;
56const { promisify} = require ( 'util' ) ;
67const gitRepoInfo = require ( 'git-repo-info' ) ;
78const gitconfig = require ( 'gitconfiglocal' ) ;
@@ -893,84 +894,7 @@ exports.truncateString = (field, truncateSizeInBytes) => {
893894
894895// Helper function to check if a pattern contains glob characters
895896exports . isGlobPattern = ( pattern ) => {
896- return pattern . includes ( '*' ) || pattern . includes ( '?' ) || pattern . includes ( '[' ) ;
897- } ;
898-
899- // Helper function to recursively find files matching a pattern
900- exports . findFilesRecursively = ( dir , pattern ) => {
901- const files = [ ] ;
902- try {
903- if ( ! fs . existsSync ( dir ) ) {
904- return files ;
905- }
906-
907- const entries = fs . readdirSync ( dir , { withFileTypes : true } ) ;
908-
909- for ( const entry of entries ) {
910- const fullPath = path . join ( dir , entry . name ) ;
911-
912- if ( entry . isDirectory ( ) ) {
913- // Recursively search subdirectories
914- files . push ( ...exports . findFilesRecursively ( fullPath , pattern ) ) ;
915- } else if ( entry . isFile ( ) ) {
916- const relativePath = path . relative ( process . cwd ( ) , fullPath ) ;
917-
918- // Enhanced pattern matching for glob patterns
919- if ( exports . matchesGlobPattern ( relativePath , pattern ) ) {
920- files . push ( relativePath ) ;
921- }
922- }
923- }
924- } catch ( err ) {
925- Logger . debug ( `Error reading directory ${ dir } : ${ err . message } ` ) ;
926- }
927-
928- return files ;
929- } ;
930-
931- // Helper function to match a file path against a glob pattern
932- exports . matchesGlobPattern = ( filePath , pattern ) => {
933- // Normalize paths to use forward slashes
934- const normalizedPath = filePath . replace ( / \\ / g, '/' ) ;
935- const normalizedPattern = pattern . replace ( / \\ / g, '/' ) ;
936-
937- // Convert glob pattern to regex step by step
938- let regexPattern = normalizedPattern ;
939-
940- // First, handle ** patterns (must be done before single *)
941- // ** should match zero or more directories
942- regexPattern = regexPattern . replace ( / \* \* / g, '§DOUBLESTAR§' ) ;
943-
944- // Escape regex special characters except the placeholders
945- regexPattern = regexPattern . replace ( / [ . + ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' ) ;
946-
947- // Now handle single * and ? patterns
948- regexPattern = regexPattern . replace ( / \* / g, '[^/]*' ) ; // * matches anything except path separators
949- regexPattern = regexPattern . replace ( / \? / g, '[^/]' ) ; // ? matches single character except path separator
950-
951- // Finally, replace ** placeholder with regex for any path (including zero directories)
952- regexPattern = regexPattern . replace ( / § D O U B L E S T A R § / g, '.*?' ) ;
953-
954- // Special case: if pattern ends with /**/* we need to handle direct files in the base directory
955- // Convert patterns like "dir/**/*" to also match "dir/*"
956- if ( normalizedPattern . includes ( '/**/' ) ) {
957- const baseRegex = regexPattern ;
958- const alternativeRegex = regexPattern . replace ( / \/ \. \* \? \/ / g, '/' ) ;
959- regexPattern = `(?:${ baseRegex } |${ alternativeRegex } )` ;
960- }
961-
962- // Ensure pattern matches from start to end
963- regexPattern = '^' + regexPattern + '$' ;
964-
965- try {
966- const regex = new RegExp ( regexPattern ) ;
967-
968- return regex . test ( normalizedPath ) ;
969- } catch ( err ) {
970- Logger . debug ( `Error in glob pattern matching: ${ err . message } ` ) ;
971-
972- return false ;
973- }
897+ return glob . hasMagic ( pattern ) ;
974898} ;
975899
976900// Helper function to resolve and collect test files from a path/pattern
@@ -1044,36 +968,17 @@ exports.findTestFilesInDirectory = (dir) => {
1044968exports . expandGlobPattern = ( pattern ) => {
1045969 Logger . debug ( `Expanding glob pattern: ${ pattern } ` ) ;
1046970
1047- // Extract the base directory from the pattern
1048- const parts = pattern . split ( / [ / \\ ] / ) ;
1049- let baseDir = '.' ;
1050- let patternStart = 0 ;
1051-
1052- // Find the first part that contains glob characters
1053- for ( let i = 0 ; i < parts . length ; i ++ ) {
1054- if ( exports . isGlobPattern ( parts [ i ] ) ) {
1055- patternStart = i ;
1056- break ;
1057- }
1058- if ( i === 0 && parts [ i ] !== '.' ) {
1059- baseDir = parts [ i ] ;
1060- } else if ( i > 0 ) {
1061- baseDir = path . join ( baseDir , parts [ i ] ) ;
1062- }
1063- }
1064-
1065- // If baseDir doesn't exist, try current directory
1066- if ( ! fs . existsSync ( baseDir ) ) {
1067- Logger . debug ( `Base directory ${ baseDir } doesn't exist, using current directory` ) ;
1068- baseDir = '.' ;
971+ try {
972+ const files = glob . sync ( pattern ) ;
973+
974+ Logger . debug ( `Found ${ files . length } files matching pattern: ${ pattern } ` ) ;
975+
976+ return files ;
977+ } catch ( err ) {
978+ Logger . debug ( `Error expanding glob pattern: ${ err . message } ` ) ;
979+
980+ return [ ] ;
1069981 }
1070-
1071- Logger . debug ( `Base directory: ${ baseDir } , Pattern: ${ pattern } ` ) ;
1072-
1073- const files = exports . findFilesRecursively ( baseDir , pattern ) ;
1074- Logger . debug ( `Found ${ files . length } files matching pattern: ${ pattern } ` ) ;
1075-
1076- return files ;
1077982} ;
1078983
1079984/**
0 commit comments