sverweij / dependency-cruiser

Validate and visualize dependencies. Your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
https://npmjs.com/dependency-cruiser
MIT License
5.24k stars 249 forks source link

Question: Rule for forbidding imports from above an entrypoint file location? #960

Open cdanielsen opened 3 hours ago

cdanielsen commented 3 hours ago

Summary

I have a need for a rule I might call something like no-root-folder-ancestor (see context below), that I sense is possible with the forbidden.from/to apis, but my weakness with regex is preventing me from achieving it. I've created a repo below with a minimal reproduction case - would really appreciate any thoughts or suggestions that might get at what I'm after. Thank you, this project is really cool!

Context

I'd like this rule to help me with a project involving migrating files from a large frontend repository with a monolith architecture (everything in one src folder) to a monorepo style (many individual packages). In order to move a chunk of code and the tree of files underneath it from the src folder into a package, I need to understand/mitigate any imports that are reaching out beyond the boundaries of that chunk of code , because packages should be self contained / cannot import things from the old monolith (only other packages).

Environment

cdanielsen commented 3 hours ago

Somewhat similar to https://github.com/sverweij/dependency-cruiser/issues/330