webpack 5.37.0 → 5.39.0

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 (139) hide show
  1. package/README.md +5 -8
  2. package/bin/webpack.js +20 -5
  3. package/lib/AsyncDependencyToInitialChunkError.js +0 -2
  4. package/lib/CacheFacade.js +3 -3
  5. package/lib/CaseSensitiveModulesWarning.js +0 -2
  6. package/lib/Chunk.js +8 -5
  7. package/lib/ChunkRenderError.js +0 -2
  8. package/lib/CodeGenerationError.js +0 -2
  9. package/lib/CommentCompilationWarning.js +0 -2
  10. package/lib/Compilation.js +43 -55
  11. package/lib/Compiler.js +7 -4
  12. package/lib/ConcatenationScope.js +2 -1
  13. package/lib/ConcurrentCompilationError.js +0 -2
  14. package/lib/ContextModule.js +5 -4
  15. package/lib/ContextModuleFactory.js +3 -1
  16. package/lib/ContextReplacementPlugin.js +4 -3
  17. package/lib/DefinePlugin.js +16 -12
  18. package/lib/DllReferencePlugin.js +0 -2
  19. package/lib/EntryPlugin.js +3 -3
  20. package/lib/EvalSourceMapDevToolPlugin.js +3 -1
  21. package/lib/ExportsInfo.js +20 -13
  22. package/lib/FileSystemInfo.js +24 -30
  23. package/lib/FlagDependencyExportsPlugin.js +8 -7
  24. package/lib/FlagDependencyUsagePlugin.js +2 -4
  25. package/lib/HarmonyLinkingError.js +0 -2
  26. package/lib/HookWebpackError.js +0 -1
  27. package/lib/HotModuleReplacementPlugin.js +27 -32
  28. package/lib/InvalidDependenciesModuleWarning.js +0 -2
  29. package/lib/JavascriptMetaInfoPlugin.js +2 -1
  30. package/lib/MainTemplate.js +2 -3
  31. package/lib/ModuleBuildError.js +0 -2
  32. package/lib/ModuleDependencyError.js +0 -2
  33. package/lib/ModuleDependencyWarning.js +0 -2
  34. package/lib/ModuleError.js +0 -2
  35. package/lib/ModuleFilenameHelpers.js +4 -2
  36. package/lib/ModuleGraphConnection.js +6 -2
  37. package/lib/ModuleInfoHeaderPlugin.js +2 -3
  38. package/lib/ModuleNotFoundError.js +0 -2
  39. package/lib/ModuleParseError.js +0 -2
  40. package/lib/ModuleRestoreError.js +0 -2
  41. package/lib/ModuleStoreError.js +0 -2
  42. package/lib/ModuleWarning.js +0 -2
  43. package/lib/MultiCompiler.js +31 -27
  44. package/lib/NoModeWarning.js +0 -2
  45. package/lib/NormalModule.js +26 -8
  46. package/lib/NormalModuleFactory.js +2 -0
  47. package/lib/RecordIdsPlugin.js +5 -4
  48. package/lib/ResolverFactory.js +10 -7
  49. package/lib/SourceMapDevToolPlugin.js +13 -14
  50. package/lib/Template.js +4 -2
  51. package/lib/UnsupportedFeatureWarning.js +0 -2
  52. package/lib/WarnDeprecatedOptionPlugin.js +0 -2
  53. package/lib/Watching.js +91 -47
  54. package/lib/WebpackError.js +0 -2
  55. package/lib/asset/AssetGenerator.js +46 -29
  56. package/lib/asset/AssetModulesPlugin.js +1 -1
  57. package/lib/buildChunkGraph.js +21 -21
  58. package/lib/cache/PackFileCacheStrategy.js +12 -9
  59. package/lib/config/defaults.js +21 -10
  60. package/lib/config/normalization.js +8 -7
  61. package/lib/config/target.js +7 -2
  62. package/lib/debug/ProfilingPlugin.js +4 -3
  63. package/lib/dependencies/AMDRequireDependency.js +3 -3
  64. package/lib/dependencies/CommonJsExportRequireDependency.js +2 -3
  65. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -1
  66. package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -4
  67. package/lib/dependencies/CommonJsPlugin.js +8 -7
  68. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  69. package/lib/dependencies/ContextDependencyHelpers.js +10 -8
  70. package/lib/dependencies/ContextElementDependency.js +6 -1
  71. package/lib/dependencies/CriticalDependencyWarning.js +0 -2
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -4
  74. package/lib/dependencies/HarmonyImportSpecifierDependency.js +4 -11
  75. package/lib/dependencies/ImportDependency.js +3 -3
  76. package/lib/dependencies/ImportParserPlugin.js +3 -4
  77. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +2 -3
  78. package/lib/dependencies/RequireEnsureDependency.js +3 -3
  79. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +0 -2
  80. package/lib/dependencies/SystemPlugin.js +0 -2
  81. package/lib/dependencies/WorkerDependency.js +6 -6
  82. package/lib/dependencies/WorkerPlugin.js +18 -19
  83. package/lib/errors/BuildCycleError.js +0 -1
  84. package/lib/hmr/LazyCompilationPlugin.js +9 -5
  85. package/lib/ids/HashedModuleIdsPlugin.js +3 -3
  86. package/lib/ids/OccurrenceModuleIdsPlugin.js +2 -3
  87. package/lib/index.js +5 -3
  88. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -6
  89. package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -3
  90. package/lib/javascript/JavascriptGenerator.js +3 -1
  91. package/lib/javascript/JavascriptModulesPlugin.js +15 -23
  92. package/lib/javascript/JavascriptParser.js +10 -8
  93. package/lib/library/AssignLibraryPlugin.js +4 -2
  94. package/lib/node/NodeEnvironmentPlugin.js +1 -0
  95. package/lib/node/NodeWatchFileSystem.js +19 -4
  96. package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
  97. package/lib/optimize/ConcatenatedModule.js +31 -27
  98. package/lib/optimize/FlagIncludedChunksPlugin.js +4 -6
  99. package/lib/optimize/InnerGraph.js +9 -11
  100. package/lib/optimize/InnerGraphPlugin.js +3 -1
  101. package/lib/optimize/ModuleConcatenationPlugin.js +7 -10
  102. package/lib/optimize/RealContentHashPlugin.js +14 -16
  103. package/lib/optimize/SideEffectsFlagPlugin.js +6 -5
  104. package/lib/optimize/SplitChunksPlugin.js +13 -15
  105. package/lib/performance/AssetsOverSizeLimitWarning.js +0 -2
  106. package/lib/performance/EntrypointsOverSizeLimitWarning.js +0 -2
  107. package/lib/performance/NoAsyncChunksWarning.js +0 -2
  108. package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
  109. package/lib/runtime/LoadScriptRuntimeModule.js +2 -3
  110. package/lib/runtime/OnChunksLoadedRuntimeModule.js +38 -37
  111. package/lib/schemes/DataUriPlugin.js +21 -2
  112. package/lib/serialization/BinaryMiddleware.js +5 -3
  113. package/lib/serialization/FileMiddleware.js +3 -1
  114. package/lib/serialization/ObjectMiddleware.js +11 -7
  115. package/lib/stats/DefaultStatsFactoryPlugin.js +7 -7
  116. package/lib/stats/DefaultStatsPrinterPlugin.js +11 -9
  117. package/lib/stats/StatsFactory.js +2 -1
  118. package/lib/stats/StatsPrinter.js +3 -3
  119. package/lib/util/LazyBucketSortedSet.js +3 -3
  120. package/lib/util/cleverMerge.js +3 -1
  121. package/lib/util/comparators.js +13 -13
  122. package/lib/util/createHash.js +5 -4
  123. package/lib/util/identifier.js +2 -1
  124. package/lib/util/serialization.js +108 -59
  125. package/lib/validateSchema.js +5 -3
  126. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +4 -4
  127. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +0 -2
  128. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +5 -4
  129. package/lib/wasm-sync/WebAssemblyGenerator.js +89 -83
  130. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +0 -2
  131. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -1
  132. package/lib/wasm-sync/WebAssemblyParser.js +6 -5
  133. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -4
  134. package/lib/webpack.js +11 -7
  135. package/package.json +9 -6
  136. package/schemas/WebpackOptions.check.js +1 -1
  137. package/schemas/WebpackOptions.json +76 -60
  138. package/types.d.ts +112 -262
  139. package/lib/util/DataURI.js +0 -32
@@ -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();
@@ -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 ||
@@ -12,7 +12,5 @@ module.exports = class HarmonyLinkingError extends WebpackError {
12
12
  super(message);
13
13
  this.name = "HarmonyLinkingError";
14
14
  this.hideStack = true;
15
-
16
- Error.captureStackTrace(this, this.constructor);
17
15
  }
18
16
  };
@@ -32,7 +32,6 @@ class HookWebpackError extends WebpackError {
32
32
  this.hideStack = true;
33
33
  this.details = `caused by plugins in ${hook}\n${error.stack}`;
34
34
 
35
- Error.captureStackTrace(this, this.constructor);
36
35
  this.stack += `\n-- inner error --\n${error.stack}`;
37
36
  }
38
37
  }
@@ -31,7 +31,8 @@ const {
31
31
  keyToRuntime,
32
32
  forEachRuntime,
33
33
  mergeRuntimeOwned,
34
- subtractRuntime
34
+ subtractRuntime,
35
+ intersectRuntime
35
36
  } = require("./util/runtime");
36
37
 
37
38
  /** @typedef {import("./Chunk")} Chunk */
@@ -87,10 +88,8 @@ class HotModuleReplacementPlugin {
87
88
  const runtimeRequirements = [RuntimeGlobals.module];
88
89
 
89
90
  const createAcceptHandler = (parser, ParamDependency) => {
90
- const {
91
- hotAcceptCallback,
92
- hotAcceptWithoutCallback
93
- } = HotModuleReplacementPlugin.getParserHooks(parser);
91
+ const { hotAcceptCallback, hotAcceptWithoutCallback } =
92
+ HotModuleReplacementPlugin.getParserHooks(parser);
94
93
 
95
94
  return expr => {
96
95
  const module = parser.state.module;
@@ -306,9 +305,7 @@ class HotModuleReplacementPlugin {
306
305
  }
307
306
  records.chunkModuleIds = {};
308
307
  for (const chunk of compilation.chunks) {
309
- records.chunkModuleIds[
310
- chunk.id
311
- ] = Array.from(
308
+ records.chunkModuleIds[chunk.id] = Array.from(
312
309
  chunkGraph.getOrderedChunkModulesIterable(
313
310
  chunk,
314
311
  compareModulesById(chunkGraph)
@@ -341,9 +338,8 @@ class HotModuleReplacementPlugin {
341
338
  return chunkGraph.getModuleHash(module, chunk.runtime);
342
339
  }
343
340
  };
344
- const fullHashModulesInThisChunk = chunkGraph.getChunkFullHashModulesSet(
345
- chunk
346
- );
341
+ const fullHashModulesInThisChunk =
342
+ chunkGraph.getChunkFullHashModulesSet(chunk);
347
343
  if (fullHashModulesInThisChunk !== undefined) {
348
344
  for (const module of fullHashModulesInThisChunk) {
349
345
  fullHashModules.add(module, chunk);
@@ -451,16 +447,14 @@ class HotModuleReplacementPlugin {
451
447
  allOldRuntime = mergeRuntimeOwned(allOldRuntime, runtime);
452
448
  }
453
449
  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
- );
450
+ const { path: filename, info: assetInfo } =
451
+ compilation.getPathWithInfo(
452
+ compilation.outputOptions.hotUpdateMainFilename,
453
+ {
454
+ hash: records.hash,
455
+ runtime
456
+ }
457
+ );
464
458
  hotUpdateMainContentByRuntime.set(runtime, {
465
459
  updatedChunkIds: new Set(),
466
460
  removedChunkIds: new Set(),
@@ -509,16 +503,19 @@ class HotModuleReplacementPlugin {
509
503
  );
510
504
  if (currentChunk) {
511
505
  chunkId = currentChunk.id;
512
- newRuntime = currentChunk.runtime;
506
+ newRuntime = intersectRuntime(
507
+ currentChunk.runtime,
508
+ allOldRuntime
509
+ );
510
+ if (newRuntime === undefined) continue;
513
511
  newModules = chunkGraph
514
512
  .getChunkModules(currentChunk)
515
513
  .filter(module => updatedModules.has(module, currentChunk));
516
514
  newRuntimeModules = Array.from(
517
515
  chunkGraph.getChunkRuntimeModulesIterable(currentChunk)
518
516
  ).filter(module => updatedModules.has(module, currentChunk));
519
- const fullHashModules = chunkGraph.getChunkFullHashModulesIterable(
520
- currentChunk
521
- );
517
+ const fullHashModules =
518
+ chunkGraph.getChunkFullHashModulesIterable(currentChunk);
522
519
  newFullHashModules =
523
520
  fullHashModules &&
524
521
  Array.from(fullHashModules).filter(module =>
@@ -631,13 +628,11 @@ class HotModuleReplacementPlugin {
631
628
  filename = entry.filename;
632
629
  assetInfo = entry.info;
633
630
  } else {
634
- ({
635
- path: filename,
636
- info: assetInfo
637
- } = compilation.getPathWithInfo(
638
- entry.filenameTemplate,
639
- entry.pathOptions
640
- ));
631
+ ({ path: filename, info: assetInfo } =
632
+ compilation.getPathWithInfo(
633
+ entry.filenameTemplate,
634
+ entry.pathOptions
635
+ ));
641
636
  }
642
637
  const source = entry.render();
643
638
  compilation.additionalChunkAssets.push(filename);
@@ -33,8 +33,6 @@ ${depsList.slice(0, 3).join("\n")}${
33
33
  this.name = "InvalidDependenciesModuleWarning";
34
34
  this.details = depsList.slice(3).join("\n");
35
35
  this.module = module;
36
-
37
- Error.captureStackTrace(this, this.constructor);
38
36
  }
39
37
  }
40
38
 
@@ -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() {
@@ -53,8 +53,6 @@ class ModuleBuildError extends WebpackError {
53
53
  this.name = "ModuleBuildError";
54
54
  this.details = details;
55
55
  this.error = err;
56
-
57
- Error.captureStackTrace(this, this.constructor);
58
56
  }
59
57
 
60
58
  serialize(context) {
@@ -30,8 +30,6 @@ class ModuleDependencyError extends WebpackError {
30
30
  /** error is not (de)serialized, so it might be undefined after deserialization */
31
31
  this.error = err;
32
32
 
33
- Error.captureStackTrace(this, this.constructor);
34
-
35
33
  if (err && /** @type {any} */ (err).hideStack) {
36
34
  this.stack =
37
35
  err.stack.split("\n").slice(1).join("\n") + "\n\n" + this.stack;
@@ -30,8 +30,6 @@ class ModuleDependencyWarning extends WebpackError {
30
30
  /** error is not (de)serialized, so it might be undefined after deserialization */
31
31
  this.error = err;
32
32
 
33
- Error.captureStackTrace(this, this.constructor);
34
-
35
33
  if (err && /** @type {any} */ (err).hideStack) {
36
34
  this.stack =
37
35
  err.stack.split("\n").slice(1).join("\n") + "\n\n" + this.stack;
@@ -37,8 +37,6 @@ class ModuleError extends WebpackError {
37
37
  err && typeof err === "object" && err.stack
38
38
  ? cleanUp(err.stack, this.message)
39
39
  : undefined;
40
-
41
- Error.captureStackTrace(this, this.constructor);
42
40
  }
43
41
 
44
42
  serialize(context) {
@@ -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]";
@@ -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;
@@ -80,8 +80,6 @@ class ModuleNotFoundError extends WebpackError {
80
80
  this.module = module;
81
81
  this.error = err;
82
82
  this.loc = loc;
83
-
84
- Error.captureStackTrace(this, this.constructor);
85
83
  }
86
84
  }
87
85
 
@@ -85,8 +85,6 @@ class ModuleParseError extends WebpackError {
85
85
  this.name = "ModuleParseError";
86
86
  this.loc = loc;
87
87
  this.error = err;
88
-
89
- Error.captureStackTrace(this, this.constructor);
90
88
  }
91
89
 
92
90
  serialize(context) {
@@ -36,8 +36,6 @@ class ModuleRestoreError extends WebpackError {
36
36
  this.details = details;
37
37
  this.module = module;
38
38
  this.error = err;
39
-
40
- Error.captureStackTrace(this, this.constructor);
41
39
  }
42
40
  }
43
41
 
@@ -36,8 +36,6 @@ class ModuleStoreError extends WebpackError {
36
36
  this.details = details;
37
37
  this.module = module;
38
38
  this.error = err;
39
-
40
- Error.captureStackTrace(this, this.constructor);
41
39
  }
42
40
  }
43
41
 
@@ -37,8 +37,6 @@ class ModuleWarning extends WebpackError {
37
37
  warning && typeof warning === "object" && warning.stack
38
38
  ? cleanUp(warning.stack, this.message)
39
39
  : undefined;
40
-
41
- Error.captureStackTrace(this, this.constructor);
42
40
  }
43
41
 
44
42
  serialize(context) {
@@ -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
 
@@ -18,7 +18,5 @@ module.exports = class NoModeWarning extends WebpackError {
18
18
  "Set 'mode' option to 'development' or 'production' to enable defaults for each environment.\n" +
19
19
  "You can also set it to 'none' to disable any default behavior. " +
20
20
  "Learn more: https://webpack.js.org/configuration/mode/";
21
-
22
- Error.captureStackTrace(this, this.constructor);
23
21
  }
24
22
  };