mrca
most recent common ancestor: find ancestors for changed files
- Builds & caches a dependency tree via static analysis
- Tracks file changes
- Determines which ancestor files are affected by a change to a file in the dependency tree
Used by Mocha to determine which tests to rerun (in "watch" mode) given a file change.
Install
$ npm install mrca
Usage
// ModuleMap extends Map<string,ModuleMapNode>const ModuleMap = ; const moduleMap = ModuleMap; // keys of `moduleMap` are absolute filepaths, and the values are `ModuleMapNode` objects// contain lists of `parents`, `children` and related `entryFiles`.// a cache of the tree is maintained and updated as files change // ..time passes, and stuff happens to a transitive dependency (quux.js) of foo.js..// we probably want something like chokidar to tell us when a file we're watching has changed // here, we ask the module map which of our entry files (foo.js, bar.js, above)// were potentially affected. passing an array of filepaths here is optional; in our case// we _know_ that quux.js changed, so we're giving it a "hint"const allFiles entryFiles = moduleMap; // in actuality, these paths are all absolute relative to a `cwd` option// to the `ModuleMap` constructor, which defaults to `process.cwd()`entryFiles; // true// bar.js is not an ancestor of quux.js, so it's not hereentryFiles; // false // entryFiles is a strict subset of allFilesallFiles; // trueallFiles; // true// foo.js depends on baz.js which depends on quux.jsallFiles; // true
License
Copyright © 2020 Christopher Hiller. Licensed Apache-2.0