Socket
Socket
Sign inDemoInstall

node-watch

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-watch - npm Package Compare versions

Comparing version 0.2.9 to 0.3.0

test/hello/hi

36

lib/watch.js

@@ -10,11 +10,16 @@ /**

* Utility functions to synchronously test whether the giving path
* is a file or a directory.
* is a file or a directory or a symbolic link.
*/
var is = (function(ret) {
['file', 'dir'].forEach(function(method) {
var shortcuts = {
'file': 'File'
, 'dir': 'Directory'
, 'sym': 'SymbolicLink'
};
Object.keys(shortcuts).forEach(function(method) {
ret[method] = function(fpath) {
var suffix = ({file: 'File', dir: 'Directory'})[method];
var stat = fs[method === 'sym' ? 'lstatSync' :'statSync'];
if (fs.existsSync(fpath)) {
memo.push(fpath, method);
return fs.statSync(fpath)['is' + suffix]();
return stat(fpath)['is' + shortcuts[method]]();
}

@@ -182,2 +187,9 @@ return false;

*
* Options:
* `recursive`: Watch it recursively or not (defaults to true).
* `followSymLinks`: Follow symbolic links or not (defaults to false).
* `maxSymLevel`: The max number of following symbolic links (defaults to 3).
*
* Example:
*
* watch('fpath', {recursive: true}, function(file) {

@@ -189,2 +201,8 @@ * console.log(file, ' changed');

if (is.sym(fpath)
&& !(options.followSymLinks
&& options.maxSymLevel--)) {
return;
}
// Due to the unstalbe fs.watch(), if the `fpath` is a file then

@@ -216,4 +234,10 @@ // switch to watch its parent directory instead of watch it directly.

// Expose.
module.exports = handleOptions(watch, {recursive: true});
/**
* Set default options and expose.
*/
module.exports = handleOptions(watch, {
recursive: true
, followSymLinks: false
, maxSymLevel: 3
});

5

package.json
{
"name": "node-watch"
, "version": "0.2.9"
, "version": "0.3.0"
, "description": "fs.watch() wrapper of Nodejs "

@@ -9,2 +9,5 @@ , "url": "https://github.com/yuanchuan/node-watch"

, "keywords": ["nodewatch", "watch", "watchfile"]
, "bugs": {
"url": "https://github.com/yuanchuan/node-watch/issues"
}
, "repository": {

@@ -11,0 +14,0 @@ "type": "git"

#Node-watch
This module will watch a directory recursively by default while trying to solve several problems caused by the native fs.watch():
This module will watch a directory **recursively** by default while trying to solve several problems when using the native [fs.watch()](http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener):
1. When modifying a file inside a watched directory, the callback function will be triggered multiple times caused by junkie files generated by the editor;
2. when modifying a watched single file, the callback function will only be triggered one time and then it is unwatched.
1. When modifying a file inside a watched directory, the callback function will be triggered multiple times;
2. when modifying a watched file with an editor like vim, the callback function will only be triggered one time and then it is unwatched.
In current version it does not differentiate event like "rename" or "delete". Once there is a change, the callback function will be triggered.

@@ -30,8 +28,15 @@

`recursive`: [ true | fase ] -- If watch recursively or not. True by default.
`recursive`:Watch it recursively or not (defaults to **true**).
`followSymLinks`: Follow symbolic links or not (defaults to **false**).
`maxSymLevel`: The max number of following symbolic links, in order to prevent circular links (defaults to **3**).
#### Usage
```js
watch('somedir', { recursive: false }, function(filename) {
watch('somedir', { recursive: false, followSymLinks: true }, function(filename) {
console.log(filename, ' changed.');
});
```
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