Comparing version 0.7.1 to 0.8.0
24
index.js
@@ -327,3 +327,3 @@ var fs = require('fs'); | ||
this.watchdir(fullPath); | ||
this.emitEvent(ADD_EVENT, relativePath); | ||
this.emitEvent(ADD_EVENT, relativePath, stat); | ||
} | ||
@@ -340,6 +340,6 @@ } else { | ||
} else if (registered) { | ||
this.emitEvent(CHANGE_EVENT, relativePath); | ||
this.emitEvent(CHANGE_EVENT, relativePath, stat); | ||
} else { | ||
if (this.register(fullPath)) { | ||
this.emitEvent(ADD_EVENT, relativePath); | ||
this.emitEvent(ADD_EVENT, relativePath, stat); | ||
} | ||
@@ -358,3 +358,3 @@ } | ||
Watcher.prototype.emitEvent = function(type, file) { | ||
Watcher.prototype.emitEvent = function(type, file, stat) { | ||
var key = type + '-' + file; | ||
@@ -364,4 +364,4 @@ clearTimeout(this.changeTimers[key]); | ||
delete this.changeTimers[key]; | ||
this.emit(type, file, this.root); | ||
this.emit(ALL_EVENT, type, file, this.root); | ||
this.emit(type, file, this.root, stat); | ||
this.emit(ALL_EVENT, type, file, this.root, stat); | ||
}.bind(this), DEFAULT_DELAY); | ||
@@ -394,6 +394,12 @@ }; | ||
Watcher.prototype.pollerEmit = function(type, file) { | ||
Watcher.prototype.pollerEmit = function(type, file, stat) { | ||
file = path.relative(this.root, file); | ||
this.emit(type, file, this.root); | ||
this.emit(ALL_EVENT, type, file, this.root); | ||
if (type === DELETE_EVENT) { | ||
// Matching the non-polling API | ||
stat = null; | ||
} | ||
this.emit(type, file, this.root, stat); | ||
this.emit(ALL_EVENT, type, file, this.root, stat); | ||
}; | ||
@@ -400,0 +406,0 @@ |
{ | ||
"name": "sane", | ||
"version": "0.7.1", | ||
"version": "0.8.0", | ||
"description": "Sane aims to be fast, small, and reliable file system watcher.", | ||
@@ -33,3 +33,3 @@ "main": "index.js", | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=0.6.0" | ||
}, | ||
@@ -36,0 +36,0 @@ "bugs": { |
@@ -14,4 +14,2 @@ sane | ||
Requires node >= v0.10.0. | ||
``` | ||
@@ -21,2 +19,4 @@ $ npm install sane | ||
If you're using node < v0.10.0 then make sure to start sane with `poll: true`. | ||
## API | ||
@@ -32,4 +32,4 @@ | ||
watcher.on('ready', function () { console.log('ready') }); | ||
watcher.on('change', function (filepath, root) { console.log('file changed', filepath); }); | ||
watcher.on('add', function (filepath, root) { console.log('file added', filepath); }); | ||
watcher.on('change', function (filepath, root, stat) { console.log('file changed', filepath); }); | ||
watcher.on('add', function (filepath, root, stat) { console.log('file added', filepath); }); | ||
watcher.on('delete', function (filepath, root) { console.log('file deleted', filepath); }); | ||
@@ -36,0 +36,0 @@ // close |
@@ -54,3 +54,4 @@ var os = require('os'); | ||
var testfile = jo(testdir, 'file_1'); | ||
this.watcher.on('change', function(filepath, dir) { | ||
this.watcher.on('change', function(filepath, dir, stat) { | ||
assert(stat instanceof fs.Stats); | ||
assert.equal(filepath, path.relative(testdir, testfile)); | ||
@@ -79,3 +80,4 @@ assert.equal(dir, testdir); | ||
var testfile = jo(testdir, 'file_x' + Math.floor(Math.random() * 10000)); | ||
this.watcher.on('add', function(filepath, dir) { | ||
this.watcher.on('add', function(filepath, dir, stat) { | ||
assert(stat instanceof fs.Stats); | ||
assert.equal(filepath, path.relative(testdir, testfile)); | ||
@@ -109,3 +111,3 @@ assert.equal(dir, testdir); | ||
this.watcher.on('all', function(type, filepath, dir) { | ||
this.watcher.on('all', function(type, filepath, dir, stat) { | ||
assert.equal(dir, testdir); | ||
@@ -117,6 +119,9 @@ if (type === 'change') { | ||
} | ||
assert(stat instanceof fs.Stats); | ||
assert.equal(filepath, path.relative(dir, toChange)); | ||
} else if (type === 'delete') { | ||
assert(!stat); | ||
assert.equal(filepath, path.relative(dir, toDelete)); | ||
} else if (type === 'add') { | ||
assert(stat instanceof fs.Stats); | ||
assert.equal(filepath, path.relative(dir, toAdd)); | ||
@@ -155,3 +160,4 @@ added = true; | ||
var subdir = jo(testdir, 'sub_x' + Math.floor(Math.random() * 10000)); | ||
this.watcher.on('add', function(filepath, dir) { | ||
this.watcher.on('add', function(filepath, dir, stat) { | ||
assert(stat instanceof fs.Stats); | ||
assert.equal(filepath, path.relative(testdir, subdir)); | ||
@@ -170,3 +176,4 @@ assert.equal(dir, testdir); | ||
var i = 0; | ||
this.watcher.on('add', function(filepath, dir) { | ||
this.watcher.on('add', function(filepath, dir, stat) { | ||
assert(stat instanceof fs.Stats); | ||
if (++i === 1) { | ||
@@ -173,0 +180,0 @@ assert.equal(filepath, path.relative(testdir, subdir)); |
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
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
22373
6
664