* Processes the provided chunk a. * @param {Chunk} chunkA the target chunk * @param {Chunk} chunkB the chunk to integrate * @returns {void}
(chunkA, chunkB)
| 1078 | * @returns {void} |
| 1079 | */ |
| 1080 | integrateChunks(chunkA, chunkB) { |
| 1081 | // Decide for one name (deterministic) |
| 1082 | if (chunkA.name && chunkB.name) { |
| 1083 | if ( |
| 1084 | this.getNumberOfEntryModules(chunkA) > 0 === |
| 1085 | this.getNumberOfEntryModules(chunkB) > 0 |
| 1086 | ) { |
| 1087 | // When both chunks have entry modules or none have one, use |
| 1088 | // shortest name |
| 1089 | if (chunkA.name.length !== chunkB.name.length) { |
| 1090 | chunkA.name = |
| 1091 | chunkA.name.length < chunkB.name.length ? chunkA.name : chunkB.name; |
| 1092 | } else { |
| 1093 | chunkA.name = chunkA.name < chunkB.name ? chunkA.name : chunkB.name; |
| 1094 | } |
| 1095 | } else if (this.getNumberOfEntryModules(chunkB) > 0) { |
| 1096 | // Pick the name of the chunk with the entry module |
| 1097 | chunkA.name = chunkB.name; |
| 1098 | } |
| 1099 | } else if (chunkB.name) { |
| 1100 | chunkA.name = chunkB.name; |
| 1101 | } |
| 1102 | |
| 1103 | // Merge id name hints |
| 1104 | for (const hint of chunkB.idNameHints) { |
| 1105 | chunkA.idNameHints.add(hint); |
| 1106 | } |
| 1107 | |
| 1108 | // Merge runtime |
| 1109 | chunkA.runtime = mergeRuntime(chunkA.runtime, chunkB.runtime); |
| 1110 | |
| 1111 | // getChunkModules is used here to create a clone, because disconnectChunkAndModule modifies |
| 1112 | for (const module of this.getChunkModules(chunkB)) { |
| 1113 | this.disconnectChunkAndModule(chunkB, module); |
| 1114 | this.connectChunkAndModule(chunkA, module); |
| 1115 | } |
| 1116 | |
| 1117 | for (const [ |
| 1118 | module, |
| 1119 | chunkGroup |
| 1120 | ] of this.getChunkEntryModulesWithChunkGroupIterable(chunkB)) { |
| 1121 | this.disconnectChunkAndEntryModule(chunkB, module); |
| 1122 | this.connectChunkAndEntryModule( |
| 1123 | chunkA, |
| 1124 | module, |
| 1125 | /** @type {Entrypoint} */ |
| 1126 | (chunkGroup) |
| 1127 | ); |
| 1128 | } |
| 1129 | |
| 1130 | for (const chunkGroup of chunkB.groupsIterable) { |
| 1131 | chunkGroup.replaceChunk(chunkB, chunkA); |
| 1132 | chunkA.addGroup(chunkGroup); |
| 1133 | chunkB.removeGroup(chunkGroup); |
| 1134 | } |
| 1135 | ChunkGraph.clearChunkGraphForChunk(chunkB); |
| 1136 | } |
| 1137 |
no test coverage detected