UNPKG

2.84 kBMarkdownView Raw
1<div align="center">
2 <img src="https://github.com/marshallcb/jeye/raw/main/docs/jeye.png" alt="jeye" width="75" />
3</div>
4
5<h1 align="center">jeye</h1>
6<h3 align="center">Watch files and their dependencies for changes</h3>
7
8<div align="center">
9 <a href="https://npmjs.org/package/jeye">
10 <img src="https://badgen.now.sh/npm/v/jeye" alt="version" />
11 </a>
12 <a href="https://packagephobia.com/result?p=jeye">
13 <img src="https://badgen.net/packagephobia/install/jeye" alt="install size" />
14 </a>
15</div>
16
17## Overview
18- Watch .js files and their dependencies for changes (combination of [`chokidar`](https://github.com/paulmillr/chokidar) and [`esm-module-lexer`](https://github.com/guybedford/es-module-lexer))
19- Run singular callbacks and aggregate callbacks
20- Requires JS files to be written in ES6 syntax (for import/export analysis)
21- Great for bundle-less build tooling
22
23## Usage
24
25```js
26// CJS
27var { watch } = require('jeye');
28// ES6
29import { watch } from 'jeye';
30
31watch('source', {
32 ignore: /(^|[\/\\])[\._]./ //ignore dot files and files with underscore prefix (_hidden.js)
33}).on('change', (p, { exports, imports, code }) => {
34 console.log(p + ' changed')
35}).on('remove', p => {
36 console.log(p + ' removed')
37}).on('aggregate', (targets, changed) => {
38 console.log(changed.length + ' files changed')
39}).on('ready', (targets) => {
40 console.log("READY")
41})
42```
43
44## API
45
46### `watch(source, options?)`
47
48- `source` : `[String]` or `String` pointing to either directories or individual files
49- `options`
50 - `ignore`: Regex to match all filenames that should be ignored
51 - `only`: Regex to match all files that should be included
52 - `chokidar`: Object to be passed to chokidar options [API](https://github.com/paulmillr/chokidar#api)
53
54### .on(event, callback)
55
56Returns instance of watcher (to allow for chained listeners)
57
58#### Events:
59
60- `change` : `(path, scriptInfo) => { }`
61 - `path` : path relative to cwd of the changed file
62 - `scriptInfo` : only available for JS files with ES6 syntax
63 - `imports` : list of imports exported by the changed file (from [`esm-module-lexer`](https://github.com/guybedford/es-module-lexer))
64 - `exports` : list of exports exported by the changed file (from [`esm-module-lexer`](https://github.com/guybedford/es-module-lexer))
65 - `code` : String of source code for that file (using utf8 encoding)
66
67- `remove` : `(path) => { }`
68 - `path` : path relative to cwd of the deleted file
69
70- `aggregate` : `(total, changed) => { }`
71 - `total`: Object with all target paths as keys and `{ imports, exports, code }` as value
72 - `changed`: Number of target files affected by the most recent edit
73
74- `ready` : `(total, changed) => { }`
75 - `total`: Object with all target paths as keys and `{ imports, exports, code }` as value
76
77
78## License
79
80MIT © [Marshall Brandt](https://m4r.sh)
\No newline at end of file