webpack 5.85.1 → 5.87.0

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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (140) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +150 -99
  3. package/lib/CaseSensitiveModulesWarning.js +3 -1
  4. package/lib/Chunk.js +35 -17
  5. package/lib/ChunkGroup.js +11 -6
  6. package/lib/Compiler.js +4 -3
  7. package/lib/ConcatenationScope.js +2 -2
  8. package/lib/ConditionalInitFragment.js +11 -1
  9. package/lib/ConstPlugin.js +57 -29
  10. package/lib/ContextModule.js +4 -2
  11. package/lib/ContextModuleFactory.js +1 -0
  12. package/lib/DependenciesBlock.js +1 -1
  13. package/lib/DllModule.js +6 -0
  14. package/lib/EvalSourceMapDevToolPlugin.js +2 -1
  15. package/lib/ExternalModule.js +15 -8
  16. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  17. package/lib/Module.js +7 -1
  18. package/lib/ModuleDependencyError.js +4 -2
  19. package/lib/ModuleDependencyWarning.js +4 -2
  20. package/lib/ModuleGraph.js +31 -24
  21. package/lib/ModuleGraphConnection.js +19 -6
  22. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  23. package/lib/ModuleNotFoundError.js +5 -2
  24. package/lib/ModuleStoreError.js +2 -1
  25. package/lib/ModuleTypeConstants.js +7 -0
  26. package/lib/MultiWatching.js +4 -0
  27. package/lib/ProgressPlugin.js +71 -15
  28. package/lib/RuntimeGlobals.js +5 -0
  29. package/lib/RuntimePlugin.js +2 -1
  30. package/lib/RuntimeTemplate.js +20 -2
  31. package/lib/WebpackError.js +6 -5
  32. package/lib/WebpackOptionsApply.js +4 -2
  33. package/lib/WebpackOptionsDefaulter.js +10 -3
  34. package/lib/config/defaults.js +31 -2
  35. package/lib/css/CssExportsGenerator.js +9 -0
  36. package/lib/css/CssGenerator.js +1 -1
  37. package/lib/css/CssLoadingRuntimeModule.js +13 -6
  38. package/lib/css/CssModulesPlugin.js +42 -14
  39. package/lib/css/CssParser.js +12 -0
  40. package/lib/dependencies/ConstDependency.js +2 -2
  41. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  42. package/lib/dependencies/ImportParserPlugin.js +25 -1
  43. package/lib/dependencies/JsonExportsDependency.js +1 -1
  44. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  45. package/lib/javascript/BasicEvaluatedExpression.js +23 -15
  46. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  47. package/lib/javascript/JavascriptModulesPlugin.js +1 -0
  48. package/lib/javascript/JavascriptParser.js +118 -58
  49. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  50. package/lib/json/JsonData.js +2 -2
  51. package/lib/json/JsonParser.js +25 -12
  52. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  53. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  54. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  55. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  56. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  57. package/lib/optimize/InnerGraph.js +4 -4
  58. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  59. package/lib/optimize/MangleExportsPlugin.js +1 -1
  60. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  61. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  62. package/lib/optimize/RealContentHashPlugin.js +80 -30
  63. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  64. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  65. package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
  66. package/lib/optimize/SplitChunksPlugin.js +71 -31
  67. package/lib/performance/SizeLimitsPlugin.js +7 -4
  68. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +3 -1
  69. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  70. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +5 -2
  71. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +3 -1
  72. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +3 -1
  73. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  74. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  75. package/lib/rules/RuleSetCompiler.js +3 -3
  76. package/lib/rules/UseEffectRulePlugin.js +6 -4
  77. package/lib/runtime/AsyncModuleRuntimeModule.js +4 -1
  78. package/lib/runtime/AutoPublicPathRuntimeModule.js +3 -1
  79. package/lib/runtime/BaseUriRuntimeModule.js +2 -2
  80. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +4 -1
  81. package/lib/runtime/CompatRuntimeModule.js +6 -1
  82. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +4 -1
  83. package/lib/runtime/CreateScriptRuntimeModule.js +3 -1
  84. package/lib/runtime/CreateScriptUrlRuntimeModule.js +3 -1
  85. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +4 -1
  86. package/lib/runtime/EnsureChunkRuntimeModule.js +14 -3
  87. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -9
  88. package/lib/runtime/GetFullHashRuntimeModule.js +3 -2
  89. package/lib/runtime/GetMainFilenameRuntimeModule.js +4 -1
  90. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +3 -1
  91. package/lib/runtime/HasOwnPropertyRuntimeModule.js +4 -1
  92. package/lib/runtime/LoadScriptRuntimeModule.js +63 -47
  93. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +4 -1
  94. package/lib/runtime/OnChunksLoadedRuntimeModule.js +3 -1
  95. package/lib/runtime/PublicPathRuntimeModule.js +3 -1
  96. package/lib/runtime/RelativeUrlRuntimeModule.js +4 -1
  97. package/lib/runtime/RuntimeIdRuntimeModule.js +5 -1
  98. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -2
  99. package/lib/runtime/StartupEntrypointRuntimeModule.js +2 -1
  100. package/lib/serialization/BinaryMiddleware.js +143 -1
  101. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  102. package/lib/serialization/ObjectMiddleware.js +9 -3
  103. package/lib/serialization/types.js +1 -1
  104. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  105. package/lib/sharing/ConsumeSharedRuntimeModule.js +13 -4
  106. package/lib/sharing/ProvideSharedDependency.js +11 -0
  107. package/lib/sharing/ProvideSharedModule.js +4 -0
  108. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  109. package/lib/sharing/ShareRuntimeModule.js +11 -4
  110. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  111. package/lib/sharing/utils.js +32 -5
  112. package/lib/util/AsyncQueue.js +4 -2
  113. package/lib/util/ParallelismFactorCalculator.js +10 -0
  114. package/lib/util/Semaphore.js +1 -1
  115. package/lib/util/createHash.js +30 -9
  116. package/lib/util/deprecation.js +10 -3
  117. package/lib/util/deterministicGrouping.js +50 -11
  118. package/lib/util/findGraphRoots.js +4 -2
  119. package/lib/util/memoize.js +3 -3
  120. package/lib/util/processAsyncTree.js +7 -1
  121. package/lib/util/registerExternalSerializer.js +1 -1
  122. package/lib/util/runtime.js +14 -1
  123. package/lib/util/smartGrouping.js +1 -1
  124. package/lib/validateSchema.js +6 -2
  125. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +5 -1
  126. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  127. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -6
  128. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  129. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  130. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  131. package/lib/web/JsonpChunkLoadingRuntimeModule.js +13 -3
  132. package/lib/webpack.js +11 -2
  133. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -15
  134. package/module.d.ts +1 -0
  135. package/package.json +4 -4
  136. package/schemas/WebpackOptions.check.js +1 -1
  137. package/schemas/WebpackOptions.json +51 -5
  138. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  139. package/schemas/plugins/css/CssParserOptions.json +1 -1
  140. package/types.d.ts +476 -218
@@ -5,16 +5,20 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const parseJson = require("json-parse-even-better-errors");
9
8
  const Parser = require("../Parser");
10
9
  const JsonExportsDependency = require("../dependencies/JsonExportsDependency");
10
+ const memoize = require("../util/memoize");
11
11
  const JsonData = require("./JsonData");
12
12
 
13
13
  /** @typedef {import("../../declarations/plugins/JsonModulesPluginParser").JsonModulesPluginParserOptions} JsonModulesPluginParserOptions */
14
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
15
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
14
16
  /** @typedef {import("../Parser").ParserState} ParserState */
15
17
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
16
18
  /** @typedef {import("./JsonModulesPlugin").RawJsonData} RawJsonData */
17
19
 
20
+ const getParseJson = memoize(() => require("json-parse-even-better-errors"));
21
+
18
22
  class JsonParser extends Parser {
19
23
  /**
20
24
  * @param {JsonModulesPluginParserOptions} options parser options
@@ -36,17 +40,26 @@ class JsonParser extends Parser {
36
40
 
37
41
  /** @type {NonNullable<JsonModulesPluginParserOptions["parse"]>} */
38
42
  const parseFn =
39
- typeof this.options.parse === "function" ? this.options.parse : parseJson;
40
- /** @type {Buffer | RawJsonData} */
41
- const data =
42
- typeof source === "object"
43
- ? source
44
- : parseFn(source[0] === "\ufeff" ? source.slice(1) : source);
45
- const jsonData = new JsonData(data);
46
- state.module.buildInfo.jsonData = jsonData;
47
- state.module.buildInfo.strict = true;
48
- state.module.buildMeta.exportsType = "default";
49
- state.module.buildMeta.defaultObject =
43
+ typeof this.options.parse === "function"
44
+ ? this.options.parse
45
+ : getParseJson();
46
+ /** @type {Buffer | RawJsonData | undefined} */
47
+ let data;
48
+ try {
49
+ data =
50
+ typeof source === "object"
51
+ ? source
52
+ : parseFn(source[0] === "\ufeff" ? source.slice(1) : source);
53
+ } catch (e) {
54
+ throw new Error(`Cannot parse JSON: ${/** @type {Error} */ (e).message}`);
55
+ }
56
+ const jsonData = new JsonData(/** @type {Buffer | RawJsonData} */ (data));
57
+ const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
58
+ buildInfo.jsonData = jsonData;
59
+ buildInfo.strict = true;
60
+ const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
61
+ buildMeta.exportsType = "default";
62
+ buildMeta.defaultObject =
50
63
  typeof data === "object" ? "redirect-warn" : false;
51
64
  state.module.addDependency(new JsonExportsDependency(jsonData));
52
65
  return state;
@@ -40,6 +40,7 @@ class ReadFileCompileAsyncWasmPlugin {
40
40
  : globalWasmLoading;
41
41
  return wasmLoading === this._type;
42
42
  };
43
+ const { importMetaName } = compilation.outputOptions;
43
44
  /**
44
45
  * @type {(path: string) => string}
45
46
  */
@@ -48,7 +49,7 @@ class ReadFileCompileAsyncWasmPlugin {
48
49
  Template.asString([
49
50
  "Promise.all([import('fs'), import('url')]).then(([{ readFile }, { URL }]) => new Promise((resolve, reject) => {",
50
51
  Template.indent([
51
- `readFile(new URL(${path}, import.meta.url), (err, buffer) => {`,
52
+ `readFile(new URL(${path}, ${importMetaName}.url), (err, buffer) => {`,
52
53
  Template.indent([
53
54
  "if (err) return reject(err);",
54
55
  "",
@@ -10,7 +10,15 @@ const { STAGE_ADVANCED } = require("../OptimizationStages");
10
10
  /** @typedef {import("../Chunk")} Chunk */
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
12
 
13
+ /**
14
+ * @typedef {Object} AggressiveMergingPluginOptions
15
+ * @property {number=} minSizeReduce minimal size reduction to trigger merging
16
+ */
17
+
13
18
  class AggressiveMergingPlugin {
19
+ /**
20
+ * @param {AggressiveMergingPluginOptions=} [options] options object
21
+ */
14
22
  constructor(options) {
15
23
  if (
16
24
  (options !== undefined && typeof options !== "object") ||
@@ -30,6 +30,12 @@ const validate = createSchemaValidation(
30
30
  }
31
31
  );
32
32
 
33
+ /**
34
+ * @param {ChunkGraph} chunkGraph the chunk graph
35
+ * @param {Chunk} oldChunk the old chunk
36
+ * @param {Chunk} newChunk the new chunk
37
+ * @returns {(module: Module) => void} function to move module between chunks
38
+ */
33
39
  const moveModuleBetween = (chunkGraph, oldChunk, newChunk) => {
34
40
  return module => {
35
41
  chunkGraph.disconnectChunkAndModule(oldChunk, module);
@@ -92,6 +98,7 @@ class AggressiveSplittingPlugin {
92
98
  compilation => {
93
99
  let needAdditionalSeal = false;
94
100
  let newSplits;
101
+ /** @type {Set<Chunk>} */
95
102
  let fromAggressiveSplittingSet;
96
103
  let chunkSplitDataMap;
97
104
  compilation.hooks.optimize.tap("AggressiveSplittingPlugin", () => {
@@ -133,8 +140,8 @@ class AggressiveSplittingPlugin {
133
140
  ? recordedSplits.concat(newSplits)
134
141
  : recordedSplits;
135
142
 
136
- const minSize = this.options.minSize;
137
- const maxSize = this.options.maxSize;
143
+ const minSize = /** @type {number} */ (this.options.minSize);
144
+ const maxSize = /** @type {number} */ (this.options.maxSize);
138
145
 
139
146
  const applySplit = splitData => {
140
147
  // Cannot split if id is already taken
@@ -21,6 +21,9 @@ class EnsureChunkConditionsPlugin {
21
21
  compiler.hooks.compilation.tap(
22
22
  "EnsureChunkConditionsPlugin",
23
23
  compilation => {
24
+ /**
25
+ * @param {Iterable<Chunk>} chunks the chunks
26
+ */
24
27
  const handler = chunks => {
25
28
  const chunkGraph = compilation.chunkGraph;
26
29
  // These sets are hoisted here to save memory
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  /** @typedef {import("../Chunk")} Chunk */
9
+ /** @typedef {import("../Chunk").ChunkId} ChunkId */
9
10
  /** @typedef {import("../Compiler")} Compiler */
10
11
  /** @typedef {import("../Module")} Module */
11
12
 
@@ -61,13 +62,15 @@ class FlagIncludedChunksPlugin {
61
62
  for (const chunk of chunks) {
62
63
  let hash = 0;
63
64
  for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
64
- hash |= moduleBits.get(module);
65
+ hash |= /** @type {number} */ (moduleBits.get(module));
65
66
  }
66
67
  chunkModulesHash.set(chunk, hash);
67
68
  }
68
69
 
69
70
  for (const chunkA of chunks) {
70
- const chunkAHash = chunkModulesHash.get(chunkA);
71
+ const chunkAHash =
72
+ /** @type {number} */
73
+ (chunkModulesHash.get(chunkA));
71
74
  const chunkAModulesCount =
72
75
  chunkGraph.getNumberOfChunkModules(chunkA);
73
76
  if (chunkAModulesCount === 0) continue;
@@ -81,7 +84,7 @@ class FlagIncludedChunksPlugin {
81
84
  bestModule = module;
82
85
  }
83
86
  loopB: for (const chunkB of chunkGraph.getModuleChunksIterable(
84
- bestModule
87
+ /** @type {Module} */ (bestModule)
85
88
  )) {
86
89
  // as we iterate the same iterables twice
87
90
  // skip if we find ourselves
@@ -100,14 +103,17 @@ class FlagIncludedChunksPlugin {
100
103
  // is chunkA in chunkB?
101
104
 
102
105
  // we do a cheap check for the hash value
103
- const chunkBHash = chunkModulesHash.get(chunkB);
106
+ const chunkBHash =
107
+ /** @type {number} */
108
+ (chunkModulesHash.get(chunkB));
104
109
  if ((chunkBHash & chunkAHash) !== chunkAHash) continue;
105
110
 
106
111
  // compare all modules
107
112
  for (const m of chunkGraph.getChunkModulesIterable(chunkA)) {
108
113
  if (!chunkGraph.isModuleInChunk(m, chunkB)) continue loopB;
109
114
  }
110
- chunkB.ids.push(chunkA.id);
115
+ /** @type {ChunkId[]} */
116
+ (chunkB.ids).push(/** @type {ChunkId} */ (chunkA.id));
111
117
  }
112
118
  }
113
119
  }
@@ -16,7 +16,7 @@ const { UsageState } = require("../ExportsInfo");
16
16
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
17
17
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
18
18
 
19
- /** @typedef {Map<TopLevelSymbol | null, Set<string | TopLevelSymbol> | true>} InnerGraph */
19
+ /** @typedef {Map<TopLevelSymbol | null, Set<string | TopLevelSymbol> | true | undefined>} InnerGraph */
20
20
  /** @typedef {function(boolean | Set<string> | undefined): void} UsageCallback */
21
21
 
22
22
  /**
@@ -34,7 +34,7 @@ const topLevelSymbolTag = Symbol("top level symbol");
34
34
 
35
35
  /**
36
36
  * @param {ParserState} parserState parser state
37
- * @returns {State} state
37
+ * @returns {State | undefined} state
38
38
  */
39
39
  function getState(parserState) {
40
40
  return parserStateMap.get(parserState);
@@ -235,7 +235,7 @@ exports.onUsage = (state, onUsageCallback) => {
235
235
 
236
236
  /**
237
237
  * @param {ParserState} state parser state
238
- * @param {TopLevelSymbol} symbol the symbol
238
+ * @param {TopLevelSymbol | undefined} symbol the symbol
239
239
  */
240
240
  exports.setTopLevelSymbol = (state, symbol) => {
241
241
  const innerGraphState = getState(state);
@@ -260,7 +260,7 @@ exports.getTopLevelSymbol = state => {
260
260
  /**
261
261
  * @param {JavascriptParser} parser parser
262
262
  * @param {string} name name of variable
263
- * @returns {TopLevelSymbol} symbol
263
+ * @returns {TopLevelSymbol | undefined} symbol
264
264
  */
265
265
  exports.tagTopLevelSymbol = (parser, name) => {
266
266
  const innerGraphState = getState(parser.state);
@@ -36,6 +36,12 @@ const validate = createSchemaValidation(
36
36
  * @property {number} bSize
37
37
  */
38
38
 
39
+ /**
40
+ * @template K, V
41
+ * @param {Map<K, Set<V>>} map map
42
+ * @param {K} key key
43
+ * @param {V} value value
44
+ */
39
45
  const addToSetMap = (map, key, value) => {
40
46
  const set = map.get(key);
41
47
  if (set === undefined) {
@@ -68,7 +74,9 @@ class LimitChunkCountPlugin {
68
74
  },
69
75
  chunks => {
70
76
  const chunkGraph = compilation.chunkGraph;
71
- const maxChunks = options.maxChunks;
77
+ const maxChunks =
78
+ /** @type {LimitChunkCountPluginOptions} */
79
+ (options).maxChunks;
72
80
  if (!maxChunks) return;
73
81
  if (maxChunks < 1) return;
74
82
  if (compilation.chunks.size <= maxChunks) return;
@@ -88,9 +96,17 @@ class LimitChunkCountPlugin {
88
96
  c => c.sizeDiff,
89
97
  (a, b) => b - a,
90
98
  // Layer 2: ordered by smallest combined size
99
+ /**
100
+ * @param {ChunkCombination} c combination
101
+ * @returns {number} integrated size
102
+ */
91
103
  c => c.integratedSize,
92
104
  (a, b) => a - b,
93
105
  // Layer 3: ordered by position difference in orderedChunk (-> to be deterministic)
106
+ /**
107
+ * @param {ChunkCombination} c combination
108
+ * @returns {number} position difference
109
+ */
94
110
  c => c.bIdx - c.aIdx,
95
111
  (a, b) => a - b,
96
112
  // Layer 4: ordered by position in orderedChunk (-> to be deterministic)
@@ -193,14 +209,18 @@ class LimitChunkCountPlugin {
193
209
  // Update all affected combinations
194
210
  // delete all combination with the removed chunk
195
211
  // we will use combinations with the kept chunk instead
196
- for (const combination of combinationsByChunk.get(a)) {
212
+ for (const combination of /** @type {Set<ChunkCombination>} */ (
213
+ combinationsByChunk.get(a)
214
+ )) {
197
215
  if (combination.deleted) continue;
198
216
  combination.deleted = true;
199
217
  combinations.delete(combination);
200
218
  }
201
219
 
202
220
  // Update combinations with the kept chunk with new sizes
203
- for (const combination of combinationsByChunk.get(b)) {
221
+ for (const combination of /** @type {Set<ChunkCombination>} */ (
222
+ combinationsByChunk.get(b)
223
+ )) {
204
224
  if (combination.deleted) continue;
205
225
  if (combination.a === b) {
206
226
  if (!chunkGraph.canChunksBeIntegrated(a, combination.b)) {
@@ -243,7 +263,12 @@ class LimitChunkCountPlugin {
243
263
  finishUpdate();
244
264
  }
245
265
  }
246
- combinationsByChunk.set(a, combinationsByChunk.get(b));
266
+ combinationsByChunk.set(
267
+ a,
268
+ /** @type {Set<ChunkCombination>} */ (
269
+ combinationsByChunk.get(b)
270
+ )
271
+ );
247
272
  combinationsByChunk.delete(b);
248
273
  }
249
274
  }
@@ -39,7 +39,7 @@ const comparator = compareSelect(e => e.name, compareStringsNumeric);
39
39
  /**
40
40
  * @param {boolean} deterministic use deterministic names
41
41
  * @param {ExportsInfo} exportsInfo exports info
42
- * @param {boolean} isNamespace is namespace object
42
+ * @param {boolean | undefined} isNamespace is namespace object
43
43
  * @returns {void}
44
44
  */
45
45
  const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
@@ -9,6 +9,11 @@ const SizeFormatHelpers = require("../SizeFormatHelpers");
9
9
  const WebpackError = require("../WebpackError");
10
10
 
11
11
  class MinMaxSizeWarning extends WebpackError {
12
+ /**
13
+ * @param {string[] | undefined} keys keys
14
+ * @param {number} minSize minimum size
15
+ * @param {number} maxSize maximum size
16
+ */
12
17
  constructor(keys, minSize, maxSize) {
13
18
  let keysMessage = "Fallback cache group";
14
19
  if (keys) {
@@ -40,6 +40,10 @@ const ConcatenatedModule = require("./ConcatenatedModule");
40
40
  * @property {number} added
41
41
  */
42
42
 
43
+ /**
44
+ * @param {string} msg message
45
+ * @returns {string} formatted message
46
+ */
43
47
  const formatBailoutReason = msg => {
44
48
  return "ModuleConcatenation bailout: " + msg;
45
49
  };
@@ -64,8 +68,13 @@ class ModuleConcatenationPlugin {
64
68
  );
65
69
  }
66
70
  const moduleGraph = compilation.moduleGraph;
71
+ /** @type {Map<Module, string | ((requestShortener: RequestShortener) => string)>} */
67
72
  const bailoutReasonMap = new Map();
68
73
 
74
+ /**
75
+ * @param {Module} module the module
76
+ * @param {string | ((requestShortener: RequestShortener) => string)} reason the reason
77
+ */
69
78
  const setBailoutReason = (module, reason) => {
70
79
  setInnerBailoutReason(module, reason);
71
80
  moduleGraph
@@ -77,16 +86,30 @@ class ModuleConcatenationPlugin {
77
86
  );
78
87
  };
79
88
 
89
+ /**
90
+ * @param {Module} module the module
91
+ * @param {string | ((requestShortener: RequestShortener) => string)} reason the reason
92
+ */
80
93
  const setInnerBailoutReason = (module, reason) => {
81
94
  bailoutReasonMap.set(module, reason);
82
95
  };
83
96
 
97
+ /**
98
+ * @param {Module} module the module
99
+ * @param {RequestShortener} requestShortener the request shortener
100
+ * @returns {string | ((requestShortener: RequestShortener) => string) | undefined} the reason
101
+ */
84
102
  const getInnerBailoutReason = (module, requestShortener) => {
85
103
  const reason = bailoutReasonMap.get(module);
86
104
  if (typeof reason === "function") return reason(requestShortener);
87
105
  return reason;
88
106
  };
89
107
 
108
+ /**
109
+ * @param {Module} module the module
110
+ * @param {Module | function(RequestShortener): string} problem the problem
111
+ * @returns {(requestShortener: RequestShortener) => string} the reason
112
+ */
90
113
  const formatBailoutWarning = (module, problem) => requestShortener => {
91
114
  if (typeof problem === "function") {
92
115
  return formatBailoutReason(
@@ -460,7 +483,7 @@ class ModuleConcatenationPlugin {
460
483
  c.module === rootModule ? c.originModule : c.module;
461
484
  const innerConnection =
462
485
  c.dependency instanceof HarmonyImportDependency &&
463
- modules.has(otherModule);
486
+ modules.has(/** @type {Module} */ (otherModule));
464
487
  return !innerConnection;
465
488
  });
466
489
  // add concatenated module to the compilation
@@ -533,7 +556,7 @@ class ModuleConcatenationPlugin {
533
556
  * @param {ChunkGraph} chunkGraph the chunk graph
534
557
  * @param {boolean} avoidMutateOnFailure avoid mutating the config when adding fails
535
558
  * @param {Statistics} statistics gathering metrics
536
- * @returns {Module | function(RequestShortener): string} the problematic module
559
+ * @returns {null | Module | function(RequestShortener): string} the problematic module
537
560
  */
538
561
  _tryToAdd(
539
562
  compilation,
@@ -572,6 +595,10 @@ class ModuleConcatenationPlugin {
572
595
  chunkGraph.getModuleChunksIterable(config.rootModule)
573
596
  ).filter(chunk => !chunkGraph.isModuleInChunk(module, chunk));
574
597
  if (missingChunks.length > 0) {
598
+ /**
599
+ * @param {RequestShortener} requestShortener request shortener
600
+ * @returns {string} problem description
601
+ */
575
602
  const problem = requestShortener => {
576
603
  const missingChunksList = Array.from(
577
604
  new Set(missingChunks.map(chunk => chunk.name || "unnamed chunk(s)"))
@@ -609,6 +636,10 @@ class ModuleConcatenationPlugin {
609
636
  return connection.isActive(runtime);
610
637
  });
611
638
  if (activeNonModulesConnections.length > 0) {
639
+ /**
640
+ * @param {RequestShortener} requestShortener request shortener
641
+ * @returns {string} problem description
642
+ */
612
643
  const problem = requestShortener => {
613
644
  const importingExplanations = new Set(
614
645
  activeNonModulesConnections.map(c => c.explanation).filter(Boolean)
@@ -666,6 +697,10 @@ class ModuleConcatenationPlugin {
666
697
  return false;
667
698
  });
668
699
  if (otherChunkModules.length > 0) {
700
+ /**
701
+ * @param {RequestShortener} requestShortener request shortener
702
+ * @returns {string} problem description
703
+ */
669
704
  const problem = requestShortener => {
670
705
  const names = otherChunkModules
671
706
  .map(m => m.readableIdentifier(requestShortener))
@@ -693,6 +728,10 @@ class ModuleConcatenationPlugin {
693
728
  nonHarmonyConnections.set(originModule, connections);
694
729
  }
695
730
  if (nonHarmonyConnections.size > 0) {
731
+ /**
732
+ * @param {RequestShortener} requestShortener request shortener
733
+ * @returns {string} problem description
734
+ */
696
735
  const problem = requestShortener => {
697
736
  const names = Array.from(nonHarmonyConnections)
698
737
  .map(([originModule, connections]) => {
@@ -753,6 +792,10 @@ class ModuleConcatenationPlugin {
753
792
  }
754
793
  }
755
794
  if (otherRuntimeConnections.length > 0) {
795
+ /**
796
+ * @param {RequestShortener} requestShortener request shortener
797
+ * @returns {string} problem description
798
+ */
756
799
  const problem = requestShortener => {
757
800
  return `Module ${module.readableIdentifier(
758
801
  requestShortener
@@ -831,10 +874,17 @@ class ConcatConfiguration {
831
874
  this.warnings = new Map();
832
875
  }
833
876
 
877
+ /**
878
+ * @param {Module} module the module
879
+ */
834
880
  add(module) {
835
881
  this.modules.add(module);
836
882
  }
837
883
 
884
+ /**
885
+ * @param {Module} module the module
886
+ * @returns {boolean} true, when the module is in the module set
887
+ */
838
888
  has(module) {
839
889
  return this.modules.has(module);
840
890
  }
@@ -843,10 +893,17 @@ class ConcatConfiguration {
843
893
  return this.modules.size === 1;
844
894
  }
845
895
 
896
+ /**
897
+ * @param {Module} module the module
898
+ * @param {Module | function(RequestShortener): string} problem the problem
899
+ */
846
900
  addWarning(module, problem) {
847
901
  this.warnings.set(module, problem);
848
902
  }
849
903
 
904
+ /**
905
+ * @returns {Map<Module, Module | function(RequestShortener): string>} warnings
906
+ */
850
907
  getWarningsSorted() {
851
908
  return new Map(
852
909
  Array.from(this.warnings).sort((a, b) => {