Rules as a JS file i.e. .dependency-cruiser.js
See original GitHub issueExpected Behavior
It would be nice if the rules can be a .js file
Example:
yarn depcruise --validate .dependency-cruiser.js packages/*/src
Possible Solution
Detect config file extension and load it differently
Context
I’m trying to make general rules for the monorepo, but allow specific packages to extend them differently. For example, our frontend packages have different no-dev-dependency rules than our backend packages (toplevel front-end app packages have no real dependencies once fully built).
The JS file will define a set of common rules, then export 3 variants that extend them via Object.assign
- backend apps, frontend apps, shared libraries. Individual packages will have their own .dependency-cruiser.js
saying e.g.
module.exports = require('@our/build-tools/dependency-cruiser-rules').frontendApp;
This will also open up a lot of possibilities with regards to the configuration - e.g. “from” and “to” could take function predicates.
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
@spion thanks for your elaborate (and very clear) response. It confirmed my suspicion and helped me get focus for #79 that shipped with 4.8.0. JSON only will indeed work just as well now (because
require.resolve
is implied) - but I’ve started to like the javascript variant too much 😄.B.t.w. your webpack set up is nice - I can see how it helps maintain sanity across many repos.
@spion Thanks for testing! I’ve published it to npm as latest (dependency-cruiser@4.7.0).
Inspired by your setup I’ve been playing around with reusable/ composable rule sets - and while
.js
config files increase flexibility to enable it, it required more coding then I liked.This is why I’m playing with the idea to add an
extends
attribute to the config, like what eslint and typescript use - and have depcruise handle the extension stuff automatically.Would this be helpful for your setup?