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
@@ -46,11 +46,13 @@ ModuleFilenameHelpers.REGEXP_HASH = /\[hash\]/gi;
46
46
  ModuleFilenameHelpers.NAMESPACE = "[namespace]";
47
47
  ModuleFilenameHelpers.REGEXP_NAMESPACE = /\[namespace\]/gi;
48
48
 
49
+ /** @typedef {() => string} ReturnStringCallback */
50
+
49
51
  /**
50
52
  * Returns a function that returns the part of the string after the token
51
- * @param {() => string} strFn the function to get the string
53
+ * @param {ReturnStringCallback} strFn the function to get the string
52
54
  * @param {string} token the token to search for
53
- * @returns {() => string} a function that returns the part of the string after the token
55
+ * @returns {ReturnStringCallback} a function that returns the part of the string after the token
54
56
  */
55
57
  const getAfter = (strFn, token) => {
56
58
  return () => {
@@ -62,9 +64,9 @@ const getAfter = (strFn, token) => {
62
64
 
63
65
  /**
64
66
  * Returns a function that returns the part of the string before the token
65
- * @param {() => string} strFn the function to get the string
67
+ * @param {ReturnStringCallback} strFn the function to get the string
66
68
  * @param {string} token the token to search for
67
- * @returns {() => string} a function that returns the part of the string before the token
69
+ * @returns {ReturnStringCallback} a function that returns the part of the string before the token
68
70
  */
69
71
  const getBefore = (strFn, token) => {
70
72
  return () => {
@@ -76,11 +78,11 @@ const getBefore = (strFn, token) => {
76
78
 
77
79
  /**
78
80
  * Returns a function that returns a hash of the string
79
- * @param {() => string} strFn the function to get the string
80
- * @param {string | Hash} hashFunction the hash function to use
81
- * @returns {() => string} a function that returns the hash of the string
81
+ * @param {ReturnStringCallback} strFn the function to get the string
82
+ * @param {string | Hash=} hashFunction the hash function to use
83
+ * @returns {ReturnStringCallback} a function that returns the hash of the string
82
84
  */
83
- const getHash = (strFn, hashFunction) => {
85
+ const getHash = (strFn, hashFunction = "md4") => {
84
86
  return () => {
85
87
  const hash = createHash(hashFunction);
86
88
  hash.update(strFn());
@@ -115,8 +117,8 @@ const asRegExp = test => {
115
117
  * @template T
116
118
  * Returns a lazy object. The object is lazy in the sense that the properties are
117
119
  * only evaluated when they are accessed. This is only obtained by setting a function as the value for each key.
118
- * @param {Record<string, () => T>} obj the object to covert to a lazy access object
119
- * @returns {Object} the lazy access object
120
+ * @param {Record<string, () => T>} obj the object to convert to a lazy access object
121
+ * @returns {object} the lazy access object
120
122
  */
121
123
  const lazyObject = obj => {
122
124
  const newObj = {};
@@ -144,10 +146,10 @@ const SQUARE_BRACKET_TAG_REGEXP = /\[\\*([\w-]+)\\*\]/gi;
144
146
  *
145
147
  * @param {Module | string} module the module
146
148
  * @param {TODO} options options
147
- * @param {Object} contextInfo context info
149
+ * @param {object} contextInfo context info
148
150
  * @param {RequestShortener} contextInfo.requestShortener requestShortener
149
151
  * @param {ChunkGraph} contextInfo.chunkGraph chunk graph
150
- * @param {string | Hash} contextInfo.hashFunction the hash function to use
152
+ * @param {string | Hash=} contextInfo.hashFunction the hash function to use
151
153
  * @returns {string} the filename
152
154
  */
153
155
  ModuleFilenameHelpers.createFilename = (
@@ -167,11 +169,16 @@ ModuleFilenameHelpers.createFilename = (
167
169
 
168
170
  let absoluteResourcePath;
169
171
  let hash;
172
+ /** @type {ReturnStringCallback} */
170
173
  let identifier;
174
+ /** @type {ReturnStringCallback} */
171
175
  let moduleId;
176
+ /** @type {ReturnStringCallback} */
172
177
  let shortIdentifier;
173
178
  if (typeof module === "string") {
174
- shortIdentifier = memoize(() => requestShortener.shorten(module));
179
+ shortIdentifier =
180
+ /** @type {ReturnStringCallback} */
181
+ (memoize(() => requestShortener.shorten(module)));
175
182
  identifier = shortIdentifier;
176
183
  moduleId = () => "";
177
184
  absoluteResourcePath = () => module.split("!").pop();
@@ -180,15 +187,21 @@ ModuleFilenameHelpers.createFilename = (
180
187
  shortIdentifier = memoize(() =>
181
188
  module.readableIdentifier(requestShortener)
182
189
  );
183
- identifier = memoize(() => requestShortener.shorten(module.identifier()));
184
- moduleId = () => chunkGraph.getModuleId(module);
190
+ identifier =
191
+ /** @type {ReturnStringCallback} */
192
+ (memoize(() => requestShortener.shorten(module.identifier())));
193
+ moduleId =
194
+ /** @type {ReturnStringCallback} */
195
+ (() => chunkGraph.getModuleId(module));
185
196
  absoluteResourcePath = () =>
186
197
  module instanceof NormalModule
187
198
  ? module.resource
188
199
  : module.identifier().split("!").pop();
189
200
  hash = getHash(identifier, hashFunction);
190
201
  }
191
- const resource = memoize(() => shortIdentifier().split("!").pop());
202
+ const resource =
203
+ /** @type {ReturnStringCallback} */
204
+ (memoize(() => shortIdentifier().split("!").pop()));
192
205
 
193
206
  const loaders = getBefore(shortIdentifier, "!");
194
207
  const allLoaders = getBefore(identifier, "!");
@@ -249,7 +262,7 @@ ModuleFilenameHelpers.createFilename = (
249
262
  ]);
250
263
 
251
264
  // TODO webpack 6: consider removing weird double placeholders
252
- return opts.moduleFilenameTemplate
265
+ return /** @type {string} */ (opts.moduleFilenameTemplate)
253
266
  .replace(ModuleFilenameHelpers.REGEXP_ALL_LOADERS_RESOURCE, "[identifier]")
254
267
  .replace(
255
268
  ModuleFilenameHelpers.REGEXP_LOADERS_RESOURCE,
@@ -89,13 +89,16 @@ const getConnectionsByModule = set => {
89
89
  return map;
90
90
  };
91
91
 
92
+ /** @typedef {SortableSet<ModuleGraphConnection>} IncomingConnections */
93
+ /** @typedef {SortableSet<ModuleGraphConnection>} OutgoingConnections */
94
+
92
95
  class ModuleGraphModule {
93
96
  constructor() {
94
- /** @type {SortableSet<ModuleGraphConnection>} */
97
+ /** @type {IncomingConnections} */
95
98
  this.incomingConnections = new SortableSet();
96
- /** @type {SortableSet<ModuleGraphConnection> | undefined} */
99
+ /** @type {OutgoingConnections | undefined} */
97
100
  this.outgoingConnections = undefined;
98
- /** @type {Module | null} */
101
+ /** @type {Module | null | undefined} */
99
102
  this.issuer = undefined;
100
103
  /** @type {(string | OptimizationBailoutFunction)[]} */
101
104
  this.optimizationBailout = [];
@@ -107,31 +110,47 @@ class ModuleGraphModule {
107
110
  this.postOrderIndex = null;
108
111
  /** @type {number | null} */
109
112
  this.depth = null;
110
- /** @type {ModuleProfile | undefined | null} */
113
+ /** @type {ModuleProfile | undefined} */
111
114
  this.profile = undefined;
112
115
  /** @type {boolean} */
113
116
  this.async = false;
114
- /** @type {ModuleGraphConnection[]} */
117
+ /** @type {ModuleGraphConnection[] | undefined} */
115
118
  this._unassignedConnections = undefined;
116
119
  }
117
120
  }
118
121
 
119
122
  class ModuleGraph {
120
123
  constructor() {
121
- /** @type {WeakMap<Dependency, ModuleGraphConnection | null>} */
124
+ /**
125
+ * @type {WeakMap<Dependency, ModuleGraphConnection | null>}
126
+ * @private
127
+ */
122
128
  this._dependencyMap = new WeakMap();
123
- /** @type {Map<Module, ModuleGraphModule>} */
129
+ /**
130
+ * @type {Map<Module, ModuleGraphModule>}
131
+ * @private
132
+ */
124
133
  this._moduleMap = new Map();
125
- /** @type {WeakMap<any, Object>} */
134
+ /**
135
+ * @type {WeakMap<any, object>}
136
+ * @private
137
+ */
126
138
  this._metaMap = new WeakMap();
127
-
128
- /** @type {WeakTupleMap<any[], any> | undefined} */
139
+ /**
140
+ * @type {WeakTupleMap<any[], any> | undefined}
141
+ * @private
142
+ */
129
143
  this._cache = undefined;
130
-
131
- /** @type {Map<Module, WeakTupleMap<any, any>>} */
144
+ /**
145
+ * @type {Map<Module, WeakTupleMap<any, any>> | undefined}
146
+ * @private
147
+ */
132
148
  this._moduleMemCaches = undefined;
133
149
 
134
- /** @type {string | undefined} */
150
+ /**
151
+ * @type {string | undefined}
152
+ * @private
153
+ */
135
154
  this._cacheStage = undefined;
136
155
  }
137
156
 
@@ -163,7 +182,7 @@ class ModuleGraph {
163
182
 
164
183
  /**
165
184
  * @param {Dependency} dependency the dependency
166
- * @returns {Module} parent module
185
+ * @returns {Module | undefined} parent module
167
186
  */
168
187
  getParentModule(dependency) {
169
188
  return dependency._parentModule;
@@ -171,7 +190,7 @@ class ModuleGraph {
171
190
 
172
191
  /**
173
192
  * @param {Dependency} dependency the dependency
174
- * @returns {DependenciesBlock} parent block
193
+ * @returns {DependenciesBlock | undefined} parent block
175
194
  */
176
195
  getParentBlock(dependency) {
177
196
  return dependency._parentDependenciesBlock;
@@ -186,7 +205,7 @@ class ModuleGraph {
186
205
  }
187
206
 
188
207
  /**
189
- * @param {Module} originModule the referencing module
208
+ * @param {Module | null} originModule the referencing module
190
209
  * @param {Dependency} dependency the referencing dependency
191
210
  * @param {Module} module the referenced module
192
211
  * @returns {void}
@@ -231,8 +250,11 @@ class ModuleGraph {
231
250
  newConnection.module = module;
232
251
  this._dependencyMap.set(dependency, newConnection);
233
252
  connection.setActive(false);
234
- const originMgm = this._getModuleGraphModule(connection.originModule);
235
- originMgm.outgoingConnections.add(newConnection);
253
+ const originMgm = this._getModuleGraphModule(
254
+ /** @type {Module} */ (connection.originModule)
255
+ );
256
+ /** @type {OutgoingConnections} */
257
+ (originMgm.outgoingConnections).add(newConnection);
236
258
  const targetMgm = this._getModuleGraphModule(module);
237
259
  targetMgm.incomingConnections.add(newConnection);
238
260
  }
@@ -242,11 +264,16 @@ class ModuleGraph {
242
264
  * @returns {void}
243
265
  */
244
266
  removeConnection(dependency) {
245
- const connection = this.getConnection(dependency);
267
+ const connection =
268
+ /** @type {ModuleGraphConnection} */
269
+ (this.getConnection(dependency));
246
270
  const targetMgm = this._getModuleGraphModule(connection.module);
247
271
  targetMgm.incomingConnections.delete(connection);
248
- const originMgm = this._getModuleGraphModule(connection.originModule);
249
- originMgm.outgoingConnections.delete(connection);
272
+ const originMgm = this._getModuleGraphModule(
273
+ /** @type {Module} */ (connection.originModule)
274
+ );
275
+ /** @type {OutgoingConnections} */
276
+ (originMgm.outgoingConnections).delete(connection);
250
277
  this._dependencyMap.set(dependency, null);
251
278
  }
252
279
 
@@ -256,7 +283,9 @@ class ModuleGraph {
256
283
  * @returns {void}
257
284
  */
258
285
  addExplanation(dependency, explanation) {
259
- const connection = this.getConnection(dependency);
286
+ const connection =
287
+ /** @type {ModuleGraphConnection} */
288
+ (this.getConnection(dependency));
260
289
  connection.addExplanation(explanation);
261
290
  }
262
291
 
@@ -468,7 +497,7 @@ class ModuleGraph {
468
497
 
469
498
  /**
470
499
  * @param {Module} module the module
471
- * @returns {readonly Map<Module | undefined, readonly ModuleGraphConnection[]>} reasons why a module is included, in a map by source module
500
+ * @returns {readonly Map<Module | undefined | null, readonly ModuleGraphConnection[]>} reasons why a module is included, in a map by source module
472
501
  */
473
502
  getIncomingConnectionsByOriginModule(module) {
474
503
  const connections = this._getModuleGraphModule(module).incomingConnections;
@@ -488,7 +517,7 @@ class ModuleGraph {
488
517
 
489
518
  /**
490
519
  * @param {Module} module the module
491
- * @returns {ModuleProfile | null} the module profile
520
+ * @returns {ModuleProfile | undefined} the module profile
492
521
  */
493
522
  getProfile(module) {
494
523
  const mgm = this._getModuleGraphModule(module);
@@ -497,7 +526,7 @@ class ModuleGraph {
497
526
 
498
527
  /**
499
528
  * @param {Module} module the module
500
- * @param {ModuleProfile | null} profile the module profile
529
+ * @param {ModuleProfile | undefined} profile the module profile
501
530
  * @returns {void}
502
531
  */
503
532
  setProfile(module, profile) {
@@ -507,7 +536,7 @@ class ModuleGraph {
507
536
 
508
537
  /**
509
538
  * @param {Module} module the module
510
- * @returns {Module | null} the issuer module
539
+ * @returns {Module | null | undefined} the issuer module
511
540
  */
512
541
  getIssuer(module) {
513
542
  const mgm = this._getModuleGraphModule(module);
@@ -728,20 +757,20 @@ class ModuleGraph {
728
757
 
729
758
  /**
730
759
  * @param {any} thing any thing
731
- * @returns {Object} metadata
760
+ * @returns {object} metadata
732
761
  */
733
762
  getMeta(thing) {
734
763
  let meta = this._metaMap.get(thing);
735
764
  if (meta === undefined) {
736
765
  meta = Object.create(null);
737
- this._metaMap.set(thing, /** @type {Object} */ (meta));
766
+ this._metaMap.set(thing, /** @type {object} */ (meta));
738
767
  }
739
- return /** @type {Object} */ (meta);
768
+ return /** @type {object} */ (meta);
740
769
  }
741
770
 
742
771
  /**
743
772
  * @param {any} thing any thing
744
- * @returns {Object | undefined} metadata
773
+ * @returns {object | undefined} metadata
745
774
  */
746
775
  getMetaIfExisting(thing) {
747
776
  return this._metaMap.get(thing);
@@ -789,7 +818,7 @@ class ModuleGraph {
789
818
  const fn = args.pop();
790
819
  if (this._moduleMemCaches && this._cacheStage) {
791
820
  const memCache = this._moduleMemCaches.get(
792
- this.getParentModule(dependency)
821
+ /** @type {Module} */ (this.getParentModule(dependency))
793
822
  );
794
823
  if (memCache !== undefined) {
795
824
  return memCache.provide(dependency, this._cacheStage, ...args, () =>
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  /** @typedef {import("./Dependency")} Dependency */
9
+ /** @typedef {import("./Dependency").GetConditionFn} GetConditionFn */
9
10
  /** @typedef {import("./Module")} Module */
10
11
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
11
12
 
@@ -56,7 +57,7 @@ class ModuleGraphConnection {
56
57
  * @param {Module} module the referenced module
57
58
  * @param {string=} explanation some extra detail
58
59
  * @param {boolean=} weak the reference is weak
59
- * @param {false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState=} condition condition for the connection
60
+ * @param {false | null | GetConditionFn | undefined} condition condition for the connection
60
61
  */
61
62
  constructor(
62
63
  originModule,
@@ -11,6 +11,7 @@ const { SyncHook, MultiHook } = require("tapable");
11
11
  const ConcurrentCompilationError = require("./ConcurrentCompilationError");
12
12
  const MultiStats = require("./MultiStats");
13
13
  const MultiWatching = require("./MultiWatching");
14
+ const WebpackError = require("./WebpackError");
14
15
  const ArrayQueue = require("./util/ArrayQueue");
15
16
 
16
17
  /** @template T @typedef {import("tapable").AsyncSeriesHook<T>} AsyncSeriesHook<T> */
@@ -28,7 +29,7 @@ const ArrayQueue = require("./util/ArrayQueue");
28
29
  /**
29
30
  * @template T
30
31
  * @callback Callback
31
- * @param {(Error | null)=} err
32
+ * @param {Error | null} err
32
33
  * @param {T=} result
33
34
  */
34
35
 
@@ -39,7 +40,7 @@ const ArrayQueue = require("./util/ArrayQueue");
39
40
  */
40
41
 
41
42
  /**
42
- * @typedef {Object} MultiCompilerOptions
43
+ * @typedef {object} MultiCompilerOptions
43
44
  * @property {number=} parallelism how many Compilers are allows to run at the same time in parallel
44
45
  */
45
46
 
@@ -50,9 +51,11 @@ module.exports = class MultiCompiler {
50
51
  */
51
52
  constructor(compilers, options) {
52
53
  if (!Array.isArray(compilers)) {
54
+ /** @type {Compiler[]} */
53
55
  compilers = Object.keys(compilers).map(name => {
54
- compilers[name].name = name;
55
- return compilers[name];
56
+ /** @type {Record<string, Compiler>} */
57
+ (compilers)[name].name = name;
58
+ return /** @type {Record<string, Compiler>} */ (compilers)[name];
56
59
  });
57
60
  }
58
61
 
@@ -107,6 +110,40 @@ module.exports = class MultiCompiler {
107
110
  }
108
111
  });
109
112
  }
113
+ this._validateCompilersOptions();
114
+ }
115
+
116
+ _validateCompilersOptions() {
117
+ if (this.compilers.length < 2) return;
118
+ /**
119
+ * @param {Compiler} compiler compiler
120
+ * @param {WebpackError} warning warning
121
+ */
122
+ const addWarning = (compiler, warning) => {
123
+ compiler.hooks.thisCompilation.tap("MultiCompiler", compilation => {
124
+ compilation.warnings.push(warning);
125
+ });
126
+ };
127
+ const cacheNames = new Set();
128
+ for (const compiler of this.compilers) {
129
+ if (compiler.options.cache && "name" in compiler.options.cache) {
130
+ const name = compiler.options.cache.name;
131
+ if (cacheNames.has(name)) {
132
+ addWarning(
133
+ compiler,
134
+ new WebpackError(
135
+ `${
136
+ compiler.name
137
+ ? `Compiler with name "${compiler.name}" doesn't use unique cache name. `
138
+ : ""
139
+ }Please set unique "cache.name" option. Name "${name}" already used.`
140
+ )
141
+ );
142
+ } else {
143
+ cacheNames.add(name);
144
+ }
145
+ }
146
+ }
110
147
  }
111
148
 
112
149
  get options() {
@@ -221,10 +258,19 @@ module.exports = class MultiCompiler {
221
258
  }
222
259
  return false;
223
260
  };
261
+ /**
262
+ * @param {{source: Compiler, target: Compiler}} e1 edge 1
263
+ * @param {{source: Compiler, target: Compiler}} e2 edge 2
264
+ * @returns {number} result
265
+ */
224
266
  const sortEdges = (e1, e2) => {
225
267
  return (
226
- e1.source.name.localeCompare(e2.source.name) ||
227
- e1.target.name.localeCompare(e2.target.name)
268
+ /** @type {string} */
269
+ (e1.source.name).localeCompare(
270
+ /** @type {string} */ (e2.source.name)
271
+ ) ||
272
+ /** @type {string} */
273
+ (e1.target.name).localeCompare(/** @type {string} */ (e2.target.name))
228
274
  );
229
275
  };
230
276
  for (const source of this.compilers) {
@@ -290,6 +336,9 @@ module.exports = class MultiCompiler {
290
336
  * @returns {boolean} when dependency was fulfilled
291
337
  */
292
338
  const isDependencyFulfilled = d => fulfilledNames.has(d);
339
+ /**
340
+ * @returns {Compiler[]} compilers
341
+ */
293
342
  const getReadyCompilers = () => {
294
343
  let readyCompilers = [];
295
344
  let list = remainingCompilers;
@@ -311,7 +360,7 @@ module.exports = class MultiCompiler {
311
360
  * @returns {void}
312
361
  */
313
362
  const runCompilers = callback => {
314
- if (remainingCompilers.length === 0) return callback();
363
+ if (remainingCompilers.length === 0) return callback(null);
315
364
  asyncLib.map(
316
365
  getReadyCompilers(),
317
366
  (compiler, callback) => {
@@ -321,7 +370,9 @@ module.exports = class MultiCompiler {
321
370
  runCompilers(callback);
322
371
  });
323
372
  },
324
- /** @type {Callback<TODO>} */ (callback)
373
+ (err, results) => {
374
+ callback(err, /** @type {TODO} */ (results));
375
+ }
325
376
  );
326
377
  };
327
378
  runCompilers(callback);
@@ -602,7 +653,9 @@ module.exports = class MultiCompiler {
602
653
  (compiler, callback) => {
603
654
  compiler.close(callback);
604
655
  },
605
- callback
656
+ error => {
657
+ callback(error);
658
+ }
606
659
  );
607
660
  }
608
661
  };
@@ -32,6 +32,7 @@ const { parseResource } = require("./util/identifier");
32
32
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
33
33
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
34
34
  /** @typedef {import("./javascript/JavascriptParser").Range} Range */
35
+ /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
35
36
 
36
37
  const PLUGIN_NAME = "NodeStuffPlugin";
37
38
 
@@ -193,7 +194,11 @@ class NodeStuffPlugin {
193
194
  break;
194
195
  case true:
195
196
  setModuleConstant("__filename", module =>
196
- relative(compiler.inputFileSystem, context, module.resource)
197
+ relative(
198
+ /** @type {InputFileSystem} */ (compiler.inputFileSystem),
199
+ context,
200
+ module.resource
201
+ )
197
202
  );
198
203
  break;
199
204
  }
@@ -227,7 +232,11 @@ class NodeStuffPlugin {
227
232
  break;
228
233
  case true:
229
234
  setModuleConstant("__dirname", module =>
230
- relative(compiler.inputFileSystem, context, module.context)
235
+ relative(
236
+ /** @type {InputFileSystem} */ (compiler.inputFileSystem),
237
+ context,
238
+ /** @type {string} */ (module.context)
239
+ )
231
240
  );
232
241
  break;
233
242
  }
@@ -236,7 +245,9 @@ class NodeStuffPlugin {
236
245
  .for("__dirname")
237
246
  .tap(PLUGIN_NAME, expr => {
238
247
  if (!parser.state.module) return;
239
- return evaluateToString(parser.state.module.context)(expr);
248
+ return evaluateToString(
249
+ /** @type {string} */ (parser.state.module.context)
250
+ )(expr);
240
251
  });
241
252
  }
242
253
  parser.hooks.expression
@@ -89,7 +89,7 @@ const memoize = require("./util/memoize");
89
89
  /** @typedef {UnsafeCacheData & { parser: undefined | Parser, parserOptions: undefined | ParserOptions, generator: undefined | Generator, generatorOptions: undefined | GeneratorOptions }} NormalModuleUnsafeCacheData */
90
90
 
91
91
  /**
92
- * @typedef {Object} SourceMap
92
+ * @typedef {object} SourceMap
93
93
  * @property {number} version
94
94
  * @property {string[]} sources
95
95
  * @property {string} mappings
@@ -107,7 +107,7 @@ const getValidate = memoize(() => require("schema-utils").validate);
107
107
  const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:\\|\\\\|\/)/;
108
108
 
109
109
  /**
110
- * @typedef {Object} LoaderItem
110
+ * @typedef {object} LoaderItem
111
111
  * @property {string} loader
112
112
  * @property {any} options
113
113
  * @property {string?} ident
@@ -117,7 +117,7 @@ const ABSOLUTE_PATH_REGEX = /^([a-zA-Z]:\\|\\\\|\/)/;
117
117
  /**
118
118
  * @param {string} context absolute context path
119
119
  * @param {string} source a source path
120
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
120
+ * @param {object=} associatedObjectForCache an object to which the cache will be attached
121
121
  * @returns {string} new source path
122
122
  */
123
123
  const contextifySourceUrl = (context, source, associatedObjectForCache) => {
@@ -132,7 +132,7 @@ const contextifySourceUrl = (context, source, associatedObjectForCache) => {
132
132
  /**
133
133
  * @param {string} context absolute context path
134
134
  * @param {SourceMap} sourceMap a source map
135
- * @param {Object=} associatedObjectForCache an object to which the cache will be attached
135
+ * @param {object=} associatedObjectForCache an object to which the cache will be attached
136
136
  * @returns {SourceMap} new source map
137
137
  */
138
138
  const contextifySourceMap = (context, sourceMap, associatedObjectForCache) => {
@@ -199,7 +199,7 @@ makeSerializable(
199
199
  );
200
200
 
201
201
  /**
202
- * @typedef {Object} NormalModuleCompilationHooks
202
+ * @typedef {object} NormalModuleCompilationHooks
203
203
  * @property {SyncHook<[object, NormalModule]>} loader
204
204
  * @property {SyncHook<[LoaderItem[], NormalModule, object]>} beforeLoaders
205
205
  * @property {SyncHook<[NormalModule]>} beforeParse
@@ -210,7 +210,7 @@ makeSerializable(
210
210
  */
211
211
 
212
212
  /**
213
- * @typedef {Object} NormalModuleCreateData
213
+ * @typedef {object} NormalModuleCreateData
214
214
  * @property {string=} layer an optional layer in which the module is
215
215
  * @property {JavaScriptModuleTypes | ""} type module type. When deserializing, this is set to an empty string "".
216
216
  * @property {string} request request string
@@ -344,12 +344,12 @@ class NormalModule extends Module {
344
344
  /**
345
345
  * @private
346
346
  * @type {Map<string, number> | undefined}
347
- **/
347
+ */
348
348
  this._sourceSizes = undefined;
349
349
  /**
350
350
  * @private
351
351
  * @type {undefined | SourceTypes}
352
- **/
352
+ */
353
353
  this._sourceTypes = undefined;
354
354
 
355
355
  // Cache
@@ -499,7 +499,7 @@ class NormalModule extends Module {
499
499
  * @param {string} name the asset name
500
500
  * @param {string | Buffer} content the content
501
501
  * @param {(string | SourceMap)=} sourceMap an optional source map
502
- * @param {Object=} associatedObjectForCache object for caching
502
+ * @param {object=} associatedObjectForCache object for caching
503
503
  * @returns {Source} the created source
504
504
  */
505
505
  createSourceForAsset(
@@ -776,7 +776,7 @@ class NormalModule extends Module {
776
776
  * @param {string} context the compilation context
777
777
  * @param {string | Buffer} content the content
778
778
  * @param {(string | SourceMapSource)=} sourceMap an optional source map
779
- * @param {Object=} associatedObjectForCache object for caching
779
+ * @param {object=} associatedObjectForCache object for caching
780
780
  * @returns {Source} the created source
781
781
  */
782
782
  createSource(context, content, sourceMap, associatedObjectForCache) {
@@ -926,6 +926,8 @@ class NormalModule extends Module {
926
926
  loaderContext._compilation =
927
927
  loaderContext._compiler =
928
928
  loaderContext._module =
929
+ // eslint-disable-next-line no-warning-comments
930
+ // @ts-ignore
929
931
  loaderContext.fs =
930
932
  undefined;
931
933
 
@@ -1325,7 +1327,6 @@ class NormalModule extends Module {
1325
1327
  moduleGraph,
1326
1328
  chunkGraph,
1327
1329
  runtime,
1328
- runtimes,
1329
1330
  concatenationScope,
1330
1331
  codeGenerationResults,
1331
1332
  sourceTypes
@@ -1352,14 +1353,13 @@ class NormalModule extends Module {
1352
1353
  ? new RawSource(
1353
1354
  "throw new Error(" + JSON.stringify(this.error.message) + ");"
1354
1355
  )
1355
- : this.generator.generate(this, {
1356
+ : /** @type {Generator} */ (this.generator).generate(this, {
1356
1357
  dependencyTemplates,
1357
1358
  runtimeTemplate,
1358
1359
  moduleGraph,
1359
1360
  chunkGraph,
1360
1361
  runtimeRequirements,
1361
1362
  runtime,
1362
- runtimes,
1363
1363
  concatenationScope,
1364
1364
  codeGenerationResults,
1365
1365
  getData,