webpack 5.59.0 → 5.71.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 (209) hide show
  1. package/README.md +1 -7
  2. package/hot/lazy-compilation-node.js +3 -1
  3. package/hot/poll.js +1 -1
  4. package/hot/signal.js +1 -1
  5. package/lib/APIPlugin.js +33 -0
  6. package/lib/BannerPlugin.js +10 -4
  7. package/lib/Cache.js +1 -1
  8. package/lib/CacheFacade.js +4 -11
  9. package/lib/Chunk.js +6 -3
  10. package/lib/ChunkGraph.js +1 -2
  11. package/lib/ChunkGroup.js +1 -1
  12. package/lib/CleanPlugin.js +81 -20
  13. package/lib/Compilation.js +179 -91
  14. package/lib/Compiler.js +86 -17
  15. package/lib/ConstPlugin.js +2 -2
  16. package/lib/ContextModule.js +142 -51
  17. package/lib/ContextModuleFactory.js +65 -25
  18. package/lib/DelegatedModule.js +1 -1
  19. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  20. package/lib/Dependency.js +17 -0
  21. package/lib/DependencyTemplate.js +9 -0
  22. package/lib/DependencyTemplates.js +1 -1
  23. package/lib/DllModule.js +1 -1
  24. package/lib/EntryOptionPlugin.js +2 -0
  25. package/lib/ErrorHelpers.js +2 -2
  26. package/lib/EvalDevToolModulePlugin.js +16 -1
  27. package/lib/EvalSourceMapDevToolPlugin.js +18 -1
  28. package/lib/ExportsInfo.js +4 -4
  29. package/lib/ExternalModule.js +94 -54
  30. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  31. package/lib/FileSystemInfo.js +89 -44
  32. package/lib/Generator.js +3 -0
  33. package/lib/HookWebpackError.js +1 -1
  34. package/lib/HotModuleReplacementPlugin.js +3 -1
  35. package/lib/LoaderOptionsPlugin.js +1 -1
  36. package/lib/Module.js +27 -4
  37. package/lib/ModuleFilenameHelpers.js +8 -4
  38. package/lib/ModuleHashingError.js +29 -0
  39. package/lib/MultiCompiler.js +1 -1
  40. package/lib/MultiWatching.js +1 -1
  41. package/lib/NodeStuffPlugin.js +10 -0
  42. package/lib/NormalModule.js +41 -26
  43. package/lib/NormalModuleFactory.js +42 -37
  44. package/lib/ProgressPlugin.js +4 -5
  45. package/lib/RawModule.js +1 -1
  46. package/lib/RuntimeGlobals.js +29 -1
  47. package/lib/RuntimeModule.js +1 -1
  48. package/lib/RuntimePlugin.js +77 -1
  49. package/lib/RuntimeTemplate.js +114 -2
  50. package/lib/Template.js +2 -1
  51. package/lib/TemplatedPathPlugin.js +48 -23
  52. package/lib/WatchIgnorePlugin.js +19 -7
  53. package/lib/Watching.js +33 -19
  54. package/lib/WebpackOptionsApply.js +57 -11
  55. package/lib/asset/AssetGenerator.js +193 -63
  56. package/lib/asset/AssetModulesPlugin.js +3 -0
  57. package/lib/asset/RawDataUrlModule.js +148 -0
  58. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  59. package/lib/buildChunkGraph.js +36 -6
  60. package/lib/cache/PackFileCacheStrategy.js +7 -4
  61. package/lib/cache/ResolverCachePlugin.js +90 -29
  62. package/lib/cli.js +44 -3
  63. package/lib/config/browserslistTargetHandler.js +41 -6
  64. package/lib/config/defaults.js +115 -19
  65. package/lib/config/normalization.js +9 -0
  66. package/lib/config/target.js +10 -0
  67. package/lib/container/ContainerEntryModule.js +8 -5
  68. package/lib/container/FallbackModule.js +4 -4
  69. package/lib/container/RemoteModule.js +4 -2
  70. package/lib/css/CssExportsGenerator.js +139 -0
  71. package/lib/css/CssGenerator.js +109 -0
  72. package/lib/css/CssLoadingRuntimeModule.js +440 -0
  73. package/lib/css/CssModulesPlugin.js +462 -0
  74. package/lib/css/CssParser.js +618 -0
  75. package/lib/css/walkCssTokens.js +659 -0
  76. package/lib/debug/ProfilingPlugin.js +24 -21
  77. package/lib/dependencies/AMDRequireDependency.js +6 -6
  78. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  79. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  80. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -3
  81. package/lib/dependencies/CommonJsRequireContextDependency.js +5 -1
  82. package/lib/dependencies/ContextDependency.js +1 -0
  83. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  84. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  85. package/lib/dependencies/ContextElementDependency.js +41 -3
  86. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  87. package/lib/dependencies/CssExportDependency.js +85 -0
  88. package/lib/dependencies/CssImportDependency.js +75 -0
  89. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  90. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  91. package/lib/dependencies/CssUrlDependency.js +132 -0
  92. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  93. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  94. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  95. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +95 -0
  96. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  97. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  98. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  99. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  100. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  101. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  102. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  103. package/lib/dependencies/ImportContextDependency.js +0 -2
  104. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  105. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  106. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  107. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  108. package/lib/dependencies/LoaderPlugin.js +4 -2
  109. package/lib/dependencies/RequireContextDependency.js +0 -16
  110. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  111. package/lib/dependencies/URLDependency.js +3 -8
  112. package/lib/dependencies/URLPlugin.js +1 -1
  113. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  114. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  115. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  116. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  117. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  118. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  119. package/lib/hmr/lazyCompilationBackend.js +51 -12
  120. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  121. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  122. package/lib/ids/IdHelpers.js +25 -11
  123. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  124. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  125. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  126. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  127. package/lib/index.js +13 -0
  128. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  129. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  130. package/lib/javascript/ChunkHelpers.js +33 -0
  131. package/lib/javascript/JavascriptGenerator.js +1 -0
  132. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  133. package/lib/javascript/JavascriptParser.js +82 -48
  134. package/lib/javascript/StartupHelpers.js +7 -30
  135. package/lib/library/AssignLibraryPlugin.js +39 -15
  136. package/lib/library/EnableLibraryPlugin.js +11 -0
  137. package/lib/library/UmdLibraryPlugin.js +5 -3
  138. package/lib/node/NodeTargetPlugin.js +3 -0
  139. package/lib/node/NodeWatchFileSystem.js +85 -31
  140. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  141. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  142. package/lib/optimize/ConcatenatedModule.js +21 -9
  143. package/lib/optimize/ModuleConcatenationPlugin.js +5 -2
  144. package/lib/optimize/SplitChunksPlugin.js +8 -1
  145. package/lib/runtime/AsyncModuleRuntimeModule.js +27 -17
  146. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  147. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  148. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  149. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  150. package/lib/schemes/HttpUriPlugin.js +77 -14
  151. package/lib/serialization/FileMiddleware.js +44 -9
  152. package/lib/sharing/ConsumeSharedModule.js +8 -2
  153. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  154. package/lib/sharing/ProvideSharedModule.js +4 -2
  155. package/lib/sharing/ShareRuntimeModule.js +1 -1
  156. package/lib/sharing/utils.js +1 -1
  157. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  158. package/lib/stats/DefaultStatsPrinterPlugin.js +89 -24
  159. package/lib/util/ArrayHelpers.js +30 -0
  160. package/lib/util/AsyncQueue.js +1 -1
  161. package/lib/util/compileBooleanMatcher.js +1 -1
  162. package/lib/util/create-schema-validation.js +9 -2
  163. package/lib/util/createHash.js +12 -0
  164. package/lib/util/deprecation.js +10 -2
  165. package/lib/util/deterministicGrouping.js +1 -1
  166. package/lib/util/extractUrlAndGlobal.js +3 -0
  167. package/lib/util/fs.js +11 -0
  168. package/lib/util/hash/BatchedHash.js +7 -4
  169. package/lib/util/hash/md4.js +20 -0
  170. package/lib/util/hash/wasm-hash.js +163 -0
  171. package/lib/util/hash/xxhash64.js +5 -139
  172. package/lib/util/identifier.js +65 -44
  173. package/lib/util/internalSerializables.js +15 -0
  174. package/lib/util/nonNumericOnlyHash.js +22 -0
  175. package/lib/util/semver.js +17 -10
  176. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  177. package/lib/web/JsonpChunkLoadingRuntimeModule.js +20 -9
  178. package/lib/webpack.js +10 -3
  179. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  180. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  181. package/module.d.ts +215 -0
  182. package/package.json +23 -28
  183. package/schemas/WebpackOptions.check.js +1 -1
  184. package/schemas/WebpackOptions.json +254 -29
  185. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  186. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  187. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  188. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  189. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  190. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  191. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  192. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  193. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  194. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  195. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  196. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  197. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  198. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  199. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  200. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  201. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  202. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  203. package/schemas/plugins/css/CssParserOptions.json +3 -0
  204. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  205. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  206. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  207. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  208. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  209. package/types.d.ts +628 -179
@@ -43,6 +43,7 @@ const Module = require("./Module");
43
43
  const ModuleDependencyError = require("./ModuleDependencyError");
44
44
  const ModuleDependencyWarning = require("./ModuleDependencyWarning");
45
45
  const ModuleGraph = require("./ModuleGraph");
46
+ const ModuleHashingError = require("./ModuleHashingError");
46
47
  const ModuleNotFoundError = require("./ModuleNotFoundError");
47
48
  const ModuleProfile = require("./ModuleProfile");
48
49
  const ModuleRestoreError = require("./ModuleRestoreError");
@@ -116,34 +117,34 @@ const { isSourceEqual } = require("./util/source");
116
117
 
117
118
  /**
118
119
  * @callback Callback
119
- * @param {WebpackError=} err
120
+ * @param {(WebpackError | null)=} err
120
121
  * @returns {void}
121
122
  */
122
123
 
123
124
  /**
124
125
  * @callback ModuleCallback
125
- * @param {WebpackError=} err
126
+ * @param {(WebpackError | null)=} err
126
127
  * @param {Module=} result
127
128
  * @returns {void}
128
129
  */
129
130
 
130
131
  /**
131
132
  * @callback ModuleFactoryResultCallback
132
- * @param {WebpackError=} err
133
+ * @param {(WebpackError | null)=} err
133
134
  * @param {ModuleFactoryResult=} result
134
135
  * @returns {void}
135
136
  */
136
137
 
137
138
  /**
138
139
  * @callback ModuleOrFactoryResultCallback
139
- * @param {WebpackError=} err
140
+ * @param {(WebpackError | null)=} err
140
141
  * @param {Module | ModuleFactoryResult=} result
141
142
  * @returns {void}
142
143
  */
143
144
 
144
145
  /**
145
146
  * @callback ExecuteModuleCallback
146
- * @param {WebpackError=} err
147
+ * @param {(WebpackError | null)=} err
147
148
  * @param {ExecuteModuleResult=} result
148
149
  * @returns {void}
149
150
  */
@@ -182,6 +183,7 @@ const { isSourceEqual } = require("./util/source");
182
183
 
183
184
  /**
184
185
  * @typedef {Object} ChunkHashContext
186
+ * @property {CodeGenerationResults} codeGenerationResults results of code generation
185
187
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
186
188
  * @property {ModuleGraph} moduleGraph the module graph
187
189
  * @property {ChunkGraph} chunkGraph the chunk graph
@@ -429,6 +431,8 @@ class Compilation {
429
431
  * @param {CompilationParams} params the compilation parameters
430
432
  */
431
433
  constructor(compiler, params) {
434
+ this._backCompat = compiler._backCompat;
435
+
432
436
  const getNormalModuleLoader = () => deprecatedNormalModuleLoaderHook(this);
433
437
  /** @typedef {{ additionalAssets?: true | Function }} ProcessAssetsAdditionalOptions */
434
438
  /** @type {AsyncSeriesHook<[CompilationAssets], ProcessAssetsAdditionalOptions>} */
@@ -559,6 +563,7 @@ class Compilation {
559
563
  * @returns {FakeHook<Pick<AsyncSeriesHook<T>, "tap" | "tapAsync" | "tapPromise" | "name">>} fake hook which redirects
560
564
  */
561
565
  const createProcessAssetsHook = (name, stage, getArgs, code) => {
566
+ if (!this._backCompat && code) return undefined;
562
567
  const errorMessage =
563
568
  reason => `Can't automatically convert plugin using Compilation.hooks.${name} to Compilation.hooks.processAssets because ${reason}.
564
569
  BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a single Compilation.hooks.processAssets hook.`;
@@ -983,7 +988,6 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
983
988
  this.asyncEntrypoints = [];
984
989
  /** @type {Set<Chunk>} */
985
990
  this.chunks = new Set();
986
- arrayToSetDeprecation(this.chunks, "Compilation.chunks");
987
991
  /** @type {ChunkGroup[]} */
988
992
  this.chunkGroups = [];
989
993
  /** @type {Map<string, ChunkGroup>} */
@@ -992,7 +996,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
992
996
  this.namedChunks = new Map();
993
997
  /** @type {Set<Module>} */
994
998
  this.modules = new Set();
995
- arrayToSetDeprecation(this.modules, "Compilation.modules");
999
+ if (this._backCompat) {
1000
+ arrayToSetDeprecation(this.chunks, "Compilation.chunks");
1001
+ arrayToSetDeprecation(this.modules, "Compilation.modules");
1002
+ }
996
1003
  /** @private @type {Map<string, Module>} */
997
1004
  this._modules = new Map();
998
1005
  this.records = null;
@@ -1015,7 +1022,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1015
1022
  /** @type {Map<DepConstructor, ModuleFactory>} */
1016
1023
  this.dependencyFactories = new Map();
1017
1024
  /** @type {DependencyTemplates} */
1018
- this.dependencyTemplates = new DependencyTemplates();
1025
+ this.dependencyTemplates = new DependencyTemplates(
1026
+ this.outputOptions.hashFunction
1027
+ );
1019
1028
  this.childrenCounters = {};
1020
1029
  /** @type {Set<number|string>} */
1021
1030
  this.usedChunkIds = null;
@@ -1286,7 +1295,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1286
1295
  }
1287
1296
  this._modules.set(identifier, module);
1288
1297
  this.modules.add(module);
1289
- ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1298
+ if (this._backCompat)
1299
+ ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1290
1300
  if (currentProfile !== undefined) {
1291
1301
  currentProfile.markIntegrationEnd();
1292
1302
  }
@@ -1426,7 +1436,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1426
1436
  * @returns {void}
1427
1437
  */
1428
1438
  _processModuleDependencies(module, callback) {
1429
- /** @type {Array<{factory: ModuleFactory, dependencies: Dependency[], originModule: Module|null}>} */
1439
+ /** @type {Array<{factory: ModuleFactory, dependencies: Dependency[], context: string|undefined, originModule: Module|null}>} */
1430
1440
  const sortedDependencies = [];
1431
1441
 
1432
1442
  /** @type {DependenciesBlock} */
@@ -1658,6 +1668,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1658
1668
  sortedDependencies.push({
1659
1669
  factory: factoryCacheKey2,
1660
1670
  dependencies: list,
1671
+ context: dep.getContext(),
1661
1672
  originModule: module
1662
1673
  });
1663
1674
  }
@@ -1701,7 +1712,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1701
1712
 
1702
1713
  this._modules.set(module.identifier(), module);
1703
1714
  this.modules.add(module);
1704
- ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1715
+ if (this._backCompat)
1716
+ ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
1705
1717
 
1706
1718
  this._handleModuleBuildAndDependencies(
1707
1719
  originModule,
@@ -2417,9 +2429,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2417
2429
  let statNew = 0;
2418
2430
  /**
2419
2431
  * @param {Module} module module
2420
- * @returns {{ modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
2432
+ * @returns {{ id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[] }} references
2421
2433
  */
2422
2434
  const computeReferences = module => {
2435
+ const id = chunkGraph.getModuleId(module);
2423
2436
  /** @type {Map<Module, string | number | undefined>} */
2424
2437
  let modules = undefined;
2425
2438
  /** @type {(string | number)[] | undefined} */
@@ -2447,16 +2460,18 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2447
2460
  queue.push.apply(queue, block.blocks);
2448
2461
  }
2449
2462
  }
2450
- return { modules, blocks };
2463
+ return { id, modules, blocks };
2451
2464
  };
2452
2465
  /**
2453
2466
  * @param {Module} module module
2454
2467
  * @param {Object} references references
2468
+ * @param {string | number} references.id id
2455
2469
  * @param {Map<Module, string | number>=} references.modules modules
2456
2470
  * @param {(string | number)[]=} references.blocks blocks
2457
2471
  * @returns {boolean} ok?
2458
2472
  */
2459
- const compareReferences = (module, { modules, blocks }) => {
2473
+ const compareReferences = (module, { id, modules, blocks }) => {
2474
+ if (id !== chunkGraph.getModuleId(module)) return false;
2460
2475
  if (modules !== undefined) {
2461
2476
  for (const [module, id] of modules) {
2462
2477
  if (chunkGraph.getModuleId(module) !== id) return false;
@@ -2482,7 +2497,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2482
2497
  };
2483
2498
 
2484
2499
  for (const [module, memCache] of moduleMemCaches) {
2485
- /** @type {{ references: { modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[]}, memCache: WeakTupleMap<any[], any> }} */
2500
+ /** @type {{ references: { id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number)[]}, memCache: WeakTupleMap<any[], any> }} */
2486
2501
  const cache = memCache.get(key);
2487
2502
  if (cache === undefined) {
2488
2503
  const memCache2 = new WeakTupleMap();
@@ -2777,8 +2792,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2777
2792
  );
2778
2793
  this.chunkGraph = chunkGraph;
2779
2794
 
2780
- for (const module of this.modules) {
2781
- ChunkGraph.setChunkGraphForModule(module, chunkGraph);
2795
+ if (this._backCompat) {
2796
+ for (const module of this.modules) {
2797
+ ChunkGraph.setChunkGraphForModule(module, chunkGraph);
2798
+ }
2782
2799
  }
2783
2800
 
2784
2801
  this.hooks.seal.call();
@@ -3045,14 +3062,16 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3045
3062
  }
3046
3063
  this.hooks.afterProcessAssets.call(this.assets);
3047
3064
  this.logger.timeEnd("process assets");
3048
- this.assets = soonFrozenObjectDeprecation(
3049
- this.assets,
3050
- "Compilation.assets",
3051
- "DEP_WEBPACK_COMPILATION_ASSETS",
3052
- `BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
3065
+ this.assets = this._backCompat
3066
+ ? soonFrozenObjectDeprecation(
3067
+ this.assets,
3068
+ "Compilation.assets",
3069
+ "DEP_WEBPACK_COMPILATION_ASSETS",
3070
+ `BREAKING CHANGE: No more changes should happen to Compilation.assets after sealing the Compilation.
3053
3071
  Do changes to assets earlier, e. g. in Compilation.hooks.processAssets.
3054
3072
  Make sure to select an appropriate stage from Compilation.PROCESS_ASSETS_STAGE_*.`
3055
- );
3073
+ )
3074
+ : Object.freeze(this.assets);
3056
3075
 
3057
3076
  this.summarizeDependencies();
3058
3077
  if (shouldRecord) {
@@ -3179,47 +3198,87 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3179
3198
  this;
3180
3199
  const results = this.codeGenerationResults;
3181
3200
  const errors = [];
3182
- asyncLib.eachLimit(
3183
- jobs,
3184
- this.options.parallelism,
3185
- ({ module, hash, runtime, runtimes }, callback) => {
3186
- this._codeGenerationModule(
3187
- module,
3188
- runtime,
3189
- runtimes,
3190
- hash,
3191
- dependencyTemplates,
3192
- chunkGraph,
3193
- moduleGraph,
3194
- runtimeTemplate,
3195
- errors,
3196
- results,
3197
- (err, codeGenerated) => {
3198
- if (codeGenerated) statModulesGenerated++;
3199
- else statModulesFromCache++;
3200
- callback(err);
3201
+ /** @type {Set<Module> | undefined} */
3202
+ let notCodeGeneratedModules = undefined;
3203
+ const runIteration = () => {
3204
+ let delayedJobs = [];
3205
+ let delayedModules = new Set();
3206
+ asyncLib.eachLimit(
3207
+ jobs,
3208
+ this.options.parallelism,
3209
+ (job, callback) => {
3210
+ const { module } = job;
3211
+ const { codeGenerationDependencies } = module;
3212
+ if (codeGenerationDependencies !== undefined) {
3213
+ if (
3214
+ notCodeGeneratedModules === undefined ||
3215
+ codeGenerationDependencies.some(dep => {
3216
+ const referencedModule = moduleGraph.getModule(dep);
3217
+ return notCodeGeneratedModules.has(referencedModule);
3218
+ })
3219
+ ) {
3220
+ delayedJobs.push(job);
3221
+ delayedModules.add(module);
3222
+ return callback();
3223
+ }
3201
3224
  }
3202
- );
3203
- },
3204
- err => {
3205
- if (err) return callback(err);
3206
- if (errors.length > 0) {
3207
- errors.sort(
3208
- compareSelect(err => err.module, compareModulesByIdentifier)
3225
+ const { hash, runtime, runtimes } = job;
3226
+ this._codeGenerationModule(
3227
+ module,
3228
+ runtime,
3229
+ runtimes,
3230
+ hash,
3231
+ dependencyTemplates,
3232
+ chunkGraph,
3233
+ moduleGraph,
3234
+ runtimeTemplate,
3235
+ errors,
3236
+ results,
3237
+ (err, codeGenerated) => {
3238
+ if (codeGenerated) statModulesGenerated++;
3239
+ else statModulesFromCache++;
3240
+ callback(err);
3241
+ }
3209
3242
  );
3210
- for (const error of errors) {
3211
- this.errors.push(error);
3243
+ },
3244
+ err => {
3245
+ if (err) return callback(err);
3246
+ if (delayedJobs.length > 0) {
3247
+ if (delayedJobs.length === jobs.length) {
3248
+ return callback(
3249
+ new Error(
3250
+ `Unable to make progress during code generation because of circular code generation dependency: ${Array.from(
3251
+ delayedModules,
3252
+ m => m.identifier()
3253
+ ).join(", ")}`
3254
+ )
3255
+ );
3256
+ }
3257
+ jobs = delayedJobs;
3258
+ delayedJobs = [];
3259
+ notCodeGeneratedModules = delayedModules;
3260
+ delayedModules = new Set();
3261
+ return runIteration();
3262
+ }
3263
+ if (errors.length > 0) {
3264
+ errors.sort(
3265
+ compareSelect(err => err.module, compareModulesByIdentifier)
3266
+ );
3267
+ for (const error of errors) {
3268
+ this.errors.push(error);
3269
+ }
3212
3270
  }
3271
+ this.logger.log(
3272
+ `${Math.round(
3273
+ (100 * statModulesGenerated) /
3274
+ (statModulesGenerated + statModulesFromCache)
3275
+ )}% code generated (${statModulesGenerated} generated, ${statModulesFromCache} from cache)`
3276
+ );
3277
+ callback();
3213
3278
  }
3214
- this.logger.log(
3215
- `${Math.round(
3216
- (100 * statModulesGenerated) /
3217
- (statModulesGenerated + statModulesFromCache)
3218
- )}% code generated (${statModulesGenerated} generated, ${statModulesFromCache} from cache)`
3219
- );
3220
- callback();
3221
- }
3222
- );
3279
+ );
3280
+ };
3281
+ runIteration();
3223
3282
  }
3224
3283
 
3225
3284
  /**
@@ -3269,7 +3328,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3269
3328
  moduleGraph,
3270
3329
  dependencyTemplates,
3271
3330
  runtimeTemplate,
3272
- runtime
3331
+ runtime,
3332
+ codeGenerationResults: results,
3333
+ compilation: this
3273
3334
  });
3274
3335
  } catch (err) {
3275
3336
  errors.push(new CodeGenerationError(module, err));
@@ -3453,7 +3514,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3453
3514
  */
3454
3515
  addRuntimeModule(chunk, module, chunkGraph = this.chunkGraph) {
3455
3516
  // Deprecated ModuleGraph association
3456
- ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
3517
+ if (this._backCompat)
3518
+ ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
3457
3519
 
3458
3520
  // add it to the list
3459
3521
  this.modules.add(module);
@@ -3497,10 +3559,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3497
3559
  }
3498
3560
 
3499
3561
  /**
3562
+ * If `module` is passed, `loc` and `request` must also be passed.
3500
3563
  * @param {string | ChunkGroupOptions} groupOptions options for the chunk group
3501
- * @param {Module} module the module the references the chunk group
3502
- * @param {DependencyLocation} loc the location from with the chunk group is referenced (inside of module)
3503
- * @param {string} request the request from which the the chunk group is referenced
3564
+ * @param {Module=} module the module the references the chunk group
3565
+ * @param {DependencyLocation=} loc the location from with the chunk group is referenced (inside of module)
3566
+ * @param {string=} request the request from which the the chunk group is referenced
3504
3567
  * @returns {ChunkGroup} the new or existing chunk group
3505
3568
  */
3506
3569
  addChunkInGroup(groupOptions, module, loc, request) {
@@ -3589,9 +3652,10 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3589
3652
  return chunk;
3590
3653
  }
3591
3654
  }
3592
- const chunk = new Chunk(name);
3655
+ const chunk = new Chunk(name, this._backCompat);
3593
3656
  this.chunks.add(chunk);
3594
- ChunkGraph.setChunkGraphForChunk(chunk, this.chunkGraph);
3657
+ if (this._backCompat)
3658
+ ChunkGraph.setChunkGraphForChunk(chunk, this.chunkGraph);
3595
3659
  if (name) {
3596
3660
  this.namedChunks.set(name, chunk);
3597
3661
  }
@@ -3822,6 +3886,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3822
3886
  let statModulesFromCache = 0;
3823
3887
  const { chunkGraph, runtimeTemplate, moduleMemCaches2 } = this;
3824
3888
  const { hashFunction, hashDigest, hashDigestLength } = this.outputOptions;
3889
+ const errors = [];
3825
3890
  for (const module of this.modules) {
3826
3891
  const memCache = moduleMemCaches2 && moduleMemCaches2.get(module);
3827
3892
  for (const runtime of chunkGraph.getModuleRuntimes(module)) {
@@ -3832,7 +3897,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3832
3897
  module,
3833
3898
  runtime,
3834
3899
  digest,
3835
- digest.substr(0, hashDigestLength)
3900
+ digest.slice(0, hashDigestLength)
3836
3901
  );
3837
3902
  statModulesFromCache++;
3838
3903
  continue;
@@ -3846,13 +3911,20 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3846
3911
  hashFunction,
3847
3912
  runtimeTemplate,
3848
3913
  hashDigest,
3849
- hashDigestLength
3914
+ hashDigestLength,
3915
+ errors
3850
3916
  );
3851
3917
  if (memCache) {
3852
3918
  memCache.set(`moduleHash-${getRuntimeKey(runtime)}`, digest);
3853
3919
  }
3854
3920
  }
3855
3921
  }
3922
+ if (errors.length > 0) {
3923
+ errors.sort(compareSelect(err => err.module, compareModulesByIdentifier));
3924
+ for (const error of errors) {
3925
+ this.errors.push(error);
3926
+ }
3927
+ }
3856
3928
  this.logger.log(
3857
3929
  `${statModulesHashed} modules hashed, ${statModulesFromCache} from cache (${
3858
3930
  Math.round(
@@ -3869,22 +3941,27 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3869
3941
  hashFunction,
3870
3942
  runtimeTemplate,
3871
3943
  hashDigest,
3872
- hashDigestLength
3944
+ hashDigestLength,
3945
+ errors
3873
3946
  ) {
3874
- const moduleHash = createHash(hashFunction);
3875
- module.updateHash(moduleHash, {
3876
- chunkGraph,
3877
- runtime,
3878
- runtimeTemplate
3879
- });
3880
- const moduleHashDigest = /** @type {string} */ (
3881
- moduleHash.digest(hashDigest)
3882
- );
3947
+ let moduleHashDigest;
3948
+ try {
3949
+ const moduleHash = createHash(hashFunction);
3950
+ module.updateHash(moduleHash, {
3951
+ chunkGraph,
3952
+ runtime,
3953
+ runtimeTemplate
3954
+ });
3955
+ moduleHashDigest = /** @type {string} */ (moduleHash.digest(hashDigest));
3956
+ } catch (err) {
3957
+ errors.push(new ModuleHashingError(module, err));
3958
+ moduleHashDigest = "XXXXXX";
3959
+ }
3883
3960
  chunkGraph.setModuleHashes(
3884
3961
  module,
3885
3962
  runtime,
3886
3963
  moduleHashDigest,
3887
- moduleHashDigest.substr(0, hashDigestLength)
3964
+ moduleHashDigest.slice(0, hashDigestLength)
3888
3965
  );
3889
3966
  return moduleHashDigest;
3890
3967
  }
@@ -4030,6 +4107,7 @@ This prevents using hashes of each other and should be avoided.`);
4030
4107
  const codeGenerationJobs = [];
4031
4108
  /** @type {Map<string, Map<Module, {module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}>>} */
4032
4109
  const codeGenerationJobsMap = new Map();
4110
+ const errors = [];
4033
4111
 
4034
4112
  const processChunk = chunk => {
4035
4113
  // Last minute module hash generation for modules that depend on chunk hashes
@@ -4044,7 +4122,8 @@ This prevents using hashes of each other and should be avoided.`);
4044
4122
  hashFunction,
4045
4123
  runtimeTemplate,
4046
4124
  hashDigest,
4047
- hashDigestLength
4125
+ hashDigestLength,
4126
+ errors
4048
4127
  );
4049
4128
  let hashMap = codeGenerationJobsMap.get(hash);
4050
4129
  if (hashMap) {
@@ -4068,15 +4147,16 @@ This prevents using hashes of each other and should be avoided.`);
4068
4147
  }
4069
4148
  }
4070
4149
  this.logger.timeAggregate("hashing: hash runtime modules");
4071
- this.logger.time("hashing: hash chunks");
4072
- const chunkHash = createHash(hashFunction);
4073
4150
  try {
4151
+ this.logger.time("hashing: hash chunks");
4152
+ const chunkHash = createHash(hashFunction);
4074
4153
  if (outputOptions.hashSalt) {
4075
4154
  chunkHash.update(outputOptions.hashSalt);
4076
4155
  }
4077
4156
  chunk.updateHash(chunkHash, chunkGraph);
4078
4157
  this.hooks.chunkHash.call(chunk, chunkHash, {
4079
4158
  chunkGraph,
4159
+ codeGenerationResults: this.codeGenerationResults,
4080
4160
  moduleGraph: this.moduleGraph,
4081
4161
  runtimeTemplate: this.runtimeTemplate
4082
4162
  });
@@ -4085,7 +4165,7 @@ This prevents using hashes of each other and should be avoided.`);
4085
4165
  );
4086
4166
  hash.update(chunkHashDigest);
4087
4167
  chunk.hash = chunkHashDigest;
4088
- chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
4168
+ chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
4089
4169
  const fullHashModules =
4090
4170
  chunkGraph.getChunkFullHashModulesIterable(chunk);
4091
4171
  if (fullHashModules) {
@@ -4100,13 +4180,19 @@ This prevents using hashes of each other and should be avoided.`);
4100
4180
  };
4101
4181
  otherChunks.forEach(processChunk);
4102
4182
  for (const chunk of runtimeChunks) processChunk(chunk);
4183
+ if (errors.length > 0) {
4184
+ errors.sort(compareSelect(err => err.module, compareModulesByIdentifier));
4185
+ for (const error of errors) {
4186
+ this.errors.push(error);
4187
+ }
4188
+ }
4103
4189
 
4104
4190
  this.logger.timeAggregateEnd("hashing: hash runtime modules");
4105
4191
  this.logger.timeAggregateEnd("hashing: hash chunks");
4106
4192
  this.logger.time("hashing: hash digest");
4107
4193
  this.hooks.fullHash.call(hash);
4108
4194
  this.fullHash = /** @type {string} */ (hash.digest(hashDigest));
4109
- this.hash = this.fullHash.substr(0, hashDigestLength);
4195
+ this.hash = this.fullHash.slice(0, hashDigestLength);
4110
4196
  this.logger.timeEnd("hashing: hash digest");
4111
4197
 
4112
4198
  this.logger.time("hashing: process full hash modules");
@@ -4126,7 +4212,7 @@ This prevents using hashes of each other and should be avoided.`);
4126
4212
  module,
4127
4213
  chunk.runtime,
4128
4214
  moduleHashDigest,
4129
- moduleHashDigest.substr(0, hashDigestLength)
4215
+ moduleHashDigest.slice(0, hashDigestLength)
4130
4216
  );
4131
4217
  codeGenerationJobsMap.get(oldHash).get(module).hash = moduleHashDigest;
4132
4218
  }
@@ -4137,7 +4223,7 @@ This prevents using hashes of each other and should be avoided.`);
4137
4223
  chunkHash.digest(hashDigest)
4138
4224
  );
4139
4225
  chunk.hash = chunkHashDigest;
4140
- chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
4226
+ chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
4141
4227
  this.hooks.contentHash.call(chunk);
4142
4228
  }
4143
4229
  this.logger.timeEnd("hashing: process full hash modules");
@@ -4715,7 +4801,7 @@ This prevents using hashes of each other and should be avoided.`);
4715
4801
  this.outputOptions;
4716
4802
  const runtimeTemplate = this.runtimeTemplate;
4717
4803
 
4718
- const chunk = new Chunk("build time chunk");
4804
+ const chunk = new Chunk("build time chunk", this._backCompat);
4719
4805
  chunk.id = chunk.name;
4720
4806
  chunk.ids = [chunk.id];
4721
4807
  chunk.runtime = runtime;
@@ -4739,6 +4825,9 @@ This prevents using hashes of each other and should be avoided.`);
4739
4825
  chunkGraph.connectChunkAndModule(chunk, module);
4740
4826
  }
4741
4827
 
4828
+ /** @type {WebpackError[]} */
4829
+ const errors = [];
4830
+
4742
4831
  // Hash modules
4743
4832
  for (const module of modules) {
4744
4833
  this._createModuleHash(
@@ -4748,15 +4837,14 @@ This prevents using hashes of each other and should be avoided.`);
4748
4837
  hashFunction,
4749
4838
  runtimeTemplate,
4750
4839
  hashDigest,
4751
- hashDigestLength
4840
+ hashDigestLength,
4841
+ errors
4752
4842
  );
4753
4843
  }
4754
4844
 
4755
4845
  const codeGenerationResults = new CodeGenerationResults(
4756
4846
  this.outputOptions.hashFunction
4757
4847
  );
4758
- /** @type {WebpackError[]} */
4759
- const errors = [];
4760
4848
  /**
4761
4849
  * @param {Module} module the module
4762
4850
  * @param {Callback} callback callback