Comparing version 0.7.1 to 0.8.0
@@ -0,1 +1,7 @@ | ||
# Chokidar 0.8.0 (29 November 2013) | ||
* Added ultra-fast low-CPU OS X file watching with FSEvents. | ||
It is enabled by default. | ||
* Added `addDir` and `unlinkDir` events. | ||
* Polling is now disabled by default on all platforms. | ||
# Chokidar 0.7.1 (18 November 2013) | ||
@@ -2,0 +8,0 @@ * `Watcher#close` now also removes all event listeners. |
560
lib/index.js
// Generated by CoffeeScript 1.6.3 | ||
'use strict'; | ||
var EventEmitter, FSWatcher, fs, isBinary, nodeVersion, sysPath, | ||
__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; }, | ||
__slice = [].slice; | ||
(function() { | ||
'use strict'; | ||
var EventEmitter, FSWatcher, createFSEventsInstance, directoryEndRe, fs, fsevents, isBinary, isDarwin, nodeVersion, os, recursiveReaddir, sysPath, | ||
__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; }, | ||
__slice = [].slice; | ||
EventEmitter = require('events').EventEmitter; | ||
EventEmitter = require('events').EventEmitter; | ||
fs = require('fs'); | ||
fs = require('fs'); | ||
sysPath = require('path'); | ||
os = require('os'); | ||
isBinary = require('./is-binary'); | ||
sysPath = require('path'); | ||
nodeVersion = process.versions.node.substring(0, 3); | ||
isBinary = require('./is-binary'); | ||
exports.FSWatcher = FSWatcher = (function(_super) { | ||
__extends(FSWatcher, _super); | ||
function FSWatcher(options) { | ||
var _base, _base1, _base2, _base3, _base4, _base5, | ||
_this = this; | ||
this.options = options != null ? options : {}; | ||
this.close = __bind(this.close, this); | ||
this.add = __bind(this.add, this); | ||
this._handle = __bind(this._handle, this); | ||
this._handleDir = __bind(this._handleDir, this); | ||
this._handleFile = __bind(this._handleFile, this); | ||
this._watch = __bind(this._watch, this); | ||
this._remove = __bind(this._remove, this); | ||
this._hasReadPermissions = __bind(this._hasReadPermissions, this); | ||
this._removeFromWatchedDir = __bind(this._removeFromWatchedDir, this); | ||
this._addToWatchedDir = __bind(this._addToWatchedDir, this); | ||
this._getWatchedDir = __bind(this._getWatchedDir, this); | ||
FSWatcher.__super__.constructor.apply(this, arguments); | ||
this.watched = Object.create(null); | ||
this.watchers = []; | ||
if ((_base = this.options).persistent == null) { | ||
_base.persistent = false; | ||
} | ||
if ((_base1 = this.options).ignoreInitial == null) { | ||
_base1.ignoreInitial = false; | ||
} | ||
if ((_base2 = this.options).ignorePermissionErrors == null) { | ||
_base2.ignorePermissionErrors = false; | ||
} | ||
if ((_base3 = this.options).interval == null) { | ||
_base3.interval = 100; | ||
} | ||
if ((_base4 = this.options).binaryInterval == null) { | ||
_base4.binaryInterval = 300; | ||
} | ||
if ((_base5 = this.options).usePolling == null) { | ||
_base5.usePolling = true; | ||
} | ||
this.enableBinaryInterval = this.options.binaryInterval !== this.options.interval; | ||
this._ignored = (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); | ||
Object.freeze(this.options); | ||
try { | ||
fsevents = require('fsevents'); | ||
recursiveReaddir = require('recursive-readdir'); | ||
} catch (_error) { | ||
fsevents = null; | ||
recursiveReaddir = null; | ||
} | ||
FSWatcher.prototype._getWatchedDir = function(directory) { | ||
var dir, _base; | ||
dir = directory.replace(/[\\\/]$/, ''); | ||
return (_base = this.watched)[dir] != null ? (_base = this.watched)[dir] : _base[dir] = []; | ||
}; | ||
nodeVersion = process.versions.node.substring(0, 3); | ||
FSWatcher.prototype._addToWatchedDir = function(directory, file) { | ||
var watchedFiles; | ||
watchedFiles = this._getWatchedDir(directory); | ||
return watchedFiles.push(file); | ||
createFSEventsInstance = function(path, callback) { | ||
var watcher; | ||
watcher = new fsevents.FSEvents(path); | ||
watcher.on('fsevent', callback); | ||
return watcher; | ||
}; | ||
FSWatcher.prototype._removeFromWatchedDir = function(directory, file) { | ||
var watchedFiles, | ||
_this = this; | ||
watchedFiles = this._getWatchedDir(directory); | ||
return watchedFiles.some(function(watchedFile, index) { | ||
if (watchedFile === file) { | ||
watchedFiles.splice(index, 1); | ||
return true; | ||
} | ||
}); | ||
}; | ||
directoryEndRe = /[\\\/]$/; | ||
FSWatcher.prototype._hasReadPermissions = function(stats) { | ||
return Boolean(4 & parseInt((stats.mode & 0x1ff).toString(8)[0])); | ||
}; | ||
isDarwin = os.platform() === 'darwin'; | ||
FSWatcher.prototype._remove = function(directory, item) { | ||
var fullPath, isDirectory, nestedDirectoryChildren, | ||
_this = this; | ||
fullPath = sysPath.join(directory, item); | ||
isDirectory = this.watched[fullPath]; | ||
nestedDirectoryChildren = this._getWatchedDir(fullPath).slice(); | ||
this._removeFromWatchedDir(directory, item); | ||
nestedDirectoryChildren.forEach(function(nestedItem) { | ||
return _this._remove(fullPath, nestedItem); | ||
}); | ||
if (this.options.usePolling) { | ||
fs.unwatchFile(fullPath); | ||
exports.FSWatcher = FSWatcher = (function(_super) { | ||
__extends(FSWatcher, _super); | ||
function FSWatcher(options) { | ||
if (options == null) { | ||
options = {}; | ||
} | ||
this.close = __bind(this.close, this); | ||
FSWatcher.__super__.constructor.apply(this, arguments); | ||
this.watched = Object.create(null); | ||
this.watchers = []; | ||
if (options.persistent == null) { | ||
options.persistent = false; | ||
} | ||
if (options.ignoreInitial == null) { | ||
options.ignoreInitial = false; | ||
} | ||
if (options.ignorePermissionErrors == null) { | ||
options.ignorePermissionErrors = false; | ||
} | ||
if (options.interval == null) { | ||
options.interval = 100; | ||
} | ||
if (options.binaryInterval == null) { | ||
options.binaryInterval = 300; | ||
} | ||
if (options.usePolling == null) { | ||
options.usePolling = false; | ||
} | ||
if (options.useFsEvents == null) { | ||
options.useFsEvents = !options.usePolling && isDarwin; | ||
} | ||
this.enableBinaryInterval = options.binaryInterval !== options.interval; | ||
this._isIgnored = (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; | ||
}; | ||
} | ||
})(options.ignored); | ||
this.options = options; | ||
Object.freeze(options); | ||
} | ||
delete this.watched[fullPath]; | ||
if (!isDirectory) { | ||
return this.emit('unlink', fullPath); | ||
} | ||
}; | ||
FSWatcher.prototype._watch = function(item, itemType, callback) { | ||
var basename, directory, options, parent, watcher, | ||
_this = this; | ||
if (callback == null) { | ||
callback = (function() {}); | ||
} | ||
directory = sysPath.dirname(item); | ||
basename = sysPath.basename(item); | ||
parent = this._getWatchedDir(directory); | ||
options = { | ||
persistent: this.options.persistent | ||
FSWatcher.prototype._getWatchedDir = function(directory) { | ||
var dir, _base; | ||
dir = directory.replace(directoryEndRe, ''); | ||
return (_base = this.watched)[dir] != null ? (_base = this.watched)[dir] : _base[dir] = []; | ||
}; | ||
if (parent.indexOf(basename) !== -1) { | ||
return; | ||
} | ||
this._addToWatchedDir(directory, basename); | ||
if (this.options.usePolling) { | ||
options.interval = this.enableBinaryInterval && isBinary(basename) ? this.options.binaryInterval : this.options.interval; | ||
return fs.watchFile(item, options, function(curr, prev) { | ||
if (curr.mtime.getTime() > prev.mtime.getTime()) { | ||
return callback(item, curr); | ||
FSWatcher.prototype._addToWatchedDir = function(directory, basename) { | ||
var watchedFiles; | ||
watchedFiles = this._getWatchedDir(directory); | ||
return watchedFiles.push(basename); | ||
}; | ||
FSWatcher.prototype._removeFromWatchedDir = function(directory, file) { | ||
var watchedFiles; | ||
watchedFiles = this._getWatchedDir(directory); | ||
return watchedFiles.some(function(watchedFile, index) { | ||
if (watchedFile === file) { | ||
watchedFiles.splice(index, 1); | ||
return true; | ||
} | ||
}); | ||
} else { | ||
watcher = fs.watch(item, options, function(event, path) { | ||
return callback(item); | ||
}; | ||
FSWatcher.prototype._hasReadPermissions = function(stats) { | ||
return Boolean(4 & parseInt((stats.mode & 0x1ff).toString(8)[0])); | ||
}; | ||
FSWatcher.prototype._remove = function(directory, item) { | ||
var fullPath, isDirectory, nestedDirectoryChildren, | ||
_this = this; | ||
fullPath = sysPath.join(directory, item); | ||
isDirectory = this.watched[fullPath]; | ||
nestedDirectoryChildren = this._getWatchedDir(fullPath).slice(); | ||
this._removeFromWatchedDir(directory, item); | ||
nestedDirectoryChildren.forEach(function(nestedItem) { | ||
return _this._remove(fullPath, nestedItem); | ||
}); | ||
return this.watchers.push(watcher); | ||
} | ||
}; | ||
if (this.options.usePolling) { | ||
fs.unwatchFile(fullPath); | ||
} | ||
delete this.watched[fullPath]; | ||
if (isDirectory) { | ||
return this.emit('unlinkDir', fullPath); | ||
} else { | ||
return this.emit('unlink', fullPath); | ||
} | ||
}; | ||
FSWatcher.prototype._handleFile = function(file, stats, initialAdd) { | ||
var _this = this; | ||
if (initialAdd == null) { | ||
initialAdd = false; | ||
} | ||
this._watch(file, 'file', function(file, newStats) { | ||
return _this.emit('change', file, newStats); | ||
}); | ||
if (!(initialAdd && this.options.ignoreInitial)) { | ||
return this.emit('add', file, stats); | ||
} | ||
}; | ||
FSWatcher.prototype._handleDir = function(directory, initialAdd) { | ||
var read, | ||
_this = this; | ||
read = function(directory, initialAdd) { | ||
return fs.readdir(directory, function(error, current) { | ||
var previous; | ||
if (error != null) { | ||
return _this.emit('error', error); | ||
} | ||
if (!current) { | ||
FSWatcher.prototype._watchWithFsEvents = function(path) { | ||
var watcher, | ||
_this = this; | ||
watcher = createFSEventsInstance(path, function(path, flags) { | ||
var emit, info; | ||
if (_this._isIgnored(path)) { | ||
return; | ||
} | ||
previous = _this._getWatchedDir(directory); | ||
previous.filter(function(file) { | ||
return current.indexOf(file) === -1; | ||
}).forEach(function(file) { | ||
return _this._remove(directory, file); | ||
info = fsevents.getInfo(path, flags); | ||
emit = function(event) { | ||
var name; | ||
name = info.type === 'file' ? event : "" + event + "Dir"; | ||
if (event === 'add' || event === 'addDir') { | ||
_this._addToWatchedDir(sysPath.dirname(path), sysPath.basename(path)); | ||
} else if (event === 'unlink' || event === 'unlinkDir') { | ||
_this._remove(sysPath.dirname(path), sysPath.basename(path)); | ||
return; | ||
} | ||
return _this.emit(name, path); | ||
}; | ||
switch (info.event) { | ||
case 'created': | ||
return emit('add'); | ||
case 'modified': | ||
return emit('change'); | ||
case 'deleted': | ||
return emit('unlink'); | ||
case 'moved': | ||
return fs.stat(path, function(error, stats) { | ||
return emit((error || !stats ? 'unlink' : 'add')); | ||
}); | ||
} | ||
}); | ||
return this.watchers.push(watcher); | ||
}; | ||
FSWatcher.prototype._watch = function(item, callback) { | ||
var basename, directory, options, parent, watcher; | ||
if (callback == null) { | ||
callback = (function() {}); | ||
} | ||
directory = sysPath.dirname(item); | ||
basename = sysPath.basename(item); | ||
parent = this._getWatchedDir(directory); | ||
if (parent.indexOf(basename) !== -1) { | ||
return; | ||
} | ||
this._addToWatchedDir(directory, basename); | ||
options = { | ||
persistent: this.options.persistent | ||
}; | ||
if (this.options.usePolling) { | ||
options.interval = this.enableBinaryInterval && isBinary(basename) ? this.options.binaryInterval : this.options.interval; | ||
return fs.watchFile(item, options, function(curr, prev) { | ||
if (curr.mtime.getTime() > prev.mtime.getTime()) { | ||
return callback(item, curr); | ||
} | ||
}); | ||
return current.filter(function(file) { | ||
return previous.indexOf(file) === -1; | ||
}).forEach(function(file) { | ||
return _this._handle(sysPath.join(directory, file), initialAdd); | ||
} else { | ||
watcher = fs.watch(item, options, function(event, path) { | ||
return callback(item); | ||
}); | ||
return this.watchers.push(watcher); | ||
} | ||
}; | ||
FSWatcher.prototype._handleFile = function(file, stats, initialAdd) { | ||
var _this = this; | ||
if (initialAdd == null) { | ||
initialAdd = false; | ||
} | ||
this._watch(file, function(file, newStats) { | ||
return _this.emit('change', file, newStats); | ||
}); | ||
if (!(initialAdd && this.options.ignoreInitial)) { | ||
return this.emit('add', file, stats); | ||
} | ||
}; | ||
read(directory, initialAdd); | ||
return this._watch(directory, 'directory', function(dir) { | ||
return read(dir, false); | ||
}); | ||
}; | ||
FSWatcher.prototype._handle = function(item, initialAdd) { | ||
var _this = this; | ||
if (this._ignored(item)) { | ||
return; | ||
} | ||
return fs.realpath(item, function(error, path) { | ||
if (error && error.code === 'ENOENT') { | ||
FSWatcher.prototype._handleDir = function(directory, stats, initialAdd) { | ||
var read, | ||
_this = this; | ||
read = function(directory, initialAdd) { | ||
return fs.readdir(directory, function(error, current) { | ||
var previous; | ||
if (error != null) { | ||
return _this.emit('error', error); | ||
} | ||
if (!current) { | ||
return; | ||
} | ||
previous = _this._getWatchedDir(directory); | ||
previous.filter(function(file) { | ||
return current.indexOf(file) === -1; | ||
}).forEach(function(file) { | ||
return _this._remove(directory, file); | ||
}); | ||
return current.filter(function(file) { | ||
return previous.indexOf(file) === -1; | ||
}).forEach(function(file) { | ||
return _this._handle(sysPath.join(directory, file), initialAdd); | ||
}); | ||
}); | ||
}; | ||
read(directory, initialAdd); | ||
this._watch(directory, function(dir) { | ||
return read(dir, false); | ||
}); | ||
if (!(initialAdd && this.options.ignoreInitial)) { | ||
return this.emit('addDir', directory, stats); | ||
} | ||
}; | ||
FSWatcher.prototype._handle = function(item, initialAdd) { | ||
var _this = this; | ||
if (this._isIgnored(item)) { | ||
return; | ||
} | ||
if (error != null) { | ||
return _this.emit('error', error); | ||
} | ||
return fs.stat(path, function(error, stats) { | ||
return fs.realpath(item, function(error, path) { | ||
if (error && error.code === 'ENOENT') { | ||
return; | ||
} | ||
if (error != null) { | ||
return _this.emit('error', error); | ||
} | ||
if (_this.options.ignorePermissionErrors && (!_this._hasReadPermissions(stats))) { | ||
return; | ||
return fs.stat(path, function(error, stats) { | ||
if (error != null) { | ||
return _this.emit('error', error); | ||
} | ||
if (_this.options.ignorePermissionErrors && (!_this._hasReadPermissions(stats))) { | ||
return; | ||
} | ||
if (_this._isIgnored.length === 2 && _this._isIgnored(item, stats)) { | ||
return; | ||
} | ||
if (stats.isFile()) { | ||
_this._handleFile(item, stats, initialAdd); | ||
} | ||
if (stats.isDirectory()) { | ||
return _this._handleDir(item, stats, initialAdd); | ||
} | ||
}); | ||
}); | ||
}; | ||
FSWatcher.prototype.emit = function() { | ||
var args, event; | ||
event = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
FSWatcher.__super__.emit.apply(this, [event].concat(__slice.call(args))); | ||
if (event === 'add' || event === 'addDir' || event === 'change' || event === 'unlink' || event === 'unlinkDir') { | ||
return FSWatcher.__super__.emit.apply(this, ['all', event].concat(__slice.call(args))); | ||
} | ||
}; | ||
FSWatcher.prototype._addToFsEvents = function(files) { | ||
var handle, | ||
_this = this; | ||
handle = function(path) { | ||
return _this.emit('add', path); | ||
}; | ||
files.forEach(function(file) { | ||
if (!_this.options.ignoreInitial) { | ||
fs.stat(file, function(error, stats) { | ||
if (error != null) { | ||
return _this.emit('error', error); | ||
} | ||
if (stats.isDirectory()) { | ||
return recursiveReaddir(file, function(error, dirFiles) { | ||
if (error != null) { | ||
return _this.emit('error', error); | ||
} | ||
return dirFiles.filter(function(path) { | ||
return !_this._isIgnored(path); | ||
}).forEach(handle); | ||
}); | ||
} else { | ||
return handle(file); | ||
} | ||
}); | ||
} | ||
if (_this._ignored.length === 2 && _this._ignored(item, stats)) { | ||
return; | ||
return _this._watchWithFsEvents(file); | ||
}); | ||
return this; | ||
}; | ||
FSWatcher.prototype.add = function(files) { | ||
var _this = this; | ||
if (this._initialAdd == null) { | ||
this._initialAdd = true; | ||
} | ||
if (!Array.isArray(files)) { | ||
files = [files]; | ||
} | ||
if (this.options.useFsEvents) { | ||
return this._addToFsEvents(files); | ||
} | ||
files.forEach(function(file) { | ||
return _this._handle(file, _this._initialAdd); | ||
}); | ||
this._initialAdd = false; | ||
return this; | ||
}; | ||
FSWatcher.prototype.close = function() { | ||
var _this = this; | ||
this.watchers.forEach(function(watcher) { | ||
if (_this.options.useFsEvents) { | ||
return watcher.stop(); | ||
} else { | ||
return watcher.close(); | ||
} | ||
if (stats.isFile()) { | ||
_this._handleFile(item, stats, initialAdd); | ||
} | ||
if (stats.isDirectory()) { | ||
return _this._handleDir(item, initialAdd); | ||
} | ||
}); | ||
}); | ||
}; | ||
if (this.options.usePolling) { | ||
Object.keys(this.watched).forEach(function(directory) { | ||
return _this.watched[directory].forEach(function(file) { | ||
return fs.unwatchFile(sysPath.join(directory, file)); | ||
}); | ||
}); | ||
} | ||
this.watched = Object.create(null); | ||
this.removeAllListeners(); | ||
return this; | ||
}; | ||
FSWatcher.prototype.emit = function() { | ||
var args, event; | ||
event = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : []; | ||
FSWatcher.__super__.emit.apply(this, arguments); | ||
if (event === 'add' || event === 'change' || event === 'unlink') { | ||
return FSWatcher.__super__.emit.apply(this, ['all', event].concat(__slice.call(args))); | ||
} | ||
}; | ||
return FSWatcher; | ||
FSWatcher.prototype.add = function(files) { | ||
var _this = this; | ||
if (!Array.isArray(files)) { | ||
files = [files]; | ||
} | ||
files.forEach(function(file) { | ||
return _this._handle(file, true); | ||
}); | ||
return this; | ||
}; | ||
})(EventEmitter); | ||
FSWatcher.prototype.close = function() { | ||
var _this = this; | ||
this.watchers.forEach(function(watcher) { | ||
return watcher.close(); | ||
}); | ||
Object.keys(this.watched).forEach(function(directory) { | ||
return _this.watched[directory].forEach(function(file) { | ||
return fs.unwatchFile(sysPath.join(directory, file)); | ||
}); | ||
}); | ||
this.watched = Object.create(null); | ||
return this; | ||
exports.watch = function(files, options) { | ||
return new FSWatcher(options).add(files); | ||
}; | ||
return FSWatcher; | ||
})(EventEmitter); | ||
exports.watch = function(files, options) { | ||
return new FSWatcher(options).add(files); | ||
}; | ||
}).call(this); |
// Generated by CoffeeScript 1.6.3 | ||
var extensions, exts, isBinary, isBinaryPath, sysPath; | ||
(function() { | ||
var extensions, exts, isBinary, isBinaryPath, sysPath; | ||
sysPath = require('path'); | ||
sysPath = require('path'); | ||
extensions = ['adp', 'au', 'mid', 'mp4a', 'mpga', 'oga', 's3m', 'sil', 'eol', 'dra', 'dts', 'dtshd', 'lvp', 'pya', 'ecelp4800', 'ecelp7470', 'ecelp9600', 'rip', 'weba', 'aac', 'aif', 'caf', 'flac', 'mka', 'm3u', 'wax', 'wma', 'wav', 'xm', 'flac', '3gp', '3g2', 'h261', 'h263', 'h264', 'jpgv', 'jpm', 'mj2', 'mp4', 'mpeg', 'ogv', 'qt', 'uvh', 'uvm', 'uvp', 'uvs', 'dvb', 'fvt', 'mxu', 'pyv', 'uvu', 'viv', 'webm', 'f4v', 'fli', 'flv', 'm4v', 'mkv', 'mng', 'asf', 'vob', 'wm', 'wmv', 'wmx', 'wvx', 'movie', 'smv', 'ts', 'bmp', 'cgm', 'g3', 'gif', 'ief', 'jpg', 'jpeg', 'ktx', 'png', 'btif', 'sgi', 'svg', 'tiff', 'psd', 'uvi', 'sub', 'djvu', 'dwg', 'dxf', 'fbs', 'fpx', 'fst', 'mmr', 'rlc', 'mdi', 'wdp', 'npx', 'wbmp', 'xif', 'webp', '3ds', 'ras', 'cmx', 'fh', 'ico', 'pcx', 'pic', 'pnm', 'pbm', 'pgm', 'ppm', 'rgb', 'tga', 'xbm', 'xpm', 'xwd', 'zip', 'rar', 'tar', 'bz2', 'eot', 'ttf', 'woff']; | ||
extensions = ['adp', 'au', 'mid', 'mp4a', 'mpga', 'oga', 's3m', 'sil', 'eol', 'dra', 'dts', 'dtshd', 'lvp', 'pya', 'ecelp4800', 'ecelp7470', 'ecelp9600', 'rip', 'weba', 'aac', 'aif', 'caf', 'flac', 'mka', 'm3u', 'wax', 'wma', 'wav', 'xm', 'flac', '3gp', '3g2', 'h261', 'h263', 'h264', 'jpgv', 'jpm', 'mj2', 'mp4', 'mpeg', 'ogv', 'qt', 'uvh', 'uvm', 'uvp', 'uvs', 'dvb', 'fvt', 'mxu', 'pyv', 'uvu', 'viv', 'webm', 'f4v', 'fli', 'flv', 'm4v', 'mkv', 'mng', 'asf', 'vob', 'wm', 'wmv', 'wmx', 'wvx', 'movie', 'smv', 'ts', 'bmp', 'cgm', 'g3', 'gif', 'ief', 'jpg', 'jpeg', 'ktx', 'png', 'btif', 'sgi', 'svg', 'tiff', 'psd', 'uvi', 'sub', 'djvu', 'dwg', 'dxf', 'fbs', 'fpx', 'fst', 'mmr', 'rlc', 'mdi', 'wdp', 'npx', 'wbmp', 'xif', 'webp', '3ds', 'ras', 'cmx', 'fh', 'ico', 'pcx', 'pic', 'pnm', 'pbm', 'pgm', 'ppm', 'rgb', 'tga', 'xbm', 'xpm', 'xwd', 'zip', 'rar', 'tar', 'bz2', 'eot', 'ttf', 'woff']; | ||
exts = Object.create(null); | ||
exts = Object.create(null); | ||
extensions.forEach(function(extension) { | ||
return exts[extension] = true; | ||
}); | ||
extensions.forEach(function(extension) { | ||
return exts[extension] = true; | ||
}); | ||
isBinary = function(extension) { | ||
return !!exts[extension]; | ||
}; | ||
isBinary = function(extension) { | ||
return !!exts[extension]; | ||
}; | ||
isBinaryPath = function(path) { | ||
var extension; | ||
extension = sysPath.extname(path).slice(1); | ||
if (extension === '') { | ||
return false; | ||
} | ||
return isBinary(extension); | ||
}; | ||
isBinaryPath = function(path) { | ||
var extension; | ||
extension = sysPath.extname(path).slice(1); | ||
if (extension === '') { | ||
return false; | ||
} | ||
return isBinary(extension); | ||
}; | ||
module.exports = isBinaryPath; | ||
module.exports = isBinaryPath; | ||
}).call(this); |
{ | ||
"name": "chokidar", | ||
"description": "A neat wrapper around node.js fs.watch / fs.watchFile.", | ||
"version": "0.7.1", | ||
"version": "0.8.0", | ||
"keywords": [ | ||
@@ -31,6 +31,8 @@ "fs", | ||
"postpublish": "node setup.js postpublish", | ||
"test": "node setup.js test", | ||
"postinstall": "node setup.js postinstall" | ||
"test": "node setup.js test" | ||
}, | ||
"dependencies": {}, | ||
"optionalDependencies": { | ||
"recursive-readdir": "0.0.2", | ||
"fsevents": "0.1.6" | ||
}, | ||
"devDependencies": { | ||
@@ -41,4 +43,5 @@ "mocha": "~1.7.3", | ||
"sinon-chai": "2.2.0", | ||
"coffee-script": "~1.6.0" | ||
"coffee-script": "~1.6.0", | ||
"rimraf": "~2.2.2" | ||
} | ||
} |
@@ -19,2 +19,6 @@ # Chokidar | ||
Other node.js file watching solutions: | ||
* Super-slow / unreliable on OS X because they are using default node.js APIs | ||
Chokidar resolves these problems. | ||
@@ -38,11 +42,13 @@ | ||
var watcher = chokidar.watch('file or dir', {ignored: /^\./, persistent: true}); | ||
var watcher = chokidar.watch('file or dir', {ignored: /[\/\\]\./, persistent: true}); | ||
watcher | ||
.on('add', function(path) {console.log('File', path, 'has been added');}) | ||
.on('addDir', function(path) {console.log('Directory', path, 'has been added');}) | ||
.on('change', function(path) {console.log('File', path, 'has been changed');}) | ||
.on('unlink', function(path) {console.log('File', path, 'has been removed');}) | ||
.on('unlinkDir', function(path) {console.log('Directory', path, 'has been removed');}) | ||
.on('error', function(error) {console.error('Error happened', error);}) | ||
// 'add' and 'change' events also receive stat() results as second argument. | ||
// 'add', 'addDir' and 'change' events also receive stat() results as second argument. | ||
// http://nodejs.org/api/fs.html#fs_class_fs_stats | ||
@@ -58,6 +64,12 @@ watcher.on('change', function(path, stats) { | ||
watcher.close(); | ||
// One-liner | ||
require('chokidar').watch('.', {ignored: /^\./}).on('all', function(event, path) { | ||
console.log(event, path); | ||
}); | ||
``` | ||
## API | ||
* `chokidar.watch(paths, options)`: takes paths to be watched and options: | ||
* `chokidar.watch(paths, options)`: takes paths to be watched recursively and options: | ||
* `options.ignored` (regexp or function) files to be ignored. | ||
@@ -76,7 +88,9 @@ This function or regexp is tested against the **whole path**, | ||
* `options.interval` (default: `100`). Interval of file system polling. | ||
* `options.binaryInterval` (default: `300`). Interval of file system | ||
* `options.binaryInterval` (default: `300`). Interval of file system | ||
polling for binary files (see extensions in src/is-binary). | ||
* `options.usePolling` (default: `true`). Whether to use fs.watchFile | ||
(backed by polling), or fs.watch. If polling leads to high CPU utilization, | ||
* `options.usePolling` (default: `false`). Whether to use fs.watchFile | ||
(backed by polling), or fs.watch. If polling leads to high CPU utilization, | ||
consider setting this to `false`. | ||
On OS X chokidar uses internal FSEvents API for watching files | ||
instead of `fs.watch`. | ||
@@ -83,0 +97,0 @@ `chokidar.watch()` produces an instance of `FSWatcher`. Methods of `FSWatcher`: |
@@ -64,7 +64,8 @@ var exec = require('child_process').exec; | ||
case 'test': | ||
execute(getBinaryPath('coffee'), '-o lib/ src/'); | ||
execute( | ||
getBinaryPath('mocha'), | ||
'--compilers coffee:coffee-script --require test/common.coffee --colors' | ||
'--compilers coffee:coffee-script --require test/common --colors' | ||
); | ||
break; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
43368
15
433
124
0
2
6
3