Support for negated ignore patterns

Open
#32 16 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
tooling

Research direction

Start by locating tinyglobby’s handling of the ignore option and its existing globbing tests. Compare the requested negated-pattern example with current behavior, then define coverage for preserving excluded paths and restoring .yarn/patches/index.js; done means the shown input returns index.js and .yarn/patches/index.js.

Written by the indexing model from the issue text.

Description

enhancement help wanted

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 })
Dominant language
TypeScript
Stars
544
Forks
30
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from SuperchupuDev/tinyglobby

All issues in SuperchupuDev/tinyglobby

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.