webpack 5.90.2 → 5.91.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 (182) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +5 -1
  3. package/lib/APIPlugin.js +8 -4
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +7 -1
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/ChunkGraph.js +32 -18
  9. package/lib/ChunkGroup.js +14 -14
  10. package/lib/CleanPlugin.js +7 -5
  11. package/lib/Compilation.js +263 -94
  12. package/lib/Compiler.js +199 -83
  13. package/lib/ConditionalInitFragment.js +4 -5
  14. package/lib/ContextModule.js +4 -1
  15. package/lib/ContextModuleFactory.js +4 -2
  16. package/lib/ContextReplacementPlugin.js +3 -2
  17. package/lib/CssModule.js +0 -3
  18. package/lib/DefinePlugin.js +4 -2
  19. package/lib/DelegatedModule.js +2 -1
  20. package/lib/Dependency.js +4 -2
  21. package/lib/DependencyTemplate.js +7 -2
  22. package/lib/DllModule.js +3 -1
  23. package/lib/DllReferencePlugin.js +6 -2
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/ExportsInfo.js +1 -4
  28. package/lib/ExternalModule.js +120 -25
  29. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  30. package/lib/FileSystemInfo.js +1 -1
  31. package/lib/Generator.js +2 -1
  32. package/lib/HookWebpackError.js +2 -2
  33. package/lib/InitFragment.js +5 -3
  34. package/lib/LibManifestPlugin.js +15 -7
  35. package/lib/Module.js +54 -5
  36. package/lib/ModuleFilenameHelpers.js +1 -1
  37. package/lib/ModuleGraph.js +56 -27
  38. package/lib/ModuleGraphConnection.js +2 -1
  39. package/lib/MultiCompiler.js +61 -17
  40. package/lib/NodeStuffPlugin.js +14 -3
  41. package/lib/NormalModule.js +239 -86
  42. package/lib/NormalModuleFactory.js +163 -32
  43. package/lib/NormalModuleReplacementPlugin.js +5 -1
  44. package/lib/ProvidePlugin.js +3 -1
  45. package/lib/RawModule.js +4 -2
  46. package/lib/ResolverFactory.js +5 -1
  47. package/lib/RuntimeModule.js +6 -5
  48. package/lib/RuntimePlugin.js +1 -0
  49. package/lib/RuntimeTemplate.js +102 -34
  50. package/lib/SourceMapDevToolPlugin.js +4 -1
  51. package/lib/Stats.js +12 -5
  52. package/lib/TemplatedPathPlugin.js +32 -6
  53. package/lib/Watching.js +67 -60
  54. package/lib/WebpackError.js +6 -6
  55. package/lib/WebpackOptionsApply.js +18 -5
  56. package/lib/asset/RawDataUrlModule.js +5 -2
  57. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  58. package/lib/buildChunkGraph.js +220 -392
  59. package/lib/cache/IdleFileCachePlugin.js +8 -3
  60. package/lib/cache/MemoryCachePlugin.js +1 -1
  61. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  62. package/lib/cache/PackFileCacheStrategy.js +49 -16
  63. package/lib/cache/ResolverCachePlugin.js +14 -6
  64. package/lib/cache/getLazyHashedEtag.js +1 -1
  65. package/lib/config/defaults.js +24 -1
  66. package/lib/config/normalization.js +3 -1
  67. package/lib/container/ContainerEntryDependency.js +2 -1
  68. package/lib/container/ContainerEntryModule.js +5 -2
  69. package/lib/container/ContainerPlugin.js +14 -10
  70. package/lib/container/FallbackModule.js +3 -2
  71. package/lib/container/RemoteModule.js +2 -1
  72. package/lib/container/RemoteRuntimeModule.js +12 -3
  73. package/lib/css/CssExportsGenerator.js +34 -17
  74. package/lib/css/CssGenerator.js +20 -2
  75. package/lib/css/CssLoadingRuntimeModule.js +212 -96
  76. package/lib/css/CssModulesPlugin.js +47 -13
  77. package/lib/debug/ProfilingPlugin.js +27 -2
  78. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  79. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  80. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  81. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  82. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  83. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  84. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  85. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  86. package/lib/dependencies/ContextElementDependency.js +8 -1
  87. package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
  88. package/lib/dependencies/CssUrlDependency.js +5 -3
  89. package/lib/dependencies/ExportsInfoDependency.js +4 -3
  90. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  91. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  92. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  93. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  94. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  95. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  96. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  97. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
  98. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  99. package/lib/dependencies/HarmonyImportSpecifierDependency.js +21 -10
  100. package/lib/dependencies/ImportDependency.js +9 -2
  101. package/lib/dependencies/ImportEagerDependency.js +4 -2
  102. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  103. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  104. package/lib/dependencies/ImportParserPlugin.js +12 -4
  105. package/lib/dependencies/ImportWeakDependency.js +4 -2
  106. package/lib/dependencies/LoaderDependency.js +2 -1
  107. package/lib/dependencies/LoaderImportDependency.js +2 -1
  108. package/lib/dependencies/ModuleDependency.js +4 -5
  109. package/lib/dependencies/PureExpressionDependency.js +4 -1
  110. package/lib/dependencies/RequireContextPlugin.js +1 -1
  111. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  112. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  113. package/lib/dependencies/URLDependency.js +7 -4
  114. package/lib/dependencies/WorkerDependency.js +1 -1
  115. package/lib/dependencies/WorkerPlugin.js +6 -5
  116. package/lib/dependencies/getFunctionExpression.js +3 -1
  117. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
  118. package/lib/hmr/LazyCompilationPlugin.js +2 -1
  119. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  120. package/lib/javascript/ChunkHelpers.js +2 -2
  121. package/lib/javascript/JavascriptParser.js +169 -57
  122. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  123. package/lib/javascript/StartupHelpers.js +22 -5
  124. package/lib/logging/Logger.js +27 -2
  125. package/lib/logging/createConsoleLogger.js +11 -7
  126. package/lib/node/NodeEnvironmentPlugin.js +13 -7
  127. package/lib/node/NodeWatchFileSystem.js +37 -26
  128. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  129. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  130. package/lib/node/nodeConsole.js +24 -1
  131. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  132. package/lib/optimize/ConcatenatedModule.js +140 -55
  133. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  134. package/lib/optimize/InnerGraph.js +7 -2
  135. package/lib/optimize/InnerGraphPlugin.js +36 -13
  136. package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
  137. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  138. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  139. package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
  140. package/lib/optimize/SplitChunksPlugin.js +2 -2
  141. package/lib/performance/SizeLimitsPlugin.js +11 -0
  142. package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
  143. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  144. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  145. package/lib/serialization/FileMiddleware.js +1 -0
  146. package/lib/serialization/ObjectMiddleware.js +2 -0
  147. package/lib/serialization/Serializer.js +19 -0
  148. package/lib/sharing/ConsumeSharedModule.js +3 -2
  149. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  150. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  151. package/lib/sharing/ProvideSharedModule.js +2 -1
  152. package/lib/sharing/ProvideSharedPlugin.js +12 -5
  153. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  154. package/lib/sharing/utils.js +13 -6
  155. package/lib/util/StackedCacheMap.js +26 -0
  156. package/lib/util/WeakTupleMap.js +57 -13
  157. package/lib/util/cleverMerge.js +24 -11
  158. package/lib/util/comparators.js +34 -14
  159. package/lib/util/conventions.js +129 -0
  160. package/lib/util/fs.js +379 -65
  161. package/lib/util/hash/BatchedHash.js +3 -0
  162. package/lib/util/hash/xxhash64.js +2 -2
  163. package/lib/util/memoize.js +2 -0
  164. package/lib/util/runtime.js +1 -1
  165. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  166. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
  167. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
  168. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -1
  169. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  170. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/webpack.js +11 -5
  172. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  173. package/package.json +25 -26
  174. package/schemas/WebpackOptions.check.js +1 -1
  175. package/schemas/WebpackOptions.json +69 -8
  176. package/schemas/plugins/BannerPlugin.check.js +1 -1
  177. package/schemas/plugins/BannerPlugin.json +5 -1
  178. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  179. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  180. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  181. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  182. package/types.d.ts +1772 -673
@@ -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,68 @@ 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;
135
152
  }
136
153
 
154
+ /**
155
+ * @param {string} returnValue return value
156
+ * @param {string} args arguments
157
+ * @returns {string} returning function
158
+ */
137
159
  returningFunction(returnValue, args = "") {
138
160
  return this.supportsArrowFunction()
139
161
  ? `(${args}) => (${returnValue})`
140
162
  : `function(${args}) { return ${returnValue}; }`;
141
163
  }
142
164
 
165
+ /**
166
+ * @param {string} args arguments
167
+ * @param {string | string[]} body body
168
+ * @returns {string} basic function
169
+ */
143
170
  basicFunction(args, body) {
144
171
  return this.supportsArrowFunction()
145
172
  ? `(${args}) => {\n${Template.indent(body)}\n}`
@@ -211,16 +238,29 @@ class RuntimeTemplate {
211
238
  : str;
212
239
  }
213
240
 
241
+ /**
242
+ * @param {string} expression expression
243
+ * @param {string} args arguments
244
+ * @returns {string} expression function code
245
+ */
214
246
  expressionFunction(expression, args = "") {
215
247
  return this.supportsArrowFunction()
216
248
  ? `(${args}) => (${expression})`
217
249
  : `function(${args}) { ${expression}; }`;
218
250
  }
219
251
 
252
+ /**
253
+ * @returns {string} empty function code
254
+ */
220
255
  emptyFunction() {
221
256
  return this.supportsArrowFunction() ? "x => {}" : "function() {}";
222
257
  }
223
258
 
259
+ /**
260
+ * @param {string[]} items items
261
+ * @param {string} value value
262
+ * @returns {string} destructure array code
263
+ */
224
264
  destructureArray(items, value) {
225
265
  return this.supportsDestructuring()
226
266
  ? `var [${items.join(", ")}] = ${value};`
@@ -229,6 +269,11 @@ class RuntimeTemplate {
229
269
  );
230
270
  }
231
271
 
272
+ /**
273
+ * @param {string[]} items items
274
+ * @param {string} value value
275
+ * @returns {string} destructure object code
276
+ */
232
277
  destructureObject(items, value) {
233
278
  return this.supportsDestructuring()
234
279
  ? `var {${items.join(", ")}} = ${value};`
@@ -237,10 +282,21 @@ class RuntimeTemplate {
237
282
  );
238
283
  }
239
284
 
285
+ /**
286
+ * @param {string} args arguments
287
+ * @param {string} body body
288
+ * @returns {string} IIFE code
289
+ */
240
290
  iife(args, body) {
241
291
  return `(${this.basicFunction(args, body)})()`;
242
292
  }
243
293
 
294
+ /**
295
+ * @param {string} variable variable
296
+ * @param {string} array array
297
+ * @param {string | string[]} body body
298
+ * @returns {string} for each code
299
+ */
244
300
  forEach(variable, array, body) {
245
301
  return this.supportsForOf()
246
302
  ? `for(const ${variable} of ${array}) {\n${Template.indent(body)}\n}`
@@ -336,7 +392,7 @@ class RuntimeTemplate {
336
392
  * @param {Object} options options object
337
393
  * @param {ChunkGraph} options.chunkGraph the chunk graph
338
394
  * @param {Module} options.module the module
339
- * @param {string} options.request the request that should be printed as comment
395
+ * @param {string=} options.request the request that should be printed as comment
340
396
  * @param {string=} options.idExpr expression to use as id expression
341
397
  * @param {"expression" | "promise" | "statements"} options.type which kind of code should be returned
342
398
  * @returns {string} the code
@@ -373,7 +429,7 @@ class RuntimeTemplate {
373
429
  * @param {Object} options options object
374
430
  * @param {Module} options.module the module
375
431
  * @param {ChunkGraph} options.chunkGraph the chunk graph
376
- * @param {string} options.request the request that should be printed as comment
432
+ * @param {string=} options.request the request that should be printed as comment
377
433
  * @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
378
434
  * @returns {string} the expression
379
435
  */
@@ -402,9 +458,9 @@ class RuntimeTemplate {
402
458
  * @param {Object} options options object
403
459
  * @param {Module | null} options.module the module
404
460
  * @param {ChunkGraph} options.chunkGraph the chunk graph
405
- * @param {string} options.request the request that should be printed as comment
461
+ * @param {string=} options.request the request that should be printed as comment
406
462
  * @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
463
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
408
464
  * @returns {string} the expression
409
465
  */
410
466
  moduleRaw({ module, chunkGraph, request, weak, runtimeRequirements }) {
@@ -447,7 +503,7 @@ class RuntimeTemplate {
447
503
  * @param {ChunkGraph} options.chunkGraph the chunk graph
448
504
  * @param {string} options.request the request that should be printed as comment
449
505
  * @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
506
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
451
507
  * @returns {string} the expression
452
508
  */
453
509
  moduleExports({ module, chunkGraph, request, weak, runtimeRequirements }) {
@@ -467,7 +523,7 @@ class RuntimeTemplate {
467
523
  * @param {string} options.request the request that should be printed as comment
468
524
  * @param {boolean=} options.strict if the current module is in strict esm mode
469
525
  * @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
526
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
471
527
  * @returns {string} the expression
472
528
  */
473
529
  moduleNamespace({
@@ -538,7 +594,7 @@ class RuntimeTemplate {
538
594
  * @param {string} options.message a message for the comment
539
595
  * @param {boolean=} options.strict if the current module is in strict esm mode
540
596
  * @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
597
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
542
598
  * @returns {string} the promise expression
543
599
  */
544
600
  moduleNamespacePromise({
@@ -684,7 +740,7 @@ class RuntimeTemplate {
684
740
  * @param {ChunkGraph} options.chunkGraph the chunk graph
685
741
  * @param {RuntimeSpec=} options.runtime runtime for which this code will be generated
686
742
  * @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
743
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
688
744
  * @returns {string} expression
689
745
  */
690
746
  runtimeConditionExpression({
@@ -698,12 +754,16 @@ class RuntimeTemplate {
698
754
  /** @type {Set<string>} */
699
755
  const positiveRuntimeIds = new Set();
700
756
  forEachRuntime(runtimeCondition, runtime =>
701
- positiveRuntimeIds.add(`${chunkGraph.getRuntimeId(runtime)}`)
757
+ positiveRuntimeIds.add(
758
+ `${chunkGraph.getRuntimeId(/** @type {string} */ (runtime))}`
759
+ )
702
760
  );
703
761
  /** @type {Set<string>} */
704
762
  const negativeRuntimeIds = new Set();
705
763
  forEachRuntime(subtractRuntime(runtime, runtimeCondition), runtime =>
706
- negativeRuntimeIds.add(`${chunkGraph.getRuntimeId(runtime)}`)
764
+ negativeRuntimeIds.add(
765
+ `${chunkGraph.getRuntimeId(/** @type {string} */ (runtime))}`
766
+ )
707
767
  );
708
768
  runtimeRequirements.add(RuntimeGlobals.runtimeId);
709
769
  return compileBooleanMatcher.fromLists(
@@ -722,7 +782,7 @@ class RuntimeTemplate {
722
782
  * @param {string} options.importVar name of the import variable
723
783
  * @param {Module} options.originModule module in which the statement is emitted
724
784
  * @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
785
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
726
786
  * @returns {[string, string]} the import statement and the compat statement
727
787
  */
728
788
  importStatement({
@@ -774,7 +834,8 @@ class RuntimeTemplate {
774
834
 
775
835
  const exportsType = module.getExportsType(
776
836
  chunkGraph.moduleGraph,
777
- originModule.buildMeta.strictHarmonyModule
837
+ /** @type {BuildMeta} */
838
+ (originModule.buildMeta).strictHarmonyModule
778
839
  );
779
840
  runtimeRequirements.add(RuntimeGlobals.require);
780
841
  const importContent = `/* harmony import */ ${optDeclaration}${importVar} = ${RuntimeGlobals.require}(${moduleId});\n`;
@@ -803,7 +864,7 @@ class RuntimeTemplate {
803
864
  * @param {string} options.importVar the identifier name of the import variable
804
865
  * @param {InitFragment<TODO>[]} options.initFragments init fragments will be added here
805
866
  * @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
867
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
807
868
  * @returns {string} expression
808
869
  */
809
870
  exportFromImport({
@@ -831,7 +892,8 @@ class RuntimeTemplate {
831
892
  }
832
893
  const exportsType = module.getExportsType(
833
894
  moduleGraph,
834
- originModule.buildMeta.strictHarmonyModule
895
+ /** @type {BuildMeta} */
896
+ (originModule.buildMeta).strictHarmonyModule
835
897
  );
836
898
 
837
899
  if (defaultInterop) {
@@ -913,10 +975,10 @@ class RuntimeTemplate {
913
975
 
914
976
  /**
915
977
  * @param {Object} options options
916
- * @param {AsyncDependenciesBlock} options.block the async block
978
+ * @param {AsyncDependenciesBlock | undefined} options.block the async block
917
979
  * @param {string} options.message the message
918
980
  * @param {ChunkGraph} options.chunkGraph the chunk graph
919
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
981
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
920
982
  * @returns {string} expression
921
983
  */
922
984
  blockPromise({ block, message, chunkGraph, runtimeRequirements }) {
@@ -962,6 +1024,10 @@ class RuntimeTemplate {
962
1024
  runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
963
1025
  }
964
1026
 
1027
+ /**
1028
+ * @param {Chunk} chunk chunk
1029
+ * @returns {string} require chunk id code
1030
+ */
965
1031
  const requireChunkId = chunk =>
966
1032
  `${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)}${
967
1033
  fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
@@ -978,7 +1044,7 @@ class RuntimeTemplate {
978
1044
  * @param {Object} options options
979
1045
  * @param {AsyncDependenciesBlock} options.block the async block
980
1046
  * @param {ChunkGraph} options.chunkGraph the chunk graph
981
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
1047
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
982
1048
  * @param {string=} options.request request string used originally
983
1049
  * @returns {string} expression
984
1050
  */
@@ -1010,7 +1076,7 @@ class RuntimeTemplate {
1010
1076
  * @param {Object} options options
1011
1077
  * @param {Dependency} options.dependency the dependency
1012
1078
  * @param {ChunkGraph} options.chunkGraph the chunk graph
1013
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
1079
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
1014
1080
  * @param {string=} options.request request string used originally
1015
1081
  * @returns {string} expression
1016
1082
  */
@@ -1030,7 +1096,7 @@ class RuntimeTemplate {
1030
1096
  /**
1031
1097
  * @param {Object} options options
1032
1098
  * @param {string} options.exportsArgument the name of the exports object
1033
- * @param {Set<string>} options.runtimeRequirements if set, will be filled with runtime requirements
1099
+ * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
1034
1100
  * @returns {string} statement
1035
1101
  */
1036
1102
  defineEsModuleFlagStatement({ exportsArgument, runtimeRequirements }) {
@@ -1052,7 +1118,9 @@ class RuntimeTemplate {
1052
1118
  return "data:,";
1053
1119
  }
1054
1120
  const codeGen = codeGenerationResults.get(module, runtime);
1055
- const { data } = codeGen;
1121
+ const data = /** @type {NonNullable<CodeGenerationResult["data"]>} */ (
1122
+ codeGen.data
1123
+ );
1056
1124
  const url = data.get("url");
1057
1125
  if (url) return url.toString();
1058
1126
  const filename = data.get("filename");
@@ -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 {
@@ -50,7 +51,7 @@ class Stats {
50
51
  }
51
52
 
52
53
  /**
53
- * @param {(string|StatsOptions)=} options stats options
54
+ * @param {(string | boolean | StatsOptions)=} options stats options
54
55
  * @returns {StatsCompilation} json output
55
56
  */
56
57
  toJson(options) {
@@ -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
@@ -66,7 +69,7 @@ class Stats {
66
69
  }
67
70
 
68
71
  /**
69
- * @param {(string|StatsOptions)=} options stats options
72
+ * @param {(string | boolean | StatsOptions)=} options stats options
70
73
  * @returns {string} string output
71
74
  */
72
75
  toString(options) {
@@ -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
@@ -12,19 +12,26 @@ const Chunk = require("./Chunk");
12
12
  const Module = require("./Module");
13
13
  const { parseResource } = require("./util/identifier");
14
14
 
15
+ /** @typedef {import("./ChunkGraph")} ChunkGraph */
15
16
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
16
17
  /** @typedef {import("./Compilation").PathData} PathData */
17
18
  /** @typedef {import("./Compiler")} Compiler */
18
19
 
19
20
  const REGEXP = /\[\\*([\w:]+)\\*\]/gi;
20
21
 
22
+ /**
23
+ * @param {string | number} id id
24
+ * @returns {string | number} result
25
+ */
21
26
  const prepareId = id => {
22
27
  if (typeof id !== "string") return id;
23
28
 
24
29
  if (/^"\s\+*.*\+\s*"$/.test(id)) {
25
30
  const match = /^"\s\+*\s*(.*)\s*\+\s*"$/.exec(id);
26
31
 
27
- return `" + (${match[1]} + "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_") + "`;
32
+ return `" + (${
33
+ /** @type {string[]} */ (match)[1]
34
+ } + "").replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_") + "`;
28
35
  }
29
36
 
30
37
  return id.replace(/(^[.-]|[^a-zA-Z0-9_-])+/g, "_");
@@ -58,7 +65,15 @@ const hashLength = (replacer, handler, assetInfo, hashName) => {
58
65
  return fn;
59
66
  };
60
67
 
68
+ /** @typedef {(match: string, arg?: string, input?: string) => string} Replacer */
69
+
70
+ /**
71
+ * @param {string | number | null | undefined | (() => string | number | null | undefined)} value value
72
+ * @param {boolean=} allowEmpty allow empty
73
+ * @returns {Replacer} replacer
74
+ */
61
75
  const replacer = (value, allowEmpty) => {
76
+ /** @type {Replacer} */
62
77
  const fn = (match, arg, input) => {
63
78
  if (typeof value === "function") {
64
79
  value = value();
@@ -81,6 +96,12 @@ const replacer = (value, allowEmpty) => {
81
96
 
82
97
  const deprecationCache = new Map();
83
98
  const deprecatedFunction = (() => () => {})();
99
+ /**
100
+ * @param {Function} fn function
101
+ * @param {string} message message
102
+ * @param {string} code code
103
+ * @returns {function(...any[]): void} function with deprecation output
104
+ */
84
105
  const deprecated = (fn, message, code) => {
85
106
  let d = deprecationCache.get(message);
86
107
  if (d === undefined) {
@@ -227,7 +248,7 @@ const replacePathVariables = (path, data, assetInfo) => {
227
248
  ),
228
249
  data.contentHashWithLength ||
229
250
  ("contentHashWithLength" in chunk && chunk.contentHashWithLength
230
- ? chunk.contentHashWithLength[contentHashType]
251
+ ? chunk.contentHashWithLength[/** @type {string} */ (contentHashType)]
231
252
  : undefined),
232
253
  assetInfo,
233
254
  "contenthash"
@@ -255,13 +276,18 @@ const replacePathVariables = (path, data, assetInfo) => {
255
276
 
256
277
  const idReplacer = replacer(() =>
257
278
  prepareId(
258
- module instanceof Module ? chunkGraph.getModuleId(module) : module.id
279
+ module instanceof Module
280
+ ? /** @type {ChunkGraph} */ (chunkGraph).getModuleId(module)
281
+ : module.id
259
282
  )
260
283
  );
261
284
  const moduleHashReplacer = hashLength(
262
285
  replacer(() =>
263
286
  module instanceof Module
264
- ? chunkGraph.getRenderedModuleHash(module, data.runtime)
287
+ ? /** @type {ChunkGraph} */ (chunkGraph).getRenderedModuleHash(
288
+ module,
289
+ data.runtime
290
+ )
265
291
  : module.hash
266
292
  ),
267
293
  "hashWithLength" in module ? module.hashWithLength : undefined,
@@ -269,7 +295,7 @@ const replacePathVariables = (path, data, assetInfo) => {
269
295
  "modulehash"
270
296
  );
271
297
  const contentHashReplacer = hashLength(
272
- replacer(data.contentHash),
298
+ replacer(/** @type {string} */ (data.contentHash)),
273
299
  undefined,
274
300
  assetInfo,
275
301
  "contenthash"
@@ -300,7 +326,7 @@ const replacePathVariables = (path, data, assetInfo) => {
300
326
  if (typeof data.runtime === "string") {
301
327
  replacements.set(
302
328
  "runtime",
303
- replacer(() => prepareId(data.runtime))
329
+ replacer(() => prepareId(/** @type {string} */ (data.runtime)))
304
330
  );
305
331
  } else {
306
332
  replacements.set("runtime", replacer("_"));