webpack 4.37.0 → 4.39.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,6 +14,7 @@
14
14
  [![builds2][builds2]][builds2-url]
15
15
  [![coverage][cover]][cover-url]
16
16
  [![licenses][licenses]][licenses-url]
17
+ [![PR's welcome][prs]][prs-url]
17
18
 
18
19
  <br>
19
20
  <a href="https://dependabot.com/compatibility-score.html?dependency-name=webpack&package-manager=npm_and_yarn&new-version=latest">
@@ -767,6 +768,9 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
767
768
  [tests]: https://img.shields.io/travis/webpack/webpack/master.svg
768
769
  [tests-url]: https://travis-ci.org/webpack/webpack
769
770
 
771
+ [prs]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg
772
+ [prs-url]: https://webpack.js.org/contribute/
773
+
770
774
  [builds-url]: https://ci.appveyor.com/project/sokra/webpack/branch/master
771
775
  [builds]: https://ci.appveyor.com/api/projects/status/github/webpack/webpack?svg=true
772
776
 
@@ -81,7 +81,6 @@ class BannerPlugin {
81
81
  continue;
82
82
  }
83
83
 
84
- let basename;
85
84
  let query = "";
86
85
  let filename = file;
87
86
  const hash = compilation.hash;
@@ -94,11 +93,10 @@ class BannerPlugin {
94
93
 
95
94
  const lastSlashIndex = filename.lastIndexOf("/");
96
95
 
97
- if (lastSlashIndex === -1) {
98
- basename = filename;
99
- } else {
100
- basename = filename.substr(lastSlashIndex + 1);
101
- }
96
+ const basename =
97
+ lastSlashIndex === -1
98
+ ? filename
99
+ : filename.substr(lastSlashIndex + 1);
102
100
 
103
101
  const data = {
104
102
  hash,
package/lib/Chunk.js CHANGED
@@ -355,7 +355,11 @@ class Chunk {
355
355
  return this._modules.getFromUnorderedCache(getModulesIdent);
356
356
  }
357
357
 
358
- remove() {
358
+ /**
359
+ * @param {string=} reason reason why chunk is removed
360
+ * @returns {void}
361
+ */
362
+ remove(reason) {
359
363
  // cleanup modules
360
364
  // Array.from is used here to create a clone, because removeChunk modifies this._modules
361
365
  for (const module of Array.from(this._modules)) {
package/lib/ChunkGroup.js CHANGED
@@ -70,12 +70,12 @@ class ChunkGroup {
70
70
  this.chunks = [];
71
71
  /** @type {OriginRecord[]} */
72
72
  this.origins = [];
73
- /** Indicies in top-down order */
73
+ /** Indices in top-down order */
74
74
  /** @private @type {Map<Module, number>} */
75
- this._moduleIndicies = new Map();
76
- /** Indicies in bottom-up order */
75
+ this._moduleIndices = new Map();
76
+ /** Indices in bottom-up order */
77
77
  /** @private @type {Map<Module, number>} */
78
- this._moduleIndicies2 = new Map();
78
+ this._moduleIndices2 = new Map();
79
79
  }
80
80
 
81
81
  /**
@@ -174,7 +174,7 @@ class ChunkGroup {
174
174
  /**
175
175
  * add a chunk into ChunkGroup. Is pushed on or prepended
176
176
  * @param {Chunk} chunk chunk being pushed into ChunkGroupS
177
- * @returns {boolean} returns true if chunk addition was ssuccesful.
177
+ * @returns {boolean} returns true if chunk addition was successful.
178
178
  */
179
179
  pushChunk(chunk) {
180
180
  const oldIdx = this.chunks.indexOf(chunk);
@@ -187,8 +187,8 @@ class ChunkGroup {
187
187
 
188
188
  /**
189
189
  * @param {Chunk} oldChunk chunk to be replaced
190
- * @param {Chunk} newChunk New chunkt that will be replaced
191
- * @returns {boolean} rerturns true for
190
+ * @param {Chunk} newChunk New chunk that will be replaced with
191
+ * @returns {boolean} returns true if the replacement was successful
192
192
  */
193
193
  replaceChunk(oldChunk, newChunk) {
194
194
  const oldIdx = this.chunks.indexOf(oldChunk);
@@ -345,7 +345,7 @@ class ChunkGroup {
345
345
  }
346
346
 
347
347
  /**
348
- * @param {ModuleReason} reason reason for removing ChunkGroup
348
+ * @param {string=} reason reason for removing ChunkGroup
349
349
  * @returns {void}
350
350
  */
351
351
  remove(reason) {
@@ -369,7 +369,7 @@ class ChunkGroup {
369
369
 
370
370
  /**
371
371
  * we need to iterate again over the children
372
- * to remove this from the childs parents.
372
+ * to remove this from the child's parents.
373
373
  * This can not be done in the above loop
374
374
  * as it is not guaranteed that `this._parents` contains anything.
375
375
  */
@@ -460,7 +460,7 @@ class ChunkGroup {
460
460
  * @returns {void}
461
461
  */
462
462
  setModuleIndex(module, index) {
463
- this._moduleIndicies.set(module, index);
463
+ this._moduleIndices.set(module, index);
464
464
  }
465
465
 
466
466
  /**
@@ -469,7 +469,7 @@ class ChunkGroup {
469
469
  * @returns {number} index
470
470
  */
471
471
  getModuleIndex(module) {
472
- return this._moduleIndicies.get(module);
472
+ return this._moduleIndices.get(module);
473
473
  }
474
474
 
475
475
  /**
@@ -479,7 +479,7 @@ class ChunkGroup {
479
479
  * @returns {void}
480
480
  */
481
481
  setModuleIndex2(module, index) {
482
- this._moduleIndicies2.set(module, index);
482
+ this._moduleIndices2.set(module, index);
483
483
  }
484
484
 
485
485
  /**
@@ -488,7 +488,7 @@ class ChunkGroup {
488
488
  * @returns {number} index
489
489
  */
490
490
  getModuleIndex2(module) {
491
- return this._moduleIndicies2.get(module);
491
+ return this._moduleIndices2.get(module);
492
492
  }
493
493
 
494
494
  checkConstraints() {
@@ -27,17 +27,16 @@ const HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate");
27
27
  const ModuleTemplate = require("./ModuleTemplate");
28
28
  const RuntimeTemplate = require("./RuntimeTemplate");
29
29
  const ChunkRenderError = require("./ChunkRenderError");
30
- const AsyncDependencyToInitialChunkError = require("./AsyncDependencyToInitialChunkError");
31
30
  const Stats = require("./Stats");
32
31
  const Semaphore = require("./util/Semaphore");
33
32
  const createHash = require("./util/createHash");
34
- const Queue = require("./util/Queue");
35
33
  const SortableSet = require("./util/SortableSet");
36
34
  const GraphHelpers = require("./GraphHelpers");
37
35
  const ModuleDependency = require("./dependencies/ModuleDependency");
38
36
  const compareLocations = require("./compareLocations");
39
37
  const { Logger, LogType } = require("./logging/Logger");
40
38
  const ErrorHelpers = require("./ErrorHelpers");
39
+ const buildChunkGraph = require("./buildChunkGraph");
41
40
 
42
41
  /** @typedef {import("./Module")} Module */
43
42
  /** @typedef {import("./Compiler")} Compiler */
@@ -165,16 +164,6 @@ const byNameOrHash = (a, b) => {
165
164
  return 0;
166
165
  };
167
166
 
168
- /**
169
- * @template T
170
- * @param {Set<T>} a first set
171
- * @param {Set<T>} b second set
172
- * @returns {number} cmp
173
- */
174
- const bySetSize = (a, b) => {
175
- return a.size - b.size;
176
- };
177
-
178
167
  /**
179
168
  * @param {DependenciesBlockVariable[]} variables DepBlock Variables to iterate over
180
169
  * @param {DepBlockVarDependenciesCallback} fn callback to apply on iterated elements
@@ -924,11 +913,6 @@ class Compilation extends Tapable {
924
913
  iterationDependencies(dependencies);
925
914
 
926
915
  const afterBuild = () => {
927
- if (currentProfile) {
928
- const afterBuilding = Date.now();
929
- currentProfile.building = afterBuilding - afterFactory;
930
- }
931
-
932
916
  if (recursive && addModuleResult.dependencies) {
933
917
  this.processModuleDependencies(dependentModule, callback);
934
918
  } else {
@@ -1070,11 +1054,6 @@ class Compilation extends Tapable {
1070
1054
  module.addReason(null, dependency);
1071
1055
 
1072
1056
  const afterBuild = () => {
1073
- if (currentProfile) {
1074
- const afterBuilding = Date.now();
1075
- currentProfile.building = afterBuilding - afterFactory;
1076
- }
1077
-
1078
1057
  if (addModuleResult.dependencies) {
1079
1058
  this.processModuleDependencies(module, err => {
1080
1059
  if (err) return callback(err);
@@ -1295,7 +1274,10 @@ class Compilation extends Tapable {
1295
1274
 
1296
1275
  this.assignDepth(module);
1297
1276
  }
1298
- this.processDependenciesBlocksForChunkGroups(this.chunkGroups.slice());
1277
+ buildChunkGraph(
1278
+ this,
1279
+ /** @type {Entrypoint[]} */ (this.chunkGroups.slice())
1280
+ );
1299
1281
  this.sortModules(this.modules);
1300
1282
  this.hooks.afterChunks.call(this.chunks);
1301
1283
 
@@ -1583,460 +1565,6 @@ class Compilation extends Tapable {
1583
1565
  return this.hooks.dependencyReference.call(ref, dependency, module);
1584
1566
  }
1585
1567
 
1586
- /**
1587
- * This method creates the Chunk graph from the Module graph
1588
- * @private
1589
- * @param {TODO[]} inputChunkGroups chunk groups which are processed
1590
- * @returns {void}
1591
- */
1592
- processDependenciesBlocksForChunkGroups(inputChunkGroups) {
1593
- // Process is splitting into two parts:
1594
- // Part one traverse the module graph and builds a very basic chunks graph
1595
- // in chunkDependencies.
1596
- // Part two traverse every possible way through the basic chunk graph and
1597
- // tracks the available modules. While traversing it connects chunks with
1598
- // eachother and Blocks with Chunks. It stops traversing when all modules
1599
- // for a chunk are already available. So it doesn't connect unneeded chunks.
1600
-
1601
- /** @type {Map<ChunkGroup, {block: AsyncDependenciesBlock, chunkGroup: ChunkGroup, couldBeFiltered: boolean}[]>} */
1602
- const chunkDependencies = new Map();
1603
- const allCreatedChunkGroups = new Set();
1604
-
1605
- // PREPARE
1606
- /** @type {Map<DependenciesBlock, { modules: Module[], blocks: AsyncDependenciesBlock[]}>} */
1607
- const blockInfoMap = new Map();
1608
-
1609
- /**
1610
- * @param {Dependency} d dependency to iterate over
1611
- * @returns {void}
1612
- */
1613
- const iteratorDependency = d => {
1614
- // We skip Dependencies without Reference
1615
- const ref = this.getDependencyReference(currentModule, d);
1616
- if (!ref) {
1617
- return;
1618
- }
1619
- // We skip Dependencies without Module pointer
1620
- const refModule = ref.module;
1621
- if (!refModule) {
1622
- return;
1623
- }
1624
- // We skip weak Dependencies
1625
- if (ref.weak) {
1626
- return;
1627
- }
1628
-
1629
- blockInfoModules.add(refModule);
1630
- };
1631
-
1632
- /**
1633
- * @param {AsyncDependenciesBlock} b blocks to prepare
1634
- * @returns {void}
1635
- */
1636
- const iteratorBlockPrepare = b => {
1637
- blockInfoBlocks.push(b);
1638
- blockQueue.push(b);
1639
- };
1640
-
1641
- /** @type {Module} */
1642
- let currentModule;
1643
- /** @type {DependenciesBlock} */
1644
- let block;
1645
- /** @type {DependenciesBlock[]} */
1646
- let blockQueue;
1647
- /** @type {Set<Module>} */
1648
- let blockInfoModules;
1649
- /** @type {AsyncDependenciesBlock[]} */
1650
- let blockInfoBlocks;
1651
-
1652
- for (const module of this.modules) {
1653
- blockQueue = [module];
1654
- currentModule = module;
1655
- while (blockQueue.length > 0) {
1656
- block = blockQueue.pop();
1657
- blockInfoModules = new Set();
1658
- blockInfoBlocks = [];
1659
-
1660
- if (block.variables) {
1661
- iterationBlockVariable(block.variables, iteratorDependency);
1662
- }
1663
-
1664
- if (block.dependencies) {
1665
- iterationOfArrayCallback(block.dependencies, iteratorDependency);
1666
- }
1667
-
1668
- if (block.blocks) {
1669
- iterationOfArrayCallback(block.blocks, iteratorBlockPrepare);
1670
- }
1671
-
1672
- const blockInfo = {
1673
- modules: Array.from(blockInfoModules),
1674
- blocks: blockInfoBlocks
1675
- };
1676
- blockInfoMap.set(block, blockInfo);
1677
- }
1678
- }
1679
-
1680
- // PART ONE
1681
-
1682
- /** @type {Map<ChunkGroup, { index: number, index2: number }>} */
1683
- const chunkGroupCounters = new Map();
1684
- for (const chunkGroup of inputChunkGroups) {
1685
- chunkGroupCounters.set(chunkGroup, { index: 0, index2: 0 });
1686
- }
1687
-
1688
- let nextFreeModuleIndex = 0;
1689
- let nextFreeModuleIndex2 = 0;
1690
-
1691
- /** @type {Map<DependenciesBlock, ChunkGroup>} */
1692
- const blockChunkGroups = new Map();
1693
-
1694
- /** @type {Set<DependenciesBlock>} */
1695
- const blocksWithNestedBlocks = new Set();
1696
-
1697
- const ADD_AND_ENTER_MODULE = 0;
1698
- const ENTER_MODULE = 1;
1699
- const PROCESS_BLOCK = 2;
1700
- const LEAVE_MODULE = 3;
1701
-
1702
- /**
1703
- * @typedef {Object} QueueItem
1704
- * @property {number} action
1705
- * @property {DependenciesBlock} block
1706
- * @property {Module} module
1707
- * @property {Chunk} chunk
1708
- * @property {ChunkGroup} chunkGroup
1709
- */
1710
-
1711
- /**
1712
- * @param {ChunkGroup} chunkGroup chunk group
1713
- * @returns {QueueItem} queue item
1714
- */
1715
- const chunkGroupToQueueItem = chunkGroup => ({
1716
- action: ENTER_MODULE,
1717
- block: chunkGroup.chunks[0].entryModule,
1718
- module: chunkGroup.chunks[0].entryModule,
1719
- chunk: chunkGroup.chunks[0],
1720
- chunkGroup
1721
- });
1722
-
1723
- // Start with the provided modules/chunks
1724
- /** @type {QueueItem[]} */
1725
- let queue = inputChunkGroups.map(chunkGroupToQueueItem).reverse();
1726
- /** @type {QueueItem[]} */
1727
- let queueDelayed = [];
1728
-
1729
- /** @type {Module} */
1730
- let module;
1731
- /** @type {Chunk} */
1732
- let chunk;
1733
- /** @type {ChunkGroup} */
1734
- let chunkGroup;
1735
-
1736
- // For each async Block in graph
1737
- /**
1738
- * @param {AsyncDependenciesBlock} b iterating over each Async DepBlock
1739
- * @returns {void}
1740
- */
1741
- const iteratorBlock = b => {
1742
- // 1. We create a chunk for this Block
1743
- // but only once (blockChunkGroups map)
1744
- let c = blockChunkGroups.get(b);
1745
- if (c === undefined) {
1746
- c = this.namedChunkGroups.get(b.chunkName);
1747
- if (c && c.isInitial()) {
1748
- this.errors.push(
1749
- new AsyncDependencyToInitialChunkError(b.chunkName, module, b.loc)
1750
- );
1751
- c = chunkGroup;
1752
- } else {
1753
- c = this.addChunkInGroup(
1754
- b.groupOptions || b.chunkName,
1755
- module,
1756
- b.loc,
1757
- b.request
1758
- );
1759
- chunkGroupCounters.set(c, { index: 0, index2: 0 });
1760
- blockChunkGroups.set(b, c);
1761
- allCreatedChunkGroups.add(c);
1762
- }
1763
- } else {
1764
- // TODO webpack 5 remove addOptions check
1765
- if (c.addOptions) c.addOptions(b.groupOptions);
1766
- c.addOrigin(module, b.loc, b.request);
1767
- }
1768
-
1769
- // 2. We store the Block+Chunk mapping as dependency for the chunk
1770
- let deps = chunkDependencies.get(chunkGroup);
1771
- if (!deps) chunkDependencies.set(chunkGroup, (deps = []));
1772
- deps.push({
1773
- block: b,
1774
- chunkGroup: c,
1775
- couldBeFiltered: true
1776
- });
1777
-
1778
- // 3. We enqueue the DependenciesBlock for traversal
1779
- queueDelayed.push({
1780
- action: PROCESS_BLOCK,
1781
- block: b,
1782
- module: module,
1783
- chunk: c.chunks[0],
1784
- chunkGroup: c
1785
- });
1786
- };
1787
-
1788
- // Iterative traversal of the Module graph
1789
- // Recursive would be simpler to write but could result in Stack Overflows
1790
- while (queue.length) {
1791
- while (queue.length) {
1792
- const queueItem = queue.pop();
1793
- module = queueItem.module;
1794
- block = queueItem.block;
1795
- chunk = queueItem.chunk;
1796
- chunkGroup = queueItem.chunkGroup;
1797
-
1798
- switch (queueItem.action) {
1799
- case ADD_AND_ENTER_MODULE: {
1800
- // We connect Module and Chunk when not already done
1801
- if (chunk.addModule(module)) {
1802
- module.addChunk(chunk);
1803
- } else {
1804
- // already connected, skip it
1805
- break;
1806
- }
1807
- }
1808
- // fallthrough
1809
- case ENTER_MODULE: {
1810
- if (chunkGroup !== undefined) {
1811
- const index = chunkGroup.getModuleIndex(module);
1812
- if (index === undefined) {
1813
- chunkGroup.setModuleIndex(
1814
- module,
1815
- chunkGroupCounters.get(chunkGroup).index++
1816
- );
1817
- }
1818
- }
1819
-
1820
- if (module.index === null) {
1821
- module.index = nextFreeModuleIndex++;
1822
- }
1823
-
1824
- queue.push({
1825
- action: LEAVE_MODULE,
1826
- block,
1827
- module,
1828
- chunk,
1829
- chunkGroup
1830
- });
1831
- }
1832
- // fallthrough
1833
- case PROCESS_BLOCK: {
1834
- // get prepared block info
1835
- const blockInfo = blockInfoMap.get(block);
1836
-
1837
- // Traverse all referenced modules
1838
- for (let i = blockInfo.modules.length - 1; i >= 0; i--) {
1839
- const refModule = blockInfo.modules[i];
1840
- if (chunk.containsModule(refModule)) {
1841
- // skip early if already connected
1842
- continue;
1843
- }
1844
- // enqueue the add and enter to enter in the correct order
1845
- // this is relevant with circular dependencies
1846
- queue.push({
1847
- action: ADD_AND_ENTER_MODULE,
1848
- block: refModule,
1849
- module: refModule,
1850
- chunk,
1851
- chunkGroup
1852
- });
1853
- }
1854
-
1855
- // Traverse all Blocks
1856
- iterationOfArrayCallback(blockInfo.blocks, iteratorBlock);
1857
-
1858
- if (blockInfo.blocks.length > 0 && module !== block) {
1859
- blocksWithNestedBlocks.add(block);
1860
- }
1861
- break;
1862
- }
1863
- case LEAVE_MODULE: {
1864
- if (chunkGroup !== undefined) {
1865
- const index = chunkGroup.getModuleIndex2(module);
1866
- if (index === undefined) {
1867
- chunkGroup.setModuleIndex2(
1868
- module,
1869
- chunkGroupCounters.get(chunkGroup).index2++
1870
- );
1871
- }
1872
- }
1873
-
1874
- if (module.index2 === null) {
1875
- module.index2 = nextFreeModuleIndex2++;
1876
- }
1877
- break;
1878
- }
1879
- }
1880
- }
1881
- const tempQueue = queue;
1882
- queue = queueDelayed.reverse();
1883
- queueDelayed = tempQueue;
1884
- }
1885
-
1886
- // PART TWO
1887
- /** @type {Set<Module>} */
1888
- let newAvailableModules;
1889
-
1890
- /**
1891
- * @typedef {Object} ChunkGroupInfo
1892
- * @property {Set<Module>} minAvailableModules current minimal set of modules available at this point
1893
- * @property {Set<Module>[]} availableModulesToBeMerged enqueued updates to the minimal set of available modules
1894
- */
1895
-
1896
- /** @type {Map<ChunkGroup, ChunkGroupInfo>} */
1897
- const chunkGroupInfoMap = new Map();
1898
-
1899
- /** @type {Queue<ChunkGroup>} */
1900
- const queue2 = new Queue(inputChunkGroups);
1901
-
1902
- for (const chunkGroup of inputChunkGroups) {
1903
- chunkGroupInfoMap.set(chunkGroup, {
1904
- minAvailableModules: undefined,
1905
- availableModulesToBeMerged: [new Set()]
1906
- });
1907
- }
1908
-
1909
- /**
1910
- * Helper function to check if all modules of a chunk are available
1911
- *
1912
- * @param {ChunkGroup} chunkGroup the chunkGroup to scan
1913
- * @param {Set<Module>} availableModules the comparitor set
1914
- * @returns {boolean} return true if all modules of a chunk are available
1915
- */
1916
- const areModulesAvailable = (chunkGroup, availableModules) => {
1917
- for (const chunk of chunkGroup.chunks) {
1918
- for (const module of chunk.modulesIterable) {
1919
- if (!availableModules.has(module)) return false;
1920
- }
1921
- }
1922
- return true;
1923
- };
1924
-
1925
- // For each edge in the basic chunk graph
1926
- /**
1927
- * @param {TODO} dep the dependency used for filtering
1928
- * @returns {boolean} used to filter "edges" (aka Dependencies) that were pointing
1929
- * to modules that are already available. Also filters circular dependencies in the chunks graph
1930
- */
1931
- const filterFn = dep => {
1932
- const depChunkGroup = dep.chunkGroup;
1933
- if (!dep.couldBeFiltered) return true;
1934
- if (blocksWithNestedBlocks.has(dep.block)) return true;
1935
- if (areModulesAvailable(depChunkGroup, newAvailableModules)) {
1936
- return false; // break all modules are already available
1937
- }
1938
- dep.couldBeFiltered = false;
1939
- return true;
1940
- };
1941
-
1942
- // Iterative traversing of the basic chunk graph
1943
- while (queue2.length) {
1944
- chunkGroup = queue2.dequeue();
1945
- const info = chunkGroupInfoMap.get(chunkGroup);
1946
- const availableModulesToBeMerged = info.availableModulesToBeMerged;
1947
- let minAvailableModules = info.minAvailableModules;
1948
-
1949
- // 1. Get minimal available modules
1950
- // It doesn't make sense to traverse a chunk again with more available modules.
1951
- // This step calculates the minimal available modules and skips traversal when
1952
- // the list didn't shrink.
1953
- availableModulesToBeMerged.sort(bySetSize);
1954
- let changed = false;
1955
- for (const availableModules of availableModulesToBeMerged) {
1956
- if (minAvailableModules === undefined) {
1957
- minAvailableModules = new Set(availableModules);
1958
- info.minAvailableModules = minAvailableModules;
1959
- changed = true;
1960
- } else {
1961
- for (const m of minAvailableModules) {
1962
- if (!availableModules.has(m)) {
1963
- minAvailableModules.delete(m);
1964
- changed = true;
1965
- }
1966
- }
1967
- }
1968
- }
1969
- availableModulesToBeMerged.length = 0;
1970
- if (!changed) continue;
1971
-
1972
- // 2. Get the edges at this point of the graph
1973
- const deps = chunkDependencies.get(chunkGroup);
1974
- if (!deps) continue;
1975
- if (deps.length === 0) continue;
1976
-
1977
- // 3. Create a new Set of available modules at this points
1978
- newAvailableModules = new Set(minAvailableModules);
1979
- for (const chunk of chunkGroup.chunks) {
1980
- for (const m of chunk.modulesIterable) {
1981
- newAvailableModules.add(m);
1982
- }
1983
- }
1984
-
1985
- // 4. Foreach remaining edge
1986
- const nextChunkGroups = new Set();
1987
- for (let i = 0; i < deps.length; i++) {
1988
- const dep = deps[i];
1989
-
1990
- // Filter inline, rather than creating a new array from `.filter()`
1991
- if (!filterFn(dep)) {
1992
- continue;
1993
- }
1994
- const depChunkGroup = dep.chunkGroup;
1995
- const depBlock = dep.block;
1996
-
1997
- // 5. Connect block with chunk
1998
- GraphHelpers.connectDependenciesBlockAndChunkGroup(
1999
- depBlock,
2000
- depChunkGroup
2001
- );
2002
-
2003
- // 6. Connect chunk with parent
2004
- GraphHelpers.connectChunkGroupParentAndChild(chunkGroup, depChunkGroup);
2005
-
2006
- nextChunkGroups.add(depChunkGroup);
2007
- }
2008
-
2009
- // 7. Enqueue further traversal
2010
- for (const nextChunkGroup of nextChunkGroups) {
2011
- let nextInfo = chunkGroupInfoMap.get(nextChunkGroup);
2012
- if (nextInfo === undefined) {
2013
- nextInfo = {
2014
- minAvailableModules: undefined,
2015
- availableModulesToBeMerged: []
2016
- };
2017
- chunkGroupInfoMap.set(nextChunkGroup, nextInfo);
2018
- }
2019
- nextInfo.availableModulesToBeMerged.push(newAvailableModules);
2020
-
2021
- // As queue deduplicates enqueued items this makes sure that a ChunkGroup
2022
- // is not enqueued twice
2023
- queue2.enqueue(nextChunkGroup);
2024
- }
2025
- }
2026
-
2027
- // Remove all unconnected chunk groups
2028
- for (const chunkGroup of allCreatedChunkGroups) {
2029
- if (chunkGroup.getNumberOfParents() === 0) {
2030
- for (const chunk of chunkGroup.chunks) {
2031
- const idx = this.chunks.indexOf(chunk);
2032
- if (idx >= 0) this.chunks.splice(idx, 1);
2033
- chunk.remove("unconnected");
2034
- }
2035
- chunkGroup.remove("unconnected");
2036
- }
2037
- }
2038
- }
2039
-
2040
1568
  /**
2041
1569
  *
2042
1570
  * @param {Module} module module relationship for removal