(
bundleId: string,
modules: Array<ModuleLengths & { id: string }>,
mapper: ModuleMapper,
)
| 63 | }; |
| 64 | |
| 65 | export 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 | |
| 99 | export const mergeTrees = (trees: Array<ModuleTree | ModuleTreeLeaf>): ModuleTree => { |
| 100 | const newTree = { |
no test coverage detected