/** * find matching files based on the given path or glob * * @param {string} patterns - glob pattern(s) or relative path * @param {boolean} [isGlob] - pass true to treat the path as a glob * @param {Object} [globOptions] - options to pass to globby * @returns {Array<string>} files */ static findMatchingFiles(patterns: string | Array<string>, {isGlob, globOptions}: { isGlob: boolean, globOptions: Object, }): Array<string> { // Try to treat the patterns as globs first if (globby.hasMagic(patterns) || Array.isArray(patterns) || isGlob) { return globby.sync(patterns, globOptions); } // Fallback to the legacy implementation for non-glob patterns to avoid code breaks return Context.walkDirSync(patterns); }
import { IOptions } from 'glob'; import * as globby from "globby"; (async () => { let result: string[]; result = await globby('*.tmp'); result = await globby(['a.tmp', '*.tmp', '!{c,d,e}.tmp']); result = globby.sync('*.tmp'); result = globby.sync(['a.tmp', '*.tmp', '!{c,d,e}.tmp']); result = await globby('*.tmp', Object.freeze({ignore: Object.freeze([])})); result = globby.sync('*.tmp', Object.freeze({ignore: Object.freeze([])})); })(); const tasks: Array<{ pattern: string, options: IOptions }> = globby.generateGlobTasks(['*.tmp', '!b.tmp'], {ignore: ['c.tmp']}); console.log(globby.hasMagic('**')); console.log(globby.hasMagic(['**', 'path1', 'path2'])); console.log(!globby.hasMagic(['path1', 'path2']));
import { IOptions } from 'glob'; import * as globby from "globby"; (async () => { let result: string[]; result = await globby('*.tmp'); result = await globby(['a.tmp', '*.tmp', '!{c,d,e}.tmp']); result = globby.sync('*.tmp'); result = globby.sync(['a.tmp', '*.tmp', '!{c,d,e}.tmp']); result = await globby('*.tmp', Object.freeze({ignore: Object.freeze([])})); result = globby.sync('*.tmp', Object.freeze({ignore: Object.freeze([])})); })(); const tasks: Array<{ pattern: string, options: IOptions }> = globby.generateGlobTasks(['*.tmp', '!b.tmp'], {ignore: ['c.tmp']}); console.log(globby.hasMagic('**') === true); console.log(globby.hasMagic(['**', 'path1', 'path2']) === true); console.log(globby.hasMagic(['path1', 'path2']) === false);