Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.capture method not working with braces #169

Open
koopero opened this issue Jun 11, 2019 · 5 comments
Open

.capture method not working with braces #169

koopero opened this issue Jun 11, 2019 · 5 comments

Comments

@koopero
Copy link

koopero commented Jun 11, 2019

The results of the capture method have changed from major version 3 to 4.

const mm = require('micromatch')
const pattern = 'foo/{1..3}'
const string = 'foo/2'

console.log( mm.capture( pattern, string ) )
// Result in 3.1.10: [ '2' ]
// Result in 4.0.2: []

I understand from previous issues & 4.0.0 refactoring that this is tricky case, but perhaps limitations should be noted in documentation?

@jonschlinkert
Copy link
Member

Try using expand as well. If that doesn't work it's a regression.

@koopero
Copy link
Author

koopero commented Jun 11, 2019

Same thing using the options {expand: true}. It appears that capture is not using the braces module at all, and going straight to picomatch.makeRe. The braces handling there is not good. {expand: true} in 3.1.10 returns same erroneous output as 4.0.2.

I'd like to help with this problem, and I will start digging into the code deeper. One question, if I may: What is the use case for the expand option in the context of micromatch?

Also, I should have mentioned before... THANK YOU @jonschlinkert for like a zillion amazing, complete node modules! You're awesome.

@jonschlinkert
Copy link
Member

It appears that capture is not using the braces module at all, and going straight to picomatch.makeRe

I guess I wasn't thinking about this use case when capture was implemented. I'll look into it, what you're saying makes sense.

What is the use case for the expand option in the context of micromatch?

  • It gives globbing implementors (like fast-glob or node-glob) the ability to choose a strategy for hitting the file system. For example: 1) Expand the pattern and glob against multiple patterns and multiple base directories, or 2) Don't expand the pattern and glob against a single pattern and one base directory. If the latter seems like an obvious choice, you probably haven't thought about it long enough :) - I can explain more if anyone is interested.
  • Parity with minimatch

I'm sure there are other reasons, but those are the reasons I remember for including the feature.

THANK YOU

You're very welcome! Thanks for saying thanks :)

@koopero
Copy link
Author

koopero commented Jun 11, 2019

I'm sure there are other reasons, but those are the reasons I remember for including the feature.

I dig that, it just makes for a bit of a mismatch between 'globs as pure regex test functions' and 'globs as expressions expanded to even more globs'. Right now, implementations vary between the methods micromatch, isMatch, makeRe and capture.

I'm working on PR right now that should uses braces more fully and cover more cases. I'll post here in a few days.

@koopero
Copy link
Author

koopero commented Jun 14, 2019

#170

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants