webpack 5.85.0 → 5.88.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (249) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +150 -99
  3. package/lib/AsyncDependenciesBlock.js +3 -3
  4. package/lib/BannerPlugin.js +2 -1
  5. package/lib/CaseSensitiveModulesWarning.js +3 -1
  6. package/lib/Chunk.js +35 -17
  7. package/lib/ChunkGraph.js +4 -4
  8. package/lib/ChunkGroup.js +20 -9
  9. package/lib/CompatibilityPlugin.js +50 -30
  10. package/lib/Compilation.js +2 -1
  11. package/lib/Compiler.js +10 -9
  12. package/lib/ConcatenationScope.js +2 -2
  13. package/lib/ConditionalInitFragment.js +11 -1
  14. package/lib/ConstPlugin.js +73 -32
  15. package/lib/ContextModule.js +8 -3
  16. package/lib/ContextModuleFactory.js +1 -0
  17. package/lib/ContextReplacementPlugin.js +13 -0
  18. package/lib/DelegatedModule.js +15 -3
  19. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  20. package/lib/DependenciesBlock.js +1 -1
  21. package/lib/Dependency.js +11 -5
  22. package/lib/DependencyTemplates.js +1 -1
  23. package/lib/DllEntryPlugin.js +11 -1
  24. package/lib/DllModule.js +6 -0
  25. package/lib/DllReferencePlugin.js +13 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/ErrorHelpers.js +1 -0
  28. package/lib/EvalSourceMapDevToolPlugin.js +6 -1
  29. package/lib/ExportsInfo.js +22 -4
  30. package/lib/ExportsInfoApiPlugin.js +14 -5
  31. package/lib/ExternalModule.js +20 -8
  32. package/lib/FileSystemInfo.js +52 -24
  33. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  34. package/lib/FlagDependencyUsagePlugin.js +3 -1
  35. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  36. package/lib/Generator.js +7 -0
  37. package/lib/HotModuleReplacementPlugin.js +8 -0
  38. package/lib/InitFragment.js +28 -5
  39. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  40. package/lib/LibManifestPlugin.js +20 -4
  41. package/lib/Module.js +14 -3
  42. package/lib/ModuleDependencyError.js +4 -2
  43. package/lib/ModuleDependencyWarning.js +4 -2
  44. package/lib/ModuleGraph.js +31 -24
  45. package/lib/ModuleGraphConnection.js +19 -6
  46. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  47. package/lib/ModuleNotFoundError.js +5 -2
  48. package/lib/ModuleProfile.js +1 -0
  49. package/lib/ModuleRestoreError.js +2 -0
  50. package/lib/ModuleStoreError.js +2 -1
  51. package/lib/ModuleTypeConstants.js +7 -0
  52. package/lib/MultiWatching.js +4 -0
  53. package/lib/NodeStuffPlugin.js +32 -6
  54. package/lib/ProgressPlugin.js +71 -15
  55. package/lib/ProvidePlugin.js +13 -4
  56. package/lib/RawModule.js +3 -1
  57. package/lib/RequireJsStuffPlugin.js +7 -0
  58. package/lib/RuntimeGlobals.js +5 -0
  59. package/lib/RuntimeModule.js +3 -3
  60. package/lib/RuntimePlugin.js +6 -3
  61. package/lib/RuntimeTemplate.js +22 -4
  62. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  63. package/lib/SourceMapDevToolPlugin.js +7 -2
  64. package/lib/UseStrictPlugin.js +10 -3
  65. package/lib/Watching.js +62 -25
  66. package/lib/WebpackError.js +6 -5
  67. package/lib/WebpackIsIncludedPlugin.js +6 -4
  68. package/lib/WebpackOptionsApply.js +4 -2
  69. package/lib/WebpackOptionsDefaulter.js +10 -3
  70. package/lib/asset/AssetGenerator.js +2 -1
  71. package/lib/asset/AssetParser.js +11 -6
  72. package/lib/asset/AssetSourceParser.js +8 -3
  73. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  74. package/lib/buildChunkGraph.js +37 -21
  75. package/lib/cache/IdleFileCachePlugin.js +2 -1
  76. package/lib/cache/PackFileCacheStrategy.js +53 -22
  77. package/lib/config/browserslistTargetHandler.js +7 -7
  78. package/lib/config/defaults.js +43 -26
  79. package/lib/container/RemoteRuntimeModule.js +1 -1
  80. package/lib/css/CssExportsGenerator.js +9 -0
  81. package/lib/css/CssGenerator.js +1 -1
  82. package/lib/css/CssLoadingRuntimeModule.js +43 -19
  83. package/lib/css/CssModulesPlugin.js +42 -14
  84. package/lib/css/CssParser.js +22 -0
  85. package/lib/dependencies/AMDDefineDependency.js +34 -4
  86. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  87. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  88. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  89. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  90. package/lib/dependencies/CommonJsPlugin.js +13 -8
  91. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  92. package/lib/dependencies/ConstDependency.js +2 -2
  93. package/lib/dependencies/ContextDependency.js +7 -2
  94. package/lib/dependencies/CssImportDependency.js +1 -1
  95. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  96. package/lib/dependencies/CssUrlDependency.js +3 -3
  97. package/lib/dependencies/DllEntryDependency.js +5 -0
  98. package/lib/dependencies/DynamicExports.js +10 -6
  99. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  100. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  101. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  102. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  103. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  104. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  105. package/lib/dependencies/HarmonyExports.js +9 -5
  106. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +40 -27
  107. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  108. package/lib/dependencies/HarmonyImportSpecifierDependency.js +31 -21
  109. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  110. package/lib/dependencies/ImportDependency.js +5 -3
  111. package/lib/dependencies/ImportEagerDependency.js +5 -3
  112. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  113. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  114. package/lib/dependencies/ImportParserPlugin.js +62 -25
  115. package/lib/dependencies/ImportWeakDependency.js +5 -3
  116. package/lib/dependencies/JsonExportsDependency.js +1 -1
  117. package/lib/dependencies/ModuleDependency.js +1 -1
  118. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  119. package/lib/dependencies/ProvidedDependency.js +4 -1
  120. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  121. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  122. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  123. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  124. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  125. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  126. package/lib/dependencies/SystemPlugin.js +17 -5
  127. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  128. package/lib/dependencies/URLDependency.js +2 -2
  129. package/lib/dependencies/URLPlugin.js +9 -4
  130. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  131. package/lib/dependencies/WorkerPlugin.js +59 -22
  132. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  134. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  135. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  136. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  137. package/lib/javascript/BasicEvaluatedExpression.js +28 -19
  138. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  139. package/lib/javascript/JavascriptModulesPlugin.js +25 -5
  140. package/lib/javascript/JavascriptParser.js +157 -85
  141. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  142. package/lib/json/JsonData.js +2 -2
  143. package/lib/json/JsonParser.js +25 -12
  144. package/lib/library/AmdLibraryPlugin.js +2 -2
  145. package/lib/library/AssignLibraryPlugin.js +13 -1
  146. package/lib/library/EnableLibraryPlugin.js +4 -0
  147. package/lib/library/SystemLibraryPlugin.js +1 -1
  148. package/lib/library/UmdLibraryPlugin.js +20 -2
  149. package/lib/logging/runtime.js +1 -1
  150. package/lib/logging/truncateArgs.js +4 -0
  151. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  152. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  153. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  154. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  155. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  156. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  157. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  158. package/lib/optimize/InnerGraph.js +5 -5
  159. package/lib/optimize/InnerGraphPlugin.js +2 -1
  160. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  161. package/lib/optimize/MangleExportsPlugin.js +1 -1
  162. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  163. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  164. package/lib/optimize/RealContentHashPlugin.js +80 -30
  165. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  166. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  167. package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
  168. package/lib/optimize/SplitChunksPlugin.js +71 -31
  169. package/lib/performance/SizeLimitsPlugin.js +7 -4
  170. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  171. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  172. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  173. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  174. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  175. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  176. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  177. package/lib/rules/RuleSetCompiler.js +3 -3
  178. package/lib/rules/UseEffectRulePlugin.js +6 -4
  179. package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
  180. package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
  181. package/lib/runtime/BaseUriRuntimeModule.js +3 -3
  182. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  183. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  184. package/lib/runtime/CompatRuntimeModule.js +7 -2
  185. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  186. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  187. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  188. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  189. package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
  190. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
  191. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  192. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  193. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
  194. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  195. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  196. package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
  197. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  198. package/lib/runtime/NonceRuntimeModule.js +1 -1
  199. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  200. package/lib/runtime/PublicPathRuntimeModule.js +4 -2
  201. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  202. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  203. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
  204. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
  205. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  206. package/lib/serialization/BinaryMiddleware.js +143 -1
  207. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  208. package/lib/serialization/ObjectMiddleware.js +9 -3
  209. package/lib/serialization/types.js +1 -1
  210. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  211. package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
  212. package/lib/sharing/ProvideSharedDependency.js +11 -0
  213. package/lib/sharing/ProvideSharedModule.js +4 -0
  214. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  215. package/lib/sharing/ShareRuntimeModule.js +12 -5
  216. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  217. package/lib/sharing/utils.js +32 -5
  218. package/lib/util/AsyncQueue.js +4 -2
  219. package/lib/util/ParallelismFactorCalculator.js +10 -0
  220. package/lib/util/Semaphore.js +1 -1
  221. package/lib/util/StackedCacheMap.js +1 -1
  222. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  223. package/lib/util/createHash.js +30 -9
  224. package/lib/util/deprecation.js +10 -3
  225. package/lib/util/deterministicGrouping.js +50 -11
  226. package/lib/util/findGraphRoots.js +4 -2
  227. package/lib/util/memoize.js +3 -3
  228. package/lib/util/processAsyncTree.js +7 -1
  229. package/lib/util/registerExternalSerializer.js +1 -1
  230. package/lib/util/runtime.js +84 -21
  231. package/lib/util/semver.js +1 -0
  232. package/lib/util/smartGrouping.js +1 -1
  233. package/lib/validateSchema.js +6 -2
  234. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
  235. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  236. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
  237. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  238. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  239. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  240. package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
  241. package/lib/webpack.js +11 -2
  242. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
  243. package/module.d.ts +1 -0
  244. package/package.json +5 -4
  245. package/schemas/WebpackOptions.check.js +1 -1
  246. package/schemas/WebpackOptions.json +52 -6
  247. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  248. package/schemas/plugins/css/CssParserOptions.json +1 -1
  249. package/types.d.ts +606 -292
package/lib/Watching.js CHANGED
@@ -11,6 +11,8 @@ const Stats = require("./Stats");
11
11
  /** @typedef {import("./Compilation")} Compilation */
12
12
  /** @typedef {import("./Compiler")} Compiler */
13
13
  /** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
14
+ /** @typedef {import("./WebpackError")} WebpackError */
15
+ /** @typedef {import("./logging/Logger").Logger} Logger */
14
16
 
15
17
  /**
16
18
  * @template T
@@ -58,9 +60,9 @@ class Watching {
58
60
  this._needRecords = true;
59
61
  this.watcher = undefined;
60
62
  this.pausedWatcher = undefined;
61
- /** @type {Set<string>} */
63
+ /** @type {Set<string> | undefined} */
62
64
  this._collectedChangedFiles = undefined;
63
- /** @type {Set<string>} */
65
+ /** @type {Set<string> | undefined} */
64
66
  this._collectedRemovedFiles = undefined;
65
67
  this._done = this._done.bind(this);
66
68
  process.nextTick(() => {
@@ -69,8 +71,8 @@ class Watching {
69
71
  }
70
72
 
71
73
  /**
72
- * @param {ReadonlySet<string>} changedFiles changed files
73
- * @param {ReadonlySet<string>} removedFiles removed files
74
+ * @param {ReadonlySet<string>=} changedFiles changed files
75
+ * @param {ReadonlySet<string>=} removedFiles removed files
74
76
  */
75
77
  _mergeWithCollected(changedFiles, removedFiles) {
76
78
  if (!changedFiles) return;
@@ -80,11 +82,13 @@ class Watching {
80
82
  } else {
81
83
  for (const file of changedFiles) {
82
84
  this._collectedChangedFiles.add(file);
83
- this._collectedRemovedFiles.delete(file);
85
+ /** @type {Set<string>} */
86
+ (this._collectedRemovedFiles).delete(file);
84
87
  }
85
- for (const file of removedFiles) {
88
+ for (const file of /** @type {ReadonlySet<string>} */ (removedFiles)) {
86
89
  this._collectedChangedFiles.delete(file);
87
- this._collectedRemovedFiles.add(file);
90
+ /** @type {Set<string>} */
91
+ (this._collectedRemovedFiles).add(file);
88
92
  }
89
93
  }
90
94
  }
@@ -228,7 +232,7 @@ class Watching {
228
232
  }
229
233
 
230
234
  /**
231
- * @param {Error=} err an optional error
235
+ * @param {(Error | null)=} err an optional error
232
236
  * @param {Compilation=} compilation the compilation
233
237
  * @returns {void}
234
238
  */
@@ -237,13 +241,18 @@ class Watching {
237
241
 
238
242
  const logger = compilation && compilation.getLogger("webpack.Watching");
239
243
 
244
+ /** @type {Stats | null} */
240
245
  let stats = null;
241
246
 
247
+ /**
248
+ * @param {Error} err error
249
+ * @param {Callback<void>[]=} cbs callbacks
250
+ */
242
251
  const handleError = (err, cbs) => {
243
252
  this.compiler.hooks.failed.call(err);
244
253
  this.compiler.cache.beginIdle();
245
254
  this.compiler.idle = true;
246
- this.handler(err, stats);
255
+ this.handler(err, /** @type {Stats} */ (stats));
247
256
  if (!cbs) {
248
257
  cbs = this.callbacks;
249
258
  this.callbacks = [];
@@ -258,11 +267,13 @@ class Watching {
258
267
  !(this._isBlocked() && (this.blocked = true))
259
268
  ) {
260
269
  if (compilation) {
261
- logger.time("storeBuildDependencies");
270
+ /** @type {Logger} */
271
+ (logger).time("storeBuildDependencies");
262
272
  this.compiler.cache.storeBuildDependencies(
263
273
  compilation.buildDependencies,
264
274
  err => {
265
- logger.timeEnd("storeBuildDependencies");
275
+ /** @type {Logger} */
276
+ (logger).timeEnd("storeBuildDependencies");
266
277
  if (err) return handleError(err);
267
278
  this._go();
268
279
  }
@@ -283,32 +294,42 @@ class Watching {
283
294
 
284
295
  const cbs = this.callbacks;
285
296
  this.callbacks = [];
286
- logger.time("done hook");
287
- this.compiler.hooks.done.callAsync(stats, err => {
288
- logger.timeEnd("done hook");
297
+ /** @type {Logger} */
298
+ (logger).time("done hook");
299
+ this.compiler.hooks.done.callAsync(/** @type {Stats} */ (stats), err => {
300
+ /** @type {Logger} */
301
+ (logger).timeEnd("done hook");
289
302
  if (err) return handleError(err, cbs);
290
- this.handler(null, stats);
291
- logger.time("storeBuildDependencies");
303
+ this.handler(null, /** @type {Stats} */ (stats));
304
+ /** @type {Logger} */
305
+ (logger).time("storeBuildDependencies");
292
306
  this.compiler.cache.storeBuildDependencies(
293
- compilation.buildDependencies,
307
+ /** @type {Compilation} */
308
+ (compilation).buildDependencies,
294
309
  err => {
295
- logger.timeEnd("storeBuildDependencies");
310
+ /** @type {Logger} */
311
+ (logger).timeEnd("storeBuildDependencies");
296
312
  if (err) return handleError(err, cbs);
297
- logger.time("beginIdle");
313
+ /** @type {Logger} */
314
+ (logger).time("beginIdle");
298
315
  this.compiler.cache.beginIdle();
299
316
  this.compiler.idle = true;
300
- logger.timeEnd("beginIdle");
317
+ /** @type {Logger} */
318
+ (logger).timeEnd("beginIdle");
301
319
  process.nextTick(() => {
302
320
  if (!this.closed) {
303
321
  this.watch(
304
- compilation.fileDependencies,
305
- compilation.contextDependencies,
306
- compilation.missingDependencies
322
+ /** @type {Compilation} */
323
+ (compilation).fileDependencies,
324
+ /** @type {Compilation} */
325
+ (compilation).contextDependencies,
326
+ /** @type {Compilation} */
327
+ (compilation).missingDependencies
307
328
  );
308
329
  }
309
330
  });
310
331
  for (const cb of cbs) cb(null);
311
- this.compiler.hooks.afterDone.call(stats);
332
+ this.compiler.hooks.afterDone.call(/** @type {Stats} */ (stats));
312
333
  }
313
334
  );
314
335
  });
@@ -377,6 +398,13 @@ class Watching {
377
398
  this._invalidate();
378
399
  }
379
400
 
401
+ /**
402
+ * @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} fileTimeInfoEntries info for files
403
+ * @param {ReadonlyMap<string, FileSystemInfoEntry | "ignore">=} contextTimeInfoEntries info for directories
404
+ * @param {ReadonlySet<string>=} changedFiles changed files
405
+ * @param {ReadonlySet<string>=} removedFiles removed files
406
+ * @returns {void}
407
+ */
380
408
  _invalidate(
381
409
  fileTimeInfoEntries,
382
410
  contextTimeInfoEntries,
@@ -423,6 +451,10 @@ class Watching {
423
451
  }
424
452
  return;
425
453
  }
454
+ /**
455
+ * @param {(WebpackError | null)=} err error if any
456
+ * @param {Compilation=} compilation compilation if any
457
+ */
426
458
  const finalCallback = (err, compilation) => {
427
459
  this.running = false;
428
460
  this.compiler.running = false;
@@ -433,9 +465,14 @@ class Watching {
433
465
  this.compiler.fileTimestamps = undefined;
434
466
  this.compiler.contextTimestamps = undefined;
435
467
  this.compiler.fsStartTime = undefined;
468
+ /**
469
+ * @param {(WebpackError | null)=} err error if any
470
+ */
436
471
  const shutdown = err => {
437
472
  this.compiler.hooks.watchClose.call();
438
- const closeCallbacks = this._closeCallbacks;
473
+ const closeCallbacks =
474
+ /** @type {Callback<void>[]} */
475
+ (this._closeCallbacks);
439
476
  this._closeCallbacks = undefined;
440
477
  for (const cb of closeCallbacks) cb(err);
441
478
  };
@@ -22,16 +22,17 @@ class WebpackError extends Error {
22
22
  constructor(message) {
23
23
  super(message);
24
24
 
25
+ /** @type {string | undefined} */
25
26
  this.details = undefined;
26
- /** @type {Module} */
27
+ /** @type {Module | undefined | null} */
27
28
  this.module = undefined;
28
- /** @type {DependencyLocation} */
29
+ /** @type {DependencyLocation | undefined} */
29
30
  this.loc = undefined;
30
- /** @type {boolean} */
31
+ /** @type {boolean | undefined} */
31
32
  this.hideStack = undefined;
32
- /** @type {Chunk} */
33
+ /** @type {Chunk | undefined} */
33
34
  this.chunk = undefined;
34
- /** @type {string} */
35
+ /** @type {string | undefined} */
35
36
  this.file = undefined;
36
37
  }
37
38
 
@@ -16,10 +16,12 @@ const {
16
16
  toConstantDependency
17
17
  } = require("./javascript/JavascriptParserHelpers");
18
18
 
19
- /** @typedef {import("enhanced-resolve/lib/Resolver")} Resolver */
19
+ /** @typedef {import("enhanced-resolve").Resolver} Resolver */
20
20
  /** @typedef {import("./Compiler")} Compiler */
21
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
21
22
  /** @typedef {import("./Module")} Module */
22
23
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
24
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
23
25
 
24
26
  const PLUGIN_NAME = "WebpackIsIncludedPlugin";
25
27
 
@@ -61,10 +63,10 @@ class WebpackIsIncludedPlugin {
61
63
  if (!request.isString()) return;
62
64
 
63
65
  const dep = new WebpackIsIncludedDependency(
64
- request.string,
65
- expr.range
66
+ /** @type {string} */ (request.string),
67
+ /** @type {Range} */ (expr.range)
66
68
  );
67
- dep.loc = expr.loc;
69
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
68
70
  parser.state.module.addDependency(dep);
69
71
  return true;
70
72
  });
@@ -368,7 +368,9 @@ class WebpackOptionsApply extends OptionsApply {
368
368
  const NodeStuffPlugin = require("./NodeStuffPlugin");
369
369
  new NodeStuffPlugin(options.node).apply(compiler);
370
370
  }
371
- new APIPlugin().apply(compiler);
371
+ new APIPlugin({
372
+ module: options.output.module
373
+ }).apply(compiler);
372
374
  new ExportsInfoApiPlugin().apply(compiler);
373
375
  new WebpackIsIncludedPlugin().apply(compiler);
374
376
  new ConstPlugin().apply(compiler);
@@ -564,7 +566,7 @@ class WebpackOptionsApply extends OptionsApply {
564
566
  for (const minimizer of options.optimization.minimizer) {
565
567
  if (typeof minimizer === "function") {
566
568
  minimizer.call(compiler, compiler);
567
- } else if (minimizer !== "...") {
569
+ } else if (minimizer !== "..." && minimizer) {
568
570
  minimizer.apply(compiler);
569
571
  }
570
572
  }
@@ -8,11 +8,18 @@
8
8
  const { applyWebpackOptionsDefaults } = require("./config/defaults");
9
9
  const { getNormalizedWebpackOptions } = require("./config/normalization");
10
10
 
11
+ /** @typedef {import("./config/normalization").WebpackOptions} WebpackOptions */
12
+ /** @typedef {import("./config/normalization").WebpackOptionsNormalized} WebpackOptionsNormalized */
13
+
11
14
  class WebpackOptionsDefaulter {
15
+ /**
16
+ * @param {WebpackOptions} options webpack options
17
+ * @returns {WebpackOptionsNormalized} normalized webpack options
18
+ */
12
19
  process(options) {
13
- options = getNormalizedWebpackOptions(options);
14
- applyWebpackOptionsDefaults(options);
15
- return options;
20
+ const normalizedOptions = getNormalizedWebpackOptions(options);
21
+ applyWebpackOptionsDefaults(normalizedOptions);
22
+ return normalizedOptions;
16
23
  }
17
24
  }
18
25
 
@@ -181,6 +181,7 @@ class AssetGenerator extends Generator {
181
181
  );
182
182
  }
183
183
 
184
+ /** @type {string | boolean | undefined} */
184
185
  let mimeType = this.dataUrlOptions.mimetype;
185
186
  if (mimeType === undefined) {
186
187
  const ext = path.extname(module.nameForCondition());
@@ -213,7 +214,7 @@ class AssetGenerator extends Generator {
213
214
  );
214
215
  }
215
216
 
216
- return mimeType;
217
+ return /** @type {string} */ (mimeType);
217
218
  }
218
219
 
219
220
  /**
@@ -9,6 +9,8 @@ const Parser = require("../Parser");
9
9
 
10
10
  /** @typedef {import("../../declarations/WebpackOptions").AssetParserDataUrlOptions} AssetParserDataUrlOptions */
11
11
  /** @typedef {import("../../declarations/WebpackOptions").AssetParserOptions} AssetParserOptions */
12
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
13
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
12
14
  /** @typedef {import("../Parser").ParserState} ParserState */
13
15
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
14
16
 
@@ -30,22 +32,25 @@ class AssetParser extends Parser {
30
32
  if (typeof source === "object" && !Buffer.isBuffer(source)) {
31
33
  throw new Error("AssetParser doesn't accept preparsed AST");
32
34
  }
33
- state.module.buildInfo.strict = true;
34
- state.module.buildMeta.exportsType = "default";
35
- state.module.buildMeta.defaultObject = false;
35
+
36
+ const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
37
+ buildInfo.strict = true;
38
+ const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
39
+ buildMeta.exportsType = "default";
40
+ buildMeta.defaultObject = false;
36
41
 
37
42
  if (typeof this.dataUrlCondition === "function") {
38
- state.module.buildInfo.dataUrl = this.dataUrlCondition(source, {
43
+ buildInfo.dataUrl = this.dataUrlCondition(source, {
39
44
  filename: state.module.matchResource || state.module.resource,
40
45
  module: state.module
41
46
  });
42
47
  } else if (typeof this.dataUrlCondition === "boolean") {
43
- state.module.buildInfo.dataUrl = this.dataUrlCondition;
48
+ buildInfo.dataUrl = this.dataUrlCondition;
44
49
  } else if (
45
50
  this.dataUrlCondition &&
46
51
  typeof this.dataUrlCondition === "object"
47
52
  ) {
48
- state.module.buildInfo.dataUrl =
53
+ buildInfo.dataUrl =
49
54
  Buffer.byteLength(source) <=
50
55
  /** @type {NonNullable<AssetParserDataUrlOptions["maxSize"]>} */
51
56
  (this.dataUrlCondition.maxSize);
@@ -7,6 +7,8 @@
7
7
 
8
8
  const Parser = require("../Parser");
9
9
 
10
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
11
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
10
12
  /** @typedef {import("../Parser").ParserState} ParserState */
11
13
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
12
14
 
@@ -21,9 +23,12 @@ class AssetSourceParser extends Parser {
21
23
  throw new Error("AssetSourceParser doesn't accept preparsed AST");
22
24
  }
23
25
  const { module } = state;
24
- module.buildInfo.strict = true;
25
- module.buildMeta.exportsType = "default";
26
- state.module.buildMeta.defaultObject = false;
26
+ /** @type {BuildInfo} */
27
+ (module.buildInfo).strict = true;
28
+ /** @type {BuildMeta} */
29
+ (module.buildMeta).exportsType = "default";
30
+ /** @type {BuildMeta} */
31
+ (state.module.buildMeta).defaultObject = false;
27
32
 
28
33
  return state;
29
34
  }
@@ -29,6 +29,10 @@ class AwaitDependenciesInitFragment extends InitFragment {
29
29
  this.promises = promises;
30
30
  }
31
31
 
32
+ /**
33
+ * @param {AwaitDependenciesInitFragment} other other AwaitDependenciesInitFragment
34
+ * @returns {AwaitDependenciesInitFragment} AwaitDependenciesInitFragment
35
+ */
32
36
  merge(other) {
33
37
  const promises = new Set(other.promises);
34
38
  for (const p of this.promises) {
@@ -16,6 +16,7 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
16
16
  /** @typedef {import("./Compilation")} Compilation */
17
17
  /** @typedef {import("./DependenciesBlock")} DependenciesBlock */
18
18
  /** @typedef {import("./Dependency")} Dependency */
19
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
19
20
  /** @typedef {import("./Entrypoint")} Entrypoint */
20
21
  /** @typedef {import("./Module")} Module */
21
22
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
@@ -39,15 +40,15 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
39
40
  * @typedef {Object} ChunkGroupInfo
40
41
  * @property {ChunkGroup} chunkGroup the chunk group
41
42
  * @property {RuntimeSpec} runtime the runtimes
42
- * @property {ModuleSetPlus} minAvailableModules current minimal set of modules available at this point
43
- * @property {boolean} minAvailableModulesOwned true, if minAvailableModules is owned and can be modified
43
+ * @property {ModuleSetPlus | undefined} minAvailableModules current minimal set of modules available at this point
44
+ * @property {boolean | undefined} minAvailableModulesOwned true, if minAvailableModules is owned and can be modified
44
45
  * @property {ModuleSetPlus[]} availableModulesToBeMerged enqueued updates to the minimal set of available modules
45
46
  * @property {Set<Module>=} skippedItems modules that were skipped because module is already available in parent chunks (need to reconsider when minAvailableModules is shrinking)
46
47
  * @property {Set<[Module, ConnectionState]>=} skippedModuleConnections referenced modules that where skipped because they were not active in this runtime
47
- * @property {ModuleSetPlus} resultingAvailableModules set of modules available including modules from this chunk group
48
- * @property {Set<ChunkGroupInfo>} children set of children chunk groups, that will be revisited when availableModules shrink
49
- * @property {Set<ChunkGroupInfo>} availableSources set of chunk groups that are the source for minAvailableModules
50
- * @property {Set<ChunkGroupInfo>} availableChildren set of chunk groups which depend on the this chunk group as availableSource
48
+ * @property {ModuleSetPlus | undefined} resultingAvailableModules set of modules available including modules from this chunk group
49
+ * @property {Set<ChunkGroupInfo> | undefined} children set of children chunk groups, that will be revisited when availableModules shrink
50
+ * @property {Set<ChunkGroupInfo> | undefined} availableSources set of chunk groups that are the source for minAvailableModules
51
+ * @property {Set<ChunkGroupInfo> | undefined} availableChildren set of chunk groups which depend on the this chunk group as availableSource
51
52
  * @property {number} preOrderIndex next pre order index
52
53
  * @property {number} postOrderIndex next post order index
53
54
  * @property {boolean} chunkLoading has a chunk loading mechanism
@@ -199,6 +200,7 @@ const visitModules = (
199
200
 
200
201
  /** @type {RuntimeSpec | false} */
201
202
  let blockModulesMapRuntime = false;
203
+ /** @type {Map<DependenciesBlock, (Module | ConnectionState)[]>} */
202
204
  let blockModulesMap;
203
205
 
204
206
  /**
@@ -239,7 +241,7 @@ const visitModules = (
239
241
  extractBlockModules(module, moduleGraph, runtime, blockModulesMap);
240
242
  blockModules = blockModulesMap.get(block);
241
243
  logger.timeAggregate("visitModules: prepare");
242
- return blockModules;
244
+ return /** @type {(Module | ConnectionState)[]} */ (blockModules);
243
245
  }
244
246
  };
245
247
 
@@ -290,7 +292,7 @@ const visitModules = (
290
292
  for (const [chunkGroup, modules] of inputEntrypointsAndModules) {
291
293
  const runtime = getEntryRuntime(
292
294
  compilation,
293
- chunkGroup.name,
295
+ /** @type {string} */ (chunkGroup.name),
294
296
  chunkGroup.options
295
297
  );
296
298
  /** @type {ChunkGroupInfo} */
@@ -352,7 +354,9 @@ const visitModules = (
352
354
  const { chunkGroup } = chunkGroupInfo;
353
355
  chunkGroupInfo.availableSources = new Set();
354
356
  for (const parent of chunkGroup.parentsIterable) {
355
- const parentChunkGroupInfo = chunkGroupInfoMap.get(parent);
357
+ const parentChunkGroupInfo =
358
+ /** @type {ChunkGroupInfo} */
359
+ (chunkGroupInfoMap.get(parent));
356
360
  chunkGroupInfo.availableSources.add(parentChunkGroupInfo);
357
361
  if (parentChunkGroupInfo.availableChildren === undefined) {
358
362
  parentChunkGroupInfo.availableChildren = new Set();
@@ -399,15 +403,15 @@ const visitModules = (
399
403
  // 1. We create a chunk group with single chunk in it for this Block
400
404
  // but only once (blockChunkGroups map)
401
405
  let cgi = blockChunkGroups.get(b);
402
- /** @type {ChunkGroup} */
406
+ /** @type {ChunkGroup | undefined} */
403
407
  let c;
404
- /** @type {Entrypoint} */
408
+ /** @type {Entrypoint | undefined} */
405
409
  let entrypoint;
406
410
  const entryOptions = b.groupOptions && b.groupOptions.entryOptions;
407
411
  if (cgi === undefined) {
408
412
  const chunkName = (b.groupOptions && b.groupOptions.name) || b.chunkName;
409
413
  if (entryOptions) {
410
- cgi = namedAsyncEntrypoints.get(chunkName);
414
+ cgi = namedAsyncEntrypoints.get(/** @type {string} */ (chunkName));
411
415
  if (!cgi) {
412
416
  entrypoint = compilation.addAsyncEntrypoint(
413
417
  entryOptions,
@@ -505,7 +509,11 @@ const visitModules = (
505
509
  c = cgi.chunkGroup;
506
510
  if (c.isInitial()) {
507
511
  compilation.errors.push(
508
- new AsyncDependencyToInitialChunkError(chunkName, module, b.loc)
512
+ new AsyncDependencyToInitialChunkError(
513
+ /** @type {string} */ (chunkName),
514
+ module,
515
+ b.loc
516
+ )
509
517
  );
510
518
  c = chunkGroup;
511
519
  } else {
@@ -515,7 +523,7 @@ const visitModules = (
515
523
  }
516
524
  blockConnections.set(b, []);
517
525
  }
518
- blockChunkGroups.set(b, cgi);
526
+ blockChunkGroups.set(b, /** @type {ChunkGroupInfo} */ (cgi));
519
527
  } else if (entryOptions) {
520
528
  entrypoint = /** @type {Entrypoint} */ (cgi.chunkGroup);
521
529
  } else {
@@ -536,7 +544,7 @@ const visitModules = (
536
544
  connectList = new Set();
537
545
  queueConnect.set(chunkGroupInfo, connectList);
538
546
  }
539
- connectList.add(cgi);
547
+ connectList.add(/** @type {ChunkGroupInfo} */ (cgi));
540
548
 
541
549
  // TODO check if this really need to be done for each traversal
542
550
  // or if it is enough when it's queued when created
@@ -547,7 +555,7 @@ const visitModules = (
547
555
  module: module,
548
556
  chunk: c.chunks[0],
549
557
  chunkGroup: c,
550
- chunkGroupInfo: cgi
558
+ chunkGroupInfo: /** @type {ChunkGroupInfo} */ (cgi)
551
559
  });
552
560
  } else if (entrypoint !== undefined) {
553
561
  chunkGroupInfo.chunkGroup.addAsyncEntrypoint(entrypoint);
@@ -690,7 +698,7 @@ const visitModules = (
690
698
  const processQueue = () => {
691
699
  while (queue.length) {
692
700
  statProcessedQueueItems++;
693
- const queueItem = queue.pop();
701
+ const queueItem = /** @type {QueueItem} */ (queue.pop());
694
702
  module = queueItem.module;
695
703
  block = queueItem.block;
696
704
  chunk = queueItem.chunk;
@@ -1087,7 +1095,9 @@ const visitModules = (
1087
1095
 
1088
1096
  const processChunkGroupsForCombining = () => {
1089
1097
  for (const info of chunkGroupsForCombining) {
1090
- for (const source of info.availableSources) {
1098
+ for (const source of /** @type {Set<ChunkGroupInfo>} */ (
1099
+ info.availableSources
1100
+ )) {
1091
1101
  if (!source.minAvailableModules) {
1092
1102
  chunkGroupsForCombining.delete(info);
1093
1103
  break;
@@ -1106,7 +1116,9 @@ const visitModules = (
1106
1116
  }
1107
1117
  };
1108
1118
  // combine minAvailableModules from all resultingAvailableModules
1109
- for (const source of info.availableSources) {
1119
+ for (const source of /** @type {Set<ChunkGroupInfo>} */ (
1120
+ info.availableSources
1121
+ )) {
1110
1122
  const resultingAvailableModules =
1111
1123
  calculateResultingAvailableModules(source);
1112
1124
  mergeSet(resultingAvailableModules);
@@ -1126,7 +1138,9 @@ const visitModules = (
1126
1138
  for (const info of outdatedChunkGroupInfo) {
1127
1139
  // 1. Reconsider skipped items
1128
1140
  if (info.skippedItems !== undefined) {
1129
- const { minAvailableModules } = info;
1141
+ const minAvailableModules =
1142
+ /** @type {ModuleSetPlus} */
1143
+ (info.minAvailableModules);
1130
1144
  for (const module of info.skippedItems) {
1131
1145
  if (
1132
1146
  !minAvailableModules.has(module) &&
@@ -1147,7 +1161,9 @@ const visitModules = (
1147
1161
 
1148
1162
  // 2. Reconsider skipped connections
1149
1163
  if (info.skippedModuleConnections !== undefined) {
1150
- const { minAvailableModules } = info;
1164
+ const minAvailableModules =
1165
+ /** @type {ModuleSetPlus} */
1166
+ (info.minAvailableModules);
1151
1167
  for (const entry of info.skippedModuleConnections) {
1152
1168
  const [module, activeState] = entry;
1153
1169
  if (activeState === false) continue;
@@ -50,7 +50,7 @@ class IdleFileCachePlugin {
50
50
  let timeSpendInStore = 0;
51
51
  let avgTimeSpendInStore = 0;
52
52
 
53
- /** @type {Map<string | typeof BUILD_DEPENDENCIES_KEY, () => Promise>} */
53
+ /** @type {Map<string | typeof BUILD_DEPENDENCIES_KEY, () => Promise<void>>} */
54
54
  const pendingIdleTasks = new Map();
55
55
 
56
56
  compiler.cache.hooks.store.tap(
@@ -171,6 +171,7 @@ class IdleFileCachePlugin {
171
171
  isInitialStore = false;
172
172
  }
173
173
  };
174
+ /** @type {ReturnType<typeof setTimeout> | undefined} */
174
175
  let idleTimer = undefined;
175
176
  compiler.cache.hooks.beginIdle.tap(
176
177
  { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },