webpack 5.59.0 → 5.76.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 (236) hide show
  1. package/README.md +22 -24
  2. package/bin/webpack.js +0 -0
  3. package/hot/dev-server.js +17 -4
  4. package/hot/lazy-compilation-node.js +3 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +33 -0
  8. package/lib/BannerPlugin.js +13 -5
  9. package/lib/Cache.js +1 -1
  10. package/lib/CacheFacade.js +4 -11
  11. package/lib/Chunk.js +6 -3
  12. package/lib/ChunkGraph.js +94 -8
  13. package/lib/ChunkGroup.js +1 -1
  14. package/lib/CleanPlugin.js +81 -20
  15. package/lib/Compilation.js +188 -93
  16. package/lib/Compiler.js +87 -18
  17. package/lib/ConstPlugin.js +2 -2
  18. package/lib/ContextModule.js +142 -51
  19. package/lib/ContextModuleFactory.js +65 -25
  20. package/lib/DelegatedModule.js +1 -1
  21. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  22. package/lib/Dependency.js +17 -0
  23. package/lib/DependencyTemplate.js +9 -0
  24. package/lib/DependencyTemplates.js +1 -1
  25. package/lib/DllModule.js +1 -1
  26. package/lib/DllReferencePlugin.js +1 -1
  27. package/lib/EntryOptionPlugin.js +2 -0
  28. package/lib/ErrorHelpers.js +2 -2
  29. package/lib/EvalDevToolModulePlugin.js +16 -1
  30. package/lib/EvalSourceMapDevToolPlugin.js +25 -4
  31. package/lib/ExportsInfo.js +5 -5
  32. package/lib/ExternalModule.js +94 -54
  33. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  34. package/lib/FileSystemInfo.js +124 -58
  35. package/lib/Generator.js +3 -0
  36. package/lib/HookWebpackError.js +1 -1
  37. package/lib/HotModuleReplacementPlugin.js +3 -1
  38. package/lib/LoaderOptionsPlugin.js +1 -1
  39. package/lib/Module.js +28 -4
  40. package/lib/ModuleFilenameHelpers.js +8 -4
  41. package/lib/ModuleHashingError.js +29 -0
  42. package/lib/MultiCompiler.js +1 -1
  43. package/lib/MultiWatching.js +1 -1
  44. package/lib/NodeStuffPlugin.js +13 -3
  45. package/lib/NormalModule.js +51 -33
  46. package/lib/NormalModuleFactory.js +42 -37
  47. package/lib/ProgressPlugin.js +4 -5
  48. package/lib/RawModule.js +1 -1
  49. package/lib/RuntimeGlobals.js +29 -1
  50. package/lib/RuntimeModule.js +1 -1
  51. package/lib/RuntimePlugin.js +84 -1
  52. package/lib/RuntimeTemplate.js +114 -2
  53. package/lib/Template.js +3 -2
  54. package/lib/TemplatedPathPlugin.js +48 -23
  55. package/lib/WatchIgnorePlugin.js +19 -7
  56. package/lib/Watching.js +33 -19
  57. package/lib/WebpackOptionsApply.js +79 -11
  58. package/lib/asset/AssetGenerator.js +228 -71
  59. package/lib/asset/AssetModulesPlugin.js +3 -0
  60. package/lib/asset/AssetParser.js +1 -0
  61. package/lib/asset/AssetSourceGenerator.js +31 -6
  62. package/lib/asset/AssetSourceParser.js +1 -0
  63. package/lib/asset/RawDataUrlModule.js +148 -0
  64. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  65. package/lib/buildChunkGraph.js +38 -7
  66. package/lib/cache/PackFileCacheStrategy.js +15 -8
  67. package/lib/cache/ResolverCachePlugin.js +90 -29
  68. package/lib/cli.js +44 -3
  69. package/lib/config/browserslistTargetHandler.js +41 -6
  70. package/lib/config/defaults.js +123 -19
  71. package/lib/config/normalization.js +10 -2
  72. package/lib/config/target.js +10 -0
  73. package/lib/container/ContainerEntryModule.js +8 -5
  74. package/lib/container/FallbackModule.js +4 -4
  75. package/lib/container/ModuleFederationPlugin.js +2 -0
  76. package/lib/container/RemoteModule.js +4 -2
  77. package/lib/container/RemoteRuntimeModule.js +8 -7
  78. package/lib/css/CssExportsGenerator.js +139 -0
  79. package/lib/css/CssGenerator.js +109 -0
  80. package/lib/css/CssLoadingRuntimeModule.js +442 -0
  81. package/lib/css/CssModulesPlugin.js +462 -0
  82. package/lib/css/CssParser.js +618 -0
  83. package/lib/css/walkCssTokens.js +659 -0
  84. package/lib/debug/ProfilingPlugin.js +24 -21
  85. package/lib/dependencies/AMDRequireDependency.js +6 -6
  86. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  87. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  88. package/lib/dependencies/CommonJsImportsParserPlugin.js +344 -61
  89. package/lib/dependencies/CommonJsRequireContextDependency.js +6 -2
  90. package/lib/dependencies/CommonJsRequireDependency.js +2 -1
  91. package/lib/dependencies/ContextDependency.js +16 -2
  92. package/lib/dependencies/ContextDependencyHelpers.js +21 -8
  93. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  94. package/lib/dependencies/ContextElementDependency.js +25 -3
  95. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  96. package/lib/dependencies/CssExportDependency.js +85 -0
  97. package/lib/dependencies/CssImportDependency.js +75 -0
  98. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  99. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  100. package/lib/dependencies/CssUrlDependency.js +132 -0
  101. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  102. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  103. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  104. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +127 -0
  105. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  106. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  107. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  108. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  109. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  110. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  111. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  112. package/lib/dependencies/ImportContextDependency.js +0 -2
  113. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  114. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  115. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  116. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  117. package/lib/dependencies/ImportParserPlugin.js +35 -29
  118. package/lib/dependencies/JsonExportsDependency.js +17 -21
  119. package/lib/dependencies/LoaderDependency.js +13 -0
  120. package/lib/dependencies/LoaderImportDependency.js +13 -0
  121. package/lib/dependencies/LoaderPlugin.js +4 -2
  122. package/lib/dependencies/ModuleDependency.js +11 -1
  123. package/lib/dependencies/ProvidedDependency.js +31 -8
  124. package/lib/dependencies/RequireContextDependency.js +0 -16
  125. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  126. package/lib/dependencies/RequireResolveContextDependency.js +2 -2
  127. package/lib/dependencies/RequireResolveDependency.js +2 -1
  128. package/lib/dependencies/URLDependency.js +3 -8
  129. package/lib/dependencies/URLPlugin.js +22 -1
  130. package/lib/dependencies/WorkerPlugin.js +2 -0
  131. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  132. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  134. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  135. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  136. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  137. package/lib/hmr/lazyCompilationBackend.js +51 -12
  138. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  139. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  140. package/lib/ids/IdHelpers.js +26 -12
  141. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  142. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  143. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  144. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  145. package/lib/index.js +20 -0
  146. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  147. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  148. package/lib/javascript/ChunkHelpers.js +33 -0
  149. package/lib/javascript/JavascriptGenerator.js +1 -0
  150. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  151. package/lib/javascript/JavascriptParser.js +143 -73
  152. package/lib/javascript/StartupHelpers.js +7 -30
  153. package/lib/json/JsonData.js +8 -0
  154. package/lib/json/JsonParser.js +4 -6
  155. package/lib/library/AssignLibraryPlugin.js +39 -15
  156. package/lib/library/EnableLibraryPlugin.js +11 -0
  157. package/lib/library/UmdLibraryPlugin.js +5 -3
  158. package/lib/node/NodeTargetPlugin.js +3 -0
  159. package/lib/node/NodeWatchFileSystem.js +85 -31
  160. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  161. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  162. package/lib/optimize/ConcatenatedModule.js +62 -26
  163. package/lib/optimize/ModuleConcatenationPlugin.js +26 -4
  164. package/lib/optimize/RealContentHashPlugin.js +45 -15
  165. package/lib/optimize/SplitChunksPlugin.js +8 -1
  166. package/lib/runtime/AsyncModuleRuntimeModule.js +50 -66
  167. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  168. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  169. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  170. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  171. package/lib/runtime/LoadScriptRuntimeModule.js +11 -9
  172. package/lib/runtime/NonceRuntimeModule.js +24 -0
  173. package/lib/schemes/HttpUriPlugin.js +77 -14
  174. package/lib/serialization/FileMiddleware.js +44 -9
  175. package/lib/sharing/ConsumeSharedModule.js +8 -2
  176. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  177. package/lib/sharing/ProvideSharedModule.js +4 -2
  178. package/lib/sharing/ProvideSharedPlugin.js +1 -2
  179. package/lib/sharing/ShareRuntimeModule.js +1 -1
  180. package/lib/sharing/utils.js +1 -1
  181. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  182. package/lib/stats/DefaultStatsPrinterPlugin.js +90 -25
  183. package/lib/util/ArrayHelpers.js +30 -0
  184. package/lib/util/AsyncQueue.js +1 -1
  185. package/lib/util/compileBooleanMatcher.js +1 -1
  186. package/lib/util/create-schema-validation.js +9 -2
  187. package/lib/util/createHash.js +12 -0
  188. package/lib/util/deprecation.js +10 -2
  189. package/lib/util/deterministicGrouping.js +1 -1
  190. package/lib/util/extractUrlAndGlobal.js +3 -0
  191. package/lib/util/fs.js +11 -0
  192. package/lib/util/hash/BatchedHash.js +7 -4
  193. package/lib/util/hash/md4.js +20 -0
  194. package/lib/util/hash/wasm-hash.js +163 -0
  195. package/lib/util/hash/xxhash64.js +5 -139
  196. package/lib/util/identifier.js +65 -44
  197. package/lib/util/internalSerializables.js +15 -0
  198. package/lib/util/nonNumericOnlyHash.js +22 -0
  199. package/lib/util/semver.js +17 -10
  200. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  201. package/lib/wasm-sync/WebAssemblyParser.js +1 -1
  202. package/lib/web/JsonpChunkLoadingRuntimeModule.js +31 -18
  203. package/lib/webpack.js +10 -3
  204. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  205. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  206. package/module.d.ts +215 -0
  207. package/package.json +28 -32
  208. package/schemas/WebpackOptions.check.js +1 -1
  209. package/schemas/WebpackOptions.json +321 -30
  210. package/schemas/plugins/BannerPlugin.check.js +1 -1
  211. package/schemas/plugins/BannerPlugin.json +4 -0
  212. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  213. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  214. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  215. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  216. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  217. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  218. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  219. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  220. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  221. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  222. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  223. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  224. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  225. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  226. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  227. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  228. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  229. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  230. package/schemas/plugins/css/CssParserOptions.json +3 -0
  231. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  232. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  233. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  234. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  235. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  236. package/types.d.ts +869 -296
@@ -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,
@@ -1926,7 +1938,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1926
1938
 
1927
1939
  // This avoids deadlocks for circular dependencies
1928
1940
  if (this.processDependenciesQueue.isProcessing(module)) {
1929
- return callback();
1941
+ return callback(null, module);
1930
1942
  }
1931
1943
 
1932
1944
  this.processModuleDependencies(module, err => {
@@ -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) {
@@ -3173,53 +3192,96 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3173
3192
  }
3174
3193
 
3175
3194
  _runCodeGenerationJobs(jobs, callback) {
3195
+ if (jobs.length === 0) {
3196
+ return callback();
3197
+ }
3176
3198
  let statModulesFromCache = 0;
3177
3199
  let statModulesGenerated = 0;
3178
3200
  const { chunkGraph, moduleGraph, dependencyTemplates, runtimeTemplate } =
3179
3201
  this;
3180
3202
  const results = this.codeGenerationResults;
3181
3203
  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);
3204
+ /** @type {Set<Module> | undefined} */
3205
+ let notCodeGeneratedModules = undefined;
3206
+ const runIteration = () => {
3207
+ let delayedJobs = [];
3208
+ let delayedModules = new Set();
3209
+ asyncLib.eachLimit(
3210
+ jobs,
3211
+ this.options.parallelism,
3212
+ (job, callback) => {
3213
+ const { module } = job;
3214
+ const { codeGenerationDependencies } = module;
3215
+ if (codeGenerationDependencies !== undefined) {
3216
+ if (
3217
+ notCodeGeneratedModules === undefined ||
3218
+ codeGenerationDependencies.some(dep => {
3219
+ const referencedModule = moduleGraph.getModule(dep);
3220
+ return notCodeGeneratedModules.has(referencedModule);
3221
+ })
3222
+ ) {
3223
+ delayedJobs.push(job);
3224
+ delayedModules.add(module);
3225
+ return callback();
3226
+ }
3201
3227
  }
3202
- );
3203
- },
3204
- err => {
3205
- if (err) return callback(err);
3206
- if (errors.length > 0) {
3207
- errors.sort(
3208
- compareSelect(err => err.module, compareModulesByIdentifier)
3228
+ const { hash, runtime, runtimes } = job;
3229
+ this._codeGenerationModule(
3230
+ module,
3231
+ runtime,
3232
+ runtimes,
3233
+ hash,
3234
+ dependencyTemplates,
3235
+ chunkGraph,
3236
+ moduleGraph,
3237
+ runtimeTemplate,
3238
+ errors,
3239
+ results,
3240
+ (err, codeGenerated) => {
3241
+ if (codeGenerated) statModulesGenerated++;
3242
+ else statModulesFromCache++;
3243
+ callback(err);
3244
+ }
3209
3245
  );
3210
- for (const error of errors) {
3211
- this.errors.push(error);
3246
+ },
3247
+ err => {
3248
+ if (err) return callback(err);
3249
+ if (delayedJobs.length > 0) {
3250
+ if (delayedJobs.length === jobs.length) {
3251
+ return callback(
3252
+ new Error(
3253
+ `Unable to make progress during code generation because of circular code generation dependency: ${Array.from(
3254
+ delayedModules,
3255
+ m => m.identifier()
3256
+ ).join(", ")}`
3257
+ )
3258
+ );
3259
+ }
3260
+ jobs = delayedJobs;
3261
+ delayedJobs = [];
3262
+ notCodeGeneratedModules = delayedModules;
3263
+ delayedModules = new Set();
3264
+ return runIteration();
3265
+ }
3266
+ if (errors.length > 0) {
3267
+ errors.sort(
3268
+ compareSelect(err => err.module, compareModulesByIdentifier)
3269
+ );
3270
+ for (const error of errors) {
3271
+ this.errors.push(error);
3272
+ }
3212
3273
  }
3274
+ this.logger.log(
3275
+ `${Math.round(
3276
+ (100 * statModulesGenerated) /
3277
+ (statModulesGenerated + statModulesFromCache)
3278
+ )}% code generated (${statModulesGenerated} generated, ${statModulesFromCache} from cache)`
3279
+ );
3280
+ callback();
3213
3281
  }
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
- );
3282
+ );
3283
+ };
3284
+ runIteration();
3223
3285
  }
3224
3286
 
3225
3287
  /**
@@ -3269,7 +3331,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3269
3331
  moduleGraph,
3270
3332
  dependencyTemplates,
3271
3333
  runtimeTemplate,
3272
- runtime
3334
+ runtime,
3335
+ codeGenerationResults: results,
3336
+ compilation: this
3273
3337
  });
3274
3338
  } catch (err) {
3275
3339
  errors.push(new CodeGenerationError(module, err));
@@ -3453,7 +3517,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3453
3517
  */
3454
3518
  addRuntimeModule(chunk, module, chunkGraph = this.chunkGraph) {
3455
3519
  // Deprecated ModuleGraph association
3456
- ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
3520
+ if (this._backCompat)
3521
+ ModuleGraph.setModuleGraphForModule(module, this.moduleGraph);
3457
3522
 
3458
3523
  // add it to the list
3459
3524
  this.modules.add(module);
@@ -3497,10 +3562,11 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3497
3562
  }
3498
3563
 
3499
3564
  /**
3565
+ * If `module` is passed, `loc` and `request` must also be passed.
3500
3566
  * @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
3567
+ * @param {Module=} module the module the references the chunk group
3568
+ * @param {DependencyLocation=} loc the location from with the chunk group is referenced (inside of module)
3569
+ * @param {string=} request the request from which the the chunk group is referenced
3504
3570
  * @returns {ChunkGroup} the new or existing chunk group
3505
3571
  */
3506
3572
  addChunkInGroup(groupOptions, module, loc, request) {
@@ -3589,9 +3655,10 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3589
3655
  return chunk;
3590
3656
  }
3591
3657
  }
3592
- const chunk = new Chunk(name);
3658
+ const chunk = new Chunk(name, this._backCompat);
3593
3659
  this.chunks.add(chunk);
3594
- ChunkGraph.setChunkGraphForChunk(chunk, this.chunkGraph);
3660
+ if (this._backCompat)
3661
+ ChunkGraph.setChunkGraphForChunk(chunk, this.chunkGraph);
3595
3662
  if (name) {
3596
3663
  this.namedChunks.set(name, chunk);
3597
3664
  }
@@ -3822,6 +3889,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3822
3889
  let statModulesFromCache = 0;
3823
3890
  const { chunkGraph, runtimeTemplate, moduleMemCaches2 } = this;
3824
3891
  const { hashFunction, hashDigest, hashDigestLength } = this.outputOptions;
3892
+ const errors = [];
3825
3893
  for (const module of this.modules) {
3826
3894
  const memCache = moduleMemCaches2 && moduleMemCaches2.get(module);
3827
3895
  for (const runtime of chunkGraph.getModuleRuntimes(module)) {
@@ -3832,7 +3900,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3832
3900
  module,
3833
3901
  runtime,
3834
3902
  digest,
3835
- digest.substr(0, hashDigestLength)
3903
+ digest.slice(0, hashDigestLength)
3836
3904
  );
3837
3905
  statModulesFromCache++;
3838
3906
  continue;
@@ -3846,13 +3914,20 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3846
3914
  hashFunction,
3847
3915
  runtimeTemplate,
3848
3916
  hashDigest,
3849
- hashDigestLength
3917
+ hashDigestLength,
3918
+ errors
3850
3919
  );
3851
3920
  if (memCache) {
3852
3921
  memCache.set(`moduleHash-${getRuntimeKey(runtime)}`, digest);
3853
3922
  }
3854
3923
  }
3855
3924
  }
3925
+ if (errors.length > 0) {
3926
+ errors.sort(compareSelect(err => err.module, compareModulesByIdentifier));
3927
+ for (const error of errors) {
3928
+ this.errors.push(error);
3929
+ }
3930
+ }
3856
3931
  this.logger.log(
3857
3932
  `${statModulesHashed} modules hashed, ${statModulesFromCache} from cache (${
3858
3933
  Math.round(
@@ -3869,22 +3944,27 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3869
3944
  hashFunction,
3870
3945
  runtimeTemplate,
3871
3946
  hashDigest,
3872
- hashDigestLength
3947
+ hashDigestLength,
3948
+ errors
3873
3949
  ) {
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
- );
3950
+ let moduleHashDigest;
3951
+ try {
3952
+ const moduleHash = createHash(hashFunction);
3953
+ module.updateHash(moduleHash, {
3954
+ chunkGraph,
3955
+ runtime,
3956
+ runtimeTemplate
3957
+ });
3958
+ moduleHashDigest = /** @type {string} */ (moduleHash.digest(hashDigest));
3959
+ } catch (err) {
3960
+ errors.push(new ModuleHashingError(module, err));
3961
+ moduleHashDigest = "XXXXXX";
3962
+ }
3883
3963
  chunkGraph.setModuleHashes(
3884
3964
  module,
3885
3965
  runtime,
3886
3966
  moduleHashDigest,
3887
- moduleHashDigest.substr(0, hashDigestLength)
3967
+ moduleHashDigest.slice(0, hashDigestLength)
3888
3968
  );
3889
3969
  return moduleHashDigest;
3890
3970
  }
@@ -4030,6 +4110,7 @@ This prevents using hashes of each other and should be avoided.`);
4030
4110
  const codeGenerationJobs = [];
4031
4111
  /** @type {Map<string, Map<Module, {module: Module, hash: string, runtime: RuntimeSpec, runtimes: RuntimeSpec[]}>>} */
4032
4112
  const codeGenerationJobsMap = new Map();
4113
+ const errors = [];
4033
4114
 
4034
4115
  const processChunk = chunk => {
4035
4116
  // Last minute module hash generation for modules that depend on chunk hashes
@@ -4044,7 +4125,8 @@ This prevents using hashes of each other and should be avoided.`);
4044
4125
  hashFunction,
4045
4126
  runtimeTemplate,
4046
4127
  hashDigest,
4047
- hashDigestLength
4128
+ hashDigestLength,
4129
+ errors
4048
4130
  );
4049
4131
  let hashMap = codeGenerationJobsMap.get(hash);
4050
4132
  if (hashMap) {
@@ -4068,15 +4150,16 @@ This prevents using hashes of each other and should be avoided.`);
4068
4150
  }
4069
4151
  }
4070
4152
  this.logger.timeAggregate("hashing: hash runtime modules");
4071
- this.logger.time("hashing: hash chunks");
4072
- const chunkHash = createHash(hashFunction);
4073
4153
  try {
4154
+ this.logger.time("hashing: hash chunks");
4155
+ const chunkHash = createHash(hashFunction);
4074
4156
  if (outputOptions.hashSalt) {
4075
4157
  chunkHash.update(outputOptions.hashSalt);
4076
4158
  }
4077
4159
  chunk.updateHash(chunkHash, chunkGraph);
4078
4160
  this.hooks.chunkHash.call(chunk, chunkHash, {
4079
4161
  chunkGraph,
4162
+ codeGenerationResults: this.codeGenerationResults,
4080
4163
  moduleGraph: this.moduleGraph,
4081
4164
  runtimeTemplate: this.runtimeTemplate
4082
4165
  });
@@ -4085,7 +4168,7 @@ This prevents using hashes of each other and should be avoided.`);
4085
4168
  );
4086
4169
  hash.update(chunkHashDigest);
4087
4170
  chunk.hash = chunkHashDigest;
4088
- chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
4171
+ chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
4089
4172
  const fullHashModules =
4090
4173
  chunkGraph.getChunkFullHashModulesIterable(chunk);
4091
4174
  if (fullHashModules) {
@@ -4100,13 +4183,19 @@ This prevents using hashes of each other and should be avoided.`);
4100
4183
  };
4101
4184
  otherChunks.forEach(processChunk);
4102
4185
  for (const chunk of runtimeChunks) processChunk(chunk);
4186
+ if (errors.length > 0) {
4187
+ errors.sort(compareSelect(err => err.module, compareModulesByIdentifier));
4188
+ for (const error of errors) {
4189
+ this.errors.push(error);
4190
+ }
4191
+ }
4103
4192
 
4104
4193
  this.logger.timeAggregateEnd("hashing: hash runtime modules");
4105
4194
  this.logger.timeAggregateEnd("hashing: hash chunks");
4106
4195
  this.logger.time("hashing: hash digest");
4107
4196
  this.hooks.fullHash.call(hash);
4108
4197
  this.fullHash = /** @type {string} */ (hash.digest(hashDigest));
4109
- this.hash = this.fullHash.substr(0, hashDigestLength);
4198
+ this.hash = this.fullHash.slice(0, hashDigestLength);
4110
4199
  this.logger.timeEnd("hashing: hash digest");
4111
4200
 
4112
4201
  this.logger.time("hashing: process full hash modules");
@@ -4126,7 +4215,7 @@ This prevents using hashes of each other and should be avoided.`);
4126
4215
  module,
4127
4216
  chunk.runtime,
4128
4217
  moduleHashDigest,
4129
- moduleHashDigest.substr(0, hashDigestLength)
4218
+ moduleHashDigest.slice(0, hashDigestLength)
4130
4219
  );
4131
4220
  codeGenerationJobsMap.get(oldHash).get(module).hash = moduleHashDigest;
4132
4221
  }
@@ -4137,7 +4226,7 @@ This prevents using hashes of each other and should be avoided.`);
4137
4226
  chunkHash.digest(hashDigest)
4138
4227
  );
4139
4228
  chunk.hash = chunkHashDigest;
4140
- chunk.renderedHash = chunk.hash.substr(0, hashDigestLength);
4229
+ chunk.renderedHash = chunk.hash.slice(0, hashDigestLength);
4141
4230
  this.hooks.contentHash.call(chunk);
4142
4231
  }
4143
4232
  this.logger.timeEnd("hashing: process full hash modules");
@@ -4155,7 +4244,11 @@ This prevents using hashes of each other and should be avoided.`);
4155
4244
  if (!isSourceEqual(this.assets[file], source)) {
4156
4245
  this.errors.push(
4157
4246
  new WebpackError(
4158
- `Conflict: Multiple assets emit different content to the same filename ${file}`
4247
+ `Conflict: Multiple assets emit different content to the same filename ${file}${
4248
+ assetInfo.sourceFilename
4249
+ ? `. Original source ${assetInfo.sourceFilename}`
4250
+ : ""
4251
+ }`
4159
4252
  )
4160
4253
  );
4161
4254
  this.assets[file] = source;
@@ -4715,7 +4808,7 @@ This prevents using hashes of each other and should be avoided.`);
4715
4808
  this.outputOptions;
4716
4809
  const runtimeTemplate = this.runtimeTemplate;
4717
4810
 
4718
- const chunk = new Chunk("build time chunk");
4811
+ const chunk = new Chunk("build time chunk", this._backCompat);
4719
4812
  chunk.id = chunk.name;
4720
4813
  chunk.ids = [chunk.id];
4721
4814
  chunk.runtime = runtime;
@@ -4739,6 +4832,9 @@ This prevents using hashes of each other and should be avoided.`);
4739
4832
  chunkGraph.connectChunkAndModule(chunk, module);
4740
4833
  }
4741
4834
 
4835
+ /** @type {WebpackError[]} */
4836
+ const errors = [];
4837
+
4742
4838
  // Hash modules
4743
4839
  for (const module of modules) {
4744
4840
  this._createModuleHash(
@@ -4748,15 +4844,14 @@ This prevents using hashes of each other and should be avoided.`);
4748
4844
  hashFunction,
4749
4845
  runtimeTemplate,
4750
4846
  hashDigest,
4751
- hashDigestLength
4847
+ hashDigestLength,
4848
+ errors
4752
4849
  );
4753
4850
  }
4754
4851
 
4755
4852
  const codeGenerationResults = new CodeGenerationResults(
4756
4853
  this.outputOptions.hashFunction
4757
4854
  );
4758
- /** @type {WebpackError[]} */
4759
- const errors = [];
4760
4855
  /**
4761
4856
  * @param {Module} module the module
4762
4857
  * @param {Callback} callback callback