thecodrr / fdir

⚡ The fastest directory crawler & globbing library for NodeJS. Crawls 1m files in < 1s
https://thecodrr.github.io/fdir/
MIT License
1.51k stars 58 forks source link

What's the correct way to use globbing? #74

Closed TwitchBronBron closed 2 years ago

TwitchBronBron commented 2 years ago

What is the correct way to utilize the globbing functionality in fdir? When I run the following test, it does not properly filter the results.

const fs = require('fs');
const { fdir } = require('fdir');
//make some temp files to scan
if (!fs.existsSync('./temp')) {
    fs.mkdirSync('./temp');
    fs.writeFileSync('./temp/alpha.json', '');
    fs.writeFileSync('./temp/beta.txt', '');
}
//find only the files that match the glob
const results = new fdir().glob('*.txt').crawlWithOptions('./temp', {}).sync();
console.log(results);

The glob seems to have no effect, and I'm instead given all of the files in the directory. image

Am I using it wrong? I've installed picomatch, and tried this on fdir 5.2.0, 5.1.0, 5.0.0, 4.1.0, and 4.0.0, all with the same results.

Running the same test but fast-glob (which also uses picomatch) returns the expected results.

const results = require('fast-glob').sync('*.txt', { cwd: './temp' });

image

thecodrr commented 2 years ago

Try this:

const fs = require("fs");
const { fdir } = require("./index");
//make some temp files to scan
if (!fs.existsSync("./temp")) {
  fs.mkdirSync("./temp");
  fs.writeFileSync("./temp/alpha.json", "");
  fs.writeFileSync("./temp/beta.txt", "");
}
//find only the files that match the glob
const results = new fdir()
  .glob("*.txt")
  .crawl("./temp")
  .sync();
console.log(results);

You can either use the builder pattern or crawlWithOptions — not both. That was the only issue with this.

TwitchBronBron commented 2 years ago

That did the trick, thanks!