Skip to content

Commit

Permalink
Rename the opts property returned from .generateGlobTasks to `opt…
Browse files Browse the repository at this point in the history
…ions`
  • Loading branch information
sindresorhus committed Nov 2, 2018
1 parent 8815ee8 commit c1c744d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
@@ -1,2 +1 @@
* text=auto
*.js text eol=lf
* text=auto eol=lf
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -3,6 +3,6 @@ os:
- osx
language: node_js
node_js:
- '10'
- '8'
- '6'
- '4'
2 changes: 1 addition & 1 deletion appveyor.yml
@@ -1,8 +1,8 @@
environment:
matrix:
- nodejs_version: '10'
- nodejs_version: '8'
- nodejs_version: '6'
- nodejs_version: '4'
install:
- ps: Install-Product node $env:nodejs_version
- npm install --global npm@latest
Expand Down
28 changes: 14 additions & 14 deletions index.js
Expand Up @@ -36,38 +36,38 @@ const generateGlobTasks = (patterns, taskOptions) => {
.filter(isNegative)
.map(pattern => pattern.slice(1));

const opts = Object.assign({}, taskOptions, {
const options = Object.assign({}, taskOptions, {
ignore: taskOptions.ignore.concat(ignore)
});

globTasks.push({pattern, opts});
globTasks.push({pattern, options});
});

return globTasks;
};

const globDirs = (task, fn) => {
let options = {cwd: task.opts.cwd};
let options = {cwd: task.options.cwd};

if (Array.isArray(task.opts.expandDirectories)) {
options = Object.assign(options, {files: task.opts.expandDirectories});
} else if (typeof task.opts.expandDirectories === 'object') {
options = Object.assign(options, task.opts.expandDirectories);
if (Array.isArray(task.options.expandDirectories)) {
options = Object.assign(options, {files: task.options.expandDirectories});
} else if (typeof task.options.expandDirectories === 'object') {
options = Object.assign(options, task.options.expandDirectories);
}

return fn(task.pattern, options);
};

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

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

Expand Down Expand Up @@ -96,7 +96,7 @@ module.exports = (patterns, options) => {
return getFilter()
.then(filter => {
return getTasks
.then(tasks => Promise.all(tasks.map(task => fastGlob(task.pattern, task.opts))))
.then(tasks => Promise.all(tasks.map(task => fastGlob(task.pattern, task.options))))
.then(paths => arrayUnion(...paths))
.then(paths => paths.filter(p => !filter(p)));
});
Expand All @@ -118,7 +118,7 @@ module.exports.sync = (patterns, options) => {

const filter = getFilter();
return tasks.reduce(
(matches, task) => arrayUnion(matches, fastGlob.sync(task.pattern, task.opts)),
(matches, task) => arrayUnion(matches, fastGlob.sync(task.pattern, task.options)),
[]
).filter(p => !filter(p));
};
Expand Down
4 changes: 2 additions & 2 deletions readme.md
@@ -1,4 +1,4 @@
# globby [![Build Status: macOS & Linux](https://travis-ci.org/sindresorhus/globby.svg?branch=master)](https://travis-ci.org/sindresorhus/globby) [![Build status: Windows](https://ci.appveyor.com/api/projects/status/ik0aj9roriqwc5uf/branch/master?svg=true)](https://ci.appveyor.com/project/sindresorhus/globby/branch/master)
# globby [![Build Status: macOS & Linux](https://travis-ci.com/sindresorhus/globby.svg?branch=master)](https://travis-ci.com/sindresorhus/globby) [![Build status: Windows](https://ci.appveyor.com/api/projects/status/ik0aj9roriqwc5uf/branch/master?svg=true)](https://ci.appveyor.com/project/sindresorhus/globby/branch/master)

> User-friendly glob matching
Expand Down Expand Up @@ -95,7 +95,7 @@ Returns an `Array` of matching paths.

### globby.generateGlobTasks(patterns, [options])

Returns an `Array<Object>` in the format `{pattern: string, opts: Object}`, which can be passed as arguments to [`fast-glob`](https://github.com/mrmlnc/fast-glob). This is useful for other globbing-related packages.
Returns an `Array<Object>` in the format `{pattern: string, options: Object}`, which can be passed as arguments to [`fast-glob`](https://github.com/mrmlnc/fast-glob). This is useful for other globbing-related packages.

Note that you should avoid running the same tasks multiple times as they contain a file system cache. Instead, run this method each time to ensure file system changes are taken into consideration.

Expand Down
2 changes: 1 addition & 1 deletion test.js
Expand Up @@ -88,7 +88,7 @@ test('expose generateGlobTasks', t => {

t.is(tasks.length, 1);
t.is(tasks[0].pattern, '*.tmp');
t.deepEqual(tasks[0].opts.ignore, ['c.tmp', 'b.tmp']);
t.deepEqual(tasks[0].options.ignore, ['c.tmp', 'b.tmp']);
});

test('expose hasMagic', t => {
Expand Down

0 comments on commit c1c744d

Please sign in to comment.