diff --git a/lib/utils.js b/lib/utils.js index 5b782698e3..013d3ffe0a 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -576,25 +576,27 @@ 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 - files = glob.sync(filepath, {nodir: true}); - if (!files.length) { - throw createNoFilesMatchPatternError( - 'Cannot find any files matching pattern ' + exports.dQuote(filepath), - filepath - ); - } - return files; + var pattern; + if (glob.hasMagic(filepath)) { + // Handle glob as is without extensions + pattern = filepath; + } else { + // glob pattern e.g. 'filepath+(.js|.ts)' + var strExtensions = extensions + .map(function(v) { + return '.' + v; + }) + .join('|'); + 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