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
@@ -7,9 +7,12 @@
7
7
 
8
8
  const util = require("util");
9
9
 
10
+ /** @typedef {import("../../declarations/WebpackOptions").Falsy} Falsy */
10
11
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetLoader} RuleSetLoader */
11
12
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetLoaderOptions} RuleSetLoaderOptions */
12
13
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
14
+ /** @typedef {import("../../declarations/WebpackOptions").RuleSetUse} RuleSetUse */
15
+ /** @typedef {import("../../declarations/WebpackOptions").RuleSetUseItem} RuleSetUseItem */
13
16
  /** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
14
17
  /** @typedef {import("./RuleSetCompiler").Effect} Effect */
15
18
 
@@ -43,7 +46,7 @@ class UseEffectRulePlugin {
43
46
  conflictWith("loader", "use");
44
47
  conflictWith("options", "use");
45
48
 
46
- const use = rule.use;
49
+ const use = /** @type {RuleSetUse} */ (rule.use);
47
50
  const enforce = rule.enforce;
48
51
 
49
52
  const type = enforce ? `use-${enforce}` : "use";
@@ -51,12 +54,17 @@ class UseEffectRulePlugin {
51
54
  /**
52
55
  * @param {string} path options path
53
56
  * @param {string} defaultIdent default ident when none is provided
54
- * @param {object} item user provided use value
55
- * @returns {Effect|function(any): Effect[]} effect
57
+ * @param {RuleSetUseItem} item user provided use value
58
+ * @returns {Effect | ((value: TODO) => Effect[])} effect
56
59
  */
57
60
  const useToEffect = (path, defaultIdent, item) => {
58
61
  if (typeof item === "function") {
59
- return data => useToEffectsWithoutIdent(path, item(data));
62
+ return data =>
63
+ useToEffectsWithoutIdent(
64
+ path,
65
+ /** @type {RuleSetUseItem | RuleSetUseItem[]} */
66
+ (item(data))
67
+ );
60
68
  }
61
69
  return useToEffectRaw(path, defaultIdent, item);
62
70
  };
@@ -64,7 +72,7 @@ class UseEffectRulePlugin {
64
72
  /**
65
73
  * @param {string} path options path
66
74
  * @param {string} defaultIdent default ident when none is provided
67
- * @param {{ ident?: string, loader?: RuleSetLoader, options?: RuleSetLoaderOptions }} item user provided use value
75
+ * @param {Exclude<NonNullable<RuleSetUseItem>, EXPECTED_FUNCTION>} item user provided use value
68
76
  * @returns {Effect} effect
69
77
  */
70
78
  const useToEffectRaw = (path, defaultIdent, item) => {
@@ -104,33 +112,50 @@ class UseEffectRulePlugin {
104
112
 
105
113
  /**
106
114
  * @param {string} path options path
107
- * @param {any} items user provided use value
115
+ * @param {RuleSetUseItem | (Falsy | RuleSetUseItem)[]} items user provided use value
108
116
  * @returns {Effect[]} effects
109
117
  */
110
118
  const useToEffectsWithoutIdent = (path, items) => {
111
119
  if (Array.isArray(items)) {
112
- return items
113
- .filter(Boolean)
114
- .map((item, idx) =>
115
- useToEffectRaw(`${path}[${idx}]`, "[[missing ident]]", item)
116
- );
120
+ return items.filter(Boolean).map((item, idx) =>
121
+ useToEffectRaw(
122
+ `${path}[${idx}]`,
123
+ "[[missing ident]]",
124
+ /** @type {Exclude<RuleSetUseItem, EXPECTED_FUNCTION>} */
125
+ (item)
126
+ )
127
+ );
117
128
  }
118
- return [useToEffectRaw(path, "[[missing ident]]", items)];
129
+ return [
130
+ useToEffectRaw(
131
+ path,
132
+ "[[missing ident]]",
133
+ /** @type {Exclude<RuleSetUseItem, EXPECTED_FUNCTION>} */
134
+ (items)
135
+ )
136
+ ];
119
137
  };
120
138
 
121
139
  /**
122
140
  * @param {string} path current path
123
- * @param {any} items user provided use value
124
- * @returns {(Effect|function(any): Effect[])[]} effects
141
+ * @param {RuleSetUse} items user provided use value
142
+ * @returns {(Effect | ((value: TODO) => Effect[]))[]} effects
125
143
  */
126
144
  const useToEffects = (path, items) => {
127
145
  if (Array.isArray(items)) {
128
146
  return items.filter(Boolean).map((item, idx) => {
129
147
  const subPath = `${path}[${idx}]`;
130
- return useToEffect(subPath, subPath, item);
148
+ return useToEffect(
149
+ subPath,
150
+ subPath,
151
+ /** @type {RuleSetUseItem} */
152
+ (item)
153
+ );
131
154
  });
132
155
  }
133
- return [useToEffect(path, path, items)];
156
+ return [
157
+ useToEffect(path, path, /** @type {RuleSetUseItem} */ (items))
158
+ ];
134
159
  };
135
160
 
136
161
  if (typeof use === "function") {
@@ -182,7 +207,12 @@ class UseEffectRulePlugin {
182
207
 
183
208
  const ident =
184
209
  options && typeof options === "object" ? path : undefined;
185
- references.set(ident, options);
210
+ references.set(
211
+ /** @type {TODO} */
212
+ (ident),
213
+ /** @type {RuleSetLoaderOptions} */
214
+ (options)
215
+ );
186
216
  result.effects.push({
187
217
  type: enforce ? `use-${enforce}` : "use",
188
218
  value: {
@@ -20,7 +20,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
20
20
  * @param {string} contentType the contentType to use the content hash for
21
21
  * @param {string} name kind of filename
22
22
  * @param {string} global function name to be assigned
23
- * @param {function(Chunk): TemplatePath | false} getFilenameForChunk functor to get the filename or function
23
+ * @param {(chunk: Chunk) => TemplatePath | false} getFilenameForChunk functor to get the filename or function
24
24
  * @param {boolean} allChunks when false, only async chunks are included
25
25
  */
26
26
  constructor(contentType, name, global, getFilenameForChunk, allChunks) {
@@ -138,7 +138,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
138
138
  };
139
139
  /**
140
140
  * @param {string} value string
141
- * @returns {function(number): string} string to put in quotes with length
141
+ * @returns {(length: number) => string} string to put in quotes with length
142
142
  */
143
143
  const unquotedStringifyWithLength = value => length =>
144
144
  unquotedStringify(`${value}`.slice(0, length));
@@ -191,7 +191,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
191
191
  }
192
192
 
193
193
  /**
194
- * @param {function(Chunk): string | number} fn function from chunk to value
194
+ * @param {(chunk: Chunk) => string | number} fn function from chunk to value
195
195
  * @returns {string} code with static mapping of results of fn
196
196
  */
197
197
  const createMap = fn => {
@@ -225,14 +225,14 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
225
225
  };
226
226
 
227
227
  /**
228
- * @param {function(Chunk): string | number} fn function from chunk to value
228
+ * @param {(chunk: Chunk) => string | number} fn function from chunk to value
229
229
  * @returns {string} code with static mapping of results of fn for including in quoted string
230
230
  */
231
231
  const mapExpr = fn => `" + ${createMap(fn)} + "`;
232
232
 
233
233
  /**
234
- * @param {function(Chunk): string | number} fn function from chunk to value
235
- * @returns {function(number): string} function which generates code with static mapping of results of fn for including in quoted string for specific length
234
+ * @param {(chunk: Chunk) => string | number} fn function from chunk to value
235
+ * @returns {(length: number) => string} function which generates code with static mapping of results of fn for including in quoted string for specific length
236
236
  */
237
237
  const mapExprWithLength = fn => length =>
238
238
  `" + ${createMap(c => `${fn(c)}`.slice(0, length))} + "`;
@@ -32,7 +32,7 @@ const getHttps = memoize(() => require("https"));
32
32
  /**
33
33
  * @param {typeof import("http") | typeof import("https")} request request
34
34
  * @param {string | { toString: () => string } | undefined} proxy proxy
35
- * @returns {function(URL, RequestOptions, function(IncomingMessage): void): EventEmitter} fn
35
+ * @returns {(url: URL, requestOptions: RequestOptions, callback: (incomingMessage: IncomingMessage) => void) => EventEmitter} fn
36
36
  */
37
37
  const proxyFetch = (request, proxy) => (url, options, callback) => {
38
38
  const eventEmitter = new EventEmitter();
@@ -255,8 +255,18 @@ class Lockfile {
255
255
 
256
256
  /**
257
257
  * @template R
258
- * @param {function(function(Error | null, R=): void): void} fn function
259
- * @returns {function(function(Error | null, R=): void): void} cached function
258
+ * @typedef {(err: Error | null, result?: R) => void} FnWithoutKeyCallback
259
+ */
260
+
261
+ /**
262
+ * @template R
263
+ * @typedef {(callback: FnWithoutKeyCallback<R>) => void} FnWithoutKey
264
+ */
265
+
266
+ /**
267
+ * @template R
268
+ * @param {FnWithoutKey<R>} fn function
269
+ * @returns {FnWithoutKey<R>} cached function
260
270
  */
261
271
  const cachedWithoutKey = fn => {
262
272
  let inFlight = false;
@@ -264,7 +274,7 @@ const cachedWithoutKey = fn => {
264
274
  let cachedError;
265
275
  /** @type {R | undefined} */
266
276
  let cachedResult;
267
- /** @type {(function(Error| null, R=): void)[] | undefined} */
277
+ /** @type {FnWithoutKeyCallback<R>[] | undefined} */
268
278
  let cachedCallbacks;
269
279
  return callback => {
270
280
  if (inFlight) {
@@ -286,23 +296,34 @@ const cachedWithoutKey = fn => {
286
296
  };
287
297
  };
288
298
 
299
+ /**
300
+ * @template R
301
+ * @typedef {(err: Error | null, result?: R) => void} FnWithKeyCallback
302
+ */
303
+
304
+ /**
305
+ * @template T
306
+ * @template R
307
+ * @typedef {(item: T, callback: FnWithKeyCallback<R>) => void} FnWithKey
308
+ */
309
+
289
310
  /**
290
311
  * @template T
291
312
  * @template R
292
- * @param {function(T, function(Error | null, R=): void): void} fn function
293
- * @param {function(T, function(Error | null, R=): void): void=} forceFn function for the second try
294
- * @returns {(function(T, function(Error | null, R=): void): void) & { force: function(T, function(Error | null, R=): void): void }} cached function
313
+ * @param {FnWithKey<T, R>} fn function
314
+ * @param {FnWithKey<T, R>=} forceFn function for the second try
315
+ * @returns {(FnWithKey<T, R>) & { force: FnWithKey<T, R> }} cached function
295
316
  */
296
317
  const cachedWithKey = (fn, forceFn = fn) => {
297
318
  /**
298
319
  * @template R
299
- * @typedef {{ result?: R, error?: Error, callbacks?: (function(Error | null, R=): void)[], force?: true }} CacheEntry
320
+ * @typedef {{ result?: R, error?: Error, callbacks?: FnWithKeyCallback<R>[], force?: true }} CacheEntry
300
321
  */
301
322
  /** @type {Map<T, CacheEntry<R>>} */
302
323
  const cache = new Map();
303
324
  /**
304
325
  * @param {T} arg arg
305
- * @param {function(Error | null, R=): void} callback callback
326
+ * @param {FnWithKeyCallback<R>} callback callback
306
327
  * @returns {void}
307
328
  */
308
329
  const resultFn = (arg, callback) => {
@@ -333,7 +354,7 @@ const cachedWithKey = (fn, forceFn = fn) => {
333
354
  };
334
355
  /**
335
356
  * @param {T} arg arg
336
- * @param {function(Error | null, R=): void} callback callback
357
+ * @param {FnWithKeyCallback<R>} callback callback
337
358
  * @returns {void}
338
359
  */
339
360
  resultFn.force = (arg, callback) => {
@@ -487,7 +508,7 @@ class HttpUriPlugin {
487
508
 
488
509
  const getLockfile = cachedWithoutKey(
489
510
  /**
490
- * @param {function(Error | null, Lockfile=): void} callback callback
511
+ * @param {(err: Error | null, lockfile?: Lockfile) => void} callback callback
491
512
  * @returns {void}
492
513
  */
493
514
  callback => {
@@ -581,7 +602,7 @@ class HttpUriPlugin {
581
602
  * @param {Lockfile} lockfile lockfile
582
603
  * @param {string} url url
583
604
  * @param {ResolveContentResult} result result
584
- * @param {function(Error | null, ResolveContentResult=): void} callback callback
605
+ * @param {(err: Error | null, result?: ResolveContentResult) => void} callback callback
585
606
  * @returns {void}
586
607
  */
587
608
  const storeResult = (lockfile, url, result, callback) => {
@@ -608,7 +629,7 @@ class HttpUriPlugin {
608
629
  /**
609
630
  * @param {string} url URL
610
631
  * @param {string | null} integrity integrity
611
- * @param {function(Error | null, ResolveContentResult=): void} callback callback
632
+ * @param {(err: Error | null, resolveContentResult?: ResolveContentResult) => void} callback callback
612
633
  */
613
634
  const resolveContent = (url, integrity, callback) => {
614
635
  /**
@@ -654,7 +675,7 @@ class HttpUriPlugin {
654
675
  /**
655
676
  * @param {string} url URL
656
677
  * @param {FetchResult | RedirectFetchResult | undefined} cachedResult result from cache
657
- * @param {function(Error | null, FetchResult=): void} callback callback
678
+ * @param {(err: Error | null, fetchResult?: FetchResult) => void} callback callback
658
679
  * @returns {void}
659
680
  */
660
681
  const fetchContentRaw = (url, cachedResult, callback) => {
@@ -826,7 +847,7 @@ class HttpUriPlugin {
826
847
  const fetchContent = cachedWithKey(
827
848
  /**
828
849
  * @param {string} url URL
829
- * @param {function(Error | null, { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }=): void} callback callback
850
+ * @param {(err: Error | null, result?: { validUntil: number, etag?: string, entry: LockfileEntry, content: Buffer, fresh: boolean } | { validUntil: number, etag?: string, location: string, fresh: boolean }) => void} callback callback
830
851
  * @returns {void}
831
852
  */
832
853
  (url, callback) => {
@@ -864,7 +885,7 @@ class HttpUriPlugin {
864
885
  const getInfo = cachedWithKey(
865
886
  /**
866
887
  * @param {string} url the url
867
- * @param {function(Error | null, Info=): void} callback callback
888
+ * @param {(err: Error | null, info?: Info) => void} callback callback
868
889
  * @returns {void}
869
890
  */
870
891
  // eslint-disable-next-line no-loop-func
@@ -1113,7 +1134,7 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
1113
1134
  /**
1114
1135
  * @param {URL} url url
1115
1136
  * @param {ResourceDataWithData} resourceData resource data
1116
- * @param {function(Error | null, true | void): void} callback callback
1137
+ * @param {(err: Error | null, result: true | void) => void} callback callback
1117
1138
  */
1118
1139
  const respondWithUrlModule = (url, resourceData, callback) => {
1119
1140
  getInfo(url.href, (err, _result) => {
@@ -7,9 +7,15 @@
7
7
  const memoize = require("../util/memoize");
8
8
  const SerializerMiddleware = require("./SerializerMiddleware");
9
9
 
10
+ /** @typedef {import("./SerializerMiddleware").Context} Context */
10
11
  /** @typedef {import("./types").BufferSerializableType} BufferSerializableType */
11
12
  /** @typedef {import("./types").PrimitiveSerializableType} PrimitiveSerializableType */
12
13
 
14
+ /**
15
+ * @template LAZY_RESULT
16
+ * @typedef {import("./SerializerMiddleware").LazyFunction<LAZY_RESULT>} LazyFunction
17
+ */
18
+
13
19
  /*
14
20
  Format:
15
21
 
@@ -135,8 +141,6 @@ const identifyBigInt = n => {
135
141
  return 2;
136
142
  };
137
143
 
138
- /** @typedef {TODO} Context */
139
-
140
144
  /**
141
145
  * @typedef {PrimitiveSerializableType[]} DeserializedType
142
146
  * @typedef {BufferSerializableType[]} SerializedType
@@ -145,17 +149,17 @@ const identifyBigInt = n => {
145
149
  class BinaryMiddleware extends SerializerMiddleware {
146
150
  /**
147
151
  * @param {DeserializedType} data data
148
- * @param {object} context context object
149
- * @returns {SerializedType|Promise<SerializedType>} serialized data
152
+ * @param {Context} context context object
153
+ * @returns {SerializedType | Promise<SerializedType> | null} serialized data
150
154
  */
151
155
  serialize(data, context) {
152
156
  return this._serialize(data, context);
153
157
  }
154
158
 
155
159
  /**
156
- * @param {function(): Promise<any> | any} fn lazy function
157
- * @param {TODO} context serialize function
158
- * @returns {function(): Promise<any> | any} new lazy
160
+ * @param {LazyFunction<DeserializedType>} fn lazy function
161
+ * @param {Context} context serialize function
162
+ * @returns {LazyFunction<SerializedType>} new lazy
159
163
  */
160
164
  _serializeLazy(fn, context) {
161
165
  return SerializerMiddleware.serializeLazy(fn, data =>
@@ -165,7 +169,7 @@ class BinaryMiddleware extends SerializerMiddleware {
165
169
 
166
170
  /**
167
171
  * @param {DeserializedType} data data
168
- * @param {TODO} context context object
172
+ * @param {Context} context context object
169
173
  * @param {{ leftOverBuffer: Buffer | null, allocationSize: number, increaseCounter: number }} allocationScope allocation scope
170
174
  * @returns {SerializedType} serialized data
171
175
  */
@@ -277,7 +281,7 @@ class BinaryMiddleware extends SerializerMiddleware {
277
281
  case "function": {
278
282
  if (!SerializerMiddleware.isLazy(thing))
279
283
  throw new Error(`Unexpected function ${thing}`);
280
- /** @type {SerializedType | (() => SerializedType)} */
284
+ /** @type {SerializedType | LazyFunction<SerializedType>} */
281
285
  let serializedData =
282
286
  SerializerMiddleware.getLazySerializedValue(thing);
283
287
  if (serializedData === undefined) {
@@ -285,16 +289,23 @@ class BinaryMiddleware extends SerializerMiddleware {
285
289
  flush();
286
290
  allocationScope.leftOverBuffer = leftOverBuffer;
287
291
  const result =
288
- /** @type {(Exclude<PrimitiveSerializableType, Promise<PrimitiveSerializableType>>)[]} */ (
289
- thing()
290
- );
292
+ /** @type {PrimitiveSerializableType[]} */
293
+ (thing());
291
294
  const data = this._serialize(result, context, allocationScope);
292
295
  leftOverBuffer = allocationScope.leftOverBuffer;
293
296
  allocationScope.leftOverBuffer = null;
294
- SerializerMiddleware.setLazySerializedValue(thing, data);
297
+ SerializerMiddleware.setLazySerializedValue(
298
+ /** @type {LazyFunction<DeserializedType>} */
299
+ (thing),
300
+ data
301
+ );
295
302
  serializedData = data;
296
303
  } else {
297
- serializedData = this._serializeLazy(thing, context);
304
+ serializedData = this._serializeLazy(
305
+ /** @type {LazyFunction<DeserializedType>} */
306
+ (thing),
307
+ context
308
+ );
298
309
  flush();
299
310
  buffers.push(serializedData);
300
311
  break;
@@ -644,13 +655,19 @@ class BinaryMiddleware extends SerializerMiddleware {
644
655
 
645
656
  /**
646
657
  * @param {SerializedType} data data
647
- * @param {object} context context object
648
- * @returns {DeserializedType|Promise<DeserializedType>} deserialized data
658
+ * @param {Context} context context object
659
+ * @returns {DeserializedType | Promise<DeserializedType>} deserialized data
649
660
  */
650
661
  deserialize(data, context) {
651
662
  return this._deserialize(data, context);
652
663
  }
653
664
 
665
+ /**
666
+ * @private
667
+ * @param {SerializedType} content content
668
+ * @param {Context} context context object
669
+ * @returns {LazyFunction<DeserializedType>} lazy function
670
+ */
654
671
  _createLazyDeserialized(content, context) {
655
672
  return SerializerMiddleware.createLazy(
656
673
  memoize(() => this._deserialize(content, context)),
@@ -660,6 +677,12 @@ class BinaryMiddleware extends SerializerMiddleware {
660
677
  );
661
678
  }
662
679
 
680
+ /**
681
+ * @private
682
+ * @param {LazyFunction<SerializedType>} fn lazy function
683
+ * @param {Context} context context object
684
+ * @returns {LazyFunction<DeserializedType>} new lazy
685
+ */
663
686
  _deserializeLazy(fn, context) {
664
687
  return SerializerMiddleware.deserializeLazy(fn, data =>
665
688
  this._deserialize(data, context)
@@ -668,7 +691,7 @@ class BinaryMiddleware extends SerializerMiddleware {
668
691
 
669
692
  /**
670
693
  * @param {SerializedType} data data
671
- * @param {TODO} context context object
694
+ * @param {Context} context context object
672
695
  * @returns {DeserializedType} deserialized data
673
696
  */
674
697
  _deserialize(data, context) {
@@ -795,13 +818,17 @@ class BinaryMiddleware extends SerializerMiddleware {
795
818
  return () => {
796
819
  const count = readU32();
797
820
  const lengths = Array.from({ length: count }).map(() => readU32());
821
+ /** @type {(Buffer | LazyFunction<BufferSerializableType[]>)[]} */
798
822
  const content = [];
799
823
  for (let l of lengths) {
800
824
  if (l === 0) {
801
825
  if (typeof currentBuffer !== "function") {
802
826
  throw new Error("Unexpected non-lazy element in stream");
803
827
  }
804
- content.push(currentBuffer);
828
+ content.push(
829
+ /** @type {LazyFunction<BufferSerializableType[]>} */
830
+ (currentBuffer)
831
+ );
805
832
  currentDataItem++;
806
833
  currentBuffer =
807
834
  currentDataItem < data.length ? data[currentDataItem] : null;
@@ -1117,7 +1144,13 @@ class BinaryMiddleware extends SerializerMiddleware {
1117
1144
  let result = [];
1118
1145
  while (currentBuffer !== null) {
1119
1146
  if (typeof currentBuffer === "function") {
1120
- result.push(this._deserializeLazy(currentBuffer, context));
1147
+ result.push(
1148
+ this._deserializeLazy(
1149
+ /** @type {LazyFunction<SerializedType>} */
1150
+ (currentBuffer),
1151
+ context
1152
+ )
1153
+ );
1121
1154
  currentDataItem++;
1122
1155
  currentBuffer =
1123
1156
  currentDataItem < data.length ? data[currentDataItem] : null;