sindresorhus / globby

User-friendly glob matching
MIT License
2.49k stars 126 forks source link

Prevent search of ignore files in ignored files list #258

Closed nicolas-goudry closed 5 months ago

nicolas-goudry commented 8 months ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch globby@13.2.2 for the project I'm working on.

The issue that gave birth to this fix can be found in xo’s repository. You’ll find there all the explanations about why I did need it.

While I believe this is not a great fix (code-wise), it does solve my issue. If you want me to open a PR, I’ll gladly do so! Please let me know :slightly_smiling_face:

Here is the diff that solved my problem:

diff --git a/node_modules/globby/ignore.js b/node_modules/globby/ignore.js
index 3d8e1a8..74de387 100644
--- a/node_modules/globby/ignore.js
+++ b/node_modules/globby/ignore.js
@@ -60,12 +60,13 @@ const normalizeOptions = (options = {}) => ({
    cwd: toPath(options.cwd) || process.cwd(),
    suppressErrors: Boolean(options.suppressErrors),
    deep: typeof options.deep === 'number' ? options.deep : Number.POSITIVE_INFINITY,
+  ignore: Array.isArray(options.ignore) ? [...options.ignore, ...ignoreFilesGlobOptions.ignore] : ignoreFilesGlobOptions.ignore
 });

 export const isIgnoredByIgnoreFiles = async (patterns, options) => {
-   const {cwd, suppressErrors, deep} = normalizeOptions(options);
+   const {cwd, suppressErrors, deep, ignore} = normalizeOptions(options);

-   const paths = await fastGlob(patterns, {cwd, suppressErrors, deep, ...ignoreFilesGlobOptions});
+   const paths = await fastGlob(patterns, {cwd, suppressErrors, deep, ...ignoreFilesGlobOptions, ignore});

    const files = await Promise.all(
        paths.map(async filePath => ({
@@ -78,9 +79,9 @@ export const isIgnoredByIgnoreFiles = async (patterns, options) => {
 };

 export const isIgnoredByIgnoreFilesSync = (patterns, options) => {
-   const {cwd, suppressErrors, deep} = normalizeOptions(options);
+   const {cwd, suppressErrors, deep, ignore} = normalizeOptions(options);

-   const paths = fastGlob.sync(patterns, {cwd, suppressErrors, deep, ...ignoreFilesGlobOptions});
+   const paths = fastGlob.sync(patterns, {cwd, suppressErrors, deep, ...ignoreFilesGlobOptions, ignore});

    const files = paths.map(filePath => ({
        filePath,

This issue body was partially generated by patch-package.

sindresorhus commented 8 months ago

PR welcome, but needs some tests.


I also think it throwing an error in your case is a bug: https://github.com/sindresorhus/globby/issues/254