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
@@ -7,11 +7,13 @@
7
7
 
8
8
  const { ConcatSource } = require("webpack-sources");
9
9
  const { UsageState } = require("../ExportsInfo");
10
+ const ExternalModule = require("../ExternalModule");
10
11
  const RuntimeGlobals = require("../RuntimeGlobals");
11
12
  const Template = require("../Template");
13
+ const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
12
14
  const ConcatenatedModule = require("../optimize/ConcatenatedModule");
13
15
  const propertyAccess = require("../util/propertyAccess");
14
- const { getEntryRuntime } = require("../util/runtime");
16
+ const { getEntryRuntime, getRuntimeKey } = require("../util/runtime");
15
17
  const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
16
18
 
17
19
  /** @typedef {import("webpack-sources").Source} Source */
@@ -20,11 +22,14 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
20
22
  /** @typedef {import("../../declarations/WebpackOptions").LibraryExport} LibraryExport */
21
23
  /** @typedef {import("../Chunk")} Chunk */
22
24
  /** @typedef {import("../Compiler")} Compiler */
25
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
23
26
  /** @typedef {import("../Module")} Module */
24
27
  /** @typedef {import("../Module").BuildMeta} BuildMeta */
25
28
  /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */
26
29
  /** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
27
30
  /** @typedef {import("../javascript/JavascriptModulesPlugin").ModuleRenderContext} ModuleRenderContext */
31
+ /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
32
+ /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
28
33
 
29
34
  /**
30
35
  * @template T
@@ -76,17 +81,20 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
76
81
  /** @type {BuildMeta} */
77
82
  const buildMeta = module.buildMeta || (module.buildMeta = {});
78
83
 
84
+ /** @type {BuildMeta["exportsSourceByRuntime"]} */
79
85
  const exportsSourceByRuntime =
80
86
  buildMeta.exportsSourceByRuntime ||
81
87
  (buildMeta.exportsSourceByRuntime = new Map());
82
88
 
89
+ /** @type {BuildMeta["exportsFinalNameByRuntime"]} */
83
90
  const exportsFinalNameByRuntime =
84
91
  buildMeta.exportsFinalNameByRuntime ||
85
92
  (buildMeta.exportsFinalNameByRuntime = new Map());
86
93
 
87
94
  for (const runtime of runtimes) {
88
- exportsSourceByRuntime.set(runtime, source);
89
- exportsFinalNameByRuntime.set(runtime, finalName);
95
+ const key = getRuntimeKey(runtime);
96
+ exportsSourceByRuntime.set(key, source);
97
+ exportsFinalNameByRuntime.set(key, finalName);
90
98
  }
91
99
 
92
100
  return true;
@@ -116,8 +124,13 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
116
124
  exportsInfo.canMangleUse = false;
117
125
  } else {
118
126
  const exportsInfo = moduleGraph.getExportsInfo(module);
119
- // If the entry module is commonjs, its exports cannot be mangled
120
- if (module.buildMeta && module.buildMeta.treatAsCommonJs) {
127
+
128
+ if (
129
+ // If the entry module is commonjs, its exports cannot be mangled
130
+ (module.buildMeta && module.buildMeta.treatAsCommonJs) ||
131
+ // The entry module provides unknown exports
132
+ exportsInfo._otherExportsInfo.provided === null
133
+ ) {
121
134
  exportsInfo.setUsedInUnknownWay(runtime);
122
135
  } else {
123
136
  exportsInfo.setAllKnownExportsUsed(runtime);
@@ -128,7 +141,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
128
141
 
129
142
  /**
130
143
  * @param {LibraryOptions} library normalized library option
131
- * @returns {T | false} preprocess as needed by overriding
144
+ * @returns {T} preprocess as needed by overriding
132
145
  */
133
146
  parseOptions(library) {
134
147
  const { name } = library;
@@ -144,6 +157,94 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
144
157
  };
145
158
  }
146
159
 
160
+ /**
161
+ * @param {Source} source source
162
+ * @param {Module} module module
163
+ * @param {ModuleGraph} moduleGraph moduleGraph
164
+ * @param {RuntimeSpec} runtime chunk runtime
165
+ * @param {[string, string][]} exports exports
166
+ * @param {Set<string>} alreadyRenderedExports already rendered exports
167
+ * @returns {ConcatSource} source with null provided exports
168
+ */
169
+ _analyzeUnknownProvidedExports(
170
+ source,
171
+ module,
172
+ moduleGraph,
173
+ runtime,
174
+ exports,
175
+ alreadyRenderedExports
176
+ ) {
177
+ const result = new ConcatSource(source);
178
+ /** @type {Set<string>} */
179
+ const moduleRequests = new Set();
180
+ /** @type {Map<string, string>} */
181
+ const unknownProvidedExports = new Map();
182
+
183
+ /**
184
+ * @param {Module} module the module
185
+ * @param {boolean} isDynamicReexport if module is dynamic reexported
186
+ */
187
+ const resolveDynamicStarReexport = (module, isDynamicReexport) => {
188
+ for (const connection of moduleGraph.getOutgoingConnections(module)) {
189
+ const dep = connection.dependency;
190
+
191
+ // Only handle star-reexport statement
192
+ if (
193
+ dep instanceof HarmonyExportImportedSpecifierDependency &&
194
+ dep.name === null
195
+ ) {
196
+ const importedModule = connection.resolvedModule;
197
+ const importedModuleExportsInfo =
198
+ moduleGraph.getExportsInfo(importedModule);
199
+
200
+ // The imported module provides unknown exports
201
+ // So keep the reexports rendered in the bundle
202
+ if (
203
+ dep.getMode(moduleGraph, runtime).type === "dynamic-reexport" &&
204
+ importedModuleExportsInfo._otherExportsInfo.provided === null
205
+ ) {
206
+ // Handle export * from 'external'
207
+ if (importedModule instanceof ExternalModule) {
208
+ moduleRequests.add(importedModule.userRequest);
209
+ } else {
210
+ resolveDynamicStarReexport(importedModule, true);
211
+ }
212
+ }
213
+ // If importer modules existing `dynamic-reexport` dependency
214
+ // We should keep export statement rendered in the bundle
215
+ else if (isDynamicReexport) {
216
+ for (const exportInfo of importedModuleExportsInfo.orderedExports) {
217
+ if (!exportInfo.provided || exportInfo.name === "default") {
218
+ continue;
219
+ }
220
+ const originalName = exportInfo.name;
221
+ const usedName = exportInfo.getUsedName(originalName, runtime);
222
+
223
+ if (!alreadyRenderedExports.has(originalName) && usedName) {
224
+ unknownProvidedExports.set(originalName, usedName);
225
+ }
226
+ }
227
+ }
228
+ }
229
+ }
230
+ };
231
+
232
+ resolveDynamicStarReexport(module, false);
233
+
234
+ for (const request of moduleRequests) {
235
+ result.add(`export * from "${request}";\n`);
236
+ }
237
+
238
+ for (const [origin, used] of unknownProvidedExports) {
239
+ exports.push([
240
+ origin,
241
+ `${RuntimeGlobals.exports}${propertyAccess([used])}`
242
+ ]);
243
+ }
244
+
245
+ return result;
246
+ }
247
+
147
248
  /**
148
249
  * @param {Source} source source
149
250
  * @param {Module} module module
@@ -164,9 +265,8 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
164
265
  },
165
266
  { options, compilation }
166
267
  ) {
167
- const result = new ConcatSource(source);
168
-
169
- const exportsInfo = options.export
268
+ let result = new ConcatSource(source);
269
+ const exportInfos = options.export
170
270
  ? [
171
271
  moduleGraph.getExportInfo(
172
272
  module,
@@ -178,7 +278,9 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
178
278
  const exportsFinalNameByRuntime =
179
279
  (module.buildMeta &&
180
280
  module.buildMeta.exportsFinalNameByRuntime &&
181
- module.buildMeta.exportsFinalNameByRuntime.get(chunk.runtime)) ||
281
+ module.buildMeta.exportsFinalNameByRuntime.get(
282
+ getRuntimeKey(chunk.runtime)
283
+ )) ||
182
284
  {};
183
285
 
184
286
  const definitions =
@@ -188,6 +290,9 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
188
290
  const shortHandedExports = [];
189
291
  /** @type {[string, string][]} */
190
292
  const exports = [];
293
+ /** @type {Set<string>} */
294
+ const alreadyRenderedExports = new Set();
295
+
191
296
  const isAsync = moduleGraph.isAsync(module);
192
297
 
193
298
  const treatAsCommonJs =
@@ -200,7 +305,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
200
305
  );
201
306
  }
202
307
 
203
- outer: for (const exportInfo of exportsInfo) {
308
+ outer: for (const exportInfo of exportInfos) {
204
309
  if (!exportInfo.provided) continue;
205
310
 
206
311
  const originalName = exportInfo.name;
@@ -273,6 +378,8 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
273
378
  : `${finalName} as ${originalName}`
274
379
  );
275
380
  }
381
+
382
+ alreadyRenderedExports.add(originalName);
276
383
  }
277
384
 
278
385
  if (treatAsCommonJs) {
@@ -283,6 +390,15 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
283
390
  result.add(`export { ${shortHandedExports.join(", ")} };\n`);
284
391
  }
285
392
 
393
+ result = this._analyzeUnknownProvidedExports(
394
+ result,
395
+ module,
396
+ moduleGraph,
397
+ chunk.runtime,
398
+ exports,
399
+ alreadyRenderedExports
400
+ );
401
+
286
402
  for (const [exportName, final] of exports) {
287
403
  result.add(
288
404
  `export ${runtimeTemplate.renderConst()} ${exportName} = ${final};\n`
@@ -308,9 +424,10 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
308
424
  const exportsSource =
309
425
  module.buildMeta &&
310
426
  module.buildMeta.exportsSourceByRuntime &&
311
- module.buildMeta.exportsSourceByRuntime.get(chunk.runtime);
427
+ module.buildMeta.exportsSourceByRuntime.get(getRuntimeKey(chunk.runtime));
312
428
 
313
- // Re-add the module's exports source when rendered in factory or as an inlined startup module wrapped in an IIFE
429
+ // Re-add the module's exports source when rendered in factory
430
+ // or as an inlined startup module wrapped in an IIFE
314
431
  if ((inlinedInIIFE || factory) && exportsSource) {
315
432
  return new ConcatSource(exportsSource, source);
316
433
  }
@@ -17,6 +17,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
17
17
  /** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
18
18
  /** @typedef {import("../Chunk")} Chunk */
19
19
  /** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
20
+ /** @typedef {import("../ExportsInfo").ExportInfoName} ExportInfoName */
20
21
  /** @typedef {import("../javascript/JavascriptModulesPlugin").RenderContext} RenderContext */
21
22
  /** @typedef {import("../util/Hash")} Hash */
22
23
  /**
@@ -51,7 +52,7 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
51
52
 
52
53
  /**
53
54
  * @param {LibraryOptions} library normalized library option
54
- * @returns {T | false} preprocess as needed by overriding
55
+ * @returns {T} preprocess as needed by overriding
55
56
  */
56
57
  parseOptions(library) {
57
58
  const { name } = library;
@@ -128,7 +129,9 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
128
129
  const otherUnused =
129
130
  exportsInfo.otherExportsInfo.getUsed(chunk.runtime) ===
130
131
  UsageState.Unused;
132
+ /** @type {string[]} */
131
133
  const instructions = [];
134
+ /** @type {ExportInfoName[]} */
132
135
  const handledNames = [];
133
136
  for (const exportInfo of exportsInfo.orderedExports) {
134
137
  const used = exportInfo.getUsedName(
@@ -83,12 +83,13 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
83
83
  type: options.type
84
84
  });
85
85
 
86
+ /** @type {UmdLibraryPluginOptions["optionalAmdExternalAsGlobal"]} */
86
87
  this.optionalAmdExternalAsGlobal = options.optionalAmdExternalAsGlobal;
87
88
  }
88
89
 
89
90
  /**
90
91
  * @param {LibraryOptions} library normalized library option
91
- * @returns {T | false} preprocess as needed by overriding
92
+ * @returns {T} preprocess as needed by overriding
92
93
  */
93
94
  parseOptions(library) {
94
95
  /** @type {LibraryName | undefined} */
@@ -207,7 +208,6 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
207
208
  replaceKeys(
208
209
  externals
209
210
  .map((m) => {
210
- let expr;
211
211
  let request = m.request;
212
212
  if (typeof request === "object") {
213
213
  request =
@@ -219,7 +219,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
219
219
  `Missing external configuration for type:${type}`
220
220
  );
221
221
  }
222
- expr = Array.isArray(request)
222
+ let expr = Array.isArray(request)
223
223
  ? `require(${JSON.stringify(
224
224
  request[0]
225
225
  )})${accessorToObjectAccess(request.slice(1))}`
@@ -258,6 +258,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
258
258
  )
259
259
  );
260
260
 
261
+ /** @type {string} */
261
262
  let amdFactory;
262
263
  if (optionalExternals.length > 0) {
263
264
  const wrapperArguments = externalsArguments(requiredExternals);
@@ -99,6 +99,9 @@ module.exports = ({ level = "info", debug = false, console }) => {
99
99
  * @returns {void}
100
100
  */
101
101
  const logger = (name, type, args) => {
102
+ /**
103
+ * @returns {[string?, ...EXPECTED_ANY]} labeled args
104
+ */
102
105
  const labeledArgs = () => {
103
106
  if (Array.isArray(args)) {
104
107
  if (args.length > 0 && typeof args[0] === "string") {
@@ -16,7 +16,7 @@ const arraySum = (array) => {
16
16
  };
17
17
 
18
18
  /**
19
- * @param {EXPECTED_ANY[]} args items to be truncated
19
+ * @param {string[]} args items to be truncated
20
20
  * @param {number} maxLength maximum length of args including spaces between
21
21
  * @returns {string[]} truncated args
22
22
  */
@@ -57,6 +57,7 @@ class CommonJsChunkLoadingPlugin {
57
57
  : globalChunkLoading;
58
58
  return chunkLoading === chunkLoadingValue;
59
59
  };
60
+ /** @type {WeakSet<Chunk>} */
60
61
  const onceForChunkSet = new WeakSet();
61
62
  /**
62
63
  * @param {Chunk} chunk chunk
@@ -77,6 +77,7 @@ class NodeTargetPlugin {
77
77
  * @param {ExternalsType} type default external type
78
78
  */
79
79
  constructor(type = "node-commonjs") {
80
+ /** @type {ExternalsType} */
80
81
  this.type = type;
81
82
  }
82
83
 
@@ -8,6 +8,7 @@
8
8
  const util = require("util");
9
9
  const Watchpack = require("watchpack");
10
10
 
11
+ /** @typedef {import("watchpack").TimeInfoEntries} TimeInfoEntries */
11
12
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
12
13
  /** @typedef {import("../util/fs").WatchMethod} WatchMethod */
13
14
  /** @typedef {import("../util/fs").Changes} Changes */
@@ -65,7 +66,9 @@ class NodeWatchFileSystem {
65
66
  }
66
67
 
67
68
  const fetchTimeInfo = () => {
69
+ /** @type {TimeInfoEntries} */
68
70
  const fileTimeInfoEntries = new Map();
71
+ /** @type {TimeInfoEntries} */
69
72
  const contextTimeInfoEntries = new Map();
70
73
  if (this.watcher) {
71
74
  this.watcher.collectTimeInfoEntries(
@@ -67,10 +67,11 @@ module.exports = ({ colors, appendOnly, stream }) => {
67
67
  };
68
68
 
69
69
  /**
70
+ * @template T
70
71
  * @param {string} prefix prefix
71
72
  * @param {string} colorPrefix color prefix
72
73
  * @param {string} colorSuffix color suffix
73
- * @returns {(...args: EXPECTED_ANY[]) => void} function to write with colors
74
+ * @returns {(...args: T[]) => void} function to write with colors
74
75
  */
75
76
  const writeColored =
76
77
  (prefix, colorPrefix, colorSuffix) =>
@@ -87,12 +88,14 @@ module.exports = ({ colors, appendOnly, stream }) => {
87
88
  writeStatusMessage();
88
89
  };
89
90
 
91
+ /** @type {<T extends unknown[]>(...args: T) => void} */
90
92
  const writeGroupMessage = writeColored(
91
93
  "<-> ",
92
94
  "\u001B[1m\u001B[36m",
93
95
  "\u001B[39m\u001B[22m"
94
96
  );
95
97
 
98
+ /** @type {<T extends unknown[]>(...args: T) => void} */
96
99
  const writeGroupCollapsedMessage = writeColored(
97
100
  "<+> ",
98
101
  "\u001B[1m\u001B[36m",
@@ -100,17 +103,25 @@ module.exports = ({ colors, appendOnly, stream }) => {
100
103
  );
101
104
 
102
105
  return {
106
+ /** @type {LoggerConsole["log"]} */
103
107
  log: writeColored(" ", "\u001B[1m", "\u001B[22m"),
108
+ /** @type {LoggerConsole["debug"]} */
104
109
  debug: writeColored(" ", "", ""),
110
+ /** @type {LoggerConsole["trace"]} */
105
111
  trace: writeColored(" ", "", ""),
112
+ /** @type {LoggerConsole["info"]} */
106
113
  info: writeColored("<i> ", "\u001B[1m\u001B[32m", "\u001B[39m\u001B[22m"),
114
+ /** @type {LoggerConsole["warn"]} */
107
115
  warn: writeColored("<w> ", "\u001B[1m\u001B[33m", "\u001B[39m\u001B[22m"),
116
+ /** @type {LoggerConsole["error"]} */
108
117
  error: writeColored("<e> ", "\u001B[1m\u001B[31m", "\u001B[39m\u001B[22m"),
118
+ /** @type {LoggerConsole["logTime"]} */
109
119
  logTime: writeColored(
110
120
  "<t> ",
111
121
  "\u001B[1m\u001B[35m",
112
122
  "\u001B[39m\u001B[22m"
113
123
  ),
124
+ /** @type {LoggerConsole["group"]} */
114
125
  group: (...args) => {
115
126
  writeGroupMessage(...args);
116
127
  if (currentCollapsed > 0) {
@@ -119,10 +130,12 @@ module.exports = ({ colors, appendOnly, stream }) => {
119
130
  currentIndent += " ";
120
131
  }
121
132
  },
133
+ /** @type {LoggerConsole["groupCollapsed"]} */
122
134
  groupCollapsed: (...args) => {
123
135
  writeGroupCollapsedMessage(...args);
124
136
  currentCollapsed++;
125
137
  },
138
+ /** @type {LoggerConsole["groupEnd"]} */
126
139
  groupEnd: () => {
127
140
  if (currentCollapsed > 0) {
128
141
  currentCollapsed--;
@@ -130,8 +143,11 @@ module.exports = ({ colors, appendOnly, stream }) => {
130
143
  currentIndent = currentIndent.slice(0, -2);
131
144
  }
132
145
  },
146
+ /** @type {LoggerConsole["profile"]} */
133
147
  profile: console.profile && ((name) => console.profile(name)),
148
+ /** @type {LoggerConsole["profileEnd"]} */
134
149
  profileEnd: console.profileEnd && ((name) => console.profileEnd(name)),
150
+ /** @type {LoggerConsole["clear"]} */
135
151
  clear:
136
152
  /** @type {() => void} */
137
153
  (
@@ -143,6 +159,7 @@ module.exports = ({ colors, appendOnly, stream }) => {
143
159
  writeStatusMessage();
144
160
  })
145
161
  ),
162
+ /** @type {LoggerConsole["status"]} */
146
163
  status: appendOnly
147
164
  ? writeColored("<s> ", "", "")
148
165
  : (name, ...args) => {
@@ -30,6 +30,7 @@ class AggressiveMergingPlugin {
30
30
  "Argument should be an options object. To use defaults, pass in nothing.\nFor more info on options, see https://webpack.js.org/plugins/"
31
31
  );
32
32
  }
33
+ /** @type {AggressiveMergingPluginOptions} */
33
34
  this.options = options || {};
34
35
  }
35
36
 
@@ -50,7 +51,7 @@ class AggressiveMergingPlugin {
50
51
  },
51
52
  (chunks) => {
52
53
  const chunkGraph = compilation.chunkGraph;
53
- /** @type {{a: Chunk, b: Chunk, improvement: number}[]} */
54
+ /** @type {{ a: Chunk, b: Chunk, improvement: number }[]} */
54
55
  const combinations = [];
55
56
  for (const a of chunks) {
56
57
  if (a.canBeInitial()) continue;
@@ -50,7 +50,7 @@ const moveModuleBetween = (chunkGraph, oldChunk, newChunk) => (module) => {
50
50
  const isNotAEntryModule = (chunkGraph, chunk) => (module) =>
51
51
  !chunkGraph.isEntryModuleInChunk(module, chunk);
52
52
 
53
- /** @typedef {{ id?: NonNullable<Chunk["id"]>, hash?: NonNullable<Chunk["hash"]>, modules: Module[], size: number }} SplitData */
53
+ /** @typedef {{ id?: NonNullable<Chunk["id"]>, hash?: NonNullable<Chunk["hash"]>, modules: string[], size: number }} SplitData */
54
54
 
55
55
  /** @type {WeakSet<Chunk>} */
56
56
  const recordedChunks = new WeakSet();
@@ -114,7 +114,9 @@ class AggressiveSplittingPlugin {
114
114
  (chunks) => {
115
115
  const chunkGraph = compilation.chunkGraph;
116
116
  // Precompute stuff
117
+ /** @type {Map<string, Module>} */
117
118
  const nameToModuleMap = new Map();
119
+ /** @type {Map<Module, string>} */
118
120
  const moduleToNameMap = new Map();
119
121
  const makePathsRelative =
120
122
  identifierUtils.makePathsRelative.bindContextCache(
@@ -128,10 +130,10 @@ class AggressiveSplittingPlugin {
128
130
  }
129
131
 
130
132
  // Check used chunk ids
131
- /** @typedef {Set<ChunkId>} */
133
+ /** @type {Set<ChunkId>} */
132
134
  const usedIds = new Set();
133
135
  for (const chunk of chunks) {
134
- usedIds.add(chunk.id);
136
+ usedIds.add(/** @type {ChunkId} */ (chunk.id));
135
137
  }
136
138
 
137
139
  const recordedSplits =
@@ -154,8 +156,8 @@ class AggressiveSplittingPlugin {
154
156
  }
155
157
 
156
158
  // Get module objects from names
157
- const selectedModules = splitData.modules.map((name) =>
158
- nameToModuleMap.get(name)
159
+ const selectedModules = splitData.modules.map(
160
+ (name) => /** @type {Module} */ (nameToModuleMap.get(name))
159
161
  );
160
162
 
161
163
  // Does the modules exist at all?
@@ -240,6 +242,7 @@ class AggressiveSplittingPlugin {
240
242
  const modules = chunkGraph
241
243
  .getOrderedChunkModules(chunk, compareModulesByIdentifier)
242
244
  .filter(isNotAEntryModule(chunkGraph, chunk));
245
+ /** @type {Module[]} */
243
246
  const selectedModules = [];
244
247
  let selectedModulesSize = 0;
245
248
  for (let k = 0; k < modules.length; k++) {
@@ -255,7 +258,7 @@ class AggressiveSplittingPlugin {
255
258
  /** @type {SplitData} */
256
259
  const splitData = {
257
260
  modules: selectedModules
258
- .map((m) => moduleToNameMap.get(m))
261
+ .map((m) => /** @type {string} */ (moduleToNameMap.get(m)))
259
262
  .sort(),
260
263
  size: selectedModulesSize
261
264
  };
@@ -271,6 +274,7 @@ class AggressiveSplittingPlugin {
271
274
  );
272
275
  compilation.hooks.recordHash.tap(PLUGIN_NAME, (records) => {
273
276
  // 4. save made splittings to records
277
+ /** @type {Set<SplitData>} */
274
278
  const allSplits = new Set();
275
279
  /** @type {Set<SplitData>} */
276
280
  const invalidSplits = new Set();