Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / chokidar / README.md
1 # Chokidar [![Mac/Linux Build Status](https://img.shields.io/travis/paulmillr/chokidar/master.svg?label=Mac%20OSX%20%26%20Linux)](https://travis-ci.org/paulmillr/chokidar) [![Windows Build status](https://img.shields.io/appveyor/ci/es128/chokidar/master.svg?label=Windows)](https://ci.appveyor.com/project/es128/chokidar/branch/master) [![Coverage Status](https://coveralls.io/repos/paulmillr/chokidar/badge.svg)](https://coveralls.io/r/paulmillr/chokidar) [![Join the chat at https://gitter.im/paulmillr/chokidar](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/paulmillr/chokidar?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2
3 > A neat wrapper around node.js fs.watch / fs.watchFile / fsevents.
4
5 [![NPM](https://nodei.co/npm-dl/chokidar.png)](https://nodei.co/npm/chokidar/)
6 [![NPM](https://nodei.co/npm/chokidar.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/chokidar/)
7
8 ## Why?
9 Node.js `fs.watch`:
10
11 * Doesn't report filenames on OS X.
12 * Doesn't report events at all when using editors like Sublime on OS X.
13 * Often reports events twice.
14 * Emits most changes as `rename`.
15 * Has [a lot of other issues](https://github.com/joyent/node/search?q=fs.watch&type=Issues)
16 * Does not provide an easy way to recursively watch file trees.
17
18 Node.js `fs.watchFile`:
19
20 * Almost as bad at event handling.
21 * Also does not provide any recursive watching.
22 * Results in high CPU utilization.
23
24 Chokidar resolves these problems.
25
26 Initially made for [brunch](http://brunch.io) (an ultra-swift web app build tool), it is now used in
27 [gulp](https://github.com/gulpjs/gulp/),
28 [karma](http://karma-runner.github.io),
29 [PM2](https://github.com/Unitech/PM2),
30 [browserify](http://browserify.org/),
31 [webpack](http://webpack.github.io/),
32 [BrowserSync](http://www.browsersync.io/),
33 [Microsoft's Visual Studio Code](https://github.com/microsoft/vscode),
34 and [many others](https://www.npmjs.org/browse/depended/chokidar/).
35 It has proven itself in production environments.
36
37 ## How?
38 Chokidar does still rely on the Node.js core `fs` module, but when using
39 `fs.watch` and `fs.watchFile` for watching, it normalizes the events it
40 receives, often checking for truth by getting file stats and/or dir contents.
41
42 On Mac OS X, chokidar by default uses a native extension exposing the Darwin
43 `FSEvents` API. This provides very efficient recursive watching compared with
44 implementations like `kqueue` available on most \*nix platforms. Chokidar still
45 does have to do some work to normalize the events received that way as well.
46
47 On other platforms, the `fs.watch`-based implementation is the default, which
48 avoids polling and keeps CPU usage down. Be advised that chokidar will initiate
49 watchers recursively for everything within scope of the paths that have been
50 specified, so be judicious about not wasting system resources by watching much
51 more than needed.
52
53 ## Getting started
54 Install with npm:
55
56     npm install chokidar --save
57
58 Then `require` and use it in your code:
59
60 ```javascript
61 var chokidar = require('chokidar');
62
63 // One-liner for current directory, ignores .dotfiles
64 chokidar.watch('.', {ignored: /[\/\\]\./}).on('all', (event, path) => {
65   console.log(event, path);
66 });
67 ```
68
69 ```javascript
70 // Example of a more typical implementation structure:
71
72 // Initialize watcher.
73 var watcher = chokidar.watch('file, dir, glob, or array', {
74   ignored: /[\/\\]\./,
75   persistent: true
76 });
77
78 // Something to use when events are received.
79 var log = console.log.bind(console);
80 // Add event listeners.
81 watcher
82   .on('add', path => log(`File ${path} has been added`))
83   .on('change', path => log(`File ${path} has been changed`))
84   .on('unlink', path => log(`File ${path} has been removed`));
85
86 // More possible events.
87 watcher
88   .on('addDir', path => log(`Directory ${path} has been added`))
89   .on('unlinkDir', path => log(`Directory ${path} has been removed`))
90   .on('error', error => log(`Watcher error: ${error}`))
91   .on('ready', () => log('Initial scan complete. Ready for changes'))
92   .on('raw', (event, path, details) => {
93     log('Raw event info:', event, path, details);
94   });
95
96 // 'add', 'addDir' and 'change' events also receive stat() results as second
97 // argument when available: http://nodejs.org/api/fs.html#fs_class_fs_stats
98 watcher.on('change', (path, stats) => {
99   if (stats) console.log(`File ${path} changed size to ${stats.size}`);
100 });
101
102 // Watch new files.
103 watcher.add('new-file');
104 watcher.add(['new-file-2', 'new-file-3', '**/other-file*']);
105
106 // Get list of actual paths being watched on the filesystem
107 var watchedPaths = watcher.getWatched();
108
109 // Un-watch some files.
110 watcher.unwatch('new-file*');
111
112 // Stop watching.
113 watcher.close();
114
115 // Full list of options. See below for descriptions. (do not use this example)
116 chokidar.watch('file', {
117   persistent: true,
118
119   ignored: '*.txt',
120   ignoreInitial: false,
121   followSymlinks: true,
122   cwd: '.',
123
124   usePolling: true,
125   interval: 100,
126   binaryInterval: 300,
127   alwaysStat: false,
128   depth: 99,
129   awaitWriteFinish: {
130     stabilityThreshold: 2000,
131     pollInterval: 100
132   },
133
134   ignorePermissionErrors: false,
135   atomic: true // or a custom 'atomicity delay', in milliseconds (default 100)
136 });
137
138 ```
139
140 ## API
141
142 `chokidar.watch(paths, [options])`
143
144 * `paths` (string or array of strings). Paths to files, dirs to be watched
145 recursively, or glob patterns.
146 * `options` (object) Options object as defined below:
147
148 #### Persistence
149
150 * `persistent` (default: `true`). Indicates whether the process
151 should continue to run as long as files are being watched. If set to
152 `false` when using `fsevents` to watch, no more events will be emitted
153 after `ready`, even if the process continues to run.
154
155 #### Path filtering
156
157 * `ignored` ([anymatch](https://github.com/es128/anymatch)-compatible definition)
158 Defines files/paths to be ignored. The whole relative or absolute path is
159 tested, not just filename. If a function with two arguments is provided, it
160 gets called twice per path - once with a single argument (the path), second
161 time with two arguments (the path and the
162 [`fs.Stats`](http://nodejs.org/api/fs.html#fs_class_fs_stats)
163 object of that path).
164 * `ignoreInitial` (default: `false`). If set to `false` then `add`/`addDir` events are also emitted for matching paths while
165 instantiating the watching as chokidar discovers these file paths (before the `ready` event).
166 * `followSymlinks` (default: `true`). When `false`, only the
167 symlinks themselves will be watched for changes instead of following
168 the link references and bubbling events through the link's path.
169 * `cwd` (no default). The base directory from which watch `paths` are to be
170 derived. Paths emitted with events will be relative to this.
171
172 #### Performance
173
174 * `usePolling` (default: `false`).
175 Whether to use fs.watchFile (backed by polling), or fs.watch. If polling
176 leads to high CPU utilization, consider setting this to `false`. It is
177 typically necessary to **set this to `true` to successfully watch files over
178 a network**, and it may be necessary to successfully watch files in other
179 non-standard situations. Setting to `true` explicitly on OS X overrides the
180 `useFsEvents` default. You may also set the CHOKIDAR_USEPOLLING env variable
181 to true (1) or false (0) in order to override this option.
182 * _Polling-specific settings_ (effective when `usePolling: true`)
183   * `interval` (default: `100`). Interval of file system polling.
184   * `binaryInterval` (default: `300`). Interval of file system
185   polling for binary files.
186   ([see list of binary extensions](https://github.com/sindresorhus/binary-extensions/blob/master/binary-extensions.json))
187 * `useFsEvents` (default: `true` on OS X). Whether to use the
188 `fsevents` watching interface if available. When set to `true` explicitly
189 and `fsevents` is available this supercedes the `usePolling` setting. When
190 set to `false` on OS X, `usePolling: true` becomes the default.
191 * `alwaysStat` (default: `false`). If relying upon the
192 [`fs.Stats`](http://nodejs.org/api/fs.html#fs_class_fs_stats)
193 object that may get passed with `add`, `addDir`, and `change` events, set
194 this to `true` to ensure it is provided even in cases where it wasn't
195 already available from the underlying watch events.
196 * `depth` (default: `undefined`). If set, limits how many levels of
197 subdirectories will be traversed.
198 * `awaitWriteFinish` (default: `false`).
199 By default, the `add` event will fire when a file first appear on disk, before
200 the entire file has been written. Furthermore, in some cases some `change`
201 events will be emitted while the file is being written. In some cases,
202 especially when watching for large files there will be a need to wait for the
203 write operation to finish before responding to a file creation or modification.
204 Setting `awaitWriteFinish` to `true` (or a truthy value) will poll file size,
205 holding its `add` and `change` events until the size does not change for a
206 configurable amount of time. The appropriate duration setting is heavily
207 dependent on the OS and hardware. For accurate detection this parameter should
208 be relatively high, making file watching much less responsive.
209 Use with caution.
210   * *`options.awaitWriteFinish` can be set to an object in order to adjust
211   timing params:*
212   * `awaitWriteFinish.stabilityThreshold` (default: 2000). Amount of time in
213   milliseconds for a file size to remain constant before emitting its event.
214   * `awaitWriteFinish.pollInterval` (default: 100). File size polling interval.
215
216 #### Errors
217 * `ignorePermissionErrors` (default: `false`). Indicates whether to watch files
218 that don't have read permissions if possible. If watching fails due to `EPERM`
219 or `EACCES` with this set to `true`, the errors will be suppressed silently.
220 * `atomic` (default: `true` if `useFsEvents` and `usePolling` are `false`).
221 Automatically filters out artifacts that occur when using editors that use
222 "atomic writes" instead of writing directly to the source file. If a file is
223 re-added within 100 ms of being deleted, Chokidar emits a `change` event
224 rather than `unlink` then `add`. If the default of 100 ms does not work well
225 for you, you can override it by setting `atomic` to a custom value, in
226 milliseconds.
227
228 ### Methods & Events
229
230 `chokidar.watch()` produces an instance of `FSWatcher`. Methods of `FSWatcher`:
231
232 * `.add(path / paths)`: Add files, directories, or glob patterns for tracking.
233 Takes an array of strings or just one string.
234 * `.on(event, callback)`: Listen for an FS event.
235 Available events: `add`, `addDir`, `change`, `unlink`, `unlinkDir`, `ready`,
236 `raw`, `error`.
237 Additionally `all` is available which gets emitted with the underlying event
238 name and path for every event other than `ready`, `raw`, and `error`.
239 * `.unwatch(path / paths)`: Stop watching files, directories, or glob patterns.
240 Takes an array of strings or just one string.
241 * `.close()`: Removes all listeners from watched files.
242 * `.getWatched()`: Returns an object representing all the paths on the file
243 system being watched by this `FSWatcher` instance. The object's keys are all the
244 directories (using absolute paths unless the `cwd` option was used), and the
245 values are arrays of the names of the items contained in each directory.
246
247 ## CLI
248
249 If you need a CLI interface for your file watching, check out
250 [chokidar-cli](https://github.com/kimmobrunfeldt/chokidar-cli), allowing you to
251 execute a command on each change, or get a stdio stream of change events.
252
253 ## Install Troubleshooting
254
255 * `npm WARN optional dep failed, continuing fsevents@n.n.n`
256   * This message is normal part of how `npm` handles optional dependencies and is
257     not indicative of a problem. Even if accompanied by other related error messages,
258     Chokidar should function properly.
259
260 * `ERR! stack Error: Python executable "python" is v3.4.1, which is not supported by gyp.`
261   * You should be able to resolve this by installing python 2.7 and running:
262     `npm config set python python2.7`
263
264 * `gyp ERR! stack Error: not found: make`
265   * On Mac, install the XCode command-line tools
266
267 ## License
268
269 The MIT License (MIT)
270
271 Copyright (c) 2016 Paul Miller (http://paulmillr.com) & Elan Shanker
272
273 Permission is hereby granted, free of charge, to any person obtaining a copy
274 of this software and associated documentation files (the “Software”), to deal
275 in the Software without restriction, including without limitation the rights
276 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
277 copies of the Software, and to permit persons to whom the Software is
278 furnished to do so, subject to the following conditions:
279
280 The above copyright notice and this permission notice shall be included in
281 all copies or substantial portions of the Software.
282
283 THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
284 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
285 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
286 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
287 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
288 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
289 THE SOFTWARE.