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
@@ -13,13 +13,18 @@ const compileBooleanMatcher = require("./util/compileBooleanMatcher");
13
13
  const propertyAccess = require("./util/propertyAccess");
14
14
  const { forEachRuntime, subtractRuntime } = require("./util/runtime");
15
15
 
16
+ /** @typedef {import("../declarations/WebpackOptions").Environment} Environment */
16
17
  /** @typedef {import("../declarations/WebpackOptions").OutputNormalized} OutputOptions */
17
18
  /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
19
+ /** @typedef {import("./Chunk")} Chunk */
18
20
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
19
21
  /** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
22
+ /** @typedef {import("./CodeGenerationResults").CodeGenerationResult} CodeGenerationResult */
20
23
  /** @typedef {import("./Compilation")} Compilation */
21
24
  /** @typedef {import("./Dependency")} Dependency */
22
25
  /** @typedef {import("./Module")} Module */
26
+ /** @typedef {import("./Module").BuildMeta} BuildMeta */
27
+ /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
23
28
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
24
29
  /** @typedef {import("./RequestShortener")} RequestShortener */
25
30
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
@@ -52,8 +57,8 @@ Module has these incoming connections: ${Array.from(
52
57
  };
53
58
 
54
59
  /**
55
- * @param {string|undefined} definition global object definition
56
- * @returns {string} save to use global object
60
+ * @param {string | undefined} definition global object definition
61
+ * @returns {string | undefined} save to use global object
57
62
  */
58
63
  function getGlobalObject(definition) {
59
64
  if (!definition) return definition;
@@ -82,8 +87,13 @@ class RuntimeTemplate {
82
87
  this.compilation = compilation;
83
88
  this.outputOptions = outputOptions || {};
84
89
  this.requestShortener = requestShortener;
85
- this.globalObject = getGlobalObject(outputOptions.globalObject);
86
- this.contentHashReplacement = "X".repeat(outputOptions.hashDigestLength);
90
+ this.globalObject =
91
+ /** @type {string} */
92
+ (getGlobalObject(outputOptions.globalObject));
93
+ this.contentHashReplacement = "X".repeat(
94
+ /** @type {NonNullable<OutputOptions["hashDigestLength"]>} */
95
+ (outputOptions.hashDigestLength)
96
+ );
87
97
  }
88
98
 
89
99
  isIIFE() {
@@ -95,51 +105,73 @@ class RuntimeTemplate {
95
105
  }
96
106
 
97
107
  supportsConst() {
98
- return this.outputOptions.environment.const;
108
+ return /** @type {Environment} */ (this.outputOptions.environment).const;
99
109
  }
100
110
 
101
111
  supportsArrowFunction() {
102
- return this.outputOptions.environment.arrowFunction;
112
+ return /** @type {Environment} */ (this.outputOptions.environment)
113
+ .arrowFunction;
103
114
  }
104
115
 
105
116
  supportsAsyncFunction() {
106
- return this.outputOptions.environment.asyncFunction;
117
+ return /** @type {Environment} */ (this.outputOptions.environment)
118
+ .asyncFunction;
107
119
  }
108
120
 
109
121
  supportsOptionalChaining() {
110
- return this.outputOptions.environment.optionalChaining;
122
+ return /** @type {Environment} */ (this.outputOptions.environment)
123
+ .optionalChaining;
111
124
  }
112
125
 
113
126
  supportsForOf() {
114
- return this.outputOptions.environment.forOf;
127
+ return /** @type {Environment} */ (this.outputOptions.environment).forOf;
115
128
  }
116
129
 
117
130
  supportsDestructuring() {
118
- return this.outputOptions.environment.destructuring;
131
+ return /** @type {Environment} */ (this.outputOptions.environment)
132
+ .destructuring;
119
133
  }
120
134
 
121
135
  supportsBigIntLiteral() {
122
- return this.outputOptions.environment.bigIntLiteral;
136
+ return /** @type {Environment} */ (this.outputOptions.environment)
137
+ .bigIntLiteral;
123
138
  }
124
139
 
125
140
  supportsDynamicImport() {
126
- return this.outputOptions.environment.dynamicImport;
141
+ return /** @type {Environment} */ (this.outputOptions.environment)
142
+ .dynamicImport;
127
143
  }
128
144
 
129
145
  supportsEcmaScriptModuleSyntax() {
130
- return this.outputOptions.environment.module;
146
+ return /** @type {Environment} */ (this.outputOptions.environment).module;
131
147
  }
132
148
 
133
149
  supportTemplateLiteral() {
134
- return this.outputOptions.environment.templateLiteral;
150
+ return /** @type {Environment} */ (this.outputOptions.environment)
151
+ .templateLiteral;
152
+ }
153
+
154
+ supportNodePrefixForCoreModules() {
155
+ return /** @type {Environment} */ (this.outputOptions.environment)
156
+ .nodePrefixForCoreModules;
135
157
  }
136
158
 
159
+ /**
160
+ * @param {string} returnValue return value
161
+ * @param {string} args arguments
162
+ * @returns {string} returning function
163
+ */
137
164
  returningFunction(returnValue, args = "") {
138
165
  return this.supportsArrowFunction()
139
166
  ? `(${args}) => (${returnValue})`
140
167
  : `function(${args}) { return ${returnValue}; }`;
141
168
  }
142
169
 
170
+ /**
171
+ * @param {string} args arguments
172
+ * @param {string | string[]} body body
173
+ * @returns {string} basic function
174
+ */
143
175
  basicFunction(args, body) {
144
176
  return this.supportsArrowFunction()
145
177
  ? `(${args}) => {\n${Template.indent(body)}\n}`
@@ -211,16 +243,29 @@ class RuntimeTemplate {
211
243
  : str;
212
244
  }
213
245
 
246
+ /**
247
+ * @param {string} expression expression
248
+ * @param {string} args arguments
249
+ * @returns {string} expression function code
250
+ */
214
251
  expressionFunction(expression, args = "") {
215
252
  return this.supportsArrowFunction()
216
253
  ? `(${args}) => (${expression})`
217
254
  : `function(${args}) { ${expression}; }`;
218
255
  }
219
256
 
257
+ /**
258
+ * @returns {string} empty function code
259
+ */
220
260
  emptyFunction() {
221
261
  return this.supportsArrowFunction() ? "x => {}" : "function() {}";
222
262
  }
223
263
 
264
+ /**
265
+ * @param {string[]} items items
266
+ * @param {string} value value
267
+ * @returns {string} destructure array code
268
+ */
224
269
  destructureArray(items, value) {
225
270
  return this.supportsDestructuring()
226
271
  ? `var [${items.join(", ")}] = ${value};`
@@ -229,6 +274,11 @@ class RuntimeTemplate {
229
274
  );
230
275
  }
231
276
 
277
+ /**
278
+ * @param {string[]} items items
279
+ * @param {string} value value
280
+ * @returns {string} destructure object code
281
+ */
232
282
  destructureObject(items, value) {
233
283
  return this.supportsDestructuring()
234
284
  ? `var {${items.join(", ")}} = ${value};`
@@ -237,10 +287,21 @@ class RuntimeTemplate {
237
287
  );
238
288
  }
239
289
 
290
+ /**
291
+ * @param {string} args arguments
292
+ * @param {string} body body
293
+ * @returns {string} IIFE code
294
+ */
240
295
  iife(args, body) {
241
296
  return `(${this.basicFunction(args, body)})()`;
242
297
  }
243
298
 
299
+ /**
300
+ * @param {string} variable variable
301
+ * @param {string} array array
302
+ * @param {string | string[]} body body
303
+ * @returns {string} for each code
304
+ */
244
305
  forEach(variable, array, body) {
245
306
  return this.supportsForOf()
246
307
  ? `for(const ${variable} of ${array}) {\n${Template.indent(body)}\n}`
@@ -333,10 +394,10 @@ class RuntimeTemplate {
333
394
  }
334
395
 
335
396
  /**
336
- * @param {Object} options options object
397
+ * @param {object} options options object
337
398
  * @param {ChunkGraph} options.chunkGraph the chunk graph
338
399
  * @param {Module} options.module the module
339
- * @param {string} options.request the request that should be printed as comment
400
+ * @param {string=} options.request the request that should be printed as comment
340
401
  * @param {string=} options.idExpr expression to use as id expression
341
402
  * @param {"expression" | "promise" | "statements"} options.type which kind of code should be returned
342
403
  * @returns {string} the code
@@ -370,10 +431,10 @@ class RuntimeTemplate {
370
431
  }
371
432
 
372
433
  /**
373
- * @param {Object} options options object
434
+ * @param {object} options options object
374
435
  * @param {Module} options.module the module
375
436
  * @param {ChunkGraph} options.chunkGraph the chunk graph
376
- * @param {string} options.request the request that should be printed as comment
437
+ * @param {string=} options.request the request that should be printed as comment
377
438
  * @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
378
439
  * @returns {string} the expression
379
440
  */
@@ -399,12 +460,12 @@ class RuntimeTemplate {
399
460
  }
400
461
 
401
462
  /**
402
- * @param {Object} options options object
463
+ * @param {object} options options object
403
464
  * @param {Module | null} options.module the module
404
465
  * @param {ChunkGraph} options.chunkGraph the chunk graph
405
- * @param {string} options.request the request that should be printed as comment
466
+ * @param {string=} options.request the request that should be printed as comment
406
467
  * @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
407
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
468
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
408
469
  * @returns {string} the expression
409
470
  */
410
471
  moduleRaw({ module, chunkGraph, request, weak, runtimeRequirements }) {
@@ -442,12 +503,12 @@ class RuntimeTemplate {
442
503
  }
443
504
 
444
505
  /**
445
- * @param {Object} options options object
506
+ * @param {object} options options object
446
507
  * @param {Module | null} options.module the module
447
508
  * @param {ChunkGraph} options.chunkGraph the chunk graph
448
509
  * @param {string} options.request the request that should be printed as comment
449
510
  * @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
450
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
511
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
451
512
  * @returns {string} the expression
452
513
  */
453
514
  moduleExports({ module, chunkGraph, request, weak, runtimeRequirements }) {
@@ -461,13 +522,13 @@ class RuntimeTemplate {
461
522
  }
462
523
 
463
524
  /**
464
- * @param {Object} options options object
525
+ * @param {object} options options object
465
526
  * @param {Module} options.module the module
466
527
  * @param {ChunkGraph} options.chunkGraph the chunk graph
467
528
  * @param {string} options.request the request that should be printed as comment
468
529
  * @param {boolean=} options.strict if the current module is in strict esm mode
469
530
  * @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
470
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
531
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
471
532
  * @returns {string} the expression
472
533
  */
473
534
  moduleNamespace({
@@ -530,7 +591,7 @@ class RuntimeTemplate {
530
591
  }
531
592
 
532
593
  /**
533
- * @param {Object} options options object
594
+ * @param {object} options options object
534
595
  * @param {ChunkGraph} options.chunkGraph the chunk graph
535
596
  * @param {AsyncDependenciesBlock=} options.block the current dependencies block
536
597
  * @param {Module} options.module the module
@@ -538,7 +599,7 @@ class RuntimeTemplate {
538
599
  * @param {string} options.message a message for the comment
539
600
  * @param {boolean=} options.strict if the current module is in strict esm mode
540
601
  * @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
541
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
602
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
542
603
  * @returns {string} the promise expression
543
604
  */
544
605
  moduleNamespacePromise({
@@ -680,11 +741,11 @@ class RuntimeTemplate {
680
741
  }
681
742
 
682
743
  /**
683
- * @param {Object} options options object
744
+ * @param {object} options options object
684
745
  * @param {ChunkGraph} options.chunkGraph the chunk graph
685
746
  * @param {RuntimeSpec=} options.runtime runtime for which this code will be generated
686
747
  * @param {RuntimeSpec | boolean=} options.runtimeCondition only execute the statement in some runtimes
687
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
748
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
688
749
  * @returns {string} expression
689
750
  */
690
751
  runtimeConditionExpression({
@@ -698,12 +759,16 @@ class RuntimeTemplate {
698
759
  /** @type {Set<string>} */
699
760
  const positiveRuntimeIds = new Set();
700
761
  forEachRuntime(runtimeCondition, runtime =>
701
- positiveRuntimeIds.add(`${chunkGraph.getRuntimeId(runtime)}`)
762
+ positiveRuntimeIds.add(
763
+ `${chunkGraph.getRuntimeId(/** @type {string} */ (runtime))}`
764
+ )
702
765
  );
703
766
  /** @type {Set<string>} */
704
767
  const negativeRuntimeIds = new Set();
705
768
  forEachRuntime(subtractRuntime(runtime, runtimeCondition), runtime =>
706
- negativeRuntimeIds.add(`${chunkGraph.getRuntimeId(runtime)}`)
769
+ negativeRuntimeIds.add(
770
+ `${chunkGraph.getRuntimeId(/** @type {string} */ (runtime))}`
771
+ )
707
772
  );
708
773
  runtimeRequirements.add(RuntimeGlobals.runtimeId);
709
774
  return compileBooleanMatcher.fromLists(
@@ -714,7 +779,7 @@ class RuntimeTemplate {
714
779
 
715
780
  /**
716
781
  *
717
- * @param {Object} options options object
782
+ * @param {object} options options object
718
783
  * @param {boolean=} options.update whether a new variable should be created or the existing one updated
719
784
  * @param {Module} options.module the module
720
785
  * @param {ChunkGraph} options.chunkGraph the chunk graph
@@ -722,7 +787,7 @@ class RuntimeTemplate {
722
787
  * @param {string} options.importVar name of the import variable
723
788
  * @param {Module} options.originModule module in which the statement is emitted
724
789
  * @param {boolean=} options.weak true, if this is a weak dependency
725
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
790
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
726
791
  * @returns {[string, string]} the import statement and the compat statement
727
792
  */
728
793
  importStatement({
@@ -774,7 +839,8 @@ class RuntimeTemplate {
774
839
 
775
840
  const exportsType = module.getExportsType(
776
841
  chunkGraph.moduleGraph,
777
- originModule.buildMeta.strictHarmonyModule
842
+ /** @type {BuildMeta} */
843
+ (originModule.buildMeta).strictHarmonyModule
778
844
  );
779
845
  runtimeRequirements.add(RuntimeGlobals.require);
780
846
  const importContent = `/* harmony import */ ${optDeclaration}${importVar} = ${RuntimeGlobals.require}(${moduleId});\n`;
@@ -790,7 +856,7 @@ class RuntimeTemplate {
790
856
  }
791
857
 
792
858
  /**
793
- * @param {Object} options options
859
+ * @param {object} options options
794
860
  * @param {ModuleGraph} options.moduleGraph the module graph
795
861
  * @param {Module} options.module the module
796
862
  * @param {string} options.request the request
@@ -803,7 +869,7 @@ class RuntimeTemplate {
803
869
  * @param {string} options.importVar the identifier name of the import variable
804
870
  * @param {InitFragment<TODO>[]} options.initFragments init fragments will be added here
805
871
  * @param {RuntimeSpec} options.runtime runtime for which this code will be generated
806
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
872
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
807
873
  * @returns {string} expression
808
874
  */
809
875
  exportFromImport({
@@ -831,7 +897,8 @@ class RuntimeTemplate {
831
897
  }
832
898
  const exportsType = module.getExportsType(
833
899
  moduleGraph,
834
- originModule.buildMeta.strictHarmonyModule
900
+ /** @type {BuildMeta} */
901
+ (originModule.buildMeta).strictHarmonyModule
835
902
  );
836
903
 
837
904
  if (defaultInterop) {
@@ -912,11 +979,11 @@ class RuntimeTemplate {
912
979
  }
913
980
 
914
981
  /**
915
- * @param {Object} options options
916
- * @param {AsyncDependenciesBlock} options.block the async block
982
+ * @param {object} options options
983
+ * @param {AsyncDependenciesBlock | undefined} options.block the async block
917
984
  * @param {string} options.message the message
918
985
  * @param {ChunkGraph} options.chunkGraph the chunk graph
919
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
986
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
920
987
  * @returns {string} expression
921
988
  */
922
989
  blockPromise({ block, message, chunkGraph, runtimeRequirements }) {
@@ -962,6 +1029,10 @@ class RuntimeTemplate {
962
1029
  runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
963
1030
  }
964
1031
 
1032
+ /**
1033
+ * @param {Chunk} chunk chunk
1034
+ * @returns {string} require chunk id code
1035
+ */
965
1036
  const requireChunkId = chunk =>
966
1037
  `${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)}${
967
1038
  fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
@@ -975,10 +1046,10 @@ class RuntimeTemplate {
975
1046
  }
976
1047
 
977
1048
  /**
978
- * @param {Object} options options
1049
+ * @param {object} options options
979
1050
  * @param {AsyncDependenciesBlock} options.block the async block
980
1051
  * @param {ChunkGraph} options.chunkGraph the chunk graph
981
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
1052
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
982
1053
  * @param {string=} options.request request string used originally
983
1054
  * @returns {string} expression
984
1055
  */
@@ -1007,10 +1078,10 @@ class RuntimeTemplate {
1007
1078
  }
1008
1079
 
1009
1080
  /**
1010
- * @param {Object} options options
1081
+ * @param {object} options options
1011
1082
  * @param {Dependency} options.dependency the dependency
1012
1083
  * @param {ChunkGraph} options.chunkGraph the chunk graph
1013
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
1084
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
1014
1085
  * @param {string=} options.request request string used originally
1015
1086
  * @returns {string} expression
1016
1087
  */
@@ -1028,9 +1099,9 @@ class RuntimeTemplate {
1028
1099
  }
1029
1100
 
1030
1101
  /**
1031
- * @param {Object} options options
1102
+ * @param {object} options options
1032
1103
  * @param {string} options.exportsArgument the name of the exports object
1033
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
1104
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
1034
1105
  * @returns {string} statement
1035
1106
  */
1036
1107
  defineEsModuleFlagStatement({ exportsArgument, runtimeRequirements }) {
@@ -1040,23 +1111,24 @@ class RuntimeTemplate {
1040
1111
  }
1041
1112
 
1042
1113
  /**
1043
- * @param {Object} options options object
1114
+ * @param {object} options options object
1044
1115
  * @param {Module} options.module the module
1045
- * @param {string} options.publicPath the public path
1046
1116
  * @param {RuntimeSpec=} options.runtime runtime
1047
1117
  * @param {CodeGenerationResults} options.codeGenerationResults the code generation results
1048
1118
  * @returns {string} the url of the asset
1049
1119
  */
1050
- assetUrl({ publicPath, runtime, module, codeGenerationResults }) {
1120
+ assetUrl({ runtime, module, codeGenerationResults }) {
1051
1121
  if (!module) {
1052
1122
  return "data:,";
1053
1123
  }
1054
1124
  const codeGen = codeGenerationResults.get(module, runtime);
1055
- const { data } = codeGen;
1125
+ const data = /** @type {NonNullable<CodeGenerationResult["data"]>} */ (
1126
+ codeGen.data
1127
+ );
1056
1128
  const url = data.get("url");
1057
1129
  if (url) return url.toString();
1058
- const filename = data.get("filename");
1059
- return publicPath + filename;
1130
+ const assetPath = data.get("assetPathForCss");
1131
+ return assetPath;
1060
1132
  }
1061
1133
  }
1062
1134
 
@@ -29,6 +29,7 @@ const { makePathsAbsolute } = require("./util/identifier");
29
29
  /** @typedef {import("./Module")} Module */
30
30
  /** @typedef {import("./NormalModule").SourceMap} SourceMap */
31
31
  /** @typedef {import("./util/Hash")} Hash */
32
+ /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
32
33
 
33
34
  const validate = createSchemaValidation(
34
35
  require("../schemas/plugins/SourceMapDevToolPlugin.check.js"),
@@ -165,7 +166,9 @@ class SourceMapDevToolPlugin {
165
166
  * @returns {void}
166
167
  */
167
168
  apply(compiler) {
168
- const outputFs = compiler.outputFileSystem;
169
+ const outputFs = /** @type {OutputFileSystem} */ (
170
+ compiler.outputFileSystem
171
+ );
169
172
  const sourceMapFilename = this.sourceMapFilename;
170
173
  const sourceMappingURLComment = this.sourceMappingURLComment;
171
174
  const moduleFilenameTemplate = this.moduleFilenameTemplate;
package/lib/Stats.js CHANGED
@@ -7,6 +7,7 @@
7
7
 
8
8
  /** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */
9
9
  /** @typedef {import("./Compilation")} Compilation */
10
+ /** @typedef {import("./Compilation").NormalizedStatsOptions} NormalizedStatsOptions */
10
11
  /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
11
12
 
12
13
  class Stats {
@@ -34,7 +35,7 @@ class Stats {
34
35
  */
35
36
  hasWarnings() {
36
37
  return (
37
- this.compilation.warnings.length > 0 ||
38
+ this.compilation.getWarnings().length > 0 ||
38
39
  this.compilation.children.some(child => child.getStats().hasWarnings())
39
40
  );
40
41
  }
@@ -58,7 +59,9 @@ class Stats {
58
59
  forToString: false
59
60
  });
60
61
 
61
- const statsFactory = this.compilation.createStatsFactory(options);
62
+ const statsFactory = this.compilation.createStatsFactory(
63
+ /** @type {NormalizedStatsOptions} */ (options)
64
+ );
62
65
 
63
66
  return statsFactory.create("compilation", this.compilation, {
64
67
  compilation: this.compilation
@@ -74,8 +77,12 @@ class Stats {
74
77
  forToString: true
75
78
  });
76
79
 
77
- const statsFactory = this.compilation.createStatsFactory(options);
78
- const statsPrinter = this.compilation.createStatsPrinter(options);
80
+ const statsFactory = this.compilation.createStatsFactory(
81
+ /** @type {NormalizedStatsOptions} */ (options)
82
+ );
83
+ const statsPrinter = this.compilation.createStatsPrinter(
84
+ /** @type {NormalizedStatsOptions} */ (options)
85
+ );
79
86
 
80
87
  const data = statsFactory.create("compilation", this.compilation, {
81
88
  compilation: this.compilation
package/lib/Template.js CHANGED
@@ -41,7 +41,7 @@ const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g;
41
41
  const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
42
42
 
43
43
  /**
44
- * @typedef {Object} RenderManifestOptions
44
+ * @typedef {object} RenderManifestOptions
45
45
  * @property {Chunk} chunk the chunk used to render
46
46
  * @property {string} hash
47
47
  * @property {string} fullHash
@@ -57,7 +57,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
57
57
  /** @typedef {RenderManifestEntryTemplated | RenderManifestEntryStatic} RenderManifestEntry */
58
58
 
59
59
  /**
60
- * @typedef {Object} RenderManifestEntryTemplated
60
+ * @typedef {object} RenderManifestEntryTemplated
61
61
  * @property {function(): Source} render
62
62
  * @property {string | function(PathData, AssetInfo=): string} filenameTemplate
63
63
  * @property {PathData=} pathOptions
@@ -68,7 +68,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
68
68
  */
69
69
 
70
70
  /**
71
- * @typedef {Object} RenderManifestEntryStatic
71
+ * @typedef {object} RenderManifestEntryStatic
72
72
  * @property {function(): Source} render
73
73
  * @property {string} filename
74
74
  * @property {AssetInfo} info
@@ -78,7 +78,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
78
78
  */
79
79
 
80
80
  /**
81
- * @typedef {Object} HasId
81
+ * @typedef {object} HasId
82
82
  * @property {number | string} id
83
83
  */
84
84
 
@@ -252,7 +252,7 @@ class Template {
252
252
  }
253
253
 
254
254
  /**
255
- * @typedef {Object} WithId
255
+ * @typedef {object} WithId
256
256
  * @property {string|number} id
257
257
  */
258
258