node icon indicating copy to clipboard operation
node copied to clipboard

Replacement for `minimatch`

Open sgrishchenko opened this issue 1 month ago • 4 comments

What is the problem this feature will solve?

It is great that now in Node 22 there is fs.glob. But it seems that also replacement for minimatch is required. Otherwise, I don't know how to use exclude function from fs.glob options, because it is a frequent scenario when I need to use some glob pattern to exclude files.

What is the feature you are proposing to solve the problem?

I propose to export some helper that matches path string and glob pattern (maybe from path module).

What alternatives have you considered?

The only alternative I see for now is use minimatch package (or package that similar to it).

sgrishchenko avatar May 01 '24 14:05 sgrishchenko

can you give an example of your use case? do you mean something along the lines of path.matchesPattern(pattern:string, path:string) => boolean?

MoLow avatar May 02 '24 11:05 MoLow

Yes, something like this. E.g. in Vitest docs you can see an example of exclude property in config. If I want to implement a similar approach in my CLI utility that is written in Node, I need to filter out file names that provides fs.glob for me. Unfortunately, I don't see any way how I can do this using current Node API.

Also, I am developing Karakum project. It also CLI util, I use it to convert Typescript definitions to Kotlin/JS definitions. And I also have a similar problem: I need to collect some files using globs, but then I need to ignore some of them (also using glob). Now I use glob and minimatch libraries for it. I considered using native Node API, but I realized that I don't have a replacement for minimatch.

BTW, thanks for asking.

sgrishchenko avatar May 03 '24 19:05 sgrishchenko

@RedYetiDev are you interested in picking this up and adding a path.isMatch/path.matchesPattern helper?

MoLow avatar May 07 '24 08:05 MoLow

Sure!

RedYetiDev avatar May 07 '24 10:05 RedYetiDev