@depup/webpack 5.110.3-depup.0 → 5.111.1-depup.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 (283) hide show
  1. package/README.md +7 -8
  2. package/changes.json +7 -11
  3. package/lib/APIPlugin.js +26 -11
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/Cache.js +8 -3
  6. package/lib/CacheFacade.js +1 -1
  7. package/lib/CircularModulesPlugin.js +157 -55
  8. package/lib/CleanPlugin.js +2 -2
  9. package/lib/CompatibilityPlugin.js +3 -4
  10. package/lib/Compilation.js +336 -337
  11. package/lib/Compiler.js +213 -51
  12. package/lib/ConstPlugin.js +16 -132
  13. package/lib/CopyPlugin.js +1054 -0
  14. package/lib/DefinePlugin.js +24 -8
  15. package/lib/DependencyTemplate.js +2 -1
  16. package/lib/DotenvPlugin.js +24 -28
  17. package/lib/ErrorHelpers.js +113 -0
  18. package/lib/ExportsInfo.js +20 -16
  19. package/lib/ExternalModule.js +47 -22
  20. package/lib/FileSystemInfo.js +17 -14
  21. package/lib/FlagDependencyExportsPlugin.js +53 -34
  22. package/lib/FlagDependencyUsagePlugin.js +9 -13
  23. package/lib/Generator.js +24 -2
  24. package/lib/HotModuleReplacementPlugin.js +55 -7
  25. package/lib/IgnorePlugin.js +1 -1
  26. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  27. package/lib/LoaderOptionsPlugin.js +1 -1
  28. package/lib/MainTemplate.js +5 -1
  29. package/lib/Module.js +19 -10
  30. package/lib/ModuleGraph.js +6 -9
  31. package/lib/MultiCompiler.js +7 -17
  32. package/lib/MultiWatching.js +1 -1
  33. package/lib/NormalModule.js +135 -50
  34. package/lib/NormalModuleFactory.js +1 -1
  35. package/lib/RuntimeGlobals.js +21 -7
  36. package/lib/RuntimeModule.js +28 -12
  37. package/lib/RuntimePlugin.js +30 -3
  38. package/lib/RuntimeTemplate.js +813 -518
  39. package/lib/SourceMapDevToolPlugin.js +54 -104
  40. package/lib/TemplatedPathPlugin.js +16 -59
  41. package/lib/Watching.js +9 -0
  42. package/lib/WebpackOptionsApply.js +84 -91
  43. package/lib/asset/AssetBytesGenerator.js +7 -1
  44. package/lib/asset/AssetGenerator.js +50 -24
  45. package/lib/asset/AssetModule.js +3 -0
  46. package/lib/asset/AssetSourceGenerator.js +7 -1
  47. package/lib/asset/WebManifestParser.js +7 -5
  48. package/lib/buildChunkGraph.js +11 -15
  49. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  50. package/lib/cache/IdleFileCachePlugin.js +2 -2
  51. package/lib/cache/MemoryCachePlugin.js +4 -4
  52. package/lib/cache/MemoryWithGcCachePlugin.js +7 -8
  53. package/lib/cache/PackFileCacheStrategy.js +17 -19
  54. package/lib/cache/getLazyHashedEtag.js +3 -5
  55. package/lib/config/browserslistTargetHandler.js +17 -4
  56. package/lib/config/defaults.js +138 -128
  57. package/lib/config/getClaimedAssetTypes.js +10 -11
  58. package/lib/config/normalization.js +82 -12
  59. package/lib/config/target.js +13 -4
  60. package/lib/container/ContainerReferencePlugin.js +6 -0
  61. package/lib/container/RemoteRuntimeModule.js +9 -0
  62. package/lib/container/declaredRemotes.js +39 -0
  63. package/lib/{ContextExclusionPlugin.js → context/ContextExclusionPlugin.js} +1 -1
  64. package/lib/{ContextModule.js → context/ContextModule.js} +54 -115
  65. package/lib/{ContextModuleFactory.js → context/ContextModuleFactory.js} +19 -21
  66. package/lib/{ContextReplacementPlugin.js → context/ContextReplacementPlugin.js} +4 -4
  67. package/lib/css/CssGenerator.js +27 -11
  68. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  69. package/lib/css/CssLoadingRuntimeModule.js +94 -36
  70. package/lib/css/CssModule.js +1 -1
  71. package/lib/css/CssModulesPlugin.js +7 -6
  72. package/lib/css/CssParser.js +162 -31
  73. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  74. package/lib/css/cssMinify.js +43 -32
  75. package/lib/css/data.js +3514 -869
  76. package/lib/css/syntax.js +6370 -1220
  77. package/lib/debug/ProfilingPlugin.js +7 -4
  78. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  79. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  80. package/lib/dependencies/CommonJsExportRequireDependency.js +13 -12
  81. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  82. package/lib/dependencies/CommonJsImportsParserPlugin.js +5 -5
  83. package/lib/dependencies/CommonJsPlugin.js +19 -3
  84. package/lib/dependencies/CommonJsRequireDependency.js +14 -5
  85. package/lib/dependencies/CommonJsSelfReferenceDependency.js +2 -4
  86. package/lib/dependencies/ContextDependency.js +1 -1
  87. package/lib/dependencies/ContextDependencyHelpers.js +3 -9
  88. package/lib/dependencies/ContextElementDependency.js +1 -1
  89. package/lib/dependencies/CssIcssExportDependency.js +13 -9
  90. package/lib/dependencies/CssIcssImportDependency.js +3 -6
  91. package/lib/dependencies/CssUrlDependency.js +3 -5
  92. package/lib/dependencies/HarmonyCompatibilityDependency.js +67 -22
  93. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -4
  94. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +10 -7
  95. package/lib/dependencies/HarmonyExportExpressionDependency.js +47 -33
  96. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +74 -17
  97. package/lib/dependencies/HarmonyExportInitFragment.js +110 -23
  98. package/lib/dependencies/HarmonyExportSpecifierDependency.js +25 -58
  99. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  100. package/lib/dependencies/HarmonyImportDependency.js +6 -1
  101. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +111 -17
  102. package/lib/dependencies/HarmonyImportSideEffectDependency.js +3 -4
  103. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -3
  104. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  105. package/lib/dependencies/HtmlEntryDependency.js +124 -102
  106. package/lib/dependencies/HtmlInlineScriptDependency.js +3 -4
  107. package/lib/dependencies/HtmlInlineStyleDependency.js +3 -4
  108. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  109. package/lib/dependencies/ImportMetaGlobHelpers.js +1 -1
  110. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  111. package/lib/dependencies/ImportMetaPlugin.js +67 -25
  112. package/lib/dependencies/ImportParserPlugin.js +1 -1
  113. package/lib/dependencies/LoaderPlugin.js +26 -1
  114. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  115. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  116. package/lib/dependencies/URLContextDependency.js +1 -1
  117. package/lib/dependencies/URLDependency.js +6 -5
  118. package/lib/dependencies/WorkerAndWorkletPlugin.js +15 -21
  119. package/lib/dependencies/WorkerDependency.js +7 -7
  120. package/lib/dependencies/WorkletDependency.js +7 -11
  121. package/lib/dll/DelegatedModule.js +18 -1
  122. package/lib/dll/DllReferencePlugin.js +11 -8
  123. package/lib/dll/LibManifestPlugin.js +1 -1
  124. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  125. package/lib/errors/DuplicateModulesWarning.js +12 -7
  126. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  127. package/lib/errors/ExternalStarReexportError.js +44 -0
  128. package/lib/errors/HookWebpackError.js +3 -2
  129. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  130. package/lib/errors/ModuleParseError.js +2 -1
  131. package/lib/errors/UnusedAssetsWarning.js +36 -0
  132. package/lib/errors/UnusedFederationWarning.js +35 -0
  133. package/lib/errors/UnusedModulesWarning.js +38 -0
  134. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  135. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  136. package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
  137. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
  138. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  139. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  140. package/lib/hmr/LazyCompilationPlugin.js +3 -5
  141. package/lib/html/HtmlGenerator.js +72 -87
  142. package/lib/html/HtmlModulesPlugin.js +418 -200
  143. package/lib/html/HtmlParser.js +110 -147
  144. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  145. package/lib/html/data.js +142 -7
  146. package/lib/html/htmlMinify.js +92 -122
  147. package/lib/html/syntax.js +1618 -1391
  148. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  149. package/lib/index.js +49 -3
  150. package/lib/javascript/ChunkFormatHelpers.js +4 -3
  151. package/lib/javascript/JavascriptGenerator.js +8 -1
  152. package/lib/javascript/JavascriptModule.js +1 -0
  153. package/lib/javascript/JavascriptModulesPlugin.js +73 -72
  154. package/lib/javascript/JavascriptParser.js +1970 -900
  155. package/lib/javascript/StartupHelpers.js +27 -3
  156. package/lib/javascript/data.js +172 -0
  157. package/lib/javascript/grammar.js +5546 -0
  158. package/lib/javascript/parser.js +1500 -0
  159. package/lib/javascript/regexp.js +1762 -0
  160. package/lib/javascript/regexpData.js +51 -0
  161. package/lib/javascript/syntax.js +9061 -5262
  162. package/lib/json/JsonGenerator.js +7 -1
  163. package/lib/library/ModuleLibraryPlugin.js +171 -132
  164. package/lib/loaders/LoaderRunner.js +137 -9
  165. package/lib/node/NodeWatchFileSystem.js +3 -9
  166. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  167. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  168. package/lib/optimize/AggressiveMergingPlugin.js +3 -5
  169. package/lib/optimize/ConcatenatedModule.js +178 -120
  170. package/lib/optimize/ConstExportsPlugin.js +50 -39
  171. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -11
  172. package/lib/optimize/InlineExports.js +20 -123
  173. package/lib/optimize/InnerGraphPlugin.js +7 -13
  174. package/lib/optimize/LimitChunkCountPlugin.js +5 -8
  175. package/lib/optimize/MangleExportsPlugin.js +13 -4
  176. package/lib/optimize/ModuleConcatenationPlugin.js +27 -5
  177. package/lib/optimize/RealContentHashPlugin.js +68 -9
  178. package/lib/optimize/SideEffectsFlagPlugin.js +24 -28
  179. package/lib/optimize/SplitChunksPlugin.js +2 -4
  180. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  181. package/lib/performance/BroadContextsPlugin.js +1 -1
  182. package/lib/performance/CacheEffectivenessPlugin.js +7 -7
  183. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  184. package/lib/performance/EvalUsagePlugin.js +5 -2
  185. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  186. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  187. package/lib/performance/SizeLimitsPlugin.js +2 -4
  188. package/lib/performance/TopLevelThisPlugin.js +5 -4
  189. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  190. package/lib/performance/UnusedFederationPlugin.js +147 -0
  191. package/lib/performance/UnusedModulesPlugin.js +141 -0
  192. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  193. package/lib/performance/isOnlyReexported.js +65 -0
  194. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  195. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +8 -8
  196. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  197. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  198. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  199. package/lib/prefetch/ResourceHintPlugin.js +18 -23
  200. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  201. package/lib/prefetch/StartupAssetHintRuntimeModule.js +16 -10
  202. package/lib/rules/RuleSetCompiler.js +211 -4
  203. package/lib/runtime/AsyncModuleRuntimeModule.js +98 -66
  204. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  205. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  206. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  207. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  208. package/lib/runtime/GetChunkFilenameRuntimeModule.js +12 -4
  209. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  210. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  211. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  212. package/lib/runtime/GlobalRuntimeModule.js +11 -4
  213. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  214. package/lib/runtime/HelperRuntimeModule.js +10 -0
  215. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +305 -224
  216. package/lib/runtime/NonceRuntimeModule.js +9 -0
  217. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  218. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  219. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  220. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  221. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  222. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  223. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  224. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  225. package/lib/schemes/DataUriPlugin.js +3 -6
  226. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  227. package/lib/serialization/BinaryMiddleware.js +9 -9
  228. package/lib/serialization/FileMiddleware.js +16 -16
  229. package/lib/serialization/ObjectMiddleware.js +168 -139
  230. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  231. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  232. package/lib/sharing/ShareRuntimeModule.js +9 -0
  233. package/lib/sharing/declaredShared.js +47 -0
  234. package/lib/stats/DefaultStatsFactoryPlugin.js +6 -5
  235. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  236. package/lib/typescript/TypeScriptPlugin.js +2 -3
  237. package/lib/url/URLParserPlugin.js +6 -8
  238. package/lib/util/LocConverter.js +4 -7
  239. package/lib/util/SourceProcessor.js +91 -91
  240. package/lib/util/async.js +292 -0
  241. package/lib/util/buildDiagnostics.js +69 -0
  242. package/lib/util/chainedImports.js +3 -4
  243. package/lib/util/concatenate.js +4 -4
  244. package/lib/util/createHooksRegistry.js +1 -2
  245. package/lib/util/dataURL.js +2 -3
  246. package/lib/util/deterministicGrouping.js +8 -13
  247. package/lib/util/findGraphRoots.js +6 -13
  248. package/lib/util/fs.js +27 -1
  249. package/lib/util/globUtils.js +1 -1
  250. package/lib/util/handlerKeys.js +40 -0
  251. package/lib/util/hash/wasm-hash.js +3 -4
  252. package/lib/util/identifier.js +20 -0
  253. package/lib/util/internalSerializables.js +5 -1
  254. package/lib/util/registerExternalSerializer.js +6 -45
  255. package/lib/util/semver.js +5 -3
  256. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
  257. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  258. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +6 -1
  259. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -1
  260. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +12 -4
  261. package/lib/wasm-sync/WebAssemblyGenerator.js +6 -1
  262. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -1
  263. package/lib/wasm-sync/WebAssemblyUtils.js +2 -4
  264. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  265. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  266. package/package.json +55 -46
  267. package/schemas/WebpackOptions.check.js +1 -1
  268. package/schemas/WebpackOptions.json +379 -66
  269. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  270. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  271. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  272. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  273. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  274. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  275. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  276. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  277. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  278. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  279. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  280. package/types.d.ts +1723 -604
  281. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  282. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  283. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const CircularModulesPlugin = require("../CircularModulesPlugin");
8
9
  const { UsageState } = require("../ExportsInfo");
9
10
  const {
10
11
  JAVASCRIPT_MODULE_TYPE_AUTO,
@@ -15,10 +16,11 @@ const { VariableInfoFlags } = require("../javascript/JavascriptParser");
15
16
  const {
16
17
  InlinedUsedName,
17
18
  enableInlineExports,
18
- findModulesInCycles,
19
19
  toInlinedValue
20
20
  } = require("./InlineExports");
21
21
 
22
+ const { CircularKind } = CircularModulesPlugin;
23
+
22
24
  /** @import { InlinedValue } from "./InlineExports" */
23
25
  /** @import Compiler from "../Compiler" */
24
26
  /** @import ExportsInfo from "../ExportsInfo" */
@@ -162,54 +164,63 @@ class ConstExportsPlugin {
162
164
  enableInlineExports(compilation.moduleGraph);
163
165
 
164
166
  const moduleGraph = compilation.moduleGraph;
165
- compilation.hooks.optimizeDependencies.tap(PLUGIN_NAME, (modules) => {
166
- // A cycle peer may read an export during its temporal dead zone,
167
- // where the binding must throw and a literal would answer.
168
- const inCycle = findModulesInCycles(moduleGraph, modules);
169
- /** @type {Set<ExportsInfo>} */
170
- const visited = new Set();
171
- /** @type {ExportsInfo[]} */
172
- let queue = [];
173
- for (const module of modules) {
174
- if (inCycle.has(module)) continue;
175
- queue.push(moduleGraph.getExportsInfo(module));
176
- }
177
- while (queue.length > 0) {
178
- const items = queue;
179
- queue = [];
180
- for (const exportsInfo of items) {
181
- if (visited.has(exportsInfo)) continue;
182
- visited.add(exportsInfo);
183
- // Other-export usage means we can't safely inline (some non-statically-known consumer)
167
+ // After CircularModulesPlugin (STAGE_DETECT): needs Binding kind flags.
168
+ compilation.hooks.optimizeDependencies.tap(
169
+ {
170
+ name: PLUGIN_NAME,
171
+ stage: CircularModulesPlugin.STAGE_DETECT + 1
172
+ },
173
+ (modules) => {
174
+ /** @type {Set<ExportsInfo>} */
175
+ const visited = new Set();
176
+ /** @type {ExportsInfo[]} */
177
+ let queue = [];
178
+ for (const module of modules) {
179
+ // Binding-observable cycle peers must keep TDZ live bindings.
184
180
  if (
185
- exportsInfo.otherExportsInfo.getUsed(undefined) !==
186
- UsageState.Unused
181
+ CircularModulesPlugin.isCircular(module, CircularKind.Binding)
187
182
  ) {
188
183
  continue;
189
184
  }
190
- for (const exportInfo of exportsInfo.ownedExports) {
191
- const inlined = exportInfo.canInline();
192
- const doInline =
193
- !exportInfo.hasUsedName() &&
194
- inlined !== undefined &&
195
- exportInfo.provided === true;
196
- if (doInline) {
197
- exportInfo.setUsedName(new InlinedUsedName(inlined));
198
- exportsInfo.markInlinedExports();
185
+ queue.push(moduleGraph.getExportsInfo(module));
186
+ }
187
+ while (queue.length > 0) {
188
+ const items = queue;
189
+ queue = [];
190
+ for (const exportsInfo of items) {
191
+ if (visited.has(exportsInfo)) continue;
192
+ visited.add(exportsInfo);
193
+ // Other-export usage means we can't safely inline (some non-statically-known consumer)
194
+ if (
195
+ exportsInfo.otherExportsInfo.getUsed(undefined) !==
196
+ UsageState.Unused
197
+ ) {
198
+ continue;
199
199
  }
200
- if (exportInfo.exportsInfoOwned && exportInfo.exportsInfo) {
201
- const used = exportInfo.getUsed(undefined);
202
- if (
203
- used === UsageState.OnlyPropertiesUsed ||
204
- used === UsageState.Unused
205
- ) {
206
- queue.push(exportInfo.exportsInfo);
200
+ for (const exportInfo of exportsInfo.ownedExports) {
201
+ const inlined = exportInfo.canInline();
202
+ const doInline =
203
+ !exportInfo.hasUsedName() &&
204
+ inlined !== undefined &&
205
+ exportInfo.provided === true;
206
+ if (doInline) {
207
+ exportInfo.setUsedName(new InlinedUsedName(inlined));
208
+ exportsInfo.markInlinedExports();
209
+ }
210
+ if (exportInfo.exportsInfoOwned && exportInfo.exportsInfo) {
211
+ const used = exportInfo.getUsed(undefined);
212
+ if (
213
+ used === UsageState.OnlyPropertiesUsed ||
214
+ used === UsageState.Unused
215
+ ) {
216
+ queue.push(exportInfo.exportsInfo);
217
+ }
207
218
  }
208
219
  }
209
220
  }
210
221
  }
211
222
  }
212
- });
223
+ );
213
224
  }
214
225
  );
215
226
  }
@@ -24,17 +24,9 @@ class FlagIncludedChunksPlugin {
24
24
  compilation.hooks.optimizeChunkIds.tap(PLUGIN_NAME, (chunks) => {
25
25
  const chunkGraph = compilation.chunkGraph;
26
26
 
27
- // prepare two bit integers for each module
28
- // 2^31 is the max number represented as SMI in v8
29
- // we want the bits distributed this way:
30
- // the bit 2^31 is pretty rar and only one module should get it
31
- // so it has a probability of 1 / modulesCount
32
- // the first bit (2^0) is the easiest and every module could get it
33
- // if it doesn't get a better bit
34
- // from bit 2^n to 2^(n+1) there is a probability of p
35
- // so 1 / modulesCount == p^31
36
- // <=> p = sqrt31(1 / modulesCount)
37
- // so we use a modulo of 1 / sqrt31(1 / modulesCount)
27
+ // Two bit integers per module, within v8's 2^31 SMI range. The bits are
28
+ // spread so 2^31 falls to about one module in `modulesCount` and 2^0 to
29
+ // any module missing a better one, which gives the modulo below.
38
30
  /** @type {WeakMap<Module, number>} */
39
31
  const moduleBits = new WeakMap();
40
32
  const modulesCount = compilation.modules.size;
@@ -17,6 +17,7 @@ const { propertyAccess } = require("../util/property");
17
17
  /** @import ModuleGraph from "../ModuleGraph" */
18
18
  /** @import Module from "../Module" */
19
19
  /** @import { RuntimeSpec } from "../util/runtime" */
20
+ /** @import Hash from "../util/Hash" */
20
21
 
21
22
  const MAX_INLINE_BYTES = 6;
22
23
 
@@ -60,6 +61,14 @@ class InlinedValue {
60
61
  return `(${comment}${this.renderLiteral()})`;
61
62
  }
62
63
 
64
+ /**
65
+ * @param {InlinedValue} other other inlined value
66
+ * @returns {boolean} true when kind and value match
67
+ */
68
+ equals(other) {
69
+ return this.kind === other.kind && this.value === other.value;
70
+ }
71
+
63
72
  /**
64
73
  * @param {ObjectSerializerContext} context context
65
74
  */
@@ -96,12 +105,21 @@ class InlinedUsedName {
96
105
  }
97
106
 
98
107
  /**
99
- * @param {string} comment leading comment text
108
+ * @param {string=} comment leading comment text
100
109
  * @returns {string} rendered literal with property access suffix
101
110
  */
102
- render(comment) {
111
+ render(comment = "") {
103
112
  return this.value.render(comment) + propertyAccess(this.suffix);
104
113
  }
114
+
115
+ /**
116
+ * Updates the hash with the data contributed by this instance.
117
+ * @param {Hash} hash the hash used to track dependencies
118
+ * @returns {void}
119
+ */
120
+ updateHash(hash) {
121
+ hash.update(this.render());
122
+ }
105
123
  }
106
124
 
107
125
  /**
@@ -172,131 +190,10 @@ const isExportInlined = (moduleGraph, module, ids, runtime) => {
172
190
  return moduleGraph.getExportsInfo(module).hasInlinedUsedName(ids, runtime);
173
191
  };
174
192
 
175
- /**
176
- * Collects, by an iterative Tarjan pass, the modules a cycle peer may read in
177
- * their dead zone. A cycle of bare side-effect imports still inlines.
178
- * @param {ModuleGraph} moduleGraph module graph
179
- * @param {Iterable<Module>} modules all modules of the compilation
180
- * @returns {Set<Module>} modules whose exports must not be inlined
181
- */
182
- const findModulesInCycles = (moduleGraph, modules) => {
183
- const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
184
- const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
185
-
186
- /** @type {Set<Module>} */
187
- const inCycle = new Set();
188
- /** @type {[Module, Module][]} */
189
- const bindingReads = [];
190
- /** @type {Map<Module, number>} */
191
- const componentOf = new Map();
192
- let nextComponent = 0;
193
- /** @type {Map<Module, number>} */
194
- const index = new Map();
195
- /** @type {Map<Module, number>} */
196
- const low = new Map();
197
- /** @type {Set<Module>} */
198
- const onStack = new Set();
199
- /** @type {Module[]} */
200
- const componentStack = [];
201
- let counter = 0;
202
- /**
203
- * @param {Module} module the module
204
- * @returns {Module[]} modules it imports, self included when self-importing
205
- */
206
- const targetsOf = (module) => {
207
- const connections = moduleGraph.getOutgoingConnectionsByModule(module);
208
- if (!connections) return [];
209
- /** @type {Module[]} */
210
- const targets = [];
211
- for (const [target, moduleConnections] of connections) {
212
- if (
213
- !target ||
214
- !moduleConnections.some(
215
- (c) => c.dependency instanceof HarmonyImportDependency
216
- )
217
- ) {
218
- continue;
219
- }
220
- // Anything but a bare side-effect import may observe the binding.
221
- if (
222
- moduleConnections.some(
223
- (c) =>
224
- c.dependency instanceof HarmonyImportDependency &&
225
- !(c.dependency instanceof HarmonyImportSideEffectDependency)
226
- )
227
- ) {
228
- bindingReads.push([module, target]);
229
- }
230
- targets.push(target);
231
- }
232
- return targets;
233
- };
234
- /** @type {{ node: Module, targets: Module[], i: number }[]} */
235
- const work = [];
236
- /**
237
- * @param {Module} node node to open
238
- */
239
- const open = (node) => {
240
- index.set(node, counter);
241
- low.set(node, counter);
242
- counter++;
243
- componentStack.push(node);
244
- onStack.add(node);
245
- work.push({ node, targets: targetsOf(node), i: 0 });
246
- };
247
- for (const seed of modules) {
248
- if (index.has(seed)) continue;
249
- open(seed);
250
- while (work.length > 0) {
251
- const frame = work[work.length - 1];
252
- if (frame.i < frame.targets.length) {
253
- const next = frame.targets[frame.i++];
254
- if (!index.has(next)) {
255
- open(next);
256
- } else if (onStack.has(next)) {
257
- const nodeLow = /** @type {number} */ (low.get(frame.node));
258
- const nextIndex = /** @type {number} */ (index.get(next));
259
- if (nextIndex < nodeLow) low.set(frame.node, nextIndex);
260
- }
261
- continue;
262
- }
263
- work.pop();
264
- const node = frame.node;
265
- const nodeLow = /** @type {number} */ (low.get(node));
266
- if (work.length > 0) {
267
- const parent = work[work.length - 1].node;
268
- if (nodeLow < /** @type {number} */ (low.get(parent))) {
269
- low.set(parent, nodeLow);
270
- }
271
- }
272
- if (nodeLow === index.get(node)) {
273
- const id = nextComponent++;
274
- let member;
275
- do {
276
- member = /** @type {Module} */ (componentStack.pop());
277
- onStack.delete(member);
278
- componentOf.set(member, id);
279
- } while (member !== node);
280
- }
281
- }
282
- }
283
- // Reader and target evaluate together exactly when they share a component.
284
- for (const [origin, target] of bindingReads) {
285
- if (
286
- origin === target ||
287
- componentOf.get(origin) === componentOf.get(target)
288
- ) {
289
- inCycle.add(target);
290
- }
291
- }
292
- return inCycle;
293
- };
294
-
295
193
  module.exports.InlinedUsedName = InlinedUsedName;
296
194
  module.exports.InlinedValue = InlinedValue;
297
195
  module.exports.MAX_INLINE_BYTES = MAX_INLINE_BYTES;
298
196
  module.exports.enableInlineExports = enableInlineExports;
299
- module.exports.findModulesInCycles = findModulesInCycles;
300
197
  module.exports.isExportInlined = isExportInlined;
301
198
  module.exports.isInlineEnabled = isInlineEnabled;
302
199
  module.exports.isInlineExportsEnabled = isInlineExportsEnabled;
@@ -122,10 +122,8 @@ class InnerGraphPlugin {
122
122
  // nodes that have a TopLevelSymbol assigned and
123
123
  // variables are tagged with the assigned TopLevelSymbol
124
124
 
125
- // We differ 3 types of nodes:
126
- // 1. full statements (export default, function declaration)
127
- // 2. classes (class declaration, class expression)
128
- // 3. variable declarators (const x = ...)
125
+ // Three kinds of node carry a symbol: a full statement, a class, and a
126
+ // variable declarator.
129
127
 
130
128
  /** @type {WeakMap<Node | MaybeNamedFunctionDeclaration | MaybeNamedClassDeclaration, TopLevelSymbol>} */
131
129
  let statementWithTopLevelSymbol = new WeakMap();
@@ -360,16 +358,12 @@ class InnerGraphPlugin {
360
358
  // During real walking we set the TopLevelSymbol state to the assigned
361
359
  // TopLevelSymbol by using the fill datastructures.
362
360
 
363
- // In addition to tracking TopLevelSymbols, we sometimes need to
364
- // add a PureExpressionDependency. This is needed to skip execution
365
- // of pure expressions, even when they are not dropped due to
366
- // minimizing. Otherwise symbols used there might not exist anymore
367
- // as they are removed as unused by this optimization
361
+ // A `PureExpressionDependency` is sometimes added too, so a pure
362
+ // expression is skipped even where minimizing leaves it: the symbols it
363
+ // uses may have been removed as unused by this optimization.
368
364
 
369
- // When we find a reference to a TopLevelSymbol, we register a
370
- // TopLevelSymbol dependency from TopLevelSymbol in state to the
371
- // referenced TopLevelSymbol. This way we get a graph of all
372
- // TopLevelSymbols.
365
+ // A reference registers a dependency from the symbol in state to the one
366
+ // referenced, which is how the graph of all of them is built.
373
367
 
374
368
  // The following hooks are called during walking:
375
369
 
@@ -101,10 +101,8 @@ class LimitChunkCountPlugin {
101
101
  /** @type {Chunk[]} */
102
102
  const orderedChunks = [...chunks].sort(compareChunksWithGraph);
103
103
 
104
- // create a lazy sorted data structure to keep all combinations
105
- // this is large. Size = chunks * (chunks - 1) / 2
106
- // It uses a multi layer bucket sort plus normal sort in the last layer
107
- // It's also lazy so only accessed buckets are sorted
104
+ // All `chunks * (chunks - 1) / 2` combinations, held in a multi-layer
105
+ // bucket sort that sorts only the buckets actually reached.
108
106
  /** @type {LazyBucketSortedSet<ChunkCombination, number>} */
109
107
  const combinations = new LazyBucketSortedSet(
110
108
  // Layer 1: ordered by largest size benefit
@@ -214,10 +212,9 @@ class LimitChunkCountPlugin {
214
212
  for (const group of queue) {
215
213
  for (const mChunk of modifiedChunks) {
216
214
  if (mChunk !== a && mChunk !== b && mChunk.isInGroup(group)) {
217
- // This is a potential pair which needs recalculation
218
- // We can't do that now, but it merge before following pairs
219
- // so we leave space for it, and consider chunks as modified
220
- // just for the worse case
215
+ // A pair needing recalculation, which cannot happen now yet may
216
+ // merge before the ones that follow, so room is left for it and
217
+ // the chunks count as modified for the worst case.
221
218
  remainingChunksToMerge--;
222
219
  if (remainingChunksToMerge <= 0) break loop;
223
220
  modifiedChunks.add(a);
@@ -15,6 +15,7 @@ const { assignDeterministicIds } = require("../ids/IdHelpers");
15
15
  const { compareSelect, compareStringsNumeric } = require("../util/comparators");
16
16
 
17
17
  /** @import Compiler from "../Compiler" */
18
+ /** @import { BuildInfo } from "../Module" */
18
19
  /** @import ExportsInfo, { ExportInfo } from "../ExportsInfo" */
19
20
  /** @import { UsedNames } from "../util/concatenate" */
20
21
 
@@ -59,10 +60,9 @@ const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
59
60
  /** @type {InstanceType<ExportInfo>[]} */
60
61
  const mangleableExports = [];
61
62
 
62
- // Avoid to renamed exports that are not provided when
63
- // 1. it's not a namespace export: non-provided exports can be found in prototype chain
64
- // 2. there are other provided exports and deterministic mode is chosen:
65
- // non-provided exports would break the determinism
63
+ // A non-provided export is left unmangled outside a namespace export, where the
64
+ // prototype chain may still carry it, and under deterministic mode beside other
65
+ // provided exports, where it would break the determinism.
66
66
  let avoidMangleNonProvided = !isNamespace;
67
67
  if (!avoidMangleNonProvided && deterministic) {
68
68
  for (const exportInfo of exportsInfo.ownedExports) {
@@ -184,6 +184,15 @@ class MangleExportsPlugin {
184
184
  );
185
185
  }
186
186
  for (const module of modules) {
187
+ // A spec namespace reports the names the module exports, so a
188
+ // module handing one out cannot have them renamed.
189
+ if (
190
+ /** @type {BuildInfo} */
191
+ (module.buildInfo).specNamespaceObject
192
+ ) {
193
+ continue;
194
+ }
195
+
187
196
  const isNamespace =
188
197
  module.buildMeta && module.buildMeta.exportsType === "namespace";
189
198
  const exportsInfo = moduleGraph.getExportsInfo(module);
@@ -5,7 +5,6 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const asyncLib = require("neo-async");
9
8
  const ChunkGraph = require("../ChunkGraph");
10
9
  const Dependency = require("../Dependency");
11
10
  const Module = require("../Module");
@@ -14,6 +13,7 @@ const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
14
13
  const { STAGE_DEFAULT } = require("../OptimizationStages");
15
14
  const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
16
15
  const { ImportPhaseUtils } = require("../dependencies/ImportPhase");
16
+ const asyncLib = require("../util/async");
17
17
  const { compareModulesByIdentifier } = require("../util/comparators");
18
18
  const { isCommonJsConcatenationEnabled } = require("../util/concatenate");
19
19
  const {
@@ -28,6 +28,7 @@ const ConcatenatedModule = require("./ConcatenatedModule");
28
28
  /** @import Chunk from "../Chunk" */
29
29
  /** @import Compilation from "../Compilation" */
30
30
  /** @import Compiler from "../Compiler" */
31
+ /** @import { JavascriptModuleBuildInfo } from "../javascript/JavascriptModule" */
31
32
  /** @import { BuildInfo, BuildMeta } from "../Module" */
32
33
  /** @import RequestShortener from "../RequestShortener" */
33
34
  /** @import { RuntimeSpec } from "../util/runtime" */
@@ -235,6 +236,19 @@ class ModuleConcatenationPlugin {
235
236
  continue;
236
237
  }
237
238
 
239
+ // Concatenation materializes the namespace inline, which would
240
+ // silently drop the spec exotic object the module asked for.
241
+ if (
242
+ /** @type {BuildInfo} */
243
+ (module.buildInfo).specNamespaceObject
244
+ ) {
245
+ setBailoutReason(
246
+ module,
247
+ "Module hands out a spec namespace object"
248
+ );
249
+ continue;
250
+ }
251
+
238
252
  // Module must be in any chunk (we don't want to do useless work)
239
253
  if (chunkGraph.getNumberOfModuleChunks(module) === 0) {
240
254
  setBailoutReason(module, "Module is not in any chunk");
@@ -302,6 +316,15 @@ class ModuleConcatenationPlugin {
302
316
  canBeInner = false;
303
317
  }
304
318
 
319
+ // The root stands in for the whole concatenation, so an
320
+ // expression only an inner module can answer statically rules it out
321
+ if (
322
+ /** @type {JavascriptModuleBuildInfo} */
323
+ (module.buildInfo).moduleConcatenationRootBailout
324
+ ) {
325
+ canBeRoot = false;
326
+ }
327
+
305
328
  if (deferEnabled && moduleGraph.isDeferred(module)) {
306
329
  setInnerBailoutReason(module, "Module is deferred");
307
330
  canBeInner = false;
@@ -455,10 +478,9 @@ class ModuleConcatenationPlugin {
455
478
  logger.debug(
456
479
  `${statsCandidates} candidates were considered for adding (${stats.cached} cached failure, ${stats.alreadyInConfig} already in config, ${stats.invalidModule} invalid module, ${stats.incorrectChunks} incorrect chunks, ${stats.incorrectDependency} incorrect dependency, ${stats.incorrectChunksOfImporter} incorrect chunks of importer, ${stats.incorrectModuleDependency} incorrect module dependency, ${stats.incorrectRuntimeCondition} incorrect runtime condition, ${stats.importerFailed} importer failed, ${stats.added} added)`
457
480
  );
458
- // Create the largest configurations first: if a root also ended up inside
459
- // a bigger configuration, the bigger one wins (smaller skipped below).
460
- // Configurations can't be reused across roots: a module shared by several
461
- // chunks is concatenated into each consumer (module duplication).
481
+ // Largest configurations first, so a root that also landed inside a
482
+ // bigger one loses to it. None is reused across roots: a module shared by
483
+ // several chunks is concatenated into each consumer.
462
484
  logger.time("sort concat configurations");
463
485
  concatConfigurations.sort((a, b) => b.modules.size - a.modules.size);
464
486
  logger.timeEnd("sort concat configurations");
@@ -187,6 +187,7 @@ const createCompilationHooks = () => ({
187
187
  * @typedef {object} RealContentHashPluginOptions
188
188
  * @property {HashFunction} hashFunction the hash function to use
189
189
  * @property {HashDigest} hashDigest the hash digest to use
190
+ * @property {boolean=} onDemand run only where analyzable output marked a name for repair
190
191
  */
191
192
 
192
193
  const PLUGIN_NAME = "RealContentHashPlugin";
@@ -196,11 +197,13 @@ class RealContentHashPlugin {
196
197
  * Creates an instance of RealContentHashPlugin.
197
198
  * @param {RealContentHashPluginOptions} options options
198
199
  */
199
- constructor({ hashFunction, hashDigest }) {
200
+ constructor({ hashFunction, hashDigest, onDemand }) {
200
201
  /** @type {HashFunction} */
201
202
  this._hashFunction = hashFunction;
202
203
  /** @type {HashDigest} */
203
204
  this._hashDigest = hashDigest;
205
+ /** @type {boolean} */
206
+ this._onDemand = Boolean(onDemand);
204
207
  }
205
208
 
206
209
  /**
@@ -223,6 +226,14 @@ class RealContentHashPlugin {
223
226
  stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH
224
227
  },
225
228
  async () => {
229
+ // Set by the deferred fill where a baked name would leave a hashed name
230
+ // stale; only then is `[chunkhash]` repaired rather than left as named.
231
+ const repairing = compilation.runtimeTemplate.needsAnalyzableRepair();
232
+ if (this._onDemand && !repairing) return;
233
+ // On demand, only a name the fill left stale moves, and whatever names it.
234
+ const repairedAssets = this._onDemand
235
+ ? compilation.runtimeTemplate.analyzableRepairedAssets()
236
+ : undefined;
226
237
  const assets = compilation.getAssets();
227
238
  /** @type {AssetInfoForRealContentHash[]} */
228
239
  const assetsWithInfo = [];
@@ -238,6 +249,7 @@ class RealContentHashPlugin {
238
249
  /** @type {Hashes} */
239
250
  const hashes = new Set();
240
251
  addToList(info.contenthash, hashes);
252
+ if (repairing) addToList(info.chunkhash, hashes);
241
253
  if (info.contenthashDigest) {
242
254
  for (const hash of Object.keys(info.contenthashDigest)) {
243
255
  hashToDigest.set(hash, info.contenthashDigest[hash]);
@@ -495,7 +507,44 @@ ${referencingAssets
495
507
  };
496
508
  /** @type {Comparator<AssetInfoForRealContentHash>} */
497
509
  const comparator = compareSelect((a) => a.name, compareStrings);
510
+ /**
511
+ * Whether a group's names went stale: the fill rewrote an asset of theirs, or
512
+ * one names a hash that already moved (groups arrive dependencies first).
513
+ * @param {string[]} group the hashes assigned together
514
+ * @returns {boolean} true when they have to be recomputed
515
+ */
516
+ const staleOnDemand = (group) => {
517
+ const own = new Set(group);
518
+ for (const hash of group) {
519
+ for (const asset of /** @type {AssetInfoForRealContentHash[]} */ (
520
+ hashToAssets.get(hash)
521
+ )) {
522
+ if (
523
+ /** @type {ReadonlySet<string>} */ (repairedAssets).has(
524
+ asset.name
525
+ )
526
+ ) {
527
+ return true;
528
+ }
529
+ for (const referenced of /** @type {Hashes} */ (
530
+ asset.referencedHashes
531
+ )) {
532
+ if (
533
+ !own.has(referenced) &&
534
+ hashToNewHash.get(referenced) !== referenced
535
+ ) {
536
+ return true;
537
+ }
538
+ }
539
+ }
540
+ }
541
+ return false;
542
+ };
498
543
  for (const group of groupsInOrder) {
544
+ if (repairedAssets !== undefined && !staleOnDemand(group)) {
545
+ for (const hash of group) hashToNewHash.set(hash, hash);
546
+ continue;
547
+ }
499
548
  // A cycle is assigned as one group: members are told apart by stable
500
549
  // markers, so the group hashes to a fixed point instead of chasing one.
501
550
  if (group.length > 1) {
@@ -608,15 +657,25 @@ ${referencingAssets
608
657
  (hash) => /** @type {string} */ (hashToNewHash.get(hash))
609
658
  );
610
659
 
660
+ /**
661
+ * @param {string | string[]} hash what the asset was named with
662
+ * @returns {string | string[]} the same, repaired
663
+ */
664
+ const repaired = (hash) =>
665
+ Array.isArray(hash)
666
+ ? hash.map(
667
+ (hash) => /** @type {string} */ (hashToNewHash.get(hash))
668
+ )
669
+ : /** @type {string} */ (hashToNewHash.get(hash));
670
+ /** @type {AssetInfo} */
611
671
  const infoUpdate = {};
612
- const hash =
613
- /** @type {Exclude<AssetInfo["contenthash"], undefined>} */
614
- (asset.info.contenthash);
615
- infoUpdate.contenthash = Array.isArray(hash)
616
- ? hash.map(
617
- (hash) => /** @type {string} */ (hashToNewHash.get(hash))
618
- )
619
- : /** @type {string} */ (hashToNewHash.get(hash));
672
+ if (asset.info.contenthash) {
673
+ infoUpdate.contenthash = repaired(asset.info.contenthash);
674
+ }
675
+ // Tracked only while repairing, so only then does it move with the name.
676
+ if (repairing && asset.info.chunkhash) {
677
+ infoUpdate.chunkhash = repaired(asset.info.chunkhash);
678
+ }
620
679
 
621
680
  if (asset.newSource !== undefined) {
622
681
  compilation.updateAsset(