Open joscha opened 5 years ago
I just stumbled across https://github.com/micromatch/glob-fs#middleware-examples which has the notion of a middleware
, the above could also be implemented in that way, e.g.:
fg.sync('pattern', {
middleware: (matchedFile, abort) => {
if (foundWhatWeareLookingFor) {
abort(); // this is the last iteration, `fg.sync` will return after this middleware
}
// acts like a filter, returning `true` means we want to include the match
return true;
}
});
which would be more flexible but also a fair bit more complex.
@mrmlnc would you accept a pull request for this feature?
Now it just looks like the functionality is beyond the scope of this package. Perhaps in the future we should think about hooks inside the fs.walk
package.
What problem are you trying to solve? Config search?
The maxMatches
option right now look better.
Implementing maxMatches
sounds great. The reason I need it is because I am searching for the existence of at least one of a specific type of file.
Currently it is not possible to stop a sync glob task. Let's say I run a glob to see if any file exists (similar to
Array.some()
) then I currently have to do:but it means that I still create the result. Ideally I would be able to:
where
.sync
would exit once it has foundmaxMatches
matches.