[entry-point] target
option has captured values from the target dependency when templating ${from}.PROP
#340
Labels
bug
Something isn't working
This plugin is so awesome, I finally can force architectural decisions not only during the code review. Thank you for creating and sharing it!
I think, I've encountered a problem similar to #212
Describe the bug
The
target
option in theboundaries/entry-point
configuration can't be used withfrom
templating, cause instead of captured values forfrom
the values are fromtarget
.To Reproduce
I have a layered project structure like this:
Each main layer I've configured as a different type in the
boundaries/elements
. Also, I'm capturing names of the entities, widgets etc. likefoo
andbar
asslice
and nested content likecomponents
,hooks
etc. assegment
.My goal is to configure
boundaries/entry-point
to allow importing anything inside the same slice, but not between different slices. Different slices should only use publiс module api defined inindex.ts
for importing each other.I'm using the configuration like this:
Other similar configurations with variations on what is defined as the target pattern and what to allow or disallow for it are possible and I tried them, but they all have the same problem, cause they all need to use templating with
${from}
.Expected behavior
This configuration should find errors in imports like:
widgets/foo/components/FooComponent/index.tsx
Additional context
I've looked into the code and found out, that when
elementRulesAllowEntryPoint
is callingelementRulesAllowDependency
, it usesgetElementRules
and passing thedependency
there aselementInfo
arg.After that,
option.rules
are filtered by usingruleMatch
. But bothtargetElement
andfromElement
arguments for theruleMatch
call are assigned toelementInfo
.So inside the matching both
from
andtarget
captured values are assigned the same value coming from thedependency
, not fromelement
I've managed to achieve the desired behaviour by changing the
getElementRules
signature to(elementInfo, options, mainKey, targetElement)
and additionally passingelement
to the function like this:After that, I've changed the
filter
by passing thetargetElement
instead of theelementInfo
inside theruleMatch
:Here is the full patch I've used:
I'm not sure about the motivation behind passing the same
elementInfo
inside theruleMatch
function, so I've decided to open an issue and discuss it first. I can make a PR with this fix, if it wasn't intentional.The text was updated successfully, but these errors were encountered: