nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
104.27k stars 28.06k forks source link

Replacement for `minimatch` #52779

Open sgrishchenko opened 2 weeks ago

sgrishchenko commented 2 weeks ago

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).

MoLow commented 2 weeks ago

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

sgrishchenko commented 1 week ago

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.

MoLow commented 1 week ago

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

RedYetiDev commented 1 week ago

Sure!