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
@@ -1632,7 +1632,11 @@ class NormalModule extends Module {
1632
1632
  * @returns {void}
1633
1633
  */
1634
1634
  updateHash(hash, context) {
1635
- hash.update(/** @type {BuildInfo} */ (this.buildInfo).hash);
1635
+ const buildInfo = /** @type {BuildInfo} */ (this.buildInfo);
1636
+ hash.update(
1637
+ /** @type {string} */
1638
+ (buildInfo.hash)
1639
+ );
1636
1640
  /** @type {Generator} */
1637
1641
  (this.generator).updateHash(hash, {
1638
1642
  module: this,
@@ -13,6 +13,8 @@ const { join, dirname } = require("./util/fs");
13
13
 
14
14
  /** @typedef {(resolveData: ResolveData) => void} ModuleReplacer */
15
15
 
16
+ const PLUGIN_NAME = "NormalModuleReplacementPlugin";
17
+
16
18
  class NormalModuleReplacementPlugin {
17
19
  /**
18
20
  * Create an instance of the plugin
@@ -32,46 +34,41 @@ class NormalModuleReplacementPlugin {
32
34
  apply(compiler) {
33
35
  const resourceRegExp = this.resourceRegExp;
34
36
  const newResource = this.newResource;
35
- compiler.hooks.normalModuleFactory.tap(
36
- "NormalModuleReplacementPlugin",
37
- nmf => {
38
- nmf.hooks.beforeResolve.tap("NormalModuleReplacementPlugin", result => {
39
- if (resourceRegExp.test(result.request)) {
40
- if (typeof newResource === "function") {
41
- newResource(result);
42
- } else {
43
- result.request = newResource;
44
- }
37
+ compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, nmf => {
38
+ nmf.hooks.beforeResolve.tap(PLUGIN_NAME, result => {
39
+ if (resourceRegExp.test(result.request)) {
40
+ if (typeof newResource === "function") {
41
+ newResource(result);
42
+ } else {
43
+ result.request = newResource;
45
44
  }
46
- });
47
- nmf.hooks.afterResolve.tap("NormalModuleReplacementPlugin", result => {
48
- const createData = result.createData;
49
- if (
50
- resourceRegExp.test(/** @type {string} */ (createData.resource))
51
- ) {
52
- if (typeof newResource === "function") {
53
- newResource(result);
45
+ }
46
+ });
47
+ nmf.hooks.afterResolve.tap(PLUGIN_NAME, result => {
48
+ const createData = result.createData;
49
+ if (resourceRegExp.test(/** @type {string} */ (createData.resource))) {
50
+ if (typeof newResource === "function") {
51
+ newResource(result);
52
+ } else {
53
+ const fs =
54
+ /** @type {InputFileSystem} */
55
+ (compiler.inputFileSystem);
56
+ if (
57
+ newResource.startsWith("/") ||
58
+ (newResource.length > 1 && newResource[1] === ":")
59
+ ) {
60
+ createData.resource = newResource;
54
61
  } else {
55
- const fs =
56
- /** @type {InputFileSystem} */
57
- (compiler.inputFileSystem);
58
- if (
59
- newResource.startsWith("/") ||
60
- (newResource.length > 1 && newResource[1] === ":")
61
- ) {
62
- createData.resource = newResource;
63
- } else {
64
- createData.resource = join(
65
- fs,
66
- dirname(fs, /** @type {string} */ (createData.resource)),
67
- newResource
68
- );
69
- }
62
+ createData.resource = join(
63
+ fs,
64
+ dirname(fs, /** @type {string} */ (createData.resource)),
65
+ newResource
66
+ );
70
67
  }
71
68
  }
72
- });
73
- }
74
- );
69
+ }
70
+ });
71
+ });
75
72
  }
76
73
  }
77
74
 
@@ -8,6 +8,8 @@
8
8
  /** @typedef {import("./Compiler")} Compiler */
9
9
  /** @typedef {import("./config/target").PlatformTargetProperties} PlatformTargetProperties */
10
10
 
11
+ const PLUGIN_NAME = "PlatformPlugin";
12
+
11
13
  /**
12
14
  * Should be used only for "target === false" or
13
15
  * when you want to overwrite platform target properties
@@ -27,7 +29,7 @@ class PlatformPlugin {
27
29
  * @returns {void}
28
30
  */
29
31
  apply(compiler) {
30
- compiler.hooks.environment.tap("PlatformPlugin", () => {
32
+ compiler.hooks.environment.tap(PLUGIN_NAME, () => {
31
33
  compiler.platform = {
32
34
  ...compiler.platform,
33
35
  ...this.platform
@@ -9,6 +9,8 @@ const PrefetchDependency = require("./dependencies/PrefetchDependency");
9
9
 
10
10
  /** @typedef {import("./Compiler")} Compiler */
11
11
 
12
+ const PLUGIN_NAME = "PrefetchPlugin";
13
+
12
14
  class PrefetchPlugin {
13
15
  /**
14
16
  * @param {string} context context or request if context is not set
@@ -31,7 +33,7 @@ class PrefetchPlugin {
31
33
  */
32
34
  apply(compiler) {
33
35
  compiler.hooks.compilation.tap(
34
- "PrefetchPlugin",
36
+ PLUGIN_NAME,
35
37
  (compilation, { normalModuleFactory }) => {
36
38
  compilation.dependencyFactories.set(
37
39
  PrefetchDependency,
@@ -39,7 +41,7 @@ class PrefetchPlugin {
39
41
  );
40
42
  }
41
43
  );
42
- compiler.hooks.make.tapAsync("PrefetchPlugin", (compilation, callback) => {
44
+ compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
43
45
  compilation.addModuleChain(
44
46
  this.context || compiler.context,
45
47
  new PrefetchDependency(this.request),
@@ -140,6 +140,8 @@ const SKIPPED_QUEUE_CONTEXTS = ["import-module", "load-module"];
140
140
  /** @type {WeakMap<Compiler, ReportProgress | undefined>} */
141
141
  const progressReporters = new WeakMap();
142
142
 
143
+ const PLUGIN_NAME = "ProgressPlugin";
144
+
143
145
  class ProgressPlugin {
144
146
  /**
145
147
  * @param {Compiler} compiler the current compiler
@@ -395,14 +397,12 @@ class ProgressPlugin {
395
397
  update();
396
398
  };
397
399
 
398
- const cache = compiler
399
- .getCache("ProgressPlugin")
400
- .getItemCache("counts", null);
400
+ const cache = compiler.getCache(PLUGIN_NAME).getItemCache("counts", null);
401
401
 
402
402
  /** @type {Promise<CountsData> | undefined} */
403
403
  let cacheGetPromise;
404
404
 
405
- compiler.hooks.beforeCompile.tap("ProgressPlugin", () => {
405
+ compiler.hooks.beforeCompile.tap(PLUGIN_NAME, () => {
406
406
  if (!cacheGetPromise) {
407
407
  cacheGetPromise = cache.getPromise().then(
408
408
  data => {
@@ -420,7 +420,7 @@ class ProgressPlugin {
420
420
  }
421
421
  });
422
422
 
423
- compiler.hooks.afterCompile.tapPromise("ProgressPlugin", compilation => {
423
+ compiler.hooks.afterCompile.tapPromise(PLUGIN_NAME, compilation => {
424
424
  if (compilation.compiler.isChild()) return Promise.resolve();
425
425
  return /** @type {Promise<CountsData>} */ (cacheGetPromise).then(
426
426
  async oldData => {
@@ -442,7 +442,7 @@ class ProgressPlugin {
442
442
  );
443
443
  });
444
444
 
445
- compiler.hooks.compilation.tap("ProgressPlugin", compilation => {
445
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
446
446
  if (compilation.compiler.isChild()) return;
447
447
  lastModulesCount = modulesCount;
448
448
  lastEntriesCount = entriesCount;
@@ -455,35 +455,32 @@ class ProgressPlugin {
455
455
  0;
456
456
  doneModules = doneDependencies = doneEntries = 0;
457
457
 
458
- compilation.factorizeQueue.hooks.added.tap("ProgressPlugin", item =>
458
+ compilation.factorizeQueue.hooks.added.tap(PLUGIN_NAME, item =>
459
459
  factorizeAdd(compilation.factorizeQueue, item)
460
460
  );
461
- compilation.factorizeQueue.hooks.result.tap(
462
- "ProgressPlugin",
463
- factorizeDone
464
- );
461
+ compilation.factorizeQueue.hooks.result.tap(PLUGIN_NAME, factorizeDone);
465
462
 
466
- compilation.addModuleQueue.hooks.added.tap("ProgressPlugin", item =>
463
+ compilation.addModuleQueue.hooks.added.tap(PLUGIN_NAME, item =>
467
464
  moduleAdd(compilation.addModuleQueue, item)
468
465
  );
469
466
  compilation.processDependenciesQueue.hooks.result.tap(
470
- "ProgressPlugin",
467
+ PLUGIN_NAME,
471
468
  moduleDone
472
469
  );
473
470
 
474
471
  if (showActiveModules) {
475
- compilation.hooks.buildModule.tap("ProgressPlugin", moduleBuild);
472
+ compilation.hooks.buildModule.tap(PLUGIN_NAME, moduleBuild);
476
473
  }
477
474
 
478
- compilation.hooks.addEntry.tap("ProgressPlugin", entryAdd);
479
- compilation.hooks.failedEntry.tap("ProgressPlugin", entryDone);
480
- compilation.hooks.succeedEntry.tap("ProgressPlugin", entryDone);
475
+ compilation.hooks.addEntry.tap(PLUGIN_NAME, entryAdd);
476
+ compilation.hooks.failedEntry.tap(PLUGIN_NAME, entryDone);
477
+ compilation.hooks.succeedEntry.tap(PLUGIN_NAME, entryDone);
481
478
 
482
479
  // @ts-expect-error avoid dynamic require if bundled with webpack
483
480
  if (typeof __webpack_require__ !== "function") {
484
481
  const requiredLoaders = new Set();
485
482
  NormalModule.getCompilationHooks(compilation).beforeLoaders.tap(
486
- "ProgressPlugin",
483
+ PLUGIN_NAME,
487
484
  loaders => {
488
485
  for (const loader of loaders) {
489
486
  if (
@@ -550,7 +547,7 @@ class ProgressPlugin {
550
547
  const title = hooks[/** @type {keyof typeof hooks} */ (name)];
551
548
  const percentage = (idx / numberOfHooks) * 0.25 + 0.7;
552
549
  compilation.hooks[/** @type {keyof typeof hooks} */ (name)].intercept({
553
- name: "ProgressPlugin",
550
+ name: PLUGIN_NAME,
554
551
  call() {
555
552
  handler(percentage, "sealing", title);
556
553
  },
@@ -576,7 +573,7 @@ class ProgressPlugin {
576
573
  }
577
574
  });
578
575
  compiler.hooks.make.intercept({
579
- name: "ProgressPlugin",
576
+ name: PLUGIN_NAME,
580
577
  call() {
581
578
  handler(0.1, "building");
582
579
  },
@@ -592,7 +589,7 @@ class ProgressPlugin {
592
589
  */
593
590
  const interceptHook = (hook, progress, category, name) => {
594
591
  hook.intercept({
595
- name: "ProgressPlugin",
592
+ name: PLUGIN_NAME,
596
593
  call() {
597
594
  handler(progress, category, name);
598
595
  },
@@ -618,14 +615,14 @@ class ProgressPlugin {
618
615
  });
619
616
  };
620
617
  compiler.cache.hooks.endIdle.intercept({
621
- name: "ProgressPlugin",
618
+ name: PLUGIN_NAME,
622
619
  call() {
623
620
  handler(0, "");
624
621
  }
625
622
  });
626
623
  interceptHook(compiler.cache.hooks.endIdle, 0.01, "cache", "end idle");
627
624
  compiler.hooks.beforeRun.intercept({
628
- name: "ProgressPlugin",
625
+ name: PLUGIN_NAME,
629
626
  call() {
630
627
  handler(0, "");
631
628
  }
@@ -659,7 +656,7 @@ class ProgressPlugin {
659
656
  interceptHook(compiler.hooks.afterEmit, 0.98, "emitting", "after emit");
660
657
  interceptHook(compiler.hooks.done, 0.99, "done", "plugins");
661
658
  compiler.hooks.done.intercept({
662
- name: "ProgressPlugin",
659
+ name: PLUGIN_NAME,
663
660
  done() {
664
661
  handler(0.99, "");
665
662
  }
@@ -679,13 +676,13 @@ class ProgressPlugin {
679
676
  "closing watch compilation"
680
677
  );
681
678
  compiler.cache.hooks.beginIdle.intercept({
682
- name: "ProgressPlugin",
679
+ name: PLUGIN_NAME,
683
680
  done() {
684
681
  handler(1, "");
685
682
  }
686
683
  });
687
684
  compiler.cache.hooks.shutdown.intercept({
688
- name: "ProgressPlugin",
685
+ name: PLUGIN_NAME,
689
686
  done() {
690
687
  handler(1, "");
691
688
  }
@@ -37,6 +37,8 @@ const identifierUtils = require("./util/identifier");
37
37
  * @property {boolean=} portableIds true, when ids need to be portable
38
38
  */
39
39
 
40
+ const PLUGIN_NAME = "RecordIdsPlugin";
41
+
40
42
  class RecordIdsPlugin {
41
43
  /**
42
44
  * @param {RecordIdsPluginOptions=} options object
@@ -69,59 +71,43 @@ class RecordIdsPlugin {
69
71
  return module.identifier();
70
72
  };
71
73
 
72
- compiler.hooks.compilation.tap("RecordIdsPlugin", compilation => {
73
- compilation.hooks.recordModules.tap(
74
- "RecordIdsPlugin",
75
- /**
76
- * @param {Iterable<Module>} modules the modules array
77
- * @param {Records} records the records object
78
- * @returns {void}
79
- */
80
- (modules, records) => {
74
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
75
+ compilation.hooks.recordModules.tap(PLUGIN_NAME, (modules, records) => {
76
+ const chunkGraph = compilation.chunkGraph;
77
+ if (!records.modules) records.modules = {};
78
+ if (!records.modules.byIdentifier) records.modules.byIdentifier = {};
79
+ /** @type {Set<number>} */
80
+ const usedIds = new Set();
81
+ for (const module of modules) {
82
+ const moduleId = chunkGraph.getModuleId(module);
83
+ if (typeof moduleId !== "number") continue;
84
+ const identifier = getModuleIdentifier(module);
85
+ records.modules.byIdentifier[identifier] = moduleId;
86
+ usedIds.add(moduleId);
87
+ }
88
+ records.modules.usedIds = Array.from(usedIds).sort(compareNumbers);
89
+ });
90
+ compilation.hooks.reviveModules.tap(PLUGIN_NAME, (modules, records) => {
91
+ if (!records.modules) return;
92
+ if (records.modules.byIdentifier) {
81
93
  const chunkGraph = compilation.chunkGraph;
82
- if (!records.modules) records.modules = {};
83
- if (!records.modules.byIdentifier) records.modules.byIdentifier = {};
84
94
  /** @type {Set<number>} */
85
95
  const usedIds = new Set();
86
96
  for (const module of modules) {
87
97
  const moduleId = chunkGraph.getModuleId(module);
88
- if (typeof moduleId !== "number") continue;
98
+ if (moduleId !== null) continue;
89
99
  const identifier = getModuleIdentifier(module);
90
- records.modules.byIdentifier[identifier] = moduleId;
91
- usedIds.add(moduleId);
100
+ const id = records.modules.byIdentifier[identifier];
101
+ if (id === undefined) continue;
102
+ if (usedIds.has(id)) continue;
103
+ usedIds.add(id);
104
+ chunkGraph.setModuleId(module, id);
92
105
  }
93
- records.modules.usedIds = Array.from(usedIds).sort(compareNumbers);
94
106
  }
95
- );
96
- compilation.hooks.reviveModules.tap(
97
- "RecordIdsPlugin",
98
- /**
99
- * @param {Iterable<Module>} modules the modules array
100
- * @param {Records} records the records object
101
- * @returns {void}
102
- */
103
- (modules, records) => {
104
- if (!records.modules) return;
105
- if (records.modules.byIdentifier) {
106
- const chunkGraph = compilation.chunkGraph;
107
- /** @type {Set<number>} */
108
- const usedIds = new Set();
109
- for (const module of modules) {
110
- const moduleId = chunkGraph.getModuleId(module);
111
- if (moduleId !== null) continue;
112
- const identifier = getModuleIdentifier(module);
113
- const id = records.modules.byIdentifier[identifier];
114
- if (id === undefined) continue;
115
- if (usedIds.has(id)) continue;
116
- usedIds.add(id);
117
- chunkGraph.setModuleId(module, id);
118
- }
119
- }
120
- if (Array.isArray(records.modules.usedIds)) {
121
- compilation.usedModuleIds = new Set(records.modules.usedIds);
122
- }
107
+ if (Array.isArray(records.modules.usedIds)) {
108
+ compilation.usedModuleIds = new Set(records.modules.usedIds);
123
109
  }
124
- );
110
+ });
125
111
 
126
112
  /**
127
113
  * @param {Chunk} chunk the chunk
@@ -167,75 +153,59 @@ class RecordIdsPlugin {
167
153
  return sources;
168
154
  };
169
155
 
170
- compilation.hooks.recordChunks.tap(
171
- "RecordIdsPlugin",
172
- /**
173
- * @param {Iterable<Chunk>} chunks the chunks array
174
- * @param {Records} records the records object
175
- * @returns {void}
176
- */
177
- (chunks, records) => {
178
- if (!records.chunks) records.chunks = {};
179
- if (!records.chunks.byName) records.chunks.byName = {};
180
- if (!records.chunks.bySource) records.chunks.bySource = {};
181
- /** @type {Set<number>} */
182
- const usedIds = new Set();
156
+ compilation.hooks.recordChunks.tap(PLUGIN_NAME, (chunks, records) => {
157
+ if (!records.chunks) records.chunks = {};
158
+ if (!records.chunks.byName) records.chunks.byName = {};
159
+ if (!records.chunks.bySource) records.chunks.bySource = {};
160
+ /** @type {Set<number>} */
161
+ const usedIds = new Set();
162
+ for (const chunk of chunks) {
163
+ if (typeof chunk.id !== "number") continue;
164
+ const name = chunk.name;
165
+ if (name) records.chunks.byName[name] = chunk.id;
166
+ const sources = getChunkSources(chunk);
167
+ for (const source of sources) {
168
+ records.chunks.bySource[source] = chunk.id;
169
+ }
170
+ usedIds.add(chunk.id);
171
+ }
172
+ records.chunks.usedIds = Array.from(usedIds).sort(compareNumbers);
173
+ });
174
+ compilation.hooks.reviveChunks.tap(PLUGIN_NAME, (chunks, records) => {
175
+ if (!records.chunks) return;
176
+ /** @type {Set<number>} */
177
+ const usedIds = new Set();
178
+ if (records.chunks.byName) {
183
179
  for (const chunk of chunks) {
184
- if (typeof chunk.id !== "number") continue;
185
- const name = chunk.name;
186
- if (name) records.chunks.byName[name] = chunk.id;
187
- const sources = getChunkSources(chunk);
188
- for (const source of sources) {
189
- records.chunks.bySource[source] = chunk.id;
190
- }
191
- usedIds.add(chunk.id);
180
+ if (chunk.id !== null) continue;
181
+ if (!chunk.name) continue;
182
+ const id = records.chunks.byName[chunk.name];
183
+ if (id === undefined) continue;
184
+ if (usedIds.has(id)) continue;
185
+ usedIds.add(id);
186
+ chunk.id = id;
187
+ chunk.ids = [id];
192
188
  }
193
- records.chunks.usedIds = Array.from(usedIds).sort(compareNumbers);
194
189
  }
195
- );
196
- compilation.hooks.reviveChunks.tap(
197
- "RecordIdsPlugin",
198
- /**
199
- * @param {Iterable<Chunk>} chunks the chunks array
200
- * @param {Records} records the records object
201
- * @returns {void}
202
- */
203
- (chunks, records) => {
204
- if (!records.chunks) return;
205
- /** @type {Set<number>} */
206
- const usedIds = new Set();
207
- if (records.chunks.byName) {
208
- for (const chunk of chunks) {
209
- if (chunk.id !== null) continue;
210
- if (!chunk.name) continue;
211
- const id = records.chunks.byName[chunk.name];
190
+ if (records.chunks.bySource) {
191
+ for (const chunk of chunks) {
192
+ if (chunk.id !== null) continue;
193
+ const sources = getChunkSources(chunk);
194
+ for (const source of sources) {
195
+ const id = records.chunks.bySource[source];
212
196
  if (id === undefined) continue;
213
197
  if (usedIds.has(id)) continue;
214
198
  usedIds.add(id);
215
199
  chunk.id = id;
216
200
  chunk.ids = [id];
201
+ break;
217
202
  }
218
203
  }
219
- if (records.chunks.bySource) {
220
- for (const chunk of chunks) {
221
- if (chunk.id !== null) continue;
222
- const sources = getChunkSources(chunk);
223
- for (const source of sources) {
224
- const id = records.chunks.bySource[source];
225
- if (id === undefined) continue;
226
- if (usedIds.has(id)) continue;
227
- usedIds.add(id);
228
- chunk.id = id;
229
- chunk.ids = [id];
230
- break;
231
- }
232
- }
233
- }
234
- if (Array.isArray(records.chunks.usedIds)) {
235
- compilation.usedChunkIds = new Set(records.chunks.usedIds);
236
- }
237
204
  }
238
- );
205
+ if (Array.isArray(records.chunks.usedIds)) {
206
+ compilation.usedChunkIds = new Set(records.chunks.usedIds);
207
+ }
208
+ });
239
209
  });
240
210
  }
241
211
  }