node-watch
Advanced tools
Comparing version 0.5.6 to 0.5.7
# Changelog | ||
## 0.5.7 | ||
* add `delay` option and set default to 100ms. | ||
## 0.5.6 | ||
@@ -4,0 +7,0 @@ * Fix recursive watch with filter option. |
var fs = require('fs'); | ||
var path = require('path'); | ||
function matchObject(item, str) { | ||
return Object.prototype.toString.call(item) | ||
=== '[object ' + str + ']'; | ||
} | ||
var is = { | ||
@@ -15,10 +20,13 @@ nil: function(item) { | ||
regExp: function(item) { | ||
return Object.prototype.toString.call(item) == '[object RegExp]'; | ||
return matchObject(item, 'RegExp'); | ||
}, | ||
string: function(item) { | ||
return typeof item === 'string'; | ||
return matchObject(item, 'String'); | ||
}, | ||
func: function(item) { | ||
return typeof item === 'function'; | ||
return matchObject(item, 'Function'); | ||
}, | ||
number: function(item) { | ||
return matchObject(item, 'Number'); | ||
}, | ||
exists: function(name) { | ||
@@ -25,0 +33,0 @@ return fs.existsSync(name); |
@@ -98,6 +98,10 @@ var fs = require('fs'); | ||
function debounce(fn, delay) { | ||
function debounce(fn) { | ||
var timer, cache = []; | ||
var info = fn.info; | ||
var encoding = info.options.encoding; | ||
var delay = info.options.delay; | ||
if (!is.number(delay)) { | ||
delay = 100; | ||
} | ||
function handle() { | ||
@@ -122,3 +126,3 @@ getMessages(cache).forEach(function(msg) { | ||
if (!timer) { | ||
timer = setTimeout(handle, delay || 200); | ||
timer = setTimeout(handle, delay); | ||
} | ||
@@ -125,0 +129,0 @@ } |
@@ -14,3 +14,3 @@ { | ||
], | ||
"version": "0.5.6", | ||
"version": "0.5.7", | ||
"bugs": { | ||
@@ -17,0 +17,0 @@ "url": "https://github.com/yuanchuan/node-watch/issues" |
@@ -61,3 +61,11 @@ # node-watch [![Status](https://travis-ci.org/yuanchuan/node-watch.svg?branch=master)](https://travis-ci.org/yuanchuan/node-watch "See test builds") | ||
``` | ||
* `delay: Number` (in ms, default **100**) | ||
Delay time of the callback function. | ||
```js | ||
// log after 5 seconds | ||
watch('./', { delay: 5000 }, console.log); | ||
``` | ||
## Events | ||
@@ -125,2 +133,6 @@ | ||
**MacOS, node 0.10.x** | ||
* Will emit double event if the directory name is of one single character. | ||
## Misc | ||
@@ -151,2 +163,10 @@ | ||
#### 3. Got ENOSPC error? | ||
If you get ENOSPC error, but you actually have free disk space - it means that your OS watcher limit is too low and you probably want to recursively watch a big tree of files. | ||
Follow this description to increase the limit: | ||
[https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit](https://confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+Limit) | ||
## Alternatives | ||
@@ -158,5 +178,19 @@ | ||
## Contributors | ||
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
<!-- prettier-ignore --> | ||
| [<img src="https://avatars1.githubusercontent.com/u/250426?v=4" width="100px;"/><br /><sub><b>Yuan Chuan</b></sub>](http://yuanchuan.name)<br />[💻](https://github.com/yuanchuan/node-watch/commits?author=yuanchuan "Code") [📖](https://github.com/yuanchuan/node-watch/commits?author=yuanchuan "Documentation") [⚠️](https://github.com/yuanchuan/node-watch/commits?author=yuanchuan "Tests") | [<img src="https://avatars2.githubusercontent.com/u/99367?v=4" width="100px;"/><br /><sub><b>Greg Thornton</b></sub>](http://xdissent.com)<br />[💻](https://github.com/yuanchuan/node-watch/commits?author=xdissent "Code") [🤔](#ideas-xdissent "Ideas, Planning, & Feedback") | [<img src="https://avatars1.githubusercontent.com/u/6019373?v=4" width="100px;"/><br /><sub><b>Amir Arad</b></sub>](https://github.com/amir-arad)<br />[💻](https://github.com/yuanchuan/node-watch/commits?author=amir-arad "Code") [📖](https://github.com/yuanchuan/node-watch/commits?author=amir-arad "Documentation") [⚠️](https://github.com/yuanchuan/node-watch/commits?author=amir-arad "Tests") | [<img src="https://avatars0.githubusercontent.com/u/693642?v=4" width="100px;"/><br /><sub><b>Gary Burgess</b></sub>](http://slipthrough.net)<br />[💻](https://github.com/yuanchuan/node-watch/commits?author=garyb "Code") | [<img src="https://avatars2.githubusercontent.com/u/557895?v=4" width="100px;"/><br /><sub><b>Peter deHaan</b></sub>](http://about.me/peterdehaan)<br />[💻](https://github.com/yuanchuan/node-watch/commits?author=pdehaan "Code") | [<img src="https://avatars2.githubusercontent.com/u/161968?v=4" width="100px;"/><br /><sub><b>kcliu</b></sub>](https://medium.com/@kcliu)<br />[💻](https://github.com/yuanchuan/node-watch/commits?author=kcliu "Code") | [<img src="https://avatars3.githubusercontent.com/u/309006?v=4" width="100px;"/><br /><sub><b>Hoovinator</b></sub>](https://github.com/crh3675)<br />[💬](#question-crh3675 "Answering Questions") | | ||
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | | ||
| [<img src="https://avatars3.githubusercontent.com/u/142875?v=4" width="100px;"/><br /><sub><b>Steve Shreeve</b></sub>](https://github.com/shreeve)<br />[💻](https://github.com/yuanchuan/node-watch/commits?author=shreeve "Code") | | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! | ||
## License | ||
MIT | ||
Copyright (c) 2012-2017 [yuanchuan](https://github.com/yuanchuan) | ||
Copyright (c) 2012-2018 [yuanchuan](https://github.com/yuanchuan) |
@@ -133,3 +133,3 @@ var assert = require('assert'); | ||
var dir = tree.getPath('home'); | ||
var file = tree.getPath('home/d/file1'); | ||
var file = tree.getPath('home/bb/file1'); | ||
watcher = watch(dir, { recursive: true }, function(evt, name) { | ||
@@ -139,3 +139,3 @@ assert.equal(file, name); | ||
}); | ||
tree.modify('home/d/file1', 1000); | ||
tree.modify('home/bb/file1', 300); | ||
}); | ||
@@ -238,4 +238,4 @@ }); | ||
var dir = tree.getPath('home'); | ||
var file1 = 'home/a/file1'; | ||
var file2 = 'home/a/file2'; | ||
var file1 = 'home/bb/file1'; | ||
var file2 = 'home/bb/file2'; | ||
@@ -253,3 +253,3 @@ var options = { | ||
if (name == tree.getPath(file2)) { | ||
assert(times, 1, 'home/a/file1 should be ignored.'); | ||
assert(times, 1, 'home/bb/file1 should be ignored.'); | ||
done(); | ||
@@ -265,4 +265,4 @@ } | ||
var dir = tree.getPath('home'); | ||
var file1 = 'home/a/file1'; | ||
var file2 = 'home/a/file2'; | ||
var file1 = 'home/bb/file1'; | ||
var file2 = 'home/bb/file2'; | ||
@@ -278,3 +278,3 @@ var options = { | ||
if (name == tree.getPath(file2)) { | ||
assert(times, 1, 'home/a/file1 should be ignored.'); | ||
assert(times, 1, 'home/bb/file1 should be ignored.'); | ||
done(); | ||
@@ -287,4 +287,21 @@ } | ||
}); | ||
}); | ||
describe('delay', function() { | ||
it('should have delayed response', function(done) { | ||
var dir = tree.getPath('home/a'); | ||
var file = 'home/a/file1'; | ||
var fpath = tree.getPath(file); | ||
var start; | ||
watcher = watch(dir, { delay: 1000 }, function(evt, name) { | ||
assert(Date.now() - start > 1000, 'delay not working'); | ||
done(); | ||
}); | ||
setTimeout(function() { | ||
tree.modify(file); | ||
start = Date.now(); | ||
}, 200); | ||
}); | ||
}); | ||
}); | ||
@@ -291,0 +308,0 @@ |
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
37451
13
947
193