gatherFiles.mjs 939 B

1234567891011121314151617181920212223
  1. import { glob } from 'glob';
  2. import { minimatch } from 'minimatch';
  3. import { dirname, isAbsolute, join } from 'path';
  4. import { args } from '../bin.mjs';
  5. /** Gathers test files that match the config */
  6. export async function gatherFiles(path, config) {
  7. const fileListsProms = [];
  8. const cwd = dirname(path);
  9. const ignoreGlobs = args.ignore?.map(String).filter((p) => !isAbsolute(p));
  10. for (const file of config.files instanceof Array ? config.files : [config.files]) {
  11. if (isAbsolute(file)) {
  12. if (!ignoreGlobs?.some((i) => minimatch(file, i))) {
  13. fileListsProms.push([file]);
  14. }
  15. }
  16. else {
  17. fileListsProms.push(glob(file, { cwd, ignore: ignoreGlobs }).then((l) => l.map((f) => join(cwd, f))));
  18. }
  19. }
  20. const files = new Set((await Promise.all(fileListsProms)).flat());
  21. args.ignore?.forEach((i) => files.delete(i));
  22. return [...files];
  23. }