webpack 5.93.0 → 5.94.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (343) hide show
  1. package/README.md +8 -5
  2. package/bin/webpack.js +6 -7
  3. package/hot/log.js +1 -2
  4. package/hot/only-dev-server.js +1 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +4 -3
  8. package/lib/AbstractMethodError.js +10 -5
  9. package/lib/AutomaticPrefetchPlugin.js +1 -1
  10. package/lib/BannerPlugin.js +12 -6
  11. package/lib/Cache.js +8 -10
  12. package/lib/CacheFacade.js +3 -3
  13. package/lib/CaseSensitiveModulesWarning.js +5 -7
  14. package/lib/Chunk.js +14 -11
  15. package/lib/ChunkGraph.js +58 -36
  16. package/lib/ChunkGroup.js +2 -3
  17. package/lib/ChunkTemplate.js +43 -0
  18. package/lib/CleanPlugin.js +10 -11
  19. package/lib/CodeGenerationResults.js +6 -5
  20. package/lib/CommentCompilationWarning.js +0 -1
  21. package/lib/Compilation.js +223 -191
  22. package/lib/Compiler.js +81 -82
  23. package/lib/ConcatenationScope.js +3 -6
  24. package/lib/ConditionalInitFragment.js +6 -7
  25. package/lib/ConstPlugin.js +7 -15
  26. package/lib/ContextExclusionPlugin.js +3 -3
  27. package/lib/ContextModule.js +33 -20
  28. package/lib/ContextModuleFactory.js +89 -44
  29. package/lib/ContextReplacementPlugin.js +10 -9
  30. package/lib/DefinePlugin.js +75 -68
  31. package/lib/DelegatedModule.js +7 -3
  32. package/lib/DelegatedModuleFactoryPlugin.js +36 -22
  33. package/lib/DelegatedPlugin.js +4 -0
  34. package/lib/DependenciesBlock.js +0 -1
  35. package/lib/Dependency.js +10 -14
  36. package/lib/DllEntryPlugin.js +4 -2
  37. package/lib/DllModuleFactory.js +1 -0
  38. package/lib/DllPlugin.js +9 -7
  39. package/lib/DllReferencePlugin.js +30 -15
  40. package/lib/EntryPlugin.js +1 -3
  41. package/lib/EnvironmentPlugin.js +5 -2
  42. package/lib/ErrorHelpers.js +11 -12
  43. package/lib/EvalDevToolModulePlugin.js +10 -12
  44. package/lib/EvalSourceMapDevToolPlugin.js +15 -13
  45. package/lib/ExportsInfo.js +185 -120
  46. package/lib/ExternalModule.js +104 -64
  47. package/lib/ExternalModuleFactoryPlugin.js +23 -10
  48. package/lib/FileSystemInfo.js +791 -422
  49. package/lib/FlagAllModulesAsUsedPlugin.js +1 -1
  50. package/lib/FlagDependencyExportsPlugin.js +12 -11
  51. package/lib/FlagDependencyUsagePlugin.js +1 -1
  52. package/lib/Generator.js +2 -5
  53. package/lib/GraphHelpers.js +3 -2
  54. package/lib/HookWebpackError.js +8 -10
  55. package/lib/HotModuleReplacementPlugin.js +78 -64
  56. package/lib/IgnoreErrorModuleFactory.js +3 -3
  57. package/lib/IgnorePlugin.js +1 -3
  58. package/lib/IgnoreWarningsPlugin.js +6 -9
  59. package/lib/InitFragment.js +2 -3
  60. package/lib/LibManifestPlugin.js +4 -3
  61. package/lib/MainTemplate.js +72 -19
  62. package/lib/Module.js +25 -9
  63. package/lib/ModuleBuildError.js +4 -11
  64. package/lib/ModuleDependencyError.js +5 -5
  65. package/lib/ModuleDependencyWarning.js +5 -5
  66. package/lib/ModuleError.js +1 -5
  67. package/lib/ModuleFilenameHelpers.js +29 -46
  68. package/lib/ModuleGraph.js +7 -6
  69. package/lib/ModuleGraphConnection.js +6 -6
  70. package/lib/ModuleInfoHeaderPlugin.js +82 -30
  71. package/lib/ModuleParseError.js +8 -9
  72. package/lib/ModuleRestoreError.js +1 -1
  73. package/lib/ModuleStoreError.js +1 -1
  74. package/lib/ModuleTemplate.js +33 -1
  75. package/lib/ModuleTypeConstants.js +21 -22
  76. package/lib/ModuleWarning.js +1 -5
  77. package/lib/MultiCompiler.js +24 -26
  78. package/lib/MultiStats.js +73 -31
  79. package/lib/MultiWatching.js +1 -1
  80. package/lib/NormalModule.js +126 -69
  81. package/lib/NormalModuleFactory.js +53 -49
  82. package/lib/OptimizationStages.js +3 -3
  83. package/lib/ProgressPlugin.js +9 -9
  84. package/lib/ProvidePlugin.js +4 -4
  85. package/lib/RuntimeGlobals.js +71 -70
  86. package/lib/RuntimeModule.js +1 -1
  87. package/lib/RuntimePlugin.js +24 -12
  88. package/lib/RuntimeTemplate.js +40 -44
  89. package/lib/SizeFormatHelpers.js +2 -4
  90. package/lib/SourceMapDevToolPlugin.js +42 -34
  91. package/lib/Stats.js +5 -11
  92. package/lib/Template.js +18 -24
  93. package/lib/TemplatedPathPlugin.js +12 -10
  94. package/lib/WarnDeprecatedOptionPlugin.js +0 -1
  95. package/lib/WatchIgnorePlugin.js +26 -9
  96. package/lib/Watching.js +10 -5
  97. package/lib/WebpackOptionsApply.js +84 -62
  98. package/lib/asset/AssetGenerator.js +107 -42
  99. package/lib/asset/AssetModulesPlugin.js +29 -23
  100. package/lib/asset/AssetSourceGenerator.js +2 -7
  101. package/lib/async-modules/AwaitDependenciesInitFragment.js +6 -7
  102. package/lib/buildChunkGraph.js +14 -19
  103. package/lib/cache/IdleFileCachePlugin.js +4 -4
  104. package/lib/cache/MemoryWithGcCachePlugin.js +5 -5
  105. package/lib/cache/PackFileCacheStrategy.js +51 -50
  106. package/lib/cache/ResolverCachePlugin.js +6 -6
  107. package/lib/cache/mergeEtags.js +16 -21
  108. package/lib/cli.js +148 -104
  109. package/lib/config/browserslistTargetHandler.js +16 -13
  110. package/lib/config/defaults.js +31 -28
  111. package/lib/config/normalization.js +335 -344
  112. package/lib/config/target.js +42 -52
  113. package/lib/container/ContainerEntryModule.js +2 -2
  114. package/lib/container/ContainerPlugin.js +1 -1
  115. package/lib/container/RemoteRuntimeModule.js +11 -8
  116. package/lib/container/options.js +18 -4
  117. package/lib/css/CssExportsGenerator.js +26 -24
  118. package/lib/css/CssGenerator.js +9 -4
  119. package/lib/css/CssLoadingRuntimeModule.js +10 -10
  120. package/lib/css/CssModulesPlugin.js +127 -47
  121. package/lib/css/CssParser.js +20 -18
  122. package/lib/css/walkCssTokens.js +80 -95
  123. package/lib/debug/ProfilingPlugin.js +19 -20
  124. package/lib/dependencies/AMDDefineDependency.js +1 -1
  125. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +83 -47
  126. package/lib/dependencies/AMDRequireArrayDependency.js +9 -10
  127. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +22 -16
  128. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  129. package/lib/dependencies/CommonJsDependencyHelpers.js +6 -2
  130. package/lib/dependencies/CommonJsExportRequireDependency.js +37 -41
  131. package/lib/dependencies/CommonJsExportsDependency.js +0 -1
  132. package/lib/dependencies/CommonJsExportsParserPlugin.js +19 -23
  133. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
  134. package/lib/dependencies/CommonJsImportsParserPlugin.js +52 -61
  135. package/lib/dependencies/CommonJsSelfReferenceDependency.js +6 -8
  136. package/lib/dependencies/ConstDependency.js +1 -1
  137. package/lib/dependencies/ContextDependency.js +1 -1
  138. package/lib/dependencies/ContextDependencyHelpers.js +31 -34
  139. package/lib/dependencies/ContextElementDependency.js +2 -2
  140. package/lib/dependencies/CriticalDependencyWarning.js +1 -1
  141. package/lib/dependencies/CssExportDependency.js +7 -7
  142. package/lib/dependencies/CssImportDependency.js +0 -2
  143. package/lib/dependencies/CssLocalIdentifierDependency.js +3 -3
  144. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  145. package/lib/dependencies/CssUrlDependency.js +4 -5
  146. package/lib/dependencies/DynamicExports.js +5 -5
  147. package/lib/dependencies/ExportsInfoDependency.js +1 -2
  148. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -1
  149. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -5
  150. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +27 -16
  151. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  152. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +107 -64
  153. package/lib/dependencies/HarmonyExports.js +2 -2
  154. package/lib/dependencies/HarmonyImportDependency.js +2 -4
  155. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -4
  156. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -15
  157. package/lib/dependencies/ImportDependency.js +1 -1
  158. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +5 -5
  159. package/lib/dependencies/ImportMetaPlugin.js +11 -13
  160. package/lib/dependencies/ImportParserPlugin.js +39 -44
  161. package/lib/dependencies/JsonExportsDependency.js +22 -18
  162. package/lib/dependencies/LoaderPlugin.js +47 -36
  163. package/lib/dependencies/LocalModule.js +1 -1
  164. package/lib/dependencies/LocalModulesHelpers.js +4 -4
  165. package/lib/dependencies/ModuleDecoratorDependency.js +1 -1
  166. package/lib/dependencies/ProvidedDependency.js +1 -1
  167. package/lib/dependencies/PureExpressionDependency.js +6 -6
  168. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  169. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  170. package/lib/dependencies/SystemPlugin.js +1 -1
  171. package/lib/dependencies/URLDependency.js +3 -3
  172. package/lib/dependencies/URLPlugin.js +66 -12
  173. package/lib/dependencies/WorkerPlugin.js +25 -24
  174. package/lib/dependencies/processExportInfo.js +3 -1
  175. package/lib/electron/ElectronTargetPlugin.js +1 -0
  176. package/lib/esm/ModuleChunkFormatPlugin.js +3 -3
  177. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -3
  178. package/lib/formatLocation.js +1 -2
  179. package/lib/hmr/HotModuleReplacement.runtime.js +4 -5
  180. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
  181. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +9 -12
  182. package/lib/hmr/LazyCompilationPlugin.js +27 -12
  183. package/lib/hmr/lazyCompilationBackend.js +64 -40
  184. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -3
  185. package/lib/ids/DeterministicChunkIdsPlugin.js +2 -4
  186. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  187. package/lib/ids/HashedModuleIdsPlugin.js +5 -1
  188. package/lib/ids/IdHelpers.js +29 -39
  189. package/lib/ids/SyncModuleIdsPlugin.js +7 -2
  190. package/lib/index.js +1 -5
  191. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -4
  192. package/lib/javascript/BasicEvaluatedExpression.js +4 -19
  193. package/lib/javascript/ChunkHelpers.js +1 -1
  194. package/lib/javascript/CommonJsChunkFormatPlugin.js +3 -2
  195. package/lib/javascript/EnableChunkLoadingPlugin.js +7 -6
  196. package/lib/javascript/JavascriptGenerator.js +23 -7
  197. package/lib/javascript/JavascriptModulesPlugin.js +91 -69
  198. package/lib/javascript/JavascriptParser.js +179 -200
  199. package/lib/javascript/JavascriptParserHelpers.js +20 -21
  200. package/lib/javascript/StartupHelpers.js +41 -13
  201. package/lib/json/JsonGenerator.js +7 -13
  202. package/lib/json/JsonModulesPlugin.js +1 -4
  203. package/lib/json/JsonParser.js +5 -3
  204. package/lib/library/AmdLibraryPlugin.js +12 -16
  205. package/lib/library/AssignLibraryPlugin.js +8 -10
  206. package/lib/library/EnableLibraryPlugin.js +15 -14
  207. package/lib/library/JsonpLibraryPlugin.js +2 -1
  208. package/lib/library/ModernModuleLibraryPlugin.js +8 -6
  209. package/lib/library/ModuleLibraryPlugin.js +2 -1
  210. package/lib/library/SystemLibraryPlugin.js +2 -1
  211. package/lib/library/UmdLibraryPlugin.js +66 -92
  212. package/lib/logging/Logger.js +32 -4
  213. package/lib/logging/createConsoleLogger.js +12 -13
  214. package/lib/logging/runtime.js +7 -8
  215. package/lib/logging/truncateArgs.js +5 -8
  216. package/lib/node/NodeWatchFileSystem.js +3 -18
  217. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
  218. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
  219. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
  220. package/lib/node/nodeConsole.js +22 -22
  221. package/lib/optimize/AggressiveMergingPlugin.js +2 -4
  222. package/lib/optimize/AggressiveSplittingPlugin.js +16 -19
  223. package/lib/optimize/ConcatenatedModule.js +80 -48
  224. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  225. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -3
  226. package/lib/optimize/InnerGraph.js +17 -17
  227. package/lib/optimize/InnerGraphPlugin.js +8 -7
  228. package/lib/optimize/LimitChunkCountPlugin.js +2 -3
  229. package/lib/optimize/MangleExportsPlugin.js +1 -0
  230. package/lib/optimize/MinMaxSizeWarning.js +1 -1
  231. package/lib/optimize/ModuleConcatenationPlugin.js +54 -78
  232. package/lib/optimize/RealContentHashPlugin.js +7 -10
  233. package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
  234. package/lib/optimize/SideEffectsFlagPlugin.js +6 -2
  235. package/lib/optimize/SplitChunksPlugin.js +34 -30
  236. package/lib/performance/SizeLimitsPlugin.js +2 -2
  237. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
  238. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
  239. package/lib/rules/BasicEffectRulePlugin.js +3 -1
  240. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  241. package/lib/rules/ObjectMatcherRulePlugin.js +4 -1
  242. package/lib/rules/RuleSetCompiler.js +41 -22
  243. package/lib/rules/UseEffectRulePlugin.js +36 -32
  244. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  245. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  246. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
  247. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
  248. package/lib/runtime/EnsureChunkRuntimeModule.js +10 -11
  249. package/lib/runtime/GetChunkFilenameRuntimeModule.js +11 -17
  250. package/lib/runtime/LoadScriptRuntimeModule.js +17 -18
  251. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -3
  252. package/lib/schemes/DataUriPlugin.js +1 -1
  253. package/lib/schemes/HttpUriPlugin.js +241 -126
  254. package/lib/serialization/BinaryMiddleware.js +44 -28
  255. package/lib/serialization/DateObjectSerializer.js +1 -0
  256. package/lib/serialization/ErrorObjectSerializer.js +2 -0
  257. package/lib/serialization/FileMiddleware.js +154 -106
  258. package/lib/serialization/MapObjectSerializer.js +2 -1
  259. package/lib/serialization/NullPrototypeObjectSerializer.js +3 -2
  260. package/lib/serialization/ObjectMiddleware.js +52 -56
  261. package/lib/serialization/PlainObjectSerializer.js +32 -6
  262. package/lib/serialization/RegExpObjectSerializer.js +1 -0
  263. package/lib/serialization/Serializer.js +4 -5
  264. package/lib/serialization/SerializerMiddleware.js +6 -6
  265. package/lib/serialization/SetObjectSerializer.js +2 -1
  266. package/lib/sharing/ConsumeSharedPlugin.js +116 -97
  267. package/lib/sharing/ConsumeSharedRuntimeModule.js +4 -4
  268. package/lib/sharing/ProvideForSharedDependency.js +0 -1
  269. package/lib/sharing/ProvideSharedPlugin.js +2 -2
  270. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  271. package/lib/sharing/utils.js +15 -27
  272. package/lib/stats/DefaultStatsFactoryPlugin.js +424 -281
  273. package/lib/stats/DefaultStatsPresetPlugin.js +73 -18
  274. package/lib/stats/DefaultStatsPrinterPlugin.js +370 -101
  275. package/lib/stats/StatsFactory.js +127 -56
  276. package/lib/stats/StatsPrinter.js +75 -44
  277. package/lib/util/ArrayHelpers.js +8 -4
  278. package/lib/util/ArrayQueue.js +1 -1
  279. package/lib/util/AsyncQueue.js +31 -12
  280. package/lib/util/IterableHelpers.js +3 -4
  281. package/lib/util/LazyBucketSortedSet.js +60 -44
  282. package/lib/util/LazySet.js +1 -0
  283. package/lib/util/MapHelpers.js +1 -3
  284. package/lib/util/ParallelismFactorCalculator.js +1 -1
  285. package/lib/util/Queue.js +1 -1
  286. package/lib/util/Semaphore.js +4 -7
  287. package/lib/util/SetHelpers.js +5 -5
  288. package/lib/util/SortableSet.js +4 -3
  289. package/lib/util/StackedCacheMap.js +4 -6
  290. package/lib/util/StackedMap.js +1 -3
  291. package/lib/util/StringXor.js +0 -5
  292. package/lib/util/TupleQueue.js +1 -1
  293. package/lib/util/TupleSet.js +15 -5
  294. package/lib/util/URLAbsoluteSpecifier.js +7 -7
  295. package/lib/util/WeakTupleMap.js +19 -21
  296. package/lib/util/binarySearchBounds.js +5 -12
  297. package/lib/util/chainedImports.js +1 -1
  298. package/lib/util/cleverMerge.js +21 -19
  299. package/lib/util/comparators.js +57 -52
  300. package/lib/util/compileBooleanMatcher.js +3 -6
  301. package/lib/util/conventions.js +8 -11
  302. package/lib/util/createHash.js +9 -6
  303. package/lib/util/deprecation.js +22 -12
  304. package/lib/util/deterministicGrouping.js +19 -26
  305. package/lib/util/findGraphRoots.js +2 -2
  306. package/lib/util/fs.js +31 -31
  307. package/lib/util/hash/md4.js +2 -2
  308. package/lib/util/hash/wasm-hash.js +7 -7
  309. package/lib/util/hash/xxhash64.js +2 -2
  310. package/lib/util/identifier.js +81 -59
  311. package/lib/util/memoize.js +8 -10
  312. package/lib/util/mergeScope.js +6 -9
  313. package/lib/util/nonNumericOnlyHash.js +2 -2
  314. package/lib/util/numberHash.js +1 -6
  315. package/lib/util/objectToMap.js +0 -1
  316. package/lib/util/propertyAccess.js +2 -5
  317. package/lib/util/propertyName.js +1 -3
  318. package/lib/util/registerExternalSerializer.js +1 -1
  319. package/lib/util/runtime.js +103 -113
  320. package/lib/util/semver.js +29 -27
  321. package/lib/util/serialization.js +16 -1
  322. package/lib/util/smartGrouping.js +5 -5
  323. package/lib/util/source.js +1 -1
  324. package/lib/wasm/EnableWasmLoadingPlugin.js +5 -4
  325. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  326. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -6
  327. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  328. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +20 -19
  329. package/lib/wasm-sync/WebAssemblyGenerator.js +14 -29
  330. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  331. package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
  332. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -3
  333. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
  334. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  335. package/package.json +15 -14
  336. package/schemas/WebpackOptions.check.js +1 -1
  337. package/schemas/WebpackOptions.json +1 -0
  338. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  339. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  340. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  341. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  342. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  343. package/types.d.ts +667 -347
@@ -15,17 +15,37 @@ const createHash = require("../util/createHash");
15
15
  const { mkdirp, dirname, join } = require("../util/fs");
16
16
  const memoize = require("../util/memoize");
17
17
 
18
+ /** @typedef {import("http").IncomingMessage} IncomingMessage */
19
+ /** @typedef {import("http").RequestOptions} RequestOptions */
20
+ /** @typedef {import("net").Socket} Socket */
21
+ /** @typedef {import("stream").Readable} Readable */
18
22
  /** @typedef {import("../../declarations/plugins/schemes/HttpUriPlugin").HttpUriPluginOptions} HttpUriPluginOptions */
19
23
  /** @typedef {import("../Compiler")} Compiler */
24
+ /** @typedef {import("../FileSystemInfo").Snapshot} Snapshot */
25
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
26
+ /** @typedef {import("../NormalModuleFactory").ResourceDataWithData} ResourceDataWithData */
27
+ /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
20
28
 
21
29
  const getHttp = memoize(() => require("http"));
22
30
  const getHttps = memoize(() => require("https"));
31
+
32
+ /**
33
+ * @param {typeof import("http") | typeof import("https")} request request
34
+ * @param {string | { toString: () => string } | undefined} proxy proxy
35
+ * @returns {function(URL, RequestOptions, function(IncomingMessage): void): EventEmitter} fn
36
+ */
23
37
  const proxyFetch = (request, proxy) => (url, options, callback) => {
24
38
  const eventEmitter = new EventEmitter();
25
- const doRequest = socket =>
39
+
40
+ /**
41
+ * @param {Socket=} socket socket
42
+ * @returns {void}
43
+ */
44
+ const doRequest = socket => {
26
45
  request
27
46
  .get(url, { ...options, ...(socket && { socket }) }, callback)
28
47
  .on("error", eventEmitter.emit.bind(eventEmitter, "error"));
48
+ };
29
49
 
30
50
  if (proxy) {
31
51
  const { hostname: host, port } = new URL(proxy);
@@ -59,8 +79,9 @@ const proxyFetch = (request, proxy) => (url, options, callback) => {
59
79
  return eventEmitter;
60
80
  };
61
81
 
62
- /** @type {(() => void)[] | undefined} */
63
- let inProgressWrite = undefined;
82
+ /** @typedef {() => void} InProgressWriteItem */
83
+ /** @type {InProgressWriteItem[] | undefined} */
84
+ let inProgressWrite;
64
85
 
65
86
  const validate = createSchemaValidation(
66
87
  require("../../schemas/plugins/schemes/HttpUriPlugin.check.js"),
@@ -87,7 +108,7 @@ const toSafePath = str =>
87
108
  const computeIntegrity = content => {
88
109
  const hash = createHash("sha512");
89
110
  hash.update(content);
90
- const integrity = "sha512-" + hash.digest("base64");
111
+ const integrity = `sha512-${hash.digest("base64")}`;
91
112
  return integrity;
92
113
  };
93
114
 
@@ -138,8 +159,8 @@ const parseCacheControl = (cacheControl, requestTime) => {
138
159
  if (cacheControl) {
139
160
  const parsed = parseKeyValuePairs(cacheControl);
140
161
  if (parsed["no-cache"]) storeCache = storeLock = false;
141
- if (parsed["max-age"] && !isNaN(+parsed["max-age"])) {
142
- validUntil = requestTime + +parsed["max-age"] * 1000;
162
+ if (parsed["max-age"] && !Number.isNaN(Number(parsed["max-age"]))) {
163
+ validUntil = requestTime + Number(parsed["max-age"]) * 1000;
143
164
  }
144
165
  if (parsed["must-revalidate"]) validUntil = 0;
145
166
  }
@@ -157,21 +178,22 @@ const parseCacheControl = (cacheControl, requestTime) => {
157
178
  * @property {string} contentType
158
179
  */
159
180
 
160
- const areLockfileEntriesEqual = (a, b) => {
161
- return (
162
- a.resolved === b.resolved &&
163
- a.integrity === b.integrity &&
164
- a.contentType === b.contentType
165
- );
166
- };
181
+ /**
182
+ * @param {LockfileEntry} a first lockfile entry
183
+ * @param {LockfileEntry} b second lockfile entry
184
+ * @returns {boolean} true when equal, otherwise false
185
+ */
186
+ const areLockfileEntriesEqual = (a, b) =>
187
+ a.resolved === b.resolved &&
188
+ a.integrity === b.integrity &&
189
+ a.contentType === b.contentType;
167
190
 
168
191
  /**
169
192
  * @param {LockfileEntry} entry lockfile entry
170
193
  * @returns {`resolved: ${string}, integrity: ${string}, contentType: ${*}`} stringified entry
171
194
  */
172
- const entryToString = entry => {
173
- return `resolved: ${entry.resolved}, integrity: ${entry.integrity}, contentType: ${entry.contentType}`;
174
- };
195
+ const entryToString = entry =>
196
+ `resolved: ${entry.resolved}, integrity: ${entry.integrity}, contentType: ${entry.contentType}`;
175
197
 
176
198
  class Lockfile {
177
199
  constructor() {
@@ -233,17 +255,17 @@ class Lockfile {
233
255
 
234
256
  /**
235
257
  * @template R
236
- * @param {function(function(Error=, R=): void): void} fn function
237
- * @returns {function(function((Error | null)=, R=): void): void} cached function
258
+ * @param {function(function(Error | null, R=): void): void} fn function
259
+ * @returns {function(function(Error | null, R=): void): void} cached function
238
260
  */
239
261
  const cachedWithoutKey = fn => {
240
262
  let inFlight = false;
241
263
  /** @type {Error | undefined} */
242
- let cachedError = undefined;
264
+ let cachedError;
243
265
  /** @type {R | undefined} */
244
- let cachedResult = undefined;
245
- /** @type {(function(Error=, R=): void)[] | undefined} */
246
- let cachedCallbacks = undefined;
266
+ let cachedResult;
267
+ /** @type {(function(Error| null, R=): void)[] | undefined} */
268
+ let cachedCallbacks;
247
269
  return callback => {
248
270
  if (inFlight) {
249
271
  if (cachedResult !== undefined) return callback(null, cachedResult);
@@ -267,14 +289,22 @@ const cachedWithoutKey = fn => {
267
289
  /**
268
290
  * @template T
269
291
  * @template R
270
- * @param {function(T, function(Error=, R=): void): void} fn function
271
- * @param {function(T, function(Error=, R=): void): void=} forceFn function for the second try
272
- * @returns {(function(T, function((Error | null)=, R=): void): void) & { force: function(T, function((Error | null)=, R=): void): void }} cached function
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
273
295
  */
274
296
  const cachedWithKey = (fn, forceFn = fn) => {
275
- /** @typedef {{ result?: R, error?: Error, callbacks?: (function((Error | null)=, R=): void)[], force?: true }} CacheEntry */
276
- /** @type {Map<T, CacheEntry>} */
297
+ /**
298
+ * @template R
299
+ * @typedef {{ result?: R, error?: Error, callbacks?: (function(Error | null, R=): void)[], force?: true }} CacheEntry
300
+ */
301
+ /** @type {Map<T, CacheEntry<R>>} */
277
302
  const cache = new Map();
303
+ /**
304
+ * @param {T} arg arg
305
+ * @param {function(Error | null, R=): void} callback callback
306
+ * @returns {void}
307
+ */
278
308
  const resultFn = (arg, callback) => {
279
309
  const cacheEntry = cache.get(arg);
280
310
  if (cacheEntry !== undefined) {
@@ -285,7 +315,7 @@ const cachedWithKey = (fn, forceFn = fn) => {
285
315
  else cacheEntry.callbacks.push(callback);
286
316
  return;
287
317
  }
288
- /** @type {CacheEntry} */
318
+ /** @type {CacheEntry<R>} */
289
319
  const newCacheEntry = {
290
320
  result: undefined,
291
321
  error: undefined,
@@ -301,6 +331,11 @@ const cachedWithKey = (fn, forceFn = fn) => {
301
331
  if (callbacks !== undefined) for (const cb of callbacks) cb(err, result);
302
332
  });
303
333
  };
334
+ /**
335
+ * @param {T} arg arg
336
+ * @param {function(Error | null, R=): void} callback callback
337
+ * @returns {void}
338
+ */
304
339
  resultFn.force = (arg, callback) => {
305
340
  const cacheEntry = cache.get(arg);
306
341
  if (cacheEntry !== undefined && cacheEntry.force) {
@@ -311,7 +346,7 @@ const cachedWithKey = (fn, forceFn = fn) => {
311
346
  else cacheEntry.callbacks.push(callback);
312
347
  return;
313
348
  }
314
- /** @type {CacheEntry} */
349
+ /** @type {CacheEntry<R>} */
315
350
  const newCacheEntry = {
316
351
  result: undefined,
317
352
  error: undefined,
@@ -331,6 +366,24 @@ const cachedWithKey = (fn, forceFn = fn) => {
331
366
  return resultFn;
332
367
  };
333
368
 
369
+ /**
370
+ * @typedef {object} LockfileCache
371
+ * @property {Lockfile} lockfile lockfile
372
+ * @property {Snapshot} snapshot snapshot
373
+ */
374
+
375
+ /**
376
+ * @typedef {object} ResolveContentResult
377
+ * @property {LockfileEntry} entry lockfile entry
378
+ * @property {Buffer} content content
379
+ * @property {boolean} storeLock need store lockfile
380
+ */
381
+
382
+ /** @typedef {{ storeCache: boolean, storeLock: boolean, validUntil: number, etag: string | undefined, fresh: boolean }} FetchResultMeta */
383
+ /** @typedef {FetchResultMeta & { location: string }} RedirectFetchResult */
384
+ /** @typedef {FetchResultMeta & { entry: LockfileEntry, content: Buffer }} ContentFetchResult */
385
+ /** @typedef {RedirectFetchResult | ContentFetchResult} FetchResult */
386
+
334
387
  class HttpUriPlugin {
335
388
  /**
336
389
  * @param {HttpUriPluginOptions} options options
@@ -352,7 +405,7 @@ class HttpUriPlugin {
352
405
  */
353
406
  apply(compiler) {
354
407
  const proxy =
355
- this._proxy || process.env["http_proxy"] || process.env["HTTP_PROXY"];
408
+ this._proxy || process.env.http_proxy || process.env.HTTP_PROXY;
356
409
  const schemes = [
357
410
  {
358
411
  scheme: "http",
@@ -363,11 +416,14 @@ class HttpUriPlugin {
363
416
  fetch: proxyFetch(getHttps(), proxy)
364
417
  }
365
418
  ];
419
+ /** @type {LockfileCache} */
366
420
  let lockfileCache;
367
421
  compiler.hooks.compilation.tap(
368
422
  "HttpUriPlugin",
369
423
  (compilation, { normalModuleFactory }) => {
370
- const intermediateFs = compiler.intermediateFileSystem;
424
+ const intermediateFs =
425
+ /** @type {IntermediateFileSystem} */
426
+ (compiler.intermediateFileSystem);
371
427
  const fs = compilation.inputFileSystem;
372
428
  const cache = compilation.getCache("webpack.HttpUriPlugin");
373
429
  const logger = compilation.getLogger("webpack.HttpUriPlugin");
@@ -385,7 +441,7 @@ class HttpUriPlugin {
385
441
  const cacheLocation =
386
442
  this._cacheLocation !== undefined
387
443
  ? this._cacheLocation
388
- : lockfileLocation + ".data";
444
+ : `${lockfileLocation}.data`;
389
445
  const upgrade = this._upgrade || false;
390
446
  const frozen = this._frozen || false;
391
447
  const hashFunction = "sha512";
@@ -431,7 +487,7 @@ class HttpUriPlugin {
431
487
 
432
488
  const getLockfile = cachedWithoutKey(
433
489
  /**
434
- * @param {function((Error | null)=, Lockfile=): void} callback callback
490
+ * @param {function(Error | null, Lockfile=): void} callback callback
435
491
  * @returns {void}
436
492
  */
437
493
  callback => {
@@ -448,14 +504,14 @@ class HttpUriPlugin {
448
504
  [],
449
505
  buffer ? [] : [lockfileLocation],
450
506
  { timestamp: true },
451
- (err, snapshot) => {
507
+ (err, s) => {
452
508
  if (err) return callback(err);
453
509
  const lockfile = buffer
454
510
  ? Lockfile.parse(buffer.toString("utf-8"))
455
511
  : new Lockfile();
456
512
  lockfileCache = {
457
513
  lockfile,
458
- snapshot
514
+ snapshot: /** @type {Snapshot} */ (s)
459
515
  };
460
516
  callback(null, lockfile);
461
517
  }
@@ -477,8 +533,10 @@ class HttpUriPlugin {
477
533
  }
478
534
  );
479
535
 
480
- /** @type {Map<string, LockfileEntry | "ignore" | "no-cache"> | undefined} */
481
- let lockfileUpdates = undefined;
536
+ /** @typedef {Map<string, LockfileEntry | "ignore" | "no-cache">} LockfileUpdates */
537
+
538
+ /** @type {LockfileUpdates | undefined} */
539
+ let lockfileUpdates;
482
540
 
483
541
  /**
484
542
  * @param {Lockfile} lockfile lockfile instance
@@ -519,6 +577,13 @@ class HttpUriPlugin {
519
577
  }
520
578
  };
521
579
 
580
+ /**
581
+ * @param {Lockfile} lockfile lockfile
582
+ * @param {string} url url
583
+ * @param {ResolveContentResult} result result
584
+ * @param {function(Error | null, ResolveContentResult=): void} callback callback
585
+ * @returns {void}
586
+ */
522
587
  const storeResult = (lockfile, url, result, callback) => {
523
588
  if (result.storeLock) {
524
589
  storeLockEntry(lockfile, url, result.entry);
@@ -541,12 +606,16 @@ class HttpUriPlugin {
541
606
 
542
607
  for (const { scheme, fetch } of schemes) {
543
608
  /**
544
- *
545
609
  * @param {string} url URL
546
- * @param {string} integrity integrity
547
- * @param {function((Error | null)=, { entry: LockfileEntry, content: Buffer, storeLock: boolean }=): void} callback callback
610
+ * @param {string | null} integrity integrity
611
+ * @param {function(Error | null, ResolveContentResult=): void} callback callback
548
612
  */
549
613
  const resolveContent = (url, integrity, callback) => {
614
+ /**
615
+ * @param {Error | null} err error
616
+ * @param {TODO} result result result
617
+ * @returns {void}
618
+ */
550
619
  const handleResult = (err, result) => {
551
620
  if (err) return callback(err);
552
621
  if ("location" in result) {
@@ -555,41 +624,37 @@ class HttpUriPlugin {
555
624
  integrity,
556
625
  (err, innerResult) => {
557
626
  if (err) return callback(err);
627
+ const { entry, content, storeLock } =
628
+ /** @type {ResolveContentResult} */ (innerResult);
558
629
  callback(null, {
559
- entry: innerResult.entry,
560
- content: innerResult.content,
561
- storeLock: innerResult.storeLock && result.storeLock
630
+ entry,
631
+ content,
632
+ storeLock: storeLock && result.storeLock
562
633
  });
563
634
  }
564
635
  );
565
- } else {
566
- if (
567
- !result.fresh &&
568
- integrity &&
569
- result.entry.integrity !== integrity &&
570
- !verifyIntegrity(result.content, integrity)
571
- ) {
572
- return fetchContent.force(url, handleResult);
573
- }
574
- return callback(null, {
575
- entry: result.entry,
576
- content: result.content,
577
- storeLock: result.storeLock
578
- });
579
636
  }
637
+ if (
638
+ !result.fresh &&
639
+ integrity &&
640
+ result.entry.integrity !== integrity &&
641
+ !verifyIntegrity(result.content, integrity)
642
+ ) {
643
+ return fetchContent.force(url, handleResult);
644
+ }
645
+ return callback(null, {
646
+ entry: result.entry,
647
+ content: result.content,
648
+ storeLock: result.storeLock
649
+ });
580
650
  };
581
651
  fetchContent(url, handleResult);
582
652
  };
583
653
 
584
- /** @typedef {{ storeCache: boolean, storeLock: boolean, validUntil: number, etag: string | undefined, fresh: boolean }} FetchResultMeta */
585
- /** @typedef {FetchResultMeta & { location: string }} RedirectFetchResult */
586
- /** @typedef {FetchResultMeta & { entry: LockfileEntry, content: Buffer }} ContentFetchResult */
587
- /** @typedef {RedirectFetchResult | ContentFetchResult} FetchResult */
588
-
589
654
  /**
590
655
  * @param {string} url URL
591
- * @param {FetchResult | RedirectFetchResult} cachedResult result from cache
592
- * @param {function((Error | null)=, FetchResult=): void} callback callback
656
+ * @param {FetchResult | RedirectFetchResult | undefined} cachedResult result from cache
657
+ * @param {function(Error | null, FetchResult=): void} callback callback
593
658
  * @returns {void}
594
659
  */
595
660
  const fetchContentRaw = (url, cachedResult, callback) => {
@@ -600,14 +665,14 @@ class HttpUriPlugin {
600
665
  headers: {
601
666
  "accept-encoding": "gzip, deflate, br",
602
667
  "user-agent": "webpack",
603
- "if-none-match": cachedResult
604
- ? cachedResult.etag || null
605
- : null
668
+ "if-none-match": /** @type {TODO} */ (
669
+ cachedResult ? cachedResult.etag || null : null
670
+ )
606
671
  }
607
672
  },
608
673
  res => {
609
- const etag = res.headers["etag"];
610
- const location = res.headers["location"];
674
+ const etag = res.headers.etag;
675
+ const location = res.headers.location;
611
676
  const cacheControl = res.headers["cache-control"];
612
677
  const { storeLock, storeCache, validUntil } = parseCacheControl(
613
678
  cacheControl,
@@ -662,23 +727,21 @@ class HttpUriPlugin {
662
727
  );
663
728
  };
664
729
  if (res.statusCode === 304) {
730
+ const result = /** @type {FetchResult} */ (cachedResult);
665
731
  if (
666
- cachedResult.validUntil < validUntil ||
667
- cachedResult.storeLock !== storeLock ||
668
- cachedResult.storeCache !== storeCache ||
669
- cachedResult.etag !== etag
732
+ result.validUntil < validUntil ||
733
+ result.storeLock !== storeLock ||
734
+ result.storeCache !== storeCache ||
735
+ result.etag !== etag
670
736
  ) {
671
- return finishWith(cachedResult);
672
- } else {
673
- logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
674
- return callback(null, {
675
- ...cachedResult,
676
- fresh: true
677
- });
737
+ return finishWith(result);
678
738
  }
739
+ logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
740
+ return callback(null, { ...result, fresh: true });
679
741
  }
680
742
  if (
681
743
  location &&
744
+ res.statusCode &&
682
745
  res.statusCode >= 301 &&
683
746
  res.statusCode <= 308
684
747
  ) {
@@ -695,22 +758,23 @@ class HttpUriPlugin {
695
758
  cachedResult.etag !== etag
696
759
  ) {
697
760
  return finishWith(result);
698
- } else {
699
- logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
700
- return callback(null, {
701
- ...result,
702
- fresh: true,
703
- storeLock,
704
- storeCache,
705
- validUntil,
706
- etag
707
- });
708
761
  }
762
+ logger.debug(`GET ${url} [${res.statusCode}] (unchanged)`);
763
+ return callback(null, {
764
+ ...result,
765
+ fresh: true,
766
+ storeLock,
767
+ storeCache,
768
+ validUntil,
769
+ etag
770
+ });
709
771
  }
710
772
  const contentType = res.headers["content-type"] || "";
773
+ /** @type {Buffer[]} */
711
774
  const bufferArr = [];
712
775
 
713
776
  const contentEncoding = res.headers["content-encoding"];
777
+ /** @type {Readable} */
714
778
  let stream = res;
715
779
  if (contentEncoding === "gzip") {
716
780
  stream = stream.pipe(createGunzip());
@@ -762,9 +826,10 @@ class HttpUriPlugin {
762
826
  const fetchContent = cachedWithKey(
763
827
  /**
764
828
  * @param {string} url URL
765
- * @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
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
766
830
  * @returns {void}
767
- */ (url, callback) => {
831
+ */
832
+ (url, callback) => {
768
833
  cache.get(url, null, (err, cachedResult) => {
769
834
  if (err) return callback(err);
770
835
  if (cachedResult) {
@@ -777,25 +842,32 @@ class HttpUriPlugin {
777
842
  (url, callback) => fetchContentRaw(url, undefined, callback)
778
843
  );
779
844
 
845
+ /**
846
+ * @param {string} uri uri
847
+ * @returns {boolean} true when allowed, otherwise false
848
+ */
780
849
  const isAllowed = uri => {
781
850
  for (const allowed of allowedUris) {
782
851
  if (typeof allowed === "string") {
783
852
  if (uri.startsWith(allowed)) return true;
784
853
  } else if (typeof allowed === "function") {
785
854
  if (allowed(uri)) return true;
786
- } else {
787
- if (allowed.test(uri)) return true;
855
+ } else if (allowed.test(uri)) {
856
+ return true;
788
857
  }
789
858
  }
790
859
  return false;
791
860
  };
792
861
 
862
+ /** @typedef {{ entry: LockfileEntry, content: Buffer }} Info */
863
+
793
864
  const getInfo = cachedWithKey(
794
865
  /**
795
866
  * @param {string} url the url
796
- * @param {function((Error | null)=, { entry: LockfileEntry, content: Buffer }=): void} callback callback
867
+ * @param {function(Error | null, Info=): void} callback callback
797
868
  * @returns {void}
798
869
  */
870
+ // eslint-disable-next-line no-loop-func
799
871
  (url, callback) => {
800
872
  if (!isAllowed(url)) {
801
873
  return callback(
@@ -806,8 +878,9 @@ class HttpUriPlugin {
806
878
  )
807
879
  );
808
880
  }
809
- getLockfile((err, lockfile) => {
881
+ getLockfile((err, _lockfile) => {
810
882
  if (err) return callback(err);
883
+ const lockfile = /** @type {Lockfile} */ (_lockfile);
811
884
  const entryOrString = lockfile.entries.get(url);
812
885
  if (!entryOrString) {
813
886
  if (frozen) {
@@ -819,14 +892,24 @@ class HttpUriPlugin {
819
892
  }
820
893
  resolveContent(url, null, (err, result) => {
821
894
  if (err) return callback(err);
822
- storeResult(lockfile, url, result, callback);
895
+ storeResult(
896
+ /** @type {Lockfile} */
897
+ (lockfile),
898
+ url,
899
+ /** @type {ResolveContentResult} */
900
+ (result),
901
+ callback
902
+ );
823
903
  });
824
904
  return;
825
905
  }
826
906
  if (typeof entryOrString === "string") {
827
907
  const entryTag = entryOrString;
828
- resolveContent(url, null, (err, result) => {
908
+ resolveContent(url, null, (err, _result) => {
829
909
  if (err) return callback(err);
910
+ const result =
911
+ /** @type {ResolveContentResult} */
912
+ (_result);
830
913
  if (!result.storeLock || entryTag === "ignore")
831
914
  return callback(null, result);
832
915
  if (frozen) {
@@ -850,8 +933,11 @@ Remove this line from the lockfile to force upgrading.`
850
933
  return;
851
934
  }
852
935
  let entry = entryOrString;
936
+ /**
937
+ * @param {Buffer=} lockedContent locked content
938
+ */
853
939
  const doFetch = lockedContent => {
854
- resolveContent(url, entry.integrity, (err, result) => {
940
+ resolveContent(url, entry.integrity, (err, _result) => {
855
941
  if (err) {
856
942
  if (lockedContent) {
857
943
  logger.warn(
@@ -865,6 +951,9 @@ Remove this line from the lockfile to force upgrading.`
865
951
  }
866
952
  return callback(err);
867
953
  }
954
+ const result =
955
+ /** @type {ResolveContentResult} */
956
+ (_result);
868
957
  if (!result.storeLock) {
869
958
  // When the lockfile entry should be no-cache
870
959
  // we need to update the lockfile
@@ -919,12 +1008,16 @@ Remove this line from the lockfile to force upgrading.`
919
1008
  const key = getCacheKey(entry.resolved);
920
1009
  const filePath = join(intermediateFs, cacheLocation, key);
921
1010
  fs.readFile(filePath, (err, result) => {
922
- const content = /** @type {Buffer} */ (result);
923
1011
  if (err) {
924
1012
  if (err.code === "ENOENT") return doFetch();
925
1013
  return callback(err);
926
1014
  }
927
- const continueWithCachedContent = result => {
1015
+ const content = /** @type {Buffer} */ (result);
1016
+ /**
1017
+ * @param {Buffer | undefined} _result result
1018
+ * @returns {void}
1019
+ */
1020
+ const continueWithCachedContent = _result => {
928
1021
  if (!upgrade) {
929
1022
  // When not in upgrade mode, we accept the result from the lockfile cache
930
1023
  return callback(null, { entry, content });
@@ -932,6 +1025,7 @@ Remove this line from the lockfile to force upgrading.`
932
1025
  return doFetch(content);
933
1026
  };
934
1027
  if (!verifyIntegrity(content, entry.integrity)) {
1028
+ /** @type {Buffer | undefined} */
935
1029
  let contentWithChangedEol;
936
1030
  let isEolChanged = false;
937
1031
  try {
@@ -942,7 +1036,7 @@ Remove this line from the lockfile to force upgrading.`
942
1036
  contentWithChangedEol,
943
1037
  entry.integrity
944
1038
  );
945
- } catch (e) {
1039
+ } catch (_err) {
946
1040
  // ignore
947
1041
  }
948
1042
  if (isEolChanged) {
@@ -969,10 +1063,14 @@ This will avoid that the end of line sequence is changed by git on Windows.`;
969
1063
  );
970
1064
  intermediateFs.writeFile(
971
1065
  filePath,
972
- contentWithChangedEol,
1066
+ /** @type {Buffer} */
1067
+ (contentWithChangedEol),
973
1068
  err => {
974
1069
  if (err) return callback(err);
975
- continueWithCachedContent(contentWithChangedEol);
1070
+ continueWithCachedContent(
1071
+ /** @type {Buffer} */
1072
+ (contentWithChangedEol)
1073
+ );
976
1074
  }
977
1075
  );
978
1076
  return;
@@ -994,15 +1092,14 @@ Lockfile corrupted (${
994
1092
  Run build with un-frozen lockfile to automatically fix lockfile.`
995
1093
  )
996
1094
  );
997
- } else {
998
- // "fix" the lockfile entry to the correct integrity
999
- // the content has priority over the integrity value
1000
- entry = {
1001
- ...entry,
1002
- integrity: computeIntegrity(content)
1003
- };
1004
- storeLockEntry(lockfile, url, entry);
1005
1095
  }
1096
+ // "fix" the lockfile entry to the correct integrity
1097
+ // the content has priority over the integrity value
1098
+ entry = {
1099
+ ...entry,
1100
+ integrity: computeIntegrity(content)
1101
+ };
1102
+ storeLockEntry(lockfile, url, entry);
1006
1103
  }
1007
1104
  continueWithCachedContent(result);
1008
1105
  });
@@ -1013,9 +1110,15 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
1013
1110
  }
1014
1111
  );
1015
1112
 
1113
+ /**
1114
+ * @param {URL} url url
1115
+ * @param {ResourceDataWithData} resourceData resource data
1116
+ * @param {function(Error | null, true | void): void} callback callback
1117
+ */
1016
1118
  const respondWithUrlModule = (url, resourceData, callback) => {
1017
- getInfo(url.href, (err, result) => {
1119
+ getInfo(url.href, (err, _result) => {
1018
1120
  if (err) return callback(err);
1121
+ const result = /** @type {Info} */ (_result);
1019
1122
  resourceData.resource = url.href;
1020
1123
  resourceData.path = url.origin + url.pathname;
1021
1124
  resourceData.query = url.search;
@@ -1051,7 +1154,7 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
1051
1154
  return callback();
1052
1155
  }
1053
1156
  respondWithUrlModule(
1054
- new URL(resourceData.resource, data.context + "/"),
1157
+ new URL(resourceData.resource, `${data.context}/`),
1055
1158
  resourceData,
1056
1159
  callback
1057
1160
  );
@@ -1059,13 +1162,15 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
1059
1162
  const hooks = NormalModule.getCompilationHooks(compilation);
1060
1163
  hooks.readResourceForScheme
1061
1164
  .for(scheme)
1062
- .tapAsync("HttpUriPlugin", (resource, module, callback) => {
1063
- return getInfo(resource, (err, result) => {
1165
+ .tapAsync("HttpUriPlugin", (resource, module, callback) =>
1166
+ getInfo(resource, (err, _result) => {
1064
1167
  if (err) return callback(err);
1065
- module.buildInfo.resourceIntegrity = result.entry.integrity;
1168
+ const result = /** @type {Info} */ (_result);
1169
+ /** @type {BuildInfo} */
1170
+ (module.buildInfo).resourceIntegrity = result.entry.integrity;
1066
1171
  callback(null, result.content);
1067
- });
1068
- });
1172
+ })
1173
+ );
1069
1174
  hooks.needBuild.tapAsync(
1070
1175
  "HttpUriPlugin",
1071
1176
  (module, context, callback) => {
@@ -1073,11 +1178,13 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
1073
1178
  module.resource &&
1074
1179
  module.resource.startsWith(`${scheme}://`)
1075
1180
  ) {
1076
- getInfo(module.resource, (err, result) => {
1181
+ getInfo(module.resource, (err, _result) => {
1077
1182
  if (err) return callback(err);
1183
+ const result = /** @type {Info} */ (_result);
1078
1184
  if (
1079
1185
  result.entry.integrity !==
1080
- module.buildInfo.resourceIntegrity
1186
+ /** @type {BuildInfo} */
1187
+ (module.buildInfo).resourceIntegrity
1081
1188
  ) {
1082
1189
  return callback(null, true);
1083
1190
  }
@@ -1103,7 +1210,9 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
1103
1210
  );
1104
1211
 
1105
1212
  const writeDone = () => {
1106
- const nextOperation = inProgressWrite.shift();
1213
+ const nextOperation =
1214
+ /** @type {InProgressWriteItem[]} */
1215
+ (inProgressWrite).shift();
1107
1216
  if (nextOperation) {
1108
1217
  nextOperation();
1109
1218
  } else {
@@ -1119,19 +1228,25 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
1119
1228
  const lockfile = buffer
1120
1229
  ? Lockfile.parse(buffer.toString("utf-8"))
1121
1230
  : new Lockfile();
1122
- for (const [key, value] of lockfileUpdates) {
1231
+ for (const [key, value] of /** @type {LockfileUpdates} */ (
1232
+ lockfileUpdates
1233
+ )) {
1123
1234
  lockfile.entries.set(key, value);
1124
1235
  }
1125
1236
  intermediateFs.writeFile(tempFile, lockfile.toString(), err => {
1126
1237
  if (err) {
1127
1238
  writeDone();
1128
- return intermediateFs.unlink(tempFile, () => callback(err));
1239
+ return (
1240
+ /** @type {NonNullable<IntermediateFileSystem["unlink"]>} */
1241
+ (intermediateFs.unlink)(tempFile, () => callback(err))
1242
+ );
1129
1243
  }
1130
1244
  intermediateFs.rename(tempFile, lockfileLocation, err => {
1131
1245
  if (err) {
1132
1246
  writeDone();
1133
- return intermediateFs.unlink(tempFile, () =>
1134
- callback(err)
1247
+ return (
1248
+ /** @type {NonNullable<IntermediateFileSystem["unlink"]>} */
1249
+ (intermediateFs.unlink)(tempFile, () => callback(err))
1135
1250
  );
1136
1251
  }
1137
1252
  writeDone();