diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:01:11 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-08-14 05:02:09 +0200 |
commit | 363723fc84f7b8477592e0105aeb331ec9a017af (patch) | |
tree | 29f92724f34131bac64d6a318dd7e30612e631c7 /node_modules/test-exclude/index.js | |
parent | 5634e77ad96bfe1818f6b6ee70b7379652e5487f (diff) |
node_modules
Diffstat (limited to 'node_modules/test-exclude/index.js')
-rw-r--r-- | node_modules/test-exclude/index.js | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/node_modules/test-exclude/index.js b/node_modules/test-exclude/index.js index ccc0957c2..9c23a5865 100644 --- a/node_modules/test-exclude/index.js +++ b/node_modules/test-exclude/index.js @@ -32,27 +32,43 @@ function TestExclude (opts) { this.include = false } - if (!this.removeNegatedModuleExclude() && this.exclude.indexOf('**/node_modules/**') === -1) { + if (this.exclude.indexOf('**/node_modules/**') === -1) { this.exclude.push('**/node_modules/**') } this.exclude = prepGlobPatterns( [].concat(arrify(this.exclude)) ) + + this.handleNegation() } -// if a glob has been provided that explicitly negates -// the **/node_modules/** default exclude rule, remove it from -// excludes but don't add the default exclude rule. -TestExclude.prototype.removeNegatedModuleExclude = function () { - var moduleExcludeNegated = false +// handle the special case of negative globs +// (!**foo/bar); we create a new this.excludeNegated set +// of rules, which is applied after excludes and we +// move excluded include rules into this.excludes. +TestExclude.prototype.handleNegation = function () { + if (Array.isArray(this.include)) { + const includeNegated = this.include.filter(function (e) { + return e.charAt(0) === '!' + }).map(function (e) { + return e.slice(1) + }) + this.exclude.push.apply(this.exclude, prepGlobPatterns(includeNegated)) + this.include = this.include.filter(function (e) { + return e.charAt(0) !== '!' + }) + } + + this.excludeNegated = this.exclude.filter(function (e) { + return e.charAt(0) === '!' + }).map(function (e) { + return e.slice(1) + }) this.exclude = this.exclude.filter(function (e) { - var negated = !!micromatch('./node_modules/foo.js', e, {nonegate: false}).length !== - !!micromatch('./node_modules/foo.js', e, {nonegate: true}).length - if (negated) moduleExcludeNegated = true - return !negated + return e.charAt(0) !== '!' }) - return moduleExcludeNegated + this.excludeNegated = prepGlobPatterns(this.excludeNegated) } TestExclude.prototype.shouldInstrument = function (filename, relFile) { @@ -67,7 +83,11 @@ TestExclude.prototype.shouldInstrument = function (filename, relFile) { pathToCheck = relFile.replace(/^\.[\\/]/, '') // remove leading './' or '.\'. } - return (!this.include || micromatch.any(pathToCheck, this.include, {dotfiles: true})) && !micromatch.any(pathToCheck, this.exclude, {dotfiles: true}) + return ( + !this.include || + micromatch.any(pathToCheck, this.include, {dotfiles: true})) && + (!micromatch.any(pathToCheck, this.exclude, {dotfiles: true}) || + micromatch.any(pathToCheck, this.excludeNegated, {dotfiles: true})) } TestExclude.prototype.pkgConf = function (key, path) { |