MCPcopy
hub / github.com/webpack/webpack / getChildOrderOptions

Method getChildOrderOptions

lib/ChunkGroup.js:557–592  ·  view source on GitHub ↗

* Aggregates per-block `*Order` options for the blocks that bridge this * chunk group to the given child chunk group. `*Order` options are tied to * the originating `import()` call and must not be sourced from the child's * shared options, otherwise a webpackPrefetch/Preload directive from one

(childGroup, chunkGraph)

Source from the content-addressed store, hash-verified

555 * @returns {Record<string, number>} merged `*Order` options for the edge from this group to `childGroup`
556 */
557 getChildOrderOptions(childGroup, chunkGraph) {
558 /** @type {Record<string, number>} */
559 const result = Object.create(null);
560 let bridged = false;
561 for (const block of childGroup.blocksIterable) {
562 const rootModule = /** @type {Module} */ (block.getRootBlock());
563 if (!chunkGraph.isModuleInChunkGroup(rootModule, this)) continue;
564 bridged = true;
565 const opts = block.groupOptions;
566 if (!opts) continue;
567 for (const key of Object.keys(opts)) {
568 if (!key.endsWith("Order")) continue;
569 const value =
570 /** @type {number} */
571 (opts[/** @type {keyof ChunkGroupOptions} */ (key)]);
572 if (typeof value !== "number") continue;
573 if (result[key] === undefined || value > result[key]) {
574 result[key] = value;
575 }
576 }
577 }
578 // Fall back to the child's own options only when no block bridges
579 // this edge (e.g. a chunk group created by APIs that don't go through
580 // an AsyncDependenciesBlock). Otherwise we'd reintroduce the leak.
581 if (!bridged) {
582 for (const key of Object.keys(childGroup.options)) {
583 if (!key.endsWith("Order")) continue;
584 const value =
585 childGroup.options[/** @type {keyof ChunkGroupOptions} */ (key)];
586 if (typeof value === "number") {
587 result[key] = value;
588 }
589 }
590 }
591 return result;
592 }
593
594 /**
595 * Groups child chunk groups by their `*Order` options and sorts each group

Callers 3

getChildrenByOrdersMethod · 0.95
getChildIdsByOrdersMethod · 0.80

Calls 4

getRootBlockMethod · 0.80
isModuleInChunkGroupMethod · 0.80
keysMethod · 0.65
createMethod · 0.45

Tested by

no test coverage detected