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

Function buildTree

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

Source from the content-addressed store, hash-verified

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

Callers 1

generateBundleFunction · 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