diff --git a/lib/utils.js b/lib/utils.js index 5b782698e3..7eaa199b06 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -576,25 +576,26 @@ exports.lookupFiles = function lookupFiles(filepath, extensions, recursive) { var stat; if (!fs.existsSync(filepath)) { - // Check all extensions, using first match found (if any) - if ( - !extensions.some(function(ext) { - if (fs.existsSync(filepath + '.' + ext)) { - filepath += '.' + ext; - return true; - } - }) - ) { - // Handle glob + if (glob.hasMagic(filepath)) { + // Handle glob without extensions files = glob.sync(filepath, {nodir: true}); - if (!files.length) { - throw createNoFilesMatchPatternError( - 'Cannot find any files matching pattern ' + exports.dQuote(filepath), - filepath - ); - } - return files; + } else { + // glob pattern e.g. 'filepath+(js|ts)' + var strExtensions = extensions + .map(function(v) { + return '.' + v; + }) + .join('|'); + var pattern = filepath + '+(' + strExtensions + ')'; + files = glob.sync(pattern, {nodir: true}); + } + if (!files.length) { + throw createNoFilesMatchPatternError( + 'Cannot find any files matching pattern ' + exports.dQuote(filepath), + filepath + ); } + return files; } // Handle file