webpack 5.94.0 → 5.96.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 (151) hide show
  1. package/README.md +1 -1
  2. package/lib/AsyncDependenciesBlock.js +1 -1
  3. package/lib/BannerPlugin.js +2 -1
  4. package/lib/Chunk.js +30 -0
  5. package/lib/ChunkGraph.js +11 -6
  6. package/lib/ChunkGroup.js +2 -2
  7. package/lib/CleanPlugin.js +4 -5
  8. package/lib/CodeGenerationResults.js +6 -5
  9. package/lib/Compilation.js +71 -48
  10. package/lib/Compiler.js +7 -5
  11. package/lib/ConcatenationScope.js +7 -20
  12. package/lib/ContextModule.js +7 -8
  13. package/lib/CssModule.js +25 -21
  14. package/lib/DefinePlugin.js +14 -8
  15. package/lib/DelegatedModule.js +3 -3
  16. package/lib/DllModule.js +4 -4
  17. package/lib/DynamicEntryPlugin.js +29 -22
  18. package/lib/EnvironmentPlugin.js +3 -2
  19. package/lib/EvalDevToolModulePlugin.js +5 -2
  20. package/lib/EvalSourceMapDevToolPlugin.js +5 -2
  21. package/lib/ExternalModule.js +118 -99
  22. package/lib/ExternalModuleFactoryPlugin.js +33 -9
  23. package/lib/FileSystemInfo.js +12 -8
  24. package/lib/Generator.js +5 -4
  25. package/lib/HotModuleReplacementPlugin.js +8 -6
  26. package/lib/IgnorePlugin.js +19 -1
  27. package/lib/LoaderOptionsPlugin.js +3 -1
  28. package/lib/Module.js +9 -8
  29. package/lib/ModuleSourceTypesConstants.js +100 -0
  30. package/lib/NormalModule.js +27 -13
  31. package/lib/NormalModuleFactory.js +38 -22
  32. package/lib/OptionsApply.js +12 -1
  33. package/lib/ProgressPlugin.js +50 -10
  34. package/lib/RawModule.js +3 -4
  35. package/lib/RuntimeModule.js +3 -4
  36. package/lib/RuntimePlugin.js +11 -4
  37. package/lib/RuntimeTemplate.js +13 -42
  38. package/lib/SourceMapDevToolPlugin.js +10 -7
  39. package/lib/TemplatedPathPlugin.js +9 -3
  40. package/lib/Watching.js +2 -2
  41. package/lib/WebpackOptionsApply.js +42 -21
  42. package/lib/asset/AssetGenerator.js +347 -194
  43. package/lib/asset/AssetModulesPlugin.js +2 -1
  44. package/lib/asset/AssetSourceGenerator.js +82 -27
  45. package/lib/asset/RawDataUrlModule.js +5 -4
  46. package/lib/buildChunkGraph.js +79 -62
  47. package/lib/cache/PackFileCacheStrategy.js +69 -31
  48. package/lib/cache/ResolverCachePlugin.js +248 -173
  49. package/lib/config/defaults.js +135 -126
  50. package/lib/container/ContainerEntryModule.js +3 -4
  51. package/lib/container/ContainerPlugin.js +8 -0
  52. package/lib/container/FallbackModule.js +2 -2
  53. package/lib/container/HoistContainerReferencesPlugin.js +250 -0
  54. package/lib/container/ModuleFederationPlugin.js +38 -1
  55. package/lib/container/RemoteModule.js +4 -2
  56. package/lib/container/RemoteRuntimeModule.js +4 -2
  57. package/lib/css/CssExportsGenerator.js +16 -12
  58. package/lib/css/CssGenerator.js +22 -16
  59. package/lib/css/CssLoadingRuntimeModule.js +7 -6
  60. package/lib/css/CssModulesPlugin.js +122 -77
  61. package/lib/css/CssParser.js +655 -526
  62. package/lib/css/walkCssTokens.js +1168 -338
  63. package/lib/debug/ProfilingPlugin.js +5 -0
  64. package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
  65. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
  66. package/lib/dependencies/ContextDependency.js +6 -1
  67. package/lib/dependencies/ContextElementDependency.js +33 -6
  68. package/lib/dependencies/CssExportDependency.js +3 -3
  69. package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
  70. package/lib/dependencies/CssUrlDependency.js +33 -3
  71. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
  74. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
  75. package/lib/dependencies/ImportParserPlugin.js +9 -7
  76. package/lib/dependencies/LoaderPlugin.js +19 -0
  77. package/lib/dependencies/SystemPlugin.js +2 -1
  78. package/lib/dependencies/URLPlugin.js +7 -1
  79. package/lib/dependencies/WorkerPlugin.js +1 -1
  80. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
  81. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  82. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  83. package/lib/hmr/LazyCompilationPlugin.js +16 -4
  84. package/lib/hmr/lazyCompilationBackend.js +1 -7
  85. package/lib/index.js +35 -6
  86. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  87. package/lib/javascript/JavascriptGenerator.js +8 -8
  88. package/lib/javascript/JavascriptModulesPlugin.js +166 -88
  89. package/lib/javascript/JavascriptParser.js +338 -117
  90. package/lib/json/JsonGenerator.js +5 -5
  91. package/lib/library/EnableLibraryPlugin.js +2 -2
  92. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  93. package/lib/library/UmdLibraryPlugin.js +16 -8
  94. package/lib/logging/Logger.js +11 -11
  95. package/lib/logging/createConsoleLogger.js +14 -14
  96. package/lib/logging/truncateArgs.js +1 -1
  97. package/lib/node/NodeWatchFileSystem.js +3 -1
  98. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
  99. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  100. package/lib/node/nodeConsole.js +11 -8
  101. package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
  102. package/lib/optimize/ConcatenatedModule.js +44 -148
  103. package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
  104. package/lib/optimize/InnerGraphPlugin.js +57 -16
  105. package/lib/optimize/LimitChunkCountPlugin.js +2 -4
  106. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
  107. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  108. package/lib/optimize/RealContentHashPlugin.js +1 -1
  109. package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
  110. package/lib/rules/RuleSetCompiler.js +2 -2
  111. package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
  112. package/lib/schemes/DataUriPlugin.js +1 -1
  113. package/lib/serialization/BinaryMiddleware.js +32 -19
  114. package/lib/serialization/ObjectMiddleware.js +23 -9
  115. package/lib/serialization/SerializerMiddleware.js +3 -2
  116. package/lib/serialization/types.js +2 -2
  117. package/lib/sharing/ConsumeSharedModule.js +2 -3
  118. package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
  119. package/lib/sharing/ProvideSharedModule.js +2 -3
  120. package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
  121. package/lib/stats/StatsFactory.js +12 -12
  122. package/lib/stats/StatsPrinter.js +7 -7
  123. package/lib/util/AsyncQueue.js +17 -1
  124. package/lib/util/IterableHelpers.js +1 -1
  125. package/lib/util/LazySet.js +12 -0
  126. package/lib/util/SetHelpers.js +1 -1
  127. package/lib/util/cleverMerge.js +48 -24
  128. package/lib/util/concatenate.js +227 -0
  129. package/lib/util/create-schema-validation.js +22 -9
  130. package/lib/util/deprecation.js +86 -28
  131. package/lib/util/fs.js +10 -10
  132. package/lib/util/hash/wasm-hash.js +12 -1
  133. package/lib/util/magicComment.js +21 -0
  134. package/lib/util/makeSerializable.js +24 -1
  135. package/lib/util/memoize.js +2 -1
  136. package/lib/util/runtime.js +10 -1
  137. package/lib/util/semver.js +130 -23
  138. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
  139. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  140. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
  141. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
  142. package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
  143. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
  144. package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
  145. package/lib/web/FetchCompileWasmPlugin.js +1 -2
  146. package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
  147. package/package.json +19 -20
  148. package/schemas/WebpackOptions.check.js +1 -1
  149. package/schemas/WebpackOptions.json +12 -2
  150. package/types.d.ts +817 -269
  151. package/lib/util/mergeScope.js +0 -76
@@ -98,7 +98,7 @@ const MAX_TIME_IN_FRESH_PACK = 1 * 60 * 1000; // 1 min
98
98
  class PackItemInfo {
99
99
  /**
100
100
  * @param {string} identifier identifier of item
101
- * @param {string | null} etag etag of item
101
+ * @param {string | null | undefined} etag etag of item
102
102
  * @param {any} value fresh value of item
103
103
  */
104
104
  constructor(identifier, etag, value) {
@@ -268,20 +268,21 @@ class Pack {
268
268
  }
269
269
 
270
270
  _persistFreshContent() {
271
+ /** @typedef {{ items: Items, map: Map<string, any>, loc: number }} PackItem */
271
272
  const itemsCount = this.freshContent.size;
272
273
  if (itemsCount > 0) {
273
274
  const packCount = Math.ceil(itemsCount / MAX_ITEMS_IN_FRESH_PACK);
274
275
  const itemsPerPack = Math.ceil(itemsCount / packCount);
276
+ /** @type {PackItem[]} */
275
277
  const packs = [];
276
278
  let i = 0;
277
279
  let ignoreNextTimeTick = false;
278
280
  const createNextPack = () => {
279
281
  const loc = this._findLocation();
280
- this.content[loc] = null; // reserve
282
+ this.content[loc] = /** @type {EXPECTED_ANY} */ (null); // reserve
283
+ /** @type {PackItem} */
281
284
  const pack = {
282
- /** @type {Items} */
283
285
  items: new Set(),
284
- /** @type {Map<string, any>} */
285
286
  map: new Map(),
286
287
  loc
287
288
  };
@@ -407,7 +408,9 @@ class Pack {
407
408
  await content.unpack(
408
409
  "it should be merged with other small pack contents"
409
410
  );
410
- for (const [identifier, value] of content.content) {
411
+ for (const [identifier, value] of /** @type {Content} */ (
412
+ content.content
413
+ )) {
411
414
  map.set(identifier, value);
412
415
  }
413
416
  });
@@ -423,7 +426,7 @@ class Pack {
423
426
  mergedItems,
424
427
  mergedUsedItems,
425
428
  memoize(async () => {
426
- /** @type {Map<string, any>} */
429
+ /** @type {Content} */
427
430
  const map = new Map();
428
431
  await Promise.all(addToMergedMap.map(fn => fn(map)));
429
432
  return new PackContentItems(map);
@@ -471,7 +474,11 @@ class Pack {
471
474
  );
472
475
  const map = new Map();
473
476
  for (const identifier of usedItems) {
474
- map.set(identifier, content.content.get(identifier));
477
+ map.set(
478
+ identifier,
479
+ /** @type {Content} */
480
+ (content.content).get(identifier)
481
+ );
475
482
  }
476
483
  return new PackContentItems(map);
477
484
  }
@@ -498,7 +505,11 @@ class Pack {
498
505
  );
499
506
  const map = new Map();
500
507
  for (const identifier of unusedItems) {
501
- map.set(identifier, content.content.get(identifier));
508
+ map.set(
509
+ identifier,
510
+ /** @type {Content} */
511
+ (content.content).get(identifier)
512
+ );
502
513
  }
503
514
  return new PackContentItems(map);
504
515
  }
@@ -552,7 +563,11 @@ class Pack {
552
563
  );
553
564
  const map = new Map();
554
565
  for (const identifier of items) {
555
- map.set(identifier, content.content.get(identifier));
566
+ map.set(
567
+ identifier,
568
+ /** @type {Content} */
569
+ (content.content).get(identifier)
570
+ );
556
571
  }
557
572
  return new PackContentItems(map);
558
573
  })
@@ -633,7 +648,8 @@ class Pack {
633
648
  )
634
649
  );
635
650
  for (const identifier of items) {
636
- this.itemInfo.get(identifier).location = idx;
651
+ /** @type {PackItemInfo} */
652
+ (this.itemInfo.get(identifier)).location = idx;
637
653
  }
638
654
  }
639
655
  items = read();
@@ -643,9 +659,11 @@ class Pack {
643
659
 
644
660
  makeSerializable(Pack, "webpack/lib/cache/PackFileCacheStrategy", "Pack");
645
661
 
662
+ /** @typedef {Map<string, any>} Content */
663
+
646
664
  class PackContentItems {
647
665
  /**
648
- * @param {Map<string, any>} map items
666
+ * @param {Content} map items
649
667
  */
650
668
  constructor(map) {
651
669
  this.map = map;
@@ -680,12 +698,17 @@ class PackContentItems {
680
698
  rollback(s);
681
699
  if (err === NOT_SERIALIZABLE) continue;
682
700
  const msg = "Skipped not serializable cache item";
683
- if (err.message.includes("ModuleBuildError")) {
684
- logger.log(`${msg} (in build error): ${err.message}`);
685
- logger.debug(`${msg} '${key}' (in build error): ${err.stack}`);
701
+ const notSerializableErr = /** @type {Error} */ (err);
702
+ if (notSerializableErr.message.includes("ModuleBuildError")) {
703
+ logger.log(
704
+ `${msg} (in build error): ${notSerializableErr.message}`
705
+ );
706
+ logger.debug(
707
+ `${msg} '${key}' (in build error): ${notSerializableErr.stack}`
708
+ );
686
709
  } else {
687
- logger.warn(`${msg}: ${err.message}`);
688
- logger.debug(`${msg} '${key}': ${err.stack}`);
710
+ logger.warn(`${msg}: ${notSerializableErr.message}`);
711
+ logger.debug(`${msg} '${key}': ${notSerializableErr.stack}`);
689
712
  }
690
713
  }
691
714
  }
@@ -710,10 +733,11 @@ class PackContentItems {
710
733
  } catch (err) {
711
734
  rollback(s);
712
735
  if (err === NOT_SERIALIZABLE) continue;
736
+ const notSerializableErr = /** @type {Error} */ (err);
713
737
  logger.warn(
714
- `Skipped not serializable cache item '${key}': ${err.message}`
738
+ `Skipped not serializable cache item '${key}': ${notSerializableErr.message}`
715
739
  );
716
- logger.debug(err.stack);
740
+ logger.debug(notSerializableErr.stack);
717
741
  }
718
742
  }
719
743
  write(null);
@@ -767,6 +791,8 @@ makeSerializable(
767
791
  "PackContentItems"
768
792
  );
769
793
 
794
+ /** @typedef {(function(): Promise<PackContentItems> | PackContentItems)} LazyFn */
795
+
770
796
  class PackContent {
771
797
  /*
772
798
  This class can be in these states:
@@ -796,9 +822,9 @@ class PackContent {
796
822
  */
797
823
  constructor(items, usedItems, dataOrFn, logger, lazyName) {
798
824
  this.items = items;
799
- /** @type {(function(): Promise<PackContentItems> | PackContentItems) | undefined} */
825
+ /** @type {LazyFn | undefined} */
800
826
  this.lazy = typeof dataOrFn === "function" ? dataOrFn : undefined;
801
- /** @type {Map<string, any> | undefined} */
827
+ /** @type {Content | undefined} */
802
828
  this.content = typeof dataOrFn === "function" ? undefined : dataOrFn.map;
803
829
  this.outdated = false;
804
830
  this.used = usedItems;
@@ -834,7 +860,7 @@ class PackContent {
834
860
  );
835
861
  logger.time(timeMessage);
836
862
  }
837
- const value = this.lazy();
863
+ const value = /** @type {LazyFn} */ (this.lazy)();
838
864
  if ("then" in value) {
839
865
  return value.then(data => {
840
866
  const map = data.map;
@@ -843,7 +869,10 @@ class PackContent {
843
869
  }
844
870
  // Move to state C
845
871
  this.content = map;
846
- this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
872
+ this.lazy = SerializerMiddleware.unMemoizeLazy(
873
+ /** @type {LazyFn} */
874
+ (this.lazy)
875
+ );
847
876
  return map.get(identifier);
848
877
  });
849
878
  }
@@ -854,7 +883,10 @@ class PackContent {
854
883
  }
855
884
  // Move to state C
856
885
  this.content = map;
857
- this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
886
+ this.lazy = SerializerMiddleware.unMemoizeLazy(
887
+ /** @type {LazyFn} */
888
+ (this.lazy)
889
+ );
858
890
  return map.get(identifier);
859
891
  }
860
892
 
@@ -944,7 +976,7 @@ class PackContent {
944
976
  }
945
977
  if (this.content) {
946
978
  // State A2 or C2
947
- /** @type {Map<string, any>} */
979
+ /** @type {Content} */
948
980
  const map = new Map();
949
981
  for (const item of this.items) {
950
982
  map.set(item, this.content.get(item));
@@ -975,7 +1007,7 @@ class PackContent {
975
1007
  );
976
1008
  logger.time(timeMessage);
977
1009
  }
978
- const value = this.lazy();
1010
+ const value = /** @type {LazyFn} */ (this.lazy)();
979
1011
  this.outdated = false;
980
1012
  if ("then" in value) {
981
1013
  // Move to state B1
@@ -985,14 +1017,17 @@ class PackContent {
985
1017
  logger.timeEnd(timeMessage);
986
1018
  }
987
1019
  const oldMap = data.map;
988
- /** @type {Map<string, any>} */
1020
+ /** @type {Content} */
989
1021
  const map = new Map();
990
1022
  for (const item of this.items) {
991
1023
  map.set(item, oldMap.get(item));
992
1024
  }
993
1025
  // Move to state C1 (or maybe C2)
994
1026
  this.content = map;
995
- this.lazy = SerializerMiddleware.unMemoizeLazy(this.lazy);
1027
+ this.lazy = SerializerMiddleware.unMemoizeLazy(
1028
+ /** @type {LazyFn} */
1029
+ (this.lazy)
1030
+ );
996
1031
 
997
1032
  return new PackContentItems(map);
998
1033
  })
@@ -1003,7 +1038,7 @@ class PackContent {
1003
1038
  logger.timeEnd(timeMessage);
1004
1039
  }
1005
1040
  const oldMap = value.map;
1006
- /** @type {Map<string, any>} */
1041
+ /** @type {Content} */
1007
1042
  const map = new Map();
1008
1043
  for (const item of this.items) {
1009
1044
  map.set(item, oldMap.get(item));
@@ -1448,10 +1483,13 @@ class PackFileCacheStrategy {
1448
1483
  const content = new PackContainer(
1449
1484
  pack,
1450
1485
  this.version,
1451
- /** @type {Snapshot} */ (this.buildSnapshot),
1486
+ /** @type {Snapshot} */
1487
+ (this.buildSnapshot),
1452
1488
  updatedBuildDependencies,
1453
- this.resolveResults,
1454
- this.resolveBuildDependenciesSnapshot
1489
+ /** @type {ResolveResults} */
1490
+ (this.resolveResults),
1491
+ /** @type {Snapshot} */
1492
+ (this.resolveBuildDependenciesSnapshot)
1455
1493
  );
1456
1494
  return this.fileSerializer
1457
1495
  .serialize(content, {