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
@@ -32,6 +32,8 @@ const validate = createSchemaValidation(
32
32
 
33
33
  /** @typedef {{ path: string, data: DllReferencePluginOptionsManifest | undefined, error: Error | undefined }} CompilationDataItem */
34
34
 
35
+ const PLUGIN_NAME = "DllReferencePlugin";
36
+
35
37
  class DllReferencePlugin {
36
38
  /**
37
39
  * @param {DllReferencePluginOptions} options options object
@@ -50,7 +52,7 @@ class DllReferencePlugin {
50
52
  */
51
53
  apply(compiler) {
52
54
  compiler.hooks.compilation.tap(
53
- "DllReferencePlugin",
55
+ PLUGIN_NAME,
54
56
  (compilation, { normalModuleFactory }) => {
55
57
  compilation.dependencyFactories.set(
56
58
  DelegatedSourceDependency,
@@ -59,51 +61,48 @@ class DllReferencePlugin {
59
61
  }
60
62
  );
61
63
 
62
- compiler.hooks.beforeCompile.tapAsync(
63
- "DllReferencePlugin",
64
- (params, callback) => {
65
- if ("manifest" in this.options) {
66
- const manifest = this.options.manifest;
67
- if (typeof manifest === "string") {
68
- /** @type {InputFileSystem} */
69
- (compiler.inputFileSystem).readFile(manifest, (err, result) => {
70
- if (err) return callback(err);
71
- /** @type {CompilationDataItem} */
72
- const data = {
73
- path: manifest,
74
- data: undefined,
75
- error: undefined
76
- };
77
- // Catch errors parsing the manifest so that blank
78
- // or malformed manifest files don't kill the process.
79
- try {
80
- data.data = parseJson(
81
- /** @type {Buffer} */ (result).toString("utf-8")
82
- );
83
- } catch (parseErr) {
84
- // Store the error in the params so that it can
85
- // be added as a compilation error later on.
86
- const manifestPath = makePathsRelative(
87
- /** @type {string} */ (compiler.options.context),
88
- manifest,
89
- compiler.root
90
- );
91
- data.error = new DllManifestError(
92
- manifestPath,
93
- /** @type {Error} */ (parseErr).message
94
- );
95
- }
96
- this._compilationData.set(params, data);
97
- return callback();
98
- });
99
- return;
100
- }
64
+ compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (params, callback) => {
65
+ if ("manifest" in this.options) {
66
+ const manifest = this.options.manifest;
67
+ if (typeof manifest === "string") {
68
+ /** @type {InputFileSystem} */
69
+ (compiler.inputFileSystem).readFile(manifest, (err, result) => {
70
+ if (err) return callback(err);
71
+ /** @type {CompilationDataItem} */
72
+ const data = {
73
+ path: manifest,
74
+ data: undefined,
75
+ error: undefined
76
+ };
77
+ // Catch errors parsing the manifest so that blank
78
+ // or malformed manifest files don't kill the process.
79
+ try {
80
+ data.data = parseJson(
81
+ /** @type {Buffer} */ (result).toString("utf-8")
82
+ );
83
+ } catch (parseErr) {
84
+ // Store the error in the params so that it can
85
+ // be added as a compilation error later on.
86
+ const manifestPath = makePathsRelative(
87
+ /** @type {string} */ (compiler.options.context),
88
+ manifest,
89
+ compiler.root
90
+ );
91
+ data.error = new DllManifestError(
92
+ manifestPath,
93
+ /** @type {Error} */ (parseErr).message
94
+ );
95
+ }
96
+ this._compilationData.set(params, data);
97
+ return callback();
98
+ });
99
+ return;
101
100
  }
102
- return callback();
103
101
  }
104
- );
102
+ return callback();
103
+ });
105
104
 
106
- compiler.hooks.compile.tap("DllReferencePlugin", params => {
105
+ compiler.hooks.compile.tap(PLUGIN_NAME, params => {
107
106
  let name = this.options.name;
108
107
  let sourceType = this.options.sourceType;
109
108
  let resolvedContent =
@@ -154,27 +153,24 @@ class DllReferencePlugin {
154
153
  }).apply(normalModuleFactory);
155
154
  });
156
155
 
157
- compiler.hooks.compilation.tap(
158
- "DllReferencePlugin",
159
- (compilation, params) => {
160
- if ("manifest" in this.options) {
161
- const manifest = this.options.manifest;
162
- if (typeof manifest === "string") {
163
- const data = /** @type {CompilationDataItem} */ (
164
- this._compilationData.get(params)
156
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation, params) => {
157
+ if ("manifest" in this.options) {
158
+ const manifest = this.options.manifest;
159
+ if (typeof manifest === "string") {
160
+ const data = /** @type {CompilationDataItem} */ (
161
+ this._compilationData.get(params)
162
+ );
163
+ // If there was an error parsing the manifest file, add the
164
+ // error as a compilation error to make the compilation fail.
165
+ if (data.error) {
166
+ compilation.errors.push(
167
+ /** @type {DllManifestError} */ (data.error)
165
168
  );
166
- // If there was an error parsing the manifest file, add the
167
- // error as a compilation error to make the compilation fail.
168
- if (data.error) {
169
- compilation.errors.push(
170
- /** @type {DllManifestError} */ (data.error)
171
- );
172
- }
173
- compilation.fileDependencies.add(manifest);
174
169
  }
170
+ compilation.fileDependencies.add(manifest);
175
171
  }
176
172
  }
177
- );
173
+ });
178
174
  }
179
175
  }
180
176
 
@@ -15,6 +15,8 @@ const EntryDependency = require("./dependencies/EntryDependency");
15
15
  /** @typedef {import("../declarations/WebpackOptions").EntryStaticNormalized} EntryStatic */
16
16
  /** @typedef {import("./Compiler")} Compiler */
17
17
 
18
+ const PLUGIN_NAME = "DynamicEntryPlugin";
19
+
18
20
  class DynamicEntryPlugin {
19
21
  /**
20
22
  * @param {string} context the context path
@@ -32,7 +34,7 @@ class DynamicEntryPlugin {
32
34
  */
33
35
  apply(compiler) {
34
36
  compiler.hooks.compilation.tap(
35
- "DynamicEntryPlugin",
37
+ PLUGIN_NAME,
36
38
  (compilation, { normalModuleFactory }) => {
37
39
  compilation.dependencyFactories.set(
38
40
  EntryDependency,
@@ -41,7 +43,7 @@ class DynamicEntryPlugin {
41
43
  }
42
44
  );
43
45
 
44
- compiler.hooks.make.tapPromise("DynamicEntryPlugin", compilation =>
46
+ compiler.hooks.make.tapPromise(PLUGIN_NAME, compilation =>
45
47
  Promise.resolve(this.entry())
46
48
  .then(entry => {
47
49
  const promises = [];
@@ -10,13 +10,15 @@
10
10
  /** @typedef {import("./Compiler")} Compiler */
11
11
  /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
12
12
 
13
+ const PLUGIN_NAME = "EntryOptionPlugin";
14
+
13
15
  class EntryOptionPlugin {
14
16
  /**
15
17
  * @param {Compiler} compiler the compiler instance one is tapping into
16
18
  * @returns {void}
17
19
  */
18
20
  apply(compiler) {
19
- compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => {
21
+ compiler.hooks.entryOption.tap(PLUGIN_NAME, (context, entry) => {
20
22
  EntryOptionPlugin.applyEntryOption(compiler, context, entry);
21
23
  return true;
22
24
  });
@@ -10,6 +10,8 @@ const EntryDependency = require("./dependencies/EntryDependency");
10
10
  /** @typedef {import("./Compiler")} Compiler */
11
11
  /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
12
12
 
13
+ const PLUGIN_NAME = "EntryPlugin";
14
+
13
15
  class EntryPlugin {
14
16
  /**
15
17
  * An entry plugin which will handle creation of the EntryDependency
@@ -30,7 +32,7 @@ class EntryPlugin {
30
32
  */
31
33
  apply(compiler) {
32
34
  compiler.hooks.compilation.tap(
33
- "EntryPlugin",
35
+ PLUGIN_NAME,
34
36
  (compilation, { normalModuleFactory }) => {
35
37
  compilation.dependencyFactories.set(
36
38
  EntryDependency,
@@ -42,7 +44,7 @@ class EntryPlugin {
42
44
  const { entry, options, context } = this;
43
45
  const dep = EntryPlugin.createDependency(entry, options);
44
46
 
45
- compiler.hooks.make.tapAsync("EntryPlugin", (compilation, callback) => {
47
+ compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
46
48
  compilation.addEntry(context, dep, options, err => {
47
49
  callback(err);
48
50
  });
@@ -11,6 +11,8 @@ const WebpackError = require("./WebpackError");
11
11
  /** @typedef {import("./Compiler")} Compiler */
12
12
  /** @typedef {import("./DefinePlugin").CodeValue} CodeValue */
13
13
 
14
+ const PLUGIN_NAME = "EnvironmentPlugin";
15
+
14
16
  class EnvironmentPlugin {
15
17
  /**
16
18
  * @param {(string | string[] | Record<string, EXPECTED_ANY>)[]} keys keys
@@ -46,9 +48,9 @@ class EnvironmentPlugin {
46
48
  : this.defaultValues[key];
47
49
 
48
50
  if (value === undefined) {
49
- compiler.hooks.thisCompilation.tap("EnvironmentPlugin", compilation => {
51
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
50
52
  const error = new WebpackError(
51
- `EnvironmentPlugin - ${key} environment variable is undefined.\n\n` +
53
+ `${PLUGIN_NAME} - ${key} environment variable is undefined.\n\n` +
52
54
  "You can pass an object with default values to suppress this warning.\n" +
53
55
  "See https://webpack.js.org/plugins/environment-plugin for example."
54
56
  );
@@ -35,6 +35,8 @@ const devtoolWarning = new RawSource(`/*
35
35
  * @property {OutputOptions["devtoolModuleFilenameTemplate"]=} moduleFilenameTemplate module filename template
36
36
  */
37
37
 
38
+ const PLUGIN_NAME = "EvalDevToolModulePlugin";
39
+
38
40
  class EvalDevToolModulePlugin {
39
41
  /**
40
42
  * @param {EvalDevToolModulePluginOptions=} options options
@@ -53,10 +55,10 @@ class EvalDevToolModulePlugin {
53
55
  * @returns {void}
54
56
  */
55
57
  apply(compiler) {
56
- compiler.hooks.compilation.tap("EvalDevToolModulePlugin", compilation => {
58
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
57
59
  const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
58
60
  hooks.renderModuleContent.tap(
59
- "EvalDevToolModulePlugin",
61
+ PLUGIN_NAME,
60
62
  (source, module, { chunk, runtimeTemplate, chunkGraph }) => {
61
63
  const cacheEntry = cache.get(source);
62
64
  if (cacheEntry !== undefined) return cacheEntry;
@@ -103,20 +105,20 @@ class EvalDevToolModulePlugin {
103
105
  }
104
106
  );
105
107
  hooks.inlineInRuntimeBailout.tap(
106
- "EvalDevToolModulePlugin",
108
+ PLUGIN_NAME,
107
109
  () => "the eval devtool is used."
108
110
  );
109
111
  hooks.render.tap(
110
- "EvalDevToolModulePlugin",
112
+ PLUGIN_NAME,
111
113
  source => new ConcatSource(devtoolWarning, source)
112
114
  );
113
- hooks.chunkHash.tap("EvalDevToolModulePlugin", (chunk, hash) => {
114
- hash.update("EvalDevToolModulePlugin");
115
+ hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash) => {
116
+ hash.update(PLUGIN_NAME);
115
117
  hash.update("2");
116
118
  });
117
119
  if (compilation.outputOptions.trustedTypes) {
118
120
  compilation.hooks.additionalModuleRuntimeRequirements.tap(
119
- "EvalDevToolModulePlugin",
121
+ PLUGIN_NAME,
120
122
  (module, set, context) => {
121
123
  set.add(RuntimeGlobals.createScript);
122
124
  }
@@ -35,9 +35,11 @@ const devtoolWarning = new RawSource(`/*
35
35
  */
36
36
  `);
37
37
 
38
+ const PLUGIN_NAME = "EvalSourceMapDevToolPlugin";
39
+
38
40
  class EvalSourceMapDevToolPlugin {
39
41
  /**
40
- * @param {SourceMapDevToolPluginOptions|string} inputOptions Options object
42
+ * @param {SourceMapDevToolPluginOptions | string} inputOptions Options object
41
43
  */
42
44
  constructor(inputOptions) {
43
45
  /** @type {SourceMapDevToolPluginOptions} */
@@ -67,160 +69,157 @@ class EvalSourceMapDevToolPlugin {
67
69
  */
68
70
  apply(compiler) {
69
71
  const options = this.options;
70
- compiler.hooks.compilation.tap(
71
- "EvalSourceMapDevToolPlugin",
72
- compilation => {
73
- const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
74
- new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
75
- const matchModule = ModuleFilenameHelpers.matchObject.bind(
76
- ModuleFilenameHelpers,
77
- options
78
- );
79
- hooks.renderModuleContent.tap(
80
- "EvalSourceMapDevToolPlugin",
81
- (source, m, { chunk, runtimeTemplate, chunkGraph }) => {
82
- const cachedSource = cache.get(source);
83
- if (cachedSource !== undefined) {
84
- return cachedSource;
85
- }
72
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
73
+ const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation);
74
+ new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
75
+ const matchModule = ModuleFilenameHelpers.matchObject.bind(
76
+ ModuleFilenameHelpers,
77
+ options
78
+ );
79
+ hooks.renderModuleContent.tap(
80
+ PLUGIN_NAME,
81
+ (source, m, { chunk, runtimeTemplate, chunkGraph }) => {
82
+ const cachedSource = cache.get(source);
83
+ if (cachedSource !== undefined) {
84
+ return cachedSource;
85
+ }
86
86
 
87
- /**
88
- * @param {Source} r result
89
- * @returns {Source} result
90
- */
91
- const result = r => {
92
- cache.set(source, r);
93
- return r;
94
- };
95
-
96
- if (m instanceof NormalModule) {
97
- const module = /** @type {NormalModule} */ (m);
87
+ /**
88
+ * @param {Source} r result
89
+ * @returns {Source} result
90
+ */
91
+ const result = r => {
92
+ cache.set(source, r);
93
+ return r;
94
+ };
95
+
96
+ if (m instanceof NormalModule) {
97
+ const module = /** @type {NormalModule} */ (m);
98
+ if (!matchModule(module.resource)) {
99
+ return result(source);
100
+ }
101
+ } else if (m instanceof ConcatenatedModule) {
102
+ const concatModule = /** @type {ConcatenatedModule} */ (m);
103
+ if (concatModule.rootModule instanceof NormalModule) {
104
+ const module = /** @type {NormalModule} */ (
105
+ concatModule.rootModule
106
+ );
98
107
  if (!matchModule(module.resource)) {
99
108
  return result(source);
100
109
  }
101
- } else if (m instanceof ConcatenatedModule) {
102
- const concatModule = /** @type {ConcatenatedModule} */ (m);
103
- if (concatModule.rootModule instanceof NormalModule) {
104
- const module = /** @type {NormalModule} */ (
105
- concatModule.rootModule
106
- );
107
- if (!matchModule(module.resource)) {
108
- return result(source);
109
- }
110
- } else {
111
- return result(source);
112
- }
113
110
  } else {
114
111
  return result(source);
115
112
  }
113
+ } else {
114
+ return result(source);
115
+ }
116
116
 
117
- const namespace = compilation.getPath(this.namespace, {
118
- chunk
119
- });
120
- /** @type {SourceMap} */
121
- let sourceMap;
122
- let content;
123
- if (source.sourceAndMap) {
124
- const sourceAndMap = source.sourceAndMap(options);
125
- sourceMap = /** @type {SourceMap} */ (sourceAndMap.map);
126
- content = sourceAndMap.source;
127
- } else {
128
- sourceMap = /** @type {SourceMap} */ (source.map(options));
129
- content = source.source();
130
- }
131
- if (!sourceMap) {
132
- return result(source);
133
- }
117
+ const namespace = compilation.getPath(this.namespace, {
118
+ chunk
119
+ });
120
+ /** @type {SourceMap} */
121
+ let sourceMap;
122
+ let content;
123
+ if (source.sourceAndMap) {
124
+ const sourceAndMap = source.sourceAndMap(options);
125
+ sourceMap = /** @type {SourceMap} */ (sourceAndMap.map);
126
+ content = sourceAndMap.source;
127
+ } else {
128
+ sourceMap = /** @type {SourceMap} */ (source.map(options));
129
+ content = source.source();
130
+ }
131
+ if (!sourceMap) {
132
+ return result(source);
133
+ }
134
134
 
135
- // Clone (flat) the sourcemap to ensure that the mutations below do not persist.
136
- sourceMap = { ...sourceMap };
137
- const context = /** @type {string} */ (compiler.options.context);
138
- const root = compiler.root;
139
- const modules = sourceMap.sources.map(source => {
140
- if (!source.startsWith("webpack://")) return source;
141
- source = makePathsAbsolute(context, source.slice(10), root);
142
- const module = compilation.findModule(source);
143
- return module || source;
144
- });
145
- let moduleFilenames = modules.map(module =>
146
- ModuleFilenameHelpers.createFilename(
147
- module,
148
- {
149
- moduleFilenameTemplate: this.moduleFilenameTemplate,
150
- namespace
151
- },
152
- {
153
- requestShortener: runtimeTemplate.requestShortener,
154
- chunkGraph,
155
- hashFunction: compilation.outputOptions.hashFunction
156
- }
157
- )
158
- );
159
- moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(
160
- moduleFilenames,
161
- (filename, i, n) => {
162
- for (let j = 0; j < n; j++) filename += "*";
163
- return filename;
135
+ // Clone (flat) the sourcemap to ensure that the mutations below do not persist.
136
+ sourceMap = { ...sourceMap };
137
+ const context = /** @type {string} */ (compiler.options.context);
138
+ const root = compiler.root;
139
+ const modules = sourceMap.sources.map(source => {
140
+ if (!source.startsWith("webpack://")) return source;
141
+ source = makePathsAbsolute(context, source.slice(10), root);
142
+ const module = compilation.findModule(source);
143
+ return module || source;
144
+ });
145
+ let moduleFilenames = modules.map(module =>
146
+ ModuleFilenameHelpers.createFilename(
147
+ module,
148
+ {
149
+ moduleFilenameTemplate: this.moduleFilenameTemplate,
150
+ namespace
151
+ },
152
+ {
153
+ requestShortener: runtimeTemplate.requestShortener,
154
+ chunkGraph,
155
+ hashFunction: compilation.outputOptions.hashFunction
164
156
  }
165
- );
166
- sourceMap.sources = moduleFilenames;
167
- if (options.noSources) {
168
- sourceMap.sourcesContent = undefined;
169
- }
170
- sourceMap.sourceRoot = options.sourceRoot || "";
171
- const moduleId =
172
- /** @type {ModuleId} */
173
- (chunkGraph.getModuleId(m));
174
- sourceMap.file =
175
- typeof moduleId === "number" ? `${moduleId}.js` : moduleId;
176
-
177
- if (options.debugIds) {
178
- sourceMap.debugId = generateDebugId(content, sourceMap.file);
157
+ )
158
+ );
159
+ moduleFilenames = ModuleFilenameHelpers.replaceDuplicates(
160
+ moduleFilenames,
161
+ (filename, i, n) => {
162
+ for (let j = 0; j < n; j++) filename += "*";
163
+ return filename;
179
164
  }
165
+ );
166
+ sourceMap.sources = moduleFilenames;
167
+ if (options.noSources) {
168
+ sourceMap.sourcesContent = undefined;
169
+ }
170
+ sourceMap.sourceRoot = options.sourceRoot || "";
171
+ const moduleId =
172
+ /** @type {ModuleId} */
173
+ (chunkGraph.getModuleId(m));
174
+ sourceMap.file =
175
+ typeof moduleId === "number" ? `${moduleId}.js` : moduleId;
180
176
 
181
- const footer = `${this.sourceMapComment.replace(
182
- /\[url\]/g,
183
- `data:application/json;charset=utf-8;base64,${Buffer.from(
184
- JSON.stringify(sourceMap),
185
- "utf8"
186
- ).toString("base64")}`
187
- )}\n//# sourceURL=webpack-internal:///${moduleId}\n`; // workaround for chrome bug
188
-
189
- return result(
190
- new RawSource(
191
- `eval(${
192
- compilation.outputOptions.trustedTypes
193
- ? `${RuntimeGlobals.createScript}(${JSON.stringify(
194
- content + footer
195
- )})`
196
- : JSON.stringify(content + footer)
197
- });`
198
- )
199
- );
177
+ if (options.debugIds) {
178
+ sourceMap.debugId = generateDebugId(content, sourceMap.file);
200
179
  }
201
- );
202
- hooks.inlineInRuntimeBailout.tap(
203
- "EvalDevToolModulePlugin",
204
- () => "the eval-source-map devtool is used."
205
- );
206
- hooks.render.tap(
207
- "EvalSourceMapDevToolPlugin",
208
- source => new ConcatSource(devtoolWarning, source)
209
- );
210
- hooks.chunkHash.tap("EvalSourceMapDevToolPlugin", (chunk, hash) => {
211
- hash.update("EvalSourceMapDevToolPlugin");
212
- hash.update("2");
213
- });
214
- if (compilation.outputOptions.trustedTypes) {
215
- compilation.hooks.additionalModuleRuntimeRequirements.tap(
216
- "EvalSourceMapDevToolPlugin",
217
- (module, set, context) => {
218
- set.add(RuntimeGlobals.createScript);
219
- }
180
+
181
+ const footer = `${this.sourceMapComment.replace(
182
+ /\[url\]/g,
183
+ `data:application/json;charset=utf-8;base64,${Buffer.from(
184
+ JSON.stringify(sourceMap),
185
+ "utf8"
186
+ ).toString("base64")}`
187
+ )}\n//# sourceURL=webpack-internal:///${moduleId}\n`; // workaround for chrome bug
188
+
189
+ return result(
190
+ new RawSource(
191
+ `eval(${
192
+ compilation.outputOptions.trustedTypes
193
+ ? `${RuntimeGlobals.createScript}(${JSON.stringify(
194
+ content + footer
195
+ )})`
196
+ : JSON.stringify(content + footer)
197
+ });`
198
+ )
220
199
  );
221
200
  }
201
+ );
202
+ hooks.inlineInRuntimeBailout.tap(
203
+ "EvalDevToolModulePlugin",
204
+ () => "the eval-source-map devtool is used."
205
+ );
206
+ hooks.render.tap(
207
+ PLUGIN_NAME,
208
+ source => new ConcatSource(devtoolWarning, source)
209
+ );
210
+ hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash) => {
211
+ hash.update(PLUGIN_NAME);
212
+ hash.update("2");
213
+ });
214
+ if (compilation.outputOptions.trustedTypes) {
215
+ compilation.hooks.additionalModuleRuntimeRequirements.tap(
216
+ PLUGIN_NAME,
217
+ (module, set, context) => {
218
+ set.add(RuntimeGlobals.createScript);
219
+ }
220
+ );
222
221
  }
223
- );
222
+ });
224
223
  }
225
224
  }
226
225