Closed karthickshanmugam0689 closed 4 months ago
Hi @karthickshanmugam0689 it seems depedency-cruiser working correctly here. The modules import only the barrel module and it identifies that - in other words the 'index.ts' is the real dependency. In itself it depends on the modules it re-exports.
Technically it is possible (and interesting) to connect re-exports and 'skip' the barrel, but to do so is quite non-trivial (see https://github.com/sverweij/dependency-cruiser/issues/896#issuecomment-1881827884 for some examples) and goes beyond dependency-cruiser's scope. Dependency-cruiser focuses on dependencies between modules as the one thing to do well and not on finer grained analysis.
Also see issues that touched upon the same subject/ are duplicates:
I'll expand this FAQ entry to include the specific scenario of barrel's re-exports.
Is there a possibility with madge to even resolve this barrel files and give us the specific file reference even if it is reexported?
You'd have to ask the maintainer(s) of madge that, but it seems you already did :-)
Ah very true @sverweij . Initially we went to the option of barrel files but then later we felt that it would not be a right choice to go towards barrel files 😞 And yes this question is also asked in madge and yes again, a small copy paste as per the description 😛
Summary
Hi
dependency-cruiser
team,We're using dependency-cruiser to analyze the dependency tree within our monorepo. It works well for identifying dependencies at the package level. However, we encounter an issue when using barrel files for re-exports. We are not able to get the complete dependency including the module from other package inside monorepo which is imported into the particular file
Context
Consider the following project structure
In
libraries/common-util/src/index.ts
we haveInside my
app-1/src/App.ts
, we haveRunning
npx depcruise src
onapp-1
, currently showsRunning
npx depcruise src --max-depth 2
onapp-1
, currently showsThe desired outcome is for depedency-cruiser to identify the actual dependency:
libraries/common-util/src/utils/helper.ts
. But it always resolves to index.ts file of that package or brings in all files reexported in index.ts of that package with--max-depth
option. Is there a possibility with madge to even resolve this barrel files and give us the specific file reference even if it is reexported?Environment