Socket
Socket
Sign inDemoInstall

chokidar

Package Overview
Dependencies
Maintainers
2
Versions
106
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chokidar - npm Package Compare versions

Comparing version 0.10.4 to 0.10.5

131

index.js

@@ -7,7 +7,6 @@ 'use strict';

var each = require('async-each');
var fsevents, readdirp;
var readdirp = require('readdirp');
var fsevents;
try {
fsevents = require('fsevents');
readdirp = require('readdirp');
} catch (error) {}

@@ -96,24 +95,5 @@

this._isIgnored = function(path, stats) {
var userIgnored = (function(ignored) {
switch (toString.call(ignored)) {
case '[object RegExp]':
return function(string) {
return ignored.test(string);
};
case '[object Function]':
return ignored;
default:
return function() {
return false;
};
}
})(opts.ignored);
var ignoredPaths = Object.keys(this.ignoredPaths);
function isParent(ip) {
return !path.indexOf(ip + sysPath.sep);
}
return ignoredPaths.length && ignoredPaths.some(isParent) ||
userIgnored(path, stats);
};
this._isntIgnored = function(entry) {
return !this._isIgnored(entry.path, entry.stat);
}.bind(this);

@@ -160,2 +140,25 @@ this.options = opts;

FSWatcher.prototype._isIgnored = function(path, stats) {
var userIgnored = (function(ignored) {
switch (toString.call(ignored)) {
case '[object RegExp]':
return function(string) {
return ignored.test(string);
};
case '[object Function]':
return ignored;
default:
return function() {
return false;
};
}
})(this.options.ignored);
var ignoredPaths = Object.keys(this.ignoredPaths);
function isParent(ip) {
return !path.indexOf(ip + sysPath.sep);
}
return ignoredPaths.length && ignoredPaths.some(isParent) ||
userIgnored(path, stats);
};
// Directory helpers

@@ -235,3 +238,5 @@ // -----------------

// FS Events helper.
var FSEventsInstanceCount = 0;
function createFSEventsInstance(path, callback) {
FSEventsInstanceCount++;
return (new fsevents(path)).on('fsevent', callback).start();

@@ -274,2 +279,3 @@ }

}
if (checkIgnored()) return;
if (event === 'add') {

@@ -411,11 +417,27 @@ this._getWatchedDir(parent).add(item);

FSWatcher.prototype._handleDir = function(dir, stats, initialAdd, target) {
var read = function read(directory, initialAdd, target) {
var throttler = this._throttle('readdir', directory, 1000);
var _this = this;
function read(directory, initialAdd, target) {
// Normalize the directory name on Windows
directory = sysPath.join(directory, '');
var throttler = _this._throttle('readdir', directory, 1000);
if (!throttler) return;
fs.readdir(directory, function(error, current) {
var previous = _this._getWatchedDir(directory);
var current = [];
readdirp({
root: directory,
entryType: 'both',
depth: 0
}).on('data', function(entry) {
var item = entry.path;
current.push(item);
// Files that present in current directory snapshot
// but absent in previous are added to watch list and
// emit `add` event.
if (item === target || !target && !previous.has(item)) {
_this._handle(sysPath.join(directory, item), initialAdd, target);
}
}).on('end', function() {
throttler.clear();
if (this._handleError(error) || !current) return;
// Normalize the directory name on Windows
directory = sysPath.join(directory, '');
var previous = this._getWatchedDir(directory);

@@ -425,18 +447,9 @@ // Files that absent in current directory snapshot

// and are removed from @watched[directory].
previous.children().filter(function(file) {
return file !== directory && current.indexOf(file) === -1;
}).forEach(function(file) {
this._remove(directory, file);
}, this);
// Files that present in current directory snapshot
// but absent in previous are added to watch list and
// emit `add` event.
current.filter(function(file) {
return file === target || !target && !previous.has(file);
}).forEach(function(file) {
this._handle(sysPath.join(directory, file), initialAdd, target);
}, this);
}.bind(this));
}.bind(this);
previous.children().filter(function(item) {
return item !== directory && current.indexOf(item) === -1;
}).forEach(function(item) {
_this._remove(directory, item);
});
}).on('error', _this._handleError.bind(_this));
}
if (!target) read(dir, initialAdd);

@@ -498,7 +511,10 @@ this._watch(dir, function(dirPath, stats) {

this._emit('addDir', file, stats);
readdirp({root: file, entryType: 'both'})
.on('data', function(entry) {
if (this._isIgnored(entry.path)) return;
emitAdd(sysPath.join(file, entry.path), entry.stat);
}.bind(this));
readdirp({
root: file,
entryType: 'both',
fileFilter: this._isntIgnored,
directoryFilter: this._isntIgnored
}).on('data', function(entry) {
emitAdd(sysPath.join(file, entry.path), entry.stat);
});
} else {

@@ -523,3 +539,3 @@ emitAdd(file, stats);

if (this.options.useFsEvents) {
if (this.options.useFsEvents && FSEventsInstanceCount < 400) {
files.forEach(this._addToFsEvents, this);

@@ -553,3 +569,8 @@ } else if (!this.closed) {

this.watchers.forEach(function(watcher) {
watcher[method]();
if (watcher.stop) {
watcher.stop();
FSEventsInstanceCount--;
} else {
watcher.close();
}
});

@@ -556,0 +577,0 @@ Object.keys(watched).forEach(function(directory) {

{
"name": "chokidar",
"description": "A neat wrapper around node.js fs.watch / fs.watchFile / fsevents.",
"version": "0.10.4",
"version": "0.10.5",
"keywords": [

@@ -42,8 +42,8 @@ "fs",

"optionalDependencies": {
"fsevents": "~0.3.1",
"readdirp": "~1.1.0"
"fsevents": "~0.3.1"
},
"dependencies": {
"readdirp": "~1.1.0",
"async-each": "~0.1.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