webpack 5.90.3 → 5.92.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 (257) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +14 -6
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +8 -2
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/Chunk.js +7 -4
  9. package/lib/ChunkGraph.js +52 -25
  10. package/lib/ChunkGroup.js +23 -17
  11. package/lib/CleanPlugin.js +8 -6
  12. package/lib/Compilation.js +295 -120
  13. package/lib/Compiler.js +223 -87
  14. package/lib/ConcatenationScope.js +3 -3
  15. package/lib/ConditionalInitFragment.js +4 -5
  16. package/lib/ContextModule.js +95 -41
  17. package/lib/ContextModuleFactory.js +4 -2
  18. package/lib/ContextReplacementPlugin.js +3 -2
  19. package/lib/DefinePlugin.js +18 -6
  20. package/lib/Dependency.js +12 -10
  21. package/lib/DependencyTemplate.js +17 -7
  22. package/lib/DllModule.js +1 -0
  23. package/lib/DllReferencePlugin.js +7 -3
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/EvalDevToolModulePlugin.js +11 -0
  28. package/lib/ExportsInfo.js +23 -8
  29. package/lib/ExternalModule.js +160 -35
  30. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  31. package/lib/FileSystemInfo.js +69 -42
  32. package/lib/FlagDependencyExportsPlugin.js +21 -7
  33. package/lib/Generator.js +4 -4
  34. package/lib/HookWebpackError.js +2 -2
  35. package/lib/HotModuleReplacementPlugin.js +108 -45
  36. package/lib/IgnorePlugin.js +4 -1
  37. package/lib/InitFragment.js +5 -3
  38. package/lib/LibManifestPlugin.js +17 -9
  39. package/lib/Module.js +41 -14
  40. package/lib/ModuleFactory.js +3 -3
  41. package/lib/ModuleFilenameHelpers.js +30 -17
  42. package/lib/ModuleGraph.js +60 -31
  43. package/lib/ModuleGraphConnection.js +2 -1
  44. package/lib/MultiCompiler.js +62 -9
  45. package/lib/NodeStuffPlugin.js +14 -3
  46. package/lib/NormalModule.js +13 -13
  47. package/lib/NormalModuleFactory.js +18 -9
  48. package/lib/NormalModuleReplacementPlugin.js +5 -1
  49. package/lib/Parser.js +1 -1
  50. package/lib/PlatformPlugin.js +39 -0
  51. package/lib/ProgressPlugin.js +1 -1
  52. package/lib/ProvidePlugin.js +3 -1
  53. package/lib/RawModule.js +2 -1
  54. package/lib/RecordIdsPlugin.js +4 -4
  55. package/lib/ResolverFactory.js +6 -4
  56. package/lib/RuntimeModule.js +4 -4
  57. package/lib/RuntimePlugin.js +1 -0
  58. package/lib/RuntimeTemplate.js +124 -52
  59. package/lib/SourceMapDevToolPlugin.js +4 -1
  60. package/lib/Stats.js +11 -4
  61. package/lib/Template.js +5 -5
  62. package/lib/TemplatedPathPlugin.js +48 -7
  63. package/lib/Watching.js +67 -60
  64. package/lib/WebpackError.js +6 -6
  65. package/lib/WebpackOptionsApply.js +18 -5
  66. package/lib/asset/AssetGenerator.js +15 -0
  67. package/lib/asset/RawDataUrlModule.js +3 -1
  68. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  69. package/lib/buildChunkGraph.js +120 -67
  70. package/lib/cache/IdleFileCachePlugin.js +8 -3
  71. package/lib/cache/MemoryCachePlugin.js +1 -1
  72. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  73. package/lib/cache/PackFileCacheStrategy.js +51 -18
  74. package/lib/cache/ResolverCachePlugin.js +22 -14
  75. package/lib/cache/getLazyHashedEtag.js +2 -2
  76. package/lib/cli.js +5 -5
  77. package/lib/config/browserslistTargetHandler.js +7 -1
  78. package/lib/config/defaults.js +108 -34
  79. package/lib/config/normalization.js +3 -1
  80. package/lib/config/target.js +18 -11
  81. package/lib/container/ContainerEntryDependency.js +2 -1
  82. package/lib/container/ContainerEntryModule.js +4 -2
  83. package/lib/container/ContainerPlugin.js +14 -10
  84. package/lib/container/FallbackModule.js +1 -1
  85. package/lib/container/RemoteRuntimeModule.js +12 -3
  86. package/lib/css/CssExportsGenerator.js +68 -25
  87. package/lib/css/CssGenerator.js +34 -6
  88. package/lib/css/CssLoadingRuntimeModule.js +217 -98
  89. package/lib/css/CssModulesPlugin.js +238 -107
  90. package/lib/css/CssParser.js +24 -15
  91. package/lib/css/walkCssTokens.js +1 -1
  92. package/lib/debug/ProfilingPlugin.js +28 -3
  93. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  94. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  95. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  96. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  97. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  98. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  99. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  100. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  101. package/lib/dependencies/ContextElementDependency.js +8 -1
  102. package/lib/dependencies/CssExportDependency.js +2 -2
  103. package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
  104. package/lib/dependencies/CssUrlDependency.js +10 -7
  105. package/lib/dependencies/ExportsInfoDependency.js +5 -4
  106. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  107. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  108. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  109. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  110. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  111. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  112. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  113. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  114. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
  115. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  116. package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
  117. package/lib/dependencies/ImportDependency.js +9 -2
  118. package/lib/dependencies/ImportEagerDependency.js +4 -2
  119. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  120. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  121. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  122. package/lib/dependencies/ImportParserPlugin.js +15 -5
  123. package/lib/dependencies/ImportWeakDependency.js +4 -2
  124. package/lib/dependencies/LoaderDependency.js +2 -1
  125. package/lib/dependencies/LoaderImportDependency.js +2 -1
  126. package/lib/dependencies/LoaderPlugin.js +2 -2
  127. package/lib/dependencies/ModuleDependency.js +4 -5
  128. package/lib/dependencies/PureExpressionDependency.js +64 -47
  129. package/lib/dependencies/RequireContextPlugin.js +1 -1
  130. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  131. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  132. package/lib/dependencies/URLDependency.js +7 -4
  133. package/lib/dependencies/WorkerDependency.js +1 -1
  134. package/lib/dependencies/WorkerPlugin.js +2 -1
  135. package/lib/dependencies/getFunctionExpression.js +3 -1
  136. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
  137. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  138. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  139. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  140. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  141. package/lib/ids/IdHelpers.js +6 -6
  142. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  143. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  144. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  145. package/lib/index.js +11 -0
  146. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  147. package/lib/javascript/ChunkHelpers.js +2 -2
  148. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  149. package/lib/javascript/JavascriptGenerator.js +0 -1
  150. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  151. package/lib/javascript/JavascriptParser.js +204 -71
  152. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  153. package/lib/javascript/StartupHelpers.js +22 -5
  154. package/lib/library/AbstractLibraryPlugin.js +2 -2
  155. package/lib/library/AmdLibraryPlugin.js +2 -2
  156. package/lib/library/AssignLibraryPlugin.js +3 -3
  157. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  158. package/lib/library/JsonpLibraryPlugin.js +2 -2
  159. package/lib/library/ModuleLibraryPlugin.js +2 -2
  160. package/lib/library/SystemLibraryPlugin.js +2 -2
  161. package/lib/library/UmdLibraryPlugin.js +33 -12
  162. package/lib/logging/Logger.js +27 -2
  163. package/lib/logging/createConsoleLogger.js +13 -9
  164. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  165. package/lib/node/NodeEnvironmentPlugin.js +14 -8
  166. package/lib/node/NodeTemplatePlugin.js +1 -1
  167. package/lib/node/NodeWatchFileSystem.js +37 -26
  168. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  169. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  170. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/node/nodeConsole.js +24 -1
  172. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  173. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  174. package/lib/optimize/ConcatenatedModule.js +140 -121
  175. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  176. package/lib/optimize/InnerGraph.js +8 -3
  177. package/lib/optimize/InnerGraphPlugin.js +36 -13
  178. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  179. package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
  180. package/lib/optimize/RealContentHashPlugin.js +3 -3
  181. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  182. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  183. package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
  184. package/lib/optimize/SplitChunksPlugin.js +10 -10
  185. package/lib/performance/SizeLimitsPlugin.js +13 -2
  186. package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
  187. package/lib/rules/RuleSetCompiler.js +9 -7
  188. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  189. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  190. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  191. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  192. package/lib/schemes/HttpUriPlugin.js +1 -1
  193. package/lib/serialization/BinaryMiddleware.js +4 -4
  194. package/lib/serialization/FileMiddleware.js +4 -3
  195. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  196. package/lib/serialization/ObjectMiddleware.js +8 -5
  197. package/lib/serialization/PlainObjectSerializer.js +2 -2
  198. package/lib/serialization/Serializer.js +19 -0
  199. package/lib/serialization/SerializerMiddleware.js +2 -2
  200. package/lib/serialization/SingleItemMiddleware.js +2 -2
  201. package/lib/serialization/types.js +1 -1
  202. package/lib/sharing/ConsumeSharedModule.js +2 -2
  203. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  204. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  205. package/lib/sharing/ProvideSharedPlugin.js +13 -6
  206. package/lib/sharing/resolveMatchedConfigs.js +3 -3
  207. package/lib/sharing/utils.js +13 -6
  208. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  209. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  210. package/lib/stats/StatsFactory.js +2 -2
  211. package/lib/stats/StatsPrinter.js +6 -6
  212. package/lib/util/ArrayQueue.js +14 -21
  213. package/lib/util/AsyncQueue.js +1 -1
  214. package/lib/util/Queue.js +8 -2
  215. package/lib/util/SortableSet.js +16 -4
  216. package/lib/util/StackedCacheMap.js +26 -0
  217. package/lib/util/TupleQueue.js +8 -2
  218. package/lib/util/WeakTupleMap.js +57 -13
  219. package/lib/util/binarySearchBounds.js +1 -1
  220. package/lib/util/cleverMerge.js +26 -13
  221. package/lib/util/comparators.js +37 -15
  222. package/lib/util/conventions.js +129 -0
  223. package/lib/util/createHash.js +3 -5
  224. package/lib/util/deprecation.js +3 -3
  225. package/lib/util/deterministicGrouping.js +2 -2
  226. package/lib/util/findGraphRoots.js +1 -1
  227. package/lib/util/fs.js +383 -69
  228. package/lib/util/hash/BatchedHash.js +3 -0
  229. package/lib/util/hash/xxhash64.js +2 -2
  230. package/lib/util/identifier.js +5 -5
  231. package/lib/util/mergeScope.js +79 -0
  232. package/lib/util/runtime.js +2 -17
  233. package/lib/util/semver.js +3 -0
  234. package/lib/util/smartGrouping.js +3 -3
  235. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  236. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  237. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  238. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  239. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
  240. package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
  241. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  242. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  243. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  244. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  245. package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
  246. package/lib/webpack.js +19 -6
  247. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  248. package/package.json +40 -39
  249. package/schemas/WebpackOptions.check.js +1 -1
  250. package/schemas/WebpackOptions.json +97 -8
  251. package/schemas/plugins/BannerPlugin.check.js +1 -1
  252. package/schemas/plugins/BannerPlugin.json +5 -1
  253. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  254. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  255. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  256. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  257. package/types.d.ts +1826 -639
package/README.md CHANGED
@@ -315,7 +315,7 @@ a question to [StackOverflow with the webpack tag](https://stackoverflow.com/tag
315
315
 
316
316
  If you are twitter savvy you can tweet #webpack with your question and someone should be able to reach out and help also.
317
317
 
318
- If you have discovered a 🐜 or have a feature suggestion, feel free to create an issue on Github.
318
+ If you have discovered a 🐜 or have a feature suggestion, feel free to create an issue on GitHub.
319
319
 
320
320
  ### License
321
321
 
@@ -405,7 +405,7 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
405
405
 
406
406
  <h2 align="center">Gold Sponsors</h2>
407
407
 
408
- [Become a gold sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on Github with a link to your site.
408
+ [Become a gold sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on GitHub with a link to your site.
409
409
 
410
410
  <div align="center">
411
411
 
@@ -444,7 +444,7 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
444
444
 
445
445
  <h2 align="center">Silver Sponsors</h2>
446
446
 
447
- [Become a silver sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on Github with a link to your site.
447
+ [Become a silver sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on GitHub with a link to your site.
448
448
 
449
449
  <div align="center">
450
450
 
@@ -483,7 +483,7 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
483
483
 
484
484
  <h2 align="center">Bronze Sponsors</h2>
485
485
 
486
- [Become a bronze sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on Github with a link to your site.
486
+ [Become a bronze sponsor](https://opencollective.com/webpack#sponsor) and get your logo on our README on GitHub with a link to your site.
487
487
 
488
488
  <div align="center">
489
489
 
@@ -593,7 +593,7 @@ src="https://static.monei.net/monei-logo.svg" height="30" alt="MONEI"></a>
593
593
 
594
594
  <h2 align="center">Backers</h2>
595
595
 
596
- [Become a backer](https://opencollective.com/webpack#backer) and get your image on our README on Github with a link to your site.
596
+ [Become a backer](https://opencollective.com/webpack#backer) and get your image on our README on GitHub with a link to your site.
597
597
 
598
598
  <a href="https://opencollective.com/webpack/backer/0/website?requireActive=false" target="_blank"><img src="https://opencollective.com/webpack/backer/0/avatar.svg?requireActive=false"></a>
599
599
  <a href="https://opencollective.com/webpack/backer/1/website?requireActive=false" target="_blank"><img src="https://opencollective.com/webpack/backer/1/avatar.svg?requireActive=false"></a>
package/bin/webpack.js CHANGED
@@ -79,7 +79,6 @@ const runCli = cli => {
79
79
  const pkg = require(pkgPath);
80
80
 
81
81
  if (pkg.type === "module" || /\.mjs/i.test(pkg.bin[cli.binName])) {
82
- // eslint-disable-next-line n/no-unsupported-features/es-syntax
83
82
  import(path.resolve(path.dirname(pkgPath), pkg.bin[cli.binName])).catch(
84
83
  error => {
85
84
  console.error(error);
@@ -92,7 +91,7 @@ const runCli = cli => {
92
91
  };
93
92
 
94
93
  /**
95
- * @typedef {Object} CliOption
94
+ * @typedef {object} CliOption
96
95
  * @property {string} name display name
97
96
  * @property {string} package npm package name
98
97
  * @property {string} binName name of the executable file
@@ -119,6 +118,7 @@ if (!cli.installed) {
119
118
 
120
119
  console.error(notify);
121
120
 
121
+ /** @type {string | undefined} */
122
122
  let packageManager;
123
123
 
124
124
  if (fs.existsSync(path.resolve(process.cwd(), "yarn.lock"))) {
@@ -171,7 +171,10 @@ if (!cli.installed) {
171
171
  }')...`
172
172
  );
173
173
 
174
- runCommand(packageManager, installOptions.concat(cli.package))
174
+ runCommand(
175
+ /** @type {string} */ (packageManager),
176
+ installOptions.concat(cli.package)
177
+ )
175
178
  .then(() => {
176
179
  runCli(cli);
177
180
  })
package/lib/APIPlugin.js CHANGED
@@ -25,6 +25,7 @@ const GetFullHashRuntimeModule = require("./runtime/GetFullHashRuntimeModule");
25
25
 
26
26
  /** @typedef {import("./Compiler")} Compiler */
27
27
  /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
28
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
28
29
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
29
30
  /** @typedef {import("./javascript/JavascriptParser").Range} Range */
30
31
 
@@ -132,7 +133,7 @@ function getReplacements(module, importMetaName) {
132
133
  const PLUGIN_NAME = "APIPlugin";
133
134
 
134
135
  /**
135
- * @typedef {Object} APIPluginOptions
136
+ * @typedef {object} APIPluginOptions
136
137
  * @property {boolean} [module] the output filename
137
138
  */
138
139
 
@@ -187,10 +188,14 @@ class APIPlugin {
187
188
  hooks.renderModuleContent.tap(
188
189
  PLUGIN_NAME,
189
190
  (source, module, renderContext) => {
190
- if (module.buildInfo.needCreateRequire) {
191
+ if (/** @type {BuildInfo} */ (module.buildInfo).needCreateRequire) {
192
+ const needPrefix =
193
+ renderContext.runtimeTemplate.supportNodePrefixForCoreModules();
191
194
  const chunkInitFragments = [
192
195
  new InitFragment(
193
- 'import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "module";\n',
196
+ `import { createRequire as __WEBPACK_EXTERNAL_createRequire } from "${
197
+ needPrefix ? "node:" : ""
198
+ }module";\n`,
194
199
  InitFragment.STAGE_HARMONY_IMPORTS,
195
200
  0,
196
201
  "external module node-commonjs"
@@ -214,7 +219,8 @@ class APIPlugin {
214
219
  const dep = toConstantDependency(parser, info.expr, info.req);
215
220
 
216
221
  if (key === "__non_webpack_require__" && this.options.module) {
217
- parser.state.module.buildInfo.needCreateRequire = true;
222
+ /** @type {BuildInfo} */
223
+ (parser.state.module.buildInfo).needCreateRequire = true;
218
224
  }
219
225
 
220
226
  return dep(expression);
@@ -267,7 +273,8 @@ class APIPlugin {
267
273
  parser.hooks.expression
268
274
  .for("__webpack_module__.id")
269
275
  .tap(PLUGIN_NAME, expr => {
270
- parser.state.module.buildInfo.moduleConcatenationBailout =
276
+ /** @type {BuildInfo} */
277
+ (parser.state.module.buildInfo).moduleConcatenationBailout =
271
278
  "__webpack_module__.id";
272
279
  const dep = new ConstDependency(
273
280
  parser.state.module.moduleArgument + ".id",
@@ -282,7 +289,8 @@ class APIPlugin {
282
289
  parser.hooks.expression
283
290
  .for("__webpack_module__")
284
291
  .tap(PLUGIN_NAME, expr => {
285
- parser.state.module.buildInfo.moduleConcatenationBailout =
292
+ /** @type {BuildInfo} */
293
+ (parser.state.module.buildInfo).moduleConcatenationBailout =
286
294
  "__webpack_module__";
287
295
  const dep = new ConstDependency(
288
296
  parser.state.module.moduleArgument,
@@ -27,7 +27,7 @@ class AutomaticPrefetchPlugin {
27
27
  );
28
28
  }
29
29
  );
30
- /** @type {{context: string, request: string}[] | null} */
30
+ /** @type {{context: string | null, request: string}[] | null} */
31
31
  let lastModules = null;
32
32
  compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => {
33
33
  lastModules = [];
@@ -83,12 +83,14 @@ class BannerPlugin {
83
83
  options
84
84
  );
85
85
  const cache = new WeakMap();
86
+ const stage =
87
+ this.options.stage || Compilation.PROCESS_ASSETS_STAGE_ADDITIONS;
86
88
 
87
89
  compiler.hooks.compilation.tap("BannerPlugin", compilation => {
88
90
  compilation.hooks.processAssets.tap(
89
91
  {
90
92
  name: "BannerPlugin",
91
- stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
93
+ stage
92
94
  },
93
95
  () => {
94
96
  for (const chunk of compilation.chunks) {
package/lib/Cache.js CHANGED
@@ -14,14 +14,14 @@ const {
14
14
  /** @typedef {import("./WebpackError")} WebpackError */
15
15
 
16
16
  /**
17
- * @typedef {Object} Etag
17
+ * @typedef {object} Etag
18
18
  * @property {function(): string} toString
19
19
  */
20
20
 
21
21
  /**
22
22
  * @template T
23
23
  * @callback CallbackCache
24
- * @param {(WebpackError | null)=} err
24
+ * @param {WebpackError | null} err
25
25
  * @param {T=} result
26
26
  * @returns {void}
27
27
  */
@@ -33,6 +33,11 @@ const {
33
33
  * @returns {void}
34
34
  */
35
35
 
36
+ /**
37
+ * @param {number} times times
38
+ * @param {function(Error=): void} callback callback
39
+ * @returns {function(Error=): void} callback
40
+ */
36
41
  const needCalls = (times, callback) => {
37
42
  return err => {
38
43
  if (--times === 0) {
@@ -71,6 +76,7 @@ class Cache {
71
76
  * @returns {void}
72
77
  */
73
78
  get(identifier, etag, callback) {
79
+ /** @type {GotHandler[]} */
74
80
  const gotHandlers = [];
75
81
  this.hooks.get.callAsync(identifier, etag, gotHandlers, (err, result) => {
76
82
  if (err) {
@@ -19,8 +19,8 @@ const mergeEtags = require("./cache/mergeEtags");
19
19
  /**
20
20
  * @template T
21
21
  * @callback CallbackCache
22
- * @param {(WebpackError | null)=} err
23
- * @param {T=} result
22
+ * @param {(Error | null)=} err
23
+ * @param {(T | null)=} result
24
24
  * @returns {void}
25
25
  */
26
26
 
@@ -196,7 +196,7 @@ class CacheFacade {
196
196
  /**
197
197
  * @param {Cache} cache the root cache
198
198
  * @param {string} name the child cache name
199
- * @param {string | HashConstructor} hashFunction the hash function to use
199
+ * @param {(string | HashConstructor)=} hashFunction the hash function to use
200
200
  */
201
201
  constructor(cache, name, hashFunction) {
202
202
  this._cache = cache;
package/lib/Chunk.js CHANGED
@@ -38,13 +38,13 @@ const { mergeRuntime } = require("./util/runtime");
38
38
  const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files");
39
39
 
40
40
  /**
41
- * @typedef {Object} WithId an object who has an id property *
41
+ * @typedef {object} WithId an object who has an id property *
42
42
  * @property {string | number} id the id of the object
43
43
  */
44
44
 
45
45
  /**
46
46
  * @deprecated
47
- * @typedef {Object} ChunkMaps
47
+ * @typedef {object} ChunkMaps
48
48
  * @property {Record<string|number, string>} hash
49
49
  * @property {Record<string|number, Record<string, string>>} contentHash
50
50
  * @property {Record<string|number, string>} name
@@ -52,7 +52,7 @@ const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files");
52
52
 
53
53
  /**
54
54
  * @deprecated
55
- * @typedef {Object} ChunkModuleMaps
55
+ * @typedef {object} ChunkModuleMaps
56
56
  * @property {Record<string|number, (string|number)[]>} id
57
57
  * @property {Record<string|number, string>} hash
58
58
  */
@@ -85,7 +85,10 @@ class Chunk {
85
85
  this.filenameTemplate = undefined;
86
86
  /** @type {(string | function(PathData, AssetInfo=): string) | undefined} */
87
87
  this.cssFilenameTemplate = undefined;
88
- /** @private @type {SortableSet<ChunkGroup>} */
88
+ /**
89
+ * @private
90
+ * @type {SortableSet<ChunkGroup>}
91
+ */
89
92
  this._groups = new SortableSet(undefined, compareChunkGroupsByIndex);
90
93
  /** @type {RuntimeSpec} */
91
94
  this.runtime = undefined;
package/lib/ChunkGraph.js CHANGED
@@ -33,6 +33,7 @@ const {
33
33
  /** @typedef {import("./ChunkGroup")} ChunkGroup */
34
34
  /** @typedef {import("./Module")} Module */
35
35
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
36
+ /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
36
37
  /** @typedef {import("./RuntimeModule")} RuntimeModule */
37
38
  /** @typedef {typeof import("./util/Hash")} Hash */
38
39
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
@@ -49,12 +50,16 @@ const compareModuleIterables = compareIterables(compareModulesByIdentifier);
49
50
  /** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */
50
51
 
51
52
  /**
52
- * @typedef {Object} ChunkSizeOptions
53
+ * @typedef {object} ChunkSizeOptions
53
54
  * @property {number=} chunkOverhead constant overhead for a chunk
54
55
  * @property {number=} entryChunkMultiplicator multiplicator for initial chunks
55
56
  */
56
57
 
57
58
  class ModuleHashInfo {
59
+ /**
60
+ * @param {string} hash hash
61
+ * @param {string} renderedHash rendered hash
62
+ */
58
63
  constructor(hash, renderedHash) {
59
64
  this.hash = hash;
60
65
  this.renderedHash = renderedHash;
@@ -180,13 +185,17 @@ const isAvailableChunk = (a, b) => {
180
185
  return true;
181
186
  };
182
187
 
188
+ /** @typedef {Set<Chunk>} EntryInChunks */
189
+ /** @typedef {Set<Chunk>} RuntimeInChunks */
190
+ /** @typedef {string | number} ModuleId */
191
+
183
192
  class ChunkGraphModule {
184
193
  constructor() {
185
194
  /** @type {SortableSet<Chunk>} */
186
195
  this.chunks = new SortableSet();
187
- /** @type {Set<Chunk> | undefined} */
196
+ /** @type {EntryInChunks | undefined} */
188
197
  this.entryInChunks = undefined;
189
- /** @type {Set<Chunk> | undefined} */
198
+ /** @type {RuntimeInChunks | undefined} */
190
199
  this.runtimeInChunks = undefined;
191
200
  /** @type {RuntimeSpecMap<ModuleHashInfo> | undefined} */
192
201
  this.hashes = undefined;
@@ -194,9 +203,9 @@ class ChunkGraphModule {
194
203
  this.id = null;
195
204
  /** @type {RuntimeSpecMap<Set<string>> | undefined} */
196
205
  this.runtimeRequirements = undefined;
197
- /** @type {RuntimeSpecMap<string>} */
206
+ /** @type {RuntimeSpecMap<string> | undefined} */
198
207
  this.graphHashes = undefined;
199
- /** @type {RuntimeSpecMap<string>} */
208
+ /** @type {RuntimeSpecMap<string> | undefined} */
200
209
  this.graphHashesWithConnections = undefined;
201
210
  }
202
211
  }
@@ -230,13 +239,25 @@ class ChunkGraph {
230
239
  * @param {string | Hash} hashFunction the hash function to use
231
240
  */
232
241
  constructor(moduleGraph, hashFunction = "md4") {
233
- /** @private @type {WeakMap<Module, ChunkGraphModule>} */
242
+ /**
243
+ * @private
244
+ * @type {WeakMap<Module, ChunkGraphModule>}
245
+ */
234
246
  this._modules = new WeakMap();
235
- /** @private @type {WeakMap<Chunk, ChunkGraphChunk>} */
247
+ /**
248
+ * @private
249
+ * @type {WeakMap<Chunk, ChunkGraphChunk>}
250
+ */
236
251
  this._chunks = new WeakMap();
237
- /** @private @type {WeakMap<AsyncDependenciesBlock, ChunkGroup>} */
252
+ /**
253
+ * @private
254
+ * @type {WeakMap<AsyncDependenciesBlock, ChunkGroup>}
255
+ */
238
256
  this._blockChunkGroups = new WeakMap();
239
- /** @private @type {Map<string, string | number>} */
257
+ /**
258
+ * @private
259
+ * @type {Map<string, string | number>}
260
+ */
240
261
  this._runtimeIds = new Map();
241
262
  /** @type {ModuleGraph} */
242
263
  this.moduleGraph = moduleGraph;
@@ -284,6 +305,9 @@ class ChunkGraph {
284
305
  findGraphRoots(set, module => {
285
306
  /** @type {Set<Module>} */
286
307
  const set = new Set();
308
+ /**
309
+ * @param {Module} module module
310
+ */
287
311
  const addDependencies = module => {
288
312
  for (const connection of moduleGraph.getOutgoingConnections(module)) {
289
313
  if (!connection.module) continue;
@@ -417,7 +441,7 @@ class ChunkGraph {
417
441
  }
418
442
  for (const chunk of oldCgm.entryInChunks) {
419
443
  const cgc = this._getChunkGraphChunk(chunk);
420
- const old = cgc.entryModules.get(oldModule);
444
+ const old = /** @type {Entrypoint} */ (cgc.entryModules.get(oldModule));
421
445
  /** @type {Map<Module, Entrypoint>} */
422
446
  const newEntryModules = new Map();
423
447
  for (const [m, cg] of cgc.entryModules) {
@@ -716,7 +740,7 @@ class ChunkGraph {
716
740
  for (const asyncChunk of includeAllChunks
717
741
  ? chunk.getAllReferencedChunks()
718
742
  : chunk.getAllAsyncChunks()) {
719
- /** @type {(string|number)[]} */
743
+ /** @type {(string | number)[] | undefined} */
720
744
  let array;
721
745
  for (const module of this.getOrderedChunkModulesIterable(
722
746
  asyncChunk,
@@ -755,7 +779,7 @@ class ChunkGraph {
755
779
  for (const asyncChunk of includeAllChunks
756
780
  ? chunk.getAllReferencedChunks()
757
781
  : chunk.getAllAsyncChunks()) {
758
- /** @type {Record<string|number, string>} */
782
+ /** @type {Record<string|number, string> | undefined} */
759
783
  let idToHashMap;
760
784
  for (const module of this.getOrderedChunkModulesIterable(
761
785
  asyncChunk,
@@ -1115,7 +1139,7 @@ class ChunkGraph {
1115
1139
  */
1116
1140
  disconnectEntryModule(module) {
1117
1141
  const cgm = this._getChunkGraphModule(module);
1118
- for (const chunk of cgm.entryInChunks) {
1142
+ for (const chunk of /** @type {EntryInChunks} */ (cgm.entryInChunks)) {
1119
1143
  const cgc = this._getChunkGraphChunk(chunk);
1120
1144
  cgc.entryModules.delete(module);
1121
1145
  }
@@ -1223,14 +1247,7 @@ class ChunkGraph {
1223
1247
  const array = Array.from(cgc.runtimeModules);
1224
1248
  array.sort(
1225
1249
  concatComparators(
1226
- compareSelect(
1227
- /**
1228
- * @param {RuntimeModule} r runtime module
1229
- * @returns {number=} stage
1230
- */
1231
- r => r.stage,
1232
- compareIds
1233
- ),
1250
+ compareSelect(r => /** @type {RuntimeModule} */ (r).stage, compareIds),
1234
1251
  compareModulesByIdentifier
1235
1252
  )
1236
1253
  );
@@ -1275,7 +1292,7 @@ class ChunkGraph {
1275
1292
 
1276
1293
  /**
1277
1294
  * @param {AsyncDependenciesBlock} depBlock the async block
1278
- * @returns {ChunkGroup} the chunk group
1295
+ * @returns {ChunkGroup | undefined} the chunk group
1279
1296
  */
1280
1297
  getBlockChunkGroup(depBlock) {
1281
1298
  return this._blockChunkGroups.get(depBlock);
@@ -1305,7 +1322,7 @@ class ChunkGraph {
1305
1322
 
1306
1323
  /**
1307
1324
  * @param {Module} module the module
1308
- * @returns {string | number} the id of the module
1325
+ * @returns {ModuleId} the id of the module
1309
1326
  */
1310
1327
  getModuleId(module) {
1311
1328
  const cgm = this._getChunkGraphModule(module);
@@ -1314,7 +1331,7 @@ class ChunkGraph {
1314
1331
 
1315
1332
  /**
1316
1333
  * @param {Module} module the module
1317
- * @param {string | number} id the id of the module
1334
+ * @param {ModuleId} id the id of the module
1318
1335
  * @returns {void}
1319
1336
  */
1320
1337
  setModuleId(module, id) {
@@ -1364,7 +1381,7 @@ class ChunkGraph {
1364
1381
  Caller might not support runtime-dependent code generation (opt-out via optimization.usedExports: "global").`
1365
1382
  );
1366
1383
  }
1367
- return first(hashInfoItems);
1384
+ return /** @type {T} */ (first(hashInfoItems));
1368
1385
  } else {
1369
1386
  const hashInfo = hashes.get(runtime);
1370
1387
  if (!hashInfo) {
@@ -1576,6 +1593,10 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1576
1593
  if (cgm.graphHashesWithConnections === undefined) {
1577
1594
  cgm.graphHashesWithConnections = new RuntimeSpecMap();
1578
1595
  }
1596
+ /**
1597
+ * @param {ConnectionState} state state
1598
+ * @returns {"F" | "T" | "O"} result
1599
+ */
1579
1600
  const activeStateToString = state => {
1580
1601
  if (state === false) return "F";
1581
1602
  if (state === true) return "T";
@@ -1646,6 +1667,9 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1646
1667
  ? Array.from(connectedModules).sort(([a], [b]) => (a < b ? -1 : 1))
1647
1668
  : connectedModules;
1648
1669
  const hash = createHash(this._hashFunction);
1670
+ /**
1671
+ * @param {Module} module module
1672
+ */
1649
1673
  const addModuleToHash = module => {
1650
1674
  hash.update(
1651
1675
  this._getModuleGraphHashBigInt(
@@ -1655,6 +1679,9 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
1655
1679
  ).toString(16)
1656
1680
  );
1657
1681
  };
1682
+ /**
1683
+ * @param {Set<Module>} modules modules
1684
+ */
1658
1685
  const addModulesToHash = modules => {
1659
1686
  let xor = ZERO_BIG_INT;
1660
1687
  for (const m of modules) {
package/lib/ChunkGroup.js CHANGED
@@ -25,7 +25,7 @@ const {
25
25
  /** @typedef {{module: Module, loc: DependencyLocation, request: string}} OriginRecord */
26
26
 
27
27
  /**
28
- * @typedef {Object} RawChunkGroupOptions
28
+ * @typedef {object} RawChunkGroupOptions
29
29
  * @property {number=} preloadOrder
30
30
  * @property {number=} prefetchOrder
31
31
  * @property {("low" | "high" | "auto")=} fetchPriority
@@ -70,7 +70,7 @@ const sortOrigin = (a, b) => {
70
70
  class ChunkGroup {
71
71
  /**
72
72
  * Creates an instance of ChunkGroup.
73
- * @param {string|ChunkGroupOptions=} options chunk group options passed to chunkGroup
73
+ * @param {string | ChunkGroupOptions=} options chunk group options passed to chunkGroup
74
74
  */
75
75
  constructor(options) {
76
76
  if (typeof options === "string") {
@@ -80,7 +80,7 @@ class ChunkGroup {
80
80
  }
81
81
  /** @type {number} */
82
82
  this.groupDebugId = debugId++;
83
- this.options = options;
83
+ this.options = /** @type {ChunkGroupOptions} */ (options);
84
84
  /** @type {SortableSet<ChunkGroup>} */
85
85
  this._children = new SortableSet(undefined, sortById);
86
86
  /** @type {SortableSet<ChunkGroup>} */
@@ -93,10 +93,16 @@ class ChunkGroup {
93
93
  /** @type {OriginRecord[]} */
94
94
  this.origins = [];
95
95
  /** Indices in top-down order */
96
- /** @private @type {Map<Module, number>} */
96
+ /**
97
+ * @private
98
+ * @type {Map<Module, number>}
99
+ */
97
100
  this._modulePreOrderIndices = new Map();
98
101
  /** Indices in bottom-up order */
99
- /** @private @type {Map<Module, number>} */
102
+ /**
103
+ * @private
104
+ * @type {Map<Module, number>}
105
+ */
100
106
  this._modulePostOrderIndices = new Map();
101
107
  /** @type {number | undefined} */
102
108
  this.index = undefined;
@@ -108,18 +114,18 @@ class ChunkGroup {
108
114
  * @returns {void}
109
115
  */
110
116
  addOptions(options) {
111
- for (const key of Object.keys(options)) {
112
- if (
113
- this.options[/** @type {keyof ChunkGroupOptions} */ (key)] === undefined
114
- ) {
115
- this.options[key] =
116
- options[/** @type {keyof ChunkGroupOptions} */ (key)];
117
- } else if (
118
- this.options[/** @type {keyof ChunkGroupOptions} */ (key)] !==
119
- options[/** @type {keyof ChunkGroupOptions} */ (key)]
120
- ) {
117
+ for (const _key of Object.keys(options)) {
118
+ const key = /** @type {keyof ChunkGroupOptions} */ (_key);
119
+ if (this.options[key] === undefined) {
120
+ /** @type {TODO} */
121
+ (this.options)[key] = options[key];
122
+ } else if (this.options[key] !== options[key]) {
121
123
  if (key.endsWith("Order")) {
122
- this.options[key] = Math.max(this.options[key], options[key]);
124
+ /** @type {TODO} */
125
+ (this.options)[key] = Math.max(
126
+ /** @type {number} */ (this.options[key]),
127
+ /** @type {number} */ (options[key])
128
+ );
123
129
  } else {
124
130
  throw new Error(
125
131
  `ChunkGroup.addOptions: No option merge strategy for ${key}`
@@ -219,7 +225,7 @@ class ChunkGroup {
219
225
  /**
220
226
  * @param {Chunk} oldChunk chunk to be replaced
221
227
  * @param {Chunk} newChunk New chunk that will be replaced with
222
- * @returns {boolean} returns true if the replacement was successful
228
+ * @returns {boolean | undefined} returns true if the replacement was successful
223
229
  */
224
230
  replaceChunk(oldChunk, newChunk) {
225
231
  const oldIdx = this.chunks.indexOf(oldChunk);
@@ -15,6 +15,7 @@ const processAsyncTree = require("./util/processAsyncTree");
15
15
  /** @typedef {import("../declarations/WebpackOptions").CleanOptions} CleanOptions */
16
16
  /** @typedef {import("./Compiler")} Compiler */
17
17
  /** @typedef {import("./logging/Logger").Logger} Logger */
18
+ /** @typedef {import("./util/fs").IStats} IStats */
18
19
  /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
19
20
  /** @typedef {import("./util/fs").StatsCallback} StatsCallback */
20
21
 
@@ -23,7 +24,7 @@ const processAsyncTree = require("./util/processAsyncTree");
23
24
  /** @typedef {function(IgnoreItem): void} AddToIgnoreCallback */
24
25
 
25
26
  /**
26
- * @typedef {Object} CleanPluginCompilationHooks
27
+ * @typedef {object} CleanPluginCompilationHooks
27
28
  * @property {SyncBailHook<[string], boolean>} keep when returning true the file/directory will be kept during cleaning, returning false will clean it and ignore the following plugins and config
28
29
  */
29
30
 
@@ -88,8 +89,8 @@ const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
88
89
  }
89
90
  return callback(err);
90
91
  }
91
- for (const entry of entries) {
92
- const file = /** @type {string} */ (entry);
92
+ for (const entry of /** @type {string[]} */ (entries)) {
93
+ const file = entry;
93
94
  const filename = directory ? `${directory}/${file}` : file;
94
95
  if (!directories.has(filename) && !currentAssets.has(filename)) {
95
96
  diff.add(filename);
@@ -196,7 +197,7 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
196
197
  }
197
198
  doStat(fs, path, (err, stats) => {
198
199
  if (err) return handleError(err);
199
- if (!stats.isDirectory()) {
200
+ if (!(/** @type {IStats} */ (stats).isDirectory())) {
200
201
  push({
201
202
  type: "unlink",
202
203
  filename,
@@ -206,7 +207,7 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
206
207
  }
207
208
 
208
209
  /** @type {NonNullable<OutputFileSystem["readdir"]>} */
209
- (fs.readdir)(path, (err, entries) => {
210
+ (fs.readdir)(path, (err, _entries) => {
210
211
  if (err) return handleError(err);
211
212
  /** @type {Job} */
212
213
  const deleteJob = {
@@ -214,6 +215,7 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
214
215
  filename,
215
216
  parent
216
217
  };
218
+ const entries = /** @type {string[]} */ (_entries);
217
219
  if (entries.length === 0) {
218
220
  push(deleteJob);
219
221
  } else {
@@ -355,7 +357,7 @@ class CleanPlugin {
355
357
  (compilation, callback) => {
356
358
  const hooks = CleanPlugin.getCompilationHooks(compilation);
357
359
  const logger = compilation.getLogger("webpack.CleanPlugin");
358
- const fs = compiler.outputFileSystem;
360
+ const fs = /** @type {OutputFileSystem} */ (compiler.outputFileSystem);
359
361
 
360
362
  if (!fs.readdir) {
361
363
  return callback(