From 8815ee8ca3cd1a05e52a2a0c0cc15918aa63bce9 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 2 Nov 2018 15:57:32 +0700 Subject: [PATCH] Require Node.js 6 and upgrade dependencies --- fixtures/gitignore/bar.js | 8 +- fixtures/negative/foo.js | 2 +- gitignore.js | 42 ++++++----- index.js | 48 ++++++------ package.json | 149 ++++++++++++++++++++------------------ test.js | 4 +- 6 files changed, 132 insertions(+), 121 deletions(-) diff --git a/fixtures/gitignore/bar.js b/fixtures/gitignore/bar.js index 475628a..c8ab7a0 100644 --- a/fixtures/gitignore/bar.js +++ b/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')); +}); diff --git a/fixtures/negative/foo.js b/fixtures/negative/foo.js index 4728aef..bb9d2a6 100644 --- a/fixtures/negative/foo.js +++ b/fixtures/negative/foo.js @@ -1 +1 @@ -console.log('no semicolon') +console.log('no semicolon'); diff --git a/gitignore.js b/gitignore.js index c491fdc..982834c 100644 --- a/gitignore.js +++ b/gitignore.js @@ -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)); }; @@ -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); }; diff --git a/index.js b/index.js index ff44705..07f073e 100644 --- a/index.js +++ b/index.js @@ -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)) { @@ -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}); @@ -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); } @@ -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 ); }; @@ -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; }; @@ -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; diff --git a/package.json b/package.json index 77bf797..1bbd53e 100644 --- a/package.json +++ b/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" + ] + } } diff --git a/test.js b/test.js index 08b75b5..af7af31 100644 --- a/test.js +++ b/test.js @@ -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(); });