fast-glob
fast-glob copied to clipboard
Allow abort glob progress
Environment
- OS Version: macOS 14.2.1
- Node.js Version: 20.10.0
Reference: https://github.com/sindresorhus/globby/issues/261
- Can't stop glob from working when timed out or 1 file is found
- Not easy to check "at least 1 file matches glob patterns"
Code sample
Have a AbortSignal
option to stop stop glob in progress.
const signal = AbortSignal.timeout(200);
try {
return await fg.glob(patterns, {signal});
}
catch {
return [];
}
Or have a globExists
matching the first file.
async function globExists(patterns, options) {
const controller = new AbortController();
for await (const entry of fg.globStream(patterns, {...options, signal: controller.signal})) {
controller.abort();
return entry;
}
}