tinyglobby icon indicating copy to clipboard operation
tinyglobby copied to clipboard

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

Open kahagerman opened this issue 1 year ago • 6 comments

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.

kahagerman avatar Sep 25 '24 13:09 kahagerman

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

SuperchupuDev avatar Sep 25 '24 14:09 SuperchupuDev

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

SuperchupuDev avatar Sep 25 '24 14:09 SuperchupuDev

@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
});

SuperchupuDev avatar Sep 25 '24 20:09 SuperchupuDev

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

benmccann avatar Sep 29 '24 17:09 benmccann

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

SuperchupuDev avatar Sep 29 '24 17:09 SuperchupuDev

it looks like this is easily fixable by using the strictSlashes picomatch option, but i'm not sure if it should be fixed until fast-glob becomes consistent at processing trailing slashes

EDIT: strictSlashes does something different than i thought, nevermind :P

SuperchupuDev avatar Jul 19 '25 00:07 SuperchupuDev