- Watch .js files and their dependencies for changes (combination of
chokidar
andesm-module-lexer
) - Run singular callbacks and aggregate callbacks
- Requires JS files to be written in ES6 syntax (for import/export analysis)
- Great for bundle-less build tooling
// CJS
var { watch } = require('jeye');
// ES6
import { watch } from 'jeye';
watch('source', {
ignore: /(^|[\/\\])[\._]./ //ignore dot files and files with underscore prefix (_hidden.js)
}).on('change', (p, { exports, imports, code }) => {
console.log(p + ' changed')
}).on('remove', p => {
console.log(p + ' removed')
}).on('aggregate', (targets, changed) => {
console.log(changed.length + ' files changed')
}).on('ready', (targets) => {
console.log("READY")
})
source
:[String]
orString
pointing to either directories or individual filesoptions
ignore
: Regex to match all filenames that should be ignoredonly
: Regex to match all files that should be includedchokidar
: Object to be passed to chokidar options API
Returns instance of watcher (to allow for chained listeners)
-
change
:(path, scriptInfo) => { }
path
: path relative to cwd of the changed filescriptInfo
: only available for JS files with ES6 syntaximports
: list of imports exported by the changed file (fromesm-module-lexer
)exports
: list of exports exported by the changed file (fromesm-module-lexer
)code
: String of source code for that file (using utf8 encoding)
-
remove
:(path) => { }
path
: path relative to cwd of the deleted file
-
aggregate
:(total, changed) => { }
total
: Object with all target paths as keys and{ imports, exports, code }
as valuechanged
: Number of target files affected by the most recent edit
-
ready
:(total, changed) => { }
total
: Object with all target paths as keys and{ imports, exports, code }
as value
MIT © Marshall Brandt