You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP

cumberbatch

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cumberbatch - npm Package Compare versions

Comparing version

to
0.1.19

@@ -71,2 +71,3 @@ /******

this.watchers = [];
this._callbacks = {};
this._foundCount = 0;

@@ -181,3 +182,7 @@ this._handledCount = 0;

if (this.options.usePolling) fs.unwatchFile(fullPath);
if (this.options.usePolling) {
delete this._callbacks[fullPath];
fs.unwatchFile(fullPath);
this.emit('removeFile', fullPath);
}

@@ -233,2 +238,24 @@ // The Entry will either be a directory that just got removed

FSWatcher.prototype.setInterval = function (filename, interval, callback) {
var self = this;
console.log('SETTING', filename, 'TO', interval);
if (callback) {
this._callbacks[filename] = callback;
}
fs.unwatchFile(filename);
var options = {
persistent: this.options.persistent,
interval: interval
};
fs.watchFile(filename, options, function(curr, prev) {
if (curr.mtime.getTime() > prev.mtime.getTime()) {
self._callbacks[filename](filename, curr);
}
});
this.emit('changeInterval', filename, interval);
};
// Private: Watch file for changes with fs.watchFile or fs.watch.

@@ -252,9 +279,6 @@

if (this.options.usePolling) {
options.interval = this.enableBinaryInterval && isBinaryPath(basename) ?
this.options.binaryInterval : this.options.interval;
fs.watchFile(item, options, function(curr, prev) {
if (curr.mtime.getTime() > prev.mtime.getTime()) {
callback(item, curr);
}
});
this.setInterval(
item,
this.enableBinaryInterval && isBinaryPath(basename) ? this.options.binaryInterval : this.options.interval,
callback);
} else {

@@ -261,0 +285,0 @@ watcher = fs.watch(item, options, function(event, path) {

@@ -9,2 +9,3 @@ var chokidar = require('./chokidar');

var Q = require('kew');
var WarmingLRU = require('./WarmingLRU');

@@ -139,5 +140,15 @@ var Watcher = function(baseDir, options) {

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
persistent: true,
interval: coldInterval
};

@@ -149,8 +160,44 @@

if (self._options.binaryInterval) {
options.binaryInterval = self._options.binaryInterval;
}
var fsWatcher = chokidar.watch(dir, options);
var fileLru = self._fileLru = new WarmingLRU({
maxHot: maxHotFiles,
maxWarm: maxWarmFiles
});
fileLru.on('filesChanged', function(files) {
for(var filename in files) {
var heat = files[filename];
switch (heat) {
case 'hot':
fsWatcher.setInterval(filename, hotInterval);
break;
case 'warm':
fsWatcher.setInterval(filename, warmInterval);
break;
case 'cold':
fsWatcher.setInterval(filename, coldInterval);
break;
}
}
});
// with fs.watch we only need to attach a watcher to the root
self._dirWatchers[dir] = chokidar.watch(dir, options);
self._dirWatchers[dir].on('all', function (ev, filename, stat) {
fsWatcher.on('all', function (ev, filename, stat) {
if (hotFileFilter && hotFileFilter(filename)) {
if (stat) {
fileLru.set(filename, stat.mtime);
} else {
fileLru.del(filename);
}
}
self._checkPath(filename, stat);
});
self._dirWatchers[dir].on('ready', function () {
fsWatcher.on('ready', function () {
if (!self._isReady) {

@@ -162,2 +209,4 @@ self._isReady = true;

});
self._dirWatchers[dir] = fsWatcher;
}

@@ -164,0 +213,0 @@

{
"name": "cumberbatch",
"description": "crazy watcher stuff",
"version": "0.1.18",
"version": "0.1.19",
"homepage": "https://github.com/azulus/cumberbatch",

@@ -19,2 +19,3 @@ "authors": [

"kew": "0.3",
"lru-cache": "2.5",
"oid": "0.5",

@@ -32,9 +33,9 @@ "minimatch": "0.2",

"readme": "ERROR: No README data found!",
"_id": "cumberbatch@0.1.17",
"_id": "cumberbatch@0.1.18",
"dist": {
"shasum": "d19485a477fa9f46472f1b6d66fa7ba4b7ca47b1"
"shasum": "2ecc8d5c2c8e2d588c6aba9e39790b305356e457"
},
"_from": "cumberbatch@0.1.17",
"_resolved": "http://registry.npmjs.org/cumberbatch/-/cumberbatch-0.1.17.tgz",
"_from": "cumberbatch@*",
"_resolved": "https://registry.npmjs.org/cumberbatch/-/cumberbatch-0.1.18.tgz",
"_shasum": "01b45dce1e0d7a706e8ce36f1fe72f40e92b4de9"
}