micromatch / picomatch

Blazing fast and accurate glob matcher written JavaScript, with no dependencies and full support for standard and extended Bash glob features, including braces, extglobs, POSIX brackets, and regular expressions. Used by GraphQL, Jest, Astro, Snowpack, Storybook, bulma, Serverless, fdir, Netlify, AWS Amplify, Revogrid, rollup, routify, open-wc, imba, ava, docusaurus, fast-glob, globby, chokidar, anymatch, cloudflare/miniflare, pts, and more than 5 million projects! Please follow picomatch's author: https://github.com/jonschlinkert
https://github.com/micromatch
MIT License
971 stars 56 forks source link

`**` does not match relative directories starting with `./` #121

Closed silverwind closed 9 months ago

silverwind commented 1 year ago

This seems like a bug:

> (await import("picomatch")).default(["**.js"])("./foo.js")
false
> (await import("picomatch")).default(["**.js"])("foo.js")
true
jonschlinkert commented 9 months ago

A couple of things.

This follows bash spec. A double star ("globstar") must be the only thing in a path segment, otherwise any number of consecutive stars are just treated as a single star: *. So **.js is the same as *.js.

Even though imports/requires and some shell commands use ./, that's not a spec for file paths or matching with globs. There are rules in bash for how to match single dots and whether or not they match when preceding a slash vs other characters. I don't remember them precisely at the moment. However, I added support for a format function to allow users to handle cases like this. I suppose this could be accomplished by wrapping this library too.

silverwind commented 9 months ago

I see, thanks. The format example even deals with this specific case, so maybe I'll use it.