webpack 5.101.3 → 5.102.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 (322) hide show
  1. package/README.md +21 -26
  2. package/lib/APIPlugin.js +30 -36
  3. package/lib/AsyncDependenciesBlock.js +1 -4
  4. package/lib/BannerPlugin.js +0 -1
  5. package/lib/Cache.js +7 -6
  6. package/lib/CacheFacade.js +0 -1
  7. package/lib/Chunk.js +49 -31
  8. package/lib/ChunkGraph.js +35 -25
  9. package/lib/ChunkGroup.js +8 -10
  10. package/lib/ChunkTemplate.js +1 -1
  11. package/lib/CleanPlugin.js +3 -3
  12. package/lib/CodeGenerationResults.js +2 -1
  13. package/lib/CompatibilityPlugin.js +29 -12
  14. package/lib/Compilation.js +204 -185
  15. package/lib/Compiler.js +36 -35
  16. package/lib/ConcatenationScope.js +6 -1
  17. package/lib/ConditionalInitFragment.js +1 -1
  18. package/lib/ConstPlugin.js +6 -5
  19. package/lib/ContextExclusionPlugin.js +0 -1
  20. package/lib/ContextModule.js +22 -20
  21. package/lib/ContextModuleFactory.js +30 -11
  22. package/lib/ContextReplacementPlugin.js +38 -15
  23. package/lib/DefinePlugin.js +4 -8
  24. package/lib/DelegatedModule.js +7 -11
  25. package/lib/DependenciesBlock.js +0 -2
  26. package/lib/Dependency.js +9 -11
  27. package/lib/DependencyTemplates.js +1 -3
  28. package/lib/DllModule.js +1 -7
  29. package/lib/DllReferencePlugin.js +2 -4
  30. package/lib/DynamicEntryPlugin.js +0 -2
  31. package/lib/EntryOptionPlugin.js +0 -5
  32. package/lib/EnvironmentNotSupportAsyncWarning.js +0 -3
  33. package/lib/EvalDevToolModulePlugin.js +4 -3
  34. package/lib/EvalSourceMapDevToolPlugin.js +3 -4
  35. package/lib/ExportsInfo.js +50 -49
  36. package/lib/ExternalModule.js +84 -52
  37. package/lib/ExternalModuleFactoryPlugin.js +27 -7
  38. package/lib/ExternalsPlugin.js +24 -17
  39. package/lib/FileSystemInfo.js +96 -78
  40. package/lib/FlagDependencyUsagePlugin.js +3 -4
  41. package/lib/Generator.js +2 -13
  42. package/lib/GraphHelpers.js +0 -3
  43. package/lib/HookWebpackError.js +0 -2
  44. package/lib/HotModuleReplacementPlugin.js +22 -24
  45. package/lib/HotUpdateChunk.js +0 -3
  46. package/lib/IgnorePlugin.js +5 -2
  47. package/lib/InitFragment.js +41 -29
  48. package/lib/InvalidDependenciesModuleWarning.js +0 -1
  49. package/lib/LibManifestPlugin.js +4 -6
  50. package/lib/LoaderOptionsPlugin.js +1 -10
  51. package/lib/MainTemplate.js +8 -19
  52. package/lib/Module.js +32 -20
  53. package/lib/ModuleFactory.js +1 -1
  54. package/lib/ModuleFilenameHelpers.js +41 -24
  55. package/lib/ModuleGraph.js +30 -16
  56. package/lib/ModuleInfoHeaderPlugin.js +0 -1
  57. package/lib/ModuleTemplate.js +0 -2
  58. package/lib/ModuleTypeConstants.js +11 -1
  59. package/lib/MultiCompiler.js +23 -15
  60. package/lib/MultiWatching.js +6 -10
  61. package/lib/NodeStuffPlugin.js +2 -10
  62. package/lib/NormalModule.js +145 -88
  63. package/lib/NormalModuleFactory.js +59 -40
  64. package/lib/OptionsApply.js +1 -1
  65. package/lib/Parser.js +1 -1
  66. package/lib/ProgressPlugin.js +6 -10
  67. package/lib/ProvidePlugin.js +5 -7
  68. package/lib/RawModule.js +1 -6
  69. package/lib/RecordIdsPlugin.js +10 -6
  70. package/lib/ResolverFactory.js +0 -2
  71. package/lib/RuntimeGlobals.js +5 -0
  72. package/lib/RuntimeModule.js +1 -3
  73. package/lib/RuntimePlugin.js +26 -22
  74. package/lib/RuntimeTemplate.js +12 -11
  75. package/lib/SourceMapDevToolModuleOptionsPlugin.js +2 -2
  76. package/lib/SourceMapDevToolPlugin.js +6 -11
  77. package/lib/Stats.js +0 -1
  78. package/lib/Template.js +6 -11
  79. package/lib/TemplatedPathPlugin.js +2 -1
  80. package/lib/WatchIgnorePlugin.js +2 -3
  81. package/lib/Watching.js +15 -15
  82. package/lib/WebpackIsIncludedPlugin.js +0 -2
  83. package/lib/WebpackOptionsApply.js +74 -107
  84. package/lib/asset/AssetBytesGenerator.js +166 -0
  85. package/lib/asset/AssetBytesParser.js +37 -0
  86. package/lib/asset/AssetGenerator.js +20 -34
  87. package/lib/asset/AssetModulesPlugin.js +34 -16
  88. package/lib/asset/AssetParser.js +7 -3
  89. package/lib/asset/AssetSourceGenerator.js +1 -1
  90. package/lib/asset/RawDataUrlModule.js +3 -2
  91. package/lib/async-modules/AsyncModuleHelpers.js +6 -4
  92. package/lib/buildChunkGraph.js +0 -1
  93. package/lib/cache/MemoryCachePlugin.js +0 -2
  94. package/lib/cache/MemoryWithGcCachePlugin.js +0 -2
  95. package/lib/cache/PackFileCacheStrategy.js +14 -1
  96. package/lib/cache/ResolverCachePlugin.js +9 -15
  97. package/lib/config/defaults.js +155 -21
  98. package/lib/config/normalization.js +18 -3
  99. package/lib/container/ContainerEntryDependency.js +0 -1
  100. package/lib/container/ContainerEntryModule.js +3 -7
  101. package/lib/container/ContainerPlugin.js +1 -2
  102. package/lib/container/ContainerReferencePlugin.js +0 -1
  103. package/lib/container/FallbackDependency.js +2 -1
  104. package/lib/container/FallbackModule.js +6 -7
  105. package/lib/container/ModuleFederationPlugin.js +0 -1
  106. package/lib/container/RemoteModule.js +8 -8
  107. package/lib/container/RemoteRuntimeModule.js +2 -2
  108. package/lib/css/CssGenerator.js +3 -6
  109. package/lib/css/CssLoadingRuntimeModule.js +6 -9
  110. package/lib/css/CssModulesPlugin.js +11 -13
  111. package/lib/css/CssParser.js +3 -3
  112. package/lib/css/walkCssTokens.js +1 -1
  113. package/lib/debug/ProfilingPlugin.js +35 -8
  114. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +12 -17
  115. package/lib/dependencies/AMDPlugin.js +2 -2
  116. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -2
  117. package/lib/dependencies/CachedConstDependency.js +0 -4
  118. package/lib/dependencies/CommonJsExportRequireDependency.js +20 -14
  119. package/lib/dependencies/CommonJsExportsDependency.js +2 -1
  120. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -5
  121. package/lib/dependencies/CommonJsFullRequireDependency.js +6 -4
  122. package/lib/dependencies/CommonJsImportsParserPlugin.js +16 -7
  123. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  124. package/lib/dependencies/CommonJsSelfReferenceDependency.js +4 -4
  125. package/lib/dependencies/ConstDependency.js +2 -2
  126. package/lib/dependencies/ContextDependency.js +9 -4
  127. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  128. package/lib/dependencies/ContextDependencyTemplateAsId.js +9 -9
  129. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +9 -9
  130. package/lib/dependencies/ContextElementDependency.js +22 -11
  131. package/lib/dependencies/CssIcssImportDependency.js +0 -2
  132. package/lib/dependencies/CssIcssSymbolDependency.js +2 -2
  133. package/lib/dependencies/CssImportDependency.js +0 -8
  134. package/lib/dependencies/CssLocalIdentifierDependency.js +3 -4
  135. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -2
  136. package/lib/dependencies/CssUrlDependency.js +0 -6
  137. package/lib/dependencies/ExportsInfoDependency.js +7 -9
  138. package/lib/dependencies/ExternalModuleDependency.js +0 -3
  139. package/lib/dependencies/ExternalModuleInitFragment.js +1 -1
  140. package/lib/dependencies/HarmonyAcceptDependency.js +1 -1
  141. package/lib/dependencies/HarmonyAcceptImportDependency.js +0 -4
  142. package/lib/dependencies/HarmonyCompatibilityDependency.js +0 -1
  143. package/lib/dependencies/HarmonyDetectionParserPlugin.js +0 -14
  144. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -3
  145. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -1
  146. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +29 -35
  147. package/lib/dependencies/HarmonyImportDependency.js +30 -14
  148. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +20 -23
  149. package/lib/dependencies/HarmonyImportSideEffectDependency.js +0 -4
  150. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -31
  151. package/lib/dependencies/HarmonyModulesPlugin.js +3 -3
  152. package/lib/dependencies/ImportDependency.js +18 -6
  153. package/lib/dependencies/ImportEagerDependency.js +2 -3
  154. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -5
  155. package/lib/dependencies/ImportMetaContextPlugin.js +0 -1
  156. package/lib/dependencies/ImportMetaPlugin.js +2 -1
  157. package/lib/dependencies/ImportParserPlugin.js +288 -45
  158. package/lib/dependencies/ImportWeakDependency.js +2 -3
  159. package/lib/dependencies/JsonExportsDependency.js +0 -1
  160. package/lib/dependencies/LoaderDependency.js +0 -3
  161. package/lib/dependencies/LoaderImportDependency.js +0 -3
  162. package/lib/dependencies/LoaderPlugin.js +11 -5
  163. package/lib/dependencies/ModuleDecoratorDependency.js +2 -4
  164. package/lib/dependencies/ModuleDependency.js +3 -9
  165. package/lib/dependencies/NullDependency.js +2 -0
  166. package/lib/dependencies/ProvidedDependency.js +6 -8
  167. package/lib/dependencies/PureExpressionDependency.js +0 -1
  168. package/lib/dependencies/RequireEnsureDependenciesBlock.js +0 -1
  169. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -2
  170. package/lib/dependencies/RequireIncludeDependency.js +2 -2
  171. package/lib/dependencies/RequireResolveDependency.js +2 -2
  172. package/lib/dependencies/RuntimeRequirementsDependency.js +2 -3
  173. package/lib/dependencies/StaticExportsDependency.js +3 -5
  174. package/lib/dependencies/URLDependency.js +2 -7
  175. package/lib/dependencies/URLPlugin.js +1 -2
  176. package/lib/dependencies/WebAssemblyExportImportedDependency.js +2 -2
  177. package/lib/dependencies/WebAssemblyImportDependency.js +2 -2
  178. package/lib/dependencies/WebpackIsIncludedDependency.js +2 -3
  179. package/lib/dependencies/WorkerDependency.js +2 -3
  180. package/lib/dependencies/WorkerPlugin.js +3 -9
  181. package/lib/dependencies/processExportInfo.js +2 -3
  182. package/lib/esm/ModuleChunkFormatPlugin.js +0 -3
  183. package/lib/esm/ModuleChunkLoadingPlugin.js +2 -1
  184. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -7
  185. package/lib/hmr/LazyCompilationPlugin.js +6 -4
  186. package/lib/hmr/lazyCompilationBackend.js +13 -10
  187. package/lib/ids/DeterministicChunkIdsPlugin.js +0 -1
  188. package/lib/ids/NamedChunkIdsPlugin.js +1 -6
  189. package/lib/ids/NamedModuleIdsPlugin.js +1 -5
  190. package/lib/ids/NaturalChunkIdsPlugin.js +0 -1
  191. package/lib/ids/NaturalModuleIdsPlugin.js +0 -1
  192. package/lib/ids/OccurrenceChunkIdsPlugin.js +0 -1
  193. package/lib/ids/OccurrenceModuleIdsPlugin.js +0 -1
  194. package/lib/ids/SyncModuleIdsPlugin.js +4 -3
  195. package/lib/index.js +8 -7
  196. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -1
  197. package/lib/javascript/BasicEvaluatedExpression.js +13 -6
  198. package/lib/javascript/ChunkFormatHelpers.js +1 -1
  199. package/lib/javascript/CommonJsChunkFormatPlugin.js +0 -1
  200. package/lib/javascript/JavascriptGenerator.js +2 -3
  201. package/lib/javascript/JavascriptModulesPlugin.js +44 -21
  202. package/lib/javascript/JavascriptParser.js +119 -54
  203. package/lib/javascript/JavascriptParserHelpers.js +2 -2
  204. package/lib/javascript/StartupHelpers.js +2 -4
  205. package/lib/json/JsonData.js +1 -1
  206. package/lib/json/JsonGenerator.js +4 -5
  207. package/lib/json/JsonModulesPlugin.js +0 -3
  208. package/lib/json/JsonParser.js +4 -2
  209. package/lib/library/AbstractLibraryPlugin.js +2 -2
  210. package/lib/library/AmdLibraryPlugin.js +0 -1
  211. package/lib/library/AssignLibraryPlugin.js +23 -12
  212. package/lib/library/EnableLibraryPlugin.js +7 -11
  213. package/lib/library/ExportPropertyLibraryPlugin.js +8 -20
  214. package/lib/library/JsonpLibraryPlugin.js +5 -2
  215. package/lib/library/ModuleLibraryPlugin.js +88 -43
  216. package/lib/library/SystemLibraryPlugin.js +0 -1
  217. package/lib/library/UmdLibraryPlugin.js +12 -18
  218. package/lib/logging/Logger.js +12 -10
  219. package/lib/logging/createConsoleLogger.js +15 -14
  220. package/lib/logging/truncateArgs.js +1 -1
  221. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  222. package/lib/node/NodeWatchFileSystem.js +4 -4
  223. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
  224. package/lib/node/RequireChunkLoadingRuntimeModule.js +5 -2
  225. package/lib/node/nodeConsole.js +2 -2
  226. package/lib/optimize/AggressiveSplittingPlugin.js +2 -0
  227. package/lib/optimize/ConcatenatedModule.js +142 -100
  228. package/lib/optimize/InnerGraph.js +17 -11
  229. package/lib/optimize/InnerGraphPlugin.js +0 -3
  230. package/lib/optimize/ModuleConcatenationPlugin.js +3 -4
  231. package/lib/optimize/RuntimeChunkPlugin.js +0 -1
  232. package/lib/optimize/SideEffectsFlagPlugin.js +3 -10
  233. package/lib/optimize/SplitChunksPlugin.js +46 -40
  234. package/lib/performance/SizeLimitsPlugin.js +2 -1
  235. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +5 -7
  236. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +0 -2
  237. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +0 -1
  238. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
  239. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
  240. package/lib/rules/BasicMatcherRulePlugin.js +0 -2
  241. package/lib/rules/ObjectMatcherRulePlugin.js +0 -1
  242. package/lib/rules/RuleSetCompiler.js +8 -6
  243. package/lib/runtime/BaseUriRuntimeModule.js +2 -2
  244. package/lib/runtime/CompatRuntimeModule.js +0 -1
  245. package/lib/runtime/GetChunkFilenameRuntimeModule.js +8 -9
  246. package/lib/runtime/LoadScriptRuntimeModule.js +0 -2
  247. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
  248. package/lib/runtime/PublicPathRuntimeModule.js +2 -2
  249. package/lib/runtime/StartupEntrypointRuntimeModule.js +0 -1
  250. package/lib/runtime/SystemContextRuntimeModule.js +0 -2
  251. package/lib/runtime/ToBinaryRuntimeModule.js +64 -0
  252. package/lib/schemes/DataUriPlugin.js +2 -28
  253. package/lib/schemes/FileUriPlugin.js +5 -2
  254. package/lib/schemes/HttpUriPlugin.js +4 -2
  255. package/lib/schemes/VirtualUrlPlugin.js +11 -11
  256. package/lib/serialization/NullPrototypeObjectSerializer.js +5 -3
  257. package/lib/serialization/ObjectMiddleware.js +30 -19
  258. package/lib/serialization/SerializerMiddleware.js +1 -3
  259. package/lib/serialization/types.js +1 -1
  260. package/lib/sharing/ConsumeSharedModule.js +3 -5
  261. package/lib/sharing/ConsumeSharedPlugin.js +2 -4
  262. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -6
  263. package/lib/sharing/ProvideSharedModule.js +3 -7
  264. package/lib/sharing/SharePlugin.js +0 -2
  265. package/lib/sharing/ShareRuntimeModule.js +4 -1
  266. package/lib/sharing/resolveMatchedConfigs.js +14 -6
  267. package/lib/sharing/utils.js +0 -6
  268. package/lib/stats/DefaultStatsFactoryPlugin.js +178 -94
  269. package/lib/stats/DefaultStatsPresetPlugin.js +15 -9
  270. package/lib/stats/DefaultStatsPrinterPlugin.js +77 -113
  271. package/lib/stats/StatsFactory.js +14 -11
  272. package/lib/url/URLParserPlugin.js +2 -4
  273. package/lib/util/ArrayHelpers.js +4 -4
  274. package/lib/util/AsyncQueue.js +1 -0
  275. package/lib/util/LazySet.js +2 -2
  276. package/lib/util/StackedCacheMap.js +0 -2
  277. package/lib/util/TupleSet.js +9 -4
  278. package/lib/util/URLAbsoluteSpecifier.js +0 -1
  279. package/lib/util/WeakTupleMap.js +1 -1
  280. package/lib/util/chainedImports.js +3 -1
  281. package/lib/util/cleverMerge.js +15 -18
  282. package/lib/util/comparators.js +2 -4
  283. package/lib/util/compileBooleanMatcher.js +11 -9
  284. package/lib/util/concatenate.js +1 -2
  285. package/lib/util/create-schema-validation.js +0 -1
  286. package/lib/util/dataURL.js +39 -0
  287. package/lib/util/deprecation.js +29 -31
  288. package/lib/util/deterministicGrouping.js +34 -30
  289. package/lib/util/extractSourceMap.js +319 -0
  290. package/lib/util/findGraphRoots.js +15 -5
  291. package/lib/util/fs.js +29 -8
  292. package/lib/util/semver.js +9 -8
  293. package/lib/util/smartGrouping.js +41 -26
  294. package/lib/util/traverseDestructuringAssignmentProperties.js +45 -0
  295. package/lib/wasm/EnableWasmLoadingPlugin.js +3 -2
  296. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
  297. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +2 -13
  298. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +2 -9
  299. package/lib/wasm-async/AsyncWebAssemblyParser.js +2 -1
  300. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -4
  301. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -3
  302. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -4
  303. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -7
  304. package/lib/wasm-sync/WebAssemblyParser.js +1 -4
  305. package/lib/web/JsonpChunkLoadingPlugin.js +2 -1
  306. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  307. package/lib/web/JsonpTemplatePlugin.js +0 -1
  308. package/lib/webpack.js +21 -8
  309. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -1
  310. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  311. package/package.json +12 -12
  312. package/schemas/WebpackOptions.check.js +1 -1
  313. package/schemas/WebpackOptions.json +77 -93
  314. package/schemas/plugins/BannerPlugin.check.js +1 -1
  315. package/schemas/plugins/BannerPlugin.json +4 -0
  316. package/schemas/plugins/IgnorePlugin.json +1 -1
  317. package/schemas/plugins/ProgressPlugin.json +1 -1
  318. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  319. package/schemas/plugins/SourceMapDevToolPlugin.json +5 -1
  320. package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
  321. package/types.d.ts +1129 -530
  322. package/SECURITY.md +0 -9
@@ -8,7 +8,6 @@ const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
 
10
10
  /** @typedef {import("../Compilation")} Compilation */
11
- /** @typedef {import("../MainTemplate")} MainTemplate */
12
11
 
13
12
  class StartupEntrypointRuntimeModule extends RuntimeModule {
14
13
  /**
@@ -7,8 +7,6 @@
7
7
  const RuntimeGlobals = require("../RuntimeGlobals");
8
8
  const RuntimeModule = require("../RuntimeModule");
9
9
 
10
- /** @typedef {import("../Compilation")} Compilation */
11
-
12
10
  class SystemContextRuntimeModule extends RuntimeModule {
13
11
  constructor() {
14
12
  super("__system_context__");
@@ -0,0 +1,64 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const RuntimeGlobals = require("../RuntimeGlobals");
9
+ const RuntimeModule = require("../RuntimeModule");
10
+ const Template = require("../Template");
11
+
12
+ /** @typedef {import("../Compilation")} Compilation */
13
+
14
+ class ToBinaryRuntimeModule extends RuntimeModule {
15
+ constructor() {
16
+ super("to binary");
17
+ }
18
+
19
+ /**
20
+ * @returns {string | null} runtime code
21
+ */
22
+ generate() {
23
+ const compilation = /** @type {Compilation} */ (this.compilation);
24
+ const fn = RuntimeGlobals.toBinary;
25
+ const { runtimeTemplate } = compilation;
26
+
27
+ // Inspired by esbuild
28
+
29
+ const isNodePlatform = compilation.compiler.platform.node;
30
+ const isWebPlatform = compilation.compiler.platform.web;
31
+ const isNeutralPlatform = runtimeTemplate.isNeutralPlatform();
32
+
33
+ return Template.asString([
34
+ "// define to binary helper",
35
+ `${fn} = ${isNeutralPlatform ? "typeof Buffer !== 'undefined' ? " : ""}${
36
+ isNodePlatform || isNeutralPlatform
37
+ ? `${runtimeTemplate.returningFunction("new Uint8Array(Buffer.from(base64, 'base64'))", "base64")}`
38
+ : ""
39
+ } ${isNeutralPlatform ? ": " : ""}${
40
+ isWebPlatform || isNeutralPlatform
41
+ ? `(${runtimeTemplate.basicFunction("", [
42
+ "var table = new Uint8Array(128);",
43
+ "for (var i = 0; i < 64; i++) table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;",
44
+ `return ${runtimeTemplate.basicFunction("base64", [
45
+ "var n = base64.length, bytes = new Uint8Array((n - (base64[n - 1] == '=') - (base64[n - 2] == '=')) * 3 / 4 | 0);",
46
+ "for (var i = 0, j = 0; i < n;) {",
47
+ Template.indent([
48
+ "var c0 = table[base64.charCodeAt(i++)], c1 = table[base64.charCodeAt(i++)];",
49
+ "var c2 = table[base64.charCodeAt(i++)], c3 = table[base64.charCodeAt(i++)];",
50
+ "bytes[j++] = (c0 << 2) | (c1 >> 4);",
51
+ "bytes[j++] = (c1 << 4) | (c2 >> 2);",
52
+ "bytes[j++] = (c2 << 6) | c3;"
53
+ ]),
54
+ "}",
55
+ "return bytes"
56
+ ])}`
57
+ ])})();`
58
+ : ""
59
+ }`
60
+ ]);
61
+ }
62
+ }
63
+
64
+ module.exports = ToBinaryRuntimeModule;
@@ -6,37 +6,10 @@
6
6
  "use strict";
7
7
 
8
8
  const NormalModule = require("../NormalModule");
9
+ const { URIRegEx, decodeDataURI } = require("../util/dataURL");
9
10
 
10
11
  /** @typedef {import("../Compiler")} Compiler */
11
12
 
12
- // data URL scheme: "data:text/javascript;charset=utf-8;base64,some-string"
13
- // http://www.ietf.org/rfc/rfc2397.txt
14
- const URIRegEx = /^data:([^;,]+)?((?:;[^;,]+)*?)(?:;(base64)?)?,(.*)$/i;
15
-
16
- /**
17
- * @param {string} uri data URI
18
- * @returns {Buffer | null} decoded data
19
- */
20
- const decodeDataURI = (uri) => {
21
- const match = URIRegEx.exec(uri);
22
- if (!match) return null;
23
-
24
- const isBase64 = match[3];
25
- const body = match[4];
26
-
27
- if (isBase64) {
28
- return Buffer.from(body, "base64");
29
- }
30
-
31
- // CSS allows to use `data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg"><rect width="100%" height="100%" style="stroke: rgb(223,224,225); stroke-width: 2px; fill: none; stroke-dasharray: 6px 3px" /></svg>`
32
- // so we return original body if we can't `decodeURIComponent`
33
- try {
34
- return Buffer.from(decodeURIComponent(body), "ascii");
35
- } catch (_) {
36
- return Buffer.from(body, "ascii");
37
- }
38
- };
39
-
40
13
  const PLUGIN_NAME = "DataUriPlugin";
41
14
 
42
15
  class DataUriPlugin {
@@ -62,6 +35,7 @@ class DataUriPlugin {
62
35
  resourceData.data.encodedContent = match[4] || "";
63
36
  }
64
37
  });
38
+
65
39
  NormalModule.getCompilationHooks(compilation)
66
40
  .readResourceForScheme.for("data")
67
41
  .tap(PLUGIN_NAME, (resource) => decodeDataURI(resource));
@@ -40,8 +40,11 @@ class FileUriPlugin {
40
40
  .for(undefined)
41
41
  .tapAsync(PLUGIN_NAME, (loaderContext, callback) => {
42
42
  const { resourcePath } = loaderContext;
43
- loaderContext.addDependency(resourcePath);
44
- loaderContext.fs.readFile(resourcePath, callback);
43
+ loaderContext.fs.readFile(resourcePath, (err, result) => {
44
+ if (err) return callback(err);
45
+ loaderContext.addDependency(resourcePath);
46
+ callback(null, result);
47
+ });
45
48
  });
46
49
  }
47
50
  );
@@ -1199,8 +1199,10 @@ Run build with un-frozen lockfile to automatically fix lockfile.`
1199
1199
  getInfo(resource, (err, _result) => {
1200
1200
  if (err) return callback(err);
1201
1201
  const result = /** @type {Info} */ (_result);
1202
- /** @type {BuildInfo} */
1203
- (module.buildInfo).resourceIntegrity = result.entry.integrity;
1202
+ if (module) {
1203
+ /** @type {BuildInfo} */
1204
+ (module.buildInfo).resourceIntegrity = result.entry.integrity;
1205
+ }
1204
1206
  callback(null, result.content);
1205
1207
  })
1206
1208
  );
@@ -11,9 +11,6 @@ const { parseResourceWithoutFragment } = require("../util/identifier");
11
11
 
12
12
  /** @typedef {import("../Compiler")} Compiler */
13
13
  /** @typedef {import("../NormalModule")} NormalModule */
14
- /** @typedef {import("../Module").BuildInfo} BuildInfo */
15
- /** @typedef {import("../Module").ValueCacheVersions} ValueCacheVersions */
16
- /** @typedef {string | Set<string>} ValueCacheVersion */
17
14
 
18
15
  /**
19
16
  * @template T
@@ -23,18 +20,21 @@ const { parseResourceWithoutFragment } = require("../util/identifier");
23
20
  const PLUGIN_NAME = "VirtualUrlPlugin";
24
21
  const DEFAULT_SCHEME = "virtual";
25
22
 
23
+ /** @typedef {(loaderContext: LoaderContext<EXPECTED_ANY>) => Promise<string | Buffer> | string | Buffer} SourceFn */
24
+ /** @typedef {() => string} VersionFn */
25
+
26
26
  /**
27
27
  * @typedef {object} VirtualModuleConfig
28
- * @property {string=} type - The module type
29
- * @property {(loaderContext: LoaderContext<EXPECTED_ANY>) => Promise<string> | string} source - The source function
30
- * @property {(() => string) | true | string=} version - Optional version function or value
28
+ * @property {string=} type the module type
29
+ * @property {SourceFn} source the source function
30
+ * @property {VersionFn | true | string=} version optional version function or value
31
31
  */
32
32
 
33
33
  /**
34
- * @typedef {string | ((loaderContext: LoaderContext<EXPECTED_ANY>) => Promise<string> | string) | VirtualModuleConfig} VirtualModuleInput
34
+ * @typedef {string | SourceFn | VirtualModuleConfig} VirtualModuleInput
35
35
  */
36
36
 
37
- /** @typedef {{[key: string]: VirtualModuleInput}} VirtualModules */
37
+ /** @typedef {{ [key: string]: VirtualModuleInput }} VirtualModules */
38
38
 
39
39
  /**
40
40
  * Normalizes a virtual module definition into a standard format
@@ -62,13 +62,13 @@ function normalizeModule(virtualConfig) {
62
62
  * Normalizes all virtual modules with the given scheme
63
63
  * @param {VirtualModules} virtualConfigs The virtual modules to normalize
64
64
  * @param {string} scheme The URL scheme to use
65
- * @returns {{[key: string]: VirtualModuleConfig}} The normalized virtual modules
65
+ * @returns {{ [key: string]: VirtualModuleConfig }} The normalized virtual modules
66
66
  */
67
67
  function normalizeModules(virtualConfigs, scheme) {
68
68
  return Object.keys(virtualConfigs).reduce((pre, id) => {
69
69
  pre[toVid(id, scheme)] = normalizeModule(virtualConfigs[id]);
70
70
  return pre;
71
- }, /** @type {{[key: string]: VirtualModuleConfig}} */ ({}));
71
+ }, /** @type {{ [key: string]: VirtualModuleConfig }} */ ({}));
72
72
  }
73
73
 
74
74
  /**
@@ -207,7 +207,7 @@ class VirtualUrlPlugin {
207
207
 
208
208
  /**
209
209
  * Get the cache version for a given version value
210
- * @param {(() => string) | true | string} version The version value or function
210
+ * @param {VersionFn | true | string} version The version value or function
211
211
  * @returns {string | undefined} The cache version
212
212
  */
213
213
  getCacheVersion(version) {
@@ -7,6 +7,8 @@
7
7
  /** @typedef {import("./ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
8
8
  /** @typedef {import("./ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
9
9
 
10
+ /** @typedef {string[]} Keys */
11
+
10
12
  class NullPrototypeObjectSerializer {
11
13
  /**
12
14
  * @template {object} T
@@ -14,7 +16,7 @@ class NullPrototypeObjectSerializer {
14
16
  * @param {ObjectSerializerContext} context context
15
17
  */
16
18
  serialize(obj, context) {
17
- /** @type {string[]} */
19
+ /** @type {Keys} */
18
20
  const keys = Object.keys(obj);
19
21
  for (const key of keys) {
20
22
  context.write(key);
@@ -33,9 +35,9 @@ class NullPrototypeObjectSerializer {
33
35
  deserialize(context) {
34
36
  /** @type {T} */
35
37
  const obj = Object.create(null);
36
- /** @type {string[]} */
38
+ /** @type {Keys} */
37
39
  const keys = [];
38
- /** @type {string | null} */
40
+ /** @type {Keys[number] | null} */
39
41
  let key = context.read();
40
42
  while (key !== null) {
41
43
  keys.push(key);
@@ -56,29 +56,29 @@ Technically any value can be used.
56
56
  * @property {number} objectTypeLookupSize
57
57
  * @property {number} currentPosTypeLookup
58
58
  */
59
- /** @typedef {TODO} Value */
59
+
60
60
  /** @typedef {EXPECTED_OBJECT | string} ReferenceableItem */
61
61
 
62
62
  /**
63
63
  * @typedef {object} ObjectSerializerContext
64
- * @property {(value: Value) => void} write
64
+ * @property {(value: EXPECTED_ANY) => void} write
65
65
  * @property {(value: ReferenceableItem) => void} setCircularReference
66
66
  * @property {() => ObjectSerializerSnapshot} snapshot
67
67
  * @property {(snapshot: ObjectSerializerSnapshot) => void} rollback
68
- * @property {((item: Value | (() => Value)) => void)=} writeLazy
69
- * @property {((item: (Value | (() => Value)), obj: LazyOptions | undefined) => import("./SerializerMiddleware").LazyFunction<EXPECTED_ANY, EXPECTED_ANY, EXPECTED_ANY, LazyOptions>)=} writeSeparate
68
+ * @property {((item: EXPECTED_ANY | (() => EXPECTED_ANY)) => void)=} writeLazy
69
+ * @property {((item: (EXPECTED_ANY | (() => EXPECTED_ANY)), obj: LazyOptions | undefined) => import("./SerializerMiddleware").LazyFunction<EXPECTED_ANY, EXPECTED_ANY, EXPECTED_ANY, LazyOptions>)=} writeSeparate
70
70
  */
71
71
 
72
72
  /**
73
73
  * @typedef {object} ObjectDeserializerContext
74
- * @property {() => Value} read
74
+ * @property {() => EXPECTED_ANY} read
75
75
  * @property {(value: ReferenceableItem) => void} setCircularReference
76
76
  */
77
77
 
78
78
  /**
79
79
  * @typedef {object} ObjectSerializer
80
- * @property {(value: Value, context: ObjectSerializerContext) => void} serialize
81
- * @property {(context: ObjectDeserializerContext) => Value} deserialize
80
+ * @property {(value: EXPECTED_ANY, context: ObjectSerializerContext) => void} serialize
81
+ * @property {(context: ObjectDeserializerContext) => EXPECTED_ANY} deserialize
82
82
  */
83
83
 
84
84
  /**
@@ -130,7 +130,7 @@ const CURRENT_VERSION = 2;
130
130
  /** @typedef {{ request?: string, name?: string | number | null, serializer?: ObjectSerializer }} SerializerConfig */
131
131
  /** @typedef {{ request?: string, name?: string | number | null, serializer: ObjectSerializer }} SerializerConfigWithSerializer */
132
132
 
133
- /** @type {Map<Constructor, SerializerConfig>} */
133
+ /** @type {Map<Constructor | null, SerializerConfig>} */
134
134
  const serializers = new Map();
135
135
  /** @type {Map<string | number, ObjectSerializer>} */
136
136
  const serializerInversed = new Map();
@@ -140,6 +140,7 @@ const loadedRequests = new Set();
140
140
 
141
141
  const NOT_SERIALIZABLE = {};
142
142
 
143
+ /** @type {Map<Constructor | null, ObjectSerializer>} */
143
144
  const jsTypes = new Map();
144
145
 
145
146
  jsTypes.set(Object, new PlainObjectSerializer());
@@ -335,7 +336,7 @@ class ObjectMiddleware extends SerializerMiddleware {
335
336
  * @returns {SerializedType | Promise<SerializedType> | null} serialized data
336
337
  */
337
338
  serialize(data, context) {
338
- /** @type {Value[]} */
339
+ /** @type {PrimitiveSerializableType[]} */
339
340
  let result = [CURRENT_VERSION];
340
341
  let currentPos = 0;
341
342
  /** @type {Map<ReferenceableItem, number>} */
@@ -412,7 +413,7 @@ class ObjectMiddleware extends SerializerMiddleware {
412
413
  let objectTypeLookup = new Map();
413
414
  const cycleStack = new Set();
414
415
  /**
415
- * @param {Value} item item to stack
416
+ * @param {ComplexSerializableType} item item to stack
416
417
  * @returns {string} stack
417
418
  */
418
419
  const stackToString = (item) => {
@@ -511,7 +512,7 @@ class ObjectMiddleware extends SerializerMiddleware {
511
512
  };
512
513
  this.extendContext(ctx);
513
514
  /**
514
- * @param {Value} item item to serialize
515
+ * @param {ComplexSerializableType} item item to serialize
515
516
  */
516
517
  const process = (item) => {
517
518
  if (Buffer.isBuffer(item)) {
@@ -533,7 +534,7 @@ class ObjectMiddleware extends SerializerMiddleware {
533
534
  }
534
535
  addReferenceable(item);
535
536
 
536
- result.push(item);
537
+ result.push(/** @type {Buffer} */ (item));
537
538
  } else if (item === ESCAPE) {
538
539
  result.push(ESCAPE, ESCAPE_ESCAPE_VALUE);
539
540
  } else if (
@@ -553,8 +554,10 @@ class ObjectMiddleware extends SerializerMiddleware {
553
554
  );
554
555
  }
555
556
 
556
- const { request, name, serializer } =
557
- ObjectMiddleware.getSerializerFor(item);
557
+ const { request, name, serializer } = ObjectMiddleware.getSerializerFor(
558
+ /** @type {Constructor} */
559
+ (item)
560
+ );
558
561
  const key = `${request}/${name}`;
559
562
  const lastIndex = objectTypeLookup.get(key);
560
563
 
@@ -616,9 +619,13 @@ class ObjectMiddleware extends SerializerMiddleware {
616
619
  } else if (SerializerMiddleware.isLazy(item, this)) {
617
620
  throw new Error("Not implemented");
618
621
  } else {
619
- const data = SerializerMiddleware.serializeLazy(item, (data) =>
620
- this.serialize([data], context)
621
- );
622
+ const data =
623
+ /** @type {() => PrimitiveSerializableType[] | Promise<PrimitiveSerializableType[]>} */
624
+ (
625
+ SerializerMiddleware.serializeLazy(item, (data) =>
626
+ this.serialize([data], context)
627
+ )
628
+ );
622
629
  SerializerMiddleware.setLazySerializedValue(item, data);
623
630
  result.push(data);
624
631
  }
@@ -677,7 +684,7 @@ class ObjectMiddleware extends SerializerMiddleware {
677
684
  /** @type {ReferenceableItem[]} */
678
685
  let referenceable = [];
679
686
  /**
680
- * @param {Value} item referenceable item
687
+ * @param {ReferenceableItem} item referenceable item
681
688
  */
682
689
  const addReferenceable = (item) => {
683
690
  referenceable.push(item);
@@ -686,6 +693,7 @@ class ObjectMiddleware extends SerializerMiddleware {
686
693
  let currentPosTypeLookup = 0;
687
694
  /** @type {ObjectSerializer[]} */
688
695
  let objectTypeLookup = [];
696
+ /** @type {ComplexSerializableType[]} */
689
697
  let result = [];
690
698
  /** @type {ObjectDeserializerContext} */
691
699
  let ctx = {
@@ -698,6 +706,9 @@ class ObjectMiddleware extends SerializerMiddleware {
698
706
  ...context
699
707
  };
700
708
  this.extendContext(ctx);
709
+ /**
710
+ * @returns {ComplexSerializableType} deserialize value
711
+ */
701
712
  const decodeValue = () => {
702
713
  const item = read();
703
714
 
@@ -789,7 +800,7 @@ class ObjectMiddleware extends SerializerMiddleware {
789
800
  const name = !serializerEntry
790
801
  ? "unknown"
791
802
  : !serializerEntry[1].request
792
- ? serializerEntry[0].name
803
+ ? /** @type {Constructor[]} */ (serializerEntry)[0].name
793
804
  : serializerEntry[1].name
794
805
  ? `${serializerEntry[1].request} ${serializerEntry[1].name}`
795
806
  : serializerEntry[1].request;
@@ -96,7 +96,6 @@ class SerializerMiddleware {
96
96
  * @template TLazyOutputValue
97
97
  * @template {LazyTarget} TLazyTarget
98
98
  * @template {Record<string, EXPECTED_ANY>} TLazyOptions
99
- * @template TLazySerializedValue
100
99
  * @param {LazyFunction<TLazyInputValue, TLazyOutputValue, TLazyTarget, TLazyOptions>} fn lazy function
101
100
  * @returns {LazyOptions | undefined} options
102
101
  */
@@ -123,7 +122,7 @@ class SerializerMiddleware {
123
122
  * @template TLazyOutputValue
124
123
  * @template {LazyTarget} TLazyTarget
125
124
  * @template {LazyOptions} TLazyOptions
126
- * @param {LazyFunction<TLazyInputValue, TLazyOutputValue, LazyTarget, LazyOptions>} fn lazy function
125
+ * @param {LazyFunction<TLazyInputValue, TLazyOutputValue, TLazyTarget, TLazyOptions>} fn lazy function
127
126
  * @param {TLazyOutputValue} value serialized value
128
127
  * @returns {void}
129
128
  */
@@ -168,7 +167,6 @@ class SerializerMiddleware {
168
167
  /**
169
168
  * @template TLazyInputValue SerializedValue
170
169
  * @template TLazyOutputValue DeserializedValue
171
- * @template SerializedValue
172
170
  * @template {LazyTarget} TLazyTarget
173
171
  * @template {LazyOptions | undefined} TLazyOptions
174
172
  * @param {LazyFunction<TLazyInputValue, TLazyOutputValue, TLazyTarget, TLazyOptions>} lazy lazy function
@@ -4,7 +4,7 @@
4
4
 
5
5
  "use strict";
6
6
 
7
- /** @typedef {undefined | null | number | string | boolean | Buffer | EXPECTED_OBJECT | (() => ComplexSerializableType[] | Promise<ComplexSerializableType[]>)} ComplexSerializableType */
7
+ /** @typedef {undefined | null | number | bigint | string | boolean | Buffer | EXPECTED_OBJECT | (() => ComplexSerializableType[] | Promise<ComplexSerializableType[]>)} ComplexSerializableType */
8
8
 
9
9
  /** @typedef {undefined | null | number | bigint | string | boolean | Buffer | (() => PrimitiveSerializableType[] | Promise<PrimitiveSerializableType[]>)} PrimitiveSerializableType */
10
10
 
@@ -17,21 +17,19 @@ const makeSerializable = require("../util/makeSerializable");
17
17
  const { rangeToString, stringifyHoley } = require("../util/semver");
18
18
  const ConsumeSharedFallbackDependency = require("./ConsumeSharedFallbackDependency");
19
19
 
20
- /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
21
- /** @typedef {import("../ChunkGraph")} ChunkGraph */
22
- /** @typedef {import("../ChunkGroup")} ChunkGroup */
20
+ /** @typedef {import("../config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
23
21
  /** @typedef {import("../Compilation")} Compilation */
24
22
  /** @typedef {import("../Dependency").UpdateHashContext} UpdateHashContext */
25
23
  /** @typedef {import("../Module").BuildCallback} BuildCallback */
26
24
  /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
27
25
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
28
26
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
27
+ /** @typedef {import("../Module").LibIdent} LibIdent */
29
28
  /** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
30
29
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
31
30
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
32
31
  /** @typedef {import("../RequestShortener")} RequestShortener */
33
32
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
34
- /** @typedef {import("../WebpackError")} WebpackError */
35
33
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
36
34
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
37
35
  /** @typedef {import("../util/Hash")} Hash */
@@ -104,7 +102,7 @@ class ConsumeSharedModule extends Module {
104
102
 
105
103
  /**
106
104
  * @param {LibIdentOptions} options options
107
- * @returns {string | null} an identifier for library inclusion
105
+ * @returns {LibIdent | null} an identifier for library inclusion
108
106
  */
109
107
  libIdent(options) {
110
108
  const { shareKey, shareScope, import: request } = this.options;
@@ -23,8 +23,8 @@ const {
23
23
  isRequiredVersion
24
24
  } = require("./utils");
25
25
 
26
+ /** @typedef {import("enhanced-resolve").ResolveContext} ResolveContext */
26
27
  /** @typedef {import("../../declarations/plugins/sharing/ConsumeSharedPlugin").ConsumeSharedPluginOptions} ConsumeSharedPluginOptions */
27
- /** @typedef {import("../../declarations/plugins/sharing/ConsumeSharedPlugin").ConsumesConfig} ConsumesConfig */
28
28
  /** @typedef {import("../Compiler")} Compiler */
29
29
  /** @typedef {import("../ResolverFactory").ResolveOptionsWithDependencyType} ResolveOptionsWithDependencyType */
30
30
  /** @typedef {import("../util/semver").SemVerRange} SemVerRange */
@@ -168,12 +168,10 @@ class ConsumeSharedPlugin {
168
168
  resolve();
169
169
  return;
170
170
  }
171
+ /** @typedef {ResolveContext} */
171
172
  const resolveContext = {
172
- /** @type {LazySet<string>} */
173
173
  fileDependencies: new LazySet(),
174
- /** @type {LazySet<string>} */
175
174
  contextDependencies: new LazySet(),
176
- /** @type {LazySet<string>} */
177
175
  missingDependencies: new LazySet()
178
176
  };
179
177
  resolver.resolve(
@@ -23,7 +23,7 @@ const {
23
23
  /** @typedef {import("../Compilation")} Compilation */
24
24
  /** @typedef {import("../Module")} Module */
25
25
  /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
26
- /** @typedef {import("./ConsumeSharedModule")} ConsumeSharedModule */
26
+ /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
27
27
 
28
28
  class ConsumeSharedRuntimeModule extends RuntimeModule {
29
29
  /**
@@ -40,17 +40,20 @@ class ConsumeSharedRuntimeModule extends RuntimeModule {
40
40
  generate() {
41
41
  const compilation = /** @type {Compilation} */ (this.compilation);
42
42
  const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
43
- const { runtimeTemplate, codeGenerationResults } = compilation;
44
- /** @type {Record<ChunkId, (string | number)[]>} */
43
+ const codeGenerationResults =
44
+ /** @type {CodeGenerationResults} */
45
+ (compilation.codeGenerationResults);
46
+ const { runtimeTemplate } = compilation;
47
+ /** @type {Record<ChunkId, ModuleId[]>} */
45
48
  const chunkToModuleMapping = {};
46
- /** @type {Map<string | number, Source>} */
49
+ /** @type {Map<ModuleId, Source>} */
47
50
  const moduleIdToSourceMapping = new Map();
48
- /** @type {(string | number)[]} */
51
+ /** @type {ModuleId[]} */
49
52
  const initialConsumes = [];
50
53
  /**
51
54
  * @param {Iterable<Module>} modules modules
52
55
  * @param {Chunk} chunk the chunk
53
- * @param {(string | number)[]} list list of ids
56
+ * @param {ModuleId[]} list list of ids
54
57
  */
55
58
  const addModules = (modules, chunk, list) => {
56
59
  for (const m of modules) {
@@ -13,24 +13,20 @@ const RuntimeGlobals = require("../RuntimeGlobals");
13
13
  const makeSerializable = require("../util/makeSerializable");
14
14
  const ProvideForSharedDependency = require("./ProvideForSharedDependency");
15
15
 
16
- /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
17
- /** @typedef {import("../Chunk")} Chunk */
18
- /** @typedef {import("../ChunkGraph")} ChunkGraph */
19
- /** @typedef {import("../ChunkGroup")} ChunkGroup */
16
+ /** @typedef {import("../config/defaults").WebpackOptionsNormalizedWithDefaults} WebpackOptions */
20
17
  /** @typedef {import("../Compilation")} Compilation */
21
18
  /** @typedef {import("../Module").BuildCallback} BuildCallback */
22
19
  /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
23
20
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
24
21
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
22
+ /** @typedef {import("../Module").LibIdent} LibIdent */
25
23
  /** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
26
24
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
27
25
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
28
26
  /** @typedef {import("../RequestShortener")} RequestShortener */
29
27
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
30
- /** @typedef {import("../WebpackError")} WebpackError */
31
28
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
32
29
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
33
- /** @typedef {import("../util/Hash")} Hash */
34
30
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
35
31
 
36
32
  class ProvideSharedModule extends Module {
@@ -69,7 +65,7 @@ class ProvideSharedModule extends Module {
69
65
 
70
66
  /**
71
67
  * @param {LibIdentOptions} options options
72
- * @returns {string | null} an identifier for library inclusion
68
+ * @returns {LibIdent | null} an identifier for library inclusion
73
69
  */
74
70
  libIdent(options) {
75
71
  return `${this.layer ? `(${this.layer})/` : ""}webpack/sharing/provide/${
@@ -10,9 +10,7 @@ const ConsumeSharedPlugin = require("./ConsumeSharedPlugin");
10
10
  const ProvideSharedPlugin = require("./ProvideSharedPlugin");
11
11
  const { isRequiredVersion } = require("./utils");
12
12
 
13
- /** @typedef {import("../../declarations/plugins/sharing/ConsumeSharedPlugin").ConsumeSharedPluginOptions} ConsumeSharedPluginOptions */
14
13
  /** @typedef {import("../../declarations/plugins/sharing/ConsumeSharedPlugin").ConsumesConfig} ConsumesConfig */
15
- /** @typedef {import("../../declarations/plugins/sharing/ProvideSharedPlugin").ProvideSharedPluginOptions} ProvideSharedPluginOptions */
16
14
  /** @typedef {import("../../declarations/plugins/sharing/ProvideSharedPlugin").ProvidesConfig} ProvidesConfig */
17
15
  /** @typedef {import("../../declarations/plugins/sharing/SharePlugin").SharePluginOptions} SharePluginOptions */
18
16
  /** @typedef {import("../../declarations/plugins/sharing/SharePlugin").SharedConfig} SharedConfig */
@@ -16,6 +16,7 @@ const {
16
16
  /** @typedef {import("../Chunk")} Chunk */
17
17
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
18
18
  /** @typedef {import("../Compilation")} Compilation */
19
+ /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
19
20
 
20
21
  class ShareRuntimeModule extends RuntimeModule {
21
22
  constructor() {
@@ -29,9 +30,11 @@ class ShareRuntimeModule extends RuntimeModule {
29
30
  const compilation = /** @type {Compilation} */ (this.compilation);
30
31
  const {
31
32
  runtimeTemplate,
32
- codeGenerationResults,
33
33
  outputOptions: { uniqueName, ignoreBrowserWarnings }
34
34
  } = compilation;
35
+ const codeGenerationResults =
36
+ /** @type {CodeGenerationResults} */
37
+ (compilation.codeGenerationResults);
35
38
  const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
36
39
  /** @type {Map<string, Map<number, Set<string>>>} */
37
40
  const initCodePerScope = new Map();
@@ -8,6 +8,7 @@
8
8
  const ModuleNotFoundError = require("../ModuleNotFoundError");
9
9
  const LazySet = require("../util/LazySet");
10
10
 
11
+ /** @typedef {import("enhanced-resolve").ResolveContext} ResolveContext */
11
12
  /** @typedef {import("../Compilation")} Compilation */
12
13
  /** @typedef {import("../ResolverFactory").ResolveOptionsWithDependencyType} ResolveOptionsWithDependencyType */
13
14
 
@@ -35,12 +36,10 @@ module.exports.resolveMatchedConfigs = (compilation, configs) => {
35
36
  const unresolved = new Map();
36
37
  /** @type {Map<string, T>} */
37
38
  const prefixed = new Map();
39
+ /** @type {ResolveContext} */
38
40
  const resolveContext = {
39
- /** @type {LazySet<string>} */
40
41
  fileDependencies: new LazySet(),
41
- /** @type {LazySet<string>} */
42
42
  contextDependencies: new LazySet(),
43
- /** @type {LazySet<string>} */
44
43
  missingDependencies: new LazySet()
45
44
  };
46
45
  const resolver = compilation.resolverFactory.get("normal", RESOLVE_OPTIONS);
@@ -84,9 +83,18 @@ module.exports.resolveMatchedConfigs = (compilation, configs) => {
84
83
  }
85
84
  })
86
85
  ).then(() => {
87
- compilation.contextDependencies.addAll(resolveContext.contextDependencies);
88
- compilation.fileDependencies.addAll(resolveContext.fileDependencies);
89
- compilation.missingDependencies.addAll(resolveContext.missingDependencies);
86
+ compilation.contextDependencies.addAll(
87
+ /** @type {LazySet<string>} */
88
+ (resolveContext.contextDependencies)
89
+ );
90
+ compilation.fileDependencies.addAll(
91
+ /** @type {LazySet<string>} */
92
+ (resolveContext.fileDependencies)
93
+ );
94
+ compilation.missingDependencies.addAll(
95
+ /** @type {LazySet<string>} */
96
+ (resolveContext.missingDependencies)
97
+ );
90
98
  return { resolved, unresolved, prefixed };
91
99
  });
92
100
  };