SuperchupuDev / tinyglobby

A fast and minimal alternative to globby and fast-glob
https://npmjs.com/package/tinyglobby
MIT License
149 stars 9 forks source link

Ignore patterns starting with `!` causes 0 results #63

Closed Jason3S closed 1 month ago

Jason3S commented 1 month ago

See: https://codesandbox.io/p/devbox/xr7rqj

import { glob } from "tinyglobby";
import fg from "fast-glob";

async function run() {
  console.log("Run");

  const ignore = ["node_modules", "docs/build/**", "!docs/build/README.md"];

  const resultFG = await fg.glob("**", { ignore });
  const resultTiny = await glob("**", { ignore });

  console.log("%o", { resultFG, resultTiny });
}

run();

Results:

{
  resultFG: [
    'README.md',
    'index.js',
    'package-lock.json',
    'package.json',
    'yarn.lock',
    'docs/README.md',
    'docs/docs-file.txt',
    [length]: 7
  ],
  resultTiny: [ [length]: 0 ]
}

Expected: Results to be similar to fast-glob. Note: fast-glob incorrectly removes docs/build/README.md

SuperchupuDev commented 1 month ago

i see, will fix. thank you

SuperchupuDev commented 1 month ago

i couldn't make it properly work, but it should be consistent with fast-glob now, making this issue solved. can you try it by using the following preview build in your package.json?

  "tinyglobby": "https://pkg.pr.new/tinyglobby@b43ffdf",
Jason3S commented 1 month ago

Thank you very much.

jdalton commented 3 weeks ago

i couldn't make it properly work, but it should be consistent with fast-glob now, making this issue solved.

😢 Ignoring negated patterns is not great. I believe globby supports these. Because this package is named tinyglobby folks might be coming from globby and this difference should definitely be documented.

It means that if any ignore pattern has a ! then the entire ignore option must be set to an empty [] and processed afterwards with something like the ignore package.

SuperchupuDev commented 3 weeks ago

can you show a case where globby produces different results? i thought it didn't support it

jdalton commented 3 weeks ago

Thanks for the quick reply @SuperchupuDev! In digging into this. I looked at the sandbox provided by @Jason3S which does contain a globby compare and it too misses it. I believe the code base I'm on does in fact do the workaround with the ignore() package 🙃. No documentation needed then 🙈