From acf44996aef1b3a056c0419ef220b3257491dbfc Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Mon, 24 Jan 2022 18:14:55 -0500 Subject: [PATCH 01/17] Add ignoreFiles option This is very similar to the `gitignore` option, except it allows globing for any compatible ignore file (eg, `.prettierignore` or `.eslintignore`). --- gitignore.js => ignore.js | 8 ++--- index.d.ts | 9 +++++ index.js | 29 ++++++++++------ package.json | 2 +- readme.md | 13 ++++++- tests/{gitignore.js => ignore.js} | 58 ++++++++++++++++--------------- 6 files changed, 74 insertions(+), 45 deletions(-) rename gitignore.js => ignore.js (89%) rename tests/{gitignore.js => ignore.js} (59%) diff --git a/gitignore.js b/ignore.js similarity index 89% rename from gitignore.js rename to ignore.js index 0d27c58..6ef314d 100644 --- a/gitignore.js +++ b/ignore.js @@ -77,10 +77,10 @@ const normalizeOptions = (options = {}) => ({ cwd: toPath(options.cwd) || slash(process.cwd()), }); -export const isGitIgnored = async options => { +export const isIgnored = async (pattern, options) => { const {cwd} = normalizeOptions(options); - const paths = await fastGlob('**/.gitignore', {cwd, ...gitignoreGlobOptions}); + const paths = await fastGlob(pattern, {cwd, ...gitignoreGlobOptions}); const files = await Promise.all(paths.map(file => getFile(file, cwd))); const ignores = reduceIgnore(files); @@ -88,10 +88,10 @@ export const isGitIgnored = async options => { return getIsIgnoredPredicate(ignores, cwd); }; -export const isGitIgnoredSync = options => { +export const isIgnoredSync = (pattern, options) => { const {cwd} = normalizeOptions(options); - const paths = fastGlob.sync('**/.gitignore', {cwd, ...gitignoreGlobOptions}); + const paths = fastGlob.sync(pattern, {cwd, ...gitignoreGlobOptions}); const files = paths.map(file => getFileSync(file, cwd)); const ignores = reduceIgnore(files); diff --git a/index.d.ts b/index.d.ts index ae46f2a..32c47e9 100644 --- a/index.d.ts +++ b/index.d.ts @@ -42,11 +42,20 @@ export interface Options extends FastGlobOptionsWithoutCwd { /** Respect ignore patterns in `.gitignore` files that apply to the globbed files. + This option takes precedence over the `ignoreFiles` option. @default false */ readonly gitignore?: boolean; + /** + A glob pattern to look for ignore files, which are then used to ignore globbed files. This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files. + This value is unused if `{ gitignore: true }`, since `gitignore` takes precedence. + + @default undefined + */ + readonly ignoreFiles?: string; + /** The current working directory in which to search. diff --git a/index.js b/index.js index 5eb4ada..52437d3 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ import fs from 'node:fs'; import merge2 from 'merge2'; import fastGlob from 'fast-glob'; import dirGlob from 'dir-glob'; -import {isGitIgnored, isGitIgnoredSync} from './gitignore.js'; +import {isIgnored, isIgnoredSync} from './ignore.js'; import {FilterStream, toPath} from './utilities.js'; const isNegative = pattern => pattern[0] === '!'; @@ -52,13 +52,21 @@ const normalizeOptions = (options = {}) => { const normalizeArguments = fn => async (patterns, options) => fn(toPatternsArray(patterns), normalizeOptions(options)); const normalizeArgumentsSync = fn => (patterns, options) => fn(toPatternsArray(patterns), normalizeOptions(options)); -const getFilter = async options => createFilterFunction( - options.gitignore && await isGitIgnored({cwd: options.cwd}), -); +const getIgnoreFilesPattern = options => options && options.gitignore ? '**/.gitignore' : options && options.ignoreFiles; -const getFilterSync = options => createFilterFunction( - options.gitignore && isGitIgnoredSync({cwd: options.cwd}), -); +const getFilter = async options => { + const ignoreFilesPattern = getIgnoreFilesPattern(options); + return createFilterFunction( + ignoreFilesPattern && await isIgnored(ignoreFilesPattern, {cwd: options.cwd}), + ); +}; + +const getFilterSync = options => { + const ignoreFilesPattern = getIgnoreFilesPattern(options); + return createFilterFunction( + ignoreFilesPattern && isIgnoredSync(ignoreFilesPattern, {cwd: options.cwd}), + ); +}; const createFilterFunction = isIgnored => { const seen = new Set(); @@ -200,7 +208,6 @@ export const isDynamicPattern = normalizeArgumentsSync( export const generateGlobTasks = normalizeArguments(generateTasks); export const generateGlobTasksSync = normalizeArgumentsSync(generateTasksSync); -export { - isGitIgnored, - isGitIgnoredSync, -} from './gitignore.js'; +export {isIgnored, isIgnoredSync} from './ignore.js'; +export const isGitIgnored = options => isIgnored('**/.gitignore', options); +export const isGitIgnoredSync = options => isIgnoredSync('**/.gitignore', options); diff --git a/package.json b/package.json index 016f4b0..2322f2d 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "files": [ "index.js", "index.d.ts", - "gitignore.js", + "ignore.js", "utilities.js" ], "keywords": [ diff --git a/readme.md b/readme.md index 8ddca37..fb3f267 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,7 @@ Based on [`fast-glob`](https://github.com/mrmlnc/fast-glob) but adds a bunch of - Multiple patterns - Negated patterns: `['foo*', '!foobar']` - Expands directories: `foo` → `foo/**/*` -- Supports `.gitignore` +- Supports `.gitignore`, or any similar ignore file configuration. - Supports `URL` as `cwd` ## Install @@ -88,6 +88,17 @@ Default: `false` Respect ignore patterns in `.gitignore` files that apply to the globbed files. +This option takes precedence over the `ignoreFiles` option. + +##### ignoreFiles + +Type: `string`\ +Default: `undefined` + +A glob pattern to look for ignore files, which are then used to ignore globbed files. This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files. + +This value is unused if `{ gitignore: true }`, because `gitignore` takes precedence. + ### globbySync(patterns, options?) Returns `string[]` of matching paths. diff --git a/tests/gitignore.js b/tests/ignore.js similarity index 59% rename from tests/gitignore.js rename to tests/ignore.js index 7dd04b6..1c2b26b 100644 --- a/tests/gitignore.js +++ b/tests/ignore.js @@ -1,63 +1,65 @@ import path from 'node:path'; import test from 'ava'; import slash from 'slash'; -import {isGitIgnored, isGitIgnoredSync} from '../gitignore.js'; +import {isIgnored, isIgnoredSync} from '../ignore.js'; import { PROJECT_ROOT, getPathValues, } from './utilities.js'; -test('gitignore', async t => { +const gitignorePattern = '**/.gitignore'; + +test('ignore', async t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/gitignore'))) { // eslint-disable-next-line no-await-in-loop - const isIgnored = await isGitIgnored({cwd}); - const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); + const ignored = await isIgnored(gitignorePattern, {cwd}); + const actual = ['foo.js', 'bar.js'].filter(file => !ignored(file)); const expected = ['bar.js']; t.deepEqual(actual, expected); } }); -test('gitignore - mixed path styles', async t => { +test('ignore - mixed path styles', async t => { const directory = path.join(PROJECT_ROOT, 'fixtures/gitignore'); for (const cwd of getPathValues(directory)) { // eslint-disable-next-line no-await-in-loop - const isIgnored = await isGitIgnored({cwd}); - t.true(isIgnored(slash(path.resolve(directory, 'foo.js')))); + const ignored = await isIgnored(gitignorePattern, {cwd}); + t.true(ignored(slash(path.resolve(directory, 'foo.js')))); } }); -test('gitignore - os paths', async t => { +test('ignore - os paths', async t => { const directory = path.join(PROJECT_ROOT, 'fixtures/gitignore'); for (const cwd of getPathValues(directory)) { // eslint-disable-next-line no-await-in-loop - const isIgnored = await isGitIgnored({cwd}); - t.true(isIgnored(path.resolve(directory, 'foo.js'))); + const ignored = await isIgnored(gitignorePattern, {cwd}); + t.true(ignored(path.resolve(directory, 'foo.js'))); } }); -test('gitignore - sync', t => { +test('ignore - sync', t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/gitignore'))) { - const isIgnored = isGitIgnoredSync({cwd}); - const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); + const ignored = isIgnoredSync(gitignorePattern, {cwd}); + const actual = ['foo.js', 'bar.js'].filter(file => !ignored(file)); const expected = ['bar.js']; t.deepEqual(actual, expected); } }); -test('negative gitignore', async t => { +test('negative ignore', async t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/negative'))) { // eslint-disable-next-line no-await-in-loop - const isIgnored = await isGitIgnored({cwd}); - const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); + const ignored = await isIgnored(gitignorePattern, {cwd}); + const actual = ['foo.js', 'bar.js'].filter(file => !ignored(file)); const expected = ['foo.js']; t.deepEqual(actual, expected); } }); -test('negative gitignore - sync', t => { +test('negative ignore - sync', t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/negative'))) { - const isIgnored = isGitIgnoredSync({cwd}); - const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); + const ignored = isIgnoredSync(gitignorePattern, {cwd}); + const actual = ['foo.js', 'bar.js'].filter(file => !ignored(file)); const expected = ['foo.js']; t.deepEqual(actual, expected); } @@ -66,14 +68,14 @@ test('negative gitignore - sync', t => { test('multiple negation', async t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/multiple-negation'))) { // eslint-disable-next-line no-await-in-loop - const isIgnored = await isGitIgnored({cwd}); + const ignored = await isIgnored(gitignorePattern, {cwd}); const actual = [ '!!!unicorn.js', '!!unicorn.js', '!unicorn.js', 'unicorn.js', - ].filter(file => !isIgnored(file)); + ].filter(file => !ignored(file)); const expected = ['!!unicorn.js', '!unicorn.js']; t.deepEqual(actual, expected); @@ -82,14 +84,14 @@ test('multiple negation', async t => { test('multiple negation - sync', t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/multiple-negation'))) { - const isIgnored = isGitIgnoredSync({cwd}); + const ignored = isIgnoredSync(gitignorePattern, {cwd}); const actual = [ '!!!unicorn.js', '!!unicorn.js', '!unicorn.js', 'unicorn.js', - ].filter(file => !isIgnored(file)); + ].filter(file => !ignored(file)); const expected = ['!!unicorn.js', '!unicorn.js']; t.deepEqual(actual, expected); @@ -99,15 +101,15 @@ test('multiple negation - sync', t => { test('check file', async t => { const directory = path.join(PROJECT_ROOT, 'fixtures/gitignore'); const ignoredFile = path.join(directory, 'foo.js'); - const isIgnored = await isGitIgnored({cwd: directory}); - const isIgnoredSync = isGitIgnoredSync({cwd: directory}); + const ignored = await isIgnored(gitignorePattern, {cwd: directory}); + const ignoredSync = isIgnoredSync(gitignorePattern, {cwd: directory}); for (const file of getPathValues(ignoredFile)) { - t.true(isIgnored(file)); - t.true(isIgnoredSync(file)); + t.true(ignored(file)); + t.true(ignoredSync(file)); } for (const file of getPathValues(path.join(directory, 'bar.js'))) { - t.false(isIgnored(file)); + t.false(ignored(file)); } }); From 42f29a56407b77b7225a5bab90ed870192f20b8a Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Mon, 24 Jan 2022 21:39:04 -0500 Subject: [PATCH 02/17] Review updates --- ignore.js | 4 ++-- index.d.ts | 6 +++--- index.js | 22 ++++++++++++++++------ tests/globby.js | 10 ++++++++++ 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/ignore.js b/ignore.js index 6ef314d..98c451f 100644 --- a/ignore.js +++ b/ignore.js @@ -2,7 +2,7 @@ import process from 'node:process'; import fs from 'node:fs'; import path from 'node:path'; import fastGlob from 'fast-glob'; -import gitIgnore from 'ignore'; +import ignore from 'ignore'; import slash from 'slash'; import {toPath} from './utilities.js'; @@ -35,7 +35,7 @@ const parseGitIgnore = (content, options) => { }; const reduceIgnore = files => { - const ignores = gitIgnore(); + const ignores = ignore(); for (const file of files) { ignores.add(parseGitIgnore(file.content, { cwd: file.cwd, diff --git a/index.d.ts b/index.d.ts index 32c47e9..3b62c22 100644 --- a/index.d.ts +++ b/index.d.ts @@ -42,7 +42,7 @@ export interface Options extends FastGlobOptionsWithoutCwd { /** Respect ignore patterns in `.gitignore` files that apply to the globbed files. - This option takes precedence over the `ignoreFiles` option. + This option merges with `ignoreFiles` is both are specified. @default false */ @@ -50,11 +50,11 @@ export interface Options extends FastGlobOptionsWithoutCwd { /** A glob pattern to look for ignore files, which are then used to ignore globbed files. This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files. - This value is unused if `{ gitignore: true }`, since `gitignore` takes precedence. + This option merges with `.gitignore` if both are specified. @default undefined */ - readonly ignoreFiles?: string; + readonly ignoreFiles?: string | string[]; /** The current working directory in which to search. diff --git a/index.js b/index.js index 52437d3..be08d98 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ const assertPatternsInput = patterns => { }; const toPatternsArray = patterns => { - patterns = [...new Set([patterns].flat())]; + patterns = [...new Set([patterns].flat(Infinity))]; assertPatternsInput(patterns); return patterns; }; @@ -52,19 +52,29 @@ const normalizeOptions = (options = {}) => { const normalizeArguments = fn => async (patterns, options) => fn(toPatternsArray(patterns), normalizeOptions(options)); const normalizeArgumentsSync = fn => (patterns, options) => fn(toPatternsArray(patterns), normalizeOptions(options)); -const getIgnoreFilesPattern = options => options && options.gitignore ? '**/.gitignore' : options && options.ignoreFiles; +const getIgnoreFilesPatterns = options => { + if (!options) { + return []; + } + + const patterns = [ + options.gitignore && '**/.gitignore', + options.ignoreFiles, + ].filter(Boolean); + return toPatternsArray(patterns); +}; const getFilter = async options => { - const ignoreFilesPattern = getIgnoreFilesPattern(options); + const filePatterns = getIgnoreFilesPatterns(options); return createFilterFunction( - ignoreFilesPattern && await isIgnored(ignoreFilesPattern, {cwd: options.cwd}), + filePatterns.length > 0 && await isIgnored(filePatterns, {cwd: options.cwd}), ); }; const getFilterSync = options => { - const ignoreFilesPattern = getIgnoreFilesPattern(options); + const filePatterns = getIgnoreFilesPatterns(options); return createFilterFunction( - ignoreFilesPattern && isIgnoredSync(ignoreFilesPattern, {cwd: options.cwd}), + filePatterns.length > 0 && isIgnoredSync(filePatterns, {cwd: options.cwd}), ); }; diff --git a/tests/globby.js b/tests/globby.js index c61e706..1c4e179 100644 --- a/tests/globby.js +++ b/tests/globby.js @@ -237,6 +237,16 @@ test('gitignore option and objectMode option', async t => { t.truthy(result[0].path); }); +test('respects ignoreFiles string option', async t => { + const actual = await runGlobby(t, '*', {gitignore: false, ignoreFiles: '.gitignore', onlyFiles: false}); + t.false(actual.includes('node_modules')); +}); + +test('respects ignoreFiles array option', async t => { + const actual = await runGlobby(t, '*', {gitignore: false, ignoreFiles: ['.gitignore'], onlyFiles: false}); + t.false(actual.includes('node_modules')); +}); + test('`{extension: false}` and `expandDirectories.extensions` option', async t => { for (const temporaryDirectory of getPathValues(temporary)) { t.deepEqual( From 5a3efcb938999bb6f63739e39907dc7a1f00319c Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Mon, 24 Jan 2022 22:18:56 -0500 Subject: [PATCH 03/17] Review edits --- index.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index be08d98..7f62d08 100644 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ const assertPatternsInput = patterns => { }; const toPatternsArray = patterns => { - patterns = [...new Set([patterns].flat(Infinity))]; + patterns = [...new Set([patterns].flat())]; assertPatternsInput(patterns); return patterns; }; @@ -57,10 +57,11 @@ const getIgnoreFilesPatterns = options => { return []; } - const patterns = [ - options.gitignore && '**/.gitignore', - options.ignoreFiles, - ].filter(Boolean); + const patterns = toPatternsArray(options.ignoreFiles || []); + if (options.gitignore) { + patterns.push('**/.gitignore'); + } + return toPatternsArray(patterns); }; From 880fa277f8e77f5079de84dd6cca0095db4aa3fe Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Mon, 24 Jan 2022 22:36:09 -0500 Subject: [PATCH 04/17] Fix leftover toPatternsArray --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 7f62d08..3744254 100644 --- a/index.js +++ b/index.js @@ -62,7 +62,7 @@ const getIgnoreFilesPatterns = options => { patterns.push('**/.gitignore'); } - return toPatternsArray(patterns); + return patterns; }; const getFilter = async options => { From 3f1594b737951e893b5a885220fdc05d7263a66e Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Jan 2022 14:56:41 +0800 Subject: [PATCH 05/17] Rename --- ignore.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ignore.js b/ignore.js index 9cbc3e1..1452baf 100644 --- a/ignore.js +++ b/ignore.js @@ -2,11 +2,11 @@ import process from 'node:process'; import fs from 'node:fs'; import path from 'node:path'; import fastGlob from 'fast-glob'; -import ignore from 'ignore'; +import gitIgnore from 'ignore'; import slash from 'slash'; import {toPath, isNegativePattern} from './utilities.js'; -const gitignoreGlobOptions = { +const ignoreFilesGlobOptions = { ignore: [ '**/node_modules', '**/flow-typed', @@ -20,7 +20,7 @@ const applyBaseToPattern = (pattern, base) => isNegativePattern(pattern) ? '!' + path.posix.join(base, pattern.slice(1)) : path.posix.join(base, pattern); -const parseGitIgnoreFile = (file, cwd) => { +const parseIgnoreFile = (file, cwd) => { const base = slash(path.relative(cwd, path.dirname(file.filePath))); return file.content @@ -43,7 +43,7 @@ const toRelativePath = (fileOrDirectory, cwd) => { }; const getIsIgnoredPredicate = (files, cwd) => { - const patterns = files.flatMap(file => parseGitIgnoreFile(file, cwd)); + const patterns = files.flatMap(file => parseIgnoreFile(file, cwd)); const ignores = gitIgnore().add(patterns); return fileOrDirectory => { @@ -57,10 +57,10 @@ const normalizeOptions = (options = {}) => ({ cwd: toPath(options.cwd) || process.cwd(), }); -export const isIgnored = async (pattern, options) => { +export const isIgnored = async (patterns, options) => { const {cwd} = normalizeOptions(options); - const paths = await fastGlob(pattern, {cwd, ...gitignoreGlobOptions}); + const paths = await fastGlob(patterns, {cwd, ...ignoreFilesGlobOptions}); const files = await Promise.all( paths.map(async filePath => ({ @@ -72,10 +72,10 @@ export const isIgnored = async (pattern, options) => { return getIsIgnoredPredicate(files, cwd); }; -export const isIgnoredSync = (pattern, options) => { +export const isIgnoredSync = (patterns, options) => { const {cwd} = normalizeOptions(options); - const paths = fastGlob.sync(pattern, {cwd, ...gitignoreGlobOptions}); + const paths = fastGlob.sync(patterns, {cwd, ...ignoreFilesGlobOptions}); const files = paths.map(filePath => ({ filePath, From 6f503fa7f6c9f0a1a59925a1ce0f155001025d72 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Jan 2022 15:01:07 +0800 Subject: [PATCH 06/17] Add `GITIGNORE_PATTERN`, remove `isIgnored` and `isIgnoredSync` --- ignore.js | 5 +++++ index.js | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/ignore.js b/ignore.js index 1452baf..3f70d2f 100644 --- a/ignore.js +++ b/ignore.js @@ -16,6 +16,8 @@ const ignoreFilesGlobOptions = { absolute: true, }; +export const GITIGNORE_PATTERN = '**/.gitignore'; + const applyBaseToPattern = (pattern, base) => isNegativePattern(pattern) ? '!' + path.posix.join(base, pattern.slice(1)) : path.posix.join(base, pattern); @@ -84,3 +86,6 @@ export const isIgnoredSync = (patterns, options) => { return getIsIgnoredPredicate(files, cwd); }; + +export const isGitIgnored = options => isIgnored(GITIGNORE_PATTERN, options); +export const isGitIgnoredSync = options => isIgnoredSync(GITIGNORE_PATTERN, options); diff --git a/index.js b/index.js index 02cf0b5..91098e1 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ import fs from 'node:fs'; import merge2 from 'merge2'; import fastGlob from 'fast-glob'; import dirGlob from 'dir-glob'; -import {isIgnored, isIgnoredSync} from './ignore.js'; +import {isIgnored, isIgnoredSync, GITIGNORE_PATTERN} from './ignore.js'; import {FilterStream, toPath, isNegativePattern} from './utilities.js'; const assertPatternsInput = patterns => { @@ -57,7 +57,7 @@ const getIgnoreFilesPatterns = options => { const patterns = toPatternsArray(options.ignoreFiles || []); if (options.gitignore) { - patterns.push('**/.gitignore'); + patterns.push(GITIGNORE_PATTERN); } return patterns; @@ -217,6 +217,7 @@ export const isDynamicPattern = normalizeArgumentsSync( export const generateGlobTasks = normalizeArguments(generateTasks); export const generateGlobTasksSync = normalizeArgumentsSync(generateTasksSync); -export {isIgnored, isIgnoredSync} from './ignore.js'; -export const isGitIgnored = options => isIgnored('**/.gitignore', options); -export const isGitIgnoredSync = options => isIgnoredSync('**/.gitignore', options); +export { + isGitIgnored, + isGitIgnoredSync, +} from './ignore.js'; From 0da7fbdbe965d34a31c67901e68683b675267949 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Jan 2022 15:03:51 +0800 Subject: [PATCH 07/17] Fix docs --- index.d.ts | 4 +--- readme.md | 8 ++------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/index.d.ts b/index.d.ts index 3b62c22..8c77fa4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -42,15 +42,13 @@ export interface Options extends FastGlobOptionsWithoutCwd { /** Respect ignore patterns in `.gitignore` files that apply to the globbed files. - This option merges with `ignoreFiles` is both are specified. @default false */ readonly gitignore?: boolean; /** - A glob pattern to look for ignore files, which are then used to ignore globbed files. This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files. - This option merges with `.gitignore` if both are specified. + Glob patterns to look for ignore files, which are then used to ignore globbed files. This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files. @default undefined */ diff --git a/readme.md b/readme.md index fb3f267..1271172 100644 --- a/readme.md +++ b/readme.md @@ -88,16 +88,12 @@ Default: `false` Respect ignore patterns in `.gitignore` files that apply to the globbed files. -This option takes precedence over the `ignoreFiles` option. - ##### ignoreFiles -Type: `string`\ +Type: `string | string[]`\ Default: `undefined` -A glob pattern to look for ignore files, which are then used to ignore globbed files. This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files. - -This value is unused if `{ gitignore: true }`, because `gitignore` takes precedence. +Glob patterns to look for ignore files, which are then used to ignore globbed files. This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files. ### globbySync(patterns, options?) From 5f295bced132bf32b2fe7b7aacc3cb821fe3d23e Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Jan 2022 15:08:23 +0800 Subject: [PATCH 08/17] Minor tweak --- ignore.js | 6 +++--- index.js | 12 +++++------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/ignore.js b/ignore.js index 3f70d2f..651f412 100644 --- a/ignore.js +++ b/ignore.js @@ -16,7 +16,7 @@ const ignoreFilesGlobOptions = { absolute: true, }; -export const GITIGNORE_PATTERN = '**/.gitignore'; +export const GITIGNORE_FILE_PATTERN = '**/.gitignore'; const applyBaseToPattern = (pattern, base) => isNegativePattern(pattern) ? '!' + path.posix.join(base, pattern.slice(1)) @@ -87,5 +87,5 @@ export const isIgnoredSync = (patterns, options) => { return getIsIgnoredPredicate(files, cwd); }; -export const isGitIgnored = options => isIgnored(GITIGNORE_PATTERN, options); -export const isGitIgnoredSync = options => isIgnoredSync(GITIGNORE_PATTERN, options); +export const isGitIgnored = options => isIgnored(GITIGNORE_FILE_PATTERN, options); +export const isGitIgnoredSync = options => isIgnoredSync(GITIGNORE_FILE_PATTERN, options); diff --git a/index.js b/index.js index 91098e1..d1b936d 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ import fs from 'node:fs'; import merge2 from 'merge2'; import fastGlob from 'fast-glob'; import dirGlob from 'dir-glob'; -import {isIgnored, isIgnoredSync, GITIGNORE_PATTERN} from './ignore.js'; +import {isIgnored, isIgnoredSync, GITIGNORE_FILE_PATTERN} from './ignore.js'; import {FilterStream, toPath, isNegativePattern} from './utilities.js'; const assertPatternsInput = patterns => { @@ -51,13 +51,11 @@ const normalizeArguments = fn => async (patterns, options) => fn(toPatternsArray const normalizeArgumentsSync = fn => (patterns, options) => fn(toPatternsArray(patterns), normalizeOptions(options)); const getIgnoreFilesPatterns = options => { - if (!options) { - return []; - } + const {ignoreFiles, gitignore} = options; - const patterns = toPatternsArray(options.ignoreFiles || []); - if (options.gitignore) { - patterns.push(GITIGNORE_PATTERN); + const patterns = ignoreFiles ? toPatternsArray(ignoreFiles) : []; + if (gitignore) { + patterns.push(GITIGNORE_FILE_PATTERN); } return patterns; From 411e85fcfbf96c6e8eb9c0189cb4b55a3d8fa519 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Jan 2022 15:14:16 +0800 Subject: [PATCH 09/17] Glob dot file --- ignore.js | 1 + tests/globby.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/ignore.js b/ignore.js index 651f412..82b48ab 100644 --- a/ignore.js +++ b/ignore.js @@ -14,6 +14,7 @@ const ignoreFilesGlobOptions = { '**/.git', ], absolute: true, + dot: true, }; export const GITIGNORE_FILE_PATTERN = '**/.gitignore'; diff --git a/tests/globby.js b/tests/globby.js index 0d67099..c141c7b 100644 --- a/tests/globby.js +++ b/tests/globby.js @@ -251,6 +251,11 @@ test('respects ignoreFiles array option', async t => { t.false(actual.includes('node_modules')); }); +test('glob dot files', async t => { + const actual = await runGlobby(t, '*', {gitignore: false, ignoreFiles: '*gitignore', onlyFiles: false}); + t.false(actual.includes('node_modules')); +}); + test('`{extension: false}` and `expandDirectories.extensions` option', async t => { for (const temporaryDirectory of getPathValues(temporary)) { t.deepEqual( From bcbcf8bea9f846479dae454fa1fc2d22ae3bf694 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Jan 2022 15:18:16 +0800 Subject: [PATCH 10/17] Rename variable --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index d1b936d..093e881 100644 --- a/index.js +++ b/index.js @@ -62,16 +62,16 @@ const getIgnoreFilesPatterns = options => { }; const getFilter = async options => { - const filePatterns = getIgnoreFilesPatterns(options); + const ignoreFilesPatterns = getIgnoreFilesPatterns(options); return createFilterFunction( - filePatterns.length > 0 && await isIgnored(filePatterns, {cwd: options.cwd}), + ignoreFilesPatterns.length > 0 && await isIgnored(ignoreFilesPatterns, {cwd: options.cwd}), ); }; const getFilterSync = options => { - const filePatterns = getIgnoreFilesPatterns(options); + const ignoreFilesPatterns = getIgnoreFilesPatterns(options); return createFilterFunction( - filePatterns.length > 0 && isIgnoredSync(filePatterns, {cwd: options.cwd}), + ignoreFilesPatterns.length > 0 && isIgnoredSync(ignoreFilesPatterns, {cwd: options.cwd}), ); }; From e2a53e0495d0e2dc394033b1559eb45e6ea32fce Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Jan 2022 15:19:24 +0800 Subject: [PATCH 11/17] Rename variable --- ignore.js | 6 +++--- index.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ignore.js b/ignore.js index 82b48ab..f5f2a2e 100644 --- a/ignore.js +++ b/ignore.js @@ -17,7 +17,7 @@ const ignoreFilesGlobOptions = { dot: true, }; -export const GITIGNORE_FILE_PATTERN = '**/.gitignore'; +export const GITIGNORE_FILES_PATTERN = '**/.gitignore'; const applyBaseToPattern = (pattern, base) => isNegativePattern(pattern) ? '!' + path.posix.join(base, pattern.slice(1)) @@ -88,5 +88,5 @@ export const isIgnoredSync = (patterns, options) => { return getIsIgnoredPredicate(files, cwd); }; -export const isGitIgnored = options => isIgnored(GITIGNORE_FILE_PATTERN, options); -export const isGitIgnoredSync = options => isIgnoredSync(GITIGNORE_FILE_PATTERN, options); +export const isGitIgnored = options => isIgnored(GITIGNORE_FILES_PATTERN, options); +export const isGitIgnoredSync = options => isIgnoredSync(GITIGNORE_FILES_PATTERN, options); diff --git a/index.js b/index.js index 093e881..0668dca 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,7 @@ import fs from 'node:fs'; import merge2 from 'merge2'; import fastGlob from 'fast-glob'; import dirGlob from 'dir-glob'; -import {isIgnored, isIgnoredSync, GITIGNORE_FILE_PATTERN} from './ignore.js'; +import {isIgnored, isIgnoredSync, GITIGNORE_FILES_PATTERN} from './ignore.js'; import {FilterStream, toPath, isNegativePattern} from './utilities.js'; const assertPatternsInput = patterns => { @@ -55,7 +55,7 @@ const getIgnoreFilesPatterns = options => { const patterns = ignoreFiles ? toPatternsArray(ignoreFiles) : []; if (gitignore) { - patterns.push(GITIGNORE_FILE_PATTERN); + patterns.push(GITIGNORE_FILES_PATTERN); } return patterns; From f821c4f33e25418bc9d29873857bde1251e4c956 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Jan 2022 15:29:21 +0800 Subject: [PATCH 12/17] Reduce diff --- ignore.js | 8 ++++---- index.js | 10 +++++++--- tests/ignore.js | 52 ++++++++++++++++++++++++++----------------------- 3 files changed, 39 insertions(+), 31 deletions(-) diff --git a/ignore.js b/ignore.js index f5f2a2e..c6172f9 100644 --- a/ignore.js +++ b/ignore.js @@ -60,7 +60,7 @@ const normalizeOptions = (options = {}) => ({ cwd: toPath(options.cwd) || process.cwd(), }); -export const isIgnored = async (patterns, options) => { +export const isIgnoredByIgnoreFiles = async (patterns, options) => { const {cwd} = normalizeOptions(options); const paths = await fastGlob(patterns, {cwd, ...ignoreFilesGlobOptions}); @@ -75,7 +75,7 @@ export const isIgnored = async (patterns, options) => { return getIsIgnoredPredicate(files, cwd); }; -export const isIgnoredSync = (patterns, options) => { +export const isIgnoredByIgnoreFilesSync = (patterns, options) => { const {cwd} = normalizeOptions(options); const paths = fastGlob.sync(patterns, {cwd, ...ignoreFilesGlobOptions}); @@ -88,5 +88,5 @@ export const isIgnoredSync = (patterns, options) => { return getIsIgnoredPredicate(files, cwd); }; -export const isGitIgnored = options => isIgnored(GITIGNORE_FILES_PATTERN, options); -export const isGitIgnoredSync = options => isIgnoredSync(GITIGNORE_FILES_PATTERN, options); +export const isGitIgnored = options => isIgnoredByIgnoreFiles(GITIGNORE_FILES_PATTERN, options); +export const isGitIgnoredSync = options => isIgnoredByIgnoreFilesSync(GITIGNORE_FILES_PATTERN, options); diff --git a/index.js b/index.js index 0668dca..f7a8000 100644 --- a/index.js +++ b/index.js @@ -2,7 +2,11 @@ import fs from 'node:fs'; import merge2 from 'merge2'; import fastGlob from 'fast-glob'; import dirGlob from 'dir-glob'; -import {isIgnored, isIgnoredSync, GITIGNORE_FILES_PATTERN} from './ignore.js'; +import { + GITIGNORE_FILES_PATTERN, + isIgnoredByIgnoreFiles, + isIgnoredByIgnoreFilesSync, +} from './ignore.js'; import {FilterStream, toPath, isNegativePattern} from './utilities.js'; const assertPatternsInput = patterns => { @@ -64,14 +68,14 @@ const getIgnoreFilesPatterns = options => { const getFilter = async options => { const ignoreFilesPatterns = getIgnoreFilesPatterns(options); return createFilterFunction( - ignoreFilesPatterns.length > 0 && await isIgnored(ignoreFilesPatterns, {cwd: options.cwd}), + ignoreFilesPatterns.length > 0 && await isIgnoredByIgnoreFiles(ignoreFilesPatterns, {cwd: options.cwd}), ); }; const getFilterSync = options => { const ignoreFilesPatterns = getIgnoreFilesPatterns(options); return createFilterFunction( - ignoreFilesPatterns.length > 0 && isIgnoredSync(ignoreFilesPatterns, {cwd: options.cwd}), + ignoreFilesPatterns.length > 0 && isIgnoredByIgnoreFilesSync(ignoreFilesPatterns, {cwd: options.cwd}), ); }; diff --git a/tests/ignore.js b/tests/ignore.js index 1c2b26b..a116940 100644 --- a/tests/ignore.js +++ b/tests/ignore.js @@ -1,19 +1,23 @@ import path from 'node:path'; import test from 'ava'; import slash from 'slash'; -import {isIgnored, isIgnoredSync} from '../ignore.js'; +import { + GITIGNORE_FILES_PATTERN, + isIgnoredByIgnoreFiles, + isIgnoredByIgnoreFilesSync, + isGitIgnored, + isGitIgnoredSync, +} from '../ignore.js'; import { PROJECT_ROOT, getPathValues, } from './utilities.js'; -const gitignorePattern = '**/.gitignore'; - test('ignore', async t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/gitignore'))) { // eslint-disable-next-line no-await-in-loop - const ignored = await isIgnored(gitignorePattern, {cwd}); - const actual = ['foo.js', 'bar.js'].filter(file => !ignored(file)); + const isIgnored = await isGitIgnored({cwd}); + const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); const expected = ['bar.js']; t.deepEqual(actual, expected); } @@ -23,8 +27,8 @@ test('ignore - mixed path styles', async t => { const directory = path.join(PROJECT_ROOT, 'fixtures/gitignore'); for (const cwd of getPathValues(directory)) { // eslint-disable-next-line no-await-in-loop - const ignored = await isIgnored(gitignorePattern, {cwd}); - t.true(ignored(slash(path.resolve(directory, 'foo.js')))); + const isIgnored = await isGitIgnored({cwd}); + t.true(isIgnored(slash(path.resolve(directory, 'foo.js')))); } }); @@ -32,15 +36,15 @@ test('ignore - os paths', async t => { const directory = path.join(PROJECT_ROOT, 'fixtures/gitignore'); for (const cwd of getPathValues(directory)) { // eslint-disable-next-line no-await-in-loop - const ignored = await isIgnored(gitignorePattern, {cwd}); - t.true(ignored(path.resolve(directory, 'foo.js'))); + const isIgnored = await isGitIgnored({cwd}); + t.true(isIgnored(path.resolve(directory, 'foo.js'))); } }); test('ignore - sync', t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/gitignore'))) { - const ignored = isIgnoredSync(gitignorePattern, {cwd}); - const actual = ['foo.js', 'bar.js'].filter(file => !ignored(file)); + const isIgnored = isGitIgnoredSync({cwd}); + const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); const expected = ['bar.js']; t.deepEqual(actual, expected); } @@ -49,8 +53,8 @@ test('ignore - sync', t => { test('negative ignore', async t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/negative'))) { // eslint-disable-next-line no-await-in-loop - const ignored = await isIgnored(gitignorePattern, {cwd}); - const actual = ['foo.js', 'bar.js'].filter(file => !ignored(file)); + const isIgnored = await isGitIgnored({cwd}); + const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); const expected = ['foo.js']; t.deepEqual(actual, expected); } @@ -58,8 +62,8 @@ test('negative ignore', async t => { test('negative ignore - sync', t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/negative'))) { - const ignored = isIgnoredSync(gitignorePattern, {cwd}); - const actual = ['foo.js', 'bar.js'].filter(file => !ignored(file)); + const isIgnored = isGitIgnoredSync({cwd}); + const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); const expected = ['foo.js']; t.deepEqual(actual, expected); } @@ -68,14 +72,14 @@ test('negative ignore - sync', t => { test('multiple negation', async t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/multiple-negation'))) { // eslint-disable-next-line no-await-in-loop - const ignored = await isIgnored(gitignorePattern, {cwd}); + const isIgnored = await isGitIgnored({cwd}); const actual = [ '!!!unicorn.js', '!!unicorn.js', '!unicorn.js', 'unicorn.js', - ].filter(file => !ignored(file)); + ].filter(file => !isIgnored(file)); const expected = ['!!unicorn.js', '!unicorn.js']; t.deepEqual(actual, expected); @@ -84,14 +88,14 @@ test('multiple negation', async t => { test('multiple negation - sync', t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/multiple-negation'))) { - const ignored = isIgnoredSync(gitignorePattern, {cwd}); + const isIgnored = isGitIgnoredSync({cwd}); const actual = [ '!!!unicorn.js', '!!unicorn.js', '!unicorn.js', 'unicorn.js', - ].filter(file => !ignored(file)); + ].filter(file => !isIgnored(file)); const expected = ['!!unicorn.js', '!unicorn.js']; t.deepEqual(actual, expected); @@ -101,15 +105,15 @@ test('multiple negation - sync', t => { test('check file', async t => { const directory = path.join(PROJECT_ROOT, 'fixtures/gitignore'); const ignoredFile = path.join(directory, 'foo.js'); - const ignored = await isIgnored(gitignorePattern, {cwd: directory}); - const ignoredSync = isIgnoredSync(gitignorePattern, {cwd: directory}); + const isIgnored = await isGitIgnored({cwd: directory}); + const isIgnoredSync = isGitIgnoredSync({cwd: directory}); for (const file of getPathValues(ignoredFile)) { - t.true(ignored(file)); - t.true(ignoredSync(file)); + t.true(isIgnored(file)); + t.true(isIgnoredSync(file)); } for (const file of getPathValues(path.join(directory, 'bar.js'))) { - t.false(ignored(file)); + t.false(isIgnored(file)); } }); From 81e91033ed262c2b6072c45ef78cb69903560097 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Jan 2022 15:39:49 +0800 Subject: [PATCH 13/17] Reduce diff --- fixtures/ignore-files/.eslintignore | 1 + fixtures/ignore-files/.prettierignore | 1 + tests/ignore.js | 69 ++++++++++++++++++++++++++- 3 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 fixtures/ignore-files/.eslintignore create mode 100644 fixtures/ignore-files/.prettierignore diff --git a/fixtures/ignore-files/.eslintignore b/fixtures/ignore-files/.eslintignore new file mode 100644 index 0000000..83217a1 --- /dev/null +++ b/fixtures/ignore-files/.eslintignore @@ -0,0 +1 @@ +ignored-by-eslint.js diff --git a/fixtures/ignore-files/.prettierignore b/fixtures/ignore-files/.prettierignore new file mode 100644 index 0000000..074b6c6 --- /dev/null +++ b/fixtures/ignore-files/.prettierignore @@ -0,0 +1 @@ +ignored-by-prettier.js diff --git a/tests/ignore.js b/tests/ignore.js index a116940..1db5f91 100644 --- a/tests/ignore.js +++ b/tests/ignore.js @@ -2,7 +2,6 @@ import path from 'node:path'; import test from 'ava'; import slash from 'slash'; import { - GITIGNORE_FILES_PATTERN, isIgnoredByIgnoreFiles, isIgnoredByIgnoreFilesSync, isGitIgnored, @@ -16,7 +15,7 @@ import { test('ignore', async t => { for (const cwd of getPathValues(path.join(PROJECT_ROOT, 'fixtures/gitignore'))) { // eslint-disable-next-line no-await-in-loop - const isIgnored = await isGitIgnored({cwd}); + const isIgnored = await isGitIgnored({cwd}); const actual = ['foo.js', 'bar.js'].filter(file => !isIgnored(file)); const expected = ['bar.js']; t.deepEqual(actual, expected); @@ -117,3 +116,69 @@ test('check file', async t => { t.false(isIgnored(file)); } }); + +test('custom ignore files - sync', t => { + const cwd = path.join(PROJECT_ROOT, 'fixtures/ignore-files'); + const files = [ + 'ignored-by-eslint.js', + 'ignored-by-prettier.js', + 'not-ignored.js', + ]; + + const isEslintIgnored = isIgnoredByIgnoreFilesSync('.eslintignore', {cwd}); + const isPrettierIgnored = isIgnoredByIgnoreFilesSync('.prettierignore', {cwd}); + const isEslintOrPrettierIgnored = isIgnoredByIgnoreFilesSync('.{prettier,eslint}ignore', {cwd}); + t.deepEqual( + files.filter(file => !isEslintIgnored(file)), + [ + 'ignored-by-prettier.js', + 'not-ignored.js', + ], + ); + t.deepEqual( + files.filter(file => !isPrettierIgnored(file)), + [ + 'ignored-by-eslint.js', + 'not-ignored.js', + ], + ); + t.deepEqual( + files.filter(file => !isEslintOrPrettierIgnored(file)), + [ + 'not-ignored.js', + ], + ); +}); + +test('custom ignore files - async', async t => { + const cwd = path.join(PROJECT_ROOT, 'fixtures/ignore-files'); + const files = [ + 'ignored-by-eslint.js', + 'ignored-by-prettier.js', + 'not-ignored.js', + ]; + + const isEslintIgnored = await isIgnoredByIgnoreFiles('.eslintignore', {cwd}); + const isPrettierIgnored = await isIgnoredByIgnoreFiles('.prettierignore', {cwd}); + const isEslintOrPrettierIgnored = await isIgnoredByIgnoreFiles('.{prettier,eslint}ignore', {cwd}); + t.deepEqual( + files.filter(file => !isEslintIgnored(file)), + [ + 'ignored-by-prettier.js', + 'not-ignored.js', + ], + ); + t.deepEqual( + files.filter(file => !isPrettierIgnored(file)), + [ + 'ignored-by-eslint.js', + 'not-ignored.js', + ], + ); + t.deepEqual( + files.filter(file => !isEslintOrPrettierIgnored(file)), + [ + 'not-ignored.js', + ], + ); +}); From 2192312baf71e34e4f85a28ab0b7785017434b19 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 25 Jan 2022 15:48:30 +0800 Subject: [PATCH 14/17] Refactor tests --- tests/ignore.js | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/ignore.js b/tests/ignore.js index 1db5f91..4153fe8 100644 --- a/tests/ignore.js +++ b/tests/ignore.js @@ -129,23 +129,22 @@ test('custom ignore files - sync', t => { const isPrettierIgnored = isIgnoredByIgnoreFilesSync('.prettierignore', {cwd}); const isEslintOrPrettierIgnored = isIgnoredByIgnoreFilesSync('.{prettier,eslint}ignore', {cwd}); t.deepEqual( - files.filter(file => !isEslintIgnored(file)), + files.filter(file => isEslintIgnored(file)), [ - 'ignored-by-prettier.js', - 'not-ignored.js', + 'ignored-by-eslint.js', ], ); t.deepEqual( - files.filter(file => !isPrettierIgnored(file)), + files.filter(file => isPrettierIgnored(file)), [ - 'ignored-by-eslint.js', - 'not-ignored.js', + 'ignored-by-prettier.js', ], ); t.deepEqual( - files.filter(file => !isEslintOrPrettierIgnored(file)), + files.filter(file => isEslintOrPrettierIgnored(file)), [ - 'not-ignored.js', + 'ignored-by-eslint.js', + 'ignored-by-prettier.js', ], ); }); @@ -162,23 +161,22 @@ test('custom ignore files - async', async t => { const isPrettierIgnored = await isIgnoredByIgnoreFiles('.prettierignore', {cwd}); const isEslintOrPrettierIgnored = await isIgnoredByIgnoreFiles('.{prettier,eslint}ignore', {cwd}); t.deepEqual( - files.filter(file => !isEslintIgnored(file)), + files.filter(file => isEslintIgnored(file)), [ - 'ignored-by-prettier.js', - 'not-ignored.js', + 'ignored-by-eslint.js', ], ); t.deepEqual( - files.filter(file => !isPrettierIgnored(file)), + files.filter(file => isPrettierIgnored(file)), [ - 'ignored-by-eslint.js', - 'not-ignored.js', + 'ignored-by-prettier.js', ], ); t.deepEqual( - files.filter(file => !isEslintOrPrettierIgnored(file)), + files.filter(file => isEslintOrPrettierIgnored(file)), [ - 'not-ignored.js', + 'ignored-by-eslint.js', + 'ignored-by-prettier.js', ], ); }); From aaa6247672e2eb8fc73e0bf02d67784c96f32212 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 25 Jan 2022 17:20:36 +0700 Subject: [PATCH 15/17] Update index.d.ts --- index.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 8c77fa4..b8d817a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -48,7 +48,9 @@ export interface Options extends FastGlobOptionsWithoutCwd { readonly gitignore?: boolean; /** - Glob patterns to look for ignore files, which are then used to ignore globbed files. This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files. + Glob patterns to look for ignore files, which are then used to ignore globbed files. + + This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files. @default undefined */ From cc898f530bd58a8fede8b8f49b57f77f6f2c9b53 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 25 Jan 2022 17:21:32 +0700 Subject: [PATCH 16/17] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 1271172..f601fc6 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,7 @@ Based on [`fast-glob`](https://github.com/mrmlnc/fast-glob) but adds a bunch of - Multiple patterns - Negated patterns: `['foo*', '!foobar']` - Expands directories: `foo` → `foo/**/*` -- Supports `.gitignore`, or any similar ignore file configuration. +- Supports `.gitignore` and similar ignore config files - Supports `URL` as `cwd` ## Install From 6d11ee63d5a0b4f94e5e837d08b8ea07063d26ef Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 25 Jan 2022 17:22:28 +0700 Subject: [PATCH 17/17] Update readme.md --- readme.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index f601fc6..ff36479 100644 --- a/readme.md +++ b/readme.md @@ -93,7 +93,9 @@ Respect ignore patterns in `.gitignore` files that apply to the globbed files. Type: `string | string[]`\ Default: `undefined` -Glob patterns to look for ignore files, which are then used to ignore globbed files. This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files. +Glob patterns to look for ignore files, which are then used to ignore globbed files. + +This is a more generic form of the `gitignore` option, allowing you to find ignore files with a [compatible syntax](http://git-scm.com/docs/gitignore). For instance, this works with Babel's `.babelignore`, Prettier's `.prettierignore`, or ESLint's `.eslintignore` files. ### globbySync(patterns, options?)