-
-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ignoreFiles
option
#172
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This don't have to "takes precedence", we can concat There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The content in readme.md file didn't fix. |
||
|
||
@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; | ||
jridgewell marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
The current working directory in which to search. | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if we want to expose these, if we do, maybe we need a better name, |
||
export const isGitIgnored = options => isIgnored('**/.gitignore', options); | ||
export const isGitIgnoredSync = options => isIgnoredSync('**/.gitignore', options); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"gitignore.js", | ||
"ignore.js", | ||
"utilities.js" | ||
], | ||
"keywords": [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add
dot: true
to the option, when pattern is*ignore
, not sure, need test.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't understand the suggestion.
Added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, if user use
{ignoreFiles: '*ignore'}
, can this glob files starts with.
? See https://github.com/mrmlnc/fast-glob#dotThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally don't find that necessary, and it makes the configuration a little complicated (what if the user didn't want to use dotfiles?). But I'll leave the decision to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a maintainer :)