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,7 @@ const ProgressPlugin = require("../ProgressPlugin");
12
12
  /** @typedef {import("./PackFileCacheStrategy")} PackFileCacheStrategy */
13
13
 
14
14
  const BUILD_DEPENDENCIES_KEY = Symbol("build dependencies key");
15
+ const PLUGIN_NAME = "IdleFileCachePlugin";
15
16
 
16
17
  class IdleFileCachePlugin {
17
18
  /**
@@ -55,7 +56,7 @@ class IdleFileCachePlugin {
55
56
  const pendingIdleTasks = new Map();
56
57
 
57
58
  compiler.cache.hooks.store.tap(
58
- { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
59
+ { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
59
60
  (identifier, etag, data) => {
60
61
  pendingIdleTasks.set(identifier, () =>
61
62
  strategy.store(identifier, etag, data)
@@ -64,7 +65,7 @@ class IdleFileCachePlugin {
64
65
  );
65
66
 
66
67
  compiler.cache.hooks.get.tapPromise(
67
- { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
68
+ { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
68
69
  (identifier, etag, gotHandlers) => {
69
70
  const restore = () =>
70
71
  strategy.restore(identifier, etag).then(cacheEntry => {
@@ -91,7 +92,7 @@ class IdleFileCachePlugin {
91
92
  );
92
93
 
93
94
  compiler.cache.hooks.storeBuildDependencies.tap(
94
- { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
95
+ { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
95
96
  dependencies => {
96
97
  pendingIdleTasks.set(BUILD_DEPENDENCIES_KEY, () =>
97
98
  Promise.resolve().then(() =>
@@ -102,7 +103,7 @@ class IdleFileCachePlugin {
102
103
  );
103
104
 
104
105
  compiler.cache.hooks.shutdown.tapPromise(
105
- { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
106
+ { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
106
107
  () => {
107
108
  if (idleTimer) {
108
109
  clearTimeout(idleTimer);
@@ -165,9 +166,7 @@ class IdleFileCachePlugin {
165
166
  timeSpendInBuild = 0;
166
167
  })
167
168
  .catch(err => {
168
- const logger = compiler.getInfrastructureLogger(
169
- "IdleFileCachePlugin"
170
- );
169
+ const logger = compiler.getInfrastructureLogger(PLUGIN_NAME);
171
170
  logger.warn(`Background tasks during idle failed: ${err.message}`);
172
171
  logger.debug(err.stack);
173
172
  });
@@ -177,12 +176,12 @@ class IdleFileCachePlugin {
177
176
  /** @type {ReturnType<typeof setTimeout> | undefined} */
178
177
  let idleTimer;
179
178
  compiler.cache.hooks.beginIdle.tap(
180
- { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
179
+ { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
181
180
  () => {
182
181
  const isLargeChange = timeSpendInBuild > avgTimeSpendInStore * 2;
183
182
  if (isInitialStore && idleTimeoutForInitialStore < idleTimeout) {
184
183
  compiler
185
- .getInfrastructureLogger("IdleFileCachePlugin")
184
+ .getInfrastructureLogger(PLUGIN_NAME)
186
185
  .log(
187
186
  `Initial cache was generated and cache will be persisted in ${
188
187
  idleTimeoutForInitialStore / 1000
@@ -193,7 +192,7 @@ class IdleFileCachePlugin {
193
192
  idleTimeoutAfterLargeChanges < idleTimeout
194
193
  ) {
195
194
  compiler
196
- .getInfrastructureLogger("IdleFileCachePlugin")
195
+ .getInfrastructureLogger(PLUGIN_NAME)
197
196
  .log(
198
197
  `Spend ${Math.round(timeSpendInBuild) / 1000}s in build and ${
199
198
  Math.round(avgTimeSpendInStore) / 1000
@@ -218,7 +217,7 @@ class IdleFileCachePlugin {
218
217
  }
219
218
  );
220
219
  compiler.cache.hooks.endIdle.tap(
221
- { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
220
+ { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
222
221
  () => {
223
222
  if (idleTimer) {
224
223
  clearTimeout(idleTimer);
@@ -227,7 +226,7 @@ class IdleFileCachePlugin {
227
226
  isIdle = false;
228
227
  }
229
228
  );
230
- compiler.hooks.done.tap("IdleFileCachePlugin", stats => {
229
+ compiler.hooks.done.tap(PLUGIN_NAME, stats => {
231
230
  // 10% build overhead is ignored, as it's not cacheable
232
231
  timeSpendInBuild *= 0.9;
233
232
  timeSpendInBuild +=
@@ -18,6 +18,8 @@ const Cache = require("../Cache");
18
18
  * @property {number} maxGenerations max generations
19
19
  */
20
20
 
21
+ const PLUGIN_NAME = "MemoryWithGcCachePlugin";
22
+
21
23
  class MemoryWithGcCachePlugin {
22
24
  /**
23
25
  * @param {MemoryWithGcCachePluginOptions} options options
@@ -39,8 +41,8 @@ class MemoryWithGcCachePlugin {
39
41
  const oldCache = new Map();
40
42
  let generation = 0;
41
43
  let cachePosition = 0;
42
- const logger = compiler.getInfrastructureLogger("MemoryWithGcCachePlugin");
43
- compiler.hooks.afterDone.tap("MemoryWithGcCachePlugin", () => {
44
+ const logger = compiler.getInfrastructureLogger(PLUGIN_NAME);
45
+ compiler.hooks.afterDone.tap(PLUGIN_NAME, () => {
44
46
  generation++;
45
47
  let clearedEntries = 0;
46
48
  let lastClearedIdentifier;
@@ -91,13 +93,13 @@ class MemoryWithGcCachePlugin {
91
93
  }
92
94
  });
93
95
  compiler.cache.hooks.store.tap(
94
- { name: "MemoryWithGcCachePlugin", stage: Cache.STAGE_MEMORY },
96
+ { name: PLUGIN_NAME, stage: Cache.STAGE_MEMORY },
95
97
  (identifier, etag, data) => {
96
98
  cache.set(identifier, { etag, data });
97
99
  }
98
100
  );
99
101
  compiler.cache.hooks.get.tap(
100
- { name: "MemoryWithGcCachePlugin", stage: Cache.STAGE_MEMORY },
102
+ { name: PLUGIN_NAME, stage: Cache.STAGE_MEMORY },
101
103
  (identifier, etag, gotHandlers) => {
102
104
  const cacheEntry = cache.get(identifier);
103
105
  if (cacheEntry === null) {
@@ -129,7 +131,7 @@ class MemoryWithGcCachePlugin {
129
131
  }
130
132
  );
131
133
  compiler.cache.hooks.shutdown.tap(
132
- { name: "MemoryWithGcCachePlugin", stage: Cache.STAGE_MEMORY },
134
+ { name: PLUGIN_NAME, stage: Cache.STAGE_MEMORY },
133
135
  () => {
134
136
  cache.clear();
135
137
  oldCache.clear();
@@ -97,6 +97,8 @@ const objectToString = (object, excludeContext) => {
97
97
 
98
98
  /** @typedef {NonNullable<ResolveContext["yield"]>} Yield */
99
99
 
100
+ const PLUGIN_NAME = "ResolverCachePlugin";
101
+
100
102
  class ResolverCachePlugin {
101
103
  /**
102
104
  * Apply the plugin
@@ -104,7 +106,7 @@ class ResolverCachePlugin {
104
106
  * @returns {void}
105
107
  */
106
108
  apply(compiler) {
107
- const cache = compiler.getCache("ResolverCachePlugin");
109
+ const cache = compiler.getCache(PLUGIN_NAME);
108
110
  /** @type {FileSystemInfo} */
109
111
  let fileSystemInfo;
110
112
  /** @type {SnapshotOptions | undefined} */
@@ -113,12 +115,12 @@ class ResolverCachePlugin {
113
115
  let cachedResolves = 0;
114
116
  let cacheInvalidResolves = 0;
115
117
  let concurrentResolves = 0;
116
- compiler.hooks.thisCompilation.tap("ResolverCachePlugin", compilation => {
118
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
117
119
  snapshotOptions = compilation.options.snapshot.resolve;
118
120
  fileSystemInfo = compilation.fileSystemInfo;
119
- compilation.hooks.finishModules.tap("ResolverCachePlugin", () => {
121
+ compilation.hooks.finishModules.tap(PLUGIN_NAME, () => {
120
122
  if (realResolves + cachedResolves > 0) {
121
- const logger = compilation.getLogger("webpack.ResolverCachePlugin");
123
+ const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
122
124
  logger.log(
123
125
  `${Math.round(
124
126
  (100 * realResolves) / (realResolves + cachedResolves)
@@ -260,7 +262,7 @@ class ResolverCachePlugin {
260
262
  const hook =
261
263
  /** @type {SyncHook<[Resolver, ResolveOptions, ResolveOptionsWithDependencyType]>} */
262
264
  (_hook);
263
- hook.tap("ResolverCachePlugin", (resolver, options, userOptions) => {
265
+ hook.tap(PLUGIN_NAME, (resolver, options, userOptions) => {
264
266
  if (
265
267
  /** @type {ResolveOptions & { cache: boolean }} */
266
268
  (options).cache !== true
@@ -273,7 +275,7 @@ class ResolverCachePlugin {
273
275
  : false;
274
276
  resolver.hooks.resolve.tapAsync(
275
277
  {
276
- name: "ResolverCachePlugin",
278
+ name: PLUGIN_NAME,
277
279
  stage: -100
278
280
  },
279
281
  (request, resolveContext, callback) => {
package/lib/cli.js CHANGED
@@ -8,7 +8,11 @@
8
8
  const path = require("path");
9
9
  const webpackSchema = require("../schemas/WebpackOptions.json");
10
10
 
11
- /** @typedef {Parameters<import("schema-utils").validate>[0] & { absolutePath: boolean, instanceof: string, cli: { helper?: boolean, exclude?: boolean, description?: string, negatedDescription?: string, resetDescription?: string } }} Schema */
11
+ /** @typedef {import("json-schema").JSONSchema4} JSONSchema4 */
12
+ /** @typedef {import("json-schema").JSONSchema6} JSONSchema6 */
13
+ /** @typedef {import("json-schema").JSONSchema7} JSONSchema7 */
14
+ /** @typedef {JSONSchema4 | JSONSchema6 | JSONSchema7} JSONSchema */
15
+ /** @typedef {JSONSchema & { absolutePath: boolean, instanceof: string, cli: { helper?: boolean, exclude?: boolean, description?: string, negatedDescription?: string, resetDescription?: string } }} Schema */
12
16
 
13
17
  // TODO add originPath to PathItem for better errors
14
18
  /**
@@ -648,11 +648,14 @@ const applyModuleDefaults = (
648
648
  "unsafeCache",
649
649
  /**
650
650
  * @param {Module} module module
651
- * @returns {boolean | null | string} true, if we want to cache the module
651
+ * @returns {boolean} true, if we want to cache the module
652
652
  */
653
653
  module => {
654
654
  const name = module.nameForCondition();
655
- return name && NODE_MODULES_REGEXP.test(name);
655
+ if (!name) {
656
+ return false;
657
+ }
658
+ return NODE_MODULES_REGEXP.test(name);
656
659
  }
657
660
  );
658
661
  } else {
@@ -683,7 +686,8 @@ const applyModuleDefaults = (
683
686
  F(module.parser, "javascript", () => ({}));
684
687
  F(module.parser, JSON_MODULE_TYPE, () => ({}));
685
688
  D(
686
- module.parser[JSON_MODULE_TYPE],
689
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown[JSON_MODULE_TYPE]>} */
690
+ (module.parser[JSON_MODULE_TYPE]),
687
691
  "exportsDepth",
688
692
  mode === "development" ? 1 : Infinity
689
693
  );
@@ -1551,7 +1555,7 @@ const applyOptimizationDefaults = (
1551
1555
  passes: 2
1552
1556
  }
1553
1557
  }
1554
- }).apply(/** @type {TODO} */ (compiler));
1558
+ }).apply(/** @type {EXPECTED_ANY} */ (compiler));
1555
1559
  }
1556
1560
  }
1557
1561
  ]);
@@ -1726,8 +1730,8 @@ const getResolveLoaderDefaults = ({ cache }) => {
1726
1730
  const applyInfrastructureLoggingDefaults = infrastructureLogging => {
1727
1731
  F(infrastructureLogging, "stream", () => process.stderr);
1728
1732
  const tty =
1729
- /** @type {EXPECTED_ANY} */ (infrastructureLogging.stream).isTTY &&
1730
- process.env.TERM !== "dumb";
1733
+ /** @type {NonNullable<InfrastructureLogging["stream"]>} */
1734
+ (infrastructureLogging.stream).isTTY && process.env.TERM !== "dumb";
1731
1735
  D(infrastructureLogging, "level", "info");
1732
1736
  D(infrastructureLogging, "debug", false);
1733
1737
  D(infrastructureLogging, "colors", tty);
@@ -22,6 +22,7 @@ const util = require("util");
22
22
  /** @typedef {import("../../declarations/WebpackOptions").WebpackOptions} WebpackOptions */
23
23
  /** @typedef {import("../../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptionsNormalized */
24
24
  /** @typedef {import("../Entrypoint")} Entrypoint */
25
+ /** @typedef {import("../WebpackError")} WebpackError */
25
26
 
26
27
  const handledDeprecatedNoEmitOnErrors = util.deprecate(
27
28
  /**
@@ -210,14 +211,19 @@ const getNormalizedWebpackOptions = config => ({
210
211
  }
211
212
  if (
212
213
  i.module &&
213
- (!warning.module ||
214
+ (!(/** @type {WebpackError} */ (warning).module) ||
214
215
  !i.module.test(
215
- warning.module.readableIdentifier(requestShortener)
216
+ /** @type {WebpackError} */
217
+ (warning).module.readableIdentifier(requestShortener)
216
218
  ))
217
219
  ) {
218
220
  return false;
219
221
  }
220
- if (i.file && (!warning.file || !i.file.test(warning.file))) {
222
+ if (
223
+ i.file &&
224
+ (!(/** @type {WebpackError} */ (warning).file) ||
225
+ !i.file.test(/** @type {WebpackError} */ (warning).file))
226
+ ) {
221
227
  return false;
222
228
  }
223
229
  return true;
@@ -543,16 +549,16 @@ const getNormalizedOptimizationRuntimeChunk = runtimeChunk => {
543
549
  }
544
550
  if (runtimeChunk === true || runtimeChunk === "multiple") {
545
551
  return {
546
- /**
547
- * @param {Entrypoint} entrypoint entrypoint
548
- * @returns {string} runtime chunk name
549
- */
550
552
  name: entrypoint => `runtime~${entrypoint.name}`
551
553
  };
552
554
  }
553
555
  const { name } = runtimeChunk;
554
556
  return {
555
- name: typeof name === "function" ? name : () => name
557
+ name:
558
+ typeof name === "function"
559
+ ? /** @type {Exclude<OptimizationRuntimeChunkNormalized, false>["name"]} */
560
+ (name)
561
+ : () => /** @type {string} */ (name)
556
562
  };
557
563
  };
558
564
 
@@ -31,6 +31,7 @@ const validate = createSchemaValidation(
31
31
  );
32
32
 
33
33
  const slashCode = "/".charCodeAt(0);
34
+ const PLUGIN_NAME = "ContainerReferencePlugin";
34
35
 
35
36
  class ContainerReferencePlugin {
36
37
  /**
@@ -79,7 +80,7 @@ class ContainerReferencePlugin {
79
80
  new ExternalsPlugin(remoteType, remoteExternals).apply(compiler);
80
81
 
81
82
  compiler.hooks.compilation.tap(
82
- "ContainerReferencePlugin",
83
+ PLUGIN_NAME,
83
84
  (compilation, { normalModuleFactory }) => {
84
85
  compilation.dependencyFactories.set(
85
86
  RemoteToExternalDependency,
@@ -96,37 +97,34 @@ class ContainerReferencePlugin {
96
97
  new FallbackModuleFactory()
97
98
  );
98
99
 
99
- normalModuleFactory.hooks.factorize.tap(
100
- "ContainerReferencePlugin",
101
- data => {
102
- if (!data.request.includes("!")) {
103
- for (const [key, config] of remotes) {
104
- if (
105
- data.request.startsWith(`${key}`) &&
106
- (data.request.length === key.length ||
107
- data.request.charCodeAt(key.length) === slashCode)
108
- ) {
109
- return new RemoteModule(
110
- data.request,
111
- config.external.map((external, i) =>
112
- external.startsWith("internal ")
113
- ? external.slice(9)
114
- : `webpack/container/reference/${key}${
115
- i ? `/fallback-${i}` : ""
116
- }`
117
- ),
118
- `.${data.request.slice(key.length)}`,
119
- config.shareScope
120
- );
121
- }
100
+ normalModuleFactory.hooks.factorize.tap(PLUGIN_NAME, data => {
101
+ if (!data.request.includes("!")) {
102
+ for (const [key, config] of remotes) {
103
+ if (
104
+ data.request.startsWith(`${key}`) &&
105
+ (data.request.length === key.length ||
106
+ data.request.charCodeAt(key.length) === slashCode)
107
+ ) {
108
+ return new RemoteModule(
109
+ data.request,
110
+ config.external.map((external, i) =>
111
+ external.startsWith("internal ")
112
+ ? external.slice(9)
113
+ : `webpack/container/reference/${key}${
114
+ i ? `/fallback-${i}` : ""
115
+ }`
116
+ ),
117
+ `.${data.request.slice(key.length)}`,
118
+ config.shareScope
119
+ );
122
120
  }
123
121
  }
124
122
  }
125
- );
123
+ });
126
124
 
127
125
  compilation.hooks.runtimeRequirementInTree
128
126
  .for(RuntimeGlobals.ensureChunkHandlers)
129
- .tap("ContainerReferencePlugin", (chunk, set) => {
127
+ .tap(PLUGIN_NAME, (chunk, set) => {
130
128
  set.add(RuntimeGlobals.module);
131
129
  set.add(RuntimeGlobals.moduleFactoriesAddOnly);
132
130
  set.add(RuntimeGlobals.hasOwnProperty);
@@ -37,6 +37,7 @@ const validate = createSchemaValidation(
37
37
 
38
38
  /** @type {WeakMap<Compilation, CompilationHooks>} */
39
39
  const compilationHooksMap = new WeakMap();
40
+ const PLUGIN_NAME = "ModuleFederationPlugin";
40
41
 
41
42
  class ModuleFederationPlugin {
42
43
  /**
@@ -89,7 +90,7 @@ class ModuleFederationPlugin {
89
90
  ) {
90
91
  compiler.options.output.enabledLibraryTypes.push(library.type);
91
92
  }
92
- compiler.hooks.afterPlugins.tap("ModuleFederationPlugin", () => {
93
+ compiler.hooks.afterPlugins.tap(PLUGIN_NAME, () => {
93
94
  if (
94
95
  options.exposes &&
95
96
  (Array.isArray(options.exposes)
@@ -292,7 +292,7 @@ class CssGenerator extends Generator {
292
292
  Array.from(exports).reduce((obj, [key, value]) => {
293
293
  obj[key] = value;
294
294
  return obj;
295
- }, {})
295
+ }, /** @type {Record<string, string>} */ ({}))
296
296
  );
297
297
 
298
298
  return stringifiedExports.length + 42;
@@ -48,6 +48,7 @@ const CssGenerator = require("./CssGenerator");
48
48
  const CssParser = require("./CssParser");
49
49
 
50
50
  /** @typedef {import("webpack-sources").Source} Source */
51
+ /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
51
52
  /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
52
53
  /** @typedef {import("../Chunk")} Chunk */
53
54
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
@@ -60,7 +61,6 @@ const CssParser = require("./CssParser");
60
61
  /** @typedef {import("../Template").RuntimeTemplate} RuntimeTemplate */
61
62
  /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
62
63
  /** @typedef {import("../util/Hash")} Hash */
63
- /** @typedef {import("../util/createHash").Algorithm} Algorithm */
64
64
  /** @typedef {import("../util/memoize")} Memoize */
65
65
 
66
66
  /**
@@ -385,15 +385,17 @@ class CssModulesPlugin {
385
385
  compilation
386
386
  ).renderModuleContent.tap(PLUGIN_NAME, (source, module) => {
387
387
  if (module instanceof CssModule && module.hot) {
388
- const exports =
389
- /** @type {BuildInfo} */
390
- (module.buildInfo).cssData.exports;
388
+ const cssData = /** @type {BuildInfo} */ (module.buildInfo).cssData;
389
+ if (!cssData) {
390
+ return source;
391
+ }
392
+ const exports = cssData.exports;
391
393
  const stringifiedExports = JSON.stringify(
392
394
  JSON.stringify(
393
395
  Array.from(exports).reduce((obj, [key, value]) => {
394
396
  obj[key] = value;
395
397
  return obj;
396
- }, {})
398
+ }, /** @type {Record<string, string>} */ ({}))
397
399
  )
398
400
  );
399
401
 
@@ -442,7 +444,7 @@ class CssModulesPlugin {
442
444
  hashFunction
443
445
  }
444
446
  } = compilation;
445
- const hash = createHash(/** @type {Algorithm} */ (hashFunction));
447
+ const hash = createHash(/** @type {HashFunction} */ (hashFunction));
446
448
  if (hashSalt) hash.update(hashSalt);
447
449
  hooks.chunkHash.call(chunk, hash, {
448
450
  chunkGraph,
@@ -14,6 +14,7 @@ const {
14
14
  const createSchemaValidation = require("../util/create-schema-validation");
15
15
  const { dirname, mkdirpSync } = require("../util/fs");
16
16
 
17
+ /** @typedef {import("inspector").Session} Session */
17
18
  /** @typedef {import("tapable").FullTap} FullTap */
18
19
  /** @typedef {import("../../declarations/plugins/debug/ProfilingPlugin").ProfilingPluginOptions} ProfilingPluginOptions */
19
20
  /** @typedef {import("../Compilation")} Compilation */
@@ -25,8 +26,6 @@ const { dirname, mkdirpSync } = require("../util/fs");
25
26
  /** @typedef {import("../ResolverFactory")} ResolverFactory */
26
27
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
27
28
 
28
- /** @typedef {TODO} Inspector */
29
-
30
29
  const validate = createSchemaValidation(
31
30
  require("../../schemas/plugins/debug/ProfilingPlugin.check.js"),
32
31
  () => require("../../schemas/plugins/debug/ProfilingPlugin.json"),
@@ -36,6 +35,8 @@ const validate = createSchemaValidation(
36
35
  }
37
36
  );
38
37
 
38
+ /** @typedef {{ Session: typeof import("inspector").Session }} Inspector */
39
+
39
40
  /** @type {Inspector | undefined} */
40
41
  let inspector;
41
42
 
@@ -52,6 +53,7 @@ class Profiler {
52
53
  * @param {Inspector} inspector inspector
53
54
  */
54
55
  constructor(inspector) {
56
+ /** @type {undefined | Session} */
55
57
  this.session = undefined;
56
58
  this.inspector = inspector;
57
59
  this._startTime = 0;
@@ -67,8 +69,9 @@ class Profiler {
67
69
  }
68
70
 
69
71
  try {
70
- this.session = new inspector.Session();
71
- this.session.connect();
72
+ this.session = new /** @type {Inspector} */ (inspector).Session();
73
+ /** @type {Session} */
74
+ (this.session).connect();
72
75
  } catch (_) {
73
76
  this.session = undefined;
74
77
  return Promise.resolve();
@@ -88,27 +91,20 @@ class Profiler {
88
91
 
89
92
  /**
90
93
  * @param {string} method method name
91
- * @param {Record<string, EXPECTED_ANY>=} params params
92
- * @returns {Promise<TODO>} Promise for the result
94
+ * @param {EXPECTED_OBJECT=} params params
95
+ * @returns {Promise<EXPECTED_ANY | void>} Promise for the result
93
96
  */
94
97
  sendCommand(method, params) {
95
98
  if (this.hasSession()) {
96
99
  return new Promise((res, rej) => {
97
- this.session.post(
98
- method,
99
- params,
100
- /**
101
- * @param {Error | null} err error
102
- * @param {object} params params
103
- */
104
- (err, params) => {
105
- if (err !== null) {
106
- rej(err);
107
- } else {
108
- res(params);
109
- }
100
+ /** @type {Session} */
101
+ (this.session).post(method, params, (err, params) => {
102
+ if (err !== null) {
103
+ rej(err);
104
+ } else {
105
+ res(params);
110
106
  }
111
- );
107
+ });
112
108
  });
113
109
  }
114
110
  return Promise.resolve();
@@ -116,7 +112,8 @@ class Profiler {
116
112
 
117
113
  destroy() {
118
114
  if (this.hasSession()) {
119
- this.session.disconnect();
115
+ /** @type {Session} */
116
+ (this.session).disconnect();
120
117
  }
121
118
 
122
119
  return Promise.resolve();
@@ -204,7 +204,7 @@ class CommonJsImportsParserPlugin {
204
204
  {
205
205
  request: /** @type {string} */ (options.unknownContextRequest),
206
206
  recursive: /** @type {boolean} */ (options.unknownContextRecursive),
207
- regExp: /** @type {TODO} */ (options.unknownContextRegExp),
207
+ regExp: /** @type {RegExp} */ (options.unknownContextRegExp),
208
208
  mode: "sync"
209
209
  },
210
210
  /** @type {Range} */ (expr.range),
@@ -22,7 +22,7 @@ const ModuleDependency = require("./ModuleDependency");
22
22
  class ContextElementDependency extends ModuleDependency {
23
23
  /**
24
24
  * @param {string} request request
25
- * @param {string|undefined} userRequest user request
25
+ * @param {string | undefined} userRequest user request
26
26
  * @param {string | undefined} typePrefix type prefix
27
27
  * @param {string} category category
28
28
  * @param {(string[][] | null)=} referencedExports referenced exports
@@ -15,6 +15,7 @@ const NullDependency = require("./NullDependency");
15
15
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
16
16
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
17
17
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
18
+ /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
18
19
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
19
20
  /** @typedef {import("../CssModule")} CssModule */
20
21
  /** @typedef {import("../Dependency")} Dependency */
@@ -29,7 +30,6 @@ const NullDependency = require("./NullDependency");
29
30
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
30
31
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
31
32
  /** @typedef {import("../util/Hash")} Hash */
32
- /** @typedef {import("../util/createHash").Algorithm} Algorithm */
33
33
 
34
34
  const getCssParser = memoize(() => require("../css/CssParser"));
35
35
 
@@ -53,7 +53,7 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
53
53
  );
54
54
  const { hashFunction, hashDigest, hashDigestLength, hashSalt, uniqueName } =
55
55
  runtimeTemplate.outputOptions;
56
- const hash = createHash(/** @type {Algorithm} */ (hashFunction));
56
+ const hash = createHash(/** @type {HashFunction} */ (hashFunction));
57
57
 
58
58
  if (hashSalt) {
59
59
  hash.update(hashSalt);
@@ -15,6 +15,8 @@ const HarmonyExports = require("./HarmonyExports");
15
15
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
16
16
  /** @typedef {import("./HarmonyModulesPlugin").HarmonyModulesPluginOptions} HarmonyModulesPluginOptions */
17
17
 
18
+ const PLUGIN_NAME = "HarmonyDetectionParserPlugin";
19
+
18
20
  module.exports = class HarmonyDetectionParserPlugin {
19
21
  /**
20
22
  * @param {HarmonyModulesPluginOptions} options options
@@ -29,7 +31,7 @@ module.exports = class HarmonyDetectionParserPlugin {
29
31
  * @returns {void}
30
32
  */
31
33
  apply(parser) {
32
- parser.hooks.program.tap("HarmonyDetectionParserPlugin", ast => {
34
+ parser.hooks.program.tap(PLUGIN_NAME, ast => {
33
35
  const isStrictHarmony =
34
36
  parser.state.module.type === JAVASCRIPT_MODULE_TYPE_ESM;
35
37
  const isHarmony =
@@ -62,7 +64,7 @@ module.exports = class HarmonyDetectionParserPlugin {
62
64
  }
63
65
  });
64
66
 
65
- parser.hooks.topLevelAwait.tap("HarmonyDetectionParserPlugin", () => {
67
+ parser.hooks.topLevelAwait.tap(PLUGIN_NAME, () => {
66
68
  const module = parser.state.module;
67
69
  if (!this.topLevelAwait) {
68
70
  throw new Error(
@@ -105,19 +107,11 @@ module.exports = class HarmonyDetectionParserPlugin {
105
107
  for (const identifier of nonHarmonyIdentifiers) {
106
108
  parser.hooks.evaluateTypeof
107
109
  .for(identifier)
108
- .tap("HarmonyDetectionParserPlugin", nullInHarmony);
109
- parser.hooks.typeof
110
- .for(identifier)
111
- .tap("HarmonyDetectionParserPlugin", skipInHarmony);
112
- parser.hooks.evaluate
113
- .for(identifier)
114
- .tap("HarmonyDetectionParserPlugin", nullInHarmony);
115
- parser.hooks.expression
116
- .for(identifier)
117
- .tap("HarmonyDetectionParserPlugin", skipInHarmony);
118
- parser.hooks.call
119
- .for(identifier)
120
- .tap("HarmonyDetectionParserPlugin", skipInHarmony);
110
+ .tap(PLUGIN_NAME, nullInHarmony);
111
+ parser.hooks.typeof.for(identifier).tap(PLUGIN_NAME, skipInHarmony);
112
+ parser.hooks.evaluate.for(identifier).tap(PLUGIN_NAME, nullInHarmony);
113
+ parser.hooks.expression.for(identifier).tap(PLUGIN_NAME, skipInHarmony);
114
+ parser.hooks.call.for(identifier).tap(PLUGIN_NAME, skipInHarmony);
121
115
  }
122
116
  }
123
117
  };