From cd3e13d8f9f02a700952fcfa82698cab43d9b203 Mon Sep 17 00:00:00 2001 From: Mario Nebl Date: Sun, 19 Nov 2017 11:10:10 +0100 Subject: [PATCH 1/8] Expose gitignore implementation (#56) --- index.js | 2 ++ readme.md | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/index.js b/index.js index f6a57d1..faa1152 100644 --- a/index.js +++ b/index.js @@ -130,3 +130,5 @@ module.exports.generateGlobTasks = generateGlobTasks; module.exports.hasMagic = (patterns, opts) => [] .concat(patterns) .some(pattern => glob.hasMagic(pattern, opts)); + +module.exports.gitignore = gitignore; diff --git a/readme.md b/readme.md index 410952c..cfb0d93 100644 --- a/readme.md +++ b/readme.md @@ -63,6 +63,26 @@ Returns a `boolean` of whether there are any special glob characters in the `pat Note that the options affect the results. If `noext: true` is set, then `+(a|b)` will not be considered a magic pattern. If the pattern has a brace expansion, like `a/{b/c,x/y}`, then that is considered magical, unless `nobrace: true` is set. +### globby.gitignore(options) + +Returns a `Promise<(path: string) => boolean>` indicating wether a given path is ignored via a `.gitignore` file. + +Takes `cwd?: string` and `ignore?: string[]` as options. `.gitignore` files matched by the ignore config are not +used for the resulting filter function. + +```js +const gitignore = require('globby').gitignore; + +gitignore({}) + .then((isIgnored) => { + const ignored = isIgnored('some/file'); + }) +``` + +### globby.gitignore.sync(options) + +Returns a `(path: string) => boolean` indicating wether a given path is ignored via a `.gitignore` file. + #### patterns Type: `string` `Array` From 745d342e4d9f1c7a6ce2b35015243d5a65a26ceb Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 19 Nov 2017 17:15:53 +0700 Subject: [PATCH 2/8] Readme tweaks --- gitignore.js | 1 + readme.md | 74 +++++++++++++++++++++++++++------------------------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/gitignore.js b/gitignore.js index cebce0b..53fd311 100644 --- a/gitignore.js +++ b/gitignore.js @@ -63,6 +63,7 @@ const getFileSync = (file, cwd) => { }; const normalizeOpts = opts => { + opts = opts || {}; const ignore = opts.ignore || []; const cwd = opts.cwd || process.cwd(); return {ignore, cwd}; diff --git a/readme.md b/readme.md index cfb0d93..0143a7c 100644 --- a/readme.md +++ b/readme.md @@ -47,42 +47,6 @@ const globby = require('globby'); Returns a `Promise` of matching paths. -### globby.sync(patterns, [options]) - -Returns an `Array` of matching paths. - -### globby.generateGlobTasks(patterns, [options]) - -Returns an `Array` in the format `{pattern: string, opts: Object}`, which can be passed as arguments to [`node-glob`](https://github.com/isaacs/node-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. - -### globby.hasMagic(patterns, [options]) - -Returns a `boolean` of whether there are any special glob characters in the `patterns`. - -Note that the options affect the results. If `noext: true` is set, then `+(a|b)` will not be considered a magic pattern. If the pattern has a brace expansion, like `a/{b/c,x/y}`, then that is considered magical, unless `nobrace: true` is set. - -### globby.gitignore(options) - -Returns a `Promise<(path: string) => boolean>` indicating wether a given path is ignored via a `.gitignore` file. - -Takes `cwd?: string` and `ignore?: string[]` as options. `.gitignore` files matched by the ignore config are not -used for the resulting filter function. - -```js -const gitignore = require('globby').gitignore; - -gitignore({}) - .then((isIgnored) => { - const ignored = isIgnored('some/file'); - }) -``` - -### globby.gitignore.sync(options) - -Returns a `(path: string) => boolean` indicating wether a given path is ignored via a `.gitignore` file. - #### patterns Type: `string` `Array` @@ -127,6 +91,44 @@ Default: `false` Respect ignore patterns in `.gitignore` files that apply to the globbed files. +### globby.sync(patterns, [options]) + +Returns an `Array` of matching paths. + +### globby.generateGlobTasks(patterns, [options]) + +Returns an `Array` in the format `{pattern: string, opts: Object}`, which can be passed as arguments to [`node-glob`](https://github.com/isaacs/node-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. + +### globby.hasMagic(patterns, [options]) + +Returns a `boolean` of whether there are any special glob characters in the `patterns`. + +Note that the options affect the results. If `noext: true` is set, then `+(a|b)` will not be considered a magic pattern. If the pattern has a brace expansion, like `a/{b/c,x/y}`, then that is considered magical, unless `nobrace: true` is set. + +### globby.gitignore([options]) + +Returns a `Promise<(path: string) => boolean>` indicating wether a given path is ignored via a `.gitignore` file. + +Takes `cwd?: string` and `ignore?: string[]` as options. `.gitignore` files matched by the ignore config are not +used for the resulting filter function. + +```js +const {gitignore} = require('globby'); + +(async () => { + const isIgnored = await gitignore(); + console.log(isIgnored('some/file')); +})(); +``` + +### globby.gitignore.sync([options]) + +Returns a `(path: string) => boolean` indicating wether a given path is ignored via a `.gitignore` file. + +Takes the same options as `globby.gitignore`. + ## Globbing patterns From 1c010918fe32f63c623b45ae356991ed255abc5f Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 19 Nov 2017 17:17:39 +0700 Subject: [PATCH 3/8] 7.1.0 --- package.json | 144 +++++++++++++++++++++++++-------------------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/package.json b/package.json index 832a6f2..10ca748 100644 --- a/package.json +++ b/package.json @@ -1,74 +1,74 @@ { - "name": "globby", - "version": "7.0.0", - "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", - "glob": "^7.1.2", - "ignore": "^3.3.5", - "pify": "^3.0.0", - "slash": "^1.0.0" - }, - "devDependencies": { - "ava": "*", - "fast-glob": "^1.0.1", - "glob-stream": "^6.1.0", - "globby": "sindresorhus/globby#master", - "matcha": "^0.7.0", - "rimraf": "^2.2.8", - "xo": "^0.18.0" - } + "name": "globby", + "version": "7.1.0", + "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", + "glob": "^7.1.2", + "ignore": "^3.3.5", + "pify": "^3.0.0", + "slash": "^1.0.0" + }, + "devDependencies": { + "ava": "*", + "fast-glob": "^1.0.1", + "glob-stream": "^6.1.0", + "globby": "sindresorhus/globby#master", + "matcha": "^0.7.0", + "rimraf": "^2.2.8", + "xo": "^0.18.0" + } } From 176d6a24232805323702c7104be6cc95d73393ee Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 19 Nov 2017 17:48:31 +0700 Subject: [PATCH 4/8] Fix using multiple non-glob file patterns Fixes #54 --- index.js | 10 +++++----- test.js | 8 ++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index faa1152..a6b63f0 100644 --- a/index.js +++ b/index.js @@ -109,13 +109,13 @@ module.exports.sync = (patterns, opts) => { DEFAULT_FILTER; }; - const tasks = globTasks.reduce( - (tasks, task) => arrayUnion(getPattern(task, dirGlob.sync).map(glob => ({ + const tasks = globTasks.reduce((tasks, task) => { + const newTask = getPattern(task, dirGlob.sync).map(glob => ({ pattern: glob, opts: task.opts - }))), - [] - ); + })); + return tasks.concat(newTask); + }, []); const filter = getFilter(); diff --git a/test.js b/test.js index c02572f..36c3e94 100644 --- a/test.js +++ b/test.js @@ -30,6 +30,10 @@ test('glob - async', async t => { t.deepEqual(await m('*.tmp'), ['a.tmp', 'b.tmp', 'c.tmp', 'd.tmp', 'e.tmp']); }); +test('glob - async - multiple file paths', t => { + t.deepEqual(m.sync(['a.tmp', 'b.tmp']), ['a.tmp', 'b.tmp']); +}); + test('glob with multiple patterns - async', async t => { t.deepEqual(await m(['a.tmp', '*.tmp', '!{c,d,e}.tmp']), ['a.tmp', 'b.tmp']); }); @@ -44,6 +48,10 @@ test('glob - sync', t => { t.deepEqual(m.sync(['!*.tmp', 'a.tmp']), ['a.tmp']); }); +test('glob - sync - multiple file paths', t => { + t.deepEqual(m.sync(['a.tmp', 'b.tmp']), ['a.tmp', 'b.tmp']); +}); + test('return [] for all negative patterns - sync', t => { t.deepEqual(m.sync(['!a.tmp', '!b.tmp']), []); }); From 9bf9983bca42c2176657a2084608bd6fca417258 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sun, 19 Nov 2017 17:50:11 +0700 Subject: [PATCH 5/8] 7.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 10ca748..ad1e78d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "globby", - "version": "7.1.0", + "version": "7.1.1", "description": "Extends `glob` with support for multiple patterns and exposes a Promise API", "license": "MIT", "repository": "sindresorhus/globby", From bc03c669fcfe44a51602cf3db867a98693693b25 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 20 Nov 2017 22:17:18 +0700 Subject: [PATCH 6/8] Add a test --- test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test.js b/test.js index 36c3e94..1f449cd 100644 --- a/test.js +++ b/test.js @@ -109,6 +109,11 @@ test('expandDirectories option', t => { }), ['tmp/a.tmp']); }); +test('expandDirectories:true and nodir:true option', t => { + t.deepEqual(m.sync('tmp', {nodir: true}), ['tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']); + t.deepEqual(m.sync('tmp', {nodir: false}), ['tmp', 'tmp/a.tmp', 'tmp/b.tmp', 'tmp/c.tmp', 'tmp/d.tmp', 'tmp/e.tmp']); +}); + // Rejected for being an invalid pattern [ {}, From 8b4ea64492e0232aec20ad30d648ef677542581a Mon Sep 17 00:00:00 2001 From: Thomas Broadley Date: Fri, 15 Dec 2017 19:09:24 -0500 Subject: [PATCH 7/8] Fix typos (#60) --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 0143a7c..3d3bcc3 100644 --- a/readme.md +++ b/readme.md @@ -109,7 +109,7 @@ Note that the options affect the results. If `noext: true` is set, then `+(a|b)` ### globby.gitignore([options]) -Returns a `Promise<(path: string) => boolean>` indicating wether a given path is ignored via a `.gitignore` file. +Returns a `Promise<(path: string) => boolean>` indicating whether a given path is ignored via a `.gitignore` file. Takes `cwd?: string` and `ignore?: string[]` as options. `.gitignore` files matched by the ignore config are not used for the resulting filter function. @@ -125,7 +125,7 @@ const {gitignore} = require('globby'); ### globby.gitignore.sync([options]) -Returns a `(path: string) => boolean` indicating wether a given path is ignored via a `.gitignore` file. +Returns a `(path: string) => boolean` indicating whether a given path is ignored via a `.gitignore` file. Takes the same options as `globby.gitignore`. From c8574aeb0b869e21d59fd6fe5c974c9604d0a43b Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 22 Jan 2018 18:20:26 +0100 Subject: [PATCH 8/8] Update benchmark dependency --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ad1e78d..411a0cb 100644 --- a/package.json +++ b/package.json @@ -64,7 +64,7 @@ }, "devDependencies": { "ava": "*", - "fast-glob": "^1.0.1", + "fast-glob": "^2.0.1", "glob-stream": "^6.1.0", "globby": "sindresorhus/globby#master", "matcha": "^0.7.0",