SuperchupuDev / tinyglobby

A fast and minimal alternative to globby and fast-glob
https://npmjs.com/package/tinyglobby
MIT License
106 stars 6 forks source link

Glob with Trailing `/` Matches Files as well as Folders #45

Open kahagerman opened 1 week ago

kahagerman commented 1 week ago

For example, packages/*/ will match a file at packages/foo.

I think expected behaviour here is to only match folders (packages/bar/).

See related downstream discussion on vitest.

SuperchupuDev commented 1 week ago

interesting, does fast-glob present that behavior? can you provide a minimal repro?

SuperchupuDev commented 1 week ago

I see the issue now, fast-glob (which this package aims to replace) does act that way

SuperchupuDev commented 1 week ago

@kahagerman further investigating i've noticed that fast-glob (which is what vitest used before and this package aims to be a replacement of) has really inconsistent behavior around trailing / in patterns and the behavior you describe is only present if the pattern is dynamic (otherwise fast-glob matches files too!). because of this, i'm not sure if making tinyglobby inconsistent as well would be a good idea

you can test this inconsistency in fast-glob this way:

import glob from 'fast-glob';

// dynamic pattern, only returns folders so no files are matched
await glob(['*.ts/'], {
  onlyFiles: false
});

// static pattern, returns files too
await glob(['index.ts/'], {
  onlyFiles: false
});
benmccann commented 5 days ago

Hmm. Maybe the thing to do is report it as a bug in fast-glob. If they fix it then we can remain consistent with fast-glob

SuperchupuDev commented 5 days ago

reported it some days ago at mrmlnc/fast-glob#458. will probably do whatever fast-glob does as long as it's applied in a consistent way