Skip to content

Commit

Permalink
Fix expandDirectories and ignores option working together (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-alvarez authored and sindresorhus committed Nov 2, 2018
1 parent c16058c commit 84632f1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
22 changes: 13 additions & 9 deletions index.js
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
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

0 comments on commit 84632f1

Please sign in to comment.