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