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
@@ -42,19 +42,28 @@ const {
42
42
  WEBPACK_MODULE_TYPE_RUNTIME
43
43
  } = require("./ModuleTypeConstants");
44
44
 
45
+ /** @typedef {import("estree").CallExpression} CallExpression */
46
+ /** @typedef {import("estree").Expression} Expression */
45
47
  /** @typedef {import("./Chunk")} Chunk */
48
+ /** @typedef {import("./Chunk").ChunkId} ChunkId */
46
49
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
47
50
  /** @typedef {import("./Compiler")} Compiler */
51
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
48
52
  /** @typedef {import("./Module")} Module */
53
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
49
54
  /** @typedef {import("./RuntimeModule")} RuntimeModule */
55
+ /** @typedef {import("./javascript/BasicEvaluatedExpression")} BasicEvaluatedExpression */
56
+ /** @typedef {import("./javascript/JavascriptParserHelpers").Range} Range */
50
57
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
51
58
 
52
59
  /**
53
- * @typedef {Object} HMRJavascriptParserHooks
60
+ * @typedef {object} HMRJavascriptParserHooks
54
61
  * @property {SyncBailHook<[TODO, string[]], void>} hotAcceptCallback
55
62
  * @property {SyncBailHook<[TODO, string[]], void>} hotAcceptWithoutCallback
56
63
  */
57
64
 
65
+ /** @typedef {Map<string, { updatedChunkIds: Set<ChunkId>, removedChunkIds: Set<ChunkId>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo }>} HotUpdateMainContentByRuntime */
66
+
58
67
  /** @type {WeakMap<JavascriptParser, HMRJavascriptParserHooks>} */
59
68
  const parserHooksMap = new WeakMap();
60
69
 
@@ -82,6 +91,9 @@ class HotModuleReplacementPlugin {
82
91
  return hooks;
83
92
  }
84
93
 
94
+ /**
95
+ * @param {object=} options options
96
+ */
85
97
  constructor(options) {
86
98
  this.options = options || {};
87
99
  }
@@ -97,6 +109,11 @@ class HotModuleReplacementPlugin {
97
109
  compiler.options.output.strictModuleErrorHandling = true;
98
110
  const runtimeRequirements = [RuntimeGlobals.module];
99
111
 
112
+ /**
113
+ * @param {JavascriptParser} parser the parser
114
+ * @param {typeof ModuleHotAcceptDependency} ParamDependency dependency
115
+ * @returns {(expr: CallExpression) => boolean | undefined} callback
116
+ */
100
117
  const createAcceptHandler = (parser, ParamDependency) => {
101
118
  const { hotAcceptCallback, hotAcceptWithoutCallback } =
102
119
  HotModuleReplacementPlugin.getParserHooks(parser);
@@ -105,27 +122,38 @@ class HotModuleReplacementPlugin {
105
122
  const module = parser.state.module;
106
123
  const dep = new ConstDependency(
107
124
  `${module.moduleArgument}.hot.accept`,
108
- expr.callee.range,
125
+ /** @type {Range} */ (expr.callee.range),
109
126
  runtimeRequirements
110
127
  );
111
- dep.loc = expr.loc;
128
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
112
129
  module.addPresentationalDependency(dep);
113
- module.buildInfo.moduleConcatenationBailout = "Hot Module Replacement";
130
+ /** @type {BuildInfo} */
131
+ (module.buildInfo).moduleConcatenationBailout =
132
+ "Hot Module Replacement";
114
133
  if (expr.arguments.length >= 1) {
115
134
  const arg = parser.evaluateExpression(expr.arguments[0]);
135
+ /** @type {BasicEvaluatedExpression[]} */
116
136
  let params = [];
117
- let requests = [];
118
137
  if (arg.isString()) {
119
138
  params = [arg];
120
139
  } else if (arg.isArray()) {
121
- params = arg.items.filter(param => param.isString());
140
+ params =
141
+ /** @type {BasicEvaluatedExpression[]} */
142
+ (arg.items).filter(param => param.isString());
122
143
  }
144
+ /** @type {string[]} */
145
+ let requests = [];
123
146
  if (params.length > 0) {
124
147
  params.forEach((param, idx) => {
125
- const request = param.string;
126
- const dep = new ParamDependency(request, param.range);
148
+ const request = /** @type {string} */ (param.string);
149
+ const dep = new ParamDependency(
150
+ request,
151
+ /** @type {Range} */ (param.range)
152
+ );
127
153
  dep.optional = true;
128
- dep.loc = Object.create(expr.loc);
154
+ dep.loc = Object.create(
155
+ /** @type {DependencyLocation} */ (expr.loc)
156
+ );
129
157
  dep.loc.index = idx;
130
158
  module.addDependency(dep);
131
159
  requests.push(request);
@@ -147,28 +175,40 @@ class HotModuleReplacementPlugin {
147
175
  };
148
176
  };
149
177
 
178
+ /**
179
+ * @param {JavascriptParser} parser the parser
180
+ * @param {typeof ModuleHotDeclineDependency} ParamDependency dependency
181
+ * @returns {(expr: CallExpression) => boolean | undefined} callback
182
+ */
150
183
  const createDeclineHandler = (parser, ParamDependency) => expr => {
151
184
  const module = parser.state.module;
152
185
  const dep = new ConstDependency(
153
186
  `${module.moduleArgument}.hot.decline`,
154
- expr.callee.range,
187
+ /** @type {Range} */ (expr.callee.range),
155
188
  runtimeRequirements
156
189
  );
157
- dep.loc = expr.loc;
190
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
158
191
  module.addPresentationalDependency(dep);
159
- module.buildInfo.moduleConcatenationBailout = "Hot Module Replacement";
192
+ /** @type {BuildInfo} */
193
+ (module.buildInfo).moduleConcatenationBailout = "Hot Module Replacement";
160
194
  if (expr.arguments.length === 1) {
161
195
  const arg = parser.evaluateExpression(expr.arguments[0]);
196
+ /** @type {BasicEvaluatedExpression[]} */
162
197
  let params = [];
163
198
  if (arg.isString()) {
164
199
  params = [arg];
165
200
  } else if (arg.isArray()) {
166
- params = arg.items.filter(param => param.isString());
201
+ params =
202
+ /** @type {BasicEvaluatedExpression[]} */
203
+ (arg.items).filter(param => param.isString());
167
204
  }
168
205
  params.forEach((param, idx) => {
169
- const dep = new ParamDependency(param.string, param.range);
206
+ const dep = new ParamDependency(
207
+ /** @type {string} */ (param.string),
208
+ /** @type {Range} */ (param.range)
209
+ );
170
210
  dep.optional = true;
171
- dep.loc = Object.create(expr.loc);
211
+ dep.loc = Object.create(/** @type {DependencyLocation} */ (expr.loc));
172
212
  dep.loc.index = idx;
173
213
  module.addDependency(dep);
174
214
  });
@@ -176,16 +216,21 @@ class HotModuleReplacementPlugin {
176
216
  return true;
177
217
  };
178
218
 
219
+ /**
220
+ * @param {JavascriptParser} parser the parser
221
+ * @returns {(expr: Expression) => boolean | undefined} callback
222
+ */
179
223
  const createHMRExpressionHandler = parser => expr => {
180
224
  const module = parser.state.module;
181
225
  const dep = new ConstDependency(
182
226
  `${module.moduleArgument}.hot`,
183
- expr.range,
227
+ /** @type {Range} */ (expr.range),
184
228
  runtimeRequirements
185
229
  );
186
- dep.loc = expr.loc;
230
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
187
231
  module.addPresentationalDependency(dep);
188
- module.buildInfo.moduleConcatenationBailout = "Hot Module Replacement";
232
+ /** @type {BuildInfo} */
233
+ (module.buildInfo).moduleConcatenationBailout = "Hot Module Replacement";
189
234
  return true;
190
235
  };
191
236
 
@@ -303,7 +348,9 @@ class HotModuleReplacementPlugin {
303
348
  //#endregion
304
349
 
305
350
  let hotIndex = 0;
351
+ /** @type {Record<string, string>} */
306
352
  const fullHashChunkModuleHashes = {};
353
+ /** @type {Record<string, string>} */
307
354
  const chunkModuleHashes = {};
308
355
 
309
356
  compilation.hooks.record.tap(PLUGIN_NAME, (compilation, records) => {
@@ -316,18 +363,20 @@ class HotModuleReplacementPlugin {
316
363
  records.chunkHashes = {};
317
364
  records.chunkRuntime = {};
318
365
  for (const chunk of compilation.chunks) {
319
- records.chunkHashes[chunk.id] = chunk.hash;
320
- records.chunkRuntime[chunk.id] = getRuntimeKey(chunk.runtime);
366
+ const chunkId = /** @type {ChunkId} */ (chunk.id);
367
+ records.chunkHashes[chunkId] = chunk.hash;
368
+ records.chunkRuntime[chunkId] = getRuntimeKey(chunk.runtime);
321
369
  }
322
370
  records.chunkModuleIds = {};
323
371
  for (const chunk of compilation.chunks) {
324
- records.chunkModuleIds[chunk.id] = Array.from(
325
- chunkGraph.getOrderedChunkModulesIterable(
326
- chunk,
327
- compareModulesById(chunkGraph)
328
- ),
329
- m => chunkGraph.getModuleId(m)
330
- );
372
+ records.chunkModuleIds[/** @type {ChunkId} */ (chunk.id)] =
373
+ Array.from(
374
+ chunkGraph.getOrderedChunkModulesIterable(
375
+ chunk,
376
+ compareModulesById(chunkGraph)
377
+ ),
378
+ m => chunkGraph.getModuleId(m)
379
+ );
331
380
  }
332
381
  });
333
382
  /** @type {TupleSet<[Module, Chunk]>} */
@@ -340,6 +389,10 @@ class HotModuleReplacementPlugin {
340
389
  const chunkGraph = compilation.chunkGraph;
341
390
  const records = compilation.records;
342
391
  for (const chunk of compilation.chunks) {
392
+ /**
393
+ * @param {Module} module module
394
+ * @returns {string} module hash
395
+ */
343
396
  const getModuleHash = module => {
344
397
  if (
345
398
  compilation.codeGenerationResults.has(module, chunk.runtime)
@@ -454,7 +507,7 @@ class HotModuleReplacementPlugin {
454
507
  chunkModuleHashes[key] = hash;
455
508
  }
456
509
 
457
- /** @type {Map<string, { updatedChunkIds: Set<string|number>, removedChunkIds: Set<string|number>, removedModules: Set<Module>, filename: string, assetInfo: AssetInfo }>} */
510
+ /** @type {HotUpdateMainContentByRuntime} */
458
511
  const hotUpdateMainContentByRuntime = new Map();
459
512
  let allOldRuntime;
460
513
  for (const key of Object.keys(records.chunkRuntime)) {
@@ -470,13 +523,16 @@ class HotModuleReplacementPlugin {
470
523
  runtime
471
524
  }
472
525
  );
473
- hotUpdateMainContentByRuntime.set(runtime, {
474
- updatedChunkIds: new Set(),
475
- removedChunkIds: new Set(),
476
- removedModules: new Set(),
477
- filename,
478
- assetInfo
479
- });
526
+ hotUpdateMainContentByRuntime.set(
527
+ /** @type {string} */ (runtime),
528
+ {
529
+ updatedChunkIds: new Set(),
530
+ removedChunkIds: new Set(),
531
+ removedModules: new Set(),
532
+ filename,
533
+ assetInfo
534
+ }
535
+ );
480
536
  });
481
537
  if (hotUpdateMainContentByRuntime.size === 0) return;
482
538
 
@@ -506,6 +562,7 @@ class HotModuleReplacementPlugin {
506
562
  }
507
563
  }
508
564
 
565
+ /** @type {ChunkId | null} */
509
566
  let chunkId;
510
567
  let newModules;
511
568
  let newRuntimeModules;
@@ -554,9 +611,10 @@ class HotModuleReplacementPlugin {
554
611
  if (removedFromRuntime) {
555
612
  // chunk was removed from some runtimes
556
613
  forEachRuntime(removedFromRuntime, runtime => {
557
- hotUpdateMainContentByRuntime
558
- .get(runtime)
559
- .removedChunkIds.add(chunkId);
614
+ const item = hotUpdateMainContentByRuntime.get(
615
+ /** @type {string} */ (runtime)
616
+ );
617
+ item.removedChunkIds.add(/** @type {ChunkId} */ (chunkId));
560
618
  });
561
619
  // dispose modules from the chunk in these runtimes
562
620
  // where they are no longer in this runtime
@@ -597,12 +655,16 @@ class HotModuleReplacementPlugin {
597
655
  if (typeof moduleRuntime === "string") {
598
656
  if (moduleRuntime === runtime) return;
599
657
  } else if (moduleRuntime !== undefined) {
600
- if (moduleRuntime.has(runtime)) return;
658
+ if (
659
+ moduleRuntime.has(/** @type {string} */ (runtime))
660
+ )
661
+ return;
601
662
  }
602
663
  }
603
- hotUpdateMainContentByRuntime
604
- .get(runtime)
605
- .removedModules.add(module);
664
+ const item = hotUpdateMainContentByRuntime.get(
665
+ /** @type {string} */ (runtime)
666
+ );
667
+ item.removedModules.add(module);
606
668
  });
607
669
  }
608
670
  }
@@ -676,9 +738,10 @@ class HotModuleReplacementPlugin {
676
738
  }
677
739
  }
678
740
  forEachRuntime(newRuntime, runtime => {
679
- hotUpdateMainContentByRuntime
680
- .get(runtime)
681
- .updatedChunkIds.add(chunkId);
741
+ const item = hotUpdateMainContentByRuntime.get(
742
+ /** @type {string} */ (runtime)
743
+ );
744
+ item.updatedChunkIds.add(/** @type {ChunkId} */ (chunkId));
682
745
  });
683
746
  }
684
747
  }
@@ -28,7 +28,10 @@ class IgnorePlugin {
28
28
  validate(options);
29
29
  this.options = options;
30
30
 
31
- /** @private @type {Function} */
31
+ /**
32
+ * @private
33
+ * @type {Function}
34
+ */
32
35
  this.checkIgnore = this.checkIgnore.bind(this);
33
36
  }
34
37
 
@@ -40,7 +40,7 @@ const sortFragmentWithIndex = ([a, i], [b, j]) => {
40
40
  */
41
41
  class InitFragment {
42
42
  /**
43
- * @param {string | Source} content the source code that will be included as initialization code
43
+ * @param {string | Source | undefined} content the source code that will be included as initialization code
44
44
  * @param {number} stage category of initialization code (contribute to order)
45
45
  * @param {number} position position in the category (contribute to order)
46
46
  * @param {string=} key unique key to avoid emitting the same initialization code twice
@@ -56,7 +56,7 @@ class InitFragment {
56
56
 
57
57
  /**
58
58
  * @param {GenerateContext} context context
59
- * @returns {string | Source} the source code that will be included as initialization code
59
+ * @returns {string | Source | undefined} the source code that will be included as initialization code
60
60
  */
61
61
  getContent(context) {
62
62
  return this.content;
@@ -171,7 +171,9 @@ class InitFragment {
171
171
 
172
172
  makeSerializable(InitFragment, "webpack/lib/InitFragment");
173
173
 
174
- InitFragment.prototype.merge = undefined;
174
+ InitFragment.prototype.merge =
175
+ /** @type {TODO} */
176
+ (undefined);
175
177
 
176
178
  InitFragment.STAGE_CONSTANTS = 10;
177
179
  InitFragment.STAGE_ASYNC_BOUNDARY = 20;
@@ -12,17 +12,18 @@ const { compareModulesById } = require("./util/comparators");
12
12
  const { dirname, mkdirp } = require("./util/fs");
13
13
 
14
14
  /** @typedef {import("./Compiler")} Compiler */
15
+ /** @typedef {import("./Compiler").IntermediateFileSystem} IntermediateFileSystem */
15
16
  /** @typedef {import("./Module").BuildMeta} BuildMeta */
16
17
 
17
18
  /**
18
- * @typedef {Object} ManifestModuleData
19
+ * @typedef {object} ManifestModuleData
19
20
  * @property {string | number} id
20
21
  * @property {BuildMeta} buildMeta
21
22
  * @property {boolean | string[] | undefined} exports
22
23
  */
23
24
 
24
25
  /**
25
- * @typedef {Object} LibManifestPluginOptions
26
+ * @typedef {object} LibManifestPluginOptions
26
27
  * @property {string=} context Context of requests in the manifest file (defaults to the webpack context).
27
28
  * @property {boolean=} entryOnly If true, only entry points will be exposed (default: true).
28
29
  * @property {boolean=} format If true, manifest json file (output) will be formatted.
@@ -52,6 +53,8 @@ class LibManifestPlugin {
52
53
  },
53
54
  (compilation, callback) => {
54
55
  const moduleGraph = compilation.moduleGraph;
56
+ // store used paths to detect issue and output an error. #18200
57
+ const usedPaths = new Set();
55
58
  asyncLib.forEach(
56
59
  Array.from(compilation.chunks),
57
60
  (chunk, callback) => {
@@ -63,6 +66,11 @@ class LibManifestPlugin {
63
66
  const targetPath = compilation.getPath(this.options.path, {
64
67
  chunk
65
68
  });
69
+ if (usedPaths.has(targetPath)) {
70
+ callback(new Error(`each chunk must have a unique path`));
71
+ return;
72
+ }
73
+ usedPaths.add(targetPath);
66
74
  const name =
67
75
  this.options.name &&
68
76
  compilation.getPath(this.options.name, {
@@ -113,16 +121,16 @@ class LibManifestPlugin {
113
121
  ? JSON.stringify(manifest, null, 2)
114
122
  : JSON.stringify(manifest);
115
123
  const buffer = Buffer.from(manifestContent, "utf8");
124
+ const intermediateFileSystem =
125
+ /** @type {IntermediateFileSystem} */ (
126
+ compiler.intermediateFileSystem
127
+ );
116
128
  mkdirp(
117
- compiler.intermediateFileSystem,
118
- dirname(compiler.intermediateFileSystem, targetPath),
129
+ intermediateFileSystem,
130
+ dirname(intermediateFileSystem, targetPath),
119
131
  err => {
120
132
  if (err) return callback(err);
121
- compiler.intermediateFileSystem.writeFile(
122
- targetPath,
123
- buffer,
124
- callback
125
- );
133
+ intermediateFileSystem.writeFile(targetPath, buffer, callback);
126
134
  }
127
135
  );
128
136
  },
package/lib/Module.js CHANGED
@@ -45,7 +45,7 @@ const makeSerializable = require("./util/makeSerializable");
45
45
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
46
46
 
47
47
  /**
48
- * @typedef {Object} SourceContext
48
+ * @typedef {object} SourceContext
49
49
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
50
50
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
51
51
  * @property {ModuleGraph} moduleGraph the module graph
@@ -56,41 +56,43 @@ const makeSerializable = require("./util/makeSerializable");
56
56
 
57
57
  // TODO webpack 6: compilation will be required in CodeGenerationContext
58
58
  /**
59
- * @typedef {Object} CodeGenerationContext
59
+ * @typedef {object} CodeGenerationContext
60
60
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
61
61
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
62
62
  * @property {ModuleGraph} moduleGraph the module graph
63
63
  * @property {ChunkGraph} chunkGraph the chunk graph
64
- * @property {RuntimeSpec} runtime the runtime code should be generated for
65
- * @property {RuntimeSpec[]} [runtimes] the runtimes code should be generated for
64
+ * @property {RuntimeSpec} runtime the runtimes code should be generated for
66
65
  * @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
67
- * @property {CodeGenerationResults} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
66
+ * @property {CodeGenerationResults | undefined} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
68
67
  * @property {Compilation=} compilation the compilation
69
68
  * @property {ReadonlySet<string>=} sourceTypes source types
70
69
  */
71
70
 
72
71
  /**
73
- * @typedef {Object} ConcatenationBailoutReasonContext
72
+ * @typedef {object} ConcatenationBailoutReasonContext
74
73
  * @property {ModuleGraph} moduleGraph the module graph
75
74
  * @property {ChunkGraph} chunkGraph the chunk graph
76
75
  */
77
76
 
77
+ /** @typedef {Set<string>} RuntimeRequirements */
78
+ /** @typedef {ReadonlySet<string>} ReadOnlyRuntimeRequirements */
79
+
78
80
  /**
79
- * @typedef {Object} CodeGenerationResult
81
+ * @typedef {object} CodeGenerationResult
80
82
  * @property {Map<string, Source>} sources the resulting sources for all source types
81
83
  * @property {Map<string, any>=} data the resulting data for all source types
82
- * @property {ReadonlySet<string>} runtimeRequirements the runtime requirements
84
+ * @property {ReadOnlyRuntimeRequirements} runtimeRequirements the runtime requirements
83
85
  * @property {string=} hash a hash of the code generation result (will be automatically calculated from sources and runtimeRequirements if not provided)
84
86
  */
85
87
 
86
88
  /**
87
- * @typedef {Object} LibIdentOptions
89
+ * @typedef {object} LibIdentOptions
88
90
  * @property {string} context absolute context path to which lib ident is relative to
89
- * @property {Object=} associatedObjectForCache object for caching
91
+ * @property {object=} associatedObjectForCache object for caching
90
92
  */
91
93
 
92
94
  /**
93
- * @typedef {Object} KnownBuildMeta
95
+ * @typedef {object} KnownBuildMeta
94
96
  * @property {string=} moduleArgument
95
97
  * @property {string=} exportsArgument
96
98
  * @property {boolean=} strict
@@ -103,7 +105,7 @@ const makeSerializable = require("./util/makeSerializable");
103
105
  */
104
106
 
105
107
  /**
106
- * @typedef {Object} KnownBuildInfo
108
+ * @typedef {object} KnownBuildInfo
107
109
  * @property {boolean=} cacheable
108
110
  * @property {boolean=} parsed
109
111
  * @property {LazySet<string>=} fileDependencies
@@ -118,7 +120,7 @@ const makeSerializable = require("./util/makeSerializable");
118
120
  */
119
121
 
120
122
  /**
121
- * @typedef {Object} NeedBuildContext
123
+ * @typedef {object} NeedBuildContext
122
124
  * @property {Compilation} compilation
123
125
  * @property {FileSystemInfo} fileSystemInfo
124
126
  * @property {Map<string, string | Set<string>>} valueCacheVersions
@@ -128,7 +130,7 @@ const makeSerializable = require("./util/makeSerializable");
128
130
  /** @typedef {KnownBuildInfo & Record<string, any>} BuildInfo */
129
131
 
130
132
  /**
131
- * @typedef {Object} FactoryMeta
133
+ * @typedef {object} FactoryMeta
132
134
  * @property {boolean=} sideEffectFree
133
135
  */
134
136
 
@@ -270,6 +272,9 @@ class Module extends DependenciesBlock {
270
272
  ).setProfile(this, value);
271
273
  }
272
274
 
275
+ /**
276
+ * @returns {number | null} the pre order index
277
+ */
273
278
  get index() {
274
279
  return ModuleGraph.getModuleGraphForModule(
275
280
  this,
@@ -278,6 +283,9 @@ class Module extends DependenciesBlock {
278
283
  ).getPreOrderIndex(this);
279
284
  }
280
285
 
286
+ /**
287
+ * @param {number} value the pre order index
288
+ */
281
289
  set index(value) {
282
290
  ModuleGraph.getModuleGraphForModule(
283
291
  this,
@@ -286,6 +294,9 @@ class Module extends DependenciesBlock {
286
294
  ).setPreOrderIndex(this, value);
287
295
  }
288
296
 
297
+ /**
298
+ * @returns {number | null} the post order index
299
+ */
289
300
  get index2() {
290
301
  return ModuleGraph.getModuleGraphForModule(
291
302
  this,
@@ -294,6 +305,9 @@ class Module extends DependenciesBlock {
294
305
  ).getPostOrderIndex(this);
295
306
  }
296
307
 
308
+ /**
309
+ * @param {number} value the post order index
310
+ */
297
311
  set index2(value) {
298
312
  ModuleGraph.getModuleGraphForModule(
299
313
  this,
@@ -302,6 +316,9 @@ class Module extends DependenciesBlock {
302
316
  ).setPostOrderIndex(this, value);
303
317
  }
304
318
 
319
+ /**
320
+ * @returns {number | null} the depth
321
+ */
305
322
  get depth() {
306
323
  return ModuleGraph.getModuleGraphForModule(
307
324
  this,
@@ -310,6 +327,9 @@ class Module extends DependenciesBlock {
310
327
  ).getDepth(this);
311
328
  }
312
329
 
330
+ /**
331
+ * @param {number} value the depth
332
+ */
313
333
  set depth(value) {
314
334
  ModuleGraph.getModuleGraphForModule(
315
335
  this,
@@ -318,6 +338,9 @@ class Module extends DependenciesBlock {
318
338
  ).setDepth(this, value);
319
339
  }
320
340
 
341
+ /**
342
+ * @returns {Module | null | undefined} issuer
343
+ */
321
344
  get issuer() {
322
345
  return ModuleGraph.getModuleGraphForModule(
323
346
  this,
@@ -326,6 +349,9 @@ class Module extends DependenciesBlock {
326
349
  ).getIssuer(this);
327
350
  }
328
351
 
352
+ /**
353
+ * @param {Module | null} value issuer
354
+ */
329
355
  set issuer(value) {
330
356
  ModuleGraph.getModuleGraphForModule(
331
357
  this,
@@ -872,6 +898,7 @@ class Module extends DependenciesBlock {
872
898
  codeGenerationResults: undefined
873
899
  };
874
900
  const sources = this.codeGeneration(codeGenContext).sources;
901
+
875
902
  return type ? sources.get(type) : sources.get(first(this.getSourceTypes()));
876
903
  }
877
904
 
@@ -10,7 +10,7 @@
10
10
  /** @typedef {import("./Module")} Module */
11
11
 
12
12
  /**
13
- * @typedef {Object} ModuleFactoryResult
13
+ * @typedef {object} ModuleFactoryResult
14
14
  * @property {Module=} module the created module or unset if no module was created
15
15
  * @property {Set<string>=} fileDependencies
16
16
  * @property {Set<string>=} contextDependencies
@@ -19,14 +19,14 @@
19
19
  */
20
20
 
21
21
  /**
22
- * @typedef {Object} ModuleFactoryCreateDataContextInfo
22
+ * @typedef {object} ModuleFactoryCreateDataContextInfo
23
23
  * @property {string} issuer
24
24
  * @property {string | null=} issuerLayer
25
25
  * @property {string} compiler
26
26
  */
27
27
 
28
28
  /**
29
- * @typedef {Object} ModuleFactoryCreateData
29
+ * @typedef {object} ModuleFactoryCreateData
30
30
  * @property {ModuleFactoryCreateDataContextInfo} contextInfo
31
31
  * @property {ResolveOptions=} resolveOptions
32
32
  * @property {string} context