MCPcopy
hub / github.com/webpack/webpack / removeProblematicNodes

Function removeProblematicNodes

lib/util/deterministicGrouping.js:366–411  ·  view source on GitHub ↗
(group, consideredSize = group.size)

Source from the content-addressed store, hash-verified

364 * @returns {boolean} true, if the group was modified
365 */
366 const removeProblematicNodes = (group, consideredSize = group.size) => {
367 const problemTypes = getTooSmallTypes(consideredSize, minSize);
368 if (problemTypes.size > 0) {
369 // We hit an edge case where the working set is already smaller than minSize
370 // We merge problematic nodes with the smallest result node to keep minSize intact
371 const problemNodes = group.popNodes(
372 (n) => getNumberOfMatchingSizeTypes(n.size, problemTypes) > 0
373 );
374 if (problemNodes === undefined) return false;
375 // Only merge it with result nodes that have the problematic size type
376 const possibleResultGroups = result.filter(
377 (n) => getNumberOfMatchingSizeTypes(n.size, problemTypes) > 0
378 );
379 if (possibleResultGroups.length > 0) {
380 const bestGroup = possibleResultGroups.reduce((min, group) => {
381 const minMatches = getNumberOfMatchingSizeTypes(min, problemTypes);
382 const groupMatches = getNumberOfMatchingSizeTypes(
383 group,
384 problemTypes
385 );
386 if (minMatches !== groupMatches) {
387 return minMatches < groupMatches ? group : min;
388 }
389 if (
390 selectiveSizeSum(min.size, problemTypes) >
391 selectiveSizeSum(group.size, problemTypes)
392 ) {
393 return group;
394 }
395 return min;
396 });
397 for (const node of problemNodes) bestGroup.nodes.push(node);
398 bestGroup.nodes.sort((a, b) => {
399 if (a.key < b.key) return -1;
400 if (a.key > b.key) return 1;
401 return 0;
402 });
403 } else {
404 // There are no other nodes with the same size types
405 // We create a new group and have to accept that it's smaller than minSize
406 result.push(new Group(problemNodes, null));
407 }
408 return true;
409 }
410 return false;
411 };
412
413 if (initialGroup.nodes.length > 0) {
414 const queue = [initialGroup];

Callers 1

Calls 6

getTooSmallTypesFunction · 0.85
selectiveSizeSumFunction · 0.85
popNodesMethod · 0.80
sortMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected