webpack 5.57.0 → 5.58.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

@@ -33,8 +33,6 @@ class AsyncDependenciesBlock extends DependenciesBlock {
33
33
  this.groupOptions = groupOptions;
34
34
  this.loc = loc;
35
35
  this.request = request;
36
- /** @type {DependenciesBlock} */
37
- this.parent = undefined;
38
36
  this._stringifiedGroupOptions = undefined;
39
37
  }
40
38
 
package/lib/ChunkGraph.js CHANGED
@@ -235,16 +235,6 @@ class ChunkGraph {
235
235
  this._hashFunction = hashFunction;
236
236
 
237
237
  this._getGraphRoots = this._getGraphRoots.bind(this);
238
-
239
- // Caching
240
- this._cacheChunkGraphModuleKey1 = undefined;
241
- this._cacheChunkGraphModuleValue1 = undefined;
242
- this._cacheChunkGraphModuleKey2 = undefined;
243
- this._cacheChunkGraphModuleValue2 = undefined;
244
- this._cacheChunkGraphChunkKey1 = undefined;
245
- this._cacheChunkGraphChunkValue1 = undefined;
246
- this._cacheChunkGraphChunkKey2 = undefined;
247
- this._cacheChunkGraphChunkValue2 = undefined;
248
238
  }
249
239
 
250
240
  /**
@@ -253,19 +243,11 @@ class ChunkGraph {
253
243
  * @returns {ChunkGraphModule} internal module
254
244
  */
255
245
  _getChunkGraphModule(module) {
256
- if (this._cacheChunkGraphModuleKey1 === module)
257
- return this._cacheChunkGraphModuleValue1;
258
- if (this._cacheChunkGraphModuleKey2 === module)
259
- return this._cacheChunkGraphModuleValue2;
260
246
  let cgm = this._modules.get(module);
261
247
  if (cgm === undefined) {
262
248
  cgm = new ChunkGraphModule();
263
249
  this._modules.set(module, cgm);
264
250
  }
265
- this._cacheChunkGraphModuleKey2 = this._cacheChunkGraphModuleKey1;
266
- this._cacheChunkGraphModuleValue2 = this._cacheChunkGraphModuleValue1;
267
- this._cacheChunkGraphModuleKey1 = module;
268
- this._cacheChunkGraphModuleValue1 = cgm;
269
251
  return cgm;
270
252
  }
271
253
 
@@ -275,19 +257,11 @@ class ChunkGraph {
275
257
  * @returns {ChunkGraphChunk} internal chunk
276
258
  */
277
259
  _getChunkGraphChunk(chunk) {
278
- if (this._cacheChunkGraphChunkKey1 === chunk)
279
- return this._cacheChunkGraphChunkValue1;
280
- if (this._cacheChunkGraphChunkKey2 === chunk)
281
- return this._cacheChunkGraphChunkValue2;
282
260
  let cgc = this._chunks.get(chunk);
283
261
  if (cgc === undefined) {
284
262
  cgc = new ChunkGraphChunk();
285
263
  this._chunks.set(chunk, cgc);
286
264
  }
287
- this._cacheChunkGraphChunkKey2 = this._cacheChunkGraphChunkKey1;
288
- this._cacheChunkGraphChunkValue2 = this._cacheChunkGraphChunkValue1;
289
- this._cacheChunkGraphChunkKey1 = chunk;
290
- this._cacheChunkGraphChunkValue1 = cgc;
291
265
  return cgc;
292
266
  }
293
267
 
@@ -416,10 +416,10 @@ const byLocation = compareSelect(err => err.loc, compareLocations);
416
416
 
417
417
  const compareErrors = concatComparators(byModule, byLocation, byMessage);
418
418
 
419
- /** @type {WeakMap<Dependency, Module & { restoreFromUnsafeCache: Function }>} */
419
+ /** @type {WeakMap<Dependency, Module & { restoreFromUnsafeCache: Function } | null>} */
420
420
  const unsafeCacheDependencies = new WeakMap();
421
421
 
422
- /** @type {WeakMap<Module, object>} */
422
+ /** @type {WeakMap<Module & { restoreFromUnsafeCache: Function }, object>} */
423
423
  const unsafeCacheData = new WeakMap();
424
424
 
425
425
  class Compilation {
@@ -1023,8 +1023,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1023
1023
  this.usedModuleIds = null;
1024
1024
  /** @type {boolean} */
1025
1025
  this.needAdditionalPass = false;
1026
- /** @type {Set<Module>} */
1027
- this._restoredUnsafeCacheEntries = new Set();
1026
+ /** @type {Set<Module & { restoreFromUnsafeCache: Function }>} */
1027
+ this._restoredUnsafeCacheModuleEntries = new Set();
1028
+ /** @type {Map<string, Module & { restoreFromUnsafeCache: Function }>} */
1029
+ this._restoredUnsafeCacheEntries = new Map();
1028
1030
  /** @type {WeakSet<Module>} */
1029
1031
  this.builtModules = new WeakSet();
1030
1032
  /** @type {WeakSet<Module>} */
@@ -1405,8 +1407,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1405
1407
  processModuleDependenciesNonRecursive(module) {
1406
1408
  const processDependenciesBlock = block => {
1407
1409
  if (block.dependencies) {
1410
+ let i = 0;
1408
1411
  for (const dep of block.dependencies) {
1409
- this.moduleGraph.setParents(dep, block, module);
1412
+ this.moduleGraph.setParents(dep, block, module, i++);
1410
1413
  }
1411
1414
  }
1412
1415
  if (block.blocks) {
@@ -1423,9 +1426,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1423
1426
  * @returns {void}
1424
1427
  */
1425
1428
  _processModuleDependencies(module, callback) {
1426
- /**
1427
- * @type {Array<{factory: ModuleFactory, dependencies: Dependency[], originModule: Module|null}>}
1428
- */
1429
+ /** @type {Array<{factory: ModuleFactory, dependencies: Dependency[], originModule: Module|null}>} */
1429
1430
  const sortedDependencies = [];
1430
1431
 
1431
1432
  /** @type {DependenciesBlock} */
@@ -1446,44 +1447,161 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1446
1447
  /** @type {Dependency[]} */
1447
1448
  let listCacheValue;
1448
1449
 
1449
- const unsafeRestoredModules = new Set();
1450
+ let inProgressSorting = 1;
1451
+ let inProgressTransitive = 1;
1452
+
1453
+ const onDependenciesSorted = err => {
1454
+ if (err) return callback(err);
1455
+
1456
+ // early exit without changing parallelism back and forth
1457
+ if (sortedDependencies.length === 0 && inProgressTransitive === 1) {
1458
+ return callback();
1459
+ }
1460
+
1461
+ // This is nested so we need to allow one additional task
1462
+ this.processDependenciesQueue.increaseParallelism();
1463
+
1464
+ for (const item of sortedDependencies) {
1465
+ inProgressTransitive++;
1466
+ this.handleModuleCreation(item, err => {
1467
+ // In V8, the Error objects keep a reference to the functions on the stack. These warnings &
1468
+ // errors are created inside closures that keep a reference to the Compilation, so errors are
1469
+ // leaking the Compilation object.
1470
+ if (err && this.bail) {
1471
+ if (inProgressTransitive <= 0) return;
1472
+ inProgressTransitive = -1;
1473
+ // eslint-disable-next-line no-self-assign
1474
+ err.stack = err.stack;
1475
+ onTransitiveTasksFinished(err);
1476
+ return;
1477
+ }
1478
+ if (--inProgressTransitive === 0) onTransitiveTasksFinished();
1479
+ });
1480
+ }
1481
+ if (--inProgressTransitive === 0) onTransitiveTasksFinished();
1482
+ };
1483
+
1484
+ const onTransitiveTasksFinished = err => {
1485
+ if (err) return callback(err);
1486
+ this.processDependenciesQueue.decreaseParallelism();
1487
+
1488
+ return callback();
1489
+ };
1450
1490
 
1451
1491
  /**
1452
1492
  * @param {Dependency} dep dependency
1493
+ * @param {number} index index in block
1453
1494
  * @returns {void}
1454
1495
  */
1455
- const processDependency = dep => {
1456
- this.moduleGraph.setParents(dep, currentBlock, module);
1496
+ const processDependency = (dep, index) => {
1497
+ this.moduleGraph.setParents(dep, currentBlock, module, index);
1457
1498
  if (this._unsafeCache) {
1458
1499
  try {
1459
- const cachedModule = unsafeCacheDependencies.get(dep);
1460
- if (cachedModule === null) return;
1461
- if (cachedModule !== undefined) {
1462
- if (!this._restoredUnsafeCacheEntries.has(cachedModule)) {
1463
- const data = unsafeCacheData.get(cachedModule);
1464
- cachedModule.restoreFromUnsafeCache(
1465
- data,
1466
- this.params.normalModuleFactory,
1467
- this.params
1500
+ const unsafeCachedModule = unsafeCacheDependencies.get(dep);
1501
+ if (unsafeCachedModule === null) return;
1502
+ if (unsafeCachedModule !== undefined) {
1503
+ if (
1504
+ this._restoredUnsafeCacheModuleEntries.has(unsafeCachedModule)
1505
+ ) {
1506
+ this._handleExistingModuleFromUnsafeCache(
1507
+ module,
1508
+ dep,
1509
+ unsafeCachedModule
1468
1510
  );
1469
- this._restoredUnsafeCacheEntries.add(cachedModule);
1470
- if (!this.modules.has(cachedModule)) {
1471
- this._handleNewModuleFromUnsafeCache(module, dep, cachedModule);
1472
- unsafeRestoredModules.add(cachedModule);
1511
+ return;
1512
+ }
1513
+ const identifier = unsafeCachedModule.identifier();
1514
+ const cachedModule =
1515
+ this._restoredUnsafeCacheEntries.get(identifier);
1516
+ if (cachedModule !== undefined) {
1517
+ // update unsafe cache to new module
1518
+ unsafeCacheDependencies.set(dep, cachedModule);
1519
+ this._handleExistingModuleFromUnsafeCache(
1520
+ module,
1521
+ dep,
1522
+ cachedModule
1523
+ );
1524
+ return;
1525
+ }
1526
+ inProgressSorting++;
1527
+ this._modulesCache.get(identifier, null, (err, cachedModule) => {
1528
+ if (err) {
1529
+ if (inProgressSorting <= 0) return;
1530
+ inProgressSorting = -1;
1531
+ onDependenciesSorted(err);
1473
1532
  return;
1474
1533
  }
1475
- }
1476
- this._handleExistingModuleFromUnsafeCache(
1477
- module,
1478
- dep,
1479
- cachedModule
1480
- );
1534
+ try {
1535
+ if (!this._restoredUnsafeCacheEntries.has(identifier)) {
1536
+ const data = unsafeCacheData.get(cachedModule);
1537
+ if (data === undefined) {
1538
+ processDependencyForResolving(dep);
1539
+ if (--inProgressSorting === 0) onDependenciesSorted();
1540
+ return;
1541
+ }
1542
+ if (cachedModule !== unsafeCachedModule) {
1543
+ unsafeCacheDependencies.set(dep, cachedModule);
1544
+ }
1545
+ cachedModule.restoreFromUnsafeCache(
1546
+ data,
1547
+ this.params.normalModuleFactory,
1548
+ this.params
1549
+ );
1550
+ this._restoredUnsafeCacheEntries.set(
1551
+ identifier,
1552
+ cachedModule
1553
+ );
1554
+ this._restoredUnsafeCacheModuleEntries.add(cachedModule);
1555
+ if (!this.modules.has(cachedModule)) {
1556
+ inProgressTransitive++;
1557
+ this._handleNewModuleFromUnsafeCache(
1558
+ module,
1559
+ dep,
1560
+ cachedModule,
1561
+ err => {
1562
+ if (err) {
1563
+ if (inProgressTransitive <= 0) return;
1564
+ inProgressTransitive = -1;
1565
+ onTransitiveTasksFinished(err);
1566
+ }
1567
+ if (--inProgressTransitive === 0)
1568
+ return onTransitiveTasksFinished();
1569
+ }
1570
+ );
1571
+ if (--inProgressSorting === 0) onDependenciesSorted();
1572
+ return;
1573
+ }
1574
+ }
1575
+ if (unsafeCachedModule !== cachedModule) {
1576
+ unsafeCacheDependencies.set(dep, cachedModule);
1577
+ }
1578
+ this._handleExistingModuleFromUnsafeCache(
1579
+ module,
1580
+ dep,
1581
+ cachedModule
1582
+ ); // a3
1583
+ } catch (err) {
1584
+ if (inProgressSorting <= 0) return;
1585
+ inProgressSorting = -1;
1586
+ onDependenciesSorted(err);
1587
+ return;
1588
+ }
1589
+ if (--inProgressSorting === 0) onDependenciesSorted();
1590
+ });
1481
1591
  return;
1482
1592
  }
1483
1593
  } catch (e) {
1484
1594
  console.error(e);
1485
1595
  }
1486
1596
  }
1597
+ processDependencyForResolving(dep);
1598
+ };
1599
+
1600
+ /**
1601
+ * @param {Dependency} dep dependency
1602
+ * @returns {void}
1603
+ */
1604
+ const processDependencyForResolving = dep => {
1487
1605
  const resourceIdent = dep.getResourceIdentifier();
1488
1606
  if (resourceIdent !== undefined && resourceIdent !== null) {
1489
1607
  const category = dep.category;
@@ -1557,7 +1675,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1557
1675
  const block = queue.pop();
1558
1676
  if (block.dependencies) {
1559
1677
  currentBlock = block;
1560
- for (const dep of block.dependencies) processDependency(dep);
1678
+ let i = 0;
1679
+ for (const dep of block.dependencies) processDependency(dep, i++);
1561
1680
  }
1562
1681
  if (block.blocks) {
1563
1682
  for (const b of block.blocks) queue.push(b);
@@ -1567,68 +1686,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1567
1686
  return callback(e);
1568
1687
  }
1569
1688
 
1570
- if (sortedDependencies.length === 0 && unsafeRestoredModules.size === 0) {
1571
- callback();
1572
- return;
1573
- }
1574
-
1575
- // This is nested so we need to allow one additional task
1576
- this.processDependenciesQueue.increaseParallelism();
1577
-
1578
- const processSortedDependency = (item, callback) => {
1579
- this.handleModuleCreation(item, err => {
1580
- // In V8, the Error objects keep a reference to the functions on the stack. These warnings &
1581
- // errors are created inside closures that keep a reference to the Compilation, so errors are
1582
- // leaking the Compilation object.
1583
- if (err && this.bail) {
1584
- // eslint-disable-next-line no-self-assign
1585
- err.stack = err.stack;
1586
- return callback(err);
1587
- }
1588
- callback();
1589
- });
1590
- };
1591
-
1592
- const processUnsafeRestoredModule = (item, callback) => {
1593
- this._handleModuleBuildAndDependencies(module, item, true, callback);
1594
- };
1595
-
1596
- const finalCallback = err => {
1597
- this.processDependenciesQueue.decreaseParallelism();
1598
-
1599
- return callback(err);
1600
- };
1601
-
1602
- if (sortedDependencies.length === 0) {
1603
- asyncLib.forEach(
1604
- unsafeRestoredModules,
1605
- processUnsafeRestoredModule,
1606
- finalCallback
1607
- );
1608
- } else if (unsafeRestoredModules.size === 0) {
1609
- asyncLib.forEach(
1610
- sortedDependencies,
1611
- processSortedDependency,
1612
- finalCallback
1613
- );
1614
- } else {
1615
- asyncLib.parallel(
1616
- [
1617
- cb =>
1618
- asyncLib.forEach(
1619
- unsafeRestoredModules,
1620
- processUnsafeRestoredModule,
1621
- cb
1622
- ),
1623
- cb =>
1624
- asyncLib.forEach(sortedDependencies, processSortedDependency, cb)
1625
- ],
1626
- finalCallback
1627
- );
1628
- }
1689
+ if (--inProgressSorting === 0) onDependenciesSorted();
1629
1690
  }
1630
1691
 
1631
- _handleNewModuleFromUnsafeCache(originModule, dependency, module) {
1692
+ _handleNewModuleFromUnsafeCache(originModule, dependency, module, callback) {
1632
1693
  const moduleGraph = this.moduleGraph;
1633
1694
 
1634
1695
  moduleGraph.setResolvedModule(originModule, dependency, module);
@@ -1641,6 +1702,13 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1641
1702
  this._modules.set(module.identifier(), module);
1642
1703
  this.modules.add(module);
1643
1704
  ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1705
+
1706
+ this._handleModuleBuildAndDependencies(
1707
+ originModule,
1708
+ module,
1709
+ true,
1710
+ callback
1711
+ );
1644
1712
  }
1645
1713
 
1646
1714
  _handleExistingModuleFromUnsafeCache(originModule, dependency, module) {
@@ -1744,20 +1812,24 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1744
1812
  /** @type {any} */ (module).restoreFromUnsafeCache &&
1745
1813
  this._unsafeCachePredicate(module)
1746
1814
  ) {
1815
+ const unsafeCacheableModule =
1816
+ /** @type {Module & { restoreFromUnsafeCache: Function }} */ (
1817
+ module
1818
+ );
1747
1819
  for (let i = 0; i < dependencies.length; i++) {
1748
1820
  const dependency = dependencies[i];
1749
1821
  moduleGraph.setResolvedModule(
1750
1822
  connectOrigin ? originModule : null,
1751
1823
  dependency,
1752
- module
1753
- );
1754
- unsafeCacheDependencies.set(
1755
- dependency,
1756
- /** @type {any} */ (module)
1824
+ unsafeCacheableModule
1757
1825
  );
1826
+ unsafeCacheDependencies.set(dependency, unsafeCacheableModule);
1758
1827
  }
1759
- if (!unsafeCacheData.has(module)) {
1760
- unsafeCacheData.set(module, module.getUnsafeCacheData());
1828
+ if (!unsafeCacheData.has(unsafeCacheableModule)) {
1829
+ unsafeCacheData.set(
1830
+ unsafeCacheableModule,
1831
+ unsafeCacheableModule.getUnsafeCacheData()
1832
+ );
1761
1833
  }
1762
1834
  } else {
1763
1835
  applyFactoryResultDependencies();
@@ -2252,7 +2324,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2252
2324
  }
2253
2325
 
2254
2326
  for (const module of modulesWithoutCache) {
2255
- const buildInfo = module.buildInfo && module.buildInfo.buildInfo;
2327
+ const buildInfo = module.buildInfo;
2256
2328
  if (buildInfo) {
2257
2329
  // create a new entry
2258
2330
  const memCache = new WeakTupleMap();
@@ -2334,12 +2406,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2334
2406
  );
2335
2407
  }
2336
2408
 
2337
- _updateAffectedModulesWithIds() {
2409
+ _computeAffectedModulesWithChunkGraph() {
2338
2410
  const { moduleMemCaches } = this;
2339
2411
  if (!moduleMemCaches) return;
2340
2412
  const moduleMemCaches2 = (this.moduleMemCaches2 = new Map());
2341
2413
  const { moduleGraph, chunkGraph } = this;
2342
2414
  const key = "memCache2";
2415
+ let statUnchanged = 0;
2416
+ let statChanged = 0;
2417
+ let statNew = 0;
2343
2418
  /**
2344
2419
  * @param {Module} module module
2345
2420
  * @returns {{ modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
@@ -2354,7 +2429,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2354
2429
  for (const m of outgoing.keys()) {
2355
2430
  if (!m) continue;
2356
2431
  if (modules === undefined) modules = new Map();
2357
- modules.set(m, chunkGraph.getModuleId(module));
2432
+ modules.set(m, chunkGraph.getModuleId(m));
2358
2433
  }
2359
2434
  }
2360
2435
  if (module.blocks.length > 0) {
@@ -2416,15 +2491,24 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2416
2491
  memCache: memCache2
2417
2492
  });
2418
2493
  moduleMemCaches2.set(module, memCache2);
2494
+ statNew++;
2419
2495
  } else if (!compareReferences(module, cache.references)) {
2420
2496
  const memCache = new WeakTupleMap();
2421
2497
  cache.references = computeReferences(module);
2422
2498
  cache.memCache = memCache;
2423
2499
  moduleMemCaches2.set(module, memCache);
2500
+ statChanged++;
2424
2501
  } else {
2425
2502
  moduleMemCaches2.set(module, cache.memCache);
2503
+ statUnchanged++;
2426
2504
  }
2427
2505
  }
2506
+
2507
+ this.logger.log(
2508
+ `${Math.round(
2509
+ (100 * statChanged) / (statNew + statChanged + statUnchanged)
2510
+ )}% modules flagged as affected by chunk graph (${statNew} new modules, ${statChanged} changed, ${statUnchanged} unchanged)`
2511
+ );
2428
2512
  }
2429
2513
 
2430
2514
  finish(callback) {
@@ -2727,13 +2811,14 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2727
2811
  this.chunkGroups.push(entrypoint);
2728
2812
  connectChunkGroupAndChunk(entrypoint, chunk);
2729
2813
 
2814
+ const entryModules = new Set();
2730
2815
  for (const dep of [...this.globalEntry.dependencies, ...dependencies]) {
2731
2816
  entrypoint.addOrigin(null, { name }, /** @type {any} */ (dep).request);
2732
2817
 
2733
2818
  const module = this.moduleGraph.getModule(dep);
2734
2819
  if (module) {
2735
2820
  chunkGraph.connectChunkAndEntryModule(chunk, module, entrypoint);
2736
- this.assignDepth(module);
2821
+ entryModules.add(module);
2737
2822
  const modulesList = chunkGraphInit.get(entrypoint);
2738
2823
  if (modulesList === undefined) {
2739
2824
  chunkGraphInit.set(entrypoint, [module]);
@@ -2743,6 +2828,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2743
2828
  }
2744
2829
  }
2745
2830
 
2831
+ this.assignDepths(entryModules);
2832
+
2746
2833
  const mapAndSort = deps =>
2747
2834
  deps
2748
2835
  .map(dep => this.moduleGraph.getModule(dep))
@@ -2889,7 +2976,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
2889
2976
 
2890
2977
  this.assignRuntimeIds();
2891
2978
 
2892
- this._updateAffectedModulesWithIds();
2979
+ this.logger.time("compute affected modules with chunk graph");
2980
+ this._computeAffectedModulesWithChunkGraph();
2981
+ this.logger.timeEnd("compute affected modules with chunk graph");
2893
2982
 
2894
2983
  this.sortItemsWithChunkIds();
2895
2984
 
@@ -3510,6 +3599,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3510
3599
  }
3511
3600
 
3512
3601
  /**
3602
+ * @deprecated
3513
3603
  * @param {Module} module module to assign depth
3514
3604
  * @returns {void}
3515
3605
  */
@@ -3543,6 +3633,38 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3543
3633
  }
3544
3634
  }
3545
3635
 
3636
+ /**
3637
+ * @param {Set<Module>} modules module to assign depth
3638
+ * @returns {void}
3639
+ */
3640
+ assignDepths(modules) {
3641
+ const moduleGraph = this.moduleGraph;
3642
+
3643
+ /** @type {Set<Module | number>} */
3644
+ const queue = new Set(modules);
3645
+ queue.add(1);
3646
+ let depth = 0;
3647
+
3648
+ let i = 0;
3649
+ for (const module of queue) {
3650
+ i++;
3651
+ if (typeof module === "number") {
3652
+ depth = module;
3653
+ if (queue.size === i) return;
3654
+ queue.add(depth + 1);
3655
+ } else {
3656
+ moduleGraph.setDepth(module, depth);
3657
+ for (const { module: refModule } of moduleGraph.getOutgoingConnections(
3658
+ module
3659
+ )) {
3660
+ if (refModule) {
3661
+ queue.add(refModule);
3662
+ }
3663
+ }
3664
+ }
3665
+ }
3666
+ }
3667
+
3546
3668
  /**
3547
3669
  * @param {Dependency} dependency the dependency
3548
3670
  * @param {RuntimeSpec} runtime the runtime
@@ -22,6 +22,15 @@ class DependenciesBlock {
22
22
  this.dependencies = [];
23
23
  /** @type {AsyncDependenciesBlock[]} */
24
24
  this.blocks = [];
25
+ /** @type {DependenciesBlock} */
26
+ this.parent = undefined;
27
+ }
28
+
29
+ getRootBlock() {
30
+ /** @type {DependenciesBlock} */
31
+ let current = this;
32
+ while (current.parent) current = current.parent;
33
+ return current;
25
34
  }
26
35
 
27
36
  /**
package/lib/Dependency.js CHANGED
@@ -91,6 +91,8 @@ class Dependency {
91
91
  this._parentModule = undefined;
92
92
  /** @type {DependenciesBlock} */
93
93
  this._parentDependenciesBlock = undefined;
94
+ /** @type {number} */
95
+ this._parentDependenciesBlockIndex = -1;
94
96
  // TODO check if this can be moved into ModuleDependency
95
97
  /** @type {boolean} */
96
98
  this.weak = false;