webpack 5.99.6 → 5.99.8

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 (219) hide show
  1. package/lib/AutomaticPrefetchPlugin.js +21 -22
  2. package/lib/BannerPlugin.js +31 -35
  3. package/lib/CleanPlugin.js +5 -3
  4. package/lib/Compilation.js +21 -15
  5. package/lib/Compiler.js +2 -1
  6. package/lib/ContextExclusionPlugin.js +4 -2
  7. package/lib/ContextModule.js +1 -1
  8. package/lib/ContextModuleFactory.js +1 -2
  9. package/lib/ContextReplacementPlugin.js +7 -4
  10. package/lib/DefinePlugin.js +2 -2
  11. package/lib/DelegatedModule.js +18 -8
  12. package/lib/DelegatedModuleFactoryPlugin.js +9 -7
  13. package/lib/DelegatedPlugin.js +4 -2
  14. package/lib/DllEntryPlugin.js +4 -2
  15. package/lib/DllPlugin.js +5 -3
  16. package/lib/DllReferencePlugin.js +56 -60
  17. package/lib/DynamicEntryPlugin.js +4 -2
  18. package/lib/EntryOptionPlugin.js +3 -1
  19. package/lib/EntryPlugin.js +4 -2
  20. package/lib/EnvironmentPlugin.js +4 -2
  21. package/lib/EvalDevToolModulePlugin.js +9 -7
  22. package/lib/EvalSourceMapDevToolPlugin.js +138 -139
  23. package/lib/ExportsInfo.js +35 -16
  24. package/lib/ExternalModule.js +6 -5
  25. package/lib/ExternalsPlugin.js +3 -1
  26. package/lib/FileSystemInfo.js +2 -2
  27. package/lib/FlagDependencyExportsPlugin.js +2 -1
  28. package/lib/IgnorePlugin.js +6 -4
  29. package/lib/IgnoreWarningsPlugin.js +4 -2
  30. package/lib/LibManifestPlugin.js +5 -6
  31. package/lib/LoaderOptionsPlugin.js +4 -2
  32. package/lib/LoaderTargetPlugin.js +4 -2
  33. package/lib/Module.js +19 -12
  34. package/lib/ModuleFilenameHelpers.js +8 -4
  35. package/lib/ModuleInfoHeaderPlugin.js +11 -12
  36. package/lib/MultiCompiler.js +5 -3
  37. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  38. package/lib/NormalModule.js +13 -8
  39. package/lib/NormalModuleReplacementPlugin.js +33 -36
  40. package/lib/PlatformPlugin.js +3 -1
  41. package/lib/PrefetchPlugin.js +4 -2
  42. package/lib/ProgressPlugin.js +23 -26
  43. package/lib/RecordIdsPlugin.js +72 -102
  44. package/lib/RuntimePlugin.js +34 -32
  45. package/lib/SourceMapDevToolPlugin.js +9 -8
  46. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  47. package/lib/WarnNoModeSetPlugin.js +3 -1
  48. package/lib/WatchIgnorePlugin.js +3 -1
  49. package/lib/WebpackError.js +11 -3
  50. package/lib/WebpackOptionsApply.js +6 -7
  51. package/lib/asset/AssetGenerator.js +2 -2
  52. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  53. package/lib/cache/IdleFileCachePlugin.js +11 -12
  54. package/lib/cache/MemoryWithGcCachePlugin.js +7 -5
  55. package/lib/cache/ResolverCachePlugin.js +8 -6
  56. package/lib/cli.js +5 -1
  57. package/lib/config/defaults.js +10 -6
  58. package/lib/config/normalization.js +14 -8
  59. package/lib/container/ContainerReferencePlugin.js +24 -26
  60. package/lib/container/ModuleFederationPlugin.js +2 -1
  61. package/lib/css/CssGenerator.js +1 -1
  62. package/lib/css/CssModulesPlugin.js +8 -6
  63. package/lib/debug/ProfilingPlugin.js +18 -21
  64. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
  65. package/lib/dependencies/ContextElementDependency.js +1 -1
  66. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  67. package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
  68. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  69. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
  70. package/lib/dependencies/LoaderPlugin.js +5 -3
  71. package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
  72. package/lib/dependencies/RequireContextPlugin.js +2 -1
  73. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
  74. package/lib/dependencies/WorkerPlugin.js +2 -2
  75. package/lib/esm/ModuleChunkLoadingPlugin.js +72 -73
  76. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  77. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -2
  78. package/lib/hmr/LazyCompilationPlugin.js +17 -18
  79. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
  80. package/lib/ids/DeterministicModuleIdsPlugin.js +47 -48
  81. package/lib/ids/HashedModuleIdsPlugin.js +4 -2
  82. package/lib/ids/NamedChunkIdsPlugin.js +4 -2
  83. package/lib/ids/NamedModuleIdsPlugin.js +4 -2
  84. package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
  85. package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
  86. package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
  87. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
  88. package/lib/index.js +11 -0
  89. package/lib/javascript/JavascriptModulesPlugin.js +2 -2
  90. package/lib/javascript/JavascriptParser.js +634 -656
  91. package/lib/json/JsonModulesPlugin.js +4 -4
  92. package/lib/library/AbstractLibraryPlugin.js +1 -1
  93. package/lib/library/ModuleLibraryPlugin.js +60 -42
  94. package/lib/node/CommonJsChunkLoadingPlugin.js +69 -73
  95. package/lib/node/NodeEnvironmentPlugin.js +3 -1
  96. package/lib/node/nodeConsole.js +3 -2
  97. package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
  98. package/lib/optimize/ConcatenatedModule.js +15 -16
  99. package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
  100. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  101. package/lib/optimize/MangleExportsPlugin.js +15 -16
  102. package/lib/optimize/MinChunkSizePlugin.js +4 -2
  103. package/lib/optimize/ModuleConcatenationPlugin.js +6 -4
  104. package/lib/optimize/RealContentHashPlugin.js +4 -2
  105. package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
  106. package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
  107. package/lib/optimize/RuntimeChunkPlugin.js +21 -23
  108. package/lib/optimize/SideEffectsFlagPlugin.js +9 -6
  109. package/lib/optimize/SplitChunksPlugin.js +9 -7
  110. package/lib/performance/SizeLimitsPlugin.js +3 -1
  111. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
  112. package/lib/rules/BasicEffectRulePlugin.js +1 -2
  113. package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
  114. package/lib/rules/RuleSetCompiler.js +19 -5
  115. package/lib/rules/UseEffectRulePlugin.js +4 -6
  116. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  117. package/lib/schemes/DataUriPlugin.js +5 -3
  118. package/lib/schemes/FileUriPlugin.js +5 -3
  119. package/lib/schemes/HttpUriPlugin.js +186 -188
  120. package/lib/serialization/AggregateErrorSerializer.js +42 -0
  121. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  122. package/lib/serialization/ObjectMiddleware.js +13 -0
  123. package/lib/sharing/ProvideSharedPlugin.js +6 -4
  124. package/lib/stats/DefaultStatsFactoryPlugin.js +89 -33
  125. package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
  126. package/lib/stats/DefaultStatsPrinterPlugin.js +306 -341
  127. package/lib/util/concatenate.js +4 -2
  128. package/lib/util/createHash.js +3 -3
  129. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  130. package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
  131. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
  132. package/package.json +35 -30
  133. package/schemas/WebpackOptions.check.d.ts +1 -1
  134. package/schemas/WebpackOptions.check.js +2 -2
  135. package/schemas/WebpackOptions.json +267 -26
  136. package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
  137. package/schemas/plugins/BannerPlugin.check.js +1 -1
  138. package/schemas/plugins/DllPlugin.check.d.ts +1 -1
  139. package/schemas/plugins/DllPlugin.check.js +1 -1
  140. package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
  141. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  142. package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
  143. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  144. package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
  145. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  146. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
  147. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  148. package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
  149. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  150. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
  151. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  152. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  153. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
  154. package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
  155. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
  156. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  157. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
  158. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  159. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
  160. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  161. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
  162. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  163. package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
  164. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  165. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
  166. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  167. package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
  168. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  169. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
  170. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  171. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
  172. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  173. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
  174. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  175. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
  176. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  177. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
  178. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  179. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
  180. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  181. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
  182. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  183. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
  184. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  185. package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
  186. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  187. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
  188. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  189. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
  190. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
  191. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
  192. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
  193. package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
  194. package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
  195. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  196. package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
  197. package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
  198. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  199. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
  200. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  201. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
  202. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  203. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
  204. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
  205. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
  206. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  207. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
  208. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  209. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
  210. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
  211. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
  212. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
  213. package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
  214. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  215. package/types.d.ts +587 -207
  216. package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
  217. package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
  218. package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
  219. package/schemas/plugins/JsonModulesPluginParser.json +0 -16
@@ -12,6 +12,8 @@ const { compareIds } = require("../util/comparators");
12
12
  /** @typedef {import("../Compiler")} Compiler */
13
13
  /** @typedef {import("../Module")} Module */
14
14
 
15
+ const PLUGIN_NAME = "FlagIncludedChunksPlugin";
16
+
15
17
  class FlagIncludedChunksPlugin {
16
18
  /**
17
19
  * Apply the plugin
@@ -19,111 +21,104 @@ class FlagIncludedChunksPlugin {
19
21
  * @returns {void}
20
22
  */
21
23
  apply(compiler) {
22
- compiler.hooks.compilation.tap("FlagIncludedChunksPlugin", compilation => {
23
- compilation.hooks.optimizeChunkIds.tap(
24
- "FlagIncludedChunksPlugin",
25
- chunks => {
26
- const chunkGraph = compilation.chunkGraph;
27
-
28
- // prepare two bit integers for each module
29
- // 2^31 is the max number represented as SMI in v8
30
- // we want the bits distributed this way:
31
- // the bit 2^31 is pretty rar and only one module should get it
32
- // so it has a probability of 1 / modulesCount
33
- // the first bit (2^0) is the easiest and every module could get it
34
- // if it doesn't get a better bit
35
- // from bit 2^n to 2^(n+1) there is a probability of p
36
- // so 1 / modulesCount == p^31
37
- // <=> p = sqrt31(1 / modulesCount)
38
- // so we use a modulo of 1 / sqrt31(1 / modulesCount)
39
- /** @type {WeakMap<Module, number>} */
40
- const moduleBits = new WeakMap();
41
- const modulesCount = compilation.modules.size;
42
-
43
- // precalculate the modulo values for each bit
44
- const modulo = 1 / (1 / modulesCount) ** (1 / 31);
45
- const modulos = Array.from(
46
- { length: 31 },
47
- (x, i) => (modulo ** i) | 0
48
- );
49
-
50
- // iterate all modules to generate bit values
51
- let i = 0;
52
- for (const module of compilation.modules) {
53
- let bit = 30;
54
- while (i % modulos[bit] !== 0) {
55
- bit--;
56
- }
57
- moduleBits.set(module, 1 << bit);
58
- i++;
24
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
25
+ compilation.hooks.optimizeChunkIds.tap(PLUGIN_NAME, chunks => {
26
+ const chunkGraph = compilation.chunkGraph;
27
+
28
+ // prepare two bit integers for each module
29
+ // 2^31 is the max number represented as SMI in v8
30
+ // we want the bits distributed this way:
31
+ // the bit 2^31 is pretty rar and only one module should get it
32
+ // so it has a probability of 1 / modulesCount
33
+ // the first bit (2^0) is the easiest and every module could get it
34
+ // if it doesn't get a better bit
35
+ // from bit 2^n to 2^(n+1) there is a probability of p
36
+ // so 1 / modulesCount == p^31
37
+ // <=> p = sqrt31(1 / modulesCount)
38
+ // so we use a modulo of 1 / sqrt31(1 / modulesCount)
39
+ /** @type {WeakMap<Module, number>} */
40
+ const moduleBits = new WeakMap();
41
+ const modulesCount = compilation.modules.size;
42
+
43
+ // precalculate the modulo values for each bit
44
+ const modulo = 1 / (1 / modulesCount) ** (1 / 31);
45
+ const modulos = Array.from({ length: 31 }, (x, i) => (modulo ** i) | 0);
46
+
47
+ // iterate all modules to generate bit values
48
+ let i = 0;
49
+ for (const module of compilation.modules) {
50
+ let bit = 30;
51
+ while (i % modulos[bit] !== 0) {
52
+ bit--;
59
53
  }
54
+ moduleBits.set(module, 1 << bit);
55
+ i++;
56
+ }
60
57
 
61
- // iterate all chunks to generate bitmaps
62
- /** @type {WeakMap<Chunk, number>} */
63
- const chunkModulesHash = new WeakMap();
64
- for (const chunk of chunks) {
65
- let hash = 0;
66
- for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
67
- hash |= /** @type {number} */ (moduleBits.get(module));
68
- }
69
- chunkModulesHash.set(chunk, hash);
58
+ // iterate all chunks to generate bitmaps
59
+ /** @type {WeakMap<Chunk, number>} */
60
+ const chunkModulesHash = new WeakMap();
61
+ for (const chunk of chunks) {
62
+ let hash = 0;
63
+ for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
64
+ hash |= /** @type {number} */ (moduleBits.get(module));
65
+ }
66
+ chunkModulesHash.set(chunk, hash);
67
+ }
68
+
69
+ for (const chunkA of chunks) {
70
+ const chunkAHash =
71
+ /** @type {number} */
72
+ (chunkModulesHash.get(chunkA));
73
+ const chunkAModulesCount = chunkGraph.getNumberOfChunkModules(chunkA);
74
+ if (chunkAModulesCount === 0) continue;
75
+ let bestModule;
76
+ for (const module of chunkGraph.getChunkModulesIterable(chunkA)) {
77
+ if (
78
+ bestModule === undefined ||
79
+ chunkGraph.getNumberOfModuleChunks(bestModule) >
80
+ chunkGraph.getNumberOfModuleChunks(module)
81
+ )
82
+ bestModule = module;
70
83
  }
84
+ loopB: for (const chunkB of chunkGraph.getModuleChunksIterable(
85
+ /** @type {Module} */ (bestModule)
86
+ )) {
87
+ // as we iterate the same iterables twice
88
+ // skip if we find ourselves
89
+ if (chunkA === chunkB) continue;
71
90
 
72
- for (const chunkA of chunks) {
73
- const chunkAHash =
91
+ const chunkBModulesCount =
92
+ chunkGraph.getNumberOfChunkModules(chunkB);
93
+
94
+ // ids for empty chunks are not included
95
+ if (chunkBModulesCount === 0) continue;
96
+
97
+ // instead of swapping A and B just bail
98
+ // as we loop twice the current A will be B and B then A
99
+ if (chunkAModulesCount > chunkBModulesCount) continue;
100
+
101
+ // is chunkA in chunkB?
102
+
103
+ // we do a cheap check for the hash value
104
+ const chunkBHash =
74
105
  /** @type {number} */
75
- (chunkModulesHash.get(chunkA));
76
- const chunkAModulesCount =
77
- chunkGraph.getNumberOfChunkModules(chunkA);
78
- if (chunkAModulesCount === 0) continue;
79
- let bestModule;
80
- for (const module of chunkGraph.getChunkModulesIterable(chunkA)) {
81
- if (
82
- bestModule === undefined ||
83
- chunkGraph.getNumberOfModuleChunks(bestModule) >
84
- chunkGraph.getNumberOfModuleChunks(module)
85
- )
86
- bestModule = module;
87
- }
88
- loopB: for (const chunkB of chunkGraph.getModuleChunksIterable(
89
- /** @type {Module} */ (bestModule)
90
- )) {
91
- // as we iterate the same iterables twice
92
- // skip if we find ourselves
93
- if (chunkA === chunkB) continue;
94
-
95
- const chunkBModulesCount =
96
- chunkGraph.getNumberOfChunkModules(chunkB);
97
-
98
- // ids for empty chunks are not included
99
- if (chunkBModulesCount === 0) continue;
100
-
101
- // instead of swapping A and B just bail
102
- // as we loop twice the current A will be B and B then A
103
- if (chunkAModulesCount > chunkBModulesCount) continue;
104
-
105
- // is chunkA in chunkB?
106
-
107
- // we do a cheap check for the hash value
108
- const chunkBHash =
109
- /** @type {number} */
110
- (chunkModulesHash.get(chunkB));
111
- if ((chunkBHash & chunkAHash) !== chunkAHash) continue;
112
-
113
- // compare all modules
114
- for (const m of chunkGraph.getChunkModulesIterable(chunkA)) {
115
- if (!chunkGraph.isModuleInChunk(m, chunkB)) continue loopB;
116
- }
117
-
118
- /** @type {ChunkId[]} */
119
- (chunkB.ids).push(/** @type {ChunkId} */ (chunkA.id));
120
- // https://github.com/webpack/webpack/issues/18837
121
- /** @type {ChunkId[]} */
122
- (chunkB.ids).sort(compareIds);
106
+ (chunkModulesHash.get(chunkB));
107
+ if ((chunkBHash & chunkAHash) !== chunkAHash) continue;
108
+
109
+ // compare all modules
110
+ for (const m of chunkGraph.getChunkModulesIterable(chunkA)) {
111
+ if (!chunkGraph.isModuleInChunk(m, chunkB)) continue loopB;
123
112
  }
113
+
114
+ /** @type {ChunkId[]} */
115
+ (chunkB.ids).push(/** @type {ChunkId} */ (chunkA.id));
116
+ // https://github.com/webpack/webpack/issues/18837
117
+ /** @type {ChunkId[]} */
118
+ (chunkB.ids).sort(compareIds);
124
119
  }
125
120
  }
126
- );
121
+ });
127
122
  });
128
123
  }
129
124
  }
@@ -51,6 +51,8 @@ const addToSetMap = (map, key, value) => {
51
51
  }
52
52
  };
53
53
 
54
+ const PLUGIN_NAME = "LimitChunkCountPlugin";
55
+
54
56
  class LimitChunkCountPlugin {
55
57
  /**
56
58
  * @param {LimitChunkCountPluginOptions=} options options object
@@ -66,10 +68,10 @@ class LimitChunkCountPlugin {
66
68
  */
67
69
  apply(compiler) {
68
70
  const options = this.options;
69
- compiler.hooks.compilation.tap("LimitChunkCountPlugin", compilation => {
71
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
70
72
  compilation.hooks.optimizeChunks.tap(
71
73
  {
72
- name: "LimitChunkCountPlugin",
74
+ name: PLUGIN_NAME,
73
75
  stage: STAGE_ADVANCED
74
76
  },
75
77
  chunks => {
@@ -142,6 +142,8 @@ const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
142
142
  }
143
143
  };
144
144
 
145
+ const PLUGIN_NAME = "MangleExportsPlugin";
146
+
145
147
  class MangleExportsPlugin {
146
148
  /**
147
149
  * @param {boolean} deterministic use deterministic names
@@ -157,24 +159,21 @@ class MangleExportsPlugin {
157
159
  */
158
160
  apply(compiler) {
159
161
  const { _deterministic: deterministic } = this;
160
- compiler.hooks.compilation.tap("MangleExportsPlugin", compilation => {
162
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
161
163
  const moduleGraph = compilation.moduleGraph;
162
- compilation.hooks.optimizeCodeGeneration.tap(
163
- "MangleExportsPlugin",
164
- modules => {
165
- if (compilation.moduleMemCaches) {
166
- throw new Error(
167
- "optimization.mangleExports can't be used with cacheUnaffected as export mangling is a global effect"
168
- );
169
- }
170
- for (const module of modules) {
171
- const isNamespace =
172
- module.buildMeta && module.buildMeta.exportsType === "namespace";
173
- const exportsInfo = moduleGraph.getExportsInfo(module);
174
- mangleExportsInfo(deterministic, exportsInfo, isNamespace);
175
- }
164
+ compilation.hooks.optimizeCodeGeneration.tap(PLUGIN_NAME, modules => {
165
+ if (compilation.moduleMemCaches) {
166
+ throw new Error(
167
+ "optimization.mangleExports can't be used with cacheUnaffected as export mangling is a global effect"
168
+ );
169
+ }
170
+ for (const module of modules) {
171
+ const isNamespace =
172
+ module.buildMeta && module.buildMeta.exportsType === "namespace";
173
+ const exportsInfo = moduleGraph.getExportsInfo(module);
174
+ mangleExportsInfo(deterministic, exportsInfo, isNamespace);
176
175
  }
177
- );
176
+ });
178
177
  });
179
178
  }
180
179
  }
@@ -21,6 +21,8 @@ const validate = createSchemaValidation(
21
21
  }
22
22
  );
23
23
 
24
+ const PLUGIN_NAME = "MinChunkSizePlugin";
25
+
24
26
  class MinChunkSizePlugin {
25
27
  /**
26
28
  * @param {MinChunkSizePluginOptions} options options object
@@ -38,10 +40,10 @@ class MinChunkSizePlugin {
38
40
  apply(compiler) {
39
41
  const options = this.options;
40
42
  const minChunkSize = options.minChunkSize;
41
- compiler.hooks.compilation.tap("MinChunkSizePlugin", compilation => {
43
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
42
44
  compilation.hooks.optimizeChunks.tap(
43
45
  {
44
- name: "MinChunkSizePlugin",
46
+ name: PLUGIN_NAME,
45
47
  stage: STAGE_ADVANCED
46
48
  },
47
49
  chunks => {
@@ -48,6 +48,8 @@ const ConcatenatedModule = require("./ConcatenatedModule");
48
48
  */
49
49
  const formatBailoutReason = msg => `ModuleConcatenation bailout: ${msg}`;
50
50
 
51
+ const PLUGIN_NAME = "ModuleConcatenationPlugin";
52
+
51
53
  class ModuleConcatenationPlugin {
52
54
  /**
53
55
  * Apply the plugin
@@ -56,7 +58,7 @@ class ModuleConcatenationPlugin {
56
58
  */
57
59
  apply(compiler) {
58
60
  const { _backCompat: backCompat } = compiler;
59
- compiler.hooks.compilation.tap("ModuleConcatenationPlugin", compilation => {
61
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
60
62
  if (compilation.moduleMemCaches) {
61
63
  throw new Error(
62
64
  "optimization.concatenateModules can't be used with cacheUnaffected as module concatenation is a global effect"
@@ -133,7 +135,7 @@ class ModuleConcatenationPlugin {
133
135
 
134
136
  compilation.hooks.optimizeChunkModules.tapAsync(
135
137
  {
136
- name: "ModuleConcatenationPlugin",
138
+ name: PLUGIN_NAME,
137
139
  stage: STAGE_DEFAULT
138
140
  },
139
141
  (allChunks, modules, callback) => {
@@ -396,9 +398,9 @@ class ModuleConcatenationPlugin {
396
398
  newModule.build(
397
399
  compiler.options,
398
400
  compilation,
399
- /** @type {TODO} */
401
+ /** @type {EXPECTED_ANY} */
400
402
  (null),
401
- /** @type {TODO} */
403
+ /** @type {EXPECTED_ANY} */
402
404
  (null),
403
405
  err => {
404
406
  if (err) {
@@ -113,6 +113,8 @@ const compilationHooksMap = new WeakMap();
113
113
  * @property {string=} hashDigest the hash digest to use
114
114
  */
115
115
 
116
+ const PLUGIN_NAME = "RealContentHashPlugin";
117
+
116
118
  class RealContentHashPlugin {
117
119
  /**
118
120
  * @param {Compilation} compilation the compilation
@@ -148,7 +150,7 @@ class RealContentHashPlugin {
148
150
  * @returns {void}
149
151
  */
150
152
  apply(compiler) {
151
- compiler.hooks.compilation.tap("RealContentHashPlugin", compilation => {
153
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
152
154
  const cacheAnalyse = compilation.getCache(
153
155
  "RealContentHashPlugin|analyse"
154
156
  );
@@ -158,7 +160,7 @@ class RealContentHashPlugin {
158
160
  const hooks = RealContentHashPlugin.getCompilationHooks(compilation);
159
161
  compilation.hooks.processAssets.tapPromise(
160
162
  {
161
- name: "RealContentHashPlugin",
163
+ name: PLUGIN_NAME,
162
164
  stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH
163
165
  },
164
166
  async () => {
@@ -10,6 +10,8 @@ const { STAGE_BASIC, STAGE_ADVANCED } = require("../OptimizationStages");
10
10
  /** @typedef {import("../Chunk")} Chunk */
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
12
 
13
+ const PLUGIN_NAME = "RemoveEmptyChunksPlugin";
14
+
13
15
  class RemoveEmptyChunksPlugin {
14
16
  /**
15
17
  * Apply the plugin
@@ -17,7 +19,7 @@ class RemoveEmptyChunksPlugin {
17
19
  * @returns {void}
18
20
  */
19
21
  apply(compiler) {
20
- compiler.hooks.compilation.tap("RemoveEmptyChunksPlugin", compilation => {
22
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
21
23
  /**
22
24
  * @param {Iterable<Chunk>} chunks the chunks array
23
25
  * @returns {void}
@@ -39,14 +41,14 @@ class RemoveEmptyChunksPlugin {
39
41
  // TODO do it once
40
42
  compilation.hooks.optimizeChunks.tap(
41
43
  {
42
- name: "RemoveEmptyChunksPlugin",
44
+ name: PLUGIN_NAME,
43
45
  stage: STAGE_BASIC
44
46
  },
45
47
  handler
46
48
  );
47
49
  compilation.hooks.optimizeChunks.tap(
48
50
  {
49
- name: "RemoveEmptyChunksPlugin",
51
+ name: PLUGIN_NAME,
50
52
  stage: STAGE_ADVANCED
51
53
  },
52
54
  handler
@@ -59,13 +59,15 @@ function* getModulesFromMask(mask, ordinalModules) {
59
59
  }
60
60
  }
61
61
 
62
+ const PLUGIN_NAME = "RemoveParentModulesPlugin";
63
+
62
64
  class RemoveParentModulesPlugin {
63
65
  /**
64
66
  * @param {Compiler} compiler the compiler
65
67
  * @returns {void}
66
68
  */
67
69
  apply(compiler) {
68
- compiler.hooks.compilation.tap("RemoveParentModulesPlugin", compilation => {
70
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
69
71
  /**
70
72
  * @param {Iterable<Chunk>} chunks the chunks
71
73
  * @param {ChunkGroup[]} chunkGroups the chunk groups
@@ -193,7 +195,7 @@ class RemoveParentModulesPlugin {
193
195
  };
194
196
  compilation.hooks.optimizeChunks.tap(
195
197
  {
196
- name: "RemoveParentModulesPlugin",
198
+ name: PLUGIN_NAME,
197
199
  stage: STAGE_BASIC
198
200
  },
199
201
  handler
@@ -9,16 +9,17 @@
9
9
  /** @typedef {import("../Compiler")} Compiler */
10
10
  /** @typedef {import("../Entrypoint")} Entrypoint */
11
11
 
12
+ const PLUGIN_NAME = "RuntimeChunkPlugin";
13
+
14
+ /** @typedef {(entrypoint: { name: string }) => string} RuntimeChunkFunction */
15
+
12
16
  class RuntimeChunkPlugin {
13
17
  /**
14
- * @param {{ name?: (entrypoint: { name: string }) => string }} options options
18
+ * @param {{ name?: RuntimeChunkFunction }=} options options
15
19
  */
16
20
  constructor(options) {
17
21
  this.options = {
18
- /**
19
- * @param {Entrypoint} entrypoint entrypoint name
20
- * @returns {string} runtime chunk name
21
- */
22
+ /** @type {RuntimeChunkFunction} */
22
23
  name: entrypoint => `runtime~${entrypoint.name}`,
23
24
  ...options
24
25
  };
@@ -30,26 +31,23 @@ class RuntimeChunkPlugin {
30
31
  * @returns {void}
31
32
  */
32
33
  apply(compiler) {
33
- compiler.hooks.thisCompilation.tap("RuntimeChunkPlugin", compilation => {
34
- compilation.hooks.addEntry.tap(
35
- "RuntimeChunkPlugin",
36
- (_, { name: entryName }) => {
37
- if (entryName === undefined) return;
38
- const data =
39
- /** @type {EntryData} */
40
- (compilation.entries.get(entryName));
41
- if (data.options.runtime === undefined && !data.options.dependOn) {
42
- // Determine runtime chunk name
43
- let name =
44
- /** @type {string | ((entrypoint: { name: string }) => string)} */
45
- (this.options.name);
46
- if (typeof name === "function") {
47
- name = name({ name: entryName });
48
- }
49
- data.options.runtime = name;
34
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
35
+ compilation.hooks.addEntry.tap(PLUGIN_NAME, (_, { name: entryName }) => {
36
+ if (entryName === undefined) return;
37
+ const data =
38
+ /** @type {EntryData} */
39
+ (compilation.entries.get(entryName));
40
+ if (data.options.runtime === undefined && !data.options.dependOn) {
41
+ // Determine runtime chunk name
42
+ let name =
43
+ /** @type {string | RuntimeChunkFunction} */
44
+ (this.options.name);
45
+ if (typeof name === "function") {
46
+ name = name({ name: entryName });
50
47
  }
48
+ data.options.runtime = name;
51
49
  }
52
- );
50
+ });
53
51
  });
54
52
  }
55
53
  }
@@ -145,7 +145,8 @@ class SideEffectsFlagPlugin {
145
145
  if (
146
146
  !parser.isPure(
147
147
  statement.expression,
148
- /** @type {Range} */ (statement.range)[0]
148
+ /** @type {Range} */
149
+ (statement.range)[0]
149
150
  )
150
151
  ) {
151
152
  sideEffectsStatement = statement;
@@ -157,7 +158,8 @@ class SideEffectsFlagPlugin {
157
158
  if (
158
159
  !parser.isPure(
159
160
  statement.test,
160
- /** @type {Range} */ (statement.range)[0]
161
+ /** @type {Range} */
162
+ (statement.range)[0]
161
163
  )
162
164
  ) {
163
165
  sideEffectsStatement = statement;
@@ -193,7 +195,8 @@ class SideEffectsFlagPlugin {
193
195
  if (
194
196
  !parser.isPure(
195
197
  statement.discriminant,
196
- /** @type {Range} */ (statement.range)[0]
198
+ /** @type {Range} */
199
+ (statement.range)[0]
197
200
  )
198
201
  ) {
199
202
  sideEffectsStatement = statement;
@@ -216,9 +219,9 @@ class SideEffectsFlagPlugin {
216
219
  case "ExportDefaultDeclaration":
217
220
  if (
218
221
  !parser.isPure(
219
- /** @type {TODO} */
220
- (statement.declaration),
221
- /** @type {Range} */ (statement.range)[0]
222
+ statement.declaration,
223
+ /** @type {Range} */
224
+ (statement.range)[0]
222
225
  )
223
226
  ) {
224
227
  sideEffectsStatement = statement;
@@ -21,6 +21,7 @@ const { makePathsRelative } = require("../util/identifier");
21
21
  const memoize = require("../util/memoize");
22
22
  const MinMaxSizeWarning = require("./MinMaxSizeWarning");
23
23
 
24
+ /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
24
25
  /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksCacheGroup} OptimizationSplitChunksCacheGroup */
25
26
  /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksGetCacheGroups} OptimizationSplitChunksGetCacheGroups */
26
27
  /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksOptions} OptimizationSplitChunksOptions */
@@ -33,7 +34,6 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
33
34
  /** @typedef {import("../Module")} Module */
34
35
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
35
36
  /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
36
- /** @typedef {import("../util/createHash").Algorithm} Algorithm */
37
37
  /** @typedef {import("../util/deterministicGrouping").GroupedItems<Module>} DeterministicGroupingGroupedItemsForModule */
38
38
  /** @typedef {import("../util/deterministicGrouping").Options<Module>} DeterministicGroupingOptionsForModule */
39
39
 
@@ -184,7 +184,7 @@ const hashFilename = (name, outputOptions) => {
184
184
  const digest =
185
185
  /** @type {string} */
186
186
  (
187
- createHash(/** @type {Algorithm} */ (outputOptions.hashFunction))
187
+ createHash(/** @type {HashFunction} */ (outputOptions.hashFunction))
188
188
  .update(name)
189
189
  .digest(outputOptions.hashDigest)
190
190
  );
@@ -631,6 +631,8 @@ const createCacheGroupSource = (options, key, defaultSizeTypes) => {
631
631
  };
632
632
  };
633
633
 
634
+ const PLUGIN_NAME = "SplitChunksPlugin";
635
+
634
636
  module.exports = class SplitChunksPlugin {
635
637
  /**
636
638
  * @param {OptimizationSplitChunksOptions=} options plugin options
@@ -822,15 +824,15 @@ module.exports = class SplitChunksPlugin {
822
824
  compiler.context,
823
825
  compiler.root
824
826
  );
825
- compiler.hooks.thisCompilation.tap("SplitChunksPlugin", compilation => {
826
- const logger = compilation.getLogger("webpack.SplitChunksPlugin");
827
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
828
+ const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
827
829
  let alreadyOptimized = false;
828
- compilation.hooks.unseal.tap("SplitChunksPlugin", () => {
830
+ compilation.hooks.unseal.tap(PLUGIN_NAME, () => {
829
831
  alreadyOptimized = false;
830
832
  });
831
833
  compilation.hooks.optimizeChunks.tap(
832
834
  {
833
- name: "SplitChunksPlugin",
835
+ name: PLUGIN_NAME,
834
836
  stage: STAGE_ADVANCED
835
837
  },
836
838
  chunks => {
@@ -1171,7 +1173,7 @@ module.exports = class SplitChunksPlugin {
1171
1173
  alreadyReportedErrors.add(name);
1172
1174
  compilation.errors.push(
1173
1175
  new WebpackError(
1174
- "SplitChunksPlugin\n" +
1176
+ `${PLUGIN_NAME}\n` +
1175
1177
  `Cache group "${cacheGroup.key}" conflicts with existing chunk.\n` +
1176
1178
  `Both have the same name "${name}" and existing chunk is not a parent of the selected modules.\n` +
1177
1179
  "Use a different name for the cache group or make sure that the existing chunk is a parent (e. g. via dependOn).\n" +
@@ -41,6 +41,8 @@ const isOverSizeLimitSet = new WeakSet();
41
41
  */
42
42
  const excludeSourceMap = (name, source, info) => !info.development;
43
43
 
44
+ const PLUGIN_NAME = "SizeLimitsPlugin";
45
+
44
46
  module.exports = class SizeLimitsPlugin {
45
47
  /**
46
48
  * @param {PerformanceOptions} options the plugin options
@@ -71,7 +73,7 @@ module.exports = class SizeLimitsPlugin {
71
73
  const hints = this.hints;
72
74
  const assetFilter = this.assetFilter || excludeSourceMap;
73
75
 
74
- compiler.hooks.afterEmit.tap("SizeLimitsPlugin", compilation => {
76
+ compiler.hooks.afterEmit.tap(PLUGIN_NAME, compilation => {
75
77
  /** @type {WebpackError[]} */
76
78
  const warnings = [];
77
79