webpack 5.99.6 → 5.99.7

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 (107) 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 +9 -8
  5. package/lib/Compiler.js +2 -1
  6. package/lib/ContextExclusionPlugin.js +4 -2
  7. package/lib/ContextReplacementPlugin.js +5 -3
  8. package/lib/DelegatedPlugin.js +4 -2
  9. package/lib/DllEntryPlugin.js +4 -2
  10. package/lib/DllPlugin.js +5 -3
  11. package/lib/DllReferencePlugin.js +56 -60
  12. package/lib/DynamicEntryPlugin.js +4 -2
  13. package/lib/EntryOptionPlugin.js +3 -1
  14. package/lib/EntryPlugin.js +4 -2
  15. package/lib/EnvironmentPlugin.js +4 -2
  16. package/lib/EvalDevToolModulePlugin.js +9 -7
  17. package/lib/EvalSourceMapDevToolPlugin.js +137 -138
  18. package/lib/ExternalsPlugin.js +3 -1
  19. package/lib/FlagDependencyExportsPlugin.js +2 -1
  20. package/lib/IgnorePlugin.js +6 -4
  21. package/lib/IgnoreWarningsPlugin.js +4 -2
  22. package/lib/LibManifestPlugin.js +3 -4
  23. package/lib/LoaderOptionsPlugin.js +4 -2
  24. package/lib/LoaderTargetPlugin.js +4 -2
  25. package/lib/Module.js +19 -12
  26. package/lib/ModuleInfoHeaderPlugin.js +11 -12
  27. package/lib/MultiCompiler.js +5 -3
  28. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  29. package/lib/NormalModule.js +5 -1
  30. package/lib/NormalModuleReplacementPlugin.js +33 -36
  31. package/lib/PlatformPlugin.js +3 -1
  32. package/lib/PrefetchPlugin.js +4 -2
  33. package/lib/ProgressPlugin.js +23 -26
  34. package/lib/RecordIdsPlugin.js +72 -102
  35. package/lib/RuntimePlugin.js +34 -32
  36. package/lib/SourceMapDevToolPlugin.js +7 -5
  37. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  38. package/lib/WarnNoModeSetPlugin.js +3 -1
  39. package/lib/WatchIgnorePlugin.js +3 -1
  40. package/lib/WebpackError.js +11 -3
  41. package/lib/WebpackOptionsApply.js +5 -3
  42. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  43. package/lib/cache/IdleFileCachePlugin.js +11 -12
  44. package/lib/cache/MemoryWithGcCachePlugin.js +7 -5
  45. package/lib/cache/ResolverCachePlugin.js +8 -6
  46. package/lib/cli.js +5 -1
  47. package/lib/config/normalization.js +9 -3
  48. package/lib/container/ContainerReferencePlugin.js +24 -26
  49. package/lib/container/ModuleFederationPlugin.js +2 -1
  50. package/lib/css/CssGenerator.js +1 -1
  51. package/lib/css/CssModulesPlugin.js +6 -4
  52. package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
  53. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  54. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
  55. package/lib/dependencies/LoaderPlugin.js +5 -3
  56. package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
  57. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
  58. package/lib/esm/ModuleChunkLoadingPlugin.js +72 -73
  59. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  60. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
  61. package/lib/hmr/LazyCompilationPlugin.js +17 -18
  62. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
  63. package/lib/ids/DeterministicModuleIdsPlugin.js +47 -48
  64. package/lib/ids/HashedModuleIdsPlugin.js +4 -2
  65. package/lib/ids/NamedChunkIdsPlugin.js +4 -2
  66. package/lib/ids/NamedModuleIdsPlugin.js +4 -2
  67. package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
  68. package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
  69. package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
  70. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
  71. package/lib/javascript/JavascriptParser.js +634 -656
  72. package/lib/library/ModuleLibraryPlugin.js +60 -42
  73. package/lib/node/CommonJsChunkLoadingPlugin.js +69 -73
  74. package/lib/node/NodeEnvironmentPlugin.js +3 -1
  75. package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
  76. package/lib/optimize/ConcatenatedModule.js +12 -15
  77. package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
  78. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  79. package/lib/optimize/MangleExportsPlugin.js +15 -16
  80. package/lib/optimize/MinChunkSizePlugin.js +4 -2
  81. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  82. package/lib/optimize/RealContentHashPlugin.js +4 -2
  83. package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
  84. package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
  85. package/lib/optimize/RuntimeChunkPlugin.js +17 -18
  86. package/lib/optimize/SplitChunksPlugin.js +7 -5
  87. package/lib/performance/SizeLimitsPlugin.js +3 -1
  88. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
  89. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  90. package/lib/schemes/DataUriPlugin.js +5 -3
  91. package/lib/schemes/FileUriPlugin.js +5 -3
  92. package/lib/schemes/HttpUriPlugin.js +32 -39
  93. package/lib/serialization/AggregateErrorSerializer.js +42 -0
  94. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  95. package/lib/serialization/ObjectMiddleware.js +13 -0
  96. package/lib/sharing/ProvideSharedPlugin.js +6 -4
  97. package/lib/stats/DefaultStatsFactoryPlugin.js +89 -33
  98. package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
  99. package/lib/stats/DefaultStatsPrinterPlugin.js +306 -341
  100. package/lib/util/concatenate.js +4 -2
  101. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  102. package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
  103. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
  104. package/package.json +4 -3
  105. package/schemas/WebpackOptions.check.js +1 -1
  106. package/schemas/WebpackOptions.json +24 -2
  107. package/types.d.ts +148 -55
@@ -11,6 +11,8 @@ const PrefetchDependency = require("./dependencies/PrefetchDependency");
11
11
 
12
12
  /** @typedef {import("./Compiler")} Compiler */
13
13
 
14
+ const PLUGIN_NAME = "AutomaticPrefetchPlugin";
15
+
14
16
  class AutomaticPrefetchPlugin {
15
17
  /**
16
18
  * Apply the plugin
@@ -19,7 +21,7 @@ class AutomaticPrefetchPlugin {
19
21
  */
20
22
  apply(compiler) {
21
23
  compiler.hooks.compilation.tap(
22
- "AutomaticPrefetchPlugin",
24
+ PLUGIN_NAME,
23
25
  (compilation, { normalModuleFactory }) => {
24
26
  compilation.dependencyFactories.set(
25
27
  PrefetchDependency,
@@ -29,7 +31,7 @@ class AutomaticPrefetchPlugin {
29
31
  );
30
32
  /** @type {{context: string | null, request: string}[] | null} */
31
33
  let lastModules = null;
32
- compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => {
34
+ compiler.hooks.afterCompile.tap(PLUGIN_NAME, compilation => {
33
35
  lastModules = [];
34
36
 
35
37
  for (const m of compilation.modules) {
@@ -41,26 +43,23 @@ class AutomaticPrefetchPlugin {
41
43
  }
42
44
  }
43
45
  });
44
- compiler.hooks.make.tapAsync(
45
- "AutomaticPrefetchPlugin",
46
- (compilation, callback) => {
47
- if (!lastModules) return callback();
48
- asyncLib.each(
49
- lastModules,
50
- (m, callback) => {
51
- compilation.addModuleChain(
52
- m.context || compiler.context,
53
- new PrefetchDependency(`!!${m.request}`),
54
- callback
55
- );
56
- },
57
- err => {
58
- lastModules = null;
59
- callback(err);
60
- }
61
- );
62
- }
63
- );
46
+ compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
47
+ if (!lastModules) return callback();
48
+ asyncLib.each(
49
+ lastModules,
50
+ (m, callback) => {
51
+ compilation.addModuleChain(
52
+ m.context || compiler.context,
53
+ new PrefetchDependency(`!!${m.request}`),
54
+ callback
55
+ );
56
+ },
57
+ err => {
58
+ lastModules = null;
59
+ callback(err);
60
+ }
61
+ );
62
+ });
64
63
  }
65
64
  }
66
65
  module.exports = AutomaticPrefetchPlugin;
@@ -44,6 +44,8 @@ const wrapComment = str => {
44
44
  .trimEnd()}\n */`;
45
45
  };
46
46
 
47
+ const PLUGIN_NAME = "BannerPlugin";
48
+
47
49
  class BannerPlugin {
48
50
  /**
49
51
  * @param {BannerPluginArgument} options options object
@@ -91,47 +93,41 @@ class BannerPlugin {
91
93
  const stage =
92
94
  this.options.stage || Compilation.PROCESS_ASSETS_STAGE_ADDITIONS;
93
95
 
94
- compiler.hooks.compilation.tap("BannerPlugin", compilation => {
95
- compilation.hooks.processAssets.tap(
96
- {
97
- name: "BannerPlugin",
98
- stage
99
- },
100
- () => {
101
- for (const chunk of compilation.chunks) {
102
- if (options.entryOnly && !chunk.canBeInitial()) {
96
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
97
+ compilation.hooks.processAssets.tap({ name: PLUGIN_NAME, stage }, () => {
98
+ for (const chunk of compilation.chunks) {
99
+ if (options.entryOnly && !chunk.canBeInitial()) {
100
+ continue;
101
+ }
102
+
103
+ for (const file of chunk.files) {
104
+ if (!matchObject(file)) {
103
105
  continue;
104
106
  }
105
107
 
106
- for (const file of chunk.files) {
107
- if (!matchObject(file)) {
108
- continue;
108
+ /** @type {PathData} */
109
+ const data = { chunk, filename: file };
110
+
111
+ const comment = compilation.getPath(
112
+ /** @type {TemplatePath} */
113
+ (banner),
114
+ data
115
+ );
116
+
117
+ compilation.updateAsset(file, old => {
118
+ const cached = cache.get(old);
119
+ if (!cached || cached.comment !== comment) {
120
+ const source = options.footer
121
+ ? new ConcatSource(old, "\n", comment)
122
+ : new ConcatSource(comment, "\n", old);
123
+ cache.set(old, { source, comment });
124
+ return source;
109
125
  }
110
-
111
- /** @type {PathData} */
112
- const data = { chunk, filename: file };
113
-
114
- const comment = compilation.getPath(
115
- /** @type {TemplatePath} */
116
- (banner),
117
- data
118
- );
119
-
120
- compilation.updateAsset(file, old => {
121
- const cached = cache.get(old);
122
- if (!cached || cached.comment !== comment) {
123
- const source = options.footer
124
- ? new ConcatSource(old, "\n", comment)
125
- : new ConcatSource(comment, "\n", old);
126
- cache.set(old, { source, comment });
127
- return source;
128
- }
129
- return cached.source;
130
- });
131
- }
126
+ return cached.source;
127
+ });
132
128
  }
133
129
  }
134
- );
130
+ });
135
131
  });
136
132
  }
137
133
  }
@@ -296,6 +296,8 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
296
296
  /** @type {WeakMap<Compilation, CleanPluginCompilationHooks>} */
297
297
  const compilationHooksMap = new WeakMap();
298
298
 
299
+ const PLUGIN_NAME = "CleanPlugin";
300
+
299
301
  class CleanPlugin {
300
302
  /**
301
303
  * @param {Compilation} compilation the compilation
@@ -349,18 +351,18 @@ class CleanPlugin {
349
351
 
350
352
  compiler.hooks.emit.tapAsync(
351
353
  {
352
- name: "CleanPlugin",
354
+ name: PLUGIN_NAME,
353
355
  stage: 100
354
356
  },
355
357
  (compilation, callback) => {
356
358
  const hooks = CleanPlugin.getCompilationHooks(compilation);
357
- const logger = compilation.getLogger("webpack.CleanPlugin");
359
+ const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
358
360
  const fs = /** @type {OutputFileSystem} */ (compiler.outputFileSystem);
359
361
 
360
362
  if (!fs.readdir) {
361
363
  return callback(
362
364
  new Error(
363
- "CleanPlugin: Output filesystem doesn't support listing directories (readdir)"
365
+ `${PLUGIN_NAME}: Output filesystem doesn't support listing directories (readdir)`
364
366
  )
365
367
  );
366
368
  }
@@ -973,9 +973,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
973
973
  /** @type {SyncBailHook<[string, LogEntry], boolean | void>} */
974
974
  log: new SyncBailHook(["origin", "logEntry"]),
975
975
 
976
- /** @type {SyncWaterfallHook<[WebpackError[]]>} */
976
+ /** @type {SyncWaterfallHook<[Error[]]>} */
977
977
  processWarnings: new SyncWaterfallHook(["warnings"]),
978
- /** @type {SyncWaterfallHook<[WebpackError[]]>} */
978
+ /** @type {SyncWaterfallHook<[Error[]]>} */
979
979
  processErrors: new SyncWaterfallHook(["errors"]),
980
980
 
981
981
  /** @type {HookMap<SyncHook<[Partial<NormalizedStatsOptions>, CreateStatsOptionsContext]>>} */
@@ -1143,9 +1143,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1143
1143
  this.assetsInfo = new Map();
1144
1144
  /** @type {Map<string, Map<string, Set<string>>>} */
1145
1145
  this._assetsRelatedIn = new Map();
1146
- /** @type {WebpackError[]} */
1146
+ /** @type {Error[]} */
1147
1147
  this.errors = [];
1148
- /** @type {WebpackError[]} */
1148
+ /** @type {Error[]} */
1149
1149
  this.warnings = [];
1150
1150
  /** @type {Compilation[]} */
1151
1151
  this.children = [];
@@ -5486,9 +5486,9 @@ This prevents using hashes of each other and should be avoided.`);
5486
5486
  if (strictModuleExceptionHandling) {
5487
5487
  if (id) delete moduleCache[id];
5488
5488
  } else if (strictModuleErrorHandling) {
5489
- moduleObject.error = /** @type {WebpackError} */ (
5490
- execErr
5491
- );
5489
+ moduleObject.error =
5490
+ /** @type {WebpackError} */
5491
+ (execErr);
5492
5492
  }
5493
5493
  if (!(/** @type {WebpackError} */ (execErr).module)) {
5494
5494
  /** @type {WebpackError} */
@@ -5515,7 +5515,8 @@ This prevents using hashes of each other and should be avoided.`);
5515
5515
  `Execution of module code from module graph (${
5516
5516
  /** @type {Module} */
5517
5517
  (module).readableIdentifier(this.requestShortener)
5518
- }) failed: ${message}`
5518
+ }) failed: ${message}`,
5519
+ { cause: execErr }
5519
5520
  );
5520
5521
  err.stack = stack;
5521
5522
  err.module = module;
package/lib/Compiler.js CHANGED
@@ -625,7 +625,8 @@ class Compiler {
625
625
  callback(err, entries, compilation);
626
626
  } catch (runAsChildErr) {
627
627
  const err = new WebpackError(
628
- `compiler.runAsChild callback error: ${runAsChildErr}`
628
+ `compiler.runAsChild callback error: ${runAsChildErr}`,
629
+ { cause: runAsChildErr }
629
630
  );
630
631
  err.details = /** @type {Error} */ (runAsChildErr).stack;
631
632
  /** @type {Compilation} */
@@ -7,6 +7,8 @@
7
7
  /** @typedef {import("./Compiler")} Compiler */
8
8
  /** @typedef {import("./ContextModuleFactory")} ContextModuleFactory */
9
9
 
10
+ const PLUGIN_NAME = "ContextExclusionPlugin";
11
+
10
12
  class ContextExclusionPlugin {
11
13
  /**
12
14
  * @param {RegExp} negativeMatcher Matcher regular expression
@@ -21,8 +23,8 @@ class ContextExclusionPlugin {
21
23
  * @returns {void}
22
24
  */
23
25
  apply(compiler) {
24
- compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", cmf => {
25
- cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files =>
26
+ compiler.hooks.contextModuleFactory.tap(PLUGIN_NAME, cmf => {
27
+ cmf.hooks.contextModuleFiles.tap(PLUGIN_NAME, files =>
26
28
  files.filter(filePath => !this.negativeMatcher.test(filePath))
27
29
  );
28
30
  });
@@ -14,6 +14,8 @@ const { join } = require("./util/fs");
14
14
 
15
15
  /** @typedef {Record<string, string>} NewContentCreateContextMap */
16
16
 
17
+ const PLUGIN_NAME = "ContextReplacementPlugin";
18
+
17
19
  class ContextReplacementPlugin {
18
20
  /**
19
21
  * @param {RegExp} resourceRegExp A regular expression that determines which files will be selected
@@ -95,8 +97,8 @@ class ContextReplacementPlugin {
95
97
  const newContentRegExp = this.newContentRegExp;
96
98
  const newContentCreateContextMap = this.newContentCreateContextMap;
97
99
 
98
- compiler.hooks.contextModuleFactory.tap("ContextReplacementPlugin", cmf => {
99
- cmf.hooks.beforeResolve.tap("ContextReplacementPlugin", result => {
100
+ compiler.hooks.contextModuleFactory.tap(PLUGIN_NAME, cmf => {
101
+ cmf.hooks.beforeResolve.tap(PLUGIN_NAME, result => {
100
102
  if (!result) return;
101
103
  if (resourceRegExp.test(result.request)) {
102
104
  if (newContentResource !== undefined) {
@@ -118,7 +120,7 @@ class ContextReplacementPlugin {
118
120
  }
119
121
  return result;
120
122
  });
121
- cmf.hooks.afterResolve.tap("ContextReplacementPlugin", result => {
123
+ cmf.hooks.afterResolve.tap(PLUGIN_NAME, result => {
122
124
  if (!result) return;
123
125
  if (resourceRegExp.test(result.resource)) {
124
126
  if (newContentResource !== undefined) {
@@ -11,6 +11,8 @@ const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDepende
11
11
  /** @typedef {import("./Compiler")} Compiler */
12
12
  /** @typedef {import("./DelegatedModuleFactoryPlugin").Options} Options */
13
13
 
14
+ const PLUGIN_NAME = "DelegatedPlugin";
15
+
14
16
  class DelegatedPlugin {
15
17
  /**
16
18
  * @param {Options} options options
@@ -26,7 +28,7 @@ class DelegatedPlugin {
26
28
  */
27
29
  apply(compiler) {
28
30
  compiler.hooks.compilation.tap(
29
- "DelegatedPlugin",
31
+ PLUGIN_NAME,
30
32
  (compilation, { normalModuleFactory }) => {
31
33
  compilation.dependencyFactories.set(
32
34
  DelegatedSourceDependency,
@@ -35,7 +37,7 @@ class DelegatedPlugin {
35
37
  }
36
38
  );
37
39
 
38
- compiler.hooks.compile.tap("DelegatedPlugin", ({ normalModuleFactory }) => {
40
+ compiler.hooks.compile.tap(PLUGIN_NAME, ({ normalModuleFactory }) => {
39
41
  new DelegatedModuleFactoryPlugin({
40
42
  associatedObjectForCache: compiler.root,
41
43
  ...this.options
@@ -13,6 +13,8 @@ const EntryDependency = require("./dependencies/EntryDependency");
13
13
  /** @typedef {string[]} Entries */
14
14
  /** @typedef {{ name: string, filename: TODO }} Options */
15
15
 
16
+ const PLUGIN_NAME = "DllEntryPlugin";
17
+
16
18
  class DllEntryPlugin {
17
19
  /**
18
20
  * @param {string} context context
@@ -32,7 +34,7 @@ class DllEntryPlugin {
32
34
  */
33
35
  apply(compiler) {
34
36
  compiler.hooks.compilation.tap(
35
- "DllEntryPlugin",
37
+ PLUGIN_NAME,
36
38
  (compilation, { normalModuleFactory }) => {
37
39
  const dllModuleFactory = new DllModuleFactory();
38
40
  compilation.dependencyFactories.set(
@@ -45,7 +47,7 @@ class DllEntryPlugin {
45
47
  );
46
48
  }
47
49
  );
48
- compiler.hooks.make.tapAsync("DllEntryPlugin", (compilation, callback) => {
50
+ compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
49
51
  compilation.addEntry(
50
52
  this.context,
51
53
  new DllEntryDependency(
package/lib/DllPlugin.js CHANGED
@@ -24,6 +24,8 @@ const validate = createSchemaValidation(
24
24
  }
25
25
  );
26
26
 
27
+ const PLUGIN_NAME = "DllPlugin";
28
+
27
29
  class DllPlugin {
28
30
  /**
29
31
  * @param {DllPluginOptions} options options object
@@ -42,7 +44,7 @@ class DllPlugin {
42
44
  * @returns {void}
43
45
  */
44
46
  apply(compiler) {
45
- compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => {
47
+ compiler.hooks.entryOption.tap(PLUGIN_NAME, (context, entry) => {
46
48
  if (typeof entry !== "function") {
47
49
  for (const name of Object.keys(entry)) {
48
50
  /** @type {Options} */
@@ -55,14 +57,14 @@ class DllPlugin {
55
57
  }
56
58
  } else {
57
59
  throw new Error(
58
- "DllPlugin doesn't support dynamic entry (function) yet"
60
+ `${PLUGIN_NAME} doesn't support dynamic entry (function) yet`
59
61
  );
60
62
  }
61
63
  return true;
62
64
  });
63
65
  new LibManifestPlugin(this.options).apply(compiler);
64
66
  if (!this.options.entryOnly) {
65
- new FlagAllModulesAsUsedPlugin("DllPlugin").apply(compiler);
67
+ new FlagAllModulesAsUsedPlugin(PLUGIN_NAME).apply(compiler);
66
68
  }
67
69
  }
68
70
  }
@@ -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
  );