MCPcopy Create free account
hub / github.com/btd/rollup-plugin-visualizer / buildTree

Function buildTree

plugin/data.ts:64–96  ·  view source on GitHub ↗
(
  bundleId: string,
  modules: Array<ModuleLengths & { id: string }>,
  mapper: ModuleMapper,
)

Source from the content-addressed store, hash-verified

62};
63
64export const buildTree = (
65 bundleId: string,
66 modules: Array<ModuleLengths & { id: string }>,
67 mapper: ModuleMapper,
68): ModuleTree => {
69 const tree: ModuleTree = {
70 name: bundleId,
71 children: [],
72 };
73
74 for (const { id, renderedLength, gzipLength, brotliLength } of modules) {
75 const bundleModuleUid = mapper.setNodePart(bundleId, id, {
76 renderedLength,
77 gzipLength,
78 brotliLength,
79 });
80
81 const trimmedModuleId = mapper.trimProjectRootId(id);
82
83 const pathParts = trimmedModuleId.split(/\\|\//).filter((p) => p !== "");
84 addToPath(trimmedModuleId, tree, pathParts, { uid: bundleModuleUid });
85 }
86
87 tree.children = tree.children.map((node) => {
88 if (isModuleTree(node)) {
89 return mergeSingleChildTrees(node);
90 } else {
91 return node;
92 }
93 });
94
95 return tree;
96};
97
98export const mergeTrees = (trees: Array<ModuleTree | ModuleTreeLeaf>): ModuleTree => {
99 const newTree = {

Callers 1

buildReportFunction · 0.85

Calls 5

addToPathFunction · 0.85
isModuleTreeFunction · 0.85
mergeSingleChildTreesFunction · 0.85
setNodePartMethod · 0.80
trimProjectRootIdMethod · 0.80

Tested by

no test coverage detected