cumberbatch
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -1,2 +0,1 @@ | ||
var chokidar = require('./chokidar'); | ||
var fs = require('fs'); | ||
@@ -19,2 +18,6 @@ var minimatch = require('minimatch'); | ||
if (typeof this._options.usePolling !== 'boolean') { | ||
this._options.usePolling = false; | ||
} | ||
this._runners = 0; | ||
@@ -30,5 +33,25 @@ this._queue = []; | ||
this._isReady = false; | ||
// Temporarily support old polling mechanism | ||
// TODO: Remove support for polling once transition is finished. | ||
if (this._options.usePolling) { | ||
// Use our modified chokidar version. | ||
// Which is based on a now older chokidar version (0.8) | ||
this._chokidar = require('./chokidar'); | ||
if (this._options.debug) { | ||
console.log('Using Polling'); | ||
} | ||
} else { | ||
// Use the new version of chokidar which | ||
// has fixed some bugs related to polling | ||
// and that has improved support for non-polling. | ||
this._chokidar = require('chokidar'); | ||
if (this._options.debug) { | ||
console.log('Not using Polling'); | ||
} | ||
} | ||
this._lastUpdate = Date.now(); | ||
this._watchDir(baseDir, true); | ||
this._onReady = Q.defer(); | ||
@@ -141,17 +164,23 @@ }; | ||
if (isRoot) { | ||
var hotInterval = this._options.hotFileInterval || 100; | ||
var warmInterval = this._options.warmFileInterval || 2000; | ||
var coldInterval = this._options.coldFileInterval || 4000; | ||
var maxHotFiles = this._options.maxHotFiles || 100; | ||
var maxWarmFiles = this._options.maxWarmFiles || 500; | ||
var hotFileFilter = this._options.hotFileFilter; | ||
var options = { | ||
ignoreInitial: false, | ||
persistent: true, | ||
interval: coldInterval | ||
alwaysStat: true, | ||
usePolling: !!this._options.usePolling | ||
}; | ||
if (this._options.usePolling) { | ||
var hotInterval = this._options.hotFileInterval || 100; | ||
var warmInterval = this._options.warmFileInterval || 2000; | ||
var coldInterval = this._options.coldFileInterval || 4000; | ||
var maxHotFiles = this._options.maxHotFiles || 100; | ||
var maxWarmFiles = this._options.maxWarmFiles || 500; | ||
var hotFileFilter = this._options.hotFileFilter; | ||
options.interval = coldInterval; | ||
} | ||
if (self._options.ignored) { | ||
@@ -165,27 +194,29 @@ options.ignored = self._options.ignored; | ||
var fsWatcher = chokidar.watch(dir, options); | ||
var fsWatcher = this._chokidar.watch(dir, options); | ||
var fileLru = self._fileLru = new WarmingLRU({ | ||
maxHot: maxHotFiles, | ||
maxWarm: maxWarmFiles | ||
}); | ||
if (this._options.usePolling) { | ||
var fileLru = self._fileLru = new WarmingLRU({ | ||
maxHot: maxHotFiles, | ||
maxWarm: maxWarmFiles | ||
}); | ||
fileLru.on('filesChanged', function(files) { | ||
for(var filename in files) { | ||
var heat = files[filename]; | ||
var interval; | ||
switch (heat) { | ||
case 'hot': | ||
interval = hotInterval; | ||
break; | ||
case 'warm': | ||
interval = warmInterval; | ||
break; | ||
default: | ||
interval = coldInterval; | ||
break; | ||
fileLru.on('filesChanged', function(files) { | ||
for(var filename in files) { | ||
var heat = files[filename]; | ||
var interval; | ||
switch (heat) { | ||
case 'hot': | ||
interval = hotInterval; | ||
break; | ||
case 'warm': | ||
interval = warmInterval; | ||
break; | ||
default: | ||
interval = coldInterval; | ||
break; | ||
} | ||
fsWatcher.setInterval(filename, interval); | ||
} | ||
fsWatcher.setInterval(filename, interval); | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -197,11 +228,13 @@ var isReady = false; | ||
fsWatcher.on('all', function (ev, filename, stat) { | ||
if (hotFileFilter && hotFileFilter(filename)) { | ||
if (stat) { | ||
if (!isReady) { | ||
allTimes.push({'filename':filename, 'mtime':stat.mtime.getTime()/1000}); | ||
if (self._options.usePolling) { | ||
if (hotFileFilter && hotFileFilter(filename)) { | ||
if (stat) { | ||
if (!isReady) { | ||
allTimes.push({'filename':filename, 'mtime':stat.mtime.getTime()/1000}); | ||
} else { | ||
fileLru.set(filename, stat.mtime); | ||
} | ||
} else { | ||
fileLru.set(filename, stat.mtime); | ||
fileLru.del(filename); | ||
} | ||
} else { | ||
fileLru.del(filename); | ||
} | ||
@@ -214,14 +247,16 @@ } | ||
fsWatcher.on('ready', function () { | ||
allTimes.sort(function (a, b) { | ||
return b.mtime - a.mtime; | ||
}); | ||
var end = Math.min(allTimes.length - 1, maxHotFiles + maxWarmFiles - 1); | ||
for (var i = end; i >= 0; i--) { | ||
var time = allTimes[i]; | ||
fileLru.set(time.filename, time.mtime); | ||
if (i < maxHotFiles) { | ||
if (self._options.usePolling) { | ||
allTimes.sort(function (a, b) { | ||
return b.mtime - a.mtime; | ||
}); | ||
var end = Math.min(allTimes.length - 1, maxHotFiles + maxWarmFiles - 1); | ||
for (var i = end; i >= 0; i--) { | ||
var time = allTimes[i]; | ||
fileLru.set(time.filename, time.mtime); | ||
} | ||
if (i < maxHotFiles) { | ||
fileLru.set(time.filename, time.mtime); | ||
} | ||
} | ||
allTimes = undefined; | ||
} | ||
allTimes = undefined; | ||
isReady = true; | ||
@@ -228,0 +263,0 @@ |
{ | ||
"name": "cumberbatch", | ||
"description": "crazy watcher stuff", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"homepage": "https://github.com/azulus/cumberbatch", | ||
@@ -17,3 +17,3 @@ "authors": [ | ||
"dependencies": { | ||
"chokidar": "0.8", | ||
"chokidar": "1.0.0-rc4", | ||
"kew": "0.3", | ||
@@ -20,0 +20,0 @@ "lru-cache": "2.5", |
54276
1559
+ Addedanymatch@1.3.2(transitive)
+ Addedarr-diff@2.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarray-unique@0.2.1(transitive)
+ Addedasync-each@0.1.6(transitive)
+ Addedbinary-extensions@1.13.1(transitive)
+ Addedbraces@1.8.5(transitive)
+ Addedchokidar@1.0.0-rc4(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedexpand-brackets@0.1.5(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedextglob@0.3.2(transitive)
+ Addedfilename-regex@2.0.1(transitive)
+ Addedfill-range@2.2.4(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedfsevents@0.3.8(transitive)
+ Addedglob-base@0.3.0(transitive)
+ Addedglob-parent@1.3.02.0.0(transitive)
+ Addedgraceful-fs@4.1.15(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-binary-path@1.0.1(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-dotfile@1.0.3(transitive)
+ Addedis-equal-shallow@0.1.3(transitive)
+ Addedis-extendable@0.1.1(transitive)
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-glob@2.0.1(transitive)
+ Addedis-number@2.1.04.0.0(transitive)
+ Addedis-posix-bracket@0.1.1(transitive)
+ Addedis-primitive@2.0.0(transitive)
+ Addedisarray@0.0.11.0.0(transitive)
+ Addedisobject@2.1.0(transitive)
+ Addedkind-of@3.2.26.0.3(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmicromatch@2.3.11(transitive)
+ Addednormalize-path@2.1.1(transitive)
+ Addedobject.omit@2.0.1(transitive)
+ Addedparse-glob@3.0.4(transitive)
+ Addedpreserve@0.2.0(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedreaddirp@1.4.0(transitive)
+ Addedregex-cache@0.4.4(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedstring_decoder@0.10.31(transitive)
- Removedchokidar@0.8.4(transitive)
- Removedrecursive-readdir@0.0.2(transitive)
Updatedchokidar@1.0.0-rc4