webpack 5.36.0 → 5.37.1

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.

Files changed (110) hide show
  1. package/README.md +5 -8
  2. package/bin/webpack.js +0 -0
  3. package/lib/CacheFacade.js +3 -3
  4. package/lib/Chunk.js +10 -5
  5. package/lib/ChunkGraph.js +58 -35
  6. package/lib/Compilation.js +116 -98
  7. package/lib/Compiler.js +31 -17
  8. package/lib/ConcatenationScope.js +2 -1
  9. package/lib/ContextModule.js +3 -3
  10. package/lib/ContextReplacementPlugin.js +4 -3
  11. package/lib/DefinePlugin.js +16 -12
  12. package/lib/EntryPlugin.js +1 -1
  13. package/lib/EvalSourceMapDevToolPlugin.js +3 -1
  14. package/lib/FileSystemInfo.js +25 -31
  15. package/lib/FlagDependencyExportsPlugin.js +8 -7
  16. package/lib/FlagDependencyUsagePlugin.js +2 -4
  17. package/lib/HotModuleReplacementPlugin.js +20 -30
  18. package/lib/InitFragment.js +21 -6
  19. package/lib/JavascriptMetaInfoPlugin.js +2 -1
  20. package/lib/MainTemplate.js +2 -3
  21. package/lib/ModuleFilenameHelpers.js +4 -2
  22. package/lib/ModuleGraph.js +2 -2
  23. package/lib/ModuleGraphConnection.js +6 -2
  24. package/lib/ModuleInfoHeaderPlugin.js +2 -3
  25. package/lib/MultiCompiler.js +31 -27
  26. package/lib/NormalModule.js +38 -7
  27. package/lib/NormalModuleFactory.js +27 -23
  28. package/lib/RecordIdsPlugin.js +5 -4
  29. package/lib/ResolverFactory.js +10 -7
  30. package/lib/RuntimeGlobals.js +7 -0
  31. package/lib/RuntimePlugin.js +19 -1
  32. package/lib/SourceMapDevToolPlugin.js +14 -15
  33. package/lib/Template.js +4 -2
  34. package/lib/Watching.js +83 -46
  35. package/lib/WebpackOptionsApply.js +1 -0
  36. package/lib/asset/AssetGenerator.js +19 -23
  37. package/lib/buildChunkGraph.js +28 -23
  38. package/lib/cache/PackFileCacheStrategy.js +77 -13
  39. package/lib/config/defaults.js +24 -10
  40. package/lib/config/normalization.js +17 -7
  41. package/lib/debug/ProfilingPlugin.js +4 -3
  42. package/lib/dependencies/AMDRequireDependency.js +3 -3
  43. package/lib/dependencies/CommonJsExportRequireDependency.js +2 -3
  44. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -1
  45. package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -4
  46. package/lib/dependencies/CommonJsPlugin.js +8 -7
  47. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  48. package/lib/dependencies/ContextDependencyHelpers.js +10 -8
  49. package/lib/dependencies/CreateScriptUrlDependency.js +54 -0
  50. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
  51. package/lib/dependencies/HarmonyExportInitFragment.js +47 -0
  52. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -4
  53. package/lib/dependencies/HarmonyImportSpecifierDependency.js +4 -11
  54. package/lib/dependencies/ImportDependency.js +3 -3
  55. package/lib/dependencies/ImportParserPlugin.js +2 -4
  56. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +2 -3
  57. package/lib/dependencies/RequireEnsureDependency.js +3 -3
  58. package/lib/dependencies/WorkerDependency.js +6 -6
  59. package/lib/dependencies/WorkerPlugin.js +47 -20
  60. package/lib/hmr/LazyCompilationPlugin.js +6 -4
  61. package/lib/ids/HashedModuleIdsPlugin.js +3 -3
  62. package/lib/ids/OccurrenceModuleIdsPlugin.js +2 -3
  63. package/lib/index.js +5 -3
  64. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -6
  65. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -3
  66. package/lib/javascript/JavascriptGenerator.js +3 -1
  67. package/lib/javascript/JavascriptModulesPlugin.js +15 -23
  68. package/lib/javascript/JavascriptParser.js +10 -8
  69. package/lib/library/AssignLibraryPlugin.js +4 -2
  70. package/lib/node/NodeWatchFileSystem.js +19 -4
  71. package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
  72. package/lib/optimize/ConcatenatedModule.js +22 -27
  73. package/lib/optimize/FlagIncludedChunksPlugin.js +4 -6
  74. package/lib/optimize/InnerGraph.js +9 -11
  75. package/lib/optimize/InnerGraphPlugin.js +3 -1
  76. package/lib/optimize/ModuleConcatenationPlugin.js +7 -10
  77. package/lib/optimize/RealContentHashPlugin.js +14 -16
  78. package/lib/optimize/SideEffectsFlagPlugin.js +6 -5
  79. package/lib/optimize/SplitChunksPlugin.js +13 -15
  80. package/lib/runtime/CreateScriptUrlRuntimeModule.js +61 -0
  81. package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
  82. package/lib/runtime/LoadScriptRuntimeModule.js +12 -5
  83. package/lib/runtime/OnChunksLoadedRuntimeModule.js +38 -37
  84. package/lib/serialization/BinaryMiddleware.js +2 -3
  85. package/lib/serialization/FileMiddleware.js +3 -1
  86. package/lib/serialization/ObjectMiddleware.js +11 -7
  87. package/lib/stats/DefaultStatsFactoryPlugin.js +2 -3
  88. package/lib/stats/DefaultStatsPrinterPlugin.js +11 -9
  89. package/lib/stats/StatsFactory.js +2 -1
  90. package/lib/stats/StatsPrinter.js +3 -3
  91. package/lib/util/LazyBucketSortedSet.js +3 -3
  92. package/lib/util/cleverMerge.js +3 -1
  93. package/lib/util/comparators.js +13 -13
  94. package/lib/util/fs.js +8 -8
  95. package/lib/util/identifier.js +2 -1
  96. package/lib/util/internalSerializables.js +2 -0
  97. package/lib/validateSchema.js +5 -3
  98. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +4 -4
  99. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +5 -4
  100. package/lib/wasm-sync/WebAssemblyGenerator.js +89 -83
  101. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -1
  102. package/lib/wasm-sync/WebAssemblyParser.js +6 -5
  103. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -4
  104. package/lib/webpack.js +11 -7
  105. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +13 -1
  106. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -4
  107. package/package.json +9 -6
  108. package/schemas/WebpackOptions.check.js +1 -1
  109. package/schemas/WebpackOptions.json +103 -60
  110. package/types.d.ts +463 -280
@@ -7,7 +7,8 @@
7
7
 
8
8
  /** @typedef {import("./Module")} Module */
9
9
 
10
- const MODULE_REFERENCE_REGEXP = /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(?:_asiSafe(\d))?__$/;
10
+ const MODULE_REFERENCE_REGEXP =
11
+ /^__WEBPACK_MODULE_REFERENCE__(\d+)_([\da-f]+|ns)(_call)?(_directImport)?(?:_asiSafe(\d))?__$/;
11
12
 
12
13
  const DEFAULT_EXPORT = "__WEBPACK_DEFAULT_EXPORT__";
13
14
  const NAMESPACE_OBJECT_EXPORT = "__WEBPACK_NAMESPACE_OBJECT__";
@@ -1016,9 +1016,9 @@ module.exports = webpackEmptyAsyncContext;`;
1016
1016
  this.getSource(this.getSourceString(this.options.mode, context))
1017
1017
  );
1018
1018
  const set = new Set();
1019
- const allDeps = /** @type {ContextElementDependency[]} */ (this.dependencies.concat(
1020
- this.blocks.map(b => b.dependencies[0])
1021
- ));
1019
+ const allDeps = /** @type {ContextElementDependency[]} */ (
1020
+ this.dependencies.concat(this.blocks.map(b => b.dependencies[0]))
1021
+ );
1022
1022
  set.add(RuntimeGlobals.module);
1023
1023
  set.add(RuntimeGlobals.hasOwnProperty);
1024
1024
  if (allDeps.length > 0) {
@@ -104,9 +104,10 @@ class ContextReplacementPlugin {
104
104
  result.regExp = newContentRegExp;
105
105
  }
106
106
  if (typeof newContentCreateContextMap === "function") {
107
- result.resolveDependencies = createResolveDependenciesFromContextMap(
108
- newContentCreateContextMap
109
- );
107
+ result.resolveDependencies =
108
+ createResolveDependenciesFromContextMap(
109
+ newContentCreateContextMap
110
+ );
110
111
  }
111
112
  if (typeof newContentCallback === "function") {
112
113
  const origResource = result.resource;
@@ -89,9 +89,9 @@ class RuntimeValue {
89
89
  module: parser.state.module,
90
90
  key,
91
91
  get version() {
92
- return /** @type {string} */ (valueCacheVersions.get(
93
- VALUE_DEP_PREFIX + key
94
- ));
92
+ return /** @type {string} */ (
93
+ valueCacheVersions.get(VALUE_DEP_PREFIX + key)
94
+ );
95
95
  }
96
96
  });
97
97
  }
@@ -286,11 +286,13 @@ class DefinePlugin {
286
286
  );
287
287
  const { runtimeTemplate } = compilation;
288
288
 
289
- const mainValue = /** @type {Set<string>} */ (provide(
290
- compilation.valueCacheVersions,
291
- VALUE_DEP_MAIN,
292
- () => new Set()
293
- ));
289
+ const mainValue = /** @type {Set<string>} */ (
290
+ provide(
291
+ compilation.valueCacheVersions,
292
+ VALUE_DEP_MAIN,
293
+ () => new Set()
294
+ )
295
+ );
294
296
 
295
297
  /**
296
298
  * Handler
@@ -313,10 +315,12 @@ class DefinePlugin {
313
315
  );
314
316
  };
315
317
 
316
- const withValueDependency = (key, fn) => (...args) => {
317
- addValueDependency(key);
318
- return fn(...args);
319
- };
318
+ const withValueDependency =
319
+ (key, fn) =>
320
+ (...args) => {
321
+ addValueDependency(key);
322
+ return fn(...args);
323
+ };
320
324
 
321
325
  /**
322
326
  * Walk definitions
@@ -17,7 +17,7 @@ class EntryPlugin {
17
17
  *
18
18
  * @param {string} context context path
19
19
  * @param {string} entry entry path
20
- * @param {EntryOptions | string} options entry options (passing a string is deprecated)
20
+ * @param {EntryOptions | string=} options entry options (passing a string is deprecated)
21
21
  */
22
22
  constructor(context, entry, options) {
23
23
  this.context = context;
@@ -91,7 +91,9 @@ class EvalSourceMapDevToolPlugin {
91
91
  } else if (m instanceof ConcatenatedModule) {
92
92
  const concatModule = /** @type {ConcatenatedModule} */ (m);
93
93
  if (concatModule.rootModule instanceof NormalModule) {
94
- const module = /** @type {NormalModule} */ (concatModule.rootModule);
94
+ const module = /** @type {NormalModule} */ (
95
+ concatModule.rootModule
96
+ );
95
97
  if (!matchModule(module.resource)) {
96
98
  return result(source);
97
99
  }
@@ -1160,12 +1160,8 @@ class FileSystemInfo {
1160
1160
  * @returns {void}
1161
1161
  */
1162
1162
  resolveBuildDependencies(context, deps, callback) {
1163
- const {
1164
- resolveContext,
1165
- resolveEsm,
1166
- resolveCjs,
1167
- resolveCjsAsChild
1168
- } = this._createBuildDependenciesResolvers();
1163
+ const { resolveContext, resolveEsm, resolveCjs, resolveCjsAsChild } =
1164
+ this._createBuildDependenciesResolvers();
1169
1165
 
1170
1166
  /** @type {Set<string>} */
1171
1167
  const files = new Set();
@@ -1472,7 +1468,7 @@ class FileSystemInfo {
1472
1468
  }
1473
1469
  } else if (supportsEsm && /\.m?js$/.test(path)) {
1474
1470
  if (!this._warnAboutExperimentalEsmTracking) {
1475
- this.logger.info(
1471
+ this.logger.log(
1476
1472
  "Node.js doesn't offer a (nice) way to introspect the ESM dependency graph yet.\n" +
1477
1473
  "Until a full solution is available webpack uses an experimental ESM tracking based on parsing.\n" +
1478
1474
  "As best effort webpack parses the ESM files to guess dependencies. But this can lead to expensive and incorrect tracking."
@@ -1547,9 +1543,8 @@ class FileSystemInfo {
1547
1543
  break;
1548
1544
  }
1549
1545
  case RBDT_DIRECTORY_DEPENDENCIES: {
1550
- const match = /(^.+[\\/]node_modules[\\/](?:@[^\\/]+[\\/])?[^\\/]+)/.exec(
1551
- path
1552
- );
1546
+ const match =
1547
+ /(^.+[\\/]node_modules[\\/](?:@[^\\/]+[\\/])?[^\\/]+)/.exec(path);
1553
1548
  const packagePath = match ? match[1] : path;
1554
1549
  const packageJson = join(this.fs, packagePath, "package.json");
1555
1550
  this.fs.readFile(packageJson, (err, content) => {
@@ -1637,12 +1632,8 @@ class FileSystemInfo {
1637
1632
  * @returns {void}
1638
1633
  */
1639
1634
  checkResolveResultsValid(resolveResults, callback) {
1640
- const {
1641
- resolveCjs,
1642
- resolveCjsAsChild,
1643
- resolveEsm,
1644
- resolveContext
1645
- } = this._createBuildDependenciesResolvers();
1635
+ const { resolveCjs, resolveCjsAsChild, resolveEsm, resolveContext } =
1636
+ this._createBuildDependenciesResolvers();
1646
1637
  asyncLib.eachLimit(
1647
1638
  resolveResults,
1648
1639
  20,
@@ -1844,11 +1835,12 @@ class FileSystemInfo {
1844
1835
  unsharedManagedFiles
1845
1836
  );
1846
1837
  }
1847
- const unsharedManagedContexts = this._managedContextsOptimization.optimize(
1848
- managedContexts,
1849
- undefined,
1850
- children
1851
- );
1838
+ const unsharedManagedContexts =
1839
+ this._managedContextsOptimization.optimize(
1840
+ managedContexts,
1841
+ undefined,
1842
+ children
1843
+ );
1852
1844
  if (managedContexts.size !== 0) {
1853
1845
  snapshot.setManagedContexts(managedContexts);
1854
1846
  this._managedContextsOptimization.storeUnsharedSnapshot(
@@ -1856,11 +1848,12 @@ class FileSystemInfo {
1856
1848
  unsharedManagedContexts
1857
1849
  );
1858
1850
  }
1859
- const unsharedManagedMissing = this._managedMissingOptimization.optimize(
1860
- managedMissing,
1861
- undefined,
1862
- children
1863
- );
1851
+ const unsharedManagedMissing =
1852
+ this._managedMissingOptimization.optimize(
1853
+ managedMissing,
1854
+ undefined,
1855
+ children
1856
+ );
1864
1857
  if (managedMissing.size !== 0) {
1865
1858
  snapshot.setManagedMissing(managedMissing);
1866
1859
  this._managedMissingOptimization.storeUnsharedSnapshot(
@@ -2064,11 +2057,12 @@ class FileSystemInfo {
2064
2057
  }
2065
2058
  break;
2066
2059
  case 1:
2067
- unsharedContextTimestamps = this._contextTimestampsOptimization.optimize(
2068
- capturedDirectories,
2069
- startTime,
2070
- children
2071
- );
2060
+ unsharedContextTimestamps =
2061
+ this._contextTimestampsOptimization.optimize(
2062
+ capturedDirectories,
2063
+ startTime,
2064
+ children
2065
+ );
2072
2066
  for (const path of capturedDirectories) {
2073
2067
  const cache = this._contextTimestamps.get(path);
2074
2068
  if (cache !== undefined) {
@@ -225,7 +225,8 @@ class FlagDependencyExportsPlugin {
225
225
  }
226
226
 
227
227
  if (exports) {
228
- const nestedExportsInfo = exportInfo.createNestedExportsInfo();
228
+ const nestedExportsInfo =
229
+ exportInfo.createNestedExportsInfo();
229
230
  mergeExports(nestedExportsInfo, exports);
230
231
  }
231
232
 
@@ -247,12 +248,12 @@ class FlagDependencyExportsPlugin {
247
248
  const target = exportInfo.getTarget(moduleGraph);
248
249
  let targetExportsInfo = undefined;
249
250
  if (target) {
250
- const targetModuleExportsInfo = moduleGraph.getExportsInfo(
251
- target.module
252
- );
253
- targetExportsInfo = targetModuleExportsInfo.getNestedExportsInfo(
254
- target.export
255
- );
251
+ const targetModuleExportsInfo =
252
+ moduleGraph.getExportsInfo(target.module);
253
+ targetExportsInfo =
254
+ targetModuleExportsInfo.getNestedExportsInfo(
255
+ target.export
256
+ );
256
257
  // add dependency for this module
257
258
  const set = dependencies.get(target.module);
258
259
  if (set === undefined) {
@@ -201,10 +201,8 @@ class FlagDependencyUsagePlugin {
201
201
  if (oldReferencedExports === EXPORTS_OBJECT_REFERENCED) {
202
202
  continue;
203
203
  }
204
- const referencedExports = compilation.getDependencyReferencedExports(
205
- dep,
206
- runtime
207
- );
204
+ const referencedExports =
205
+ compilation.getDependencyReferencedExports(dep, runtime);
208
206
  if (
209
207
  oldReferencedExports === undefined ||
210
208
  oldReferencedExports === NO_EXPORTS_REFERENCED ||
@@ -87,10 +87,8 @@ class HotModuleReplacementPlugin {
87
87
  const runtimeRequirements = [RuntimeGlobals.module];
88
88
 
89
89
  const createAcceptHandler = (parser, ParamDependency) => {
90
- const {
91
- hotAcceptCallback,
92
- hotAcceptWithoutCallback
93
- } = HotModuleReplacementPlugin.getParserHooks(parser);
90
+ const { hotAcceptCallback, hotAcceptWithoutCallback } =
91
+ HotModuleReplacementPlugin.getParserHooks(parser);
94
92
 
95
93
  return expr => {
96
94
  const module = parser.state.module;
@@ -306,9 +304,7 @@ class HotModuleReplacementPlugin {
306
304
  }
307
305
  records.chunkModuleIds = {};
308
306
  for (const chunk of compilation.chunks) {
309
- records.chunkModuleIds[
310
- chunk.id
311
- ] = Array.from(
307
+ records.chunkModuleIds[chunk.id] = Array.from(
312
308
  chunkGraph.getOrderedChunkModulesIterable(
313
309
  chunk,
314
310
  compareModulesById(chunkGraph)
@@ -341,9 +337,8 @@ class HotModuleReplacementPlugin {
341
337
  return chunkGraph.getModuleHash(module, chunk.runtime);
342
338
  }
343
339
  };
344
- const fullHashModulesInThisChunk = chunkGraph.getChunkFullHashModulesSet(
345
- chunk
346
- );
340
+ const fullHashModulesInThisChunk =
341
+ chunkGraph.getChunkFullHashModulesSet(chunk);
347
342
  if (fullHashModulesInThisChunk !== undefined) {
348
343
  for (const module of fullHashModulesInThisChunk) {
349
344
  fullHashModules.add(module, chunk);
@@ -451,16 +446,14 @@ class HotModuleReplacementPlugin {
451
446
  allOldRuntime = mergeRuntimeOwned(allOldRuntime, runtime);
452
447
  }
453
448
  forEachRuntime(allOldRuntime, runtime => {
454
- const {
455
- path: filename,
456
- info: assetInfo
457
- } = compilation.getPathWithInfo(
458
- compilation.outputOptions.hotUpdateMainFilename,
459
- {
460
- hash: records.hash,
461
- runtime
462
- }
463
- );
449
+ const { path: filename, info: assetInfo } =
450
+ compilation.getPathWithInfo(
451
+ compilation.outputOptions.hotUpdateMainFilename,
452
+ {
453
+ hash: records.hash,
454
+ runtime
455
+ }
456
+ );
464
457
  hotUpdateMainContentByRuntime.set(runtime, {
465
458
  updatedChunkIds: new Set(),
466
459
  removedChunkIds: new Set(),
@@ -516,9 +509,8 @@ class HotModuleReplacementPlugin {
516
509
  newRuntimeModules = Array.from(
517
510
  chunkGraph.getChunkRuntimeModulesIterable(currentChunk)
518
511
  ).filter(module => updatedModules.has(module, currentChunk));
519
- const fullHashModules = chunkGraph.getChunkFullHashModulesIterable(
520
- currentChunk
521
- );
512
+ const fullHashModules =
513
+ chunkGraph.getChunkFullHashModulesIterable(currentChunk);
522
514
  newFullHashModules =
523
515
  fullHashModules &&
524
516
  Array.from(fullHashModules).filter(module =>
@@ -631,13 +623,11 @@ class HotModuleReplacementPlugin {
631
623
  filename = entry.filename;
632
624
  assetInfo = entry.info;
633
625
  } else {
634
- ({
635
- path: filename,
636
- info: assetInfo
637
- } = compilation.getPathWithInfo(
638
- entry.filenameTemplate,
639
- entry.pathOptions
640
- ));
626
+ ({ path: filename, info: assetInfo } =
627
+ compilation.getPathWithInfo(
628
+ entry.filenameTemplate,
629
+ entry.pathOptions
630
+ ));
641
631
  }
642
632
  const source = entry.render();
643
633
  compilation.additionalChunkAssets.push(filename);
@@ -73,13 +73,25 @@ class InitFragment {
73
73
  // Deduplicate fragments. If a fragment has no key, it is always included.
74
74
  const keyedFragments = new Map();
75
75
  for (const [fragment] of sortedFragments) {
76
- if (typeof fragment.merge === "function") {
76
+ if (typeof fragment.mergeAll === "function") {
77
+ if (!fragment.key) {
78
+ throw new Error(
79
+ `InitFragment with mergeAll function must have a valid key: ${fragment.constructor.name}`
80
+ );
81
+ }
82
+ const oldValue = keyedFragments.get(fragment.key);
83
+ if (oldValue === undefined) {
84
+ keyedFragments.set(fragment.key, fragment);
85
+ } else if (Array.isArray(oldValue)) {
86
+ oldValue.push(fragment);
87
+ } else {
88
+ keyedFragments.set(fragment.key, [oldValue, fragment]);
89
+ }
90
+ continue;
91
+ } else if (typeof fragment.merge === "function") {
77
92
  const oldValue = keyedFragments.get(fragment.key);
78
93
  if (oldValue !== undefined) {
79
- keyedFragments.set(
80
- fragment.key || Symbol(),
81
- fragment.merge(oldValue)
82
- );
94
+ keyedFragments.set(fragment.key, fragment.merge(oldValue));
83
95
  continue;
84
96
  }
85
97
  }
@@ -88,7 +100,10 @@ class InitFragment {
88
100
 
89
101
  const concatSource = new ConcatSource();
90
102
  const endContents = [];
91
- for (const fragment of keyedFragments.values()) {
103
+ for (let fragment of keyedFragments.values()) {
104
+ if (Array.isArray(fragment)) {
105
+ fragment = fragment[0].mergeAll(fragment);
106
+ }
92
107
  concatSource.add(fragment.getContent(generateContext));
93
108
  const endContent = fragment.getEndContent(generateContext);
94
109
  if (endContent) {
@@ -34,7 +34,8 @@ class JavascriptMetaInfoPlugin {
34
34
  let topLevelDeclarations =
35
35
  parser.state.module.buildInfo.topLevelDeclarations;
36
36
  if (topLevelDeclarations === undefined) {
37
- topLevelDeclarations = parser.state.module.buildInfo.topLevelDeclarations = new Set();
37
+ topLevelDeclarations =
38
+ parser.state.module.buildInfo.topLevelDeclarations = new Set();
38
39
  }
39
40
  for (const name of parser.scope.definitions.asSet()) {
40
41
  const freeInfo = parser.getFreeInfoFromVariable(name);
@@ -239,9 +239,8 @@ class MainTemplate {
239
239
  "chunkIdExpression"
240
240
  ]),
241
241
  get jsonpScript() {
242
- const hooks = getLoadScriptRuntimeModule().getCompilationHooks(
243
- compilation
244
- );
242
+ const hooks =
243
+ getLoadScriptRuntimeModule().getCompilationHooks(compilation);
245
244
  return hooks.createScript;
246
245
  },
247
246
  get linkPrefetch() {
@@ -12,14 +12,16 @@ const ModuleFilenameHelpers = exports;
12
12
 
13
13
  // TODO webpack 6: consider removing these
14
14
  ModuleFilenameHelpers.ALL_LOADERS_RESOURCE = "[all-loaders][resource]";
15
- ModuleFilenameHelpers.REGEXP_ALL_LOADERS_RESOURCE = /\[all-?loaders\]\[resource\]/gi;
15
+ ModuleFilenameHelpers.REGEXP_ALL_LOADERS_RESOURCE =
16
+ /\[all-?loaders\]\[resource\]/gi;
16
17
  ModuleFilenameHelpers.LOADERS_RESOURCE = "[loaders][resource]";
17
18
  ModuleFilenameHelpers.REGEXP_LOADERS_RESOURCE = /\[loaders\]\[resource\]/gi;
18
19
  ModuleFilenameHelpers.RESOURCE = "[resource]";
19
20
  ModuleFilenameHelpers.REGEXP_RESOURCE = /\[resource\]/gi;
20
21
  ModuleFilenameHelpers.ABSOLUTE_RESOURCE_PATH = "[absolute-resource-path]";
21
22
  // cSpell:words olute
22
- ModuleFilenameHelpers.REGEXP_ABSOLUTE_RESOURCE_PATH = /\[abs(olute)?-?resource-?path\]/gi;
23
+ ModuleFilenameHelpers.REGEXP_ABSOLUTE_RESOURCE_PATH =
24
+ /\[abs(olute)?-?resource-?path\]/gi;
23
25
  ModuleFilenameHelpers.RESOURCE_PATH = "[resource-path]";
24
26
  ModuleFilenameHelpers.REGEXP_RESOURCE_PATH = /\[resource-?path\]/gi;
25
27
  ModuleFilenameHelpers.ALL_LOADERS = "[all-loaders]";
@@ -25,7 +25,7 @@ const WeakTupleMap = require("./util/WeakTupleMap");
25
25
  * @returns {string}
26
26
  */
27
27
 
28
- const EMPTY_ARRAY = [];
28
+ const EMPTY_SET = new Set();
29
29
 
30
30
  /**
31
31
  * @param {SortableSet<ModuleGraphConnection>} set input
@@ -396,7 +396,7 @@ class ModuleGraph {
396
396
  */
397
397
  getOutgoingConnections(module) {
398
398
  const connections = this._getModuleGraphModule(module).outgoingConnections;
399
- return connections === undefined ? EMPTY_ARRAY : connections;
399
+ return connections === undefined ? EMPTY_SET : connections;
400
400
  }
401
401
 
402
402
  /**
@@ -183,5 +183,9 @@ class ModuleGraphConnection {
183
183
 
184
184
  module.exports = ModuleGraphConnection;
185
185
  module.exports.addConnectionStates = addConnectionStates;
186
- module.exports.TRANSITIVE_ONLY = /** @type {typeof TRANSITIVE_ONLY} */ (TRANSITIVE_ONLY);
187
- module.exports.CIRCULAR_CONNECTION = /** @type {typeof CIRCULAR_CONNECTION} */ (CIRCULAR_CONNECTION);
186
+ module.exports.TRANSITIVE_ONLY = /** @type {typeof TRANSITIVE_ONLY} */ (
187
+ TRANSITIVE_ONLY
188
+ );
189
+ module.exports.CIRCULAR_CONNECTION = /** @type {typeof CIRCULAR_CONNECTION} */ (
190
+ CIRCULAR_CONNECTION
191
+ );
@@ -222,9 +222,8 @@ class ModuleInfoHeaderPlugin {
222
222
  )}`
223
223
  ) + "\n"
224
224
  );
225
- const optimizationBailout = moduleGraph.getOptimizationBailout(
226
- module
227
- );
225
+ const optimizationBailout =
226
+ moduleGraph.getOptimizationBailout(module);
228
227
  if (optimizationBailout) {
229
228
  for (const text of optimizationBailout) {
230
229
  let code;
@@ -318,16 +318,17 @@ module.exports = class MultiCompiler {
318
318
  * @returns {SetupResult[]} result of setup
319
319
  */
320
320
  _runGraph(setup, run, callback) {
321
- /** @typedef {{ compiler: Compiler, result: Stats, state: "pending" | "blocked" | "queued" | "running" | "running-outdated" | "done", children: Node[], parents: Node[] }} Node */
321
+ /** @typedef {{ compiler: Compiler, result: Stats, state: "pending" | "blocked" | "queued" | "starting" | "running" | "running-outdated" | "done", children: Node[], parents: Node[] }} Node */
322
322
 
323
323
  // State transitions for nodes:
324
324
  // -> blocked (initial)
325
- // blocked -> queued [add to queue] (when all parents done)
326
- // queued -> running [running++] (when processing the queue)
325
+ // blocked -> starting [running++] (when all parents done)
326
+ // queued -> starting [running++] (when processing the queue)
327
+ // starting -> running (when run has been called)
327
328
  // running -> done [running--] (when compilation is done)
328
329
  // done -> pending (when invalidated from file change)
329
- // pending -> blocked (when invalidated from aggregated changes)
330
- // done -> blocked (when invalidated, from parent invalidation)
330
+ // pending -> blocked [add to queue] (when invalidated from aggregated changes)
331
+ // done -> blocked [add to queue] (when invalidated, from parent invalidation)
331
332
  // running -> running-outdated (when invalidated, either from change or parent invalidation)
332
333
  // running-outdated -> blocked [running--] (when compilation is done)
333
334
 
@@ -351,6 +352,7 @@ module.exports = class MultiCompiler {
351
352
  parent.children.push(node);
352
353
  }
353
354
  }
355
+ /** @type {ArrayQueue<Node>} */
354
356
  const queue = new ArrayQueue();
355
357
  for (const node of nodes) {
356
358
  if (node.parents.length === 0) {
@@ -388,13 +390,13 @@ module.exports = class MultiCompiler {
388
390
  if (node.state === "running") {
389
391
  node.state = "done";
390
392
  for (const child of node.children) {
391
- checkUnblocked(child);
393
+ if (child.state === "blocked") queue.enqueue(child);
392
394
  }
393
395
  } else if (node.state === "running-outdated") {
394
396
  node.state = "blocked";
395
- checkUnblocked(node);
397
+ queue.enqueue(node);
396
398
  }
397
- process.nextTick(processQueue);
399
+ processQueue();
398
400
  };
399
401
  /**
400
402
  * @param {Node} node node
@@ -433,20 +435,9 @@ module.exports = class MultiCompiler {
433
435
  if (node.state === "pending") {
434
436
  node.state = "blocked";
435
437
  }
436
- checkUnblocked(node);
437
- processQueue();
438
- };
439
- /**
440
- * @param {Node} node node
441
- * @returns {void}
442
- */
443
- const checkUnblocked = node => {
444
- if (
445
- node.state === "blocked" &&
446
- node.parents.every(p => p.state === "done")
447
- ) {
448
- node.state = "queued";
438
+ if (node.state === "blocked") {
449
439
  queue.enqueue(node);
440
+ processQueue();
450
441
  }
451
442
  };
452
443
 
@@ -457,20 +448,33 @@ module.exports = class MultiCompiler {
457
448
  node.compiler,
458
449
  i,
459
450
  nodeDone.bind(null, node),
460
- () => node.state !== "done" && node.state !== "running",
451
+ () => node.state !== "starting" && node.state !== "running",
461
452
  () => nodeChange(node),
462
453
  () => nodeInvalid(node)
463
454
  )
464
455
  );
465
456
  });
457
+ let processing = true;
466
458
  const processQueue = () => {
459
+ if (processing) return;
460
+ processing = true;
461
+ process.nextTick(processQueueWorker);
462
+ };
463
+ const processQueueWorker = () => {
467
464
  while (running < parallelism && queue.length > 0 && !errored) {
468
465
  const node = queue.dequeue();
469
- if (node.state !== "queued") continue;
470
- running++;
471
- node.state = "running";
472
- run(node.compiler, nodeDone.bind(null, node));
466
+ if (
467
+ node.state === "queued" ||
468
+ (node.state === "blocked" &&
469
+ node.parents.every(p => p.state === "done"))
470
+ ) {
471
+ running++;
472
+ node.state = "starting";
473
+ run(node.compiler, nodeDone.bind(null, node));
474
+ node.state = "running";
475
+ }
473
476
  }
477
+ processing = false;
474
478
  if (
475
479
  !errored &&
476
480
  running === 0 &&
@@ -489,7 +493,7 @@ module.exports = class MultiCompiler {
489
493
  }
490
494
  }
491
495
  };
492
- processQueue();
496
+ processQueueWorker();
493
497
  return setupResults;
494
498
  }
495
499