Skip to content

Commit

Permalink
Require Node.js 6 and upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 2, 2018
1 parent 84632f1 commit 8815ee8
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 121 deletions.
8 changes: 4 additions & 4 deletions fixtures/gitignore/bar.js
@@ -1,6 +1,6 @@
import test from 'ava'
import fn from '..'
import test from 'ava';
import fn from '..';

test(t => {
t.is(fn('foo'), fn('foobar'))
})
t.is(fn('foo'), fn('foobar'));
});
2 changes: 1 addition & 1 deletion fixtures/negative/foo.js
@@ -1 +1 @@
console.log('no semicolon')
console.log('no semicolon');
42 changes: 24 additions & 18 deletions gitignore.js
Expand Up @@ -18,19 +18,19 @@ const readFileP = pify(fs.readFile);

const mapGitIgnorePatternTo = base => ignore => {
if (ignore.startsWith('!')) {
return '!' + path.posix.join(base, ignore.substr(1));
return '!' + path.posix.join(base, ignore.slice(1));
}

return path.posix.join(base, ignore);
};

const parseGitIgnore = (content, opts) => {
const base = slash(path.relative(opts.cwd, path.dirname(opts.fileName)));
const parseGitIgnore = (content, options) => {
const base = slash(path.relative(options.cwd, path.dirname(options.fileName)));

return content
.split(/\r?\n/)
.filter(Boolean)
.filter(l => l.charAt(0) !== '#')
.filter(line => line.charAt(0) !== '#')
.map(mapGitIgnorePatternTo(base));
};

Expand Down Expand Up @@ -69,27 +69,33 @@ const getFileSync = (file, cwd) => {
};
};

const normalizeOpts = opts => {
opts = opts || {};
const ignore = opts.ignore || [];
const cwd = opts.cwd || process.cwd();
const normalizeOptions = (options = {}) => {
const ignore = options.ignore || [];
const cwd = options.cwd || process.cwd();
return {ignore, cwd};
};

module.exports = o => {
const opts = normalizeOpts(o);
module.exports = options => {
options = normalizeOptions(options);

return fastGlob('**/.gitignore', {ignore: DEFAULT_IGNORE.concat(opts.ignore), cwd: opts.cwd})
.then(paths => Promise.all(paths.map(file => getFile(file, opts.cwd))))
return fastGlob('**/.gitignore', {
ignore: DEFAULT_IGNORE.concat(options.ignore),
cwd: options.cwd
})
.then(paths => Promise.all(paths.map(file => getFile(file, options.cwd))))
.then(files => reduceIgnore(files))
.then(ignores => getIsIgnoredPredecate(ignores, opts.cwd));
.then(ignores => getIsIgnoredPredecate(ignores, options.cwd));
};

module.exports.sync = o => {
const opts = normalizeOpts(o);
module.exports.sync = options => {
options = normalizeOptions(options);

const paths = fastGlob.sync('**/.gitignore', {ignore: DEFAULT_IGNORE.concat(opts.ignore), cwd: opts.cwd});
const files = paths.map(file => getFileSync(file, opts.cwd));
const paths = fastGlob.sync('**/.gitignore', {
ignore: DEFAULT_IGNORE.concat(options.ignore),
cwd: options.cwd
});
const files = paths.map(file => getFileSync(file, options.cwd));
const ignores = reduceIgnore(files);
return getIsIgnoredPredecate(ignores, opts.cwd);

return getIsIgnoredPredecate(ignores, options.cwd);
};
48 changes: 24 additions & 24 deletions index.js
Expand Up @@ -15,16 +15,16 @@ const assertPatternsInput = patterns => {
}
};

const generateGlobTasks = (patterns, taskOpts) => {
const generateGlobTasks = (patterns, taskOptions) => {
patterns = [].concat(patterns);
assertPatternsInput(patterns);

const globTasks = [];

taskOpts = Object.assign({
taskOptions = Object.assign({
ignore: [],
expandDirectories: true
}, taskOpts);
}, taskOptions);

patterns.forEach((pattern, i) => {
if (isNegative(pattern)) {
Expand All @@ -36,8 +36,8 @@ const generateGlobTasks = (patterns, taskOpts) => {
.filter(isNegative)
.map(pattern => pattern.slice(1));

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

globTasks.push({pattern, opts});
Expand All @@ -47,21 +47,21 @@ const generateGlobTasks = (patterns, taskOpts) => {
};

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

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

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

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

const globToTask = task => glob => {
const opts = task.opts;
const {opts} = task;
if (opts.ignore && Array.isArray(opts.ignore) && opts.expandDirectories) {
opts.ignore = dirGlob.sync(opts.ignore);
}
Expand All @@ -71,24 +71,24 @@ const globToTask = task => glob => {
};
};

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

try {
globTasks = generateGlobTasks(patterns, opts);
} catch (err) {
return Promise.reject(err);
globTasks = generateGlobTasks(patterns, options);
} catch (error) {
return Promise.reject(error);
}

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

const getFilter = () => {
return Promise.resolve(
opts && opts.gitignore ?
gitignore({cwd: opts.cwd, ignore: opts.ignore}) :
options && options.gitignore ?
gitignore({cwd: options.cwd, ignore: options.ignore}) :
DEFAULT_FILTER
);
};
Expand All @@ -97,17 +97,17 @@ module.exports = (patterns, opts) => {
.then(filter => {
return getTasks
.then(tasks => Promise.all(tasks.map(task => fastGlob(task.pattern, task.opts))))
.then(paths => arrayUnion.apply(null, paths))
.then(paths => arrayUnion(...paths))
.then(paths => paths.filter(p => !filter(p)));
});
};

module.exports.sync = (patterns, opts) => {
const globTasks = generateGlobTasks(patterns, opts);
module.exports.sync = (patterns, options) => {
const globTasks = generateGlobTasks(patterns, options);

const getFilter = () => {
return opts && opts.gitignore ?
gitignore.sync({cwd: opts.cwd, ignore: opts.ignore}) :
return options && options.gitignore ?
gitignore.sync({cwd: options.cwd, ignore: options.ignore}) :
DEFAULT_FILTER;
};

Expand All @@ -125,8 +125,8 @@ module.exports.sync = (patterns, opts) => {

module.exports.generateGlobTasks = generateGlobTasks;

module.exports.hasMagic = (patterns, opts) => []
module.exports.hasMagic = (patterns, options) => []
.concat(patterns)
.some(pattern => glob.hasMagic(pattern, opts));
.some(pattern => glob.hasMagic(pattern, options));

module.exports.gitignore = gitignore;
149 changes: 77 additions & 72 deletions package.json
@@ -1,74 +1,79 @@
{
"name": "globby",
"version": "8.0.1",
"description": "Extends `glob` with support for multiple patterns and exposes a Promise API",
"license": "MIT",
"repository": "sindresorhus/globby",
"author": {
"email": "sindresorhus@gmail.com",
"name": "Sindre Sorhus",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=4"
},
"scripts": {
"bench": "npm update glob-stream fast-glob && matcha bench.js",
"test": "xo && ava"
},
"files": [
"index.js",
"gitignore.js"
],
"keywords": [
"all",
"array",
"directories",
"dirs",
"expand",
"files",
"filesystem",
"filter",
"find",
"fnmatch",
"folders",
"fs",
"glob",
"globbing",
"globs",
"gulpfriendly",
"match",
"matcher",
"minimatch",
"multi",
"multiple",
"paths",
"pattern",
"patterns",
"traverse",
"util",
"utility",
"wildcard",
"wildcards",
"promise",
"gitignore",
"git"
],
"dependencies": {
"array-union": "^1.0.1",
"dir-glob": "^2.0.0",
"fast-glob": "^2.0.2",
"glob": "^7.1.2",
"ignore": "^3.3.5",
"pify": "^3.0.0",
"slash": "^1.0.0"
},
"devDependencies": {
"ava": "*",
"glob-stream": "^6.1.0",
"globby": "sindresorhus/globby#master",
"matcha": "^0.7.0",
"rimraf": "^2.2.8",
"xo": "^0.18.0"
}
"name": "globby",
"version": "8.0.1",
"description": "Extends `glob` with support for multiple patterns and exposes a Promise API",
"license": "MIT",
"repository": "sindresorhus/globby",
"author": {
"email": "sindresorhus@gmail.com",
"name": "Sindre Sorhus",
"url": "sindresorhus.com"
},
"engines": {
"node": ">=6"
},
"scripts": {
"bench": "npm update glob-stream fast-glob && matcha bench.js",
"test": "xo && ava"
},
"files": [
"index.js",
"gitignore.js"
],
"keywords": [
"all",
"array",
"directories",
"dirs",
"expand",
"files",
"filesystem",
"filter",
"find",
"fnmatch",
"folders",
"fs",
"glob",
"globbing",
"globs",
"gulpfriendly",
"match",
"matcher",
"minimatch",
"multi",
"multiple",
"paths",
"pattern",
"patterns",
"traverse",
"util",
"utility",
"wildcard",
"wildcards",
"promise",
"gitignore",
"git"
],
"dependencies": {
"array-union": "^1.0.2",
"dir-glob": "^2.0.0",
"fast-glob": "^2.2.3",
"glob": "^7.1.3",
"ignore": "^4.0.3",
"pify": "^4.0.1",
"slash": "^2.0.0"
},
"devDependencies": {
"ava": "^0.25.0",
"glob-stream": "^6.1.0",
"globby": "sindresorhus/globby#master",
"matcha": "^0.7.0",
"rimraf": "^2.2.8",
"xo": "^0.23.0"
},
"xo": {
"ignores": [
"fixtures"
]
}
}
4 changes: 2 additions & 2 deletions test.js
Expand Up @@ -73,12 +73,12 @@ test('cwd option', t => {
process.chdir(cwd);
});

test(`don't mutate the options object - async`, async t => {
test('don\'t mutate the options object - async', async t => {
await m(['*.tmp', '!b.tmp'], Object.freeze({ignore: Object.freeze([])}));
t.pass();
});

test(`don't mutate the options object - sync`, t => {
test('don\'t mutate the options object - sync', t => {
m.sync(['*.tmp', '!b.tmp'], Object.freeze({ignore: Object.freeze([])}));
t.pass();
});
Expand Down

0 comments on commit 8815ee8

Please sign in to comment.