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/lib/Compiler.js CHANGED
@@ -40,21 +40,33 @@ const { isSourceEqual } = require("./util/source");
40
40
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
41
41
  /** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
42
42
  /** @typedef {import("./Chunk")} Chunk */
43
+ /** @typedef {import("./Compilation").References} References */
43
44
  /** @typedef {import("./Dependency")} Dependency */
44
45
  /** @typedef {import("./FileSystemInfo").FileSystemInfoEntry} FileSystemInfoEntry */
45
46
  /** @typedef {import("./Module")} Module */
47
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
48
+ /** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */
49
+ /** @typedef {import("./logging/createConsoleLogger").LoggingFunction} LoggingFunction */
46
50
  /** @typedef {import("./util/WeakTupleMap")} WeakTupleMap */
51
+ /** @typedef {import("./util/fs").IStats} IStats */
47
52
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
48
53
  /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
49
54
  /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
50
55
  /** @typedef {import("./util/fs").WatchFileSystem} WatchFileSystem */
51
56
 
52
57
  /**
53
- * @typedef {Object} CompilationParams
58
+ * @typedef {object} CompilationParams
54
59
  * @property {NormalModuleFactory} normalModuleFactory
55
60
  * @property {ContextModuleFactory} contextModuleFactory
56
61
  */
57
62
 
63
+ /**
64
+ * @template T
65
+ * @callback RunCallback
66
+ * @param {Error | null} err
67
+ * @param {T=} result
68
+ */
69
+
58
70
  /**
59
71
  * @template T
60
72
  * @callback Callback
@@ -64,13 +76,13 @@ const { isSourceEqual } = require("./util/source");
64
76
 
65
77
  /**
66
78
  * @callback RunAsChildCallback
67
- * @param {(Error | null)=} err
79
+ * @param {Error | null} err
68
80
  * @param {Chunk[]=} entries
69
81
  * @param {Compilation=} compilation
70
82
  */
71
83
 
72
84
  /**
73
- * @typedef {Object} AssetEmittedInfo
85
+ * @typedef {object} AssetEmittedInfo
74
86
  * @property {Buffer} content
75
87
  * @property {Source} source
76
88
  * @property {Compilation} compilation
@@ -78,6 +90,9 @@ const { isSourceEqual } = require("./util/source");
78
90
  * @property {string} targetPath
79
91
  */
80
92
 
93
+ /** @typedef {{ sizeOnlySource: SizeOnlySource | undefined, writtenTo: Map<string, number> }} CacheEntry */
94
+ /** @typedef {{ path: string, source: Source, size: number | undefined, waiting: ({ cacheEntry: any, file: string }[] | undefined) }} SimilarEntry */
95
+
81
96
  /**
82
97
  * @param {string[]} array an array
83
98
  * @returns {boolean} true, if the array is sorted
@@ -90,11 +105,12 @@ const isSorted = array => {
90
105
  };
91
106
 
92
107
  /**
93
- * @param {Object} obj an object
108
+ * @param {{[key: string]: any}} obj an object
94
109
  * @param {string[]} keys the keys of the object
95
- * @returns {Object} the object with properties sorted by property name
110
+ * @returns {{[key: string]: any}} the object with properties sorted by property name
96
111
  */
97
112
  const sortObject = (obj, keys) => {
113
+ /** @type {{[key: string]: any}} */
98
114
  const o = {};
99
115
  for (const k of keys.sort()) {
100
116
  o[k] = obj[k];
@@ -200,9 +216,9 @@ class Compiler {
200
216
 
201
217
  this.webpack = webpack;
202
218
 
203
- /** @type {string=} */
219
+ /** @type {string | undefined} */
204
220
  this.name = undefined;
205
- /** @type {Compilation=} */
221
+ /** @type {Compilation | undefined} */
206
222
  this.parentCompilation = undefined;
207
223
  /** @type {Compiler} */
208
224
  this.root = this;
@@ -211,19 +227,20 @@ class Compiler {
211
227
  /** @type {Watching | undefined} */
212
228
  this.watching = undefined;
213
229
 
214
- /** @type {OutputFileSystem} */
230
+ /** @type {OutputFileSystem | null} */
215
231
  this.outputFileSystem = null;
216
- /** @type {IntermediateFileSystem} */
232
+ /** @type {IntermediateFileSystem | null} */
217
233
  this.intermediateFileSystem = null;
218
- /** @type {InputFileSystem} */
234
+ /** @type {InputFileSystem | null} */
219
235
  this.inputFileSystem = null;
220
- /** @type {WatchFileSystem} */
236
+ /** @type {WatchFileSystem | null} */
221
237
  this.watchFileSystem = null;
222
238
 
223
239
  /** @type {string|null} */
224
240
  this.recordsInputPath = null;
225
241
  /** @type {string|null} */
226
242
  this.recordsOutputPath = null;
243
+ /** @type {Record<string, TODO>} */
227
244
  this.records = {};
228
245
  /** @type {Set<string | RegExp>} */
229
246
  this.managedPaths = new Set();
@@ -246,8 +263,19 @@ class Compiler {
246
263
  /** @type {ResolverFactory} */
247
264
  this.resolverFactory = new ResolverFactory();
248
265
 
266
+ /** @type {LoggingFunction | undefined} */
249
267
  this.infrastructureLogger = undefined;
250
268
 
269
+ /** @type {Readonly<PlatformTargetProperties>} */
270
+ this.platform = {
271
+ web: null,
272
+ browser: null,
273
+ webworker: null,
274
+ node: null,
275
+ nwjs: null,
276
+ electron: null
277
+ };
278
+
251
279
  this.options = options;
252
280
 
253
281
  this.context = context;
@@ -256,7 +284,7 @@ class Compiler {
256
284
 
257
285
  this.cache = new Cache();
258
286
 
259
- /** @type {Map<Module, { buildInfo: object, references: WeakMap<Dependency, Module>, memCache: WeakTupleMap }> | undefined} */
287
+ /** @type {Map<Module, { buildInfo: BuildInfo, references: References | undefined, memCache: WeakTupleMap }> | undefined} */
260
288
  this.moduleMemCaches = undefined;
261
289
 
262
290
  this.compilerPath = "";
@@ -272,16 +300,25 @@ class Compiler {
272
300
 
273
301
  this._backCompat = this.options.experiments.backCompat !== false;
274
302
 
275
- /** @type {Compilation} */
303
+ /** @type {Compilation | undefined} */
276
304
  this._lastCompilation = undefined;
277
- /** @type {NormalModuleFactory} */
305
+ /** @type {NormalModuleFactory | undefined} */
278
306
  this._lastNormalModuleFactory = undefined;
279
307
 
280
- /** @private @type {WeakMap<Source, { sizeOnlySource: SizeOnlySource, writtenTo: Map<string, number> }>} */
308
+ /**
309
+ * @private
310
+ * @type {WeakMap<Source, CacheEntry>}
311
+ */
281
312
  this._assetEmittingSourceCache = new WeakMap();
282
- /** @private @type {Map<string, number>} */
313
+ /**
314
+ * @private
315
+ * @type {Map<string, number>}
316
+ */
283
317
  this._assetEmittingWrittenFiles = new Map();
284
- /** @private @type {Set<string>} */
318
+ /**
319
+ * @private
320
+ * @type {Set<string>}
321
+ */
285
322
  this._assetEmittingPreviousFiles = new Set();
286
323
  }
287
324
 
@@ -416,7 +453,7 @@ class Compiler {
416
453
 
417
454
  /**
418
455
  * @param {WatchOptions} watchOptions the watcher's options
419
- * @param {Callback<Stats>} handler signals when the call finishes
456
+ * @param {RunCallback<Stats>} handler signals when the call finishes
420
457
  * @returns {Watching} a compiler watcher
421
458
  */
422
459
  watch(watchOptions, handler) {
@@ -431,7 +468,7 @@ class Compiler {
431
468
  }
432
469
 
433
470
  /**
434
- * @param {Callback<Stats>} callback signals when the call finishes
471
+ * @param {RunCallback<Stats>} callback signals when the call finishes
435
472
  * @returns {void}
436
473
  */
437
474
  run(callback) {
@@ -439,8 +476,13 @@ class Compiler {
439
476
  return callback(new ConcurrentCompilationError());
440
477
  }
441
478
 
479
+ /** @type {Logger | undefined} */
442
480
  let logger;
443
481
 
482
+ /**
483
+ * @param {Error | null} err error
484
+ * @param {Stats=} stats stats
485
+ */
444
486
  const finalCallback = (err, stats) => {
445
487
  if (logger) logger.time("beginIdle");
446
488
  this.idle = true;
@@ -452,16 +494,23 @@ class Compiler {
452
494
  this.hooks.failed.call(err);
453
495
  }
454
496
  if (callback !== undefined) callback(err, stats);
455
- this.hooks.afterDone.call(stats);
497
+ this.hooks.afterDone.call(/** @type {Stats} */ (stats));
456
498
  };
457
499
 
458
500
  const startTime = Date.now();
459
501
 
460
502
  this.running = true;
461
503
 
462
- const onCompiled = (err, compilation) => {
504
+ /**
505
+ * @param {Error | null} err error
506
+ * @param {Compilation=} _compilation compilation
507
+ * @returns {void}
508
+ */
509
+ const onCompiled = (err, _compilation) => {
463
510
  if (err) return finalCallback(err);
464
511
 
512
+ const compilation = /** @type {Compilation} */ (_compilation);
513
+
465
514
  if (this.hooks.shouldEmit.call(compilation) === false) {
466
515
  compilation.startTime = startTime;
467
516
  compilation.endTime = Date.now();
@@ -477,7 +526,8 @@ class Compiler {
477
526
  logger = compilation.getLogger("webpack.Compiler");
478
527
  logger.time("emitAssets");
479
528
  this.emitAssets(compilation, err => {
480
- logger.timeEnd("emitAssets");
529
+ /** @type {Logger} */
530
+ (logger).timeEnd("emitAssets");
481
531
  if (err) return finalCallback(err);
482
532
 
483
533
  if (compilation.hooks.needAdditionalPass.call()) {
@@ -485,10 +535,12 @@ class Compiler {
485
535
 
486
536
  compilation.startTime = startTime;
487
537
  compilation.endTime = Date.now();
488
- logger.time("done hook");
538
+ /** @type {Logger} */
539
+ (logger).time("done hook");
489
540
  const stats = new Stats(compilation);
490
541
  this.hooks.done.callAsync(stats, err => {
491
- logger.timeEnd("done hook");
542
+ /** @type {Logger} */
543
+ (logger).timeEnd("done hook");
492
544
  if (err) return finalCallback(err);
493
545
 
494
546
  this.hooks.additionalPass.callAsync(err => {
@@ -499,17 +551,21 @@ class Compiler {
499
551
  return;
500
552
  }
501
553
 
502
- logger.time("emitRecords");
554
+ /** @type {Logger} */
555
+ (logger).time("emitRecords");
503
556
  this.emitRecords(err => {
504
- logger.timeEnd("emitRecords");
557
+ /** @type {Logger} */
558
+ (logger).timeEnd("emitRecords");
505
559
  if (err) return finalCallback(err);
506
560
 
507
561
  compilation.startTime = startTime;
508
562
  compilation.endTime = Date.now();
509
- logger.time("done hook");
563
+ /** @type {Logger} */
564
+ (logger).time("done hook");
510
565
  const stats = new Stats(compilation);
511
566
  this.hooks.done.callAsync(stats, err => {
512
- logger.timeEnd("done hook");
567
+ /** @type {Logger} */
568
+ (logger).timeEnd("done hook");
513
569
  if (err) return finalCallback(err);
514
570
  this.cache.storeBuildDependencies(
515
571
  compilation.buildDependencies,
@@ -559,6 +615,11 @@ class Compiler {
559
615
  runAsChild(callback) {
560
616
  const startTime = Date.now();
561
617
 
618
+ /**
619
+ * @param {Error | null} err error
620
+ * @param {Chunk[]=} entries entries
621
+ * @param {Compilation=} compilation compilation
622
+ */
562
623
  const finalCallback = (err, entries, compilation) => {
563
624
  try {
564
625
  callback(err, entries, compilation);
@@ -566,20 +627,29 @@ class Compiler {
566
627
  const err = new WebpackError(
567
628
  `compiler.runAsChild callback error: ${e}`
568
629
  );
569
- err.details = e.stack;
570
- this.parentCompilation.errors.push(err);
630
+ err.details = /** @type {Error} */ (e).stack;
631
+ /** @type {Compilation} */
632
+ (this.parentCompilation).errors.push(err);
571
633
  }
572
634
  };
573
635
 
574
- this.compile((err, compilation) => {
636
+ this.compile((err, _compilation) => {
575
637
  if (err) return finalCallback(err);
576
638
 
577
- this.parentCompilation.children.push(compilation);
639
+ const compilation = /** @type {Compilation} */ (_compilation);
640
+ const parentCompilation = /** @type {Compilation} */ (
641
+ this.parentCompilation
642
+ );
643
+
644
+ parentCompilation.children.push(compilation);
645
+
578
646
  for (const { name, source, info } of compilation.getAssets()) {
579
- this.parentCompilation.emitAsset(name, source, info);
647
+ parentCompilation.emitAsset(name, source, info);
580
648
  }
581
649
 
650
+ /** @type {Chunk[]} */
582
651
  const entries = [];
652
+
583
653
  for (const ep of compilation.entrypoints.values()) {
584
654
  entries.push(...ep.chunks);
585
655
  }
@@ -603,14 +673,19 @@ class Compiler {
603
673
  * @returns {void}
604
674
  */
605
675
  emitAssets(compilation, callback) {
676
+ /** @type {string} */
606
677
  let outputPath;
607
678
 
679
+ /**
680
+ * @param {Error=} err error
681
+ * @returns {void}
682
+ */
608
683
  const emitFiles = err => {
609
684
  if (err) return callback(err);
610
685
 
611
686
  const assets = compilation.getAssets();
612
687
  compilation.assets = { ...compilation.assets };
613
- /** @type {Map<string, { path: string, source: Source, size: number, waiting: { cacheEntry: any, file: string }[] }>} */
688
+ /** @type {Map<string, SimilarEntry>} */
614
689
  const caseInsensitiveMap = new Map();
615
690
  /** @type {Set<string>} */
616
691
  const allTargetPaths = new Set();
@@ -634,10 +709,15 @@ class Compiler {
634
709
  includesHash(targetFile, info.fullhash));
635
710
  }
636
711
 
712
+ /**
713
+ * @param {Error=} err error
714
+ * @returns {void}
715
+ */
637
716
  const writeOut = err => {
638
717
  if (err) return callback(err);
639
718
  const targetPath = join(
640
- this.outputFileSystem,
719
+ /** @type {OutputFileSystem} */
720
+ (this.outputFileSystem),
641
721
  outputPath,
642
722
  targetFile
643
723
  );
@@ -657,6 +737,7 @@ class Compiler {
657
737
  this._assetEmittingSourceCache.set(source, cacheEntry);
658
738
  }
659
739
 
740
+ /** @type {SimilarEntry | undefined} */
660
741
  let similarEntry;
661
742
 
662
743
  const checkSimilarFile = () => {
@@ -687,12 +768,12 @@ ${other}`);
687
768
  } else {
688
769
  caseInsensitiveMap.set(
689
770
  caseInsensitiveTargetPath,
690
- (similarEntry = {
771
+ (similarEntry = /** @type {SimilarEntry} */ ({
691
772
  path: targetPath,
692
773
  source,
693
774
  size: undefined,
694
775
  waiting: undefined
695
- })
776
+ }))
696
777
  );
697
778
  return false;
698
779
  }
@@ -720,9 +801,11 @@ ${other}`);
720
801
  if (targetFileGeneration === undefined) {
721
802
  const newGeneration = 1;
722
803
  this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
723
- cacheEntry.writtenTo.set(targetPath, newGeneration);
804
+ /** @type {CacheEntry} */
805
+ (cacheEntry).writtenTo.set(targetPath, newGeneration);
724
806
  } else {
725
- cacheEntry.writtenTo.set(targetPath, targetFileGeneration);
807
+ /** @type {CacheEntry} */
808
+ (cacheEntry).writtenTo.set(targetPath, targetFileGeneration);
726
809
  }
727
810
  callback();
728
811
  };
@@ -733,7 +816,8 @@ ${other}`);
733
816
  * @returns {void}
734
817
  */
735
818
  const doWrite = content => {
736
- this.outputFileSystem.writeFile(targetPath, content, err => {
819
+ /** @type {OutputFileSystem} */
820
+ (this.outputFileSystem).writeFile(targetPath, content, err => {
737
821
  if (err) return callback(err);
738
822
 
739
823
  // information marker that the asset has been emitted
@@ -744,7 +828,8 @@ ${other}`);
744
828
  targetFileGeneration === undefined
745
829
  ? 1
746
830
  : targetFileGeneration + 1;
747
- cacheEntry.writtenTo.set(targetPath, newGeneration);
831
+ /** @type {CacheEntry} */
832
+ (cacheEntry).writtenTo.set(targetPath, newGeneration);
748
833
  this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
749
834
  this.hooks.assetEmitted.callAsync(
750
835
  file,
@@ -760,16 +845,33 @@ ${other}`);
760
845
  });
761
846
  };
762
847
 
848
+ /**
849
+ * @param {number} size size
850
+ */
763
851
  const updateWithReplacementSource = size => {
764
- updateFileWithReplacementSource(file, cacheEntry, size);
765
- similarEntry.size = size;
766
- if (similarEntry.waiting !== undefined) {
767
- for (const { file, cacheEntry } of similarEntry.waiting) {
852
+ updateFileWithReplacementSource(
853
+ file,
854
+ /** @type {CacheEntry} */ (cacheEntry),
855
+ size
856
+ );
857
+ /** @type {SimilarEntry} */
858
+ (similarEntry).size = size;
859
+ if (
860
+ /** @type {SimilarEntry} */ (similarEntry).waiting !== undefined
861
+ ) {
862
+ for (const { file, cacheEntry } of /** @type {SimilarEntry} */ (
863
+ similarEntry
864
+ ).waiting) {
768
865
  updateFileWithReplacementSource(file, cacheEntry, size);
769
866
  }
770
867
  }
771
868
  };
772
869
 
870
+ /**
871
+ * @param {string} file file
872
+ * @param {CacheEntry} cacheEntry cache entry
873
+ * @param {number} size size
874
+ */
773
875
  const updateFileWithReplacementSource = (
774
876
  file,
775
877
  cacheEntry,
@@ -786,10 +888,14 @@ ${other}`);
786
888
  });
787
889
  };
788
890
 
891
+ /**
892
+ * @param {IStats} stats stats
893
+ * @returns {void}
894
+ */
789
895
  const processExistingFile = stats => {
790
896
  // skip emitting if it's already there and an immutable file
791
897
  if (immutable) {
792
- updateWithReplacementSource(stats.size);
898
+ updateWithReplacementSource(/** @type {number} */ (stats.size));
793
899
  return alreadyWritten();
794
900
  }
795
901
 
@@ -803,19 +909,18 @@ ${other}`);
803
909
  // for a fast negative match file size is compared first
804
910
  if (content.length === stats.size) {
805
911
  compilation.comparedForEmitAssets.add(file);
806
- return this.outputFileSystem.readFile(
807
- targetPath,
808
- (err, existingContent) => {
809
- if (
810
- err ||
811
- !content.equals(/** @type {Buffer} */ (existingContent))
812
- ) {
813
- return doWrite(content);
814
- } else {
815
- return alreadyWritten();
816
- }
912
+ return /** @type {OutputFileSystem} */ (
913
+ this.outputFileSystem
914
+ ).readFile(targetPath, (err, existingContent) => {
915
+ if (
916
+ err ||
917
+ !content.equals(/** @type {Buffer} */ (existingContent))
918
+ ) {
919
+ return doWrite(content);
920
+ } else {
921
+ return alreadyWritten();
817
922
  }
818
- );
923
+ });
819
924
  }
820
925
 
821
926
  return doWrite(content);
@@ -832,16 +937,22 @@ ${other}`);
832
937
  // if the target file has already been written
833
938
  if (targetFileGeneration !== undefined) {
834
939
  // check if the Source has been written to this target file
835
- const writtenGeneration = cacheEntry.writtenTo.get(targetPath);
940
+ const writtenGeneration = /** @type {CacheEntry} */ (
941
+ cacheEntry
942
+ ).writtenTo.get(targetPath);
836
943
  if (writtenGeneration === targetFileGeneration) {
837
944
  // if yes, we may skip writing the file
838
945
  // if it's already there
839
946
  // (we assume one doesn't modify files while the Compiler is running, other then removing them)
840
947
 
841
948
  if (this._assetEmittingPreviousFiles.has(targetPath)) {
949
+ const sizeOnlySource = /** @type {SizeOnlySource} */ (
950
+ /** @type {CacheEntry} */ (cacheEntry).sizeOnlySource
951
+ );
952
+
842
953
  // We assume that assets from the last compilation say intact on disk (they are not removed)
843
- compilation.updateAsset(file, cacheEntry.sizeOnlySource, {
844
- size: cacheEntry.sizeOnlySource.size()
954
+ compilation.updateAsset(file, sizeOnlySource, {
955
+ size: sizeOnlySource.size()
845
956
  });
846
957
 
847
958
  return callback();
@@ -860,11 +971,12 @@ ${other}`);
860
971
 
861
972
  if (checkSimilarFile()) return;
862
973
  if (this.options.output.compareBeforeEmit) {
863
- this.outputFileSystem.stat(targetPath, (err, stats) => {
864
- const exists = !err && stats.isFile();
974
+ /** @type {OutputFileSystem} */
975
+ (this.outputFileSystem).stat(targetPath, (err, stats) => {
976
+ const exists = !err && /** @type {IStats} */ (stats).isFile();
865
977
 
866
978
  if (exists) {
867
- processExistingFile(stats);
979
+ processExistingFile(/** @type {IStats} */ (stats));
868
980
  } else {
869
981
  processMissingFile();
870
982
  }
@@ -875,7 +987,7 @@ ${other}`);
875
987
  };
876
988
 
877
989
  if (targetFile.match(/\/|\\/)) {
878
- const fs = this.outputFileSystem;
990
+ const fs = /** @type {OutputFileSystem} */ (this.outputFileSystem);
879
991
  const dir = dirname(fs, join(fs, outputPath, targetFile));
880
992
  mkdirp(fs, dir, writeOut);
881
993
  } else {
@@ -904,7 +1016,11 @@ ${other}`);
904
1016
  this.hooks.emit.callAsync(compilation, err => {
905
1017
  if (err) return callback(err);
906
1018
  outputPath = compilation.getPath(this.outputPath, {});
907
- mkdirp(this.outputFileSystem, outputPath, emitFiles);
1019
+ mkdirp(
1020
+ /** @type {OutputFileSystem} */ (this.outputFileSystem),
1021
+ outputPath,
1022
+ emitFiles
1023
+ );
908
1024
  });
909
1025
  }
910
1026
 
@@ -940,8 +1056,9 @@ ${other}`);
940
1056
  */
941
1057
  _emitRecords(callback) {
942
1058
  const writeFile = () => {
943
- this.outputFileSystem.writeFile(
944
- this.recordsOutputPath,
1059
+ /** @type {OutputFileSystem} */
1060
+ (this.outputFileSystem).writeFile(
1061
+ /** @type {string} */ (this.recordsOutputPath),
945
1062
  JSON.stringify(
946
1063
  this.records,
947
1064
  (n, value) => {
@@ -964,16 +1081,20 @@ ${other}`);
964
1081
  };
965
1082
 
966
1083
  const recordsOutputPathDirectory = dirname(
967
- this.outputFileSystem,
968
- this.recordsOutputPath
1084
+ /** @type {OutputFileSystem} */ (this.outputFileSystem),
1085
+ /** @type {string} */ (this.recordsOutputPath)
969
1086
  );
970
1087
  if (!recordsOutputPathDirectory) {
971
1088
  return writeFile();
972
1089
  }
973
- mkdirp(this.outputFileSystem, recordsOutputPathDirectory, err => {
974
- if (err) return callback(err);
975
- writeFile();
976
- });
1090
+ mkdirp(
1091
+ /** @type {OutputFileSystem} */ (this.outputFileSystem),
1092
+ recordsOutputPathDirectory,
1093
+ err => {
1094
+ if (err) return callback(err);
1095
+ writeFile();
1096
+ }
1097
+ );
977
1098
  }
978
1099
 
979
1100
  /**
@@ -1013,22 +1134,33 @@ ${other}`);
1013
1134
  this.records = {};
1014
1135
  return callback();
1015
1136
  }
1016
- this.inputFileSystem.stat(this.recordsInputPath, err => {
1137
+ /** @type {InputFileSystem} */
1138
+ (this.inputFileSystem).stat(this.recordsInputPath, err => {
1017
1139
  // It doesn't exist
1018
1140
  // We can ignore this.
1019
1141
  if (err) return callback();
1020
1142
 
1021
- this.inputFileSystem.readFile(this.recordsInputPath, (err, content) => {
1022
- if (err) return callback(err);
1143
+ /** @type {InputFileSystem} */
1144
+ (this.inputFileSystem).readFile(
1145
+ /** @type {string} */ (this.recordsInputPath),
1146
+ (err, content) => {
1147
+ if (err) return callback(err);
1023
1148
 
1024
- try {
1025
- this.records = parseJson(content.toString("utf-8"));
1026
- } catch (e) {
1027
- return callback(new Error(`Cannot parse records: ${e.message}`));
1028
- }
1149
+ try {
1150
+ this.records = parseJson(
1151
+ /** @type {Buffer} */ (content).toString("utf-8")
1152
+ );
1153
+ } catch (e) {
1154
+ return callback(
1155
+ new Error(
1156
+ `Cannot parse records: ${/** @type {Error} */ (e).message}`
1157
+ )
1158
+ );
1159
+ }
1029
1160
 
1030
- return callback();
1031
- });
1161
+ return callback();
1162
+ }
1163
+ );
1032
1164
  });
1033
1165
  }
1034
1166
 
@@ -1122,6 +1254,10 @@ ${other}`);
1122
1254
  return !!this.parentCompilation;
1123
1255
  }
1124
1256
 
1257
+ /**
1258
+ * @param {CompilationParams} params the compilation parameters
1259
+ * @returns {Compilation} compilation
1260
+ */
1125
1261
  createCompilation(params) {
1126
1262
  this._cleanupLastCompilation();
1127
1263
  return (this._lastCompilation = new Compilation(this, params));
@@ -1144,7 +1280,7 @@ ${other}`);
1144
1280
  this._cleanupLastNormalModuleFactory();
1145
1281
  const normalModuleFactory = new NormalModuleFactory({
1146
1282
  context: this.options.context,
1147
- fs: this.inputFileSystem,
1283
+ fs: /** @type {InputFileSystem} */ (this.inputFileSystem),
1148
1284
  resolverFactory: this.resolverFactory,
1149
1285
  options: this.options.module,
1150
1286
  associatedObjectForCache: this.root,
@@ -1170,7 +1306,7 @@ ${other}`);
1170
1306
  }
1171
1307
 
1172
1308
  /**
1173
- * @param {Callback<Compilation>} callback signals when the compilation finishes
1309
+ * @param {RunCallback<Compilation>} callback signals when the compilation finishes
1174
1310
  * @returns {void}
1175
1311
  */
1176
1312
  compile(callback) {
@@ -1221,7 +1357,7 @@ ${other}`);
1221
1357
  }
1222
1358
 
1223
1359
  /**
1224
- * @param {Callback<void>} callback signals when the compiler closes
1360
+ * @param {RunCallback<void>} callback signals when the compiler closes
1225
1361
  * @returns {void}
1226
1362
  */
1227
1363
  close(callback) {