Skip to content

Commit

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

0 comments on commit 37325b4

Please sign in to comment.