UNPKG

44.5 kBJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8const AsyncDependencyToInitialChunkError = require("./AsyncDependencyToInitialChunkError");
9const { connectChunkGroupParentAndChild } = require("./GraphHelpers");
10const ModuleGraphConnection = require("./ModuleGraphConnection");
11const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
12
13/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
14/** @typedef {import("./Chunk")} Chunk */
15/** @typedef {import("./ChunkGroup")} ChunkGroup */
16/** @typedef {import("./Compilation")} Compilation */
17/** @typedef {import("./DependenciesBlock")} DependenciesBlock */
18/** @typedef {import("./Dependency")} Dependency */
19/** @typedef {import("./Entrypoint")} Entrypoint */
20/** @typedef {import("./Module")} Module */
21/** @typedef {import("./ModuleGraph")} ModuleGraph */
22/** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
23/** @typedef {import("./logging/Logger").Logger} Logger */
24/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
25
26/**
27 * @typedef {Object} QueueItem
28 * @property {number} action
29 * @property {DependenciesBlock} block
30 * @property {Module} module
31 * @property {Chunk} chunk
32 * @property {ChunkGroup} chunkGroup
33 * @property {ChunkGroupInfo} chunkGroupInfo
34 */
35
36/** @typedef {Set<Module> & { plus: Set<Module> }} ModuleSetPlus */
37
38/**
39 * @typedef {Object} ChunkGroupInfo
40 * @property {ChunkGroup} chunkGroup the chunk group
41 * @property {RuntimeSpec} runtime the runtimes
42 * @property {ModuleSetPlus} minAvailableModules current minimal set of modules available at this point
43 * @property {boolean} minAvailableModulesOwned true, if minAvailableModules is owned and can be modified
44 * @property {ModuleSetPlus[]} availableModulesToBeMerged enqueued updates to the minimal set of available modules
45 * @property {Set<Module>=} skippedItems modules that were skipped because module is already available in parent chunks (need to reconsider when minAvailableModules is shrinking)
46 * @property {Set<[Module, ConnectionState]>=} skippedModuleConnections referenced modules that where skipped because they were not active in this runtime
47 * @property {ModuleSetPlus} resultingAvailableModules set of modules available including modules from this chunk group
48 * @property {Set<ChunkGroupInfo>} children set of children chunk groups, that will be revisited when availableModules shrink
49 * @property {Set<ChunkGroupInfo>} availableSources set of chunk groups that are the source for minAvailableModules
50 * @property {Set<ChunkGroupInfo>} availableChildren set of chunk groups which depend on the this chunk group as availableSource
51 * @property {number} preOrderIndex next pre order index
52 * @property {number} postOrderIndex next post order index
53 */
54
55/**
56 * @typedef {Object} BlockChunkGroupConnection
57 * @property {ChunkGroupInfo} originChunkGroupInfo origin chunk group
58 * @property {ChunkGroup} chunkGroup referenced chunk group
59 */
60
61const EMPTY_SET = /** @type {ModuleSetPlus} */ (new Set());
62EMPTY_SET.plus = EMPTY_SET;
63
64/**
65 * @param {ModuleSetPlus} a first set
66 * @param {ModuleSetPlus} b second set
67 * @returns {number} cmp
68 */
69const bySetSize = (a, b) => {
70 return b.size + b.plus.size - a.size - a.plus.size;
71};
72
73const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
74 let blockCache;
75 let modules;
76
77 const arrays = [];
78
79 const queue = [module];
80 while (queue.length > 0) {
81 const block = queue.pop();
82 const arr = [];
83 arrays.push(arr);
84 blockModulesMap.set(block, arr);
85 for (const b of block.blocks) {
86 queue.push(b);
87 }
88 }
89
90 for (const connection of moduleGraph.getOutgoingConnections(module)) {
91 const d = connection.dependency;
92 // We skip connections without dependency
93 if (!d) continue;
94 const m = connection.module;
95 // We skip connections without Module pointer
96 if (!m) continue;
97 // We skip weak connections
98 if (connection.weak) continue;
99 const state = connection.getActiveState(runtime);
100 // We skip inactive connections
101 if (state === false) continue;
102
103 const block = moduleGraph.getParentBlock(d);
104 let index = moduleGraph.getParentBlockIndex(d);
105
106 // deprecated fallback
107 if (index < 0) {
108 index = block.dependencies.indexOf(d);
109 }
110
111 if (blockCache !== block) {
112 modules = blockModulesMap.get((blockCache = block));
113 }
114
115 const i = index << 2;
116 modules[i] = m;
117 modules[i + 1] = state;
118 }
119
120 for (const modules of arrays) {
121 if (modules.length === 0) continue;
122 let indexMap;
123 let length = 0;
124 outer: for (let j = 0; j < modules.length; j += 2) {
125 const m = modules[j];
126 if (m === undefined) continue;
127 const state = modules[j + 1];
128 if (indexMap === undefined) {
129 let i = 0;
130 for (; i < length; i += 2) {
131 if (modules[i] === m) {
132 const merged = modules[i + 1];
133 if (merged === true) continue outer;
134 modules[i + 1] = ModuleGraphConnection.addConnectionStates(
135 merged,
136 state
137 );
138 }
139 }
140 modules[length] = m;
141 length++;
142 modules[length] = state;
143 length++;
144 if (length > 30) {
145 // To avoid worse case performance, we will use an index map for
146 // linear cost access, which allows to maintain O(n) complexity
147 // while keeping allocations down to a minimum
148 indexMap = new Map();
149 for (let i = 0; i < length; i += 2) {
150 indexMap.set(modules[i], i + 1);
151 }
152 }
153 } else {
154 const idx = indexMap.get(m);
155 if (idx !== undefined) {
156 const merged = modules[idx];
157 if (merged === true) continue outer;
158 modules[idx] = ModuleGraphConnection.addConnectionStates(
159 merged,
160 state
161 );
162 } else {
163 modules[length] = m;
164 length++;
165 modules[length] = state;
166 indexMap.set(m, length);
167 length++;
168 }
169 }
170 }
171 modules.length = length;
172 }
173};
174
175/**
176 *
177 * @param {Logger} logger a logger
178 * @param {Compilation} compilation the compilation
179 * @param {Map<Entrypoint, Module[]>} inputEntrypointsAndModules chunk groups which are processed with the modules
180 * @param {Map<ChunkGroup, ChunkGroupInfo>} chunkGroupInfoMap mapping from chunk group to available modules
181 * @param {Map<AsyncDependenciesBlock, BlockChunkGroupConnection[]>} blockConnections connection for blocks
182 * @param {Set<DependenciesBlock>} blocksWithNestedBlocks flag for blocks that have nested blocks
183 * @param {Set<ChunkGroup>} allCreatedChunkGroups filled with all chunk groups that are created here
184 */
185const visitModules = (
186 logger,
187 compilation,
188 inputEntrypointsAndModules,
189 chunkGroupInfoMap,
190 blockConnections,
191 blocksWithNestedBlocks,
192 allCreatedChunkGroups
193) => {
194 const { moduleGraph, chunkGraph, moduleMemCaches } = compilation;
195
196 const blockModulesRuntimeMap = new Map();
197
198 /** @type {RuntimeSpec | false} */
199 let blockModulesMapRuntime = false;
200 let blockModulesMap;
201
202 /**
203 *
204 * @param {DependenciesBlock} block block
205 * @param {RuntimeSpec} runtime runtime
206 * @returns {(Module | ConnectionState)[]} block modules in flatten tuples
207 */
208 const getBlockModules = (block, runtime) => {
209 if (blockModulesMapRuntime !== runtime) {
210 blockModulesMap = blockModulesRuntimeMap.get(runtime);
211 if (blockModulesMap === undefined) {
212 blockModulesMap = new Map();
213 blockModulesRuntimeMap.set(runtime, blockModulesMap);
214 }
215 }
216 let blockModules = blockModulesMap.get(block);
217 if (blockModules !== undefined) return blockModules;
218 const module = /** @type {Module} */ (block.getRootBlock());
219 const memCache = moduleMemCaches && moduleMemCaches.get(module);
220 if (memCache !== undefined) {
221 const map = memCache.provide(
222 "bundleChunkGraph.blockModules",
223 runtime,
224 () => {
225 logger.time("visitModules: prepare");
226 const map = new Map();
227 extractBlockModules(module, moduleGraph, runtime, map);
228 logger.timeAggregate("visitModules: prepare");
229 return map;
230 }
231 );
232 for (const [block, blockModules] of map)
233 blockModulesMap.set(block, blockModules);
234 return map.get(block);
235 } else {
236 logger.time("visitModules: prepare");
237 extractBlockModules(module, moduleGraph, runtime, blockModulesMap);
238 blockModules = blockModulesMap.get(block);
239 logger.timeAggregate("visitModules: prepare");
240 return blockModules;
241 }
242 };
243
244 let statProcessedQueueItems = 0;
245 let statProcessedBlocks = 0;
246 let statConnectedChunkGroups = 0;
247 let statProcessedChunkGroupsForMerging = 0;
248 let statMergedAvailableModuleSets = 0;
249 let statForkedAvailableModules = 0;
250 let statForkedAvailableModulesCount = 0;
251 let statForkedAvailableModulesCountPlus = 0;
252 let statForkedMergedModulesCount = 0;
253 let statForkedMergedModulesCountPlus = 0;
254 let statForkedResultModulesCount = 0;
255 let statChunkGroupInfoUpdated = 0;
256 let statChildChunkGroupsReconnected = 0;
257
258 let nextChunkGroupIndex = 0;
259 let nextFreeModulePreOrderIndex = 0;
260 let nextFreeModulePostOrderIndex = 0;
261
262 /** @type {Map<DependenciesBlock, ChunkGroupInfo>} */
263 const blockChunkGroups = new Map();
264
265 /** @type {Map<string, ChunkGroupInfo>} */
266 const namedChunkGroups = new Map();
267
268 /** @type {Map<string, ChunkGroupInfo>} */
269 const namedAsyncEntrypoints = new Map();
270
271 const ADD_AND_ENTER_ENTRY_MODULE = 0;
272 const ADD_AND_ENTER_MODULE = 1;
273 const ENTER_MODULE = 2;
274 const PROCESS_BLOCK = 3;
275 const PROCESS_ENTRY_BLOCK = 4;
276 const LEAVE_MODULE = 5;
277
278 /** @type {QueueItem[]} */
279 let queue = [];
280
281 /** @type {Map<ChunkGroupInfo, Set<ChunkGroupInfo>>} */
282 const queueConnect = new Map();
283 /** @type {Set<ChunkGroupInfo>} */
284 const chunkGroupsForCombining = new Set();
285
286 // Fill queue with entrypoint modules
287 // Create ChunkGroupInfo for entrypoints
288 for (const [chunkGroup, modules] of inputEntrypointsAndModules) {
289 const runtime = getEntryRuntime(
290 compilation,
291 chunkGroup.name,
292 chunkGroup.options
293 );
294 /** @type {ChunkGroupInfo} */
295 const chunkGroupInfo = {
296 chunkGroup,
297 runtime,
298 minAvailableModules: undefined,
299 minAvailableModulesOwned: false,
300 availableModulesToBeMerged: [],
301 skippedItems: undefined,
302 resultingAvailableModules: undefined,
303 children: undefined,
304 availableSources: undefined,
305 availableChildren: undefined,
306 preOrderIndex: 0,
307 postOrderIndex: 0
308 };
309 chunkGroup.index = nextChunkGroupIndex++;
310 if (chunkGroup.getNumberOfParents() > 0) {
311 // minAvailableModules for child entrypoints are unknown yet, set to undefined.
312 // This means no module is added until other sets are merged into
313 // this minAvailableModules (by the parent entrypoints)
314 const skippedItems = new Set();
315 for (const module of modules) {
316 skippedItems.add(module);
317 }
318 chunkGroupInfo.skippedItems = skippedItems;
319 chunkGroupsForCombining.add(chunkGroupInfo);
320 } else {
321 // The application may start here: We start with an empty list of available modules
322 chunkGroupInfo.minAvailableModules = EMPTY_SET;
323 const chunk = chunkGroup.getEntrypointChunk();
324 for (const module of modules) {
325 queue.push({
326 action: ADD_AND_ENTER_MODULE,
327 block: module,
328 module,
329 chunk,
330 chunkGroup,
331 chunkGroupInfo
332 });
333 }
334 }
335 chunkGroupInfoMap.set(chunkGroup, chunkGroupInfo);
336 if (chunkGroup.name) {
337 namedChunkGroups.set(chunkGroup.name, chunkGroupInfo);
338 }
339 }
340 // Fill availableSources with parent-child dependencies between entrypoints
341 for (const chunkGroupInfo of chunkGroupsForCombining) {
342 const { chunkGroup } = chunkGroupInfo;
343 chunkGroupInfo.availableSources = new Set();
344 for (const parent of chunkGroup.parentsIterable) {
345 const parentChunkGroupInfo = chunkGroupInfoMap.get(parent);
346 chunkGroupInfo.availableSources.add(parentChunkGroupInfo);
347 if (parentChunkGroupInfo.availableChildren === undefined) {
348 parentChunkGroupInfo.availableChildren = new Set();
349 }
350 parentChunkGroupInfo.availableChildren.add(chunkGroupInfo);
351 }
352 }
353 // pop() is used to read from the queue
354 // so it need to be reversed to be iterated in
355 // correct order
356 queue.reverse();
357
358 /** @type {Set<ChunkGroupInfo>} */
359 const outdatedChunkGroupInfo = new Set();
360 /** @type {Set<ChunkGroupInfo>} */
361 const chunkGroupsForMerging = new Set();
362 /** @type {QueueItem[]} */
363 let queueDelayed = [];
364
365 /** @type {[Module, ConnectionState][]} */
366 const skipConnectionBuffer = [];
367 /** @type {Module[]} */
368 const skipBuffer = [];
369 /** @type {QueueItem[]} */
370 const queueBuffer = [];
371
372 /** @type {Module} */
373 let module;
374 /** @type {Chunk} */
375 let chunk;
376 /** @type {ChunkGroup} */
377 let chunkGroup;
378 /** @type {DependenciesBlock} */
379 let block;
380 /** @type {ChunkGroupInfo} */
381 let chunkGroupInfo;
382
383 // For each async Block in graph
384 /**
385 * @param {AsyncDependenciesBlock} b iterating over each Async DepBlock
386 * @returns {void}
387 */
388 const iteratorBlock = b => {
389 // 1. We create a chunk group with single chunk in it for this Block
390 // but only once (blockChunkGroups map)
391 let cgi = blockChunkGroups.get(b);
392 /** @type {ChunkGroup} */
393 let c;
394 /** @type {Entrypoint} */
395 let entrypoint;
396 const entryOptions = b.groupOptions && b.groupOptions.entryOptions;
397 if (cgi === undefined) {
398 const chunkName = (b.groupOptions && b.groupOptions.name) || b.chunkName;
399 if (entryOptions) {
400 cgi = namedAsyncEntrypoints.get(chunkName);
401 if (!cgi) {
402 entrypoint = compilation.addAsyncEntrypoint(
403 entryOptions,
404 module,
405 b.loc,
406 b.request
407 );
408 entrypoint.index = nextChunkGroupIndex++;
409 cgi = {
410 chunkGroup: entrypoint,
411 runtime: entrypoint.options.runtime || entrypoint.name,
412 minAvailableModules: EMPTY_SET,
413 minAvailableModulesOwned: false,
414 availableModulesToBeMerged: [],
415 skippedItems: undefined,
416 resultingAvailableModules: undefined,
417 children: undefined,
418 availableSources: undefined,
419 availableChildren: undefined,
420 preOrderIndex: 0,
421 postOrderIndex: 0
422 };
423 chunkGroupInfoMap.set(entrypoint, cgi);
424
425 chunkGraph.connectBlockAndChunkGroup(b, entrypoint);
426 if (chunkName) {
427 namedAsyncEntrypoints.set(chunkName, cgi);
428 }
429 } else {
430 entrypoint = /** @type {Entrypoint} */ (cgi.chunkGroup);
431 // TODO merge entryOptions
432 entrypoint.addOrigin(module, b.loc, b.request);
433 chunkGraph.connectBlockAndChunkGroup(b, entrypoint);
434 }
435
436 // 2. We enqueue the DependenciesBlock for traversal
437 queueDelayed.push({
438 action: PROCESS_ENTRY_BLOCK,
439 block: b,
440 module: module,
441 chunk: entrypoint.chunks[0],
442 chunkGroup: entrypoint,
443 chunkGroupInfo: cgi
444 });
445 } else {
446 cgi = namedChunkGroups.get(chunkName);
447 if (!cgi) {
448 c = compilation.addChunkInGroup(
449 b.groupOptions || b.chunkName,
450 module,
451 b.loc,
452 b.request
453 );
454 c.index = nextChunkGroupIndex++;
455 cgi = {
456 chunkGroup: c,
457 runtime: chunkGroupInfo.runtime,
458 minAvailableModules: undefined,
459 minAvailableModulesOwned: undefined,
460 availableModulesToBeMerged: [],
461 skippedItems: undefined,
462 resultingAvailableModules: undefined,
463 children: undefined,
464 availableSources: undefined,
465 availableChildren: undefined,
466 preOrderIndex: 0,
467 postOrderIndex: 0
468 };
469 allCreatedChunkGroups.add(c);
470 chunkGroupInfoMap.set(c, cgi);
471 if (chunkName) {
472 namedChunkGroups.set(chunkName, cgi);
473 }
474 } else {
475 c = cgi.chunkGroup;
476 if (c.isInitial()) {
477 compilation.errors.push(
478 new AsyncDependencyToInitialChunkError(chunkName, module, b.loc)
479 );
480 c = chunkGroup;
481 }
482 c.addOptions(b.groupOptions);
483 c.addOrigin(module, b.loc, b.request);
484 }
485 blockConnections.set(b, []);
486 }
487 blockChunkGroups.set(b, cgi);
488 } else if (entryOptions) {
489 entrypoint = /** @type {Entrypoint} */ (cgi.chunkGroup);
490 } else {
491 c = cgi.chunkGroup;
492 }
493
494 if (c !== undefined) {
495 // 2. We store the connection for the block
496 // to connect it later if needed
497 blockConnections.get(b).push({
498 originChunkGroupInfo: chunkGroupInfo,
499 chunkGroup: c
500 });
501
502 // 3. We enqueue the chunk group info creation/updating
503 let connectList = queueConnect.get(chunkGroupInfo);
504 if (connectList === undefined) {
505 connectList = new Set();
506 queueConnect.set(chunkGroupInfo, connectList);
507 }
508 connectList.add(cgi);
509
510 // TODO check if this really need to be done for each traversal
511 // or if it is enough when it's queued when created
512 // 4. We enqueue the DependenciesBlock for traversal
513 queueDelayed.push({
514 action: PROCESS_BLOCK,
515 block: b,
516 module: module,
517 chunk: c.chunks[0],
518 chunkGroup: c,
519 chunkGroupInfo: cgi
520 });
521 } else {
522 chunkGroupInfo.chunkGroup.addAsyncEntrypoint(entrypoint);
523 }
524 };
525
526 /**
527 * @param {DependenciesBlock} block the block
528 * @returns {void}
529 */
530 const processBlock = block => {
531 statProcessedBlocks++;
532 // get prepared block info
533 const blockModules = getBlockModules(block, chunkGroupInfo.runtime);
534
535 if (blockModules !== undefined) {
536 const { minAvailableModules } = chunkGroupInfo;
537 // Buffer items because order need to be reversed to get indices correct
538 // Traverse all referenced modules
539 for (let i = 0; i < blockModules.length; i += 2) {
540 const refModule = /** @type {Module} */ (blockModules[i]);
541 if (chunkGraph.isModuleInChunk(refModule, chunk)) {
542 // skip early if already connected
543 continue;
544 }
545 const activeState = /** @type {ConnectionState} */ (
546 blockModules[i + 1]
547 );
548 if (activeState !== true) {
549 skipConnectionBuffer.push([refModule, activeState]);
550 if (activeState === false) continue;
551 }
552 if (
553 activeState === true &&
554 (minAvailableModules.has(refModule) ||
555 minAvailableModules.plus.has(refModule))
556 ) {
557 // already in parent chunks, skip it for now
558 skipBuffer.push(refModule);
559 continue;
560 }
561 // enqueue, then add and enter to be in the correct order
562 // this is relevant with circular dependencies
563 queueBuffer.push({
564 action: activeState === true ? ADD_AND_ENTER_MODULE : PROCESS_BLOCK,
565 block: refModule,
566 module: refModule,
567 chunk,
568 chunkGroup,
569 chunkGroupInfo
570 });
571 }
572 // Add buffered items in reverse order
573 if (skipConnectionBuffer.length > 0) {
574 let { skippedModuleConnections } = chunkGroupInfo;
575 if (skippedModuleConnections === undefined) {
576 chunkGroupInfo.skippedModuleConnections = skippedModuleConnections =
577 new Set();
578 }
579 for (let i = skipConnectionBuffer.length - 1; i >= 0; i--) {
580 skippedModuleConnections.add(skipConnectionBuffer[i]);
581 }
582 skipConnectionBuffer.length = 0;
583 }
584 if (skipBuffer.length > 0) {
585 let { skippedItems } = chunkGroupInfo;
586 if (skippedItems === undefined) {
587 chunkGroupInfo.skippedItems = skippedItems = new Set();
588 }
589 for (let i = skipBuffer.length - 1; i >= 0; i--) {
590 skippedItems.add(skipBuffer[i]);
591 }
592 skipBuffer.length = 0;
593 }
594 if (queueBuffer.length > 0) {
595 for (let i = queueBuffer.length - 1; i >= 0; i--) {
596 queue.push(queueBuffer[i]);
597 }
598 queueBuffer.length = 0;
599 }
600 }
601
602 // Traverse all Blocks
603 for (const b of block.blocks) {
604 iteratorBlock(b);
605 }
606
607 if (block.blocks.length > 0 && module !== block) {
608 blocksWithNestedBlocks.add(block);
609 }
610 };
611
612 /**
613 * @param {DependenciesBlock} block the block
614 * @returns {void}
615 */
616 const processEntryBlock = block => {
617 statProcessedBlocks++;
618 // get prepared block info
619 const blockModules = getBlockModules(block, chunkGroupInfo.runtime);
620
621 if (blockModules !== undefined) {
622 // Traverse all referenced modules
623 for (let i = 0; i < blockModules.length; i += 2) {
624 const refModule = /** @type {Module} */ (blockModules[i]);
625 const activeState = /** @type {ConnectionState} */ (
626 blockModules[i + 1]
627 );
628 // enqueue, then add and enter to be in the correct order
629 // this is relevant with circular dependencies
630 queueBuffer.push({
631 action:
632 activeState === true ? ADD_AND_ENTER_ENTRY_MODULE : PROCESS_BLOCK,
633 block: refModule,
634 module: refModule,
635 chunk,
636 chunkGroup,
637 chunkGroupInfo
638 });
639 }
640 // Add buffered items in reverse order
641 if (queueBuffer.length > 0) {
642 for (let i = queueBuffer.length - 1; i >= 0; i--) {
643 queue.push(queueBuffer[i]);
644 }
645 queueBuffer.length = 0;
646 }
647 }
648
649 // Traverse all Blocks
650 for (const b of block.blocks) {
651 iteratorBlock(b);
652 }
653
654 if (block.blocks.length > 0 && module !== block) {
655 blocksWithNestedBlocks.add(block);
656 }
657 };
658
659 const processQueue = () => {
660 while (queue.length) {
661 statProcessedQueueItems++;
662 const queueItem = queue.pop();
663 module = queueItem.module;
664 block = queueItem.block;
665 chunk = queueItem.chunk;
666 chunkGroup = queueItem.chunkGroup;
667 chunkGroupInfo = queueItem.chunkGroupInfo;
668
669 switch (queueItem.action) {
670 case ADD_AND_ENTER_ENTRY_MODULE:
671 chunkGraph.connectChunkAndEntryModule(
672 chunk,
673 module,
674 /** @type {Entrypoint} */ (chunkGroup)
675 );
676 // fallthrough
677 case ADD_AND_ENTER_MODULE: {
678 if (chunkGraph.isModuleInChunk(module, chunk)) {
679 // already connected, skip it
680 break;
681 }
682 // We connect Module and Chunk
683 chunkGraph.connectChunkAndModule(chunk, module);
684 }
685 // fallthrough
686 case ENTER_MODULE: {
687 const index = chunkGroup.getModulePreOrderIndex(module);
688 if (index === undefined) {
689 chunkGroup.setModulePreOrderIndex(
690 module,
691 chunkGroupInfo.preOrderIndex++
692 );
693 }
694
695 if (
696 moduleGraph.setPreOrderIndexIfUnset(
697 module,
698 nextFreeModulePreOrderIndex
699 )
700 ) {
701 nextFreeModulePreOrderIndex++;
702 }
703
704 // reuse queueItem
705 queueItem.action = LEAVE_MODULE;
706 queue.push(queueItem);
707 }
708 // fallthrough
709 case PROCESS_BLOCK: {
710 processBlock(block);
711 break;
712 }
713 case PROCESS_ENTRY_BLOCK: {
714 processEntryBlock(block);
715 break;
716 }
717 case LEAVE_MODULE: {
718 const index = chunkGroup.getModulePostOrderIndex(module);
719 if (index === undefined) {
720 chunkGroup.setModulePostOrderIndex(
721 module,
722 chunkGroupInfo.postOrderIndex++
723 );
724 }
725
726 if (
727 moduleGraph.setPostOrderIndexIfUnset(
728 module,
729 nextFreeModulePostOrderIndex
730 )
731 ) {
732 nextFreeModulePostOrderIndex++;
733 }
734 break;
735 }
736 }
737 }
738 };
739
740 const calculateResultingAvailableModules = chunkGroupInfo => {
741 if (chunkGroupInfo.resultingAvailableModules)
742 return chunkGroupInfo.resultingAvailableModules;
743
744 const minAvailableModules = chunkGroupInfo.minAvailableModules;
745
746 // Create a new Set of available modules at this point
747 // We want to be as lazy as possible. There are multiple ways doing this:
748 // Note that resultingAvailableModules is stored as "(a) + (b)" as it's a ModuleSetPlus
749 // - resultingAvailableModules = (modules of chunk) + (minAvailableModules + minAvailableModules.plus)
750 // - resultingAvailableModules = (minAvailableModules + modules of chunk) + (minAvailableModules.plus)
751 // We choose one depending on the size of minAvailableModules vs minAvailableModules.plus
752
753 let resultingAvailableModules;
754 if (minAvailableModules.size > minAvailableModules.plus.size) {
755 // resultingAvailableModules = (modules of chunk) + (minAvailableModules + minAvailableModules.plus)
756 resultingAvailableModules =
757 /** @type {Set<Module> & {plus: Set<Module>}} */ (new Set());
758 for (const module of minAvailableModules.plus)
759 minAvailableModules.add(module);
760 minAvailableModules.plus = EMPTY_SET;
761 resultingAvailableModules.plus = minAvailableModules;
762 chunkGroupInfo.minAvailableModulesOwned = false;
763 } else {
764 // resultingAvailableModules = (minAvailableModules + modules of chunk) + (minAvailableModules.plus)
765 resultingAvailableModules =
766 /** @type {Set<Module> & {plus: Set<Module>}} */ (
767 new Set(minAvailableModules)
768 );
769 resultingAvailableModules.plus = minAvailableModules.plus;
770 }
771
772 // add the modules from the chunk group to the set
773 for (const chunk of chunkGroupInfo.chunkGroup.chunks) {
774 for (const m of chunkGraph.getChunkModulesIterable(chunk)) {
775 resultingAvailableModules.add(m);
776 }
777 }
778 return (chunkGroupInfo.resultingAvailableModules =
779 resultingAvailableModules);
780 };
781
782 const processConnectQueue = () => {
783 // Figure out new parents for chunk groups
784 // to get new available modules for these children
785 for (const [chunkGroupInfo, targets] of queueConnect) {
786 // 1. Add new targets to the list of children
787 if (chunkGroupInfo.children === undefined) {
788 chunkGroupInfo.children = targets;
789 } else {
790 for (const target of targets) {
791 chunkGroupInfo.children.add(target);
792 }
793 }
794
795 // 2. Calculate resulting available modules
796 const resultingAvailableModules =
797 calculateResultingAvailableModules(chunkGroupInfo);
798
799 const runtime = chunkGroupInfo.runtime;
800
801 // 3. Update chunk group info
802 for (const target of targets) {
803 target.availableModulesToBeMerged.push(resultingAvailableModules);
804 chunkGroupsForMerging.add(target);
805 const oldRuntime = target.runtime;
806 const newRuntime = mergeRuntime(oldRuntime, runtime);
807 if (oldRuntime !== newRuntime) {
808 target.runtime = newRuntime;
809 outdatedChunkGroupInfo.add(target);
810 }
811 }
812
813 statConnectedChunkGroups += targets.size;
814 }
815 queueConnect.clear();
816 };
817
818 const processChunkGroupsForMerging = () => {
819 statProcessedChunkGroupsForMerging += chunkGroupsForMerging.size;
820
821 // Execute the merge
822 for (const info of chunkGroupsForMerging) {
823 const availableModulesToBeMerged = info.availableModulesToBeMerged;
824 let cachedMinAvailableModules = info.minAvailableModules;
825
826 statMergedAvailableModuleSets += availableModulesToBeMerged.length;
827
828 // 1. Get minimal available modules
829 // It doesn't make sense to traverse a chunk again with more available modules.
830 // This step calculates the minimal available modules and skips traversal when
831 // the list didn't shrink.
832 if (availableModulesToBeMerged.length > 1) {
833 availableModulesToBeMerged.sort(bySetSize);
834 }
835 let changed = false;
836 merge: for (const availableModules of availableModulesToBeMerged) {
837 if (cachedMinAvailableModules === undefined) {
838 cachedMinAvailableModules = availableModules;
839 info.minAvailableModules = cachedMinAvailableModules;
840 info.minAvailableModulesOwned = false;
841 changed = true;
842 } else {
843 if (info.minAvailableModulesOwned) {
844 // We own it and can modify it
845 if (cachedMinAvailableModules.plus === availableModules.plus) {
846 for (const m of cachedMinAvailableModules) {
847 if (!availableModules.has(m)) {
848 cachedMinAvailableModules.delete(m);
849 changed = true;
850 }
851 }
852 } else {
853 for (const m of cachedMinAvailableModules) {
854 if (!availableModules.has(m) && !availableModules.plus.has(m)) {
855 cachedMinAvailableModules.delete(m);
856 changed = true;
857 }
858 }
859 for (const m of cachedMinAvailableModules.plus) {
860 if (!availableModules.has(m) && !availableModules.plus.has(m)) {
861 // We can't remove modules from the plus part
862 // so we need to merge plus into the normal part to allow modifying it
863 const iterator =
864 cachedMinAvailableModules.plus[Symbol.iterator]();
865 // fast forward add all modules until m
866 /** @type {IteratorResult<Module>} */
867 let it;
868 while (!(it = iterator.next()).done) {
869 const module = it.value;
870 if (module === m) break;
871 cachedMinAvailableModules.add(module);
872 }
873 // check the remaining modules before adding
874 while (!(it = iterator.next()).done) {
875 const module = it.value;
876 if (
877 availableModules.has(module) ||
878 availableModules.plus.has(m)
879 ) {
880 cachedMinAvailableModules.add(module);
881 }
882 }
883 cachedMinAvailableModules.plus = EMPTY_SET;
884 changed = true;
885 continue merge;
886 }
887 }
888 }
889 } else if (cachedMinAvailableModules.plus === availableModules.plus) {
890 // Common and fast case when the plus part is shared
891 // We only need to care about the normal part
892 if (availableModules.size < cachedMinAvailableModules.size) {
893 // the new availableModules is smaller so it's faster to
894 // fork from the new availableModules
895 statForkedAvailableModules++;
896 statForkedAvailableModulesCount += availableModules.size;
897 statForkedMergedModulesCount += cachedMinAvailableModules.size;
898 // construct a new Set as intersection of cachedMinAvailableModules and availableModules
899 const newSet = /** @type {ModuleSetPlus} */ (new Set());
900 newSet.plus = availableModules.plus;
901 for (const m of availableModules) {
902 if (cachedMinAvailableModules.has(m)) {
903 newSet.add(m);
904 }
905 }
906 statForkedResultModulesCount += newSet.size;
907 cachedMinAvailableModules = newSet;
908 info.minAvailableModulesOwned = true;
909 info.minAvailableModules = newSet;
910 changed = true;
911 continue merge;
912 }
913 for (const m of cachedMinAvailableModules) {
914 if (!availableModules.has(m)) {
915 // cachedMinAvailableModules need to be modified
916 // but we don't own it
917 statForkedAvailableModules++;
918 statForkedAvailableModulesCount +=
919 cachedMinAvailableModules.size;
920 statForkedMergedModulesCount += availableModules.size;
921 // construct a new Set as intersection of cachedMinAvailableModules and availableModules
922 // as the plus part is equal we can just take over this one
923 const newSet = /** @type {ModuleSetPlus} */ (new Set());
924 newSet.plus = availableModules.plus;
925 const iterator = cachedMinAvailableModules[Symbol.iterator]();
926 // fast forward add all modules until m
927 /** @type {IteratorResult<Module>} */
928 let it;
929 while (!(it = iterator.next()).done) {
930 const module = it.value;
931 if (module === m) break;
932 newSet.add(module);
933 }
934 // check the remaining modules before adding
935 while (!(it = iterator.next()).done) {
936 const module = it.value;
937 if (availableModules.has(module)) {
938 newSet.add(module);
939 }
940 }
941 statForkedResultModulesCount += newSet.size;
942 cachedMinAvailableModules = newSet;
943 info.minAvailableModulesOwned = true;
944 info.minAvailableModules = newSet;
945 changed = true;
946 continue merge;
947 }
948 }
949 } else {
950 for (const m of cachedMinAvailableModules) {
951 if (!availableModules.has(m) && !availableModules.plus.has(m)) {
952 // cachedMinAvailableModules need to be modified
953 // but we don't own it
954 statForkedAvailableModules++;
955 statForkedAvailableModulesCount +=
956 cachedMinAvailableModules.size;
957 statForkedAvailableModulesCountPlus +=
958 cachedMinAvailableModules.plus.size;
959 statForkedMergedModulesCount += availableModules.size;
960 statForkedMergedModulesCountPlus += availableModules.plus.size;
961 // construct a new Set as intersection of cachedMinAvailableModules and availableModules
962 const newSet = /** @type {ModuleSetPlus} */ (new Set());
963 newSet.plus = EMPTY_SET;
964 const iterator = cachedMinAvailableModules[Symbol.iterator]();
965 // fast forward add all modules until m
966 /** @type {IteratorResult<Module>} */
967 let it;
968 while (!(it = iterator.next()).done) {
969 const module = it.value;
970 if (module === m) break;
971 newSet.add(module);
972 }
973 // check the remaining modules before adding
974 while (!(it = iterator.next()).done) {
975 const module = it.value;
976 if (
977 availableModules.has(module) ||
978 availableModules.plus.has(module)
979 ) {
980 newSet.add(module);
981 }
982 }
983 // also check all modules in cachedMinAvailableModules.plus
984 for (const module of cachedMinAvailableModules.plus) {
985 if (
986 availableModules.has(module) ||
987 availableModules.plus.has(module)
988 ) {
989 newSet.add(module);
990 }
991 }
992 statForkedResultModulesCount += newSet.size;
993 cachedMinAvailableModules = newSet;
994 info.minAvailableModulesOwned = true;
995 info.minAvailableModules = newSet;
996 changed = true;
997 continue merge;
998 }
999 }
1000 for (const m of cachedMinAvailableModules.plus) {
1001 if (!availableModules.has(m) && !availableModules.plus.has(m)) {
1002 // cachedMinAvailableModules need to be modified
1003 // but we don't own it
1004 statForkedAvailableModules++;
1005 statForkedAvailableModulesCount +=
1006 cachedMinAvailableModules.size;
1007 statForkedAvailableModulesCountPlus +=
1008 cachedMinAvailableModules.plus.size;
1009 statForkedMergedModulesCount += availableModules.size;
1010 statForkedMergedModulesCountPlus += availableModules.plus.size;
1011 // construct a new Set as intersection of cachedMinAvailableModules and availableModules
1012 // we already know that all modules directly from cachedMinAvailableModules are in availableModules too
1013 const newSet = /** @type {ModuleSetPlus} */ (
1014 new Set(cachedMinAvailableModules)
1015 );
1016 newSet.plus = EMPTY_SET;
1017 const iterator =
1018 cachedMinAvailableModules.plus[Symbol.iterator]();
1019 // fast forward add all modules until m
1020 /** @type {IteratorResult<Module>} */
1021 let it;
1022 while (!(it = iterator.next()).done) {
1023 const module = it.value;
1024 if (module === m) break;
1025 newSet.add(module);
1026 }
1027 // check the remaining modules before adding
1028 while (!(it = iterator.next()).done) {
1029 const module = it.value;
1030 if (
1031 availableModules.has(module) ||
1032 availableModules.plus.has(module)
1033 ) {
1034 newSet.add(module);
1035 }
1036 }
1037 statForkedResultModulesCount += newSet.size;
1038 cachedMinAvailableModules = newSet;
1039 info.minAvailableModulesOwned = true;
1040 info.minAvailableModules = newSet;
1041 changed = true;
1042 continue merge;
1043 }
1044 }
1045 }
1046 }
1047 }
1048 availableModulesToBeMerged.length = 0;
1049 if (changed) {
1050 info.resultingAvailableModules = undefined;
1051 outdatedChunkGroupInfo.add(info);
1052 }
1053 }
1054 chunkGroupsForMerging.clear();
1055 };
1056
1057 const processChunkGroupsForCombining = () => {
1058 for (const info of chunkGroupsForCombining) {
1059 for (const source of info.availableSources) {
1060 if (!source.minAvailableModules) {
1061 chunkGroupsForCombining.delete(info);
1062 break;
1063 }
1064 }
1065 }
1066 for (const info of chunkGroupsForCombining) {
1067 const availableModules = /** @type {ModuleSetPlus} */ (new Set());
1068 availableModules.plus = EMPTY_SET;
1069 const mergeSet = set => {
1070 if (set.size > availableModules.plus.size) {
1071 for (const item of availableModules.plus) availableModules.add(item);
1072 availableModules.plus = set;
1073 } else {
1074 for (const item of set) availableModules.add(item);
1075 }
1076 };
1077 // combine minAvailableModules from all resultingAvailableModules
1078 for (const source of info.availableSources) {
1079 const resultingAvailableModules =
1080 calculateResultingAvailableModules(source);
1081 mergeSet(resultingAvailableModules);
1082 mergeSet(resultingAvailableModules.plus);
1083 }
1084 info.minAvailableModules = availableModules;
1085 info.minAvailableModulesOwned = false;
1086 info.resultingAvailableModules = undefined;
1087 outdatedChunkGroupInfo.add(info);
1088 }
1089 chunkGroupsForCombining.clear();
1090 };
1091
1092 const processOutdatedChunkGroupInfo = () => {
1093 statChunkGroupInfoUpdated += outdatedChunkGroupInfo.size;
1094 // Revisit skipped elements
1095 for (const info of outdatedChunkGroupInfo) {
1096 // 1. Reconsider skipped items
1097 if (info.skippedItems !== undefined) {
1098 const { minAvailableModules } = info;
1099 for (const module of info.skippedItems) {
1100 if (
1101 !minAvailableModules.has(module) &&
1102 !minAvailableModules.plus.has(module)
1103 ) {
1104 queue.push({
1105 action: ADD_AND_ENTER_MODULE,
1106 block: module,
1107 module,
1108 chunk: info.chunkGroup.chunks[0],
1109 chunkGroup: info.chunkGroup,
1110 chunkGroupInfo: info
1111 });
1112 info.skippedItems.delete(module);
1113 }
1114 }
1115 }
1116
1117 // 2. Reconsider skipped connections
1118 if (info.skippedModuleConnections !== undefined) {
1119 const { minAvailableModules } = info;
1120 for (const entry of info.skippedModuleConnections) {
1121 const [module, activeState] = entry;
1122 if (activeState === false) continue;
1123 if (activeState === true) {
1124 info.skippedModuleConnections.delete(entry);
1125 }
1126 if (
1127 activeState === true &&
1128 (minAvailableModules.has(module) ||
1129 minAvailableModules.plus.has(module))
1130 ) {
1131 info.skippedItems.add(module);
1132 continue;
1133 }
1134 queue.push({
1135 action: activeState === true ? ADD_AND_ENTER_MODULE : PROCESS_BLOCK,
1136 block: module,
1137 module,
1138 chunk: info.chunkGroup.chunks[0],
1139 chunkGroup: info.chunkGroup,
1140 chunkGroupInfo: info
1141 });
1142 }
1143 }
1144
1145 // 2. Reconsider children chunk groups
1146 if (info.children !== undefined) {
1147 statChildChunkGroupsReconnected += info.children.size;
1148 for (const cgi of info.children) {
1149 let connectList = queueConnect.get(info);
1150 if (connectList === undefined) {
1151 connectList = new Set();
1152 queueConnect.set(info, connectList);
1153 }
1154 connectList.add(cgi);
1155 }
1156 }
1157
1158 // 3. Reconsider chunk groups for combining
1159 if (info.availableChildren !== undefined) {
1160 for (const cgi of info.availableChildren) {
1161 chunkGroupsForCombining.add(cgi);
1162 }
1163 }
1164 }
1165 outdatedChunkGroupInfo.clear();
1166 };
1167
1168 // Iterative traversal of the Module graph
1169 // Recursive would be simpler to write but could result in Stack Overflows
1170 while (queue.length || queueConnect.size) {
1171 logger.time("visitModules: visiting");
1172 processQueue();
1173 logger.timeAggregateEnd("visitModules: prepare");
1174 logger.timeEnd("visitModules: visiting");
1175
1176 if (chunkGroupsForCombining.size > 0) {
1177 logger.time("visitModules: combine available modules");
1178 processChunkGroupsForCombining();
1179 logger.timeEnd("visitModules: combine available modules");
1180 }
1181
1182 if (queueConnect.size > 0) {
1183 logger.time("visitModules: calculating available modules");
1184 processConnectQueue();
1185 logger.timeEnd("visitModules: calculating available modules");
1186
1187 if (chunkGroupsForMerging.size > 0) {
1188 logger.time("visitModules: merging available modules");
1189 processChunkGroupsForMerging();
1190 logger.timeEnd("visitModules: merging available modules");
1191 }
1192 }
1193
1194 if (outdatedChunkGroupInfo.size > 0) {
1195 logger.time("visitModules: check modules for revisit");
1196 processOutdatedChunkGroupInfo();
1197 logger.timeEnd("visitModules: check modules for revisit");
1198 }
1199
1200 // Run queueDelayed when all items of the queue are processed
1201 // This is important to get the global indexing correct
1202 // Async blocks should be processed after all sync blocks are processed
1203 if (queue.length === 0) {
1204 const tempQueue = queue;
1205 queue = queueDelayed.reverse();
1206 queueDelayed = tempQueue;
1207 }
1208 }
1209
1210 logger.log(
1211 `${statProcessedQueueItems} queue items processed (${statProcessedBlocks} blocks)`
1212 );
1213 logger.log(`${statConnectedChunkGroups} chunk groups connected`);
1214 logger.log(
1215 `${statProcessedChunkGroupsForMerging} chunk groups processed for merging (${statMergedAvailableModuleSets} module sets, ${statForkedAvailableModules} forked, ${statForkedAvailableModulesCount} + ${statForkedAvailableModulesCountPlus} modules forked, ${statForkedMergedModulesCount} + ${statForkedMergedModulesCountPlus} modules merged into fork, ${statForkedResultModulesCount} resulting modules)`
1216 );
1217 logger.log(
1218 `${statChunkGroupInfoUpdated} chunk group info updated (${statChildChunkGroupsReconnected} already connected chunk groups reconnected)`
1219 );
1220};
1221
1222/**
1223 *
1224 * @param {Compilation} compilation the compilation
1225 * @param {Set<DependenciesBlock>} blocksWithNestedBlocks flag for blocks that have nested blocks
1226 * @param {Map<AsyncDependenciesBlock, BlockChunkGroupConnection[]>} blockConnections connection for blocks
1227 * @param {Map<ChunkGroup, ChunkGroupInfo>} chunkGroupInfoMap mapping from chunk group to available modules
1228 */
1229const connectChunkGroups = (
1230 compilation,
1231 blocksWithNestedBlocks,
1232 blockConnections,
1233 chunkGroupInfoMap
1234) => {
1235 const { chunkGraph } = compilation;
1236
1237 /**
1238 * Helper function to check if all modules of a chunk are available
1239 *
1240 * @param {ChunkGroup} chunkGroup the chunkGroup to scan
1241 * @param {ModuleSetPlus} availableModules the comparator set
1242 * @returns {boolean} return true if all modules of a chunk are available
1243 */
1244 const areModulesAvailable = (chunkGroup, availableModules) => {
1245 for (const chunk of chunkGroup.chunks) {
1246 for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
1247 if (!availableModules.has(module) && !availableModules.plus.has(module))
1248 return false;
1249 }
1250 }
1251 return true;
1252 };
1253
1254 // For each edge in the basic chunk graph
1255 for (const [block, connections] of blockConnections) {
1256 // 1. Check if connection is needed
1257 // When none of the dependencies need to be connected
1258 // we can skip all of them
1259 // It's not possible to filter each item so it doesn't create inconsistent
1260 // connections and modules can only create one version
1261 // TODO maybe decide this per runtime
1262 if (
1263 // TODO is this needed?
1264 !blocksWithNestedBlocks.has(block) &&
1265 connections.every(({ chunkGroup, originChunkGroupInfo }) =>
1266 areModulesAvailable(
1267 chunkGroup,
1268 originChunkGroupInfo.resultingAvailableModules
1269 )
1270 )
1271 ) {
1272 continue;
1273 }
1274
1275 // 2. Foreach edge
1276 for (let i = 0; i < connections.length; i++) {
1277 const { chunkGroup, originChunkGroupInfo } = connections[i];
1278
1279 // 3. Connect block with chunk
1280 chunkGraph.connectBlockAndChunkGroup(block, chunkGroup);
1281
1282 // 4. Connect chunk with parent
1283 connectChunkGroupParentAndChild(
1284 originChunkGroupInfo.chunkGroup,
1285 chunkGroup
1286 );
1287 }
1288 }
1289};
1290
1291/**
1292 * Remove all unconnected chunk groups
1293 * @param {Compilation} compilation the compilation
1294 * @param {Iterable<ChunkGroup>} allCreatedChunkGroups all chunk groups that where created before
1295 */
1296const cleanupUnconnectedGroups = (compilation, allCreatedChunkGroups) => {
1297 const { chunkGraph } = compilation;
1298
1299 for (const chunkGroup of allCreatedChunkGroups) {
1300 if (chunkGroup.getNumberOfParents() === 0) {
1301 for (const chunk of chunkGroup.chunks) {
1302 compilation.chunks.delete(chunk);
1303 chunkGraph.disconnectChunk(chunk);
1304 }
1305 chunkGraph.disconnectChunkGroup(chunkGroup);
1306 chunkGroup.remove();
1307 }
1308 }
1309};
1310
1311/**
1312 * This method creates the Chunk graph from the Module graph
1313 * @param {Compilation} compilation the compilation
1314 * @param {Map<Entrypoint, Module[]>} inputEntrypointsAndModules chunk groups which are processed with the modules
1315 * @returns {void}
1316 */
1317const buildChunkGraph = (compilation, inputEntrypointsAndModules) => {
1318 const logger = compilation.getLogger("webpack.buildChunkGraph");
1319
1320 // SHARED STATE
1321
1322 /** @type {Map<AsyncDependenciesBlock, BlockChunkGroupConnection[]>} */
1323 const blockConnections = new Map();
1324
1325 /** @type {Set<ChunkGroup>} */
1326 const allCreatedChunkGroups = new Set();
1327
1328 /** @type {Map<ChunkGroup, ChunkGroupInfo>} */
1329 const chunkGroupInfoMap = new Map();
1330
1331 /** @type {Set<DependenciesBlock>} */
1332 const blocksWithNestedBlocks = new Set();
1333
1334 // PART ONE
1335
1336 logger.time("visitModules");
1337 visitModules(
1338 logger,
1339 compilation,
1340 inputEntrypointsAndModules,
1341 chunkGroupInfoMap,
1342 blockConnections,
1343 blocksWithNestedBlocks,
1344 allCreatedChunkGroups
1345 );
1346 logger.timeEnd("visitModules");
1347
1348 // PART TWO
1349
1350 logger.time("connectChunkGroups");
1351 connectChunkGroups(
1352 compilation,
1353 blocksWithNestedBlocks,
1354 blockConnections,
1355 chunkGroupInfoMap
1356 );
1357 logger.timeEnd("connectChunkGroups");
1358
1359 for (const [chunkGroup, chunkGroupInfo] of chunkGroupInfoMap) {
1360 for (const chunk of chunkGroup.chunks)
1361 chunk.runtime = mergeRuntime(chunk.runtime, chunkGroupInfo.runtime);
1362 }
1363
1364 // Cleanup work
1365
1366 logger.time("cleanup");
1367 cleanupUnconnectedGroups(compilation, allCreatedChunkGroups);
1368 logger.timeEnd("cleanup");
1369};
1370
1371module.exports = buildChunkGraph;