node-watch
Advanced tools
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
| var watch = require('../'); | ||
| watch('/tmp/node-blade',{followSymLinks: true}, function(s) { | ||
| console.log(s); | ||
| }); | ||
+30
-6
@@ -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 | ||
| }); | ||
+4
-1
| { | ||
| "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" |
+12
-7
| #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.'); | ||
| }); | ||
| ``` |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
8393
14.75%8
60%213
14.52%0
-100%42
13.51%