Replicating exact .gitignore style parsing in nodejs
Asked Answered
P

1

7

I'm trying to determine which matcher to use for a few different use cases we have. Most importantly we want to replicate the behaviour that the gitignore parser has.

We were considering using globby fast-glob or node-glob. But they all seem to have extended functionality that .gitignore default parsing doesn't provide.

I.e. globby uses fast-glob and fast-glob uses micromatch, which exposes custom functionality. And node-glob also seems extend the default syntax. Hence I've started investigating a little lower down the chain.

I'm a bit confused why there are so many packages that all seem to be doing the same/very similar things.

Observations / Questions:

  1. All of them seem to do file path wildcard matching one way or another (expect anymatch possibly being more generic)
  2. Minimatch is apparently slower than Micromatch, but has the same/similar functionality?
  3. Multimatch seems to be a simple wrapper around minimatch allowing for multiple patterns. Not sure if this is optimised in any way.
  4. Anymatch seems to be very generic. It doesn't seem to know about file path matching?
  5. Picomatch has "full support for standard and extended Bash glob features". I would assume this matches the gitignore processing closely?
  6. Nanomatch seems to extend functionality of Picomatch. Is this more functionality than what the gitignore processor provides?
  7. Micromatch seems to extend functionality of Nanomatch and appears to be a replacement for Minimatch? It claims to be a "drop-in" replacement, however that doesn't seem to be the case looking at the functionality they expose?
  8. Anymatch, Picomatch, Nanomatch and Micromatch are all published under the github organization Micromatch (naming confusion anyone?)
  9. There doesn't seem to be the equivalent of Multimatch for the "Micromatch organization" suite? Or did I just not find it?

The first question to answer is what standard git actually uses to process it's gitignore. And then figure out which package would match that most closely.

Praenomen answered 7/12, 2018 at 18:35 Comment(0)
A
2

This library comparison has been on picomatch for as long as I can remember. It answers all of your questions, and more (full disclosure: I'm the author of picomatch).

I'm a bit confused why there are so many packages that all seem to be doing the same/very similar things.

Understandable. Your confusion should be cleared up after reading more about the libraries on their extensive readmes. Each library addresses your questions in great detail.

Astolat answered 31/1, 2020 at 16:4 Comment(2)
Well hidden at the bottom of the readme in deed ;) Thank you! Do you by any chance know which standard gitignore files use?Praenomen
I believe gitignore (git) uses wildmatch (wildmat.c) or some derivative of thatAstolat

© 2022 - 2024 — McMap. All rights reserved.