webpack 5.98.0 → 5.99.1

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.
Files changed (251) hide show
  1. package/README.md +7 -3
  2. package/lib/AsyncDependenciesBlock.js +3 -1
  3. package/lib/BannerPlugin.js +1 -1
  4. package/lib/Cache.js +9 -7
  5. package/lib/CacheFacade.js +5 -5
  6. package/lib/Chunk.js +2 -2
  7. package/lib/ChunkGraph.js +21 -16
  8. package/lib/ChunkTemplate.js +6 -6
  9. package/lib/CleanPlugin.js +10 -10
  10. package/lib/CodeGenerationResults.js +4 -3
  11. package/lib/CompatibilityPlugin.js +4 -1
  12. package/lib/Compilation.js +326 -152
  13. package/lib/Compiler.js +13 -18
  14. package/lib/ConditionalInitFragment.js +1 -1
  15. package/lib/ConstPlugin.js +5 -3
  16. package/lib/ContextModule.js +4 -2
  17. package/lib/ContextModuleFactory.js +3 -3
  18. package/lib/ContextReplacementPlugin.js +43 -16
  19. package/lib/DefinePlugin.js +25 -24
  20. package/lib/DelegatedModule.js +4 -2
  21. package/lib/DelegatedModuleFactoryPlugin.js +2 -1
  22. package/lib/Dependency.js +19 -13
  23. package/lib/DependencyTemplates.js +4 -3
  24. package/lib/DllModule.js +4 -2
  25. package/lib/DllModuleFactory.js +2 -2
  26. package/lib/DllReferencePlugin.js +2 -1
  27. package/lib/DynamicEntryPlugin.js +1 -1
  28. package/lib/EnvironmentPlugin.js +4 -2
  29. package/lib/ExportsInfo.js +72 -40
  30. package/lib/ExternalModule.js +14 -5
  31. package/lib/ExternalModuleFactoryPlugin.js +24 -12
  32. package/lib/FileSystemInfo.js +129 -94
  33. package/lib/FlagDependencyExportsPlugin.js +6 -4
  34. package/lib/FlagDependencyUsagePlugin.js +1 -1
  35. package/lib/Generator.js +29 -1
  36. package/lib/HookWebpackError.js +2 -2
  37. package/lib/HotModuleReplacementPlugin.js +3 -9
  38. package/lib/IgnoreErrorModuleFactory.js +2 -2
  39. package/lib/IgnorePlugin.js +0 -5
  40. package/lib/InitFragment.js +1 -1
  41. package/lib/LoaderOptionsPlugin.js +8 -5
  42. package/lib/MainTemplate.js +7 -7
  43. package/lib/Module.js +40 -17
  44. package/lib/ModuleBuildError.js +3 -1
  45. package/lib/ModuleDependencyError.js +4 -3
  46. package/lib/ModuleDependencyWarning.js +4 -3
  47. package/lib/ModuleFactory.js +9 -3
  48. package/lib/ModuleFilenameHelpers.js +13 -13
  49. package/lib/ModuleGraph.js +20 -14
  50. package/lib/ModuleGraphConnection.js +7 -13
  51. package/lib/ModuleNotFoundError.js +1 -1
  52. package/lib/ModuleParseError.js +2 -1
  53. package/lib/ModuleSourceTypesConstants.js +11 -0
  54. package/lib/ModuleTemplate.js +5 -5
  55. package/lib/ModuleTypeConstants.js +15 -0
  56. package/lib/MultiCompiler.js +4 -4
  57. package/lib/MultiStats.js +1 -1
  58. package/lib/NormalModule.js +101 -54
  59. package/lib/NormalModuleFactory.js +38 -33
  60. package/lib/NormalModuleReplacementPlugin.js +3 -2
  61. package/lib/NullFactory.js +2 -2
  62. package/lib/Parser.js +4 -3
  63. package/lib/ProgressPlugin.js +1 -2
  64. package/lib/RawModule.js +4 -2
  65. package/lib/RecordIdsPlugin.js +6 -2
  66. package/lib/RequestShortener.js +3 -1
  67. package/lib/ResolverFactory.js +12 -9
  68. package/lib/RuntimeModule.js +4 -2
  69. package/lib/RuntimeTemplate.js +2 -1
  70. package/lib/SelfModuleFactory.js +2 -2
  71. package/lib/SourceMapDevToolPlugin.js +0 -8
  72. package/lib/Template.js +6 -5
  73. package/lib/TemplatedPathPlugin.js +15 -12
  74. package/lib/WebpackOptionsApply.js +1 -1
  75. package/lib/asset/AssetGenerator.js +237 -170
  76. package/lib/asset/AssetModulesPlugin.js +50 -8
  77. package/lib/asset/AssetSourceGenerator.js +18 -0
  78. package/lib/asset/RawDataUrlModule.js +4 -2
  79. package/lib/buildChunkGraph.js +14 -4
  80. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  81. package/lib/cache/PackFileCacheStrategy.js +137 -121
  82. package/lib/cache/ResolverCachePlugin.js +15 -7
  83. package/lib/cache/getLazyHashedEtag.js +4 -3
  84. package/lib/cli.js +23 -15
  85. package/lib/config/defaults.js +93 -26
  86. package/lib/config/normalization.js +14 -13
  87. package/lib/config/target.js +8 -8
  88. package/lib/container/ContainerEntryModule.js +4 -2
  89. package/lib/container/ContainerEntryModuleFactory.js +2 -2
  90. package/lib/container/FallbackModule.js +4 -2
  91. package/lib/container/FallbackModuleFactory.js +2 -2
  92. package/lib/container/RemoteModule.js +4 -2
  93. package/lib/container/options.js +5 -5
  94. package/lib/css/CssGenerator.js +71 -9
  95. package/lib/css/CssModulesPlugin.js +30 -5
  96. package/lib/css/CssParser.js +37 -17
  97. package/lib/css/walkCssTokens.js +17 -17
  98. package/lib/debug/ProfilingPlugin.js +98 -38
  99. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
  100. package/lib/dependencies/AMDPlugin.js +5 -2
  101. package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
  102. package/lib/dependencies/AMDRequireContextDependency.js +2 -1
  103. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
  104. package/lib/dependencies/AMDRuntimeModules.js +3 -1
  105. package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
  106. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
  107. package/lib/dependencies/CommonJsImportsParserPlugin.js +8 -7
  108. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  109. package/lib/dependencies/ContextDependencyHelpers.js +13 -6
  110. package/lib/dependencies/CssIcssExportDependency.js +15 -12
  111. package/lib/dependencies/CssIcssImportDependency.js +4 -1
  112. package/lib/dependencies/CssLocalIdentifierDependency.js +17 -14
  113. package/lib/dependencies/ExportsInfoDependency.js +6 -1
  114. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
  115. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
  116. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
  117. package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
  118. package/lib/dependencies/HarmonyImportDependency.js +8 -6
  119. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
  120. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
  121. package/lib/dependencies/ImportContextDependency.js +2 -1
  122. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
  123. package/lib/dependencies/JsonExportsDependency.js +24 -8
  124. package/lib/dependencies/LoaderPlugin.js +4 -14
  125. package/lib/dependencies/RequireContextDependency.js +2 -1
  126. package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
  127. package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
  128. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
  129. package/lib/dependencies/RequireResolveContextDependency.js +1 -1
  130. package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
  131. package/lib/dependencies/WorkerDependency.js +6 -3
  132. package/lib/dependencies/WorkerPlugin.js +100 -41
  133. package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
  134. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  135. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  136. package/lib/hmr/LazyCompilationPlugin.js +32 -24
  137. package/lib/hmr/lazyCompilationBackend.js +1 -1
  138. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  139. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  140. package/lib/ids/IdHelpers.js +15 -14
  141. package/lib/ids/SyncModuleIdsPlugin.js +9 -5
  142. package/lib/index.js +5 -5
  143. package/lib/javascript/BasicEvaluatedExpression.js +6 -6
  144. package/lib/javascript/JavascriptGenerator.js +11 -1
  145. package/lib/javascript/JavascriptModulesPlugin.js +51 -31
  146. package/lib/javascript/JavascriptParser.js +287 -188
  147. package/lib/javascript/JavascriptParserHelpers.js +10 -9
  148. package/lib/javascript/StartupHelpers.js +4 -1
  149. package/lib/json/JsonData.js +4 -4
  150. package/lib/json/JsonGenerator.js +54 -22
  151. package/lib/json/JsonModulesPlugin.js +16 -2
  152. package/lib/json/JsonParser.js +8 -4
  153. package/lib/library/AbstractLibraryPlugin.js +7 -3
  154. package/lib/library/AssignLibraryPlugin.js +29 -1
  155. package/lib/library/EnableLibraryPlugin.js +7 -10
  156. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  157. package/lib/library/ModuleLibraryPlugin.js +121 -15
  158. package/lib/logging/Logger.js +2 -2
  159. package/lib/logging/createConsoleLogger.js +4 -4
  160. package/lib/node/NodeEnvironmentPlugin.js +6 -2
  161. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
  162. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  163. package/lib/node/nodeConsole.js +3 -1
  164. package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
  165. package/lib/optimize/ConcatenatedModule.js +19 -12
  166. package/lib/optimize/InnerGraph.js +3 -2
  167. package/lib/optimize/InnerGraphPlugin.js +13 -7
  168. package/lib/optimize/LimitChunkCountPlugin.js +20 -0
  169. package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
  170. package/lib/optimize/RealContentHashPlugin.js +8 -4
  171. package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
  172. package/lib/optimize/SplitChunksPlugin.js +87 -65
  173. package/lib/rules/BasicEffectRulePlugin.js +9 -1
  174. package/lib/rules/BasicMatcherRulePlugin.js +15 -4
  175. package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
  176. package/lib/rules/RuleSetCompiler.js +25 -14
  177. package/lib/rules/UseEffectRulePlugin.js +47 -17
  178. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
  179. package/lib/schemes/HttpUriPlugin.js +38 -17
  180. package/lib/serialization/BinaryMiddleware.js +52 -19
  181. package/lib/serialization/FileMiddleware.js +78 -48
  182. package/lib/serialization/ObjectMiddleware.js +78 -29
  183. package/lib/serialization/PlainObjectSerializer.js +1 -1
  184. package/lib/serialization/Serializer.js +15 -10
  185. package/lib/serialization/SerializerMiddleware.js +80 -41
  186. package/lib/serialization/SingleItemMiddleware.js +10 -7
  187. package/lib/serialization/types.js +1 -1
  188. package/lib/sharing/ConsumeSharedModule.js +4 -2
  189. package/lib/sharing/ProvideSharedModule.js +4 -2
  190. package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
  191. package/lib/sharing/utils.js +2 -2
  192. package/lib/stats/DefaultStatsFactoryPlugin.js +80 -78
  193. package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
  194. package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
  195. package/lib/stats/StatsFactory.js +11 -11
  196. package/lib/stats/StatsPrinter.js +7 -7
  197. package/lib/util/ArrayHelpers.js +2 -4
  198. package/lib/util/ArrayQueue.js +1 -1
  199. package/lib/util/AsyncQueue.js +4 -4
  200. package/lib/util/IterableHelpers.js +1 -1
  201. package/lib/util/LazyBucketSortedSet.js +41 -23
  202. package/lib/util/LazySet.js +3 -2
  203. package/lib/util/MapHelpers.js +1 -1
  204. package/lib/util/ParallelismFactorCalculator.js +1 -1
  205. package/lib/util/Semaphore.js +3 -3
  206. package/lib/util/SetHelpers.js +1 -1
  207. package/lib/util/SortableSet.js +9 -7
  208. package/lib/util/TupleQueue.js +9 -8
  209. package/lib/util/TupleSet.js +2 -2
  210. package/lib/util/WeakTupleMap.js +12 -11
  211. package/lib/util/binarySearchBounds.js +2 -1
  212. package/lib/util/cleverMerge.js +84 -54
  213. package/lib/util/comparators.js +22 -21
  214. package/lib/util/compileBooleanMatcher.js +3 -3
  215. package/lib/util/concatenate.js +6 -4
  216. package/lib/util/create-schema-validation.js +4 -4
  217. package/lib/util/createHash.js +2 -2
  218. package/lib/util/deprecation.js +35 -33
  219. package/lib/util/deterministicGrouping.js +6 -6
  220. package/lib/util/findGraphRoots.js +1 -1
  221. package/lib/util/fs.js +39 -39
  222. package/lib/util/hash/wasm-hash.js +2 -2
  223. package/lib/util/identifier.js +15 -18
  224. package/lib/util/makeSerializable.js +1 -1
  225. package/lib/util/memoize.js +4 -1
  226. package/lib/util/objectToMap.js +3 -2
  227. package/lib/util/processAsyncTree.js +2 -2
  228. package/lib/util/propertyName.js +0 -1
  229. package/lib/util/registerExternalSerializer.js +15 -18
  230. package/lib/util/removeBOM.js +25 -0
  231. package/lib/util/runtime.js +34 -27
  232. package/lib/util/serialization.js +5 -16
  233. package/lib/util/smartGrouping.js +3 -3
  234. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  235. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
  236. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
  237. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
  238. package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
  239. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
  240. package/lib/wasm-sync/WebAssemblyParser.js +9 -4
  241. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
  242. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
  243. package/package.json +19 -17
  244. package/schemas/WebpackOptions.check.js +1 -1
  245. package/schemas/WebpackOptions.json +48 -13
  246. package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
  247. package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
  248. package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
  249. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  250. package/types.d.ts +918 -615
  251. package/lib/library/ModernModuleLibraryPlugin.js +0 -144
@@ -479,8 +479,7 @@ class ProgressPlugin {
479
479
  compilation.hooks.failedEntry.tap("ProgressPlugin", entryDone);
480
480
  compilation.hooks.succeedEntry.tap("ProgressPlugin", entryDone);
481
481
 
482
- // avoid dynamic require if bundled with webpack
483
- // @ts-expect-error
482
+ // @ts-expect-error avoid dynamic require if bundled with webpack
484
483
  if (typeof __webpack_require__ !== "function") {
485
484
  const requiredLoaders = new Set();
486
485
  NormalModule.getCompilationHooks(compilation).beforeLoaders.tap(
package/lib/RawModule.js CHANGED
@@ -18,8 +18,10 @@ const makeSerializable = require("./util/makeSerializable");
18
18
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
19
19
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
20
20
  /** @typedef {import("./Generator").SourceTypes} SourceTypes */
21
+ /** @typedef {import("./Module").BuildCallback} BuildCallback */
21
22
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
22
23
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
24
+ /** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
23
25
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
24
26
  /** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
25
27
  /** @typedef {import("./RequestShortener")} RequestShortener */
@@ -80,7 +82,7 @@ class RawModule extends Module {
80
82
 
81
83
  /**
82
84
  * @param {NeedBuildContext} context context info
83
- * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
85
+ * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild
84
86
  * @returns {void}
85
87
  */
86
88
  needBuild(context, callback) {
@@ -92,7 +94,7 @@ class RawModule extends Module {
92
94
  * @param {Compilation} compilation the compilation
93
95
  * @param {ResolverWithOptions} resolver the resolver
94
96
  * @param {InputFileSystem} fs the file system
95
- * @param {function(WebpackError=): void} callback callback function
97
+ * @param {BuildCallback} callback callback function
96
98
  * @returns {void}
97
99
  */
98
100
  build(options, compilation, resolver, fs, callback) {
@@ -32,10 +32,14 @@ const identifierUtils = require("./util/identifier");
32
32
  * @property {RecordsModules=} modules
33
33
  */
34
34
 
35
+ /**
36
+ * @typedef {object} RecordIdsPluginOptions
37
+ * @property {boolean=} portableIds true, when ids need to be portable
38
+ */
39
+
35
40
  class RecordIdsPlugin {
36
41
  /**
37
- * @param {object} options Options object
38
- * @param {boolean=} options.portableIds true, when ids need to be portable
42
+ * @param {RecordIdsPluginOptions} [options] object
39
43
  */
40
44
  constructor(options) {
41
45
  this.options = options || {};
@@ -7,10 +7,12 @@
7
7
 
8
8
  const { contextify } = require("./util/identifier");
9
9
 
10
+ /** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
11
+
10
12
  class RequestShortener {
11
13
  /**
12
14
  * @param {string} dir the directory
13
- * @param {object=} associatedObjectForCache an object to which the cache will be attached
15
+ * @param {AssociatedObjectForCache=} associatedObjectForCache an object to which the cache will be attached
14
16
  */
15
17
  constructor(dir, associatedObjectForCache) {
16
18
  this.contextify = contextify.bindContextCache(
@@ -20,15 +20,16 @@ const {
20
20
  /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} WebpackResolveOptions */
21
21
  /** @typedef {import("../declarations/WebpackOptions").ResolvePluginInstance} ResolvePluginInstance */
22
22
 
23
- /** @typedef {WebpackResolveOptions & {dependencyType?: string, resolveToContext?: boolean }} ResolveOptionsWithDependencyType */
23
+ /** @typedef {WebpackResolveOptions & { dependencyType?: string, resolveToContext?: boolean }} ResolveOptionsWithDependencyType */
24
24
  /**
25
25
  * @typedef {object} WithOptions
26
- * @property {function(Partial<ResolveOptionsWithDependencyType>): ResolverWithOptions} withOptions create a resolver with additional/different options
26
+ * @property {(options: Partial<ResolveOptionsWithDependencyType>) => ResolverWithOptions} withOptions create a resolver with additional/different options
27
27
  */
28
28
 
29
29
  /** @typedef {Resolver & WithOptions} ResolverWithOptions */
30
30
 
31
31
  // need to be hoisted on module level for caching identity
32
+ /** @type {ResolveOptionsWithDependencyType} */
32
33
  const EMPTY_RESOLVE_OPTIONS = {};
33
34
 
34
35
  /**
@@ -39,7 +40,7 @@ const convertToResolveOptions = resolveOptionsWithDepType => {
39
40
  const { dependencyType, plugins, ...remaining } = resolveOptionsWithDepType;
40
41
 
41
42
  // check type compat
42
- /** @type {Partial<ResolveOptions>} */
43
+ /** @type {Partial<ResolveOptionsWithDependencyType>} */
43
44
  const partialOptions = {
44
45
  ...remaining,
45
46
  plugins:
@@ -56,20 +57,22 @@ const convertToResolveOptions = resolveOptionsWithDepType => {
56
57
  }
57
58
  // These weird types validate that we checked all non-optional properties
58
59
  const options =
59
- /** @type {Partial<ResolveOptions> & Pick<ResolveOptions, "fileSystem">} */ (
60
+ /** @type {Partial<ResolveOptionsWithDependencyType> & Pick<ResolveOptionsWithDependencyType, "fileSystem">} */ (
60
61
  partialOptions
61
62
  );
62
63
 
63
- return removeOperations(
64
- resolveByProperty(options, "byDependency", dependencyType),
65
- // Keep the `unsafeCache` because it can be a `Proxy`
66
- ["unsafeCache"]
64
+ return /** @type {ResolveOptions} */ (
65
+ removeOperations(
66
+ resolveByProperty(options, "byDependency", dependencyType),
67
+ // Keep the `unsafeCache` because it can be a `Proxy`
68
+ ["unsafeCache"]
69
+ )
67
70
  );
68
71
  };
69
72
 
70
73
  /**
71
74
  * @typedef {object} ResolverCache
72
- * @property {WeakMap<object, ResolverWithOptions>} direct
75
+ * @property {WeakMap<ResolveOptionsWithDependencyType, ResolverWithOptions>} direct
73
76
  * @property {Map<string, ResolverWithOptions>} stringified
74
77
  */
75
78
 
@@ -18,8 +18,10 @@ const { WEBPACK_MODULE_TYPE_RUNTIME } = require("./ModuleTypeConstants");
18
18
  /** @typedef {import("./Compilation")} Compilation */
19
19
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
20
20
  /** @typedef {import("./Generator").SourceTypes} SourceTypes */
21
+ /** @typedef {import("./Module").BuildCallback} BuildCallback */
21
22
  /** @typedef {import("./Module").CodeGenerationContext} CodeGenerationContext */
22
23
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
24
+ /** @typedef {import("./Module").NeedBuildCallback} NeedBuildCallback */
23
25
  /** @typedef {import("./Module").NeedBuildContext} NeedBuildContext */
24
26
  /** @typedef {import("./RequestShortener")} RequestShortener */
25
27
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
@@ -79,7 +81,7 @@ class RuntimeModule extends Module {
79
81
 
80
82
  /**
81
83
  * @param {NeedBuildContext} context context info
82
- * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
84
+ * @param {NeedBuildCallback} callback callback function, returns true, if the module needs a rebuild
83
85
  * @returns {void}
84
86
  */
85
87
  needBuild(context, callback) {
@@ -91,7 +93,7 @@ class RuntimeModule extends Module {
91
93
  * @param {Compilation} compilation the compilation
92
94
  * @param {ResolverWithOptions} resolver the resolver
93
95
  * @param {InputFileSystem} fs the file system
94
- * @param {function(WebpackError=): void} callback callback function
96
+ * @param {BuildCallback} callback callback function
95
97
  * @returns {void}
96
98
  */
97
99
  build(options, compilation, resolver, fs, callback) {
@@ -853,6 +853,7 @@ class RuntimeTemplate {
853
853
  }
854
854
 
855
855
  /**
856
+ * @template GenerateContext
856
857
  * @param {object} options options
857
858
  * @param {ModuleGraph} options.moduleGraph the module graph
858
859
  * @param {Module} options.module the module
@@ -864,7 +865,7 @@ class RuntimeTemplate {
864
865
  * @param {boolean | null} options.callContext when false, call context will not be preserved
865
866
  * @param {boolean} options.defaultInterop when true and accessing the default exports, interop code will be generated
866
867
  * @param {string} options.importVar the identifier name of the import variable
867
- * @param {InitFragment<TODO>[]} options.initFragments init fragments will be added here
868
+ * @param {InitFragment<GenerateContext>[]} options.initFragments init fragments will be added here
868
869
  * @param {RuntimeSpec} options.runtime runtime for which this code will be generated
869
870
  * @param {RuntimeRequirements} options.runtimeRequirements if set, will be filled with runtime requirements
870
871
  * @returns {string} expression
@@ -5,8 +5,8 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /** @typedef {import("./ModuleFactory").ModuleFactoryCallback} ModuleFactoryCallback */
8
9
  /** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
9
- /** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
10
10
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
11
11
 
12
12
  class SelfModuleFactory {
@@ -19,7 +19,7 @@ class SelfModuleFactory {
19
19
 
20
20
  /**
21
21
  * @param {ModuleFactoryCreateData} data data object
22
- * @param {function((Error | null)=, ModuleFactoryResult=): void} callback callback
22
+ * @param {ModuleFactoryCallback} callback callback
23
23
  * @returns {void}
24
24
  */
25
25
  create(data, callback) {
@@ -146,16 +146,12 @@ class SourceMapDevToolPlugin {
146
146
  ? false
147
147
  : // eslint-disable-next-line no-useless-concat
148
148
  options.append || "\n//# source" + "MappingURL=[url]";
149
- /** @type {string | Function} */
150
149
  this.moduleFilenameTemplate =
151
150
  options.moduleFilenameTemplate || "webpack://[namespace]/[resourcePath]";
152
- /** @type {string | Function} */
153
151
  this.fallbackModuleFilenameTemplate =
154
152
  options.fallbackModuleFilenameTemplate ||
155
153
  "webpack://[namespace]/[resourcePath]?[hash]";
156
- /** @type {string} */
157
154
  this.namespace = options.namespace || "";
158
- /** @type {SourceMapDevToolPluginOptions} */
159
155
  this.options = options;
160
156
  }
161
157
 
@@ -196,10 +192,6 @@ class SourceMapDevToolPlugin {
196
192
  const cache = compilation.getCache("SourceMapDevToolPlugin");
197
193
  /** @type {Map<string | Module, string>} */
198
194
  const moduleToSourceNameMapping = new Map();
199
- /**
200
- * @type {Function}
201
- * @returns {void}
202
- */
203
195
  const reportProgress =
204
196
  ProgressPlugin.getReporter(compilation.compiler) || (() => {});
205
197
 
package/lib/Template.js CHANGED
@@ -60,7 +60,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
60
60
 
61
61
  /**
62
62
  * @typedef {object} RenderManifestEntryTemplated
63
- * @property {function(): Source} render
63
+ * @property {() => Source} render
64
64
  * @property {TemplatePath} filenameTemplate
65
65
  * @property {PathData=} pathOptions
66
66
  * @property {AssetInfo=} info
@@ -71,7 +71,7 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
71
71
 
72
72
  /**
73
73
  * @typedef {object} RenderManifestEntryStatic
74
- * @property {function(): Source} render
74
+ * @property {() => Source} render
75
75
  * @property {string} filename
76
76
  * @property {AssetInfo} info
77
77
  * @property {string} identifier
@@ -85,12 +85,13 @@ const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
85
85
  */
86
86
 
87
87
  /**
88
- * @typedef {function(Module, number): boolean} ModuleFilterPredicate
88
+ * @typedef {(module: Module) => boolean} ModuleFilterPredicate
89
89
  */
90
90
 
91
91
  class Template {
92
92
  /**
93
- * @param {Function} fn a runtime function (.runtime.js) "template"
93
+ * @template {EXPECTED_FUNCTION} T
94
+ * @param {T} fn a runtime function (.runtime.js) "template"
94
95
  * @returns {string} the updated and normalized function string
95
96
  */
96
97
  static getFunctionContent(fn) {
@@ -284,7 +285,7 @@ class Template {
284
285
  /**
285
286
  * @param {ChunkRenderContext} renderContext render context
286
287
  * @param {Module[]} modules modules to render (should be ordered by identifier)
287
- * @param {function(Module): Source | null} renderModule function to render a module
288
+ * @param {(module: Module) => Source | null} renderModule function to render a module
288
289
  * @param {string=} prefix applying prefix strings
289
290
  * @returns {Source | null} rendered chunk modules in a Source object or null if no modules
290
291
  */
@@ -50,10 +50,10 @@ const prepareId = id => {
50
50
  * @param {((arg0: number) => string) | undefined} handler handler
51
51
  * @param {AssetInfo | undefined} assetInfo asset info
52
52
  * @param {string} hashName hash name
53
- * @returns {ReplacerFunction} hash replacer function
53
+ * @returns {Replacer} hash replacer function
54
54
  */
55
55
  const hashLength = (replacer, handler, assetInfo, hashName) => {
56
- /** @type {ReplacerFunction} */
56
+ /** @type {Replacer} */
57
57
  const fn = (match, arg, input) => {
58
58
  let result;
59
59
  const length = arg && Number.parseInt(arg, 10);
@@ -81,7 +81,7 @@ const hashLength = (replacer, handler, assetInfo, hashName) => {
81
81
  return fn;
82
82
  };
83
83
 
84
- /** @typedef {(match: string, arg?: string, input?: string) => string} Replacer */
84
+ /** @typedef {(match: string, arg: string | undefined, input: string) => string} Replacer */
85
85
 
86
86
  /**
87
87
  * @param {string | number | null | undefined | (() => string | number | null | undefined)} value value
@@ -113,10 +113,11 @@ const replacer = (value, allowEmpty) => {
113
113
  const deprecationCache = new Map();
114
114
  const deprecatedFunction = (() => () => {})();
115
115
  /**
116
- * @param {Function} fn function
116
+ * @template {(...args: EXPECTED_ANY[]) => EXPECTED_ANY} T
117
+ * @param {T} fn function
117
118
  * @param {string} message message
118
119
  * @param {string} code code
119
- * @returns {function(...any[]): void} function with deprecation output
120
+ * @returns {T} function with deprecation output
120
121
  */
121
122
  const deprecated = (fn, message, code) => {
122
123
  let d = deprecationCache.get(message);
@@ -124,13 +125,15 @@ const deprecated = (fn, message, code) => {
124
125
  d = util.deprecate(deprecatedFunction, message, code);
125
126
  deprecationCache.set(message, d);
126
127
  }
127
- return (...args) => {
128
- d();
129
- return fn(...args);
130
- };
128
+ return /** @type {T} */ (
129
+ (...args) => {
130
+ d();
131
+ return fn(...args);
132
+ }
133
+ );
131
134
  };
132
135
 
133
- /** @typedef {string | function(PathData, AssetInfo=): string} TemplatePath */
136
+ /** @typedef {string | ((pathData: PathData, assetInfo?: AssetInfo) => string)} TemplatePath */
134
137
 
135
138
  /**
136
139
  * @param {TemplatePath} path the raw path
@@ -141,7 +144,7 @@ const deprecated = (fn, message, code) => {
141
144
  const replacePathVariables = (path, data, assetInfo) => {
142
145
  const chunkGraph = data.chunkGraph;
143
146
 
144
- /** @type {Map<string, Function>} */
147
+ /** @type {Map<string, Replacer>} */
145
148
  const replacements = new Map();
146
149
 
147
150
  // Filename context
@@ -366,7 +369,7 @@ const replacePathVariables = (path, data, assetInfo) => {
366
369
  const [, kind, arg] = contentMatch;
367
370
  const replacer = replacements.get(kind);
368
371
  if (replacer !== undefined) {
369
- return replacer(match, arg, path);
372
+ return replacer(match, arg, /** @type {string} */ (path));
370
373
  }
371
374
  } else if (match.startsWith("[\\") && match.endsWith("\\]")) {
372
375
  return `[${match.slice(2, -2)}]`;
@@ -395,7 +395,7 @@ class WebpackOptionsApply extends OptionsApply {
395
395
  new RequireJsStuffPlugin().apply(compiler);
396
396
  }
397
397
  new CommonJsPlugin().apply(compiler);
398
- new LoaderPlugin({}).apply(compiler);
398
+ new LoaderPlugin().apply(compiler);
399
399
  if (options.node !== false) {
400
400
  const NodeStuffPlugin = require("./NodeStuffPlugin");
401
401
  new NodeStuffPlugin(options.node).apply(compiler);