Wrapper library for directory and file watching.

\href{https://travis-ci.org/webpack/watchpack}{\texttt{ }} \href{https://ci.appveyor.com/project/sokra/watchpack/branch/master}{\texttt{ }} \href{https://coveralls.io/r/webpack/watchpack/}{\texttt{ }}\hypertarget{md_sfcode_node_modules_watchpack_README_autotoc_md31824}{}\doxysection{Concept}\label{md_sfcode_node_modules_watchpack_README_autotoc_md31824}
watchpack high level API doesn\textquotesingle{}t map directly to watchers. Instead a three level architecture ensures that for each directory only a single watcher exists.


\begin{DoxyItemize}
\item The high level API requests {\ttfamily Directory\+Watchers} from a {\ttfamily Watcher\+Manager}, which ensures that only a single {\ttfamily Directory\+Watcher} per directory is created.
\item A user-\/faced {\ttfamily Watcher} can be obtained from a {\ttfamily Directory\+Watcher} and provides a filtered view on the {\ttfamily Directory\+Watcher}.
\item Reference-\/counting is used on the {\ttfamily Directory\+Watcher} and {\ttfamily Watcher} to decide when to close them.
\item The real watchers (currently chokidar) are created by the {\ttfamily Directory\+Watcher}.
\item Files are never watched directly. This should keep the watcher count low.
\item Watching can be started in the past. This way watching can start after file reading.
\item Symlinks are not followed, instead the symlink is watched.
\end{DoxyItemize}\hypertarget{md_sfcode_node_modules_watchpack_README_autotoc_md31825}{}\doxysection{API}\label{md_sfcode_node_modules_watchpack_README_autotoc_md31825}

\begin{DoxyCode}{0}
\DoxyCodeLine{var Watchpack = require("{}watchpack"{});}
\DoxyCodeLine{}
\DoxyCodeLine{var wp = new Watchpack(\{}
\DoxyCodeLine{    // options:}
\DoxyCodeLine{    aggregateTimeout: 1000}
\DoxyCodeLine{    // fire "{}aggregated"{} event when after a change for 1000ms no additional change occurred}
\DoxyCodeLine{    // aggregated defaults to undefined, which doesn't fire an "{}aggregated"{} event}
\DoxyCodeLine{}
\DoxyCodeLine{    poll: true}
\DoxyCodeLine{    // poll: true -\/ use polling with the default interval}
\DoxyCodeLine{    // poll: 10000 -\/ use polling with an interval of 10s}
\DoxyCodeLine{    // poll defaults to undefined, which prefer native watching methods}
\DoxyCodeLine{    // Note: enable polling when watching on a network path}
\DoxyCodeLine{}
\DoxyCodeLine{    ignored: /node\_modules/,}
\DoxyCodeLine{    // anymatch-\/compatible definition of files/paths to be ignored}
\DoxyCodeLine{    // see https://github.com/paulmillr/chokidar\#path-\/filtering}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{// Watchpack.prototype.watch(string[] files, string[] directories, [number startTime])}
\DoxyCodeLine{wp.watch(listOfFiles, listOfDirectories, Date.now() -\/ 10000);}
\DoxyCodeLine{// starts watching these files and directories}
\DoxyCodeLine{// calling this again will override the files and directories}
\DoxyCodeLine{}
\DoxyCodeLine{wp.on("{}change"{}, function(filePath, mtime) \{}
\DoxyCodeLine{    // filePath: the changed file}
\DoxyCodeLine{    // mtime: last modified time for the changed file}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{wp.on("{}aggregated"{}, function(changes) \{}
\DoxyCodeLine{    // changes: an array of all changed files}
\DoxyCodeLine{\});}
\DoxyCodeLine{}
\DoxyCodeLine{// Watchpack.prototype.pause()}
\DoxyCodeLine{wp.pause();}
\DoxyCodeLine{// stops emitting events, but keeps watchers open}
\DoxyCodeLine{// next "{}watch"{} call can reuse the watchers}
\DoxyCodeLine{}
\DoxyCodeLine{// Watchpack.prototype.close()}
\DoxyCodeLine{wp.close();}
\DoxyCodeLine{// stops emitting events and closes all watchers}
\DoxyCodeLine{}
\DoxyCodeLine{// Watchpack.prototype.getTimes()}
\DoxyCodeLine{var fileTimes = wp.getTimes();}
\DoxyCodeLine{// returns an object with all know change times for files}
\DoxyCodeLine{// this include timestamps from files not directly watched}
\DoxyCodeLine{// key: absolute path, value: timestamp as number }

\end{DoxyCode}
 