Skip to content

Commit

Permalink
fix: check --ignore patterns before dir access;
Browse files Browse the repository at this point in the history
- drops / inlines totalist dependency
- Closes #111
  • Loading branch information
lukeed committed Oct 29, 2021
1 parent 117457c commit 730e7be
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@
"dequal": "^2.0.0",
"diff": "^5.0.0",
"kleur": "^4.0.3",
"sade": "^1.7.3",
"totalist": "^2.0.0"
"sade": "^1.7.3"
},
"devDependencies": {
"bundt": "1.1.1",
"esm": "3.2.25",
"module-alias": "2.2.2"
"module-alias": "2.2.2",
"totalist": "2.0.0"
},
"_moduleAliases": {
"uvu": "src/index.js",
Expand Down
31 changes: 24 additions & 7 deletions src/parse.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { resolve } from 'path';
import { totalist } from 'totalist';
import { readdir, stat } from 'fs';
import { resolve, join } from 'path';
import { promisify } from 'util';

const ls = promisify(readdir);
const toStat = promisify(stat);
const toRegex = x => new RegExp(x, 'i');

function exists(dep) {
Expand All @@ -25,11 +28,25 @@ export async function parse(dir, pattern, opts = {}) {
throw new Error(`Cannot find module '${name}'`);
});

await totalist(dir, (rel, abs) => {
if (pattern.test(rel) && !ignores.some(x => x.test(rel))) {
suites.push({ name: rel, file: abs });
}
});
// NOTE: Node 8.x support
// @modified lukeed/totalist
await (async function collect(d, p) {
await ls(d).then(files => {
return Promise.all(
files.map(async str => {
let name = join(p, str);
for (let i = ignores.length; i--;) {
if (ignores[i].test(name)) return;
}

let file = join(dir, str);
let stats = await toStat(file);
if (stats.isDirectory()) return collect(file, name);
else if (pattern.test(name)) suites.push({ name, file });
})
);
});
})(dir, '');

suites.sort((a, b) => a.name.localeCompare(b.name));

Expand Down

0 comments on commit 730e7be

Please sign in to comment.