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

Fix expandDirectories and ignores option working together #88

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ const globDirs = (task, fn) => {

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

const globToTask = task => glob => {
const opts = task.opts;
if (opts.ignore && Array.isArray(opts.ignore) && opts.expandDirectories) {
opts.ignore = dirGlob.sync(opts.ignore);
}
return {
pattern: glob,
opts: task.opts
};
};

module.exports = (patterns, opts) => {
let globTasks;

Expand All @@ -70,10 +81,7 @@ module.exports = (patterns, opts) => {
}

const getTasks = Promise.all(globTasks.map(task => Promise.resolve(getPattern(task, dirGlob))
.then(globs => Promise.all(globs.map(glob => ({
pattern: glob,
opts: task.opts
}))))
.then(globs => Promise.all(globs.map(globToTask(task))))
))
.then(tasks => arrayUnion.apply(null, tasks));

Expand Down Expand Up @@ -104,15 +112,11 @@ module.exports.sync = (patterns, opts) => {
};

const tasks = globTasks.reduce((tasks, task) => {
const newTask = getPattern(task, dirGlob.sync).map(glob => ({
pattern: glob,
opts: task.opts
}));
const newTask = getPattern(task, dirGlob.sync).map(globToTask(task));
return tasks.concat(newTask);
}, []);

const filter = getFilter();

return tasks.reduce(
(matches, task) => arrayUnion(matches, fastGlob.sync(task.pattern, task.opts)),
[]
Expand Down
11 changes: 10 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ test.failing('expandDirectories:true and onlyFiles:false option', t => {
t.deepEqual(m.sync(tmp, {onlyFiles: false}), ['tmp', 'tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']);
});

test.failing('expandDirectories and ignores option', t => {
test('expandDirectories and ignores option', t => {
t.deepEqual(m.sync('tmp', {
ignore: ['tmp']
}), []);
Expand All @@ -138,6 +138,15 @@ test.failing('expandDirectories and ignores option', t => {
}), ['tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']);
});

test.failing('relative paths and ignores option', t => {
process.chdir(tmp);
t.deepEqual(m.sync('../tmp', {
cwd: process.cwd(),
ignore: ['tmp']
}), []);
process.chdir(cwd);
});

// Rejected for being an invalid pattern
[
{},
Expand Down