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

beholder

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

beholder - npm Package Compare versions

Comparing version 0.2.0 to 1.0.0

436

lib/beholder.js

@@ -1,7 +0,7 @@

// Generated by CoffeeScript 1.6.3
// Generated by CoffeeScript 1.10.0
var Beholder, EventEmitter, async, fs, glob, minimatch, path,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
hasProp = {}.hasOwnProperty,
indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

@@ -20,25 +20,25 @@ EventEmitter = require('events').EventEmitter;

Beholder = (function(_super) {
__extends(Beholder, _super);
Beholder = (function(superClass) {
extend(Beholder, superClass);
function Beholder(pattern, options, cb) {
var _base, _base1, _base2, _base3, _base4;
this.pattern = pattern;
this.options = options != null ? options : {};
this.listDir = __bind(this.listDir, this);
this.list = __bind(this.list, this);
this.add = __bind(this.add, this);
this.removeAll = __bind(this.removeAll, this);
this.remove = __bind(this.remove, this);
this.handleError = __bind(this.handleError, this);
this.hiddenPath = __bind(this.hiddenPath, this);
this.invalidFile = __bind(this.invalidFile, this);
this.swapWatchers = __bind(this.swapWatchers, this);
this.removeWatch = __bind(this.removeWatch, this);
this.processFile = __bind(this.processFile, this);
this.processDir = __bind(this.processDir, this);
this.initWatch = __bind(this.initWatch, this);
this.addFile = __bind(this.addFile, this);
this.processPath = __bind(this.processPath, this);
this.walkPath = __bind(this.walkPath, this);
function Beholder(pattern1, options1, cb) {
var base1, base2, base3, base4, base5;
this.pattern = pattern1;
this.options = options1 != null ? options1 : {};
this.listDir = bind(this.listDir, this);
this.list = bind(this.list, this);
this.add = bind(this.add, this);
this.removeAll = bind(this.removeAll, this);
this.remove = bind(this.remove, this);
this.handleError = bind(this.handleError, this);
this.hiddenPath = bind(this.hiddenPath, this);
this.invalidFile = bind(this.invalidFile, this);
this.swapWatchers = bind(this.swapWatchers, this);
this.removeWatch = bind(this.removeWatch, this);
this.processFile = bind(this.processFile, this);
this.processDir = bind(this.processDir, this);
this.initWatch = bind(this.initWatch, this);
this.addFile = bind(this.addFile, this);
this.processPath = bind(this.processPath, this);
this.walkPath = bind(this.walkPath, this);
this.files = [];

@@ -48,16 +48,16 @@ this.dirs = [];

this.init = true;
if ((_base = this.options).interval == null) {
_base.interval = 5007;
if ((base1 = this.options).interval == null) {
base1.interval = 5007;
}
if ((_base1 = this.options).persistent == null) {
_base1.persistent = true;
if ((base2 = this.options).persistent == null) {
base2.persistent = true;
}
if ((_base2 = this.options).includeHidden == null) {
_base2.includeHidden = false;
if ((base3 = this.options).includeHidden == null) {
base3.includeHidden = false;
}
if ((_base3 = this.options).exclude == null) {
_base3.exclude = [];
if ((base4 = this.options).exclude == null) {
base4.exclude = [];
}
if ((_base4 = this.options).debug == null) {
_base4.debug = false;
if ((base5 = this.options).debug == null) {
base5.debug = false;
}

@@ -72,3 +72,2 @@ this.pollOpts = {

Beholder.prototype.startWatch = function(pattern, cb) {
var _this = this;
if (process.platform === 'win32') {

@@ -78,72 +77,76 @@ pattern = pattern.replace(/\\/g, "/");

this.patterns.push(pattern);
return glob(pattern, function(err, matches) {
if (pattern.indexOf('*' !== -1)) {
_this.addDir(pattern.replace(/\/\*.*/, ''));
}
return async.each(matches, _this.processPath, function(err) {
var finish;
if (err && cb) {
return cb(err);
return glob(pattern, (function(_this) {
return function(err, matches) {
if (pattern.indexOf('*' !== -1)) {
_this.addDir(pattern.replace(/\/\*.*/, ''));
}
if (err) {
return handleError(err);
}
_this.init = false;
finish = function() {
if (cb) {
cb(null, _this);
return async.each(matches, _this.processPath, function(err) {
var finish;
if (err && cb) {
return cb(err);
}
return _this.emit('ready');
};
return setTimeout(finish, matches.length);
});
});
};
Beholder.prototype.walkPath = function(base) {
var _this = this;
return fs.stat(base, function(err, stats) {
if (err) {
return _this.handleError(err);
}
if (stats.isDirectory()) {
_this.addDir(base);
return fs.readdir(base, function(err, files) {
var file, filePath, _i, _len;
if (err) {
return _this.handleError(err);
return handleError(err);
}
for (_i = 0, _len = files.length; _i < _len; _i++) {
file = files[_i];
filePath = path.join(base, file);
if (process.platform === 'win32') {
filePath = filePath.replace(/\\/g, "/");
_this.init = false;
finish = function() {
if (cb) {
cb(null, _this);
}
_this.processPath(filePath, null, true);
}
return _this.emit('ready');
};
return setTimeout(finish, matches.length);
});
} else {
return _this.addFile(base, stats);
}
});
};
})(this));
};
Beholder.prototype.walkPath = function(base) {
return fs.stat(base, (function(_this) {
return function(err, stats) {
if (err) {
return _this.handleError(err);
}
if (stats.isDirectory()) {
_this.addDir(base);
return fs.readdir(base, function(err, files) {
var file, filePath, j, len;
if (err) {
return _this.handleError(err);
}
for (j = 0, len = files.length; j < len; j++) {
file = files[j];
filePath = path.join(base, file);
if (process.platform === 'win32') {
filePath = filePath.replace(/\\/g, "/");
}
_this.processPath(filePath, null, true);
}
});
} else {
return _this.addFile(base, stats);
}
};
})(this));
};
Beholder.prototype.processPath = function(filePath, cb, descend) {
var _this = this;
return fs.stat(filePath, function(err, stats) {
if (err) {
return _this.handleError(err, true);
}
if (stats.isDirectory()) {
_this.addDir(filePath);
if (descend) {
_this.walkPath(filePath);
return fs.stat(filePath, (function(_this) {
return function(err, stats) {
if (err) {
return _this.handleError(err, true);
}
} else {
_this.addFile(filePath, stats, _this.init);
}
if (cb) {
return cb();
}
});
if (stats.isDirectory()) {
_this.addDir(filePath);
if (descend) {
_this.walkPath(filePath);
}
} else {
_this.addFile(filePath, stats, _this.init);
}
if (cb) {
return cb();
}
};
})(this));
};

@@ -156,11 +159,11 @@

}
if (__indexOf.call((function() {
var _i, _len, _ref, _results;
_ref = this.dirs;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
_results.push(i.name);
if (indexOf.call((function() {
var j, len, ref, results;
ref = this.dirs;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
results.push(i.name);
}
return _results;
return results;
}).call(this), dirPath) >= 0) {

@@ -176,3 +179,3 @@ return;

Beholder.prototype.addFile = function(filePath, stats, silent) {
var i, _ref;
var i, ref;
if (this.invalidFile(filePath)) {

@@ -189,12 +192,12 @@ return;

}
if (_ref = path.dirname(filePath), __indexOf.call((function() {
var _i, _len, _ref1, _results;
_ref1 = this.dirs;
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
i = _ref1[_i];
_results.push(i.name);
if (ref = path.dirname(filePath), indexOf.call((function() {
var j, len, ref1, results;
ref1 = this.dirs;
results = [];
for (j = 0, len = ref1.length; j < len; j++) {
i = ref1[j];
results.push(i.name);
}
return _results;
}).call(this), _ref) < 0) {
return results;
}).call(this), ref) < 0) {
return this.addDir(path.dirname(filePath));

@@ -205,4 +208,3 @@ }

Beholder.prototype.initWatch = function(watchPath, watchFn) {
var err,
_this = this;
var err, error1;
if ((this.maxFiles != null) && this.files.length >= this.maxFiles) {

@@ -212,7 +214,9 @@ return this.initPoll(watchPath, watchFn);

try {
return fs.watch(path.normalize(watchPath), function(event, filename) {
return watchFn(watchPath, event);
});
} catch (_error) {
err = _error;
return fs.watch(path.normalize(watchPath), (function(_this) {
return function(event, filename) {
return watchFn(watchPath, event);
};
})(this));
} catch (error1) {
err = error1;
if (err.code === 'EMFILE') {

@@ -229,9 +233,10 @@ this.maxFiles = this.files.length;

Beholder.prototype.initPoll = function(watchPath, watchFn) {
var _this = this;
return fs.watchFile(path.normalize(watchPath), this.pollOpts, function(curr, prev) {
if (curr.mtime.getTime() && curr.mtime.getTime() < prev.mtime.getTime()) {
return;
}
return watchFn(watchPath, 'change');
});
return fs.watchFile(path.normalize(watchPath), this.pollOpts, (function(_this) {
return function(curr, prev) {
if (curr.mtime.getTime() && curr.mtime.getTime() < prev.mtime.getTime()) {
return;
}
return watchFn(watchPath, 'change');
};
})(this));
};

@@ -244,7 +249,6 @@

Beholder.prototype.processFile = function(filePath, event) {
var file, i, _i, _len, _ref,
_this = this;
_ref = this.files;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
var file, i, j, len, ref;
ref = this.files;
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
if (i.name === filePath) {

@@ -254,26 +258,28 @@ file = i;

}
fs.stat(filePath, function(err, stats) {
if ((err != null ? err.code : void 0) === 'ENOENT') {
_this.removeWatch(file);
}
if (err) {
return _this.handleError(err);
}
if (event !== 'new' && stats.mtime.getTime() === file.mtime.getTime()) {
return;
}
file.mtime = stats.mtime;
_this.emit('any', filePath, event);
_this.emit(event, filePath);
_this.removeWatch(file, true);
_this.addFile(filePath, stats, true);
file = null;
filePath = null;
return event = null;
});
fs.stat(filePath, (function(_this) {
return function(err, stats) {
if ((err != null ? err.code : void 0) === 'ENOENT') {
_this.removeWatch(file);
}
if (err) {
return _this.handleError(err);
}
if (event !== 'new' && stats.mtime.getTime() === file.mtime.getTime()) {
return;
}
file.mtime = stats.mtime;
_this.emit('any', filePath, event);
_this.emit(event, filePath);
_this.removeWatch(file, true);
_this.addFile(filePath, stats, true);
file = null;
filePath = null;
return event = null;
};
})(this));
};
Beholder.prototype.removeWatch = function(file, silent) {
var i, _ref;
if (((_ref = file.watcher) != null ? _ref.close : void 0) != null) {
var i, ref;
if (((ref = file.watcher) != null ? ref.close : void 0) != null) {
file.watcher.close();

@@ -284,24 +290,24 @@ } else {

this.files = (function() {
var _i, _len, _ref1, _results;
_ref1 = this.files;
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
i = _ref1[_i];
var j, len, ref1, results;
ref1 = this.files;
results = [];
for (j = 0, len = ref1.length; j < len; j++) {
i = ref1[j];
if (i.name !== file.name) {
_results.push(i);
results.push(i);
}
}
return _results;
return results;
}).call(this);
this.dirs = (function() {
var _i, _len, _ref1, _results;
_ref1 = this.dirs;
_results = [];
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
i = _ref1[_i];
var j, len, ref1, results;
ref1 = this.dirs;
results = [];
for (j = 0, len = ref1.length; j < len; j++) {
i = ref1[j];
if (i.name !== file.name) {
_results.push(i);
results.push(i);
}
}
return _results;
return results;
}).call(this);

@@ -319,6 +325,6 @@ if (!silent) {

Beholder.prototype.swapWatchers = function() {
var file, index, _i, _len, _ref;
_ref = this.files;
for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
file = _ref[index];
var file, index, j, len, ref;
ref = this.files;
for (index = j = 0, len = ref.length; j < len; index = ++j) {
file = ref[index];
if (!(index > this.maxFiles - 25)) {

@@ -336,15 +342,15 @@ continue;

Beholder.prototype.invalidFile = function(filePath) {
var i, _i, _len, _ref;
var i, j, len, ref;
if (this.hiddenPath(filePath)) {
return true;
}
if (__indexOf.call((function() {
var _i, _len, _ref, _results;
_ref = this.files;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
_results.push(i.name);
if (indexOf.call((function() {
var j, len, ref, results;
ref = this.files;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
results.push(i.name);
}
return _results;
return results;
}).call(this), filePath) >= 0) {

@@ -356,5 +362,5 @@ return true;

}
_ref = this.options.exclude;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
ref = this.options.exclude;
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
if (minimatch(filePath, i)) {

@@ -368,6 +374,6 @@ return true;

Beholder.prototype.patternMatch = function(filePath) {
var pattern, _i, _len, _ref;
_ref = this.patterns;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
pattern = _ref[_i];
var j, len, pattern, ref;
ref = this.patterns;
for (j = 0, len = ref.length; j < len; j++) {
pattern = ref[j];
if (minimatch(filePath, pattern)) {

@@ -396,6 +402,6 @@ return true;

Beholder.prototype.remove = function(filePath, silent) {
var file, i, _i, _j, _len, _len1, _ref, _ref1;
_ref = this.files;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
var file, i, j, k, len, len1, ref, ref1;
ref = this.files;
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
if (i.name === filePath) {

@@ -406,5 +412,5 @@ file = i;

if (!file) {
_ref1 = this.dirs;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
i = _ref1[_j];
ref1 = this.dirs;
for (k = 0, len1 = ref1.length; k < len1; k++) {
i = ref1[k];
if (i.name === filePath) {

@@ -422,6 +428,6 @@ file = i;

Beholder.prototype.removeAll = function(silent) {
var file, _i, _len, _ref;
_ref = this.files;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
file = _ref[_i];
var file, j, len, ref;
ref = this.files;
for (j = 0, len = ref.length; j < len; j++) {
file = ref[j];
this.removeWatch(file, silent);

@@ -436,21 +442,21 @@ }

Beholder.prototype.list = function() {
var i, _i, _len, _ref, _results;
_ref = this.files;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
_results.push(i.name);
var i, j, len, ref, results;
ref = this.files;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
results.push(i.name);
}
return _results;
return results;
};
Beholder.prototype.listDir = function() {
var i, _i, _len, _ref, _results;
_ref = this.dirs;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
_results.push(i.name);
var i, j, len, ref, results;
ref = this.dirs;
results = [];
for (j = 0, len = ref.length; j < len; j++) {
i = ref[j];
results.push(i.name);
}
return _results;
return results;
};

@@ -457,0 +463,0 @@

{
"name": "beholder",
"version": "0.2.0",
"version": "1.0.0",
"author": "Charles Moncrief <cmoncrief@gmail.com>",

@@ -28,10 +28,10 @@ "description": "Robust cross-platform file watcher",

"dependencies": {
"glob": "~3.2.7",
"minimatch": "~0.2.9",
"async": "~0.2.5"
"async": "~1.5.2",
"glob": "~7.0.0",
"minimatch": "^3.0.0"
},
"devDependencies": {
"mocha": "~1.8.1",
"coffee-script": "~1.6.3",
"mkdirp": "^0.3.5"
"mkdirp": "^0.5.1",
"mocha": "^2.4.5"
},

@@ -38,0 +38,0 @@ "engines": {

@@ -9,3 +9,3 @@ # Beholder

* Globbing syntax for fine-grained control
* Detects new files and directories automatically
* Detects new files and directories automatically
* Handles large file sets

@@ -103,3 +103,3 @@ * Event-based API

Copyright (c) 2013 Charles Moncrief <<cmoncrief@gmail.com>>
Copyright (c) 2016 Charles Moncrief <<cmoncrief@gmail.com>>

@@ -123,2 +123,2 @@ Permission is hereby granted, free of charge, to any person obtaining

TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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