My own slow and unoptimised glob
const process = require('process'); | |
const fs = require('fs'); | |
const util = require('util'); | |
const readdir = util.promisify(fs.readdir); | |
const realpath = util.promisify(fs.realpath); | |
const stat = util.promisify(fs.stat); | |
const ls = async (cwd, paths = []) => { | |
for (let p of (await readdir(cwd))) { | |
const rp = await realpath(`${cwd}/${p}`); | |
paths.push(rp); | |
if ((await stat(rp)).isDirectory()) { | |
await ls(rp, paths); | |
} | |
} | |
return paths; | |
}; | |
const glob = async (cwd, regexp) => (await ls(cwd)).filter(p => p.match(regexp)); | |
(async () => console.log(await glob(process.cwd(), /package.json$/)))(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment