node-watch
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -54,2 +54,4 @@ var fs = require('fs'); | ||
var pending = false; | ||
module.exports = function hasNativeRecursive(fn) { | ||
@@ -63,2 +65,12 @@ if (!is.func(fn)) { | ||
if (!pending) { | ||
pending = true; | ||
} | ||
// check again later | ||
else { | ||
return setTimeout(function() { | ||
hasNativeRecursive(fn); | ||
}, 300); | ||
} | ||
var stack = new TempStack(); | ||
@@ -80,4 +92,4 @@ var parent = stack.create('dir', TEMP_DIR); | ||
watcher.on('change', function(evt) { | ||
if (/^(rename|change)$/.test(evt)) { | ||
watcher.on('change', function(evt, name) { | ||
if (path.basename(file) == path.basename(name)) { | ||
watcher.close(); | ||
@@ -90,4 +102,3 @@ clearTimeout(timer); | ||
}); | ||
stack.write(file); | ||
} |
@@ -5,2 +5,5 @@ var fs = require('fs'); | ||
var is = { | ||
nil: function(item) { | ||
return (item === null) || (item === undefined); | ||
}, | ||
array: function(item) { | ||
@@ -7,0 +10,0 @@ return Array.isArray(item); |
var fs = require('fs'); | ||
var path = require('path'); | ||
var os = require('os'); | ||
var util = require('util'); | ||
@@ -79,3 +80,3 @@ var events = require('events'); | ||
function debounce(fn, delay) { | ||
var pending, timer, cache = []; | ||
var timer, cache = []; | ||
var info = fn.info; | ||
@@ -86,12 +87,12 @@ function handle() { | ||
}); | ||
timer = pending = null; | ||
timer = null; | ||
cache = []; | ||
} | ||
return function(evt, name) { | ||
name = path.join(info.fpath, name); | ||
cache.push(name); | ||
if (!pending) { | ||
pending = true; | ||
if (is.nil(name)) { | ||
name = ''; | ||
} | ||
cache.push( | ||
path.join(info.fpath, name) | ||
); | ||
if (!timer) { | ||
@@ -205,3 +206,4 @@ timer = setTimeout(handle, delay || 200); | ||
filterGuard(name, function() { | ||
self.emit('change', evt, name); | ||
if (self.flag) self.flag = ''; | ||
else self.emit('change', evt, name); | ||
}); | ||
@@ -212,6 +214,14 @@ } | ||
callback.info = info; | ||
watcher.on('change', debounce(callback)); | ||
watcher.on('error', function(err) { | ||
self.emit('error', err); | ||
if (os.platform() == 'win32' && err.code == 'EPERM') { | ||
watcher.emit('change', EVENT_REMOVE, info.fpath && ''); | ||
self.flag = 'windows-error'; | ||
self.close(fullPath); | ||
} else { | ||
self.emit('error', err); | ||
} | ||
}); | ||
watcher.on('change', debounce(callback)); | ||
} | ||
@@ -244,2 +254,3 @@ | ||
var watcher = fs.watch(dir, options); | ||
self.add(watcher, { | ||
@@ -274,2 +285,5 @@ type: 'dir', | ||
}); | ||
w.on('error', function(err) { | ||
watcher.emit('error', err); | ||
}); | ||
}); | ||
@@ -276,0 +290,0 @@ watcher.close = function() { |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"bugs": { | ||
@@ -17,0 +17,0 @@ "url": "https://github.com/yuanchuan/node-watch/issues" |
@@ -129,17 +129,10 @@ # node-watch | ||
### Known bugs on Windows | ||
1. Failed to detect `remove` event below **node@v4.2.5** | ||
2. Failed to get deleted filename or directory name below **node@v4.2.5** | ||
### Misc | ||
##### 1. Watch mutiple files or directories in one place | ||
##### 1. watch multiple files or directories in one place | ||
```js | ||
watch(['file1', 'file2'], console.log); | ||
``` | ||
##### 2. Catch errors after deleting a watched directory on Windows | ||
```js | ||
watch('somedir', console.log) | ||
.on('error', function() { | ||
// ignore it if you wish. | ||
}); | ||
``` |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
24056
731
0
138