Closed mhdawson closed 4 years ago
@rodion-arr you had already started to investigate, should I assign to you?
Yes, I'll try to dive a bit deeper to understand what's going on inside buildIdealTree()
Looks like depth
property which we rely on represents physical folder structure, not supplied by dependencies tree based on package.json. Here parent
for dep3
from specified example is root node_modules, so it is getting depth=1, according to its physical location.
We can do a workaround and try to rebuild depth properties based on edgesOut
Map which contains dependencies of current node. Not sure that this solution will be stable.
@mhdawson what do you think, is it worth trying?
npm itself is basically removing depth
where possible; really everyone either wants "1" or "infinity". I wouldn't worry about anything in between those two.
@rodion-arr if we followed edgesout instead of children would that get us what we want (even if there is some additional duplication) ?
I mean for this case we will need to build tree by ourselves according to data in edgesOut
@rodion-arr, what I was wondering if in this code:
for (const child of module.children.values()) {
await printModule(child, depth + 1, argv);
}
If it might be as simple as iterating over the edgesout instead of children? Have not had time to try that out yet and thought you might know based on your look at arborist.
@mhdawson, this may work! The only problem I see here is that edgesOut
is Map of Edges
not Nodes
, so they have different set of fields. But it looks like we can use edge.to
property with reference to relevant Node
instance.
I'll try this idea and update
@rodion-arr sounds good. Thanks for trying it out !
We may get packages being duplicated under several deps but I think that's ok as from my perspective that would provide an easier to consume picture of the deps.
See https://github.com/pkgjs/support/pull/12 for more details.
We still don't print out the right output for the structure in: https://github.com/rodion-arr/support/tree/flat_node_modules/test/cli/show-local-tree-flat/node_modules