Skip to content

Support for negated ignore patterns #32

Open
@webpro

Description

@webpro

Would be great to support negated patterns in the ignore option.

Use case: respect files like .gitignore (or others like .prettierignore etc) when globbing.

E.g. globby has the gitignore option which does the .gitignore reading, parsing and evaluation.

I wouldn't expect tinyglobby to include this feature (to read and parse such ignore files), but would be great to support negated ignore patterns so tinyglobby could be extended to support the use case.

The same has been requested in both node-glob and fast-glob, but neither of them currently supports it. Refs:

It would make migration more interesting for globby (with gitignore: true) users. Also I understand tinyglobby wants to stay tiny so feel free to reject!

Here's an example simplified use case to clarify things a bit. Let's say we want to glob all **/index.js files in a workspace that has this .gitignore:

.yarn/*
!.yarn/patches
...

And files:

.
├── index.js
└── .yarn
    ├── patches
    │   └── index.js
    └── index.js

After reading the .gitignore file(s) and converting the patterns the options look like this:

glob(["**/*.js"], {
  dot: true,
  ignore: ["**/.yarn/*", "!**/.yarn/patches/**"],
});

Expected result:

["index.js", ".yarn/patches/index.js"]

Just saying, for users to stuff it all into patterns argument directly is likely not a good idea. I think this doesn't and shouldn't work:

glob(["**/*.{js,ts}", "!.yarn", ".yarn/patches/**/*.{js,ts}"], { dot: true })

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions