webpack 5.104.1 → 5.105.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 (279) hide show
  1. package/bin/webpack.js +6 -3
  2. package/lib/APIPlugin.js +85 -15
  3. package/lib/AbstractMethodError.js +1 -0
  4. package/lib/AsyncDependenciesBlock.js +13 -1
  5. package/lib/AsyncDependencyToInitialChunkError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -1
  7. package/lib/BannerPlugin.js +2 -0
  8. package/lib/CacheFacade.js +2 -2
  9. package/lib/CaseSensitiveModulesWarning.js +1 -0
  10. package/lib/Chunk.js +8 -4
  11. package/lib/ChunkGraph.js +30 -9
  12. package/lib/ChunkGroup.js +6 -3
  13. package/lib/ChunkRenderError.js +2 -0
  14. package/lib/CleanPlugin.js +4 -1
  15. package/lib/CodeGenerationError.js +7 -1
  16. package/lib/CodeGenerationResults.js +10 -3
  17. package/lib/CommentCompilationWarning.js +2 -1
  18. package/lib/Compilation.js +280 -236
  19. package/lib/Compiler.js +3 -2
  20. package/lib/ConcatenationScope.js +2 -1
  21. package/lib/ConcurrentCompilationError.js +3 -3
  22. package/lib/ContextModule.js +248 -111
  23. package/lib/ContextModuleFactory.js +14 -2
  24. package/lib/DefinePlugin.js +3 -1
  25. package/lib/DelegatedModule.js +6 -0
  26. package/lib/DelegatedModuleFactoryPlugin.js +2 -0
  27. package/lib/Dependency.js +6 -1
  28. package/lib/DependencyTemplates.js +3 -2
  29. package/lib/DllModule.js +2 -0
  30. package/lib/DllReferencePlugin.js +1 -0
  31. package/lib/DotenvPlugin.js +11 -5
  32. package/lib/DynamicEntryPlugin.js +1 -0
  33. package/lib/EnvironmentNotSupportAsyncWarning.js +1 -0
  34. package/lib/EvalSourceMapDevToolPlugin.js +17 -13
  35. package/lib/ExportsInfo.js +8 -4
  36. package/lib/ExternalModule.js +16 -0
  37. package/lib/FalseIIFEUmdWarning.js +1 -0
  38. package/lib/FileSystemInfo.js +49 -25
  39. package/lib/FlagDependencyExportsPlugin.js +8 -1
  40. package/lib/FlagDependencyUsagePlugin.js +9 -7
  41. package/lib/HarmonyLinkingError.js +1 -0
  42. package/lib/HookWebpackError.js +2 -0
  43. package/lib/HotModuleReplacementPlugin.js +16 -2
  44. package/lib/InitFragment.js +1 -0
  45. package/lib/InvalidDependenciesModuleWarning.js +1 -0
  46. package/lib/LibManifestPlugin.js +1 -0
  47. package/lib/ManifestPlugin.js +4 -1
  48. package/lib/Module.js +7 -4
  49. package/lib/ModuleBuildError.js +3 -1
  50. package/lib/ModuleDependencyError.js +1 -0
  51. package/lib/ModuleDependencyWarning.js +1 -0
  52. package/lib/ModuleError.js +2 -1
  53. package/lib/ModuleFilenameHelpers.js +2 -1
  54. package/lib/ModuleGraph.js +3 -0
  55. package/lib/ModuleGraphConnection.js +10 -1
  56. package/lib/ModuleHashingError.js +2 -0
  57. package/lib/ModuleInfoHeaderPlugin.js +6 -1
  58. package/lib/ModuleNotFoundError.js +1 -0
  59. package/lib/ModuleParseError.js +5 -1
  60. package/lib/ModuleProfile.js +1 -1
  61. package/lib/ModuleRestoreError.js +2 -0
  62. package/lib/ModuleSourceTypeConstants.js +1 -11
  63. package/lib/ModuleStoreError.js +2 -0
  64. package/lib/ModuleWarning.js +3 -1
  65. package/lib/MultiCompiler.js +11 -7
  66. package/lib/MultiWatching.js +2 -2
  67. package/lib/NoModeWarning.js +1 -0
  68. package/lib/NodeStuffInWebError.js +1 -0
  69. package/lib/NormalModule.js +26 -5
  70. package/lib/NormalModuleFactory.js +20 -4
  71. package/lib/OptionsApply.js +3 -1
  72. package/lib/ProgressPlugin.js +4 -0
  73. package/lib/RawModule.js +2 -0
  74. package/lib/RuntimeModule.js +10 -0
  75. package/lib/RuntimePlugin.js +7 -9
  76. package/lib/RuntimeTemplate.js +14 -7
  77. package/lib/SourceMapDevToolPlugin.js +30 -23
  78. package/lib/Template.js +10 -5
  79. package/lib/TemplatedPathPlugin.js +4 -2
  80. package/lib/UnhandledSchemeError.js +1 -0
  81. package/lib/UnsupportedFeatureWarning.js +1 -0
  82. package/lib/WarnDeprecatedOptionPlugin.js +1 -0
  83. package/lib/WatchIgnorePlugin.js +1 -1
  84. package/lib/Watching.js +5 -0
  85. package/lib/WebpackError.js +4 -0
  86. package/lib/WebpackOptionsApply.js +60 -40
  87. package/lib/asset/AssetBytesGenerator.js +1 -0
  88. package/lib/asset/AssetGenerator.js +9 -3
  89. package/lib/asset/AssetModulesPlugin.js +33 -2
  90. package/lib/asset/AssetSourceGenerator.js +1 -0
  91. package/lib/asset/RawDataUrlModule.js +4 -0
  92. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  93. package/lib/buildChunkGraph.js +31 -2
  94. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  95. package/lib/cache/PackFileCacheStrategy.js +41 -8
  96. package/lib/cache/getLazyHashedEtag.js +13 -4
  97. package/lib/cache/mergeEtags.js +3 -1
  98. package/lib/cli.js +3 -1
  99. package/lib/config/defaults.js +65 -44
  100. package/lib/config/normalization.js +96 -0
  101. package/lib/container/ContainerEntryModule.js +4 -0
  102. package/lib/container/FallbackModule.js +2 -0
  103. package/lib/container/HoistContainerReferencesPlugin.js +6 -0
  104. package/lib/container/RemoteModule.js +19 -0
  105. package/lib/css/CssGenerator.js +31 -4
  106. package/lib/css/CssModulesPlugin.js +26 -30
  107. package/lib/css/CssParser.js +12 -9
  108. package/lib/debug/ProfilingPlugin.js +1 -0
  109. package/lib/dependencies/AMDDefineDependency.js +3 -1
  110. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
  111. package/lib/dependencies/AMDPlugin.js +1 -1
  112. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
  113. package/lib/dependencies/CachedConstDependency.js +1 -0
  114. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
  115. package/lib/dependencies/CommonJsExportRequireDependency.js +1 -0
  116. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
  117. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -0
  118. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  119. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
  120. package/lib/dependencies/ConstDependency.js +1 -0
  121. package/lib/dependencies/ContextDependencyHelpers.js +11 -4
  122. package/lib/dependencies/ContextElementDependency.js +1 -0
  123. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  124. package/lib/dependencies/CssIcssExportDependency.js +5 -4
  125. package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
  126. package/lib/dependencies/CssUrlDependency.js +2 -3
  127. package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
  128. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
  129. package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
  130. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +1 -0
  131. package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
  132. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
  133. package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
  134. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  135. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +266 -5
  136. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
  137. package/lib/dependencies/ImportDependency.js +1 -0
  138. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  139. package/lib/dependencies/ImportMetaPlugin.js +53 -11
  140. package/lib/dependencies/ImportParserPlugin.js +7 -12
  141. package/lib/dependencies/LoaderPlugin.js +3 -0
  142. package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
  143. package/lib/dependencies/ModuleDependency.js +1 -0
  144. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  145. package/lib/dependencies/ProvidedDependency.js +1 -0
  146. package/lib/dependencies/RequireContextPlugin.js +1 -0
  147. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
  148. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
  149. package/lib/dependencies/WorkerDependency.js +9 -3
  150. package/lib/dependencies/WorkerPlugin.js +1 -0
  151. package/lib/dependencies/getFunctionExpression.js +3 -1
  152. package/lib/errors/BuildCycleError.js +4 -1
  153. package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
  154. package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
  155. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
  156. package/lib/hmr/LazyCompilationPlugin.js +5 -0
  157. package/lib/hmr/lazyCompilationBackend.js +3 -2
  158. package/lib/ids/ChunkModuleIdRangePlugin.js +2 -0
  159. package/lib/ids/IdHelpers.js +10 -8
  160. package/lib/ids/OccurrenceModuleIdsPlugin.js +15 -7
  161. package/lib/ids/SyncModuleIdsPlugin.js +5 -1
  162. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  163. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
  164. package/lib/javascript/JavascriptModulesPlugin.js +29 -8
  165. package/lib/javascript/JavascriptParser.js +47 -14
  166. package/lib/json/JsonParser.js +6 -0
  167. package/lib/library/AbstractLibraryPlugin.js +4 -1
  168. package/lib/library/AmdLibraryPlugin.js +2 -1
  169. package/lib/library/AssignLibraryPlugin.js +6 -2
  170. package/lib/library/EnableLibraryPlugin.js +1 -0
  171. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  172. package/lib/library/JsonpLibraryPlugin.js +1 -1
  173. package/lib/library/ModuleLibraryPlugin.js +130 -13
  174. package/lib/library/SystemLibraryPlugin.js +4 -1
  175. package/lib/library/UmdLibraryPlugin.js +4 -3
  176. package/lib/logging/createConsoleLogger.js +3 -0
  177. package/lib/logging/truncateArgs.js +1 -1
  178. package/lib/node/CommonJsChunkLoadingPlugin.js +1 -0
  179. package/lib/node/NodeTargetPlugin.js +1 -0
  180. package/lib/node/NodeWatchFileSystem.js +3 -0
  181. package/lib/node/nodeConsole.js +18 -1
  182. package/lib/optimize/AggressiveMergingPlugin.js +2 -1
  183. package/lib/optimize/AggressiveSplittingPlugin.js +10 -6
  184. package/lib/optimize/ConcatenatedModule.js +33 -19
  185. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
  186. package/lib/optimize/InnerGraph.js +5 -3
  187. package/lib/optimize/InnerGraphPlugin.js +25 -25
  188. package/lib/optimize/MangleExportsPlugin.js +14 -2
  189. package/lib/optimize/MergeDuplicateChunksPlugin.js +3 -0
  190. package/lib/optimize/MinChunkSizePlugin.js +5 -2
  191. package/lib/optimize/ModuleConcatenationPlugin.js +19 -4
  192. package/lib/optimize/RealContentHashPlugin.js +35 -27
  193. package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
  194. package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
  195. package/lib/optimize/SplitChunksPlugin.js +14 -3
  196. package/lib/performance/AssetsOverSizeLimitWarning.js +6 -2
  197. package/lib/performance/EntrypointsOverSizeLimitWarning.js +6 -2
  198. package/lib/performance/NoAsyncChunksWarning.js +1 -0
  199. package/lib/rules/BasicEffectRulePlugin.js +2 -0
  200. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  201. package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
  202. package/lib/rules/RuleSetCompiler.js +2 -0
  203. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  204. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  205. package/lib/runtime/CompatRuntimeModule.js +1 -0
  206. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  207. package/lib/runtime/GetChunkFilenameRuntimeModule.js +4 -0
  208. package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
  209. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  210. package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
  211. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +15 -32
  212. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  213. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
  214. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  215. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  216. package/lib/schemes/HttpUriPlugin.js +27 -7
  217. package/lib/schemes/VirtualUrlPlugin.js +7 -2
  218. package/lib/serialization/BinaryMiddleware.js +4 -0
  219. package/lib/serialization/FileMiddleware.js +9 -4
  220. package/lib/serialization/ObjectMiddleware.js +34 -11
  221. package/lib/serialization/PlainObjectSerializer.js +2 -0
  222. package/lib/sharing/ConsumeSharedModule.js +60 -0
  223. package/lib/sharing/ConsumeSharedPlugin.js +5 -4
  224. package/lib/sharing/ProvideSharedModule.js +4 -0
  225. package/lib/sharing/ProvideSharedPlugin.js +24 -25
  226. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  227. package/lib/sharing/utils.js +8 -6
  228. package/lib/stats/DefaultStatsFactoryPlugin.js +14 -12
  229. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
  230. package/lib/stats/StatsFactory.js +2 -2
  231. package/lib/url/URLParserPlugin.js +4 -3
  232. package/lib/util/AppendOnlyStackedSet.js +57 -0
  233. package/lib/util/Hash.js +1 -0
  234. package/lib/util/IterableHelpers.js +1 -0
  235. package/lib/util/LazyBucketSortedSet.js +1 -0
  236. package/lib/util/LazySet.js +1 -0
  237. package/lib/util/ParallelismFactorCalculator.js +1 -0
  238. package/lib/util/SortableSet.js +1 -0
  239. package/lib/util/StringXor.js +1 -0
  240. package/lib/util/binarySearchBounds.js +15 -8
  241. package/lib/util/chainedImports.js +1 -1
  242. package/lib/util/cleverMerge.js +6 -1
  243. package/lib/util/comparators.js +21 -1
  244. package/lib/util/compileBooleanMatcher.js +3 -3
  245. package/lib/util/concatenate.js +3 -2
  246. package/lib/util/conventions.js +3 -2
  247. package/lib/util/deterministicGrouping.js +13 -1
  248. package/lib/util/extractSourceMap.js +12 -13
  249. package/lib/util/fs.js +15 -19
  250. package/lib/util/hash/BatchedHash.js +3 -0
  251. package/lib/util/hash/BulkUpdateHash.js +7 -1
  252. package/lib/util/hash/hash-digest.js +1 -0
  253. package/lib/util/hash/wasm-hash.js +16 -1
  254. package/lib/util/identifier.js +7 -2
  255. package/lib/util/magicComment.js +1 -1
  256. package/lib/util/propertyName.js +1 -1
  257. package/lib/util/registerExternalSerializer.js +1 -0
  258. package/lib/util/runtime.js +15 -1
  259. package/lib/util/semver.js +1 -0
  260. package/lib/util/serialization.js +2 -2
  261. package/lib/wasm/EnableWasmLoadingPlugin.js +1 -0
  262. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
  263. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
  264. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
  265. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
  266. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
  267. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  268. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
  269. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
  270. package/lib/wasm-sync/WebAssemblyParser.js +3 -1
  271. package/lib/web/FetchCompileWasmPlugin.js +1 -0
  272. package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
  273. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  274. package/lib/webpack.js +13 -3
  275. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  276. package/package.json +20 -28
  277. package/schemas/WebpackOptions.check.js +1 -1
  278. package/schemas/WebpackOptions.json +71 -5
  279. package/types.d.ts +339 -93
@@ -22,8 +22,10 @@ const makeSerializable = require("../util/makeSerializable");
22
22
  /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
23
23
  /** @typedef {import("../Module").CodeGenerationContext} CodeGenerationContext */
24
24
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
25
+ /** @typedef {import("../Module").CodeGenerationResultData} CodeGenerationResultData */
25
26
  /** @typedef {import("../Module").NeedBuildCallback} NeedBuildCallback */
26
27
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
28
+ /** @typedef {import("../Module").Sources} Sources */
27
29
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
28
30
  /** @typedef {import("../RequestShortener")} RequestShortener */
29
31
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
@@ -114,11 +116,13 @@ class RawDataUrlModule extends Module {
114
116
  if (this.url === undefined) {
115
117
  this.url = /** @type {Buffer} */ (this.urlBuffer).toString();
116
118
  }
119
+ /** @type {Sources} */
117
120
  const sources = new Map();
118
121
  sources.set(
119
122
  JAVASCRIPT_TYPE,
120
123
  new RawSource(`module.exports = ${JSON.stringify(this.url)};`)
121
124
  );
125
+ /** @type {CodeGenerationResultData} */
122
126
  const data = new Map();
123
127
  data.set("url", {
124
128
  javascript: this.url
@@ -12,12 +12,14 @@ const Template = require("../Template");
12
12
  /** @typedef {import("webpack-sources").Source} Source */
13
13
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
14
14
 
15
+ /** @typedef {Map<string, string>} Dependencies */
16
+
15
17
  /**
16
18
  * @extends {InitFragment<GenerateContext>}
17
19
  */
18
20
  class AwaitDependenciesInitFragment extends InitFragment {
19
21
  /**
20
- * @param {Map<string, string>} dependencies maps an import var to an async module that needs to be awaited
22
+ * @param {Dependencies} dependencies maps an import var to an async module that needs to be awaited
21
23
  */
22
24
  constructor(dependencies) {
23
25
  super(
@@ -26,6 +28,7 @@ class AwaitDependenciesInitFragment extends InitFragment {
26
28
  0,
27
29
  "await-dependencies"
28
30
  );
31
+ /** @type {Dependencies} */
29
32
  this.dependencies = dependencies;
30
33
  }
31
34
 
@@ -50,6 +50,8 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
50
50
  * @property {number} postOrderIndex next post order index
51
51
  * @property {boolean} chunkLoading has a chunk loading mechanism
52
52
  * @property {boolean} asyncChunks create async chunks
53
+ * @property {Module | null} depModule the module that is the dependency of the block
54
+ * @property {boolean} circular Whether to deduplicate to avoid circular references
53
55
  */
54
56
 
55
57
  /**
@@ -165,6 +167,7 @@ const extractBlockModules = (module, moduleGraph, runtime, blockModulesMap) => {
165
167
 
166
168
  for (const modules of arrays) {
167
169
  if (modules.length === 0) continue;
170
+ /** @type {undefined | Map<Module | ModuleGraphConnection | ConnectionState, number>} */
168
171
  let indexMap;
169
172
  let length = 0;
170
173
  outer: for (let j = 0; j < modules.length; j += 3) {
@@ -360,6 +363,9 @@ const visitModules = (
360
363
  /** @type {NamedChunkGroup} */
361
364
  const namedAsyncEntrypoints = new Map();
362
365
 
366
+ /** @type {Map<Module, ChunkGroupInfo>} */
367
+ const depModuleAsyncEntrypoints = new Map();
368
+
363
369
  /** @type {Set<ChunkGroupInfo>} */
364
370
  const outdatedOrderIndexChunkGroups = new Set();
365
371
 
@@ -373,7 +379,8 @@ const visitModules = (
373
379
  /** @type {QueueItem[]} */
374
380
  let queue = [];
375
381
 
376
- /** @type {Map<ChunkGroupInfo, Set<[ChunkGroupInfo, QueueItem | null]>>} */
382
+ /** @typedef {Set<[ChunkGroupInfo, QueueItem | null]>} ConnectList */
383
+ /** @type {Map<ChunkGroupInfo, ConnectList>} */
377
384
  const queueConnect = new Map();
378
385
  /** @type {Set<ChunkGroupInfo>} */
379
386
  const chunkGroupsForCombining = new Set();
@@ -388,6 +395,8 @@ const visitModules = (
388
395
  );
389
396
  /** @type {ChunkGroupInfo} */
390
397
  const chunkGroupInfo = {
398
+ depModule: null,
399
+ circular: false,
391
400
  initialized: false,
392
401
  chunkGroup,
393
402
  runtime,
@@ -496,11 +505,16 @@ const visitModules = (
496
505
  let c;
497
506
  /** @type {Entrypoint | undefined} */
498
507
  let entrypoint;
508
+ /** @type {Module | null} */
509
+ const depModule = moduleGraph.getModule(b.dependencies[0]);
499
510
  const entryOptions = b.groupOptions && b.groupOptions.entryOptions;
500
511
  if (cgi === undefined) {
501
512
  const chunkName = (b.groupOptions && b.groupOptions.name) || b.chunkName;
502
513
  if (entryOptions) {
503
514
  cgi = namedAsyncEntrypoints.get(/** @type {string} */ (chunkName));
515
+ if (!cgi && !b.circular && depModule) {
516
+ cgi = depModuleAsyncEntrypoints.get(depModule);
517
+ }
504
518
  if (!cgi) {
505
519
  entrypoint = compilation.addAsyncEntrypoint(
506
520
  entryOptions,
@@ -511,6 +525,8 @@ const visitModules = (
511
525
  maskByChunk.set(entrypoint.chunks[0], ZERO_BIGINT);
512
526
  entrypoint.index = nextChunkGroupIndex++;
513
527
  cgi = {
528
+ depModule,
529
+ circular: b.circular,
514
530
  chunkGroup: entrypoint,
515
531
  initialized: false,
516
532
  runtime:
@@ -548,6 +564,12 @@ const visitModules = (
548
564
  (cgi)
549
565
  );
550
566
  }
567
+ if (!b.circular && depModule) {
568
+ depModuleAsyncEntrypoints.set(
569
+ depModule,
570
+ /** @type {ChunkGroupInfo} */ (cgi)
571
+ );
572
+ }
551
573
  } else {
552
574
  entrypoint = /** @type {Entrypoint} */ (cgi.chunkGroup);
553
575
  // TODO merge entryOptions
@@ -590,6 +612,8 @@ const visitModules = (
590
612
  maskByChunk.set(c.chunks[0], ZERO_BIGINT);
591
613
  c.index = nextChunkGroupIndex++;
592
614
  cgi = {
615
+ depModule,
616
+ circular: b.circular,
593
617
  initialized: false,
594
618
  chunkGroup: c,
595
619
  runtime: chunkGroupInfo.runtime,
@@ -651,6 +675,7 @@ const visitModules = (
651
675
  // 3. We enqueue the chunk group info creation/updating
652
676
  let connectList = queueConnect.get(chunkGroupInfo);
653
677
  if (connectList === undefined) {
678
+ /** @type {ConnectList} */
654
679
  connectList = new Set();
655
680
  queueConnect.set(chunkGroupInfo, connectList);
656
681
  }
@@ -665,7 +690,10 @@ const visitModules = (
665
690
  chunkGroupInfo: /** @type {ChunkGroupInfo} */ (cgi)
666
691
  }
667
692
  ]);
668
- } else if (entrypoint !== undefined) {
693
+ } else if (
694
+ entrypoint !== undefined &&
695
+ (chunkGroupInfo.circular || chunkGroupInfo.depModule !== depModule)
696
+ ) {
669
697
  chunkGroupInfo.chunkGroup.addAsyncEntrypoint(entrypoint);
670
698
  }
671
699
  };
@@ -1091,6 +1119,7 @@ const visitModules = (
1091
1119
  for (const cgi of info.children) {
1092
1120
  let connectList = queueConnect.get(info);
1093
1121
  if (connectList === undefined) {
1122
+ /** @type {ConnectList} */
1094
1123
  connectList = new Set();
1095
1124
  queueConnect.set(info, connectList);
1096
1125
  }
@@ -43,6 +43,7 @@ class MemoryWithGcCachePlugin {
43
43
  compiler.hooks.afterDone.tap(PLUGIN_NAME, () => {
44
44
  generation++;
45
45
  let clearedEntries = 0;
46
+ /** @type {undefined | string} */
46
47
  let lastClearedIdentifier;
47
48
  // Avoid coverage problems due indirect changes
48
49
  /* istanbul ignore next */
@@ -28,7 +28,7 @@ const {
28
28
  /** @typedef {import("../logging/Logger").Logger} Logger */
29
29
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
30
30
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
31
- /** @typedef {typeof import("../util/Hash")} Hash */
31
+ /** @typedef {import("../util/Hash").HashFunction} HashFunction */
32
32
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
33
33
 
34
34
  /** @typedef {Set<string>} Items */
@@ -134,13 +134,17 @@ class Pack {
134
134
  this.itemInfo = new Map();
135
135
  /** @type {(string | undefined)[]} */
136
136
  this.requests = [];
137
+ /** @type {undefined | NodeJS.Timeout} */
137
138
  this.requestsTimeout = undefined;
138
139
  /** @type {ItemInfo} */
139
140
  this.freshContent = new Map();
140
141
  /** @type {(undefined | PackContent)[]} */
141
142
  this.content = [];
143
+ /** @type {boolean} */
142
144
  this.invalid = false;
145
+ /** @type {Logger} */
143
146
  this.logger = logger;
147
+ /** @type {number} */
144
148
  this.maxAge = maxAge;
145
149
  }
146
150
 
@@ -243,6 +247,7 @@ class Pack {
243
247
  * @returns {number} new location of data entries
244
248
  */
245
249
  _findLocation() {
250
+ /** @type {number} */
246
251
  let i;
247
252
  for (i = 0; i < this.content.length && this.content[i] !== undefined; i++);
248
253
  return i;
@@ -256,6 +261,7 @@ class Pack {
256
261
  */
257
262
  _gcAndUpdateLocation(items, usedItems, newLoc) {
258
263
  let count = 0;
264
+ /** @type {undefined | string} */
259
265
  let lastGC;
260
266
  const now = Date.now();
261
267
  for (const identifier of items) {
@@ -381,6 +387,7 @@ class Pack {
381
387
  }
382
388
 
383
389
  // 2. Check if minimum number is reached
390
+ /** @type {number[]} */
384
391
  let mergedIndices;
385
392
  if (
386
393
  smallUsedContents.length >= CONTENT_COUNT_TO_MERGE ||
@@ -505,6 +512,7 @@ class Pack {
505
512
 
506
513
  // 5. Determine items for the unused content file
507
514
  const unusedItems = new Set(content.items);
515
+ /** @type {Items} */
508
516
  const usedOfUnusedItems = new Set();
509
517
  for (const identifier of usedItems) {
510
518
  unusedItems.delete(identifier);
@@ -521,6 +529,7 @@ class Pack {
521
529
  await content.unpack(
522
530
  "it should be splitted into used and unused items"
523
531
  );
532
+ /** @type {Content} */
524
533
  const map = new Map();
525
534
  for (const identifier of unusedItems) {
526
535
  map.set(
@@ -579,6 +588,7 @@ class Pack {
579
588
  await content.unpack(
580
589
  "it contains old items that should be garbage collected"
581
590
  );
591
+ /** @type {Content} */
582
592
  const map = new Map();
583
593
  for (const identifier of items) {
584
594
  map.set(
@@ -691,7 +701,7 @@ class PackContentItems {
691
701
  }
692
702
 
693
703
  /**
694
- * @param {ObjectSerializerContext & { logger: Logger, profile: boolean | undefined }} context context
704
+ * @param {ObjectSerializerContext & { logger: Logger, profile: boolean | undefined }} context context
695
705
  */
696
706
  serialize({ write, snapshot, rollback, logger, profile }) {
697
707
  if (profile) {
@@ -774,6 +784,7 @@ class PackContentItems {
774
784
  if (read()) {
775
785
  this.map = read();
776
786
  } else if (profile) {
787
+ /** @type {Map<EXPECTED_ANY, EXPECTED_ANY>} */
777
788
  const map = new Map();
778
789
  let key = read();
779
790
  while (key !== null) {
@@ -799,6 +810,7 @@ class PackContentItems {
799
810
  }
800
811
  this.map = map;
801
812
  } else {
813
+ /** @type {Map<EXPECTED_ANY, EXPECTED_ANY>} */
802
814
  const map = new Map();
803
815
  let key = read();
804
816
  while (key !== null) {
@@ -816,7 +828,7 @@ makeSerializable(
816
828
  "PackContentItems"
817
829
  );
818
830
 
819
- /** @typedef {(() => Promise<PackContentItems> | PackContentItems) & Partial<{ options: { size?: number }}>} LazyFunction */
831
+ /** @typedef {(() => Promise<PackContentItems> | PackContentItems) & Partial<{ options: { size?: number } }>} LazyFunction */
820
832
 
821
833
  class PackContent {
822
834
  /*
@@ -846,14 +858,19 @@ class PackContent {
846
858
  * @param {string=} lazyName name of dataOrFn for logging
847
859
  */
848
860
  constructor(items, usedItems, dataOrFn, logger, lazyName) {
861
+ /** @type {Items} */
849
862
  this.items = items;
850
863
  /** @type {LazyFunction | undefined} */
851
864
  this.lazy = typeof dataOrFn === "function" ? dataOrFn : undefined;
852
865
  /** @type {Content | undefined} */
853
866
  this.content = typeof dataOrFn === "function" ? undefined : dataOrFn.map;
867
+ /** @type {boolean} */
854
868
  this.outdated = false;
869
+ /** @type {Items} */
855
870
  this.used = usedItems;
871
+ /** @type {Logger | undefined} */
856
872
  this.logger = logger;
873
+ /** @type {string | undefined} */
857
874
  this.lazyName = lazyName;
858
875
  }
859
876
 
@@ -1091,10 +1108,10 @@ class PackFileCacheStrategy {
1091
1108
  * @param {Logger} options.logger a logger
1092
1109
  * @param {SnapshotOptions} options.snapshot options regarding snapshotting
1093
1110
  * @param {number} options.maxAge max age of cache items
1094
- * @param {boolean | undefined} options.profile track and log detailed timing information for individual cache items
1095
- * @param {boolean | undefined} options.allowCollectingMemory allow to collect unused memory created during deserialization
1096
- * @param {false | "gzip" | "brotli" | undefined} options.compression compression used
1097
- * @param {boolean | undefined} options.readonly disable storing cache into filesystem
1111
+ * @param {boolean=} options.profile track and log detailed timing information for individual cache items
1112
+ * @param {boolean=} options.allowCollectingMemory allow to collect unused memory created during deserialization
1113
+ * @param {false | "gzip" | "brotli"=} options.compression compression used
1114
+ * @param {boolean=} options.readonly disable storing cache into filesystem
1098
1115
  */
1099
1116
  constructor({
1100
1117
  compiler,
@@ -1113,31 +1130,44 @@ class PackFileCacheStrategy {
1113
1130
  /** @type {import("../serialization/Serializer")<PackContainer, null, EXPECTED_OBJECT>} */
1114
1131
  this.fileSerializer = createFileSerializer(
1115
1132
  fs,
1116
- /** @type {string | Hash} */
1133
+ /** @type {HashFunction} */
1117
1134
  (compiler.options.output.hashFunction)
1118
1135
  );
1136
+ /** @type {FileSystemInfo} */
1119
1137
  this.fileSystemInfo = new FileSystemInfo(fs, {
1120
1138
  managedPaths: snapshot.managedPaths,
1121
1139
  immutablePaths: snapshot.immutablePaths,
1122
1140
  logger: logger.getChildLogger("webpack.FileSystemInfo"),
1123
1141
  hashFunction: compiler.options.output.hashFunction
1124
1142
  });
1143
+ /** @type {Compiler} */
1125
1144
  this.compiler = compiler;
1145
+ /** @type {string} */
1126
1146
  this.context = context;
1147
+ /** @type {string} */
1127
1148
  this.cacheLocation = cacheLocation;
1149
+ /** @type {string} */
1128
1150
  this.version = version;
1151
+ /** @type {Logger} */
1129
1152
  this.logger = logger;
1153
+ /** @type {number} */
1130
1154
  this.maxAge = maxAge;
1155
+ /** @type {boolean | undefined} */
1131
1156
  this.profile = profile;
1157
+ /** @type {boolean | undefined} */
1132
1158
  this.readonly = readonly;
1159
+ /** @type {boolean | undefined} */
1133
1160
  this.allowCollectingMemory = allowCollectingMemory;
1161
+ /** @type {false | "gzip" | "brotli" | undefined} */
1134
1162
  this.compression = compression;
1163
+ /** @type {string} */
1135
1164
  this._extension =
1136
1165
  compression === "brotli"
1137
1166
  ? ".pack.br"
1138
1167
  : compression === "gzip"
1139
1168
  ? ".pack.gz"
1140
1169
  : ".pack";
1170
+ /** @type {SnapshotOptions} */
1141
1171
  this.snapshot = snapshot;
1142
1172
  /** @type {BuildDependencies} */
1143
1173
  this.buildDependencies = new Set();
@@ -1151,6 +1181,7 @@ class PackFileCacheStrategy {
1151
1181
  this.buildSnapshot = undefined;
1152
1182
  /** @type {Promise<Pack> | undefined} */
1153
1183
  this.packPromise = this._openPack();
1184
+ /** @type {Promise<void>} */
1154
1185
  this.storePromise = Promise.resolve();
1155
1186
  }
1156
1187
 
@@ -1382,7 +1413,9 @@ class PackFileCacheStrategy {
1382
1413
  if (!pack.invalid) return;
1383
1414
  this.packPromise = undefined;
1384
1415
  this.logger.log("Storing pack...");
1416
+ /** @type {undefined | Promise<void>} */
1385
1417
  let promise;
1418
+ /** @type {Set<string>} */
1386
1419
  const newBuildDependencies = new Set();
1387
1420
  for (const dep of this.newBuildDependencies) {
1388
1421
  if (!this.buildDependencies.has(dep)) {
@@ -10,6 +10,7 @@ const createHash = require("../util/createHash");
10
10
 
11
11
  /** @typedef {import("../util/Hash")} Hash */
12
12
  /** @typedef {typeof import("../util/Hash")} HashConstructor */
13
+ /** @typedef {import("../util/Hash").HashFunction} HashFunction */
13
14
 
14
15
  /**
15
16
  * @typedef {object} HashableObject
@@ -19,11 +20,14 @@ const createHash = require("../util/createHash");
19
20
  class LazyHashedEtag {
20
21
  /**
21
22
  * @param {HashableObject} obj object with updateHash method
22
- * @param {string | HashConstructor} hashFunction the hash function to use
23
+ * @param {HashFunction} hashFunction the hash function to use
23
24
  */
24
25
  constructor(obj, hashFunction = DEFAULTS.HASH_FUNCTION) {
26
+ /** @type {HashableObject} */
25
27
  this._obj = obj;
28
+ /** @type {undefined | string} */
26
29
  this._hash = undefined;
30
+ /** @type {HashFunction} */
27
31
  this._hashFunction = hashFunction;
28
32
  }
29
33
 
@@ -40,23 +44,27 @@ class LazyHashedEtag {
40
44
  }
41
45
  }
42
46
 
43
- /** @type {Map<string | HashConstructor, WeakMap<HashableObject, LazyHashedEtag>>} */
47
+ /** @typedef {WeakMap<HashableObject, LazyHashedEtag>} InnerCache */
48
+
49
+ /** @type {Map<HashFunction, InnerCache>} */
44
50
  const mapStrings = new Map();
45
51
 
46
- /** @type {WeakMap<HashConstructor, WeakMap<HashableObject, LazyHashedEtag>>} */
52
+ /** @type {WeakMap<HashConstructor, InnerCache>} */
47
53
  const mapObjects = new WeakMap();
48
54
 
49
55
  /**
50
56
  * @param {HashableObject} obj object with updateHash method
51
- * @param {(string | HashConstructor)=} hashFunction the hash function to use
57
+ * @param {HashFunction=} hashFunction the hash function to use
52
58
  * @returns {LazyHashedEtag} etag
53
59
  */
54
60
  const getter = (obj, hashFunction = DEFAULTS.HASH_FUNCTION) => {
61
+ /** @type {undefined | InnerCache} */
55
62
  let innerMap;
56
63
  if (typeof hashFunction === "string") {
57
64
  innerMap = mapStrings.get(hashFunction);
58
65
  if (innerMap === undefined) {
59
66
  const newHash = new LazyHashedEtag(obj, hashFunction);
67
+ /** @type {InnerCache} */
60
68
  innerMap = new WeakMap();
61
69
  innerMap.set(obj, newHash);
62
70
  mapStrings.set(hashFunction, innerMap);
@@ -66,6 +74,7 @@ const getter = (obj, hashFunction = DEFAULTS.HASH_FUNCTION) => {
66
74
  innerMap = mapObjects.get(hashFunction);
67
75
  if (innerMap === undefined) {
68
76
  const newHash = new LazyHashedEtag(obj, hashFunction);
77
+ /** @type {InnerCache} */
69
78
  innerMap = new WeakMap();
70
79
  innerMap.set(obj, newHash);
71
80
  mapObjects.set(hashFunction, innerMap);
@@ -22,13 +22,15 @@ class MergedEtag {
22
22
  }
23
23
  }
24
24
 
25
+ /** @type {WeakMap<Etag, WeakMap<Etag, MergedEtag>>} */
25
26
  const dualObjectMap = new WeakMap();
27
+ /** @type {WeakMap<Etag, WeakMap<Etag, MergedEtag>>} */
26
28
  const objectStringMap = new WeakMap();
27
29
 
28
30
  /**
29
31
  * @param {Etag} a first
30
32
  * @param {Etag} b second
31
- * @returns {Etag} result
33
+ * @returns {string | MergedEtag} result
32
34
  */
33
35
  const mergeEtags = (a, b) => {
34
36
  if (typeof a === "string") {
package/lib/cli.js CHANGED
@@ -427,6 +427,7 @@ const getArguments = (schema = webpackSchema) => {
427
427
  return flags;
428
428
  };
429
429
 
430
+ /** @type {WeakMap<EXPECTED_OBJECT, number>} */
430
431
  const cliAddedItems = new WeakMap();
431
432
 
432
433
  /** @typedef {string | number} Property */
@@ -621,7 +622,7 @@ const parseValueForArgumentConfig = (argConfig, value) => {
621
622
  break;
622
623
  case "number":
623
624
  if (typeof value === "number") return value;
624
- if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) {
625
+ if (typeof value === "string" && /^[+-]?\d*(\.\d*)e\d+$/i) {
625
626
  const n = Number(value);
626
627
  if (!Number.isNaN(n)) return n;
627
628
  }
@@ -685,6 +686,7 @@ const processArguments = (args, config, values) => {
685
686
  * @param {number | undefined} i index
686
687
  */
687
688
  const processValue = (value, i) => {
689
+ /** @type {Problem[]} */
688
690
  const currentProblems = [];
689
691
  for (const argConfig of arg.configs) {
690
692
  const problem = processArgumentConfig(argConfig, config, value, i);