( compilation, blocksWithNestedBlocks, blockConnections, maskByChunk )
| 1338 | * @param {MaskByChunk} maskByChunk mapping from chunk to module mask |
| 1339 | */ |
| 1340 | const connectChunkGroups = ( |
| 1341 | compilation, |
| 1342 | blocksWithNestedBlocks, |
| 1343 | blockConnections, |
| 1344 | maskByChunk |
| 1345 | ) => { |
| 1346 | const { chunkGraph } = compilation; |
| 1347 | |
| 1348 | /** |
| 1349 | * Helper function to check if all modules of a chunk are available |
| 1350 | * @param {ChunkGroup} chunkGroup the chunkGroup to scan |
| 1351 | * @param {bigint} availableModules the comparator set |
| 1352 | * @returns {boolean} return true if all modules of a chunk are available |
| 1353 | */ |
| 1354 | const areModulesAvailable = (chunkGroup, availableModules) => { |
| 1355 | for (const chunk of chunkGroup.chunks) { |
| 1356 | const chunkMask = /** @type {bigint} */ (maskByChunk.get(chunk)); |
| 1357 | if ((chunkMask & availableModules) !== chunkMask) return false; |
| 1358 | } |
| 1359 | return true; |
| 1360 | }; |
| 1361 | |
| 1362 | // For each edge in the basic chunk graph |
| 1363 | for (const [block, connections] of blockConnections) { |
| 1364 | // 1. Check if connection is needed |
| 1365 | // When none of the dependencies need to be connected |
| 1366 | // we can skip all of them |
| 1367 | // It's not possible to filter each item so it doesn't create inconsistent |
| 1368 | // connections and modules can only create one version |
| 1369 | // TODO maybe decide this per runtime |
| 1370 | if ( |
| 1371 | // Blocks with nested blocks must stay connected — skipping orphans the |
| 1372 | // nested block's chunk group from this block's chunk group parent. |
| 1373 | !blocksWithNestedBlocks.has(block) && |
| 1374 | connections.every(({ chunkGroup, originChunkGroupInfo }) => |
| 1375 | areModulesAvailable( |
| 1376 | chunkGroup, |
| 1377 | /** @type {bigint} */ (originChunkGroupInfo.resultingAvailableModules) |
| 1378 | ) |
| 1379 | ) |
| 1380 | ) { |
| 1381 | continue; |
| 1382 | } |
| 1383 | |
| 1384 | // 2. Foreach edge |
| 1385 | for (let i = 0; i < connections.length; i++) { |
| 1386 | const { chunkGroup, originChunkGroupInfo } = connections[i]; |
| 1387 | |
| 1388 | // 3. Connect block with chunk |
| 1389 | chunkGraph.connectBlockAndChunkGroup(block, chunkGroup); |
| 1390 | |
| 1391 | // 4. Connect chunk with parent |
| 1392 | if (originChunkGroupInfo.chunkGroup.addChild(chunkGroup)) { |
| 1393 | chunkGroup.addParent(originChunkGroupInfo.chunkGroup); |
| 1394 | } |
| 1395 | } |
| 1396 | } |
| 1397 | }; |
no test coverage detected