webpack 5.109.1 → 5.109.2

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.
package/README.md CHANGED
@@ -629,6 +629,10 @@ Before we started using OpenCollective, donations were made anonymously. Now tha
629
629
  <a href="https://opencollective.com/webpack/backer/99/website?requireActive=false" target="_blank"><img width="30" src="https://opencollective.com/webpack/backer/99/avatar.svg?requireActive=false"></a>
630
630
  <a href="https://opencollective.com/webpack/backer/100/website?requireActive=false" target="_blank"><img width="30" src="https://opencollective.com/webpack/backer/100/avatar.svg?requireActive=false"></a>
631
631
 
632
+ ## Other Partners
633
+
634
+ - [CodSpeed](https://codspeed.io/?utm_source=webpack&utm_medium=readme) for generously supporting us with benchmarks on their paid runners.
635
+
632
636
  ## Special Thanks to
633
637
 
634
638
  <p>(In chronological order)</p>
@@ -22,10 +22,17 @@ const processAsyncTree = require("./util/processAsyncTree");
22
22
 
23
23
  /** @typedef {Map<string, number>} Assets */
24
24
 
25
+ const createCompilationHooks = () => ({
26
+ /**
27
+ * When returning true the file/directory will be kept during cleaning, returning false will clean it and ignore the following plugins and config.
28
+ * @type {SyncBailHook<[string], boolean | void>}
29
+ * @since 5.20.0
30
+ */
31
+ keep: new SyncBailHook(["ignore"])
32
+ });
33
+
25
34
  /**
26
- * Defines the clean plugin compilation hooks type used by this module.
27
- * @typedef {object} CleanPluginCompilationHooks
28
- * @property {SyncBailHook<[string], boolean | void>} keep when returning true the file/directory will be kept during cleaning, returning false will clean it and ignore the following plugins and config
35
+ * @typedef {ReturnType<typeof createCompilationHooks>} CleanPluginCompilationHooks
29
36
  */
30
37
 
31
38
  /**
@@ -484,12 +491,7 @@ class CleanPlugin {
484
491
  }
485
492
  }
486
493
 
487
- CleanPlugin.getCompilationHooks = createHooksRegistry(
488
- () =>
489
- /** @type {CleanPluginCompilationHooks} */ ({
490
- keep: new SyncBailHook(["ignore"])
491
- })
492
- );
494
+ CleanPlugin.getCompilationHooks = createHooksRegistry(createCompilationHooks);
493
495
 
494
496
  module.exports = CleanPlugin;
495
497
  module.exports._getDirectories = getDirectories;
@@ -884,9 +884,15 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
884
884
  "runtime"
885
885
  ]),
886
886
 
887
- /** @type {SyncHook<[ExecuteModuleArgument, ExecuteModuleContext]>} */
887
+ /**
888
+ * @type {SyncHook<[ExecuteModuleArgument, ExecuteModuleContext]>}
889
+ * @since 5.32.0
890
+ */
888
891
  executeModule: new SyncHook(["options", "context"]),
889
- /** @type {AsyncParallelHook<[ExecuteModuleArgument, ExecuteModuleContext]>} */
892
+ /**
893
+ * @type {AsyncParallelHook<[ExecuteModuleArgument, ExecuteModuleContext]>}
894
+ * @since 5.33.0
895
+ */
890
896
  prepareModuleExecution: new AsyncParallelHook(["options", "context"]),
891
897
 
892
898
  /** @type {AsyncSeriesHook<[Iterable<Module>]>} */
@@ -1090,7 +1096,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1090
1096
 
1091
1097
  processAssets: processAssetsHook,
1092
1098
  afterProcessAssets: afterProcessAssetsHook,
1093
- /** @type {AsyncSeriesHook<[CompilationAssets]>} */
1099
+ /**
1100
+ * @type {AsyncSeriesHook<[CompilationAssets]>}
1101
+ * @since 5.8.0
1102
+ */
1094
1103
  processAdditionalAssets: new AsyncSeriesHook(["assets"]),
1095
1104
 
1096
1105
  /** @type {SyncBailHook<[], boolean | void>} */
package/lib/Compiler.js CHANGED
@@ -222,9 +222,15 @@ class Compiler {
222
222
  /** @type {AsyncSeriesHook<[Compilation]>} */
223
223
  afterCompile: new AsyncSeriesHook(["compilation"]),
224
224
 
225
- /** @type {AsyncSeriesHook<[]>} */
225
+ /**
226
+ * @type {AsyncSeriesHook<[]>}
227
+ * @since 5.67.0
228
+ */
226
229
  readRecords: new AsyncSeriesHook([]),
227
- /** @type {AsyncSeriesHook<[]>} */
230
+ /**
231
+ * @type {AsyncSeriesHook<[]>}
232
+ * @since 5.67.0
233
+ */
228
234
  emitRecords: new AsyncSeriesHook([]),
229
235
 
230
236
  /** @type {AsyncSeriesHook<[Compiler]>} */
@@ -235,7 +241,10 @@ class Compiler {
235
241
  invalid: new SyncHook(["filename", "changeTime"]),
236
242
  /** @type {SyncHook<[]>} */
237
243
  watchClose: new SyncHook([]),
238
- /** @type {AsyncSeriesHook<[]>} */
244
+ /**
245
+ * @type {AsyncSeriesHook<[]>}
246
+ * @since 5.17.0
247
+ */
239
248
  shutdown: new AsyncSeriesHook([]),
240
249
 
241
250
  /** @type {SyncBailHook<[string, string, EXPECTED_ANY[] | undefined], true | void>} */
@@ -243,7 +252,10 @@ class Compiler {
243
252
 
244
253
  // TODO the following hooks are weirdly located here
245
254
  // TODO move them for webpack 5
246
- /** @type {SyncHook<[]>} */
255
+ /**
256
+ * @type {SyncHook<[]>}
257
+ * @since 5.106.0
258
+ */
247
259
  validate: new SyncHook([]),
248
260
  /** @type {SyncHook<[]>} */
249
261
  environment: new SyncHook([]),
@@ -628,6 +628,14 @@ const getRuntimeRequirements = (code) => {
628
628
  : [RuntimeGlobals.requireScope];
629
629
  };
630
630
 
631
+ const createCompilationHooks = () => ({
632
+ /**
633
+ * @type {SyncWaterfallHook<[Record<string, CodeValue>]>}
634
+ * @since 5.104.0
635
+ */
636
+ definitions: new SyncWaterfallHook(["definitions"])
637
+ });
638
+
631
639
  /**
632
640
  * Prefixes an evaluation error with the offending define key so a bare
633
641
  * "Unexpected token" becomes actionable. The original error is mutated and
@@ -649,9 +657,7 @@ const annotateEvaluationError = (key, code, error) => {
649
657
  };
650
658
 
651
659
  /**
652
- * Defines the define plugin hooks type used by this module.
653
- * @typedef {object} DefinePluginHooks
654
- * @property {SyncWaterfallHook<[Record<string, CodeValue>]>} definitions
660
+ * @typedef {ReturnType<typeof createCompilationHooks>} DefinePluginHooks
655
661
  */
656
662
 
657
663
  /** @typedef {Record<string, CodeValue>} Definitions */
@@ -1259,12 +1265,7 @@ class DefinePlugin {
1259
1265
  }
1260
1266
  }
1261
1267
 
1262
- DefinePlugin.getCompilationHooks = createHooksRegistry(
1263
- () =>
1264
- /** @type {DefinePluginHooks} */ ({
1265
- definitions: new SyncWaterfallHook(["definitions"])
1266
- })
1267
- );
1268
+ DefinePlugin.getCompilationHooks = createHooksRegistry(createCompilationHooks);
1268
1269
 
1269
1270
  module.exports = DefinePlugin;
1270
1271
  module.exports.VALUE_DEP_MAIN = VALUE_DEP_MAIN;
@@ -810,10 +810,16 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
810
810
  /** @typedef {Record<string, string | string[]>} RequestRecord */
811
811
  /** @typedef {string | string[] | RequestRecord} ExternalModuleRequest */
812
812
 
813
+ const createCompilationHooks = () => ({
814
+ /**
815
+ * @type {SyncBailHook<[Chunk, Compilation], boolean>}
816
+ * @since 5.106.0
817
+ */
818
+ chunkCondition: new SyncBailHook(["chunk", "compilation"])
819
+ });
820
+
813
821
  /**
814
- * Defines the external module hooks type used by this module.
815
- * @typedef {object} ExternalModuleHooks
816
- * @property {SyncBailHook<[Chunk, Compilation], boolean>} chunkCondition
822
+ * @typedef {ReturnType<typeof createCompilationHooks>} ExternalModuleHooks
817
823
  */
818
824
 
819
825
  /**
@@ -1486,10 +1492,7 @@ class ExternalModule extends Module {
1486
1492
  }
1487
1493
 
1488
1494
  ExternalModule.getCompilationHooks = createHooksRegistry(
1489
- () =>
1490
- /** @type {ExternalModuleHooks} */ ({
1491
- chunkCondition: new SyncBailHook(["chunk", "compilation"])
1492
- })
1495
+ createCompilationHooks
1493
1496
  );
1494
1497
 
1495
1498
  makeSerializable(ExternalModule, "webpack/lib/ExternalModule");
@@ -169,11 +169,14 @@ ModuleFilenameHelpers.createFilename = (
169
169
  let moduleId;
170
170
  /** @type {ReturnStringCallback} */
171
171
  let shortIdentifier;
172
+ /** @type {ReturnStringCallback} */
173
+ let resourceIdentifier;
172
174
  if (typeof module === "string") {
173
175
  shortIdentifier =
174
176
  /** @type {ReturnStringCallback} */
175
177
  (memoize(() => requestShortener.shorten(module)));
176
178
  identifier = shortIdentifier;
179
+ resourceIdentifier = shortIdentifier;
177
180
  moduleId = () => "";
178
181
  absoluteResourcePath = () =>
179
182
  /** @type {string} */ (module.split("!").pop());
@@ -182,6 +185,14 @@ ModuleFilenameHelpers.createFilename = (
182
185
  shortIdentifier = memoize(() =>
183
186
  module.readableIdentifier(requestShortener)
184
187
  );
188
+ // `[resource]` and `[loaders]` must stay request paths: a subclass's
189
+ // readable identifier may carry display-only decorations (e.g. CssModule's
190
+ // `css ` prefix)
191
+ resourceIdentifier = memoize(() =>
192
+ module instanceof NormalModule
193
+ ? /** @type {string} */ (requestShortener.shorten(module.userRequest))
194
+ : module.readableIdentifier(requestShortener)
195
+ );
185
196
  identifier =
186
197
  /** @type {ReturnStringCallback} */
187
198
  (memoize(() => requestShortener.shorten(module.identifier())));
@@ -196,9 +207,9 @@ ModuleFilenameHelpers.createFilename = (
196
207
  }
197
208
  const resource =
198
209
  /** @type {ReturnStringCallback} */
199
- (memoize(() => shortIdentifier().split("!").pop()));
210
+ (memoize(() => resourceIdentifier().split("!").pop()));
200
211
 
201
- const loaders = getBefore(shortIdentifier, "!");
212
+ const loaders = getBefore(resourceIdentifier, "!");
202
213
  const allLoaders = getBefore(identifier, "!");
203
214
  const query = getAfter(resource, "?");
204
215
  const resourcePath = () => {
@@ -52,7 +52,7 @@ const {
52
52
  ABSOLUTE_PATH_REGEXP,
53
53
  absolutify,
54
54
  contextify,
55
- makePathsRelative
55
+ contextifySourceUrl
56
56
  } = require("./util/identifier");
57
57
  const makeSerializable = require("./util/makeSerializable");
58
58
  const memoize = require("./util/memoize");
@@ -391,21 +391,6 @@ const walkSideEffects = (rootMod, moduleGraph, SideEffectDep) => {
391
391
  * @property {string | null=} type
392
392
  */
393
393
 
394
- /**
395
- * @param {string} context absolute context path
396
- * @param {string} source a source path
397
- * @param {AssociatedObjectForCache=} associatedObjectForCache an object to which the cache will be attached
398
- * @returns {string} new source path
399
- */
400
- const contextifySourceUrl = (context, source, associatedObjectForCache) => {
401
- if (source.startsWith("webpack://")) return source;
402
- return `webpack://${makePathsRelative(
403
- context,
404
- source,
405
- associatedObjectForCache
406
- )}`;
407
- };
408
-
409
394
  /**
410
395
  * @param {string} context absolute context path
411
396
  * @param {string | RawSourceMap} sourceMap a source map
@@ -471,16 +456,79 @@ const asBuffer = (input) => {
471
456
  * @typedef {HookMap<FakeHook<AsyncSeriesBailHook<[string, NormalModule], string | Buffer | null>>>} DeprecatedReadResourceForScheme
472
457
  */
473
458
 
459
+ const createCompilationHooks = () => {
460
+ /** @type {HookMap<AsyncSeriesBailHook<[AnyLoaderContext], string | Buffer | null>>} */
461
+ const readResource = new HookMap(
462
+ () => new AsyncSeriesBailHook(["loaderContext"])
463
+ );
464
+ return {
465
+ // TODO webpack 6 deprecate
466
+ /**
467
+ * @deprecated Use the `readResource` hook instead.
468
+ * @type {DeprecatedReadResourceForScheme}
469
+ */
470
+ readResourceForScheme: new HookMap((scheme) => {
471
+ const hook = readResource.for(scheme);
472
+ return createFakeHook(
473
+ /** @type {AsyncSeriesBailHook<[string, NormalModule], string | Buffer | null>} */ ({
474
+ tap: (options, fn) =>
475
+ hook.tap(options, (loaderContext) =>
476
+ fn(
477
+ loaderContext.resource,
478
+ /** @type {NormalModule} */ (loaderContext._module)
479
+ )
480
+ ),
481
+ tapAsync: (options, fn) =>
482
+ hook.tapAsync(options, (loaderContext, callback) =>
483
+ fn(
484
+ loaderContext.resource,
485
+ /** @type {NormalModule} */ (loaderContext._module),
486
+ callback
487
+ )
488
+ ),
489
+ tapPromise: (options, fn) =>
490
+ hook.tapPromise(options, (loaderContext) =>
491
+ fn(
492
+ loaderContext.resource,
493
+ /** @type {NormalModule} */ (loaderContext._module)
494
+ )
495
+ )
496
+ })
497
+ );
498
+ }),
499
+ /**
500
+ * @since 5.58.0
501
+ */
502
+ readResource,
503
+ /** @type {SyncHook<[AnyLoaderContext, NormalModule]>} */
504
+ loader: new SyncHook(["loaderContext", "module"]),
505
+ /** @type {SyncHook<[LoaderItem[], NormalModule, AnyLoaderContext]>} */
506
+ beforeLoaders: new SyncHook(["loaders", "module", "loaderContext"]),
507
+ /**
508
+ * @type {SyncHook<[NormalModule]>}
509
+ * @since 5.59.0
510
+ */
511
+ beforeParse: new SyncHook(["module"]),
512
+ /**
513
+ * @type {SyncHook<[NormalModule]>}
514
+ * @since 5.59.0
515
+ */
516
+ beforeSnapshot: new SyncHook(["module"]),
517
+ /**
518
+ * @type {SyncWaterfallHook<[Result, NormalModule]>}
519
+ * @since 5.99.0
520
+ */
521
+ processResult: new SyncWaterfallHook(["result", "module"]),
522
+ /**
523
+ * @type {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>}
524
+ * @since 5.49.0
525
+ */
526
+ needBuild: new AsyncSeriesBailHook(["module", "context"])
527
+ };
528
+ };
529
+
474
530
  /**
475
- * @typedef {object} NormalModuleCompilationHooks
476
- * @property {SyncHook<[AnyLoaderContext, NormalModule]>} loader
477
- * @property {SyncHook<[LoaderItem[], NormalModule, AnyLoaderContext]>} beforeLoaders
478
- * @property {SyncHook<[NormalModule]>} beforeParse
479
- * @property {SyncHook<[NormalModule]>} beforeSnapshot
480
- * @property {DeprecatedReadResourceForScheme} readResourceForScheme
481
- * @property {HookMap<AsyncSeriesBailHook<[AnyLoaderContext], string | Buffer | null>>} readResource
482
- * @property {SyncWaterfallHook<[Result, NormalModule]>} processResult
483
- * @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
531
+ * @typedef {ReturnType<typeof createCompilationHooks>} NormalModuleCompilationHooks
484
532
  */
485
533
 
486
534
  /**
@@ -524,52 +572,7 @@ const asBuffer = (input) => {
524
572
 
525
573
  /** @typedef {BuildInfo & KnownNormalModuleBuildInfo} NormalModuleBuildInfo */
526
574
 
527
- const normalModuleHooksRegistry = createHooksRegistry(() => {
528
- // TODO webpack 6 deprecate
529
- /** @type {Partial<NormalModuleCompilationHooks>} */
530
- const hooks = {};
531
- hooks.readResourceForScheme = new HookMap((scheme) => {
532
- const hook =
533
- /** @type {NormalModuleCompilationHooks} */
534
- (hooks).readResource.for(scheme);
535
- return createFakeHook(
536
- /** @type {AsyncSeriesBailHook<[string, NormalModule], string | Buffer | null>} */ ({
537
- tap: (options, fn) =>
538
- hook.tap(options, (loaderContext) =>
539
- fn(
540
- loaderContext.resource,
541
- /** @type {NormalModule} */ (loaderContext._module)
542
- )
543
- ),
544
- tapAsync: (options, fn) =>
545
- hook.tapAsync(options, (loaderContext, callback) =>
546
- fn(
547
- loaderContext.resource,
548
- /** @type {NormalModule} */ (loaderContext._module),
549
- callback
550
- )
551
- ),
552
- tapPromise: (options, fn) =>
553
- hook.tapPromise(options, (loaderContext) =>
554
- fn(
555
- loaderContext.resource,
556
- /** @type {NormalModule} */ (loaderContext._module)
557
- )
558
- )
559
- })
560
- );
561
- });
562
- hooks.readResource = new HookMap(
563
- () => new AsyncSeriesBailHook(["loaderContext"])
564
- );
565
- hooks.loader = new SyncHook(["loaderContext", "module"]);
566
- hooks.beforeLoaders = new SyncHook(["loaders", "module", "loaderContext"]);
567
- hooks.beforeParse = new SyncHook(["module"]);
568
- hooks.beforeSnapshot = new SyncHook(["module"]);
569
- hooks.processResult = new SyncWaterfallHook(["result", "module"]);
570
- hooks.needBuild = new AsyncSeriesBailHook(["module", "context"]);
571
- return /** @type {NormalModuleCompilationHooks} */ (hooks);
572
- });
575
+ const normalModuleHooksRegistry = createHooksRegistry(createCompilationHooks);
573
576
 
574
577
  class NormalModule extends Module {
575
578
  /**
@@ -435,7 +435,10 @@ class NormalModuleFactory extends ModuleFactory {
435
435
  resolveForScheme: new HookMap(
436
436
  () => new AsyncSeriesBailHook(["resourceData", "resolveData"])
437
437
  ),
438
- /** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */
438
+ /**
439
+ * @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>}
440
+ * @since 5.49.0
441
+ */
439
442
  resolveInScheme: new HookMap(
440
443
  () => new AsyncSeriesBailHook(["resourceData", "resolveData"])
441
444
  ),
@@ -461,7 +464,10 @@ class NormalModuleFactory extends ModuleFactory {
461
464
  generator: new HookMap(
462
465
  () => new SyncHook(["generator", "generatorOptions"])
463
466
  ),
464
- /** @type {HookMap<SyncBailHook<[CreateData, ResolveData], Module | void>>} */
467
+ /**
468
+ * @type {HookMap<SyncBailHook<[CreateData, ResolveData], Module | void>>}
469
+ * @since 5.81.0
470
+ */
465
471
  createModuleClass: new HookMap(
466
472
  () => new SyncBailHook(["createData", "resolveData"])
467
473
  )