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
@@ -101,13 +101,15 @@ const TREE_DEPENDENCIES = {
101
101
  [RuntimeGlobals.shareScopeMap]: [RuntimeGlobals.hasOwnProperty]
102
102
  };
103
103
 
104
+ const PLUGIN_NAME = "RuntimePlugin";
105
+
104
106
  class RuntimePlugin {
105
107
  /**
106
108
  * @param {Compiler} compiler the Compiler
107
109
  * @returns {void}
108
110
  */
109
111
  apply(compiler) {
110
- compiler.hooks.compilation.tap("RuntimePlugin", compilation => {
112
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
111
113
  const globalChunkLoading = compilation.outputOptions.chunkLoading;
112
114
  /**
113
115
  * @param {Chunk} chunk chunk
@@ -128,12 +130,12 @@ class RuntimePlugin {
128
130
  for (const req of GLOBALS_ON_REQUIRE) {
129
131
  compilation.hooks.runtimeRequirementInModule
130
132
  .for(req)
131
- .tap("RuntimePlugin", (module, set) => {
133
+ .tap(PLUGIN_NAME, (module, set) => {
132
134
  set.add(RuntimeGlobals.requireScope);
133
135
  });
134
136
  compilation.hooks.runtimeRequirementInTree
135
137
  .for(req)
136
- .tap("RuntimePlugin", (module, set) => {
138
+ .tap(PLUGIN_NAME, (module, set) => {
137
139
  set.add(RuntimeGlobals.requireScope);
138
140
  });
139
141
  }
@@ -142,7 +144,7 @@ class RuntimePlugin {
142
144
  TREE_DEPENDENCIES[/** @type {keyof TREE_DEPENDENCIES} */ (req)];
143
145
  compilation.hooks.runtimeRequirementInTree
144
146
  .for(req)
145
- .tap("RuntimePlugin", (chunk, set) => {
147
+ .tap(PLUGIN_NAME, (chunk, set) => {
146
148
  for (const dep of deps) set.add(dep);
147
149
  });
148
150
  }
@@ -151,13 +153,13 @@ class RuntimePlugin {
151
153
  MODULE_DEPENDENCIES[/** @type {keyof MODULE_DEPENDENCIES} */ (req)];
152
154
  compilation.hooks.runtimeRequirementInModule
153
155
  .for(req)
154
- .tap("RuntimePlugin", (chunk, set) => {
156
+ .tap(PLUGIN_NAME, (chunk, set) => {
155
157
  for (const dep of deps) set.add(dep);
156
158
  });
157
159
  }
158
160
  compilation.hooks.runtimeRequirementInTree
159
161
  .for(RuntimeGlobals.definePropertyGetters)
160
- .tap("RuntimePlugin", chunk => {
162
+ .tap(PLUGIN_NAME, chunk => {
161
163
  compilation.addRuntimeModule(
162
164
  chunk,
163
165
  new DefinePropertyGettersRuntimeModule()
@@ -166,7 +168,7 @@ class RuntimePlugin {
166
168
  });
167
169
  compilation.hooks.runtimeRequirementInTree
168
170
  .for(RuntimeGlobals.makeNamespaceObject)
169
- .tap("RuntimePlugin", chunk => {
171
+ .tap(PLUGIN_NAME, chunk => {
170
172
  compilation.addRuntimeModule(
171
173
  chunk,
172
174
  new MakeNamespaceObjectRuntimeModule()
@@ -175,7 +177,7 @@ class RuntimePlugin {
175
177
  });
176
178
  compilation.hooks.runtimeRequirementInTree
177
179
  .for(RuntimeGlobals.createFakeNamespaceObject)
178
- .tap("RuntimePlugin", chunk => {
180
+ .tap(PLUGIN_NAME, chunk => {
179
181
  compilation.addRuntimeModule(
180
182
  chunk,
181
183
  new CreateFakeNamespaceObjectRuntimeModule()
@@ -184,7 +186,7 @@ class RuntimePlugin {
184
186
  });
185
187
  compilation.hooks.runtimeRequirementInTree
186
188
  .for(RuntimeGlobals.hasOwnProperty)
187
- .tap("RuntimePlugin", chunk => {
189
+ .tap(PLUGIN_NAME, chunk => {
188
190
  compilation.addRuntimeModule(
189
191
  chunk,
190
192
  new HasOwnPropertyRuntimeModule()
@@ -193,7 +195,7 @@ class RuntimePlugin {
193
195
  });
194
196
  compilation.hooks.runtimeRequirementInTree
195
197
  .for(RuntimeGlobals.compatGetDefaultExport)
196
- .tap("RuntimePlugin", chunk => {
198
+ .tap(PLUGIN_NAME, chunk => {
197
199
  compilation.addRuntimeModule(
198
200
  chunk,
199
201
  new CompatGetDefaultExportRuntimeModule()
@@ -202,13 +204,13 @@ class RuntimePlugin {
202
204
  });
203
205
  compilation.hooks.runtimeRequirementInTree
204
206
  .for(RuntimeGlobals.runtimeId)
205
- .tap("RuntimePlugin", chunk => {
207
+ .tap(PLUGIN_NAME, chunk => {
206
208
  compilation.addRuntimeModule(chunk, new RuntimeIdRuntimeModule());
207
209
  return true;
208
210
  });
209
211
  compilation.hooks.runtimeRequirementInTree
210
212
  .for(RuntimeGlobals.publicPath)
211
- .tap("RuntimePlugin", (chunk, set) => {
213
+ .tap(PLUGIN_NAME, (chunk, set) => {
212
214
  const { outputOptions } = compilation;
213
215
  const { publicPath: globalPublicPath, scriptType } = outputOptions;
214
216
  const entryOptions = chunk.getEntryOptions();
@@ -237,19 +239,19 @@ class RuntimePlugin {
237
239
  });
238
240
  compilation.hooks.runtimeRequirementInTree
239
241
  .for(RuntimeGlobals.global)
240
- .tap("RuntimePlugin", chunk => {
242
+ .tap(PLUGIN_NAME, chunk => {
241
243
  compilation.addRuntimeModule(chunk, new GlobalRuntimeModule());
242
244
  return true;
243
245
  });
244
246
  compilation.hooks.runtimeRequirementInTree
245
247
  .for(RuntimeGlobals.asyncModule)
246
- .tap("RuntimePlugin", chunk => {
248
+ .tap(PLUGIN_NAME, chunk => {
247
249
  compilation.addRuntimeModule(chunk, new AsyncModuleRuntimeModule());
248
250
  return true;
249
251
  });
250
252
  compilation.hooks.runtimeRequirementInTree
251
253
  .for(RuntimeGlobals.systemContext)
252
- .tap("RuntimePlugin", chunk => {
254
+ .tap(PLUGIN_NAME, chunk => {
253
255
  const entryOptions = chunk.getEntryOptions();
254
256
  const libraryType =
255
257
  entryOptions && entryOptions.library !== undefined
@@ -267,7 +269,7 @@ class RuntimePlugin {
267
269
  });
268
270
  compilation.hooks.runtimeRequirementInTree
269
271
  .for(RuntimeGlobals.getChunkScriptFilename)
270
- .tap("RuntimePlugin", (chunk, set, { chunkGraph }) => {
272
+ .tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => {
271
273
  if (
272
274
  typeof compilation.outputOptions.chunkFilename === "string" &&
273
275
  /\[(full)?hash(:\d+)?\]/.test(
@@ -297,7 +299,7 @@ class RuntimePlugin {
297
299
  });
298
300
  compilation.hooks.runtimeRequirementInTree
299
301
  .for(RuntimeGlobals.getChunkCssFilename)
300
- .tap("RuntimePlugin", (chunk, set, { chunkGraph }) => {
302
+ .tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => {
301
303
  if (
302
304
  typeof compilation.outputOptions.cssChunkFilename === "string" &&
303
305
  /\[(full)?hash(:\d+)?\]/.test(
@@ -322,7 +324,7 @@ class RuntimePlugin {
322
324
  });
323
325
  compilation.hooks.runtimeRequirementInTree
324
326
  .for(RuntimeGlobals.getChunkUpdateScriptFilename)
325
- .tap("RuntimePlugin", (chunk, set) => {
327
+ .tap(PLUGIN_NAME, (chunk, set) => {
326
328
  if (
327
329
  /\[(full)?hash(:\d+)?\]/.test(
328
330
  /** @type {NonNullable<OutputNormalized["hotUpdateChunkFilename"]>} */
@@ -346,7 +348,7 @@ class RuntimePlugin {
346
348
  });
347
349
  compilation.hooks.runtimeRequirementInTree
348
350
  .for(RuntimeGlobals.getUpdateManifestFilename)
349
- .tap("RuntimePlugin", (chunk, set) => {
351
+ .tap(PLUGIN_NAME, (chunk, set) => {
350
352
  if (
351
353
  /\[(full)?hash(:\d+)?\]/.test(
352
354
  /** @type {NonNullable<OutputNormalized["hotUpdateMainFilename"]>} */
@@ -368,7 +370,7 @@ class RuntimePlugin {
368
370
  });
369
371
  compilation.hooks.runtimeRequirementInTree
370
372
  .for(RuntimeGlobals.ensureChunk)
371
- .tap("RuntimePlugin", (chunk, set) => {
373
+ .tap(PLUGIN_NAME, (chunk, set) => {
372
374
  const hasAsyncChunks = chunk.hasAsyncChunks();
373
375
  if (hasAsyncChunks) {
374
376
  set.add(RuntimeGlobals.ensureChunkHandlers);
@@ -381,18 +383,18 @@ class RuntimePlugin {
381
383
  });
382
384
  compilation.hooks.runtimeRequirementInTree
383
385
  .for(RuntimeGlobals.ensureChunkIncludeEntries)
384
- .tap("RuntimePlugin", (chunk, set) => {
386
+ .tap(PLUGIN_NAME, (chunk, set) => {
385
387
  set.add(RuntimeGlobals.ensureChunkHandlers);
386
388
  });
387
389
  compilation.hooks.runtimeRequirementInTree
388
390
  .for(RuntimeGlobals.shareScopeMap)
389
- .tap("RuntimePlugin", (chunk, set) => {
391
+ .tap(PLUGIN_NAME, (chunk, set) => {
390
392
  compilation.addRuntimeModule(chunk, new ShareRuntimeModule());
391
393
  return true;
392
394
  });
393
395
  compilation.hooks.runtimeRequirementInTree
394
396
  .for(RuntimeGlobals.loadScript)
395
- .tap("RuntimePlugin", (chunk, set) => {
397
+ .tap(PLUGIN_NAME, (chunk, set) => {
396
398
  const withCreateScriptUrl = Boolean(
397
399
  compilation.outputOptions.trustedTypes
398
400
  );
@@ -408,7 +410,7 @@ class RuntimePlugin {
408
410
  });
409
411
  compilation.hooks.runtimeRequirementInTree
410
412
  .for(RuntimeGlobals.createScript)
411
- .tap("RuntimePlugin", (chunk, set) => {
413
+ .tap(PLUGIN_NAME, (chunk, set) => {
412
414
  if (compilation.outputOptions.trustedTypes) {
413
415
  set.add(RuntimeGlobals.getTrustedTypesPolicy);
414
416
  }
@@ -417,7 +419,7 @@ class RuntimePlugin {
417
419
  });
418
420
  compilation.hooks.runtimeRequirementInTree
419
421
  .for(RuntimeGlobals.createScriptUrl)
420
- .tap("RuntimePlugin", (chunk, set) => {
422
+ .tap(PLUGIN_NAME, (chunk, set) => {
421
423
  if (compilation.outputOptions.trustedTypes) {
422
424
  set.add(RuntimeGlobals.getTrustedTypesPolicy);
423
425
  }
@@ -429,7 +431,7 @@ class RuntimePlugin {
429
431
  });
430
432
  compilation.hooks.runtimeRequirementInTree
431
433
  .for(RuntimeGlobals.getTrustedTypesPolicy)
432
- .tap("RuntimePlugin", (chunk, set) => {
434
+ .tap(PLUGIN_NAME, (chunk, set) => {
433
435
  compilation.addRuntimeModule(
434
436
  chunk,
435
437
  new GetTrustedTypesPolicyRuntimeModule(set)
@@ -438,13 +440,13 @@ class RuntimePlugin {
438
440
  });
439
441
  compilation.hooks.runtimeRequirementInTree
440
442
  .for(RuntimeGlobals.relativeUrl)
441
- .tap("RuntimePlugin", (chunk, set) => {
443
+ .tap(PLUGIN_NAME, (chunk, set) => {
442
444
  compilation.addRuntimeModule(chunk, new RelativeUrlRuntimeModule());
443
445
  return true;
444
446
  });
445
447
  compilation.hooks.runtimeRequirementInTree
446
448
  .for(RuntimeGlobals.onChunksLoaded)
447
- .tap("RuntimePlugin", (chunk, set) => {
449
+ .tap(PLUGIN_NAME, (chunk, set) => {
448
450
  compilation.addRuntimeModule(
449
451
  chunk,
450
452
  new OnChunksLoadedRuntimeModule()
@@ -453,7 +455,7 @@ class RuntimePlugin {
453
455
  });
454
456
  compilation.hooks.runtimeRequirementInTree
455
457
  .for(RuntimeGlobals.baseURI)
456
- .tap("RuntimePlugin", chunk => {
458
+ .tap(PLUGIN_NAME, chunk => {
457
459
  if (isChunkLoadingDisabledForChunk(chunk)) {
458
460
  compilation.addRuntimeModule(chunk, new BaseUriRuntimeModule());
459
461
  return true;
@@ -461,13 +463,13 @@ class RuntimePlugin {
461
463
  });
462
464
  compilation.hooks.runtimeRequirementInTree
463
465
  .for(RuntimeGlobals.scriptNonce)
464
- .tap("RuntimePlugin", chunk => {
466
+ .tap(PLUGIN_NAME, chunk => {
465
467
  compilation.addRuntimeModule(chunk, new NonceRuntimeModule());
466
468
  return true;
467
469
  });
468
470
  // TODO webpack 6: remove CompatRuntimeModule
469
471
  compilation.hooks.additionalTreeRuntimeRequirements.tap(
470
- "RuntimePlugin",
472
+ PLUGIN_NAME,
471
473
  (chunk, set) => {
472
474
  const { mainTemplate } = compilation;
473
475
  if (
@@ -481,7 +483,7 @@ class RuntimePlugin {
481
483
  }
482
484
  );
483
485
  JavascriptModulesPlugin.getCompilationHooks(compilation).chunkHash.tap(
484
- "RuntimePlugin",
486
+ PLUGIN_NAME,
485
487
  (chunk, hash, { chunkGraph }) => {
486
488
  const xor = new StringXor();
487
489
  for (const m of chunkGraph.getChunkRuntimeModulesIterable(chunk)) {
@@ -131,6 +131,8 @@ const getTaskForFile = (
131
131
  };
132
132
  };
133
133
 
134
+ const PLUGIN_NAME = "SourceMapDevToolPlugin";
135
+
134
136
  class SourceMapDevToolPlugin {
135
137
  /**
136
138
  * @param {SourceMapDevToolPluginOptions=} options options object
@@ -178,18 +180,18 @@ class SourceMapDevToolPlugin {
178
180
  options
179
181
  );
180
182
 
181
- compiler.hooks.compilation.tap("SourceMapDevToolPlugin", compilation => {
183
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
182
184
  new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation);
183
185
 
184
186
  compilation.hooks.processAssets.tapAsync(
185
187
  {
186
- name: "SourceMapDevToolPlugin",
188
+ name: PLUGIN_NAME,
187
189
  stage: Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING,
188
190
  additionalAssets: true
189
191
  },
190
192
  (assets, callback) => {
191
193
  const chunkGraph = compilation.chunkGraph;
192
- const cache = compilation.getCache("SourceMapDevToolPlugin");
194
+ const cache = compilation.getCache(PLUGIN_NAME);
193
195
  /** @type {Map<string | Module, string>} */
194
196
  const moduleToSourceNameMapping = new Map();
195
197
  const reportProgress =
@@ -552,12 +554,12 @@ class SourceMapDevToolPlugin {
552
554
  } else {
553
555
  if (currentSourceMappingURLComment === false) {
554
556
  throw new Error(
555
- "SourceMapDevToolPlugin: append can't be false when no filename is provided"
557
+ `${PLUGIN_NAME}: append can't be false when no filename is provided`
556
558
  );
557
559
  }
558
560
  if (typeof currentSourceMappingURLComment === "function") {
559
561
  throw new Error(
560
- "SourceMapDevToolPlugin: append can't be a function when no filename is provided"
562
+ `${PLUGIN_NAME}: append can't be a function when no filename is provided`
561
563
  );
562
564
  }
563
565
  /**
@@ -11,6 +11,8 @@ const CaseSensitiveModulesWarning = require("./CaseSensitiveModulesWarning");
11
11
  /** @typedef {import("./Module")} Module */
12
12
  /** @typedef {import("./NormalModule")} NormalModule */
13
13
 
14
+ const PLUGIN_NAME = "WarnCaseSensitiveModulesPlugin";
15
+
14
16
  class WarnCaseSensitiveModulesPlugin {
15
17
  /**
16
18
  * Apply the plugin
@@ -18,47 +20,44 @@ class WarnCaseSensitiveModulesPlugin {
18
20
  * @returns {void}
19
21
  */
20
22
  apply(compiler) {
21
- compiler.hooks.compilation.tap(
22
- "WarnCaseSensitiveModulesPlugin",
23
- compilation => {
24
- compilation.hooks.seal.tap("WarnCaseSensitiveModulesPlugin", () => {
25
- /** @type {Map<string, Map<string, Module>>} */
26
- const moduleWithoutCase = new Map();
27
- for (const module of compilation.modules) {
28
- const identifier = module.identifier();
23
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
24
+ compilation.hooks.seal.tap(PLUGIN_NAME, () => {
25
+ /** @type {Map<string, Map<string, Module>>} */
26
+ const moduleWithoutCase = new Map();
27
+ for (const module of compilation.modules) {
28
+ const identifier = module.identifier();
29
29
 
30
- // Ignore `data:` URLs, because it's not a real path
31
- if (
32
- /** @type {NormalModule} */
33
- (module).resourceResolveData !== undefined &&
34
- /** @type {NormalModule} */
35
- (module).resourceResolveData.encodedContent !== undefined
36
- ) {
37
- continue;
38
- }
30
+ // Ignore `data:` URLs, because it's not a real path
31
+ if (
32
+ /** @type {NormalModule} */
33
+ (module).resourceResolveData !== undefined &&
34
+ /** @type {NormalModule} */
35
+ (module).resourceResolveData.encodedContent !== undefined
36
+ ) {
37
+ continue;
38
+ }
39
39
 
40
- const lowerIdentifier = identifier.toLowerCase();
41
- let map = moduleWithoutCase.get(lowerIdentifier);
42
- if (map === undefined) {
43
- map = new Map();
44
- moduleWithoutCase.set(lowerIdentifier, map);
45
- }
46
- map.set(identifier, module);
40
+ const lowerIdentifier = identifier.toLowerCase();
41
+ let map = moduleWithoutCase.get(lowerIdentifier);
42
+ if (map === undefined) {
43
+ map = new Map();
44
+ moduleWithoutCase.set(lowerIdentifier, map);
47
45
  }
48
- for (const pair of moduleWithoutCase) {
49
- const map = pair[1];
50
- if (map.size > 1) {
51
- compilation.warnings.push(
52
- new CaseSensitiveModulesWarning(
53
- map.values(),
54
- compilation.moduleGraph
55
- )
56
- );
57
- }
46
+ map.set(identifier, module);
47
+ }
48
+ for (const pair of moduleWithoutCase) {
49
+ const map = pair[1];
50
+ if (map.size > 1) {
51
+ compilation.warnings.push(
52
+ new CaseSensitiveModulesWarning(
53
+ map.values(),
54
+ compilation.moduleGraph
55
+ )
56
+ );
58
57
  }
59
- });
60
- }
61
- );
58
+ }
59
+ });
60
+ });
62
61
  }
63
62
  }
64
63
 
@@ -9,6 +9,8 @@ const NoModeWarning = require("./NoModeWarning");
9
9
 
10
10
  /** @typedef {import("./Compiler")} Compiler */
11
11
 
12
+ const PLUGIN_NAME = "WarnNoModeSetPlugin";
13
+
12
14
  class WarnNoModeSetPlugin {
13
15
  /**
14
16
  * Apply the plugin
@@ -16,7 +18,7 @@ class WarnNoModeSetPlugin {
16
18
  * @returns {void}
17
19
  */
18
20
  apply(compiler) {
19
- compiler.hooks.thisCompilation.tap("WarnNoModeSetPlugin", compilation => {
21
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
20
22
  compilation.warnings.push(new NoModeWarning());
21
23
  });
22
24
  }
@@ -125,6 +125,8 @@ class IgnoringWatchFileSystem {
125
125
  }
126
126
  }
127
127
 
128
+ const PLUGIN_NAME = "WatchIgnorePlugin";
129
+
128
130
  class WatchIgnorePlugin {
129
131
  /**
130
132
  * @param {WatchIgnorePluginOptions} options options
@@ -140,7 +142,7 @@ class WatchIgnorePlugin {
140
142
  * @returns {void}
141
143
  */
142
144
  apply(compiler) {
143
- compiler.hooks.afterEnvironment.tap("WatchIgnorePlugin", () => {
145
+ compiler.hooks.afterEnvironment.tap(PLUGIN_NAME, () => {
144
146
  compiler.watchFileSystem = new IgnoringWatchFileSystem(
145
147
  /** @type {WatchFileSystem} */
146
148
  (compiler.watchFileSystem),
@@ -18,9 +18,11 @@ class WebpackError extends Error {
18
18
  /**
19
19
  * Creates an instance of WebpackError.
20
20
  * @param {string=} message error message
21
+ * @param {{ cause?: unknown }} options error options
21
22
  */
22
- constructor(message) {
23
- super(message);
23
+ constructor(message, options = {}) {
24
+ // @ts-expect-error ES2018 doesn't `Error.cause`, but it can be used by developers
25
+ super(message, options);
24
26
 
25
27
  /** @type {string=} */
26
28
  this.details = undefined;
@@ -37,7 +39,11 @@ class WebpackError extends Error {
37
39
  }
38
40
 
39
41
  [inspect]() {
40
- return this.stack + (this.details ? `\n${this.details}` : "");
42
+ return (
43
+ this.stack +
44
+ (this.details ? `\n${this.details}` : "") +
45
+ (this.cause ? `\n${this.cause}` : "")
46
+ );
41
47
  }
42
48
 
43
49
  /**
@@ -47,6 +53,7 @@ class WebpackError extends Error {
47
53
  write(this.name);
48
54
  write(this.message);
49
55
  write(this.stack);
56
+ write(this.cause);
50
57
  write(this.details);
51
58
  write(this.loc);
52
59
  write(this.hideStack);
@@ -59,6 +66,7 @@ class WebpackError extends Error {
59
66
  this.name = read();
60
67
  this.message = read();
61
68
  this.stack = read();
69
+ this.cause = read();
62
70
  this.details = read();
63
71
  this.loc = read();
64
72
  this.hideStack = read();
@@ -63,6 +63,8 @@ const { cleverMerge } = require("./util/cleverMerge");
63
63
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
64
64
  /** @typedef {import("./util/fs").IntermediateFileSystem} IntermediateFileSystem */
65
65
 
66
+ const CLASS_NAME = "WebpackOptionsApply";
67
+
66
68
  class WebpackOptionsApply extends OptionsApply {
67
69
  constructor() {
68
70
  super();
@@ -764,7 +766,7 @@ class WebpackOptionsApply extends OptionsApply {
764
766
  }
765
767
  compiler.resolverFactory.hooks.resolveOptions
766
768
  .for("normal")
767
- .tap("WebpackOptionsApply", resolveOptions => {
769
+ .tap(CLASS_NAME, resolveOptions => {
768
770
  resolveOptions = cleverMerge(options.resolve, resolveOptions);
769
771
  resolveOptions.fileSystem =
770
772
  /** @type {InputFileSystem} */
@@ -773,7 +775,7 @@ class WebpackOptionsApply extends OptionsApply {
773
775
  });
774
776
  compiler.resolverFactory.hooks.resolveOptions
775
777
  .for("context")
776
- .tap("WebpackOptionsApply", resolveOptions => {
778
+ .tap(CLASS_NAME, resolveOptions => {
777
779
  resolveOptions = cleverMerge(options.resolve, resolveOptions);
778
780
  resolveOptions.fileSystem =
779
781
  /** @type {InputFileSystem} */
@@ -783,7 +785,7 @@ class WebpackOptionsApply extends OptionsApply {
783
785
  });
784
786
  compiler.resolverFactory.hooks.resolveOptions
785
787
  .for("loader")
786
- .tap("WebpackOptionsApply", resolveOptions => {
788
+ .tap(CLASS_NAME, resolveOptions => {
787
789
  resolveOptions = cleverMerge(options.resolveLoader, resolveOptions);
788
790
  resolveOptions.fileSystem =
789
791
  /** @type {InputFileSystem} */
@@ -10,6 +10,8 @@ const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency
10
10
  /** @typedef {import("../Compiler")} Compiler */
11
11
  /** @typedef {import("../Module")} Module */
12
12
 
13
+ const PLUGIN_NAME = "InferAsyncModulesPlugin";
14
+
13
15
  class InferAsyncModulesPlugin {
14
16
  /**
15
17
  * Apply the plugin
@@ -17,37 +19,34 @@ class InferAsyncModulesPlugin {
17
19
  * @returns {void}
18
20
  */
19
21
  apply(compiler) {
20
- compiler.hooks.compilation.tap("InferAsyncModulesPlugin", compilation => {
22
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
21
23
  const { moduleGraph } = compilation;
22
- compilation.hooks.finishModules.tap(
23
- "InferAsyncModulesPlugin",
24
- modules => {
25
- /** @type {Set<Module>} */
26
- const queue = new Set();
27
- for (const module of modules) {
28
- if (module.buildMeta && module.buildMeta.async) {
29
- queue.add(module);
30
- }
24
+ compilation.hooks.finishModules.tap(PLUGIN_NAME, modules => {
25
+ /** @type {Set<Module>} */
26
+ const queue = new Set();
27
+ for (const module of modules) {
28
+ if (module.buildMeta && module.buildMeta.async) {
29
+ queue.add(module);
31
30
  }
32
- for (const module of queue) {
33
- moduleGraph.setAsync(module);
34
- for (const [
35
- originModule,
36
- connections
37
- ] of moduleGraph.getIncomingConnectionsByOriginModule(module)) {
38
- if (
39
- connections.some(
40
- c =>
41
- c.dependency instanceof HarmonyImportDependency &&
42
- c.isTargetActive(undefined)
43
- )
44
- ) {
45
- queue.add(/** @type {Module} */ (originModule));
46
- }
31
+ }
32
+ for (const module of queue) {
33
+ moduleGraph.setAsync(module);
34
+ for (const [
35
+ originModule,
36
+ connections
37
+ ] of moduleGraph.getIncomingConnectionsByOriginModule(module)) {
38
+ if (
39
+ connections.some(
40
+ c =>
41
+ c.dependency instanceof HarmonyImportDependency &&
42
+ c.isTargetActive(undefined)
43
+ )
44
+ ) {
45
+ queue.add(/** @type {Module} */ (originModule));
47
46
  }
48
47
  }
49
48
  }
50
- );
49
+ });
51
50
  });
52
51
  }
53
52
  }