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

Can't match **.internal-test.js #99

Open jakobrosenberg opened 3 years ago

jakobrosenberg commented 3 years ago

I would expect the below to be true

const isMatch = picomatch('**.internal-test.js')
isMatch('my-tests/some-spec.internal-test.js') // false

However this works

const regex = picomatch.toRegex(picomatch.parse('**.internal-test.js').output)
regex.test('my-tests/some-spec.internal-test.js') // true
jakobrosenberg commented 3 years ago

Fixed with by changing glob to **/*.internal-test.js

jakobrosenberg commented 3 years ago

I noticed this inconsistency. Not sure if this is by design or a bug. To err on the side of caution, I'll reopen the issue.

import picomatch from "picomatch";

const isMatch1 = picomatch('**/*.dash-thing.js')
const isMatch2 = picomatch('**/*.thing.js')
const isMatch3 = picomatch('**.dash-thing.js')
const isMatch4 = picomatch('**.thing.js')

console.log(isMatch1('somepath/test.dash-thing.js')) // true
console.log(isMatch2('somepath/test.thing.js'))      // true
console.log(isMatch3('somepath/test.dash-thing.js')) // false
console.log(isMatch4('somepath/test.thing.js'))      // true
jonschlinkert commented 3 years ago

Good catch. '**.thing.js' should not match, so that is a bug since ** should be treated as a single star when it's not the only thing in a path segment (according to bash).

However, the correct way to do what you want is one of the following:

const isMatch1 = picomatch('*/*.thing.js')
const isMatch2 = picomatch('**/*.thing.js')

console.log(isMatch1('somepath/test.thing.js'))      // true
console.log(isMatch2('somepath/test.thing.js'))      // true

thanks for the issue!