micromatch / glob-fs

file globbing for node.js. speedy and powerful alternative to node-glob. This library is experimental and does not work on windows!
http://jonschlinkert.github.io/glob-fs
MIT License
55 stars 17 forks source link

readdirAsync doesn't filter #13

Open akaRem opened 8 years ago

akaRem commented 8 years ago

When I try this

require('glob-fs')().readdirPromise('**/*.yaml').then((_)=>console.log(_))

I see just just all files in dir

I suppose that error is somewhere here:

    readdirPromise: function(pattern, options) {
      this.emit('read');
      this.setPattern(pattern, options);
      var res = this.iteratorPromise(this.pattern.base);  
      this.emit('end', this.files);
      return res;
    }

because it's strange to me that end is emitted before promise is resolved.

but change from this:

      this.emit('end', this.files);

to this:

      res.then(() => this.emit('end', this.files));

didn't help

Did I used this method properly? Or am I missing somethig? Or is there some error?

revelt commented 7 years ago

I'm having the same problem. This was driving me nuts for few days.

This will output all json files:

var res = glob.readdirSync('/**/*.json')
console.log('res = ' + res)

This will not filter all json files, but everything instead:

glob.readdirPromise('**/*.json')
  .then(function (file) {
  console.log(file)
})

My current plan is to switch to other libraries that actually can filter out files by extension.

tunnckoCore commented 7 years ago

@revelt @akaRem, yea, well-known bug (or at least) for me from the very beginning of the refactor with these iterators. At all, glob-fs is not fully ready and is experimental.

revelt commented 7 years ago

@tunnckoCore I see! What library do you prefer for promises+glob file reads?

tunnckoCore commented 7 years ago

unfortunately... there is no other package in the whole community that do globs... evey is based on glob, which is very sad and i hate that fact. but it will be changed this year - i made couple of streaming implementation that performs 100-200x better and faster, passing 90% of glob-stream tests. but anyway.

the only thing is custom promise wrapper over glob, or globby directly

revelt commented 7 years ago

Hm. With regards to glob-fs, should we, in theory, add a proper test suite to show where exactly it fails its promises (pun intended)? In my understanding the test suite is not complete according to what's said in readme... Although I don't see Travis set up either..