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
package/README.md CHANGED
@@ -101,6 +101,7 @@ within webpack itself use this plugin interface. This makes webpack very
101
101
  | :---------------------------------------: | :----------------: | :-----------------: | :-------------------------------------------------------------------------------------- |
102
102
  | [mini-css-extract-plugin][mini-css] | ![mini-css-npm] | ![mini-css-size] | Extracts CSS into separate files. It creates a CSS file per JS file which contains CSS. |
103
103
  | [compression-webpack-plugin][compression] | ![compression-npm] | ![compression-size] | Prepares compressed versions of assets to serve them with Content-Encoding |
104
+ | [html-bundler-webpack-plugin][bundler] | ![bundler-npm] | ![bundler-size] | Renders a template (EJS, Handlebars, Pug) with referenced source asset files into HTML. |
104
105
  | [html-webpack-plugin][html-plugin] | ![html-plugin-npm] | ![html-plugin-size] | Simplifies creation of HTML files (`index.html`) to serve your bundles |
105
106
  | [pug-plugin][pug-plugin] | ![pug-plugin-npm] | ![pug-plugin-size] | Renders Pug files to HTML, extracts JS and CSS from sources specified directly in Pug. |
106
107
 
@@ -114,6 +115,9 @@ within webpack itself use this plugin interface. This makes webpack very
114
115
  [compression]: https://github.com/webpack-contrib/compression-webpack-plugin
115
116
  [compression-npm]: https://img.shields.io/npm/v/compression-webpack-plugin.svg
116
117
  [compression-size]: https://packagephobia.com/badge?p=compression-webpack-plugin
118
+ [bundler]: https://github.com/webdiscus/html-bundler-webpack-plugin
119
+ [bundler-npm]: https://img.shields.io/npm/v/html-bundler-webpack-plugin.svg
120
+ [bundler-size]: https://packagephobia.com/badge?p=html-bundler-webpack-plugin
117
121
  [html-plugin]: https://github.com/jantimon/html-webpack-plugin
118
122
  [html-plugin-npm]: https://img.shields.io/npm/v/html-webpack-plugin.svg
119
123
  [html-plugin-size]: https://packagephobia.com/badge?p=html-webpack-plugin
@@ -298,14 +302,14 @@ For information about the governance of the Node.js project, see [GOVERNANCE.md]
298
302
 
299
303
  - [alexander-akait](https://github.com/alexander-akait) -
300
304
  **Alexander Akait** <<sheo13666q@gmail.com>> (he/him)
301
- - [ematipico](https://github.com/ematipico) -
302
- **Emanuele Stoppa** <<my.burning@gmail.com>> (he/him)
303
305
  - [evenstensberg](https://github.com/evenstensberg) -
304
306
  **Even Stensberg** <<evenstensberg@gmail.com>> (he/him)
305
307
  - [ovflowd](https://github.com/ovflowd) -
306
308
  **Claudio Wunder** <<cwunder@gnome.org>> (he/they)
307
309
  - [snitin315](https://github.com/snitin315) -
308
- **Nitin Kumarr** <<snitin315@gmail.com>> (he/him)
310
+ **Nitin Kumar** <<snitin315@gmail.com>> (he/him)
311
+ - [thelarkinn](https://github.com/thelarkinn) -
312
+ **Sean Larkin** <<selarkin@microsoft.com>> (he/him)
309
313
 
310
314
  <h3>Core Collaborators</h3>
311
315
 
@@ -19,9 +19,11 @@ const makeSerializable = require("./util/makeSerializable");
19
19
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
20
20
  /** @typedef {import("./util/Hash")} Hash */
21
21
 
22
+ /** @typedef {(ChunkGroupOptions & { entryOptions?: EntryOptions }) | string} GroupOptions */
23
+
22
24
  class AsyncDependenciesBlock extends DependenciesBlock {
23
25
  /**
24
- * @param {(ChunkGroupOptions & { entryOptions?: EntryOptions }) | null} groupOptions options for the group
26
+ * @param {GroupOptions | null} groupOptions options for the group
25
27
  * @param {(DependencyLocation | null)=} loc the line of code
26
28
  * @param {(string | null)=} request the request
27
29
  */
@@ -19,7 +19,7 @@ const createSchemaValidation = require("./util/create-schema-validation");
19
19
  /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
20
20
 
21
21
  const validate = createSchemaValidation(
22
- /** @type {(function(typeof import("../schemas/plugins/BannerPlugin.json")): boolean)} */
22
+ /** @type {((value: typeof import("../schemas/plugins/BannerPlugin.json")) => boolean)} */
23
23
  (require("../schemas/plugins/BannerPlugin.check.js")),
24
24
  () => require("../schemas/plugins/BannerPlugin.json"),
25
25
  {
package/lib/Cache.js CHANGED
@@ -15,7 +15,7 @@ const {
15
15
 
16
16
  /**
17
17
  * @typedef {object} Etag
18
- * @property {function(): string} toString
18
+ * @property {() => string} toString
19
19
  */
20
20
 
21
21
  /**
@@ -26,17 +26,19 @@ const {
26
26
  * @returns {void}
27
27
  */
28
28
 
29
+ /** @typedef {TODO} Data */
30
+
29
31
  /**
30
32
  * @callback GotHandler
31
- * @param {any} result
32
- * @param {function(Error=): void} callback
33
+ * @param {TODO} result
34
+ * @param {(err?: Error) => void} callback
33
35
  * @returns {void}
34
36
  */
35
37
 
36
38
  /**
37
39
  * @param {number} times times
38
- * @param {function(Error=): void} callback callback
39
- * @returns {function(Error=): void} callback
40
+ * @param {(err?: Error) => void} callback callback
41
+ * @returns {(err?: Error) => void} callback
40
42
  */
41
43
  const needCalls = (times, callback) => err => {
42
44
  if (--times === 0) {
@@ -51,9 +53,9 @@ const needCalls = (times, callback) => err => {
51
53
  class Cache {
52
54
  constructor() {
53
55
  this.hooks = {
54
- /** @type {AsyncSeriesBailHook<[string, Etag | null, GotHandler[]], any>} */
56
+ /** @type {AsyncSeriesBailHook<[string, Etag | null, GotHandler[]], Data>} */
55
57
  get: new AsyncSeriesBailHook(["identifier", "etag", "gotHandlers"]),
56
- /** @type {AsyncParallelHook<[string, Etag | null, any]>} */
58
+ /** @type {AsyncParallelHook<[string, Etag | null, Data]>} */
57
59
  store: new AsyncParallelHook(["identifier", "etag", "data"]),
58
60
  /** @type {AsyncParallelHook<[Iterable<string>]>} */
59
61
  storeBuildDependencies: new AsyncParallelHook(["dependencies"]),
@@ -39,7 +39,7 @@ class MultiItemCache {
39
39
  constructor(items) {
40
40
  this._items = items;
41
41
  // eslint-disable-next-line no-constructor-return
42
- if (items.length === 1) return /** @type {any} */ (items[0]);
42
+ if (items.length === 1) return /** @type {TODO} */ (items[0]);
43
43
  }
44
44
 
45
45
  /**
@@ -160,7 +160,7 @@ class ItemCacheFacade {
160
160
 
161
161
  /**
162
162
  * @template T
163
- * @param {function(CallbackNormalErrorCache<T>): void} computer function to compute the value if not cached
163
+ * @param {(callback: CallbackNormalErrorCache<T>) => void} computer function to compute the value if not cached
164
164
  * @param {CallbackNormalErrorCache<T>} callback signals when the value is retrieved
165
165
  * @returns {void}
166
166
  */
@@ -180,7 +180,7 @@ class ItemCacheFacade {
180
180
 
181
181
  /**
182
182
  * @template T
183
- * @param {function(): Promise<T> | T} computer function to compute the value if not cached
183
+ * @param {() => Promise<T> | T} computer function to compute the value if not cached
184
184
  * @returns {Promise<T>} promise with the data
185
185
  */
186
186
  async providePromise(computer) {
@@ -310,7 +310,7 @@ class CacheFacade {
310
310
  * @template T
311
311
  * @param {string} identifier the cache identifier
312
312
  * @param {Etag | null} etag the etag
313
- * @param {function(CallbackNormalErrorCache<T>): void} computer function to compute the value if not cached
313
+ * @param {(callback: CallbackNormalErrorCache<T>) => void} computer function to compute the value if not cached
314
314
  * @param {CallbackNormalErrorCache<T>} callback signals when the value is retrieved
315
315
  * @returns {void}
316
316
  */
@@ -332,7 +332,7 @@ class CacheFacade {
332
332
  * @template T
333
333
  * @param {string} identifier the cache identifier
334
334
  * @param {Etag | null} etag the etag
335
- * @param {function(): Promise<T> | T} computer function to compute the value if not cached
335
+ * @param {() => Promise<T> | T} computer function to compute the value if not cached
336
336
  * @returns {Promise<T>} promise with the data
337
337
  */
338
338
  async providePromise(identifier, etag, computer) {
package/lib/Chunk.js CHANGED
@@ -66,7 +66,7 @@ let debugId = 1000;
66
66
  */
67
67
  class Chunk {
68
68
  /**
69
- * @param {string=} name of chunk being created, is optional (for subclasses)
69
+ * @param {(string | null)=} name of chunk being created, is optional (for subclasses)
70
70
  * @param {boolean} backCompat enable backward-compatibility
71
71
  */
72
72
  constructor(name, backCompat = true) {
@@ -76,7 +76,7 @@ class Chunk {
76
76
  this.ids = null;
77
77
  /** @type {number} */
78
78
  this.debugId = debugId++;
79
- /** @type {string | undefined} */
79
+ /** @type {string | null | undefined} */
80
80
  this.name = name;
81
81
  /** @type {SortableSet<string>} */
82
82
  this.idNameHints = new SortableSet();
package/lib/ChunkGraph.js CHANGED
@@ -8,6 +8,7 @@
8
8
  const util = require("util");
9
9
  const Entrypoint = require("./Entrypoint");
10
10
  const ModuleGraphConnection = require("./ModuleGraphConnection");
11
+ const { DEFAULTS } = require("./config/defaults");
11
12
  const { first } = require("./util/SetHelpers");
12
13
  const SortableSet = require("./util/SortableSet");
13
14
  const {
@@ -35,6 +36,7 @@ const {
35
36
  /** @typedef {import("./Generator").SourceTypes} SourceTypes */
36
37
  /** @typedef {import("./Module")} Module */
37
38
  /** @typedef {import("./Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
39
+ /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
38
40
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
39
41
  /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
40
42
  /** @typedef {import("./RuntimeModule")} RuntimeModule */
@@ -61,7 +63,7 @@ const compareModuleIterables = compareIterables(compareModulesByIdentifier);
61
63
  class ModuleHashInfo {
62
64
  /**
63
65
  * @param {string} hash hash
64
- * @param {string} renderedHash rendered hash
66
+ * @param {string} renderedHash rendered hash
65
67
  */
66
68
  constructor(hash, renderedHash) {
67
69
  this.hash = hash;
@@ -69,8 +71,6 @@ class ModuleHashInfo {
69
71
  }
70
72
  }
71
73
 
72
- /** @template T @typedef {(set: SortableSet<T>) => T[]} SetToArrayFunction<T> */
73
-
74
74
  /**
75
75
  * @template T
76
76
  * @param {SortableSet<T>} set the set
@@ -92,7 +92,7 @@ const getModuleRuntimes = chunks => {
92
92
 
93
93
  /**
94
94
  * @param {WeakMap<Module, Set<string>> | undefined} sourceTypesByModule sourceTypesByModule
95
- * @returns {function (SortableSet<Module>): Map<string, SortableSet<Module>>} modules by source type
95
+ * @returns {(set: SortableSet<Module>) => Map<string, SortableSet<Module>>} modules by source type
96
96
  */
97
97
  const modulesBySourceType = sourceTypesByModule => set => {
98
98
  /** @type {Map<string, SortableSet<Module>>} */
@@ -121,19 +121,22 @@ const modulesBySourceType = sourceTypesByModule => set => {
121
121
  };
122
122
  const defaultModulesBySourceType = modulesBySourceType(undefined);
123
123
 
124
+ /**
125
+ * @typedef {(set: SortableSet<Module>) => Module[]} ModuleSetToArrayFunction
126
+ */
127
+
124
128
  /**
125
129
  * @template T
126
- * @type {WeakMap<Function, any>}
130
+ * @type {WeakMap<ModuleComparator, ModuleSetToArrayFunction>}
127
131
  */
128
132
  const createOrderedArrayFunctionMap = new WeakMap();
129
133
 
130
134
  /**
131
135
  * @template T
132
- * @param {function(T, T): -1|0|1} comparator comparator function
133
- * @returns {SetToArrayFunction<T>} set as ordered array
136
+ * @param {ModuleComparator} comparator comparator function
137
+ * @returns {ModuleSetToArrayFunction} set as ordered array
134
138
  */
135
139
  const createOrderedArrayFunction = comparator => {
136
- /** @type {SetToArrayFunction<T>} */
137
140
  let fn = createOrderedArrayFunctionMap.get(comparator);
138
141
  if (fn !== undefined) return fn;
139
142
  fn = set => {
@@ -205,11 +208,11 @@ class ChunkGraphModule {
205
208
  this.hashes = undefined;
206
209
  /** @type {ModuleId | null} */
207
210
  this.id = null;
208
- /** @type {RuntimeSpecMap<Set<string>> | undefined} */
211
+ /** @type {RuntimeSpecMap<Set<string>, RuntimeRequirements> | undefined} */
209
212
  this.runtimeRequirements = undefined;
210
- /** @type {RuntimeSpecMap<string> | undefined} */
213
+ /** @type {RuntimeSpecMap<string, bigint> | undefined} */
211
214
  this.graphHashes = undefined;
212
- /** @type {RuntimeSpecMap<string> | undefined} */
215
+ /** @type {RuntimeSpecMap<string, string> | undefined} */
213
216
  this.graphHashesWithConnections = undefined;
214
217
  }
215
218
  }
@@ -237,12 +240,14 @@ class ChunkGraphChunk {
237
240
  }
238
241
  }
239
242
 
243
+ /** @typedef {(a: Module, b: Module) => -1 | 0 | 1} ModuleComparator */
244
+
240
245
  class ChunkGraph {
241
246
  /**
242
247
  * @param {ModuleGraph} moduleGraph the module graph
243
248
  * @param {string | Hash} hashFunction the hash function to use
244
249
  */
245
- constructor(moduleGraph, hashFunction = "md4") {
250
+ constructor(moduleGraph, hashFunction = DEFAULTS.HASH_FUNCTION) {
246
251
  /**
247
252
  * @private
248
253
  * @type {WeakMap<Module, ChunkGraphModule>}
@@ -535,7 +540,7 @@ class ChunkGraph {
535
540
 
536
541
  /**
537
542
  * @param {Module} module the module
538
- * @param {function(Chunk, Chunk): -1|0|1} sortFn sort function
543
+ * @param {(a: Chunk, b: Chunk) => -1 | 0 | 1} sortFn sort function
539
544
  * @returns {Iterable<Chunk>} iterable of chunks (do not modify)
540
545
  */
541
546
  getOrderedModuleChunksIterable(module, sortFn) {
@@ -686,7 +691,7 @@ class ChunkGraph {
686
691
 
687
692
  /**
688
693
  * @param {Chunk} chunk the chunk
689
- * @param {function(Module, Module): -1|0|1} comparator comparator function
694
+ * @param {ModuleComparator} comparator comparator function
690
695
  * @returns {Iterable<Module>} return the modules for this chunk
691
696
  */
692
697
  getOrderedChunkModulesIterable(chunk, comparator) {
@@ -698,7 +703,7 @@ class ChunkGraph {
698
703
  /**
699
704
  * @param {Chunk} chunk the chunk
700
705
  * @param {string} sourceType source type
701
- * @param {function(Module, Module): -1|0|1} comparator comparator function
706
+ * @param {ModuleComparator} comparator comparator function
702
707
  * @returns {Iterable<Module> | undefined} return the modules for this chunk
703
708
  */
704
709
  getOrderedChunkModulesIterableBySourceType(chunk, sourceType, comparator) {
@@ -722,7 +727,7 @@ class ChunkGraph {
722
727
 
723
728
  /**
724
729
  * @param {Chunk} chunk the chunk
725
- * @param {function(Module, Module): -1|0|1} comparator comparator function
730
+ * @param {ModuleComparator} comparator comparator function
726
731
  * @returns {Module[]} return the modules for this chunk (cached, do not modify)
727
732
  */
728
733
  getOrderedChunkModules(chunk, comparator) {
@@ -42,7 +42,7 @@ class ChunkTemplate {
42
42
  /**
43
43
  * @template AdditionalOptions
44
44
  * @param {string | Tap & IfSet<AdditionalOptions>} options options
45
- * @param {function(RenderManifestEntry[], RenderManifestOptions): RenderManifestEntry[]} fn function
45
+ * @param {(renderManifestEntries: RenderManifestEntry[], renderManifestOptions: RenderManifestOptions) => RenderManifestEntry[]} fn function
46
46
  */
47
47
  (options, fn) => {
48
48
  compilation.hooks.renderManifest.tap(
@@ -62,7 +62,7 @@ class ChunkTemplate {
62
62
  /**
63
63
  * @template AdditionalOptions
64
64
  * @param {string | Tap & IfSet<AdditionalOptions>} options options
65
- * @param {function(Source, ModuleTemplate, RenderContext): Source} fn function
65
+ * @param {(source: Source, moduleTemplate: ModuleTemplate, renderContext: RenderContext) => Source} fn function
66
66
  */
67
67
  (options, fn) => {
68
68
  getJavascriptModulesPlugin()
@@ -84,7 +84,7 @@ class ChunkTemplate {
84
84
  /**
85
85
  * @template AdditionalOptions
86
86
  * @param {string | Tap & IfSet<AdditionalOptions>} options options
87
- * @param {function(Source, ModuleTemplate, RenderContext): Source} fn function
87
+ * @param {(source: Source, moduleTemplate: ModuleTemplate, renderContext: RenderContext) => Source} fn function
88
88
  */
89
89
  (options, fn) => {
90
90
  getJavascriptModulesPlugin()
@@ -106,7 +106,7 @@ class ChunkTemplate {
106
106
  /**
107
107
  * @template AdditionalOptions
108
108
  * @param {string | Tap & IfSet<AdditionalOptions>} options options
109
- * @param {function(Source, Chunk): Source} fn function
109
+ * @param {(source: Source, chunk: Chunk) => Source} fn function
110
110
  */
111
111
  (options, fn) => {
112
112
  getJavascriptModulesPlugin()
@@ -132,7 +132,7 @@ class ChunkTemplate {
132
132
  /**
133
133
  * @template AdditionalOptions
134
134
  * @param {string | Tap & IfSet<AdditionalOptions>} options options
135
- * @param {function(Hash): void} fn function
135
+ * @param {(hash: Hash) => void} fn function
136
136
  */
137
137
  (options, fn) => {
138
138
  compilation.hooks.fullHash.tap(options, fn);
@@ -146,7 +146,7 @@ class ChunkTemplate {
146
146
  /**
147
147
  * @template AdditionalOptions
148
148
  * @param {string | Tap & IfSet<AdditionalOptions>} options options
149
- * @param {function(Hash, Chunk, ChunkHashContext): void} fn function
149
+ * @param {(hash: Hash, chunk: Chunk, chunkHashContext: ChunkHashContext) => void} fn function
150
150
  */
151
151
  (options, fn) => {
152
152
  getJavascriptModulesPlugin()
@@ -19,9 +19,7 @@ const processAsyncTree = require("./util/processAsyncTree");
19
19
  /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
20
20
  /** @typedef {import("./util/fs").StatsCallback} StatsCallback */
21
21
 
22
- /** @typedef {(function(string):boolean)|RegExp} IgnoreItem */
23
22
  /** @typedef {Map<string, number>} Assets */
24
- /** @typedef {function(IgnoreItem): void} AddToIgnoreCallback */
25
23
 
26
24
  /**
27
25
  * @typedef {object} CleanPluginCompilationHooks
@@ -51,7 +49,7 @@ const validate = createSchemaValidation(
51
49
  const _10sec = 10 * 1000;
52
50
 
53
51
  /**
54
- * marge assets map 2 into map 1
52
+ * merge assets map 2 into map 1
55
53
  * @param {Assets} as1 assets
56
54
  * @param {Assets} as2 assets
57
55
  * @returns {void}
@@ -63,11 +61,13 @@ const mergeAssets = (as1, as2) => {
63
61
  }
64
62
  };
65
63
 
64
+ /** @typedef {Set<string>} Diff */
65
+
66
66
  /**
67
67
  * @param {OutputFileSystem} fs filesystem
68
68
  * @param {string} outputPath output path
69
69
  * @param {Map<string, number>} currentAssets filename of the current assets (must not start with .. or ., must only use / as path separator)
70
- * @param {function((Error | null)=, Set<string>=): void} callback returns the filenames of the assets that shouldn't be there
70
+ * @param {(err?: Error | null, set?: Diff) => void} callback returns the filenames of the assets that shouldn't be there
71
71
  * @returns {void}
72
72
  */
73
73
  const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
@@ -116,7 +116,7 @@ const getDiffToFs = (fs, outputPath, currentAssets, callback) => {
116
116
  /**
117
117
  * @param {Assets} currentAssets assets list
118
118
  * @param {Assets} oldAssets old assets list
119
- * @returns {Set<string>} diff
119
+ * @returns {Diff} diff
120
120
  */
121
121
  const getDiffToOldAssets = (currentAssets, oldAssets) => {
122
122
  const diff = new Set();
@@ -148,9 +148,9 @@ const doStat = (fs, filename, callback) => {
148
148
  * @param {string} outputPath output path
149
149
  * @param {boolean} dry only log instead of fs modification
150
150
  * @param {Logger} logger logger
151
- * @param {Set<string>} diff filenames of the assets that shouldn't be there
152
- * @param {function(string): boolean | void} isKept check if the entry is ignored
153
- * @param {function(Error=, Assets=): void} callback callback
151
+ * @param {Diff} diff filenames of the assets that shouldn't be there
152
+ * @param {(path: string) => boolean | void} isKept check if the entry is ignored
153
+ * @param {(err?: Error, assets?: Assets) => void} callback callback
154
154
  * @returns {void}
155
155
  */
156
156
  const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
@@ -402,7 +402,7 @@ class CleanPlugin {
402
402
 
403
403
  /**
404
404
  * @param {(Error | null)=} err err
405
- * @param {Set<string>=} diff diff
405
+ * @param {Diff=} diff diff
406
406
  */
407
407
  const diffCallback = (err, diff) => {
408
408
  if (err) {
@@ -415,7 +415,7 @@ class CleanPlugin {
415
415
  outputPath,
416
416
  dry,
417
417
  logger,
418
- /** @type {Set<string>} */ (diff),
418
+ /** @type {Diff} */ (diff),
419
419
  isKept,
420
420
  (err, keptAssets) => {
421
421
  if (err) {
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { DEFAULTS } = require("./config/defaults");
8
9
  const { getOrInsert } = require("./util/MapHelpers");
9
10
  const { first } = require("./util/SetHelpers");
10
11
  const createHash = require("./util/createHash");
@@ -21,7 +22,7 @@ class CodeGenerationResults {
21
22
  /**
22
23
  * @param {string | Hash} hashFunction the hash function to use
23
24
  */
24
- constructor(hashFunction = "md4") {
25
+ constructor(hashFunction = DEFAULTS.HASH_FUNCTION) {
25
26
  /** @type {Map<Module, RuntimeSpecMap<CodeGenerationResult>>} */
26
27
  this.map = new Map();
27
28
  this._hashFunction = hashFunction;
@@ -116,7 +117,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
116
117
  * @param {Module} module the module
117
118
  * @param {RuntimeSpec} runtime runtime(s)
118
119
  * @param {string} key data key
119
- * @returns {any} data generated by code generation
120
+ * @returns {TODO | undefined} data generated by code generation
120
121
  */
121
122
  getData(module, runtime, key) {
122
123
  const data = this.get(module, runtime).data;
@@ -126,7 +127,7 @@ Caller might not support runtime-dependent code generation (opt-out via optimiza
126
127
  /**
127
128
  * @param {Module} module the module
128
129
  * @param {RuntimeSpec} runtime runtime(s)
129
- * @returns {any} hash of the code generation
130
+ * @returns {string} hash of the code generation
130
131
  */
131
132
  getHash(module, runtime) {
132
133
  const info = this.get(module, runtime);
@@ -18,6 +18,7 @@ const ConstDependency = require("./dependencies/ConstDependency");
18
18
  /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
19
19
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
20
20
  /** @typedef {import("./javascript/JavascriptParser").Range} Range */
21
+ /** @typedef {import("./javascript/JavascriptParser").TagData} TagData */
21
22
 
22
23
  const nestedWebpackIdentifierTag = Symbol("nested webpack identifier");
23
24
  const PLUGIN_NAME = "CompatibilityPlugin";
@@ -145,7 +146,9 @@ class CompatibilityPlugin {
145
146
  parser.hooks.expression
146
147
  .for(nestedWebpackIdentifierTag)
147
148
  .tap(PLUGIN_NAME, expr => {
148
- const { name, declaration } = parser.currentTagData;
149
+ const { name, declaration } =
150
+ /** @type {TagData} */
151
+ (parser.currentTagData);
149
152
  if (!declaration.updated) {
150
153
  const dep = new ConstDependency(name, declaration.range);
151
154
  dep.loc = declaration.loc;