Skip to content
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

Drop support for checking object with path property in function returns by isGitIgnored #208

Merged
merged 3 commits into from Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion gitignore.js
Expand Up @@ -56,7 +56,7 @@ const ensureAbsolutePathForCwd = (cwd, p) => {
return path.join(cwd, p);
};

const getIsIgnoredPredicate = (ignores, cwd) => p => ignores.ignores(slash(path.relative(cwd, ensureAbsolutePathForCwd(cwd, toPath(p.path || p)))));
const getIsIgnoredPredicate = (ignores, cwd) => p => ignores.ignores(slash(path.relative(cwd, ensureAbsolutePathForCwd(cwd, toPath(p)))));

const getFile = async (file, cwd) => {
const filePath = path.join(cwd, file);
Expand Down
2 changes: 0 additions & 2 deletions gitignore.test.js
Expand Up @@ -127,9 +127,7 @@ test('check file', async t => {

for (const file of getPathValues(ignoredFile)) {
t.true(isIgnored(file));
t.true(isIgnored({path: file}));
t.true(isIgnoredSync(file));
t.true(isIgnoredSync({path: file}));
}

for (const file of getPathValues(path.join(directory, 'bar.js'))) {
Expand Down
38 changes: 24 additions & 14 deletions index.js
Expand Up @@ -34,9 +34,9 @@ const checkCwdOption = options => {
}
};

const getPathString = p => p.stats instanceof fs.Stats ? p.path : p;
const getPathString = fastGlobResult => fastGlobResult.path || fastGlobResult;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function mean to handle fastGlobResult, but p.stats is not always true, see objectMode option in fast-glob


export const generateGlobTasks = (patterns, taskOptions = {}) => {
export const generateGlobTasks = (patterns, taskOptions) => {
patterns = arrayUnion([patterns].flat());
assertPatternsInput(patterns);

Expand Down Expand Up @@ -95,9 +95,23 @@ const globDirectories = (task, fn) => {

const getPattern = (task, fn) => task.options.expandDirectories ? globDirectories(task, fn) : [task.pattern];

const getFilterSync = options => options && options.gitignore
? isGitIgnoredSync({cwd: options.cwd, ignore: options.ignore})
: DEFAULT_FILTER;
const getFilter = async options => {
if (!options.gitignore) {
return DEFAULT_FILTER;
}

const filter = await isGitIgnored({cwd: options.cwd, ignore: options.ignore});
return fastGlobResult => filter(getPathString(fastGlobResult));
};

const getFilterSync = options => {
if (!options.gitignore) {
return DEFAULT_FILTER;
}

const filter = isGitIgnoredSync({cwd: options.cwd, ignore: options.ignore});
return fastGlobResult => filter(getPathString(fastGlobResult));
};

const globToTask = task => async glob => {
const {options} = task;
Expand All @@ -123,13 +137,9 @@ const globToTaskSync = task => glob => {
};
};

export const globby = async (patterns, options) => {
export const globby = async (patterns, options = {}) => {
const globTasks = generateGlobTasks(patterns, options);

const getFilter = async () => options && options.gitignore
? isGitIgnored({cwd: options.cwd, ignore: options.ignore})
: DEFAULT_FILTER;

const getTasks = async () => {
const tasks = await Promise.all(globTasks.map(async task => {
const globs = await getPattern(task, dirGlob);
Expand All @@ -139,13 +149,13 @@ export const globby = async (patterns, options) => {
return arrayUnion(...tasks);
};

const [filter, tasks] = await Promise.all([getFilter(), getTasks()]);
const [filter, tasks] = await Promise.all([getFilter(options), getTasks()]);
const paths = await Promise.all(tasks.map(task => fastGlob(task.pattern, task.options)));

return arrayUnion(...paths).filter(path_ => !filter(getPathString(path_)));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter already handles objectMode result, not needed here, globbySync and globbyStream also not doing this.

return arrayUnion(...paths).filter(path_ => !filter(path_));
};

export const globbySync = (patterns, options) => {
export const globbySync = (patterns, options = {}) => {
const globTasks = generateGlobTasks(patterns, options);

const tasks = [];
Expand All @@ -164,7 +174,7 @@ export const globbySync = (patterns, options) => {
return matches.filter(path_ => !filter(path_));
};

export const globbyStream = (patterns, options) => {
export const globbyStream = (patterns, options = {}) => {
const globTasks = generateGlobTasks(patterns, options);

const tasks = [];
Expand Down