dependency-cruiser
dependency-cruiser copied to clipboard
Matching against transitive dependencies (enhance `reachable` rules)
Context
I am trying to figure out where my application is importing a very heavy npm module that should only imported by code that is behind a dynamic import
and React.lazy
, but for some reason it's getting bundled into the main index.js bundle.
Now eventually I'll find it, but I'd love to declare a rule to prevent this from happening again. I can catch if it is directly imported:
{
from: {
path: '^app',
},
to: {
path: '^node_modules/big-heavy-library',
dynamic: false,
}
}
and I can catch when it is loaded transitively:
{
from: {
path: '^app',
},
to: {
path: '^node_modules/big-heavy-library',
reachable: true,
}
}
but I cannot use reachable: true
in combination with dynamic: false
or with other qualifiers. (And it's not clear how dynamic: false
would be interpreted unless combined with a qualifier like "all modules in the via chain", "some modules in the via chain", "no modules in the via chain")
Expected Behavior
I'd like to be able to match against the via
modules, like:
{
comment: "big-heavy-library must be behind a dynamic import",
from: {
path: '^app,
},
// none of the links in the chain are dynamic imports
viaNot: {
dynamic: true
},
to: {
path: '^node_modules/big-heavy-library',
reachable: true,
}
}
Current Behavior
I can either catch transitive imports or static imports, but not static transitive imports.
Possible Solution
Considered alternatives
Make all transitive imports forbidden and use ignore-known
... but first I gotta catch the one that's already in my app.