question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rules as a JS file i.e. .dependency-cruiser.js

See original GitHub issue

Expected 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:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sverweijcommented, Dec 11, 2018

@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.

1reaction
sverweijcommented, Dec 2, 2018

@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?

module.exports = {
  extends: './.dependency-cruiser-base',  // or something like  'dependency-cruiser/rules/base', or ....
  forbidden: [
    // rules specific for current repo/ folder + overrides of the 'extends' where necessary
  ],
  options: {
    // options specific for current repo/ folder/ ... like webpack configs, tsconfs, 
    // paths not to follow, ...
  }
}

Read more comments on GitHub >

github_iconTop Results From Across the Web

sverweij/dependency-cruiser: Validate and visualize ... - GitHub
Validate things​​ dependency-cruiser. js that make sense in most projects, like detecting circular dependencies, dependencies missing in package. json, orphans, ...
Read more >
How to easily visualize a project's dependency graph with ...
Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD. I think visualizing projects is ...
Read more >
How to enforce dependency rules in javascript/typescript ...
You can use dependency cruiser to validate code base against your own rules based on regex literals. You can use it as part...
Read more >
Small but Useful Habits to maintain a Node.js app
Finding good resources to create an app from scratch is relatively easy, but how to maintain it over time is a different story...
Read more >
dependency-cruiser - npm Package Health Analysis - Snyk
dependency -cruiser. v12.1.1. Validate and visualize dependencies. With your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found