Skip to content

Commit

Permalink
Drop support for checking object with path property in function ret…
Browse files Browse the repository at this point in the history
…urns by `isGitIgnored` (#208)
  • Loading branch information
fisker committed Jan 17, 2022
1 parent fc653c7 commit 7833ad5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
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;

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_)));
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

0 comments on commit 7833ad5

Please sign in to comment.