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