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
@@ -57,6 +57,7 @@ const memoize = require("./util/memoize");
57
57
  /** @typedef {import("../declarations/WebpackOptions").Mode} Mode */
58
58
  /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
59
59
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
60
+ /** @typedef {import("../declarations/WebpackOptions").NoParse} NoParse */
60
61
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
61
62
  /** @typedef {import("./Compiler")} Compiler */
62
63
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
@@ -92,7 +93,7 @@ const memoize = require("./util/memoize");
92
93
  /** @typedef {import("./util/Hash")} Hash */
93
94
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
94
95
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
95
- /** @typedef {import("./util/createHash").Algorithm} Algorithm */
96
+ /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
96
97
  /** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
97
98
  /**
98
99
  * @template T
@@ -649,13 +650,13 @@ class NormalModule extends Module {
649
650
  ? getContextifyInContext()(request)
650
651
  : getContextify()(context, request),
651
652
  /**
652
- * @param {(string | typeof import("./util/Hash"))=} type type
653
+ * @param {HashFunction=} type type
653
654
  * @returns {Hash} hash
654
655
  */
655
656
  createHash: type =>
656
657
  createHash(
657
658
  type ||
658
- /** @type {Algorithm} */
659
+ /** @type {HashFunction} */
659
660
  (compilation.outputOptions.hashFunction)
660
661
  )
661
662
  };
@@ -803,7 +804,7 @@ class NormalModule extends Module {
803
804
  webpack: true,
804
805
  sourceMap: Boolean(this.useSourceMap),
805
806
  mode: options.mode || "production",
806
- hashFunction: /** @type {TODO} */ (options.output.hashFunction),
807
+ hashFunction: /** @type {string} */ (options.output.hashFunction),
807
808
  hashDigest: /** @type {string} */ (options.output.hashDigest),
808
809
  hashDigestLength: /** @type {number} */ (options.output.hashDigestLength),
809
810
  hashSalt: /** @type {string} */ (options.output.hashSalt),
@@ -1079,7 +1080,7 @@ class NormalModule extends Module {
1079
1080
  }
1080
1081
 
1081
1082
  /**
1082
- * @param {TODO} rule rule
1083
+ * @param {Exclude<NoParse, EXPECTED_ANY[]>} rule rule
1083
1084
  * @param {string} content content
1084
1085
  * @returns {boolean} result
1085
1086
  */
@@ -1097,7 +1098,7 @@ class NormalModule extends Module {
1097
1098
  }
1098
1099
 
1099
1100
  /**
1100
- * @param {TODO} noParseRule no parse rule
1101
+ * @param {undefined | NoParse} noParseRule no parse rule
1101
1102
  * @param {string} request request
1102
1103
  * @returns {boolean} check if module should not be parsed, returns "true" if the module should !not! be parsed, returns "false" if the module !must! be parsed
1103
1104
  */
@@ -1132,7 +1133,7 @@ class NormalModule extends Module {
1132
1133
  */
1133
1134
  _initBuildHash(compilation) {
1134
1135
  const hash = createHash(
1135
- /** @type {Algorithm} */
1136
+ /** @type {HashFunction} */
1136
1137
  (compilation.outputOptions.hashFunction)
1137
1138
  );
1138
1139
  if (this._source) {
@@ -1632,7 +1633,11 @@ class NormalModule extends Module {
1632
1633
  * @returns {void}
1633
1634
  */
1634
1635
  updateHash(hash, context) {
1635
- hash.update(/** @type {BuildInfo} */ (this.buildInfo).hash);
1636
+ const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
1637
+ hash.update(
1638
+ /** @type {string} */
1639
+ (buildInfo.hash)
1640
+ );
1636
1641
  /** @type {Generator} */
1637
1642
  (this.generator).updateHash(hash, {
1638
1643
  module: this,
@@ -13,6 +13,8 @@ const { join, dirname } = require("./util/fs");
13
13
 
14
14
  /** @typedef {(resolveData: ResolveData) => void} ModuleReplacer */
15
15
 
16
+ const PLUGIN_NAME = "NormalModuleReplacementPlugin";
17
+
16
18
  class NormalModuleReplacementPlugin {
17
19
  /**
18
20
  * Create an instance of the plugin
@@ -32,46 +34,41 @@ class NormalModuleReplacementPlugin {
32
34
  apply(compiler) {
33
35
  const resourceRegExp = this.resourceRegExp;
34
36
  const newResource = this.newResource;
35
- compiler.hooks.normalModuleFactory.tap(
36
- "NormalModuleReplacementPlugin",
37
- nmf => {
38
- nmf.hooks.beforeResolve.tap("NormalModuleReplacementPlugin", result => {
39
- if (resourceRegExp.test(result.request)) {
40
- if (typeof newResource === "function") {
41
- newResource(result);
42
- } else {
43
- result.request = newResource;
44
- }
37
+ compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, nmf => {
38
+ nmf.hooks.beforeResolve.tap(PLUGIN_NAME, result => {
39
+ if (resourceRegExp.test(result.request)) {
40
+ if (typeof newResource === "function") {
41
+ newResource(result);
42
+ } else {
43
+ result.request = newResource;
45
44
  }
46
- });
47
- nmf.hooks.afterResolve.tap("NormalModuleReplacementPlugin", result => {
48
- const createData = result.createData;
49
- if (
50
- resourceRegExp.test(/** @type {string} */ (createData.resource))
51
- ) {
52
- if (typeof newResource === "function") {
53
- newResource(result);
45
+ }
46
+ });
47
+ nmf.hooks.afterResolve.tap(PLUGIN_NAME, result => {
48
+ const createData = result.createData;
49
+ if (resourceRegExp.test(/** @type {string} */ (createData.resource))) {
50
+ if (typeof newResource === "function") {
51
+ newResource(result);
52
+ } else {
53
+ const fs =
54
+ /** @type {InputFileSystem} */
55
+ (compiler.inputFileSystem);
56
+ if (
57
+ newResource.startsWith("/") ||
58
+ (newResource.length > 1 && newResource[1] === ":")
59
+ ) {
60
+ createData.resource = newResource;
54
61
  } else {
55
- const fs =
56
- /** @type {InputFileSystem} */
57
- (compiler.inputFileSystem);
58
- if (
59
- newResource.startsWith("/") ||
60
- (newResource.length > 1 && newResource[1] === ":")
61
- ) {
62
- createData.resource = newResource;
63
- } else {
64
- createData.resource = join(
65
- fs,
66
- dirname(fs, /** @type {string} */ (createData.resource)),
67
- newResource
68
- );
69
- }
62
+ createData.resource = join(
63
+ fs,
64
+ dirname(fs, /** @type {string} */ (createData.resource)),
65
+ newResource
66
+ );
70
67
  }
71
68
  }
72
- });
73
- }
74
- );
69
+ }
70
+ });
71
+ });
75
72
  }
76
73
  }
77
74
 
@@ -8,6 +8,8 @@
8
8
  /** @typedef {import("./Compiler")} Compiler */
9
9
  /** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */
10
10
 
11
+ const PLUGIN_NAME = "PlatformPlugin";
12
+
11
13
  /**
12
14
  * Should be used only for "target === false" or
13
15
  * when you want to overwrite platform target properties
@@ -27,7 +29,7 @@ class PlatformPlugin {
27
29
  * @returns {void}
28
30
  */
29
31
  apply(compiler) {
30
- compiler.hooks.environment.tap("PlatformPlugin", () => {
32
+ compiler.hooks.environment.tap(PLUGIN_NAME, () => {
31
33
  compiler.platform = {
32
34
  ...compiler.platform,
33
35
  ...this.platform
@@ -9,6 +9,8 @@ const PrefetchDependency = require("./dependencies/PrefetchDependency");
9
9
 
10
10
  /** @typedef {import("./Compiler")} Compiler */
11
11
 
12
+ const PLUGIN_NAME = "PrefetchPlugin";
13
+
12
14
  class PrefetchPlugin {
13
15
  /**
14
16
  * @param {string} context context or request if context is not set
@@ -31,7 +33,7 @@ class PrefetchPlugin {
31
33
  */
32
34
  apply(compiler) {
33
35
  compiler.hooks.compilation.tap(
34
- "PrefetchPlugin",
36
+ PLUGIN_NAME,
35
37
  (compilation, { normalModuleFactory }) => {
36
38
  compilation.dependencyFactories.set(
37
39
  PrefetchDependency,
@@ -39,7 +41,7 @@ class PrefetchPlugin {
39
41
  );
40
42
  }
41
43
  );
42
- compiler.hooks.make.tapAsync("PrefetchPlugin", (compilation, callback) => {
44
+ compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
43
45
  compilation.addModuleChain(
44
46
  this.context || compiler.context,
45
47
  new PrefetchDependency(this.request),
@@ -140,6 +140,8 @@ const SKIPPED_QUEUE_CONTEXTS = ["import-module", "load-module"];
140
140
  /** @type {WeakMap<Compiler, ReportProgress | undefined>} */
141
141
  const progressReporters = new WeakMap();
142
142
 
143
+ const PLUGIN_NAME = "ProgressPlugin";
144
+
143
145
  class ProgressPlugin {
144
146
  /**
145
147
  * @param {Compiler} compiler the current compiler
@@ -395,14 +397,12 @@ class ProgressPlugin {
395
397
  update();
396
398
  };
397
399
 
398
- const cache = compiler
399
- .getCache("ProgressPlugin")
400
- .getItemCache("counts", null);
400
+ const cache = compiler.getCache(PLUGIN_NAME).getItemCache("counts", null);
401
401
 
402
402
  /** @type {Promise<CountsData> | undefined} */
403
403
  let cacheGetPromise;
404
404
 
405
- compiler.hooks.beforeCompile.tap("ProgressPlugin", () => {
405
+ compiler.hooks.beforeCompile.tap(PLUGIN_NAME, () => {
406
406
  if (!cacheGetPromise) {
407
407
  cacheGetPromise = cache.getPromise().then(
408
408
  data => {
@@ -420,7 +420,7 @@ class ProgressPlugin {
420
420
  }
421
421
  });
422
422
 
423
- compiler.hooks.afterCompile.tapPromise("ProgressPlugin", compilation => {
423
+ compiler.hooks.afterCompile.tapPromise(PLUGIN_NAME, compilation => {
424
424
  if (compilation.compiler.isChild()) return Promise.resolve();
425
425
  return /** @type {Promise<CountsData>} */ (cacheGetPromise).then(
426
426
  async oldData => {
@@ -442,7 +442,7 @@ class ProgressPlugin {
442
442
  );
443
443
  });
444
444
 
445
- compiler.hooks.compilation.tap("ProgressPlugin", compilation => {
445
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
446
446
  if (compilation.compiler.isChild()) return;
447
447
  lastModulesCount = modulesCount;
448
448
  lastEntriesCount = entriesCount;
@@ -455,35 +455,32 @@ class ProgressPlugin {
455
455
  0;
456
456
  doneModules = doneDependencies = doneEntries = 0;
457
457
 
458
- compilation.factorizeQueue.hooks.added.tap("ProgressPlugin", item =>
458
+ compilation.factorizeQueue.hooks.added.tap(PLUGIN_NAME, item =>
459
459
  factorizeAdd(compilation.factorizeQueue, item)
460
460
  );
461
- compilation.factorizeQueue.hooks.result.tap(
462
- "ProgressPlugin",
463
- factorizeDone
464
- );
461
+ compilation.factorizeQueue.hooks.result.tap(PLUGIN_NAME, factorizeDone);
465
462
 
466
- compilation.addModuleQueue.hooks.added.tap("ProgressPlugin", item =>
463
+ compilation.addModuleQueue.hooks.added.tap(PLUGIN_NAME, item =>
467
464
  moduleAdd(compilation.addModuleQueue, item)
468
465
  );
469
466
  compilation.processDependenciesQueue.hooks.result.tap(
470
- "ProgressPlugin",
467
+ PLUGIN_NAME,
471
468
  moduleDone
472
469
  );
473
470
 
474
471
  if (showActiveModules) {
475
- compilation.hooks.buildModule.tap("ProgressPlugin", moduleBuild);
472
+ compilation.hooks.buildModule.tap(PLUGIN_NAME, moduleBuild);
476
473
  }
477
474
 
478
- compilation.hooks.addEntry.tap("ProgressPlugin", entryAdd);
479
- compilation.hooks.failedEntry.tap("ProgressPlugin", entryDone);
480
- compilation.hooks.succeedEntry.tap("ProgressPlugin", entryDone);
475
+ compilation.hooks.addEntry.tap(PLUGIN_NAME, entryAdd);
476
+ compilation.hooks.failedEntry.tap(PLUGIN_NAME, entryDone);
477
+ compilation.hooks.succeedEntry.tap(PLUGIN_NAME, entryDone);
481
478
 
482
479
  // @ts-expect-error avoid dynamic require if bundled with webpack
483
480
  if (typeof __webpack_require__ !== "function") {
484
481
  const requiredLoaders = new Set();
485
482
  NormalModule.getCompilationHooks(compilation).beforeLoaders.tap(
486
- "ProgressPlugin",
483
+ PLUGIN_NAME,
487
484
  loaders => {
488
485
  for (const loader of loaders) {
489
486
  if (
@@ -550,7 +547,7 @@ class ProgressPlugin {
550
547
  const title = hooks[/** @type {keyof typeof hooks} */ (name)];
551
548
  const percentage = (idx / numberOfHooks) * 0.25 + 0.7;
552
549
  compilation.hooks[/** @type {keyof typeof hooks} */ (name)].intercept({
553
- name: "ProgressPlugin",
550
+ name: PLUGIN_NAME,
554
551
  call() {
555
552
  handler(percentage, "sealing", title);
556
553
  },
@@ -576,7 +573,7 @@ class ProgressPlugin {
576
573
  }
577
574
  });
578
575
  compiler.hooks.make.intercept({
579
- name: "ProgressPlugin",
576
+ name: PLUGIN_NAME,
580
577
  call() {
581
578
  handler(0.1, "building");
582
579
  },
@@ -592,7 +589,7 @@ class ProgressPlugin {
592
589
  */
593
590
  const interceptHook = (hook, progress, category, name) => {
594
591
  hook.intercept({
595
- name: "ProgressPlugin",
592
+ name: PLUGIN_NAME,
596
593
  call() {
597
594
  handler(progress, category, name);
598
595
  },
@@ -618,14 +615,14 @@ class ProgressPlugin {
618
615
  });
619
616
  };
620
617
  compiler.cache.hooks.endIdle.intercept({
621
- name: "ProgressPlugin",
618
+ name: PLUGIN_NAME,
622
619
  call() {
623
620
  handler(0, "");
624
621
  }
625
622
  });
626
623
  interceptHook(compiler.cache.hooks.endIdle, 0.01, "cache", "end idle");
627
624
  compiler.hooks.beforeRun.intercept({
628
- name: "ProgressPlugin",
625
+ name: PLUGIN_NAME,
629
626
  call() {
630
627
  handler(0, "");
631
628
  }
@@ -659,7 +656,7 @@ class ProgressPlugin {
659
656
  interceptHook(compiler.hooks.afterEmit, 0.98, "emitting", "after emit");
660
657
  interceptHook(compiler.hooks.done, 0.99, "done", "plugins");
661
658
  compiler.hooks.done.intercept({
662
- name: "ProgressPlugin",
659
+ name: PLUGIN_NAME,
663
660
  done() {
664
661
  handler(0.99, "");
665
662
  }
@@ -679,13 +676,13 @@ class ProgressPlugin {
679
676
  "closing watch compilation"
680
677
  );
681
678
  compiler.cache.hooks.beginIdle.intercept({
682
- name: "ProgressPlugin",
679
+ name: PLUGIN_NAME,
683
680
  done() {
684
681
  handler(1, "");
685
682
  }
686
683
  });
687
684
  compiler.cache.hooks.shutdown.intercept({
688
- name: "ProgressPlugin",
685
+ name: PLUGIN_NAME,
689
686
  done() {
690
687
  handler(1, "");
691
688
  }
@@ -37,6 +37,8 @@ const identifierUtils = require("./util/identifier");
37
37
  * @property {boolean=} portableIds true, when ids need to be portable
38
38
  */
39
39
 
40
+ const PLUGIN_NAME = "RecordIdsPlugin";
41
+
40
42
  class RecordIdsPlugin {
41
43
  /**
42
44
  * @param {RecordIdsPluginOptions=} options object
@@ -69,59 +71,43 @@ class RecordIdsPlugin {
69
71
  return module.identifier();
70
72
  };
71
73
 
72
- compiler.hooks.compilation.tap("RecordIdsPlugin", compilation => {
73
- compilation.hooks.recordModules.tap(
74
- "RecordIdsPlugin",
75
- /**
76
- * @param {Iterable<Module>} modules the modules array
77
- * @param {Records} records the records object
78
- * @returns {void}
79
- */
80
- (modules, records) => {
74
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
75
+ compilation.hooks.recordModules.tap(PLUGIN_NAME, (modules, records) => {
76
+ const chunkGraph = compilation.chunkGraph;
77
+ if (!records.modules) records.modules = {};
78
+ if (!records.modules.byIdentifier) records.modules.byIdentifier = {};
79
+ /** @type {Set<number>} */
80
+ const usedIds = new Set();
81
+ for (const module of modules) {
82
+ const moduleId = chunkGraph.getModuleId(module);
83
+ if (typeof moduleId !== "number") continue;
84
+ const identifier = getModuleIdentifier(module);
85
+ records.modules.byIdentifier[identifier] = moduleId;
86
+ usedIds.add(moduleId);
87
+ }
88
+ records.modules.usedIds = Array.from(usedIds).sort(compareNumbers);
89
+ });
90
+ compilation.hooks.reviveModules.tap(PLUGIN_NAME, (modules, records) => {
91
+ if (!records.modules) return;
92
+ if (records.modules.byIdentifier) {
81
93
  const chunkGraph = compilation.chunkGraph;
82
- if (!records.modules) records.modules = {};
83
- if (!records.modules.byIdentifier) records.modules.byIdentifier = {};
84
94
  /** @type {Set<number>} */
85
95
  const usedIds = new Set();
86
96
  for (const module of modules) {
87
97
  const moduleId = chunkGraph.getModuleId(module);
88
- if (typeof moduleId !== "number") continue;
98
+ if (moduleId !== null) continue;
89
99
  const identifier = getModuleIdentifier(module);
90
- records.modules.byIdentifier[identifier] = moduleId;
91
- usedIds.add(moduleId);
100
+ const id = records.modules.byIdentifier[identifier];
101
+ if (id === undefined) continue;
102
+ if (usedIds.has(id)) continue;
103
+ usedIds.add(id);
104
+ chunkGraph.setModuleId(module, id);
92
105
  }
93
- records.modules.usedIds = Array.from(usedIds).sort(compareNumbers);
94
106
  }
95
- );
96
- compilation.hooks.reviveModules.tap(
97
- "RecordIdsPlugin",
98
- /**
99
- * @param {Iterable<Module>} modules the modules array
100
- * @param {Records} records the records object
101
- * @returns {void}
102
- */
103
- (modules, records) => {
104
- if (!records.modules) return;
105
- if (records.modules.byIdentifier) {
106
- const chunkGraph = compilation.chunkGraph;
107
- /** @type {Set<number>} */
108
- const usedIds = new Set();
109
- for (const module of modules) {
110
- const moduleId = chunkGraph.getModuleId(module);
111
- if (moduleId !== null) continue;
112
- const identifier = getModuleIdentifier(module);
113
- const id = records.modules.byIdentifier[identifier];
114
- if (id === undefined) continue;
115
- if (usedIds.has(id)) continue;
116
- usedIds.add(id);
117
- chunkGraph.setModuleId(module, id);
118
- }
119
- }
120
- if (Array.isArray(records.modules.usedIds)) {
121
- compilation.usedModuleIds = new Set(records.modules.usedIds);
122
- }
107
+ if (Array.isArray(records.modules.usedIds)) {
108
+ compilation.usedModuleIds = new Set(records.modules.usedIds);
123
109
  }
124
- );
110
+ });
125
111
 
126
112
  /**
127
113
  * @param {Chunk} chunk the chunk
@@ -167,75 +153,59 @@ class RecordIdsPlugin {
167
153
  return sources;
168
154
  };
169
155
 
170
- compilation.hooks.recordChunks.tap(
171
- "RecordIdsPlugin",
172
- /**
173
- * @param {Iterable<Chunk>} chunks the chunks array
174
- * @param {Records} records the records object
175
- * @returns {void}
176
- */
177
- (chunks, records) => {
178
- if (!records.chunks) records.chunks = {};
179
- if (!records.chunks.byName) records.chunks.byName = {};
180
- if (!records.chunks.bySource) records.chunks.bySource = {};
181
- /** @type {Set<number>} */
182
- const usedIds = new Set();
156
+ compilation.hooks.recordChunks.tap(PLUGIN_NAME, (chunks, records) => {
157
+ if (!records.chunks) records.chunks = {};
158
+ if (!records.chunks.byName) records.chunks.byName = {};
159
+ if (!records.chunks.bySource) records.chunks.bySource = {};
160
+ /** @type {Set<number>} */
161
+ const usedIds = new Set();
162
+ for (const chunk of chunks) {
163
+ if (typeof chunk.id !== "number") continue;
164
+ const name = chunk.name;
165
+ if (name) records.chunks.byName[name] = chunk.id;
166
+ const sources = getChunkSources(chunk);
167
+ for (const source of sources) {
168
+ records.chunks.bySource[source] = chunk.id;
169
+ }
170
+ usedIds.add(chunk.id);
171
+ }
172
+ records.chunks.usedIds = Array.from(usedIds).sort(compareNumbers);
173
+ });
174
+ compilation.hooks.reviveChunks.tap(PLUGIN_NAME, (chunks, records) => {
175
+ if (!records.chunks) return;
176
+ /** @type {Set<number>} */
177
+ const usedIds = new Set();
178
+ if (records.chunks.byName) {
183
179
  for (const chunk of chunks) {
184
- if (typeof chunk.id !== "number") continue;
185
- const name = chunk.name;
186
- if (name) records.chunks.byName[name] = chunk.id;
187
- const sources = getChunkSources(chunk);
188
- for (const source of sources) {
189
- records.chunks.bySource[source] = chunk.id;
190
- }
191
- usedIds.add(chunk.id);
180
+ if (chunk.id !== null) continue;
181
+ if (!chunk.name) continue;
182
+ const id = records.chunks.byName[chunk.name];
183
+ if (id === undefined) continue;
184
+ if (usedIds.has(id)) continue;
185
+ usedIds.add(id);
186
+ chunk.id = id;
187
+ chunk.ids = [id];
192
188
  }
193
- records.chunks.usedIds = Array.from(usedIds).sort(compareNumbers);
194
189
  }
195
- );
196
- compilation.hooks.reviveChunks.tap(
197
- "RecordIdsPlugin",
198
- /**
199
- * @param {Iterable<Chunk>} chunks the chunks array
200
- * @param {Records} records the records object
201
- * @returns {void}
202
- */
203
- (chunks, records) => {
204
- if (!records.chunks) return;
205
- /** @type {Set<number>} */
206
- const usedIds = new Set();
207
- if (records.chunks.byName) {
208
- for (const chunk of chunks) {
209
- if (chunk.id !== null) continue;
210
- if (!chunk.name) continue;
211
- const id = records.chunks.byName[chunk.name];
190
+ if (records.chunks.bySource) {
191
+ for (const chunk of chunks) {
192
+ if (chunk.id !== null) continue;
193
+ const sources = getChunkSources(chunk);
194
+ for (const source of sources) {
195
+ const id = records.chunks.bySource[source];
212
196
  if (id === undefined) continue;
213
197
  if (usedIds.has(id)) continue;
214
198
  usedIds.add(id);
215
199
  chunk.id = id;
216
200
  chunk.ids = [id];
201
+ break;
217
202
  }
218
203
  }
219
- if (records.chunks.bySource) {
220
- for (const chunk of chunks) {
221
- if (chunk.id !== null) continue;
222
- const sources = getChunkSources(chunk);
223
- for (const source of sources) {
224
- const id = records.chunks.bySource[source];
225
- if (id === undefined) continue;
226
- if (usedIds.has(id)) continue;
227
- usedIds.add(id);
228
- chunk.id = id;
229
- chunk.ids = [id];
230
- break;
231
- }
232
- }
233
- }
234
- if (Array.isArray(records.chunks.usedIds)) {
235
- compilation.usedChunkIds = new Set(records.chunks.usedIds);
236
- }
237
204
  }
238
- );
205
+ if (Array.isArray(records.chunks.usedIds)) {
206
+ compilation.usedChunkIds = new Set(records.chunks.usedIds);
207
+ }
208
+ });
239
209
  });
240
210
  }
241
211
  }