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
@@ -307,6 +307,8 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
307
307
  * @property {StatsModuleTraceItem[]=} moduleTrace
308
308
  * @property {string=} details
309
309
  * @property {string=} stack
310
+ * @property {KnownStatsError=} cause
311
+ * @property {KnownStatsError[]=} errors
310
312
  * @property {string=} compilerPath
311
313
  */
312
314
 
@@ -336,6 +338,7 @@ const { makePathsRelative, parseResource } = require("../util/identifier");
336
338
  * @property {ExtractorsByOption<OriginRecord, StatsChunkOrigin>} chunkOrigin
337
339
  * @property {ExtractorsByOption<WebpackError, StatsError>} error
338
340
  * @property {ExtractorsByOption<WebpackError, StatsError>} warning
341
+ * @property {ExtractorsByOption<WebpackError, StatsError>} cause
339
342
  * @property {ExtractorsByOption<ModuleTrace, StatsModuleTraceItem>} moduleTraceItem
340
343
  * @property {ExtractorsByOption<Dependency, StatsModuleTraceDependency>} moduleTraceDependency
341
344
  */
@@ -405,47 +408,66 @@ const countWithChildren = (compilation, getItems) => {
405
408
  return count;
406
409
  };
407
410
 
408
- /** @type {ExtractorsByOption<WebpackError | string, StatsError>} */
411
+ /** @typedef {Error & { cause?: unknown }} ErrorWithCause */
412
+ /** @typedef {Error & { errors: EXPECTED_ANY[] }} AggregateError */
413
+
414
+ /** @type {ExtractorsByOption<string | ErrorWithCause | AggregateError | WebpackError, StatsError>} */
409
415
  const EXTRACT_ERROR = {
410
416
  _: (object, error, context, { requestShortener }) => {
411
417
  // TODO webpack 6 disallow strings in the errors/warnings list
412
418
  if (typeof error === "string") {
413
419
  object.message = error;
414
420
  } else {
415
- if (error.chunk) {
421
+ if (/** @type {WebpackError} */ (error).chunk) {
422
+ const chunk = /** @type {WebpackError} */ (error).chunk;
416
423
  object.chunkName =
417
424
  /** @type {string | undefined} */
418
- (error.chunk.name);
419
- object.chunkEntry = error.chunk.hasRuntime();
420
- object.chunkInitial = error.chunk.canBeInitial();
425
+ (chunk.name);
426
+ object.chunkEntry = chunk.hasRuntime();
427
+ object.chunkInitial = chunk.canBeInitial();
421
428
  }
422
- if (error.file) {
423
- object.file = error.file;
429
+
430
+ if (/** @type {WebpackError} */ (error).file) {
431
+ object.file = /** @type {WebpackError} */ (error).file;
424
432
  }
425
- if (error.module) {
426
- object.moduleIdentifier = error.module.identifier();
427
- object.moduleName = error.module.readableIdentifier(requestShortener);
433
+
434
+ if (/** @type {WebpackError} */ (error).module) {
435
+ object.moduleIdentifier =
436
+ /** @type {WebpackError} */
437
+ (error).module.identifier();
438
+ object.moduleName =
439
+ /** @type {WebpackError} */
440
+ (error).module.readableIdentifier(requestShortener);
428
441
  }
429
- if (error.loc) {
430
- object.loc = formatLocation(error.loc);
442
+
443
+ if (/** @type {WebpackError} */ (error).loc) {
444
+ object.loc = formatLocation(/** @type {WebpackError} */ (error).loc);
431
445
  }
446
+
432
447
  object.message = error.message;
433
448
  }
434
449
  },
435
450
  ids: (object, error, { compilation: { chunkGraph } }) => {
436
451
  if (typeof error !== "string") {
437
- if (error.chunk) {
438
- object.chunkId = /** @type {ChunkId} */ (error.chunk.id);
452
+ if (/** @type {WebpackError} */ (error).chunk) {
453
+ object.chunkId = /** @type {ChunkId} */ (
454
+ /** @type {WebpackError} */
455
+ (error).chunk.id
456
+ );
439
457
  }
440
- if (error.module) {
458
+
459
+ if (/** @type {WebpackError} */ (error).module) {
441
460
  object.moduleId =
442
461
  /** @type {ModuleId} */
443
- (chunkGraph.getModuleId(error.module));
462
+ (chunkGraph.getModuleId(/** @type {WebpackError} */ (error).module));
444
463
  }
445
464
  }
446
465
  },
447
466
  moduleTrace: (object, error, context, options, factory) => {
448
- if (typeof error !== "string" && error.module) {
467
+ if (
468
+ typeof error !== "string" &&
469
+ /** @type {WebpackError} */ (error).module
470
+ ) {
449
471
  const {
450
472
  type,
451
473
  compilation: { moduleGraph }
@@ -454,7 +476,7 @@ const EXTRACT_ERROR = {
454
476
  const visitedModules = new Set();
455
477
  /** @type {ModuleTrace[]} */
456
478
  const moduleTrace = [];
457
- let current = error.module;
479
+ let current = /** @type {WebpackError} */ (error).module;
458
480
  while (current) {
459
481
  if (visitedModules.has(current)) break; // circular (technically impossible, but how knows)
460
482
  visitedModules.add(current);
@@ -481,13 +503,44 @@ const EXTRACT_ERROR = {
481
503
  (errorDetails === true ||
482
504
  (type.endsWith(".error") && cachedGetErrors(compilation).length < 3))
483
505
  ) {
484
- object.details = error.details;
506
+ object.details = /** @type {WebpackError} */ (error).details;
485
507
  }
486
508
  },
487
509
  errorStack: (object, error) => {
488
510
  if (typeof error !== "string") {
489
511
  object.stack = error.stack;
490
512
  }
513
+ },
514
+ errorCause: (object, error, context, options, factory) => {
515
+ if (
516
+ typeof error !== "string" &&
517
+ /** @type {ErrorWithCause} */ (error).cause
518
+ ) {
519
+ const rawCause = /** @type {ErrorWithCause} */ (error).cause;
520
+ /** @type {Error} */
521
+ const cause =
522
+ typeof rawCause === "string"
523
+ ? /** @type {Error} */ ({ message: rawCause })
524
+ : /** @type {Error} */ (rawCause);
525
+ const { type } = context;
526
+
527
+ object.cause = factory.create(`${type}.cause`, cause, context);
528
+ }
529
+ },
530
+ errorErrors: (object, error, context, options, factory) => {
531
+ if (
532
+ typeof error !== "string" &&
533
+ /** @type {AggregateError} */
534
+ (error).errors
535
+ ) {
536
+ const { type } = context;
537
+ object.errors = factory.create(
538
+ `${type}.errors`,
539
+ /** @type {Error[]} */
540
+ (/** @type {AggregateError} */ (error).errors),
541
+ context
542
+ );
543
+ }
491
544
  }
492
545
  };
493
546
 
@@ -1560,6 +1613,7 @@ const SIMPLE_EXTRACTORS = {
1560
1613
  },
1561
1614
  error: EXTRACT_ERROR,
1562
1615
  warning: EXTRACT_ERROR,
1616
+ cause: EXTRACT_ERROR,
1563
1617
  moduleTraceItem: {
1564
1618
  _: (object, { origin, module }, context, { requestShortener }, factory) => {
1565
1619
  const {
@@ -2474,6 +2528,8 @@ const ITEM_NAMES = {
2474
2528
  "compilation.namedChunkGroups[]": "chunkGroup",
2475
2529
  "compilation.errors[]": "error",
2476
2530
  "compilation.warnings[]": "warning",
2531
+ "error.errors[]": "error",
2532
+ "warning.errors[]": "error",
2477
2533
  "chunk.modules[]": "module",
2478
2534
  "chunk.rootModules[]": "module",
2479
2535
  "chunk.origins[]": "chunkOrigin",
@@ -2515,6 +2571,8 @@ const MERGER = {
2515
2571
  "compilation.namedChunkGroups": mergeToObject
2516
2572
  };
2517
2573
 
2574
+ const PLUGIN_NAME = "DefaultStatsFactoryPlugin";
2575
+
2518
2576
  class DefaultStatsFactoryPlugin {
2519
2577
  /**
2520
2578
  * Apply the plugin
@@ -2522,9 +2580,9 @@ class DefaultStatsFactoryPlugin {
2522
2580
  * @returns {void}
2523
2581
  */
2524
2582
  apply(compiler) {
2525
- compiler.hooks.compilation.tap("DefaultStatsFactoryPlugin", compilation => {
2583
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
2526
2584
  compilation.hooks.statsFactory.tap(
2527
- "DefaultStatsFactoryPlugin",
2585
+ PLUGIN_NAME,
2528
2586
  /**
2529
2587
  * @param {StatsFactory} stats stats factory
2530
2588
  * @param {NormalizedStatsOptions} options stats options
@@ -2537,7 +2595,7 @@ class DefaultStatsFactoryPlugin {
2537
2595
  (hookFor, fn) => {
2538
2596
  stats.hooks.extract
2539
2597
  .for(hookFor)
2540
- .tap("DefaultStatsFactoryPlugin", (obj, data, ctx) =>
2598
+ .tap(PLUGIN_NAME, (obj, data, ctx) =>
2541
2599
  fn(obj, data, ctx, options, stats)
2542
2600
  );
2543
2601
  }
@@ -2545,28 +2603,28 @@ class DefaultStatsFactoryPlugin {
2545
2603
  iterateConfig(FILTER, options, (hookFor, fn) => {
2546
2604
  stats.hooks.filter
2547
2605
  .for(hookFor)
2548
- .tap("DefaultStatsFactoryPlugin", (item, ctx, idx, i) =>
2606
+ .tap(PLUGIN_NAME, (item, ctx, idx, i) =>
2549
2607
  fn(item, ctx, options, idx, i)
2550
2608
  );
2551
2609
  });
2552
2610
  iterateConfig(FILTER_RESULTS, options, (hookFor, fn) => {
2553
2611
  stats.hooks.filterResults
2554
2612
  .for(hookFor)
2555
- .tap("DefaultStatsFactoryPlugin", (item, ctx, idx, i) =>
2613
+ .tap(PLUGIN_NAME, (item, ctx, idx, i) =>
2556
2614
  fn(item, ctx, options, idx, i)
2557
2615
  );
2558
2616
  });
2559
2617
  iterateConfig(SORTERS, options, (hookFor, fn) => {
2560
2618
  stats.hooks.sort
2561
2619
  .for(hookFor)
2562
- .tap("DefaultStatsFactoryPlugin", (comparators, ctx) =>
2620
+ .tap(PLUGIN_NAME, (comparators, ctx) =>
2563
2621
  fn(comparators, ctx, options)
2564
2622
  );
2565
2623
  });
2566
2624
  iterateConfig(RESULT_SORTERS, options, (hookFor, fn) => {
2567
2625
  stats.hooks.sortResults
2568
2626
  .for(hookFor)
2569
- .tap("DefaultStatsFactoryPlugin", (comparators, ctx) =>
2627
+ .tap(PLUGIN_NAME, (comparators, ctx) =>
2570
2628
  fn(comparators, ctx, options)
2571
2629
  );
2572
2630
  });
@@ -2577,27 +2635,25 @@ class DefaultStatsFactoryPlugin {
2577
2635
  (hookFor, fn) => {
2578
2636
  stats.hooks.groupResults
2579
2637
  .for(hookFor)
2580
- .tap("DefaultStatsFactoryPlugin", (groupConfigs, ctx) =>
2638
+ .tap(PLUGIN_NAME, (groupConfigs, ctx) =>
2581
2639
  fn(groupConfigs, ctx, options)
2582
2640
  );
2583
2641
  }
2584
2642
  );
2585
2643
  for (const key of Object.keys(ITEM_NAMES)) {
2586
2644
  const itemName = ITEM_NAMES[key];
2587
- stats.hooks.getItemName
2588
- .for(key)
2589
- .tap("DefaultStatsFactoryPlugin", () => itemName);
2645
+ stats.hooks.getItemName.for(key).tap(PLUGIN_NAME, () => itemName);
2590
2646
  }
2591
2647
  for (const key of Object.keys(MERGER)) {
2592
2648
  const merger = MERGER[key];
2593
- stats.hooks.merge.for(key).tap("DefaultStatsFactoryPlugin", merger);
2649
+ stats.hooks.merge.for(key).tap(PLUGIN_NAME, merger);
2594
2650
  }
2595
2651
  if (options.children) {
2596
2652
  if (Array.isArray(options.children)) {
2597
2653
  stats.hooks.getItemFactory
2598
2654
  .for("compilation.children[].compilation")
2599
2655
  .tap(
2600
- "DefaultStatsFactoryPlugin",
2656
+ PLUGIN_NAME,
2601
2657
  /**
2602
2658
  * @param {Compilation} comp compilation
2603
2659
  * @param {StatsFactoryContext} options options
@@ -2620,7 +2676,7 @@ class DefaultStatsFactoryPlugin {
2620
2676
  );
2621
2677
  stats.hooks.getItemFactory
2622
2678
  .for("compilation.children[].compilation")
2623
- .tap("DefaultStatsFactoryPlugin", () => childFactory);
2679
+ .tap(PLUGIN_NAME, () => childFactory);
2624
2680
  }
2625
2681
  }
2626
2682
  }
@@ -55,6 +55,8 @@ const NAMED_PRESETS = {
55
55
  optimizationBailout: true,
56
56
  errorDetails: true,
57
57
  errorStack: true,
58
+ errorCause: true,
59
+ errorErrors: true,
58
60
  publicPath: true,
59
61
  logging: "verbose",
60
62
  orphanModules: true,
@@ -84,6 +86,8 @@ const NAMED_PRESETS = {
84
86
  providedExports: true,
85
87
  optimizationBailout: true,
86
88
  errorDetails: true,
89
+ errorCause: true,
90
+ errorErrors: true,
87
91
  publicPath: true,
88
92
  logging: true,
89
93
  runtimeModules: true,
@@ -260,6 +264,8 @@ const DEFAULTS = {
260
264
  errorsCount: NORMAL_ON,
261
265
  errorDetails: AUTO_FOR_TO_STRING,
262
266
  errorStack: OFF_FOR_TO_STRING,
267
+ errorCause: AUTO_FOR_TO_STRING,
268
+ errorErrors: AUTO_FOR_TO_STRING,
263
269
  warnings: NORMAL_ON,
264
270
  warningsCount: NORMAL_ON,
265
271
  publicPath: OFF_FOR_TO_STRING,
@@ -364,6 +370,8 @@ const NORMALIZER = {
364
370
  }
365
371
  };
366
372
 
373
+ const PLUGIN_NAME = "DefaultStatsPresetPlugin";
374
+
367
375
  class DefaultStatsPresetPlugin {
368
376
  /**
369
377
  * Apply the plugin
@@ -371,35 +379,32 @@ class DefaultStatsPresetPlugin {
371
379
  * @returns {void}
372
380
  */
373
381
  apply(compiler) {
374
- compiler.hooks.compilation.tap("DefaultStatsPresetPlugin", compilation => {
382
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
375
383
  for (const key of Object.keys(NAMED_PRESETS)) {
376
384
  const defaults = NAMED_PRESETS[/** @type {keyof NamedPresets} */ (key)];
377
385
  compilation.hooks.statsPreset
378
386
  .for(key)
379
- .tap("DefaultStatsPresetPlugin", (options, context) => {
387
+ .tap(PLUGIN_NAME, (options, context) => {
380
388
  applyDefaults(options, defaults);
381
389
  });
382
390
  }
383
- compilation.hooks.statsNormalize.tap(
384
- "DefaultStatsPresetPlugin",
385
- (options, context) => {
386
- for (const key of Object.keys(DEFAULTS)) {
387
- if (options[key] === undefined)
388
- options[key] =
389
- /** @type {Defaults[DefaultsKeys]} */
390
- (DEFAULTS[/** @type {DefaultsKeys} */ (key)])(
391
- options,
392
- context,
393
- compilation
394
- );
395
- }
396
- for (const key of Object.keys(NORMALIZER)) {
391
+ compilation.hooks.statsNormalize.tap(PLUGIN_NAME, (options, context) => {
392
+ for (const key of Object.keys(DEFAULTS)) {
393
+ if (options[key] === undefined)
397
394
  options[key] =
398
- /** @type {TODO} */
399
- (NORMALIZER[/** @type {NormalizerKeys} */ (key)])(options[key]);
400
- }
395
+ /** @type {Defaults[DefaultsKeys]} */
396
+ (DEFAULTS[/** @type {DefaultsKeys} */ (key)])(
397
+ options,
398
+ context,
399
+ compilation
400
+ );
401
+ }
402
+ for (const key of Object.keys(NORMALIZER)) {
403
+ options[key] =
404
+ /** @type {TODO} */
405
+ (NORMALIZER[/** @type {NormalizerKeys} */ (key)])(options[key]);
401
406
  }
402
- );
407
+ });
403
408
  });
404
409
  }
405
410
  }