webpack 5.95.0 → 5.96.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) 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/EvalDevToolModulePlugin.js +5 -2
  19. package/lib/EvalSourceMapDevToolPlugin.js +5 -2
  20. package/lib/ExternalModule.js +40 -7
  21. package/lib/ExternalModuleFactoryPlugin.js +33 -9
  22. package/lib/FileSystemInfo.js +12 -8
  23. package/lib/Generator.js +5 -4
  24. package/lib/HotModuleReplacementPlugin.js +8 -6
  25. package/lib/IgnorePlugin.js +19 -1
  26. package/lib/LoaderOptionsPlugin.js +3 -1
  27. package/lib/Module.js +9 -8
  28. package/lib/ModuleSourceTypesConstants.js +100 -0
  29. package/lib/NormalModule.js +27 -17
  30. package/lib/NormalModuleFactory.js +38 -22
  31. package/lib/OptionsApply.js +12 -1
  32. package/lib/ProgressPlugin.js +50 -10
  33. package/lib/RawModule.js +3 -4
  34. package/lib/RuntimeModule.js +3 -4
  35. package/lib/RuntimePlugin.js +11 -4
  36. package/lib/RuntimeTemplate.js +13 -42
  37. package/lib/SourceMapDevToolPlugin.js +10 -7
  38. package/lib/Watching.js +2 -2
  39. package/lib/WebpackOptionsApply.js +42 -21
  40. package/lib/asset/AssetGenerator.js +347 -194
  41. package/lib/asset/AssetModulesPlugin.js +2 -1
  42. package/lib/asset/AssetSourceGenerator.js +82 -27
  43. package/lib/asset/RawDataUrlModule.js +5 -4
  44. package/lib/buildChunkGraph.js +2 -2
  45. package/lib/cache/PackFileCacheStrategy.js +69 -31
  46. package/lib/cache/ResolverCachePlugin.js +248 -173
  47. package/lib/config/defaults.js +134 -126
  48. package/lib/container/ContainerEntryModule.js +3 -4
  49. package/lib/container/ContainerPlugin.js +8 -0
  50. package/lib/container/FallbackModule.js +2 -2
  51. package/lib/container/HoistContainerReferencesPlugin.js +250 -0
  52. package/lib/container/ModuleFederationPlugin.js +38 -1
  53. package/lib/container/RemoteModule.js +4 -2
  54. package/lib/container/RemoteRuntimeModule.js +4 -2
  55. package/lib/css/CssExportsGenerator.js +16 -12
  56. package/lib/css/CssGenerator.js +22 -16
  57. package/lib/css/CssLoadingRuntimeModule.js +7 -6
  58. package/lib/css/CssModulesPlugin.js +122 -77
  59. package/lib/css/CssParser.js +655 -526
  60. package/lib/css/walkCssTokens.js +1168 -338
  61. package/lib/debug/ProfilingPlugin.js +5 -0
  62. package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
  63. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
  64. package/lib/dependencies/CssExportDependency.js +3 -3
  65. package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
  66. package/lib/dependencies/CssUrlDependency.js +33 -3
  67. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  68. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
  69. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
  71. package/lib/dependencies/ImportParserPlugin.js +9 -7
  72. package/lib/dependencies/LoaderPlugin.js +19 -0
  73. package/lib/dependencies/SystemPlugin.js +2 -1
  74. package/lib/dependencies/URLPlugin.js +7 -1
  75. package/lib/dependencies/WorkerPlugin.js +1 -1
  76. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
  77. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  78. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  79. package/lib/hmr/LazyCompilationPlugin.js +16 -4
  80. package/lib/hmr/lazyCompilationBackend.js +1 -7
  81. package/lib/index.js +37 -7
  82. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  83. package/lib/javascript/JavascriptGenerator.js +8 -8
  84. package/lib/javascript/JavascriptModulesPlugin.js +126 -73
  85. package/lib/javascript/JavascriptParser.js +338 -117
  86. package/lib/json/JsonGenerator.js +5 -5
  87. package/lib/library/EnableLibraryPlugin.js +2 -2
  88. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  89. package/lib/library/UmdLibraryPlugin.js +16 -8
  90. package/lib/logging/Logger.js +11 -11
  91. package/lib/logging/createConsoleLogger.js +14 -14
  92. package/lib/logging/truncateArgs.js +1 -1
  93. package/lib/node/NodeWatchFileSystem.js +3 -1
  94. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
  95. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  96. package/lib/node/nodeConsole.js +11 -8
  97. package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
  98. package/lib/optimize/ConcatenatedModule.js +43 -145
  99. package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
  100. package/lib/optimize/InnerGraphPlugin.js +57 -16
  101. package/lib/optimize/LimitChunkCountPlugin.js +2 -4
  102. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  103. package/lib/optimize/RealContentHashPlugin.js +1 -1
  104. package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
  105. package/lib/rules/RuleSetCompiler.js +2 -2
  106. package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
  107. package/lib/schemes/DataUriPlugin.js +1 -1
  108. package/lib/serialization/BinaryMiddleware.js +32 -19
  109. package/lib/serialization/ObjectMiddleware.js +23 -9
  110. package/lib/serialization/SerializerMiddleware.js +3 -2
  111. package/lib/serialization/types.js +2 -2
  112. package/lib/sharing/ConsumeSharedModule.js +2 -3
  113. package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
  114. package/lib/sharing/ProvideSharedModule.js +2 -3
  115. package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
  116. package/lib/stats/StatsFactory.js +12 -12
  117. package/lib/stats/StatsPrinter.js +7 -7
  118. package/lib/util/AsyncQueue.js +17 -1
  119. package/lib/util/IterableHelpers.js +1 -1
  120. package/lib/util/SetHelpers.js +1 -1
  121. package/lib/util/cleverMerge.js +48 -24
  122. package/lib/util/concatenate.js +227 -0
  123. package/lib/util/create-schema-validation.js +22 -9
  124. package/lib/util/deprecation.js +86 -28
  125. package/lib/util/fs.js +9 -9
  126. package/lib/util/hash/wasm-hash.js +12 -1
  127. package/lib/util/magicComment.js +21 -0
  128. package/lib/util/makeSerializable.js +24 -1
  129. package/lib/util/memoize.js +2 -1
  130. package/lib/util/runtime.js +4 -1
  131. package/lib/util/semver.js +130 -23
  132. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
  133. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  134. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
  135. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
  136. package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
  137. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
  138. package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
  139. package/lib/web/FetchCompileWasmPlugin.js +1 -2
  140. package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
  141. package/package.json +18 -19
  142. package/schemas/WebpackOptions.check.js +1 -1
  143. package/schemas/WebpackOptions.json +8 -2
  144. package/types.d.ts +801 -259
  145. package/lib/util/mergeScope.js +0 -76
@@ -9,15 +9,18 @@ const fs = require("fs");
9
9
  const path = require("path");
10
10
  const {
11
11
  JAVASCRIPT_MODULE_TYPE_AUTO,
12
- JSON_MODULE_TYPE,
13
- WEBASSEMBLY_MODULE_TYPE_ASYNC,
14
12
  JAVASCRIPT_MODULE_TYPE_ESM,
15
13
  JAVASCRIPT_MODULE_TYPE_DYNAMIC,
14
+ JSON_MODULE_TYPE,
15
+ WEBASSEMBLY_MODULE_TYPE_ASYNC,
16
16
  WEBASSEMBLY_MODULE_TYPE_SYNC,
17
17
  ASSET_MODULE_TYPE,
18
+ ASSET_MODULE_TYPE_INLINE,
19
+ ASSET_MODULE_TYPE_RESOURCE,
18
20
  CSS_MODULE_TYPE_AUTO,
19
21
  CSS_MODULE_TYPE,
20
- CSS_MODULE_TYPE_MODULE
22
+ CSS_MODULE_TYPE_MODULE,
23
+ CSS_MODULE_TYPE_GLOBAL
21
24
  } = require("../ModuleTypeConstants");
22
25
  const Template = require("../Template");
23
26
  const { cleverMerge } = require("../util/cleverMerge");
@@ -123,7 +126,7 @@ const A = (obj, prop, factory) => {
123
126
  if (value === undefined) {
124
127
  obj[prop] = factory();
125
128
  } else if (Array.isArray(value)) {
126
- /** @type {any[] | undefined} */
129
+ /** @type {EXPECTED_ANY[] | undefined} */
127
130
  let newArray;
128
131
  for (let i = 0; i < value.length; i++) {
129
132
  const item = value[i];
@@ -132,7 +135,9 @@ const A = (obj, prop, factory) => {
132
135
  newArray = value.slice(0, i);
133
136
  obj[prop] = /** @type {T[P]} */ (/** @type {unknown} */ (newArray));
134
137
  }
135
- const items = /** @type {any[]} */ (/** @type {unknown} */ (factory()));
138
+ const items = /** @type {EXPECTED_ANY[]} */ (
139
+ /** @type {unknown} */ (factory())
140
+ );
136
141
  if (items !== undefined) {
137
142
  for (const item of items) {
138
143
  newArray.push(item);
@@ -283,7 +288,9 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
283
288
  futureDefaults:
284
289
  /** @type {NonNullable<WebpackOptionsNormalized["experiments"]["futureDefaults"]>} */
285
290
  (options.experiments.futureDefaults),
286
- outputModule: options.output.module,
291
+ outputModule:
292
+ /** @type {NonNullable<WebpackOptionsNormalized["output"]["module"]>} */
293
+ (options.output.module),
287
294
  targetProperties
288
295
  });
289
296
 
@@ -631,19 +638,19 @@ const applyModuleDefaults = (
631
638
  F(module.parser, ASSET_MODULE_TYPE, () => ({}));
632
639
  F(
633
640
  /** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
634
- (module.parser.asset),
641
+ (module.parser[ASSET_MODULE_TYPE]),
635
642
  "dataUrlCondition",
636
643
  () => ({})
637
644
  );
638
645
  if (
639
646
  typeof (
640
647
  /** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
641
- (module.parser.asset).dataUrlCondition
648
+ (module.parser[ASSET_MODULE_TYPE]).dataUrlCondition
642
649
  ) === "object"
643
650
  ) {
644
651
  D(
645
652
  /** @type {NonNullable<ParserOptionsByModuleTypeKnown["asset"]>} */
646
- (module.parser.asset).dataUrlCondition,
653
+ (module.parser[ASSET_MODULE_TYPE]).dataUrlCondition,
647
654
  "maxSize",
648
655
  8096
649
656
  );
@@ -661,41 +668,41 @@ const applyModuleDefaults = (
661
668
  );
662
669
 
663
670
  if (css) {
664
- F(module.parser, "css", () => ({}));
671
+ F(module.parser, CSS_MODULE_TYPE, () => ({}));
665
672
 
666
- D(module.parser.css, "namedExports", true);
673
+ D(module.parser[CSS_MODULE_TYPE], "namedExports", true);
667
674
 
668
- F(module.generator, "css", () => ({}));
675
+ F(module.generator, CSS_MODULE_TYPE, () => ({}));
669
676
 
670
677
  applyCssGeneratorOptionsDefaults(
671
678
  /** @type {NonNullable<GeneratorOptionsByModuleTypeKnown["css"]>} */
672
- (module.generator.css),
679
+ (module.generator[CSS_MODULE_TYPE]),
673
680
  { targetProperties }
674
681
  );
675
682
 
676
- F(module.generator, "css/auto", () => ({}));
683
+ F(module.generator, CSS_MODULE_TYPE_AUTO, () => ({}));
677
684
  D(
678
- module.generator["css/auto"],
685
+ module.generator[CSS_MODULE_TYPE_AUTO],
679
686
  "localIdentName",
680
687
  "[uniqueName]-[id]-[local]"
681
688
  );
682
- D(module.generator["css/auto"], "exportsConvention", "as-is");
689
+ D(module.generator[CSS_MODULE_TYPE_AUTO], "exportsConvention", "as-is");
683
690
 
684
- F(module.generator, "css/module", () => ({}));
691
+ F(module.generator, CSS_MODULE_TYPE_MODULE, () => ({}));
685
692
  D(
686
- module.generator["css/module"],
693
+ module.generator[CSS_MODULE_TYPE_MODULE],
687
694
  "localIdentName",
688
695
  "[uniqueName]-[id]-[local]"
689
696
  );
690
- D(module.generator["css/module"], "exportsConvention", "as-is");
697
+ D(module.generator[CSS_MODULE_TYPE_MODULE], "exportsConvention", "as-is");
691
698
 
692
- F(module.generator, "css/global", () => ({}));
699
+ F(module.generator, CSS_MODULE_TYPE_GLOBAL, () => ({}));
693
700
  D(
694
- module.generator["css/global"],
701
+ module.generator[CSS_MODULE_TYPE_GLOBAL],
695
702
  "localIdentName",
696
703
  "[uniqueName]-[id]-[local]"
697
704
  );
698
- D(module.generator["css/global"], "exportsConvention", "as-is");
705
+ D(module.generator[CSS_MODULE_TYPE_GLOBAL], "exportsConvention", "as-is");
699
706
  }
700
707
 
701
708
  A(module, "defaultRules", () => {
@@ -827,19 +834,19 @@ const applyModuleDefaults = (
827
834
  oneOf: [
828
835
  {
829
836
  scheme: /^data$/,
830
- type: "asset/inline"
837
+ type: ASSET_MODULE_TYPE_INLINE
831
838
  },
832
839
  {
833
- type: "asset/resource"
840
+ type: ASSET_MODULE_TYPE_RESOURCE
834
841
  }
835
842
  ]
836
843
  },
837
844
  {
838
- assert: { type: "json" },
845
+ assert: { type: JSON_MODULE_TYPE },
839
846
  type: JSON_MODULE_TYPE
840
847
  },
841
848
  {
842
- with: { type: "json" },
849
+ with: { type: JSON_MODULE_TYPE },
843
850
  type: JSON_MODULE_TYPE
844
851
  }
845
852
  );
@@ -920,6 +927,104 @@ const applyOutputDefaults = (
920
927
  });
921
928
 
922
929
  F(output, "module", () => Boolean(outputModule));
930
+
931
+ const environment = /** @type {Environment} */ (output.environment);
932
+ /**
933
+ * @param {boolean | undefined} v value
934
+ * @returns {boolean} true, when v is truthy or undefined
935
+ */
936
+ const optimistic = v => v || v === undefined;
937
+ /**
938
+ * @param {boolean | undefined} v value
939
+ * @param {boolean | undefined} c condition
940
+ * @returns {boolean | undefined} true, when v is truthy or undefined, or c is truthy
941
+ */
942
+ const conditionallyOptimistic = (v, c) => (v === undefined && c) || v;
943
+
944
+ F(
945
+ environment,
946
+ "globalThis",
947
+ () => /** @type {boolean | undefined} */ (tp && tp.globalThis)
948
+ );
949
+ F(
950
+ environment,
951
+ "bigIntLiteral",
952
+ () =>
953
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.bigIntLiteral))
954
+ );
955
+ F(
956
+ environment,
957
+ "const",
958
+ () => tp && optimistic(/** @type {boolean | undefined} */ (tp.const))
959
+ );
960
+ F(
961
+ environment,
962
+ "arrowFunction",
963
+ () =>
964
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.arrowFunction))
965
+ );
966
+ F(
967
+ environment,
968
+ "asyncFunction",
969
+ () =>
970
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.asyncFunction))
971
+ );
972
+ F(
973
+ environment,
974
+ "forOf",
975
+ () => tp && optimistic(/** @type {boolean | undefined} */ (tp.forOf))
976
+ );
977
+ F(
978
+ environment,
979
+ "destructuring",
980
+ () =>
981
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.destructuring))
982
+ );
983
+ F(
984
+ environment,
985
+ "optionalChaining",
986
+ () =>
987
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.optionalChaining))
988
+ );
989
+ F(
990
+ environment,
991
+ "nodePrefixForCoreModules",
992
+ () =>
993
+ tp &&
994
+ optimistic(
995
+ /** @type {boolean | undefined} */ (tp.nodePrefixForCoreModules)
996
+ )
997
+ );
998
+ F(
999
+ environment,
1000
+ "templateLiteral",
1001
+ () =>
1002
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.templateLiteral))
1003
+ );
1004
+ F(environment, "dynamicImport", () =>
1005
+ conditionallyOptimistic(
1006
+ /** @type {boolean | undefined} */ (tp && tp.dynamicImport),
1007
+ output.module
1008
+ )
1009
+ );
1010
+ F(environment, "dynamicImportInWorker", () =>
1011
+ conditionallyOptimistic(
1012
+ /** @type {boolean | undefined} */ (tp && tp.dynamicImportInWorker),
1013
+ output.module
1014
+ )
1015
+ );
1016
+ F(environment, "module", () =>
1017
+ conditionallyOptimistic(
1018
+ /** @type {boolean | undefined} */ (tp && tp.module),
1019
+ output.module
1020
+ )
1021
+ );
1022
+ F(
1023
+ environment,
1024
+ "document",
1025
+ () => tp && optimistic(/** @type {boolean | undefined} */ (tp.document))
1026
+ );
1027
+
923
1028
  D(output, "filename", output.module ? "[name].mjs" : "[name].js");
924
1029
  F(output, "iife", () => !output.module);
925
1030
  D(output, "importFunctionName", "import");
@@ -981,7 +1086,7 @@ const applyOutputDefaults = (
981
1086
  ? "Make sure that your 'browserslist' includes only platforms that support these features or select an appropriate 'target' to allow selecting a chunk format by default. Alternatively specify the 'output.chunkFormat' directly."
982
1087
  : "Select an appropriate 'target' to allow selecting one by default, or specify the 'output.chunkFormat' directly.";
983
1088
  if (output.module) {
984
- if (tp.dynamicImport) return "module";
1089
+ if (environment.dynamicImport) return "module";
985
1090
  if (tp.document) return "array-push";
986
1091
  throw new Error(
987
1092
  "For the selected environment is no default ESM chunk format available:\n" +
@@ -1021,7 +1126,7 @@ const applyOutputDefaults = (
1021
1126
  if (tp.nodeBuiltins) return "async-node";
1022
1127
  break;
1023
1128
  case "module":
1024
- if (tp.dynamicImport || output.module) return "import";
1129
+ if (environment.dynamicImport) return "import";
1025
1130
  break;
1026
1131
  }
1027
1132
  if (
@@ -1046,7 +1151,7 @@ const applyOutputDefaults = (
1046
1151
  if (tp.nodeBuiltins) return "async-node";
1047
1152
  break;
1048
1153
  case "module":
1049
- if (tp.dynamicImportInWorker || output.module) return "import";
1154
+ if (environment.dynamicImportInWorker) return "import";
1050
1155
  break;
1051
1156
  }
1052
1157
  if (
@@ -1101,103 +1206,6 @@ const applyOutputDefaults = (
1101
1206
  D(output, "strictModuleErrorHandling", false);
1102
1207
  D(output, "strictModuleExceptionHandling", false);
1103
1208
 
1104
- const environment = /** @type {Environment} */ (output.environment);
1105
- /**
1106
- * @param {boolean | undefined} v value
1107
- * @returns {boolean} true, when v is truthy or undefined
1108
- */
1109
- const optimistic = v => v || v === undefined;
1110
- /**
1111
- * @param {boolean | undefined} v value
1112
- * @param {boolean | undefined} c condition
1113
- * @returns {boolean | undefined} true, when v is truthy or undefined, or c is truthy
1114
- */
1115
- const conditionallyOptimistic = (v, c) => (v === undefined && c) || v;
1116
-
1117
- F(
1118
- environment,
1119
- "globalThis",
1120
- () => /** @type {boolean | undefined} */ (tp && tp.globalThis)
1121
- );
1122
- F(
1123
- environment,
1124
- "bigIntLiteral",
1125
- () =>
1126
- tp && optimistic(/** @type {boolean | undefined} */ (tp.bigIntLiteral))
1127
- );
1128
- F(
1129
- environment,
1130
- "const",
1131
- () => tp && optimistic(/** @type {boolean | undefined} */ (tp.const))
1132
- );
1133
- F(
1134
- environment,
1135
- "arrowFunction",
1136
- () =>
1137
- tp && optimistic(/** @type {boolean | undefined} */ (tp.arrowFunction))
1138
- );
1139
- F(
1140
- environment,
1141
- "asyncFunction",
1142
- () =>
1143
- tp && optimistic(/** @type {boolean | undefined} */ (tp.asyncFunction))
1144
- );
1145
- F(
1146
- environment,
1147
- "forOf",
1148
- () => tp && optimistic(/** @type {boolean | undefined} */ (tp.forOf))
1149
- );
1150
- F(
1151
- environment,
1152
- "destructuring",
1153
- () =>
1154
- tp && optimistic(/** @type {boolean | undefined} */ (tp.destructuring))
1155
- );
1156
- F(
1157
- environment,
1158
- "optionalChaining",
1159
- () =>
1160
- tp && optimistic(/** @type {boolean | undefined} */ (tp.optionalChaining))
1161
- );
1162
- F(
1163
- environment,
1164
- "nodePrefixForCoreModules",
1165
- () =>
1166
- tp &&
1167
- optimistic(
1168
- /** @type {boolean | undefined} */ (tp.nodePrefixForCoreModules)
1169
- )
1170
- );
1171
- F(
1172
- environment,
1173
- "templateLiteral",
1174
- () =>
1175
- tp && optimistic(/** @type {boolean | undefined} */ (tp.templateLiteral))
1176
- );
1177
- F(environment, "dynamicImport", () =>
1178
- conditionallyOptimistic(
1179
- /** @type {boolean | undefined} */ (tp && tp.dynamicImport),
1180
- output.module
1181
- )
1182
- );
1183
- F(environment, "dynamicImportInWorker", () =>
1184
- conditionallyOptimistic(
1185
- /** @type {boolean | undefined} */ (tp && tp.dynamicImportInWorker),
1186
- output.module
1187
- )
1188
- );
1189
- F(environment, "module", () =>
1190
- conditionallyOptimistic(
1191
- /** @type {boolean | undefined} */ (tp && tp.module),
1192
- output.module
1193
- )
1194
- );
1195
- F(
1196
- environment,
1197
- "document",
1198
- () => tp && optimistic(/** @type {boolean | undefined} */ (tp.document))
1199
- );
1200
-
1201
1209
  const { trustedTypes } = output;
1202
1210
  if (trustedTypes) {
1203
1211
  F(
@@ -8,6 +8,7 @@
8
8
  const { OriginalSource, RawSource } = require("webpack-sources");
9
9
  const AsyncDependenciesBlock = require("../AsyncDependenciesBlock");
10
10
  const Module = require("../Module");
11
+ const { JS_TYPES } = require("../ModuleSourceTypesConstants");
11
12
  const { JAVASCRIPT_MODULE_TYPE_DYNAMIC } = require("../ModuleTypeConstants");
12
13
  const RuntimeGlobals = require("../RuntimeGlobals");
13
14
  const Template = require("../Template");
@@ -41,8 +42,6 @@ const ContainerExposedDependency = require("./ContainerExposedDependency");
41
42
 
42
43
  /** @typedef {[string, ExposeOptions][]} ExposesList */
43
44
 
44
- const SOURCE_TYPES = new Set(["javascript"]);
45
-
46
45
  class ContainerEntryModule extends Module {
47
46
  /**
48
47
  * @param {string} name container entry name
@@ -60,7 +59,7 @@ class ContainerEntryModule extends Module {
60
59
  * @returns {SourceTypes} types available (do not mutate)
61
60
  */
62
61
  getSourceTypes() {
63
- return SOURCE_TYPES;
62
+ return JS_TYPES;
64
63
  }
65
64
 
66
65
  /**
@@ -230,7 +229,7 @@ class ContainerEntryModule extends Module {
230
229
  `if (!${RuntimeGlobals.shareScopeMap}) return;`,
231
230
  `var name = ${JSON.stringify(this._shareScope)}`,
232
231
  `var oldScope = ${RuntimeGlobals.shareScopeMap}[name];`,
233
- `if(oldScope && oldScope !== shareScope) throw new Error("Container initialization failed as it has already been initialized with a different share scope");`,
232
+ 'if(oldScope && oldScope !== shareScope) throw new Error("Container initialization failed as it has already been initialized with a different share scope");',
234
233
  `${RuntimeGlobals.shareScopeMap}[name] = shareScope;`,
235
234
  `return ${RuntimeGlobals.initializeSharing}(name, initScope);`
236
235
  ])};`,
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const createSchemaValidation = require("../util/create-schema-validation");
9
+ const memoize = require("../util/memoize");
9
10
  const ContainerEntryDependency = require("./ContainerEntryDependency");
10
11
  const ContainerEntryModuleFactory = require("./ContainerEntryModuleFactory");
11
12
  const ContainerExposedDependency = require("./ContainerExposedDependency");
@@ -16,6 +17,10 @@ const { parseOptions } = require("./options");
16
17
  /** @typedef {import("./ContainerEntryModule").ExposeOptions} ExposeOptions */
17
18
  /** @typedef {import("./ContainerEntryModule").ExposesList} ExposesList */
18
19
 
20
+ const getModuleFederationPlugin = memoize(() =>
21
+ require("./ModuleFederationPlugin")
22
+ );
23
+
19
24
  const validate = createSchemaValidation(
20
25
  require("../../schemas/plugins/container/ContainerPlugin.check.js"),
21
26
  () => require("../../schemas/plugins/container/ContainerPlugin.json"),
@@ -73,6 +78,8 @@ class ContainerPlugin {
73
78
  }
74
79
 
75
80
  compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
81
+ const hooks =
82
+ getModuleFederationPlugin().getCompilationHooks(compilation);
76
83
  const dep = new ContainerEntryDependency(name, exposes, shareScope);
77
84
  dep.loc = { name };
78
85
  compilation.addEntry(
@@ -86,6 +93,7 @@ class ContainerPlugin {
86
93
  },
87
94
  error => {
88
95
  if (error) return callback(error);
96
+ hooks.addContainerEntryDependency.call(dep);
89
97
  callback();
90
98
  }
91
99
  );
@@ -7,6 +7,7 @@
7
7
 
8
8
  const { RawSource } = require("webpack-sources");
9
9
  const Module = require("../Module");
10
+ const { JS_TYPES } = require("../ModuleSourceTypesConstants");
10
11
  const { WEBPACK_MODULE_TYPE_FALLBACK } = require("../ModuleTypeConstants");
11
12
  const RuntimeGlobals = require("../RuntimeGlobals");
12
13
  const Template = require("../Template");
@@ -31,7 +32,6 @@ const FallbackItemDependency = require("./FallbackItemDependency");
31
32
  /** @typedef {import("../util/Hash")} Hash */
32
33
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
33
34
 
34
- const TYPES = new Set(["javascript"]);
35
35
  const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
36
36
 
37
37
  class FallbackModule extends Module {
@@ -120,7 +120,7 @@ class FallbackModule extends Module {
120
120
  * @returns {SourceTypes} types available (do not mutate)
121
121
  */
122
122
  getSourceTypes() {
123
- return TYPES;
123
+ return JS_TYPES;
124
124
  }
125
125
 
126
126
  /**