glob-watcher
Advanced tools
Comparing version 5.0.1 to 5.0.2
49
index.js
@@ -7,2 +7,4 @@ 'use strict'; | ||
var defaults = require('object.defaults/immutable'); | ||
var isNegatedGlob = require('is-negated-glob'); | ||
var anymatch = require('anymatch'); | ||
@@ -28,2 +30,6 @@ var defaultOpts = { | ||
function exists(val) { | ||
return val != null; | ||
} | ||
function watch(glob, options, cb) { | ||
@@ -41,7 +47,48 @@ if (typeof options === 'function') { | ||
if (Array.isArray(glob)) { | ||
// We slice so we don't mutate the passed globs array | ||
glob = glob.slice(); | ||
} else { | ||
glob = [glob]; | ||
} | ||
var queued = false; | ||
var running = false; | ||
var watcher = chokidar.watch(glob, opt); | ||
// These use sparse arrays to keep track of the index in the | ||
// original globs array | ||
var positives = new Array(glob.length); | ||
var negatives = new Array(glob.length); | ||
// Reverse the glob here so we don't end up with a positive | ||
// and negative glob in position 0 after a reverse | ||
glob.reverse().forEach(sortGlobs); | ||
function sortGlobs(globString, index) { | ||
var result = isNegatedGlob(globString); | ||
if (result.negated) { | ||
negatives[index] = result.pattern; | ||
} else { | ||
positives[index] = result.pattern; | ||
} | ||
} | ||
function shouldBeIgnored(path) { | ||
var positiveMatch = anymatch(positives, path, true); | ||
var negativeMatch = anymatch(negatives, path, true); | ||
// If negativeMatch is -1, that means it was never negated | ||
if (negativeMatch === -1) { | ||
return false; | ||
} | ||
// If the negative is "less than" the positive, that means | ||
// it came later in the glob array before we reversed them | ||
return negativeMatch < positiveMatch; | ||
} | ||
var toWatch = positives.filter(exists); | ||
opt.ignored = shouldBeIgnored; | ||
var watcher = chokidar.watch(toWatch, opt); | ||
function runComplete(err) { | ||
@@ -48,0 +95,0 @@ running = false; |
{ | ||
"name": "glob-watcher", | ||
"version": "5.0.1", | ||
"version": "5.0.2", | ||
"description": "Watch globs and execute a function upon change, with intelligent defaults for debouncing and queueing.", | ||
@@ -17,3 +17,3 @@ "author": "Gulp Team <team@gulpjs.com> (http://gulpjs.com/)", | ||
"scripts": { | ||
"lint": "eslint . && jscs index.js test/", | ||
"lint": "eslint .", | ||
"pretest": "npm run lint", | ||
@@ -25,4 +25,6 @@ "test": "mocha --async-only", | ||
"dependencies": { | ||
"anymatch": "^2.0.0", | ||
"async-done": "^1.2.0", | ||
"chokidar": "^2.0.0", | ||
"is-negated-glob": "^1.0.0", | ||
"just-debounce": "^1.0.0", | ||
@@ -33,9 +35,7 @@ "object.defaults": "^1.1.0" | ||
"coveralls": "^2.11.2", | ||
"eslint": "^1.10.3", | ||
"eslint-config-gulp": "^2.0.0", | ||
"eslint": "^2.13.1", | ||
"eslint-config-gulp": "^3.0.1", | ||
"expect": "^1.16.0", | ||
"istanbul": "^0.4.0", | ||
"istanbul-coveralls": "^1.0.1", | ||
"jscs": "^2.3.5", | ||
"jscs-preset-gulp": "^1.0.0", | ||
"mocha": "^2.0.0", | ||
@@ -42,0 +42,0 @@ "mocha-lcov-reporter": "^1.2.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10901
11
105
6
+ Addedanymatch@^2.0.0
+ Addedis-negated-glob@^1.0.0
+ Addedis-negated-glob@1.0.0(transitive)