Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cumberbatch

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cumberbatch - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

135

lib/Watcher.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc