Skip to content

Commit

Permalink
more glob
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed May 11, 2019
1 parent c58b911 commit 6ef5519
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions lib/utils.js
Expand Up @@ -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
Expand Down

0 comments on commit 6ef5519

Please sign in to comment.