diff options
author | Forrest L Norvell <forrest@npmjs.com> | 2015-02-20 19:16:42 +0300 |
---|---|---|
committer | Forrest L Norvell <forrest@npmjs.com> | 2015-02-20 19:16:42 +0300 |
commit | 0fe0caa7eddb7acdacbe5ee81ceabaca27175c78 (patch) | |
tree | 0ef2efcd11cb37fef5fa9ba7af8a56f00092b00e /node_modules/glob | |
parent | aa791942a9f3c8af6a650edec72a675deb7a7c6e (diff) |
glob@4.4.0
Adds ignoring matches.
Diffstat (limited to 'node_modules/glob')
-rw-r--r-- | node_modules/glob/README.md | 1 | ||||
-rw-r--r-- | node_modules/glob/common.js | 55 | ||||
-rw-r--r-- | node_modules/glob/glob.js | 6 | ||||
-rw-r--r-- | node_modules/glob/package.json | 21 | ||||
-rw-r--r-- | node_modules/glob/sync.js | 6 |
5 files changed, 77 insertions, 12 deletions
diff --git a/node_modules/glob/README.md b/node_modules/glob/README.md index e479ae29e..ba95474c2 100644 --- a/node_modules/glob/README.md +++ b/node_modules/glob/README.md @@ -264,6 +264,7 @@ filesystem. * `nocomment` Suppress `comment` behavior. (See below.) * `nonull` Return the pattern when no matches are found. * `nodir` Do not match directories, only files. +* `ignore` Add a pattern or an array of patterns to exclude matches. ## Comparisons to other fnmatch/glob implementations diff --git a/node_modules/glob/common.js b/node_modules/glob/common.js index 610d1245b..491b9730b 100644 --- a/node_modules/glob/common.js +++ b/node_modules/glob/common.js @@ -6,6 +6,8 @@ exports.ownProp = ownProp exports.makeAbs = makeAbs exports.finish = finish exports.mark = mark +exports.isIgnored = isIgnored +exports.childrenIgnored = childrenIgnored function ownProp (obj, field) { return Object.prototype.hasOwnProperty.call(obj, field) @@ -41,6 +43,29 @@ function alphasort (a, b) { return a.localeCompare(b) } +function setupIgnores (self, options) { + self.ignore = options.ignore || [] + + if (!Array.isArray(self.ignore)) + self.ignore = [self.ignore] + + if (self.ignore.length) { + self.ignore = self.ignore.map(ignoreMap) + } +} + +function ignoreMap (pattern) { + var gmatcher = null + if (pattern.slice(-3) === '/**') { + var gpattern = pattern.replace(/(\/\*\*)+$/, '') + gmatcher = new Minimatch(gpattern, { nonegate: true }) + } + + return { + matcher: new Minimatch(pattern, { nonegate: true }), + gmatcher: gmatcher + } +} function setopts (self, pattern, options) { if (!options) @@ -74,6 +99,8 @@ function setopts (self, pattern, options) { self.statCache = options.statCache || Object.create(null) self.symlinks = options.symlinks || Object.create(null) + setupIgnores(self, options) + self.changedCwd = false var cwd = process.cwd() if (!ownProp(options, "cwd")) @@ -139,6 +166,11 @@ function finish (self) { } } + if (self.ignore.length) + all = all.filter(function(m) { + return !isIgnored(self, m) + }) + self.found = all } @@ -166,7 +198,7 @@ function mark (self, p) { // lotta situps... function makeAbs (self, f) { var abs = f - if (f.charAt(0) === "/") { + if (f.charAt(0) === '/') { abs = path.join(self.root, f) } else if (exports.isAbsolute(f)) { abs = f @@ -175,3 +207,24 @@ function makeAbs (self, f) { } return abs } + + +// Return true, if pattern ends with globstar '**', for the accompanying parent directory. +// Ex:- If node_modules/** is the pattern, add 'node_modules' to ignore list along with it's contents +function isIgnored (self, path) { + if (!self.ignore.length) + return false + + return self.ignore.some(function(item) { + return item.matcher.match(path) || !!(item.gmatcher && item.gmatcher.match(path)) + }) +} + +function childrenIgnored (self, path) { + if (!self.ignore.length) + return false + + return self.ignore.some(function(item) { + return !!(item.gmatcher && item.gmatcher.match(path)) + }) +} diff --git a/node_modules/glob/glob.js b/node_modules/glob/glob.js index 7401e0b7e..0075c1fb8 100644 --- a/node_modules/glob/glob.js +++ b/node_modules/glob/glob.js @@ -56,6 +56,7 @@ var setopts = common.setopts var ownProp = common.ownProp var inflight = require('inflight') var util = require('util') +var childrenIgnored = common.childrenIgnored var once = require('once') @@ -270,6 +271,10 @@ Glob.prototype._process = function (pattern, index, inGlobStar, cb) { var abs = this._makeAbs(read) + //if ignored, skip _processing + if (childrenIgnored(this, read)) + return cb() + var isGlobStar = remain[0] === minimatch.GLOBSTAR if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb) @@ -277,7 +282,6 @@ Glob.prototype._process = function (pattern, index, inGlobStar, cb) { this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb) } - Glob.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar, cb) { var self = this this._readdir(abs, inGlobStar, function (er, entries) { diff --git a/node_modules/glob/package.json b/node_modules/glob/package.json index 5b782d625..c5032684b 100644 --- a/node_modules/glob/package.json +++ b/node_modules/glob/package.json @@ -6,7 +6,7 @@ }, "name": "glob", "description": "a little globber", - "version": "4.3.5", + "version": "4.4.0", "repository": { "type": "git", "url": "git://github.com/isaacs/node-glob.git" @@ -42,16 +42,16 @@ "benchclean": "bash benchclean.sh" }, "license": "ISC", - "gitHead": "9de4cb6bfeb9c8458cf188fe91447b99bf8f3cfd", + "gitHead": "57e6b293108b48d9771a05e2b9a6a1b12cb81c12", "bugs": { "url": "https://github.com/isaacs/node-glob/issues" }, "homepage": "https://github.com/isaacs/node-glob", - "_id": "glob@4.3.5", - "_shasum": "80fbb08ca540f238acce5d11d1e9bc41e75173d3", - "_from": "glob@>=4.3.5 <4.4.0", - "_npmVersion": "2.2.0", - "_nodeVersion": "0.10.35", + "_id": "glob@4.4.0", + "_shasum": "91d63dc1ed1d82b52ba2cb76044852ccafc2130f", + "_from": "glob@>=4.4.0 <4.5.0", + "_npmVersion": "2.6.0", + "_nodeVersion": "1.1.0", "_npmUser": { "name": "isaacs", "email": "i@izs.me" @@ -63,9 +63,10 @@ } ], "dist": { - "shasum": "80fbb08ca540f238acce5d11d1e9bc41e75173d3", - "tarball": "http://registry.npmjs.org/glob/-/glob-4.3.5.tgz" + "shasum": "91d63dc1ed1d82b52ba2cb76044852ccafc2130f", + "tarball": "http://registry.npmjs.org/glob/-/glob-4.4.0.tgz" }, "directories": {}, - "_resolved": "https://registry.npmjs.org/glob/-/glob-4.3.5.tgz" + "_resolved": "https://registry.npmjs.org/glob/-/glob-4.4.0.tgz", + "readme": "ERROR: No README data found!" } diff --git a/node_modules/glob/sync.js b/node_modules/glob/sync.js index f981055af..686f2c369 100644 --- a/node_modules/glob/sync.js +++ b/node_modules/glob/sync.js @@ -14,6 +14,7 @@ var alphasorti = common.alphasorti var isAbsolute = common.isAbsolute var setopts = common.setopts var ownProp = common.ownProp +var childrenIgnored = common.childrenIgnored function globSync (pattern, options) { if (typeof options === 'function' || arguments.length === 3) @@ -98,6 +99,10 @@ GlobSync.prototype._process = function (pattern, index, inGlobStar) { var abs = this._makeAbs(read) + //if ignored, skip processing + if (childrenIgnored(this, read)) + return + var isGlobStar = remain[0] === minimatch.GLOBSTAR if (isGlobStar) this._processGlobStar(prefix, read, abs, remain, index, inGlobStar) @@ -105,6 +110,7 @@ GlobSync.prototype._process = function (pattern, index, inGlobStar) { this._processReaddir(prefix, read, abs, remain, index, inGlobStar) } + GlobSync.prototype._processReaddir = function (prefix, read, abs, remain, index, inGlobStar) { var entries = this._readdir(abs, inGlobStar) |