-
-
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,32 @@ 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 getIgnoreFilesPatterns = options => { | ||
if (!options) { | ||
return []; | ||
} | ||
|
||
const getFilterSync = options => createFilterFunction( | ||
options.gitignore && isGitIgnoredSync({cwd: options.cwd}), | ||
); | ||
const patterns = toPatternsArray(options.ignoreFiles || []); | ||
if (options.gitignore) { | ||
patterns.push('**/.gitignore'); | ||
} | ||
|
||
return patterns; | ||
}; | ||
|
||
const getFilter = async options => { | ||
const filePatterns = getIgnoreFilesPatterns(options); | ||
return createFilterFunction( | ||
filePatterns.length > 0 && await isIgnored(filePatterns, {cwd: options.cwd}), | ||
); | ||
}; | ||
|
||
const getFilterSync = options => { | ||
const filePatterns = getIgnoreFilesPatterns(options); | ||
return createFilterFunction( | ||
filePatterns.length > 0 && isIgnoredSync(filePatterns, {cwd: options.cwd}), | ||
); | ||
}; | ||
|
||
const createFilterFunction = isIgnored => { | ||
const seen = new Set(); | ||
|
@@ -200,7 +219,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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 :)