webpack 5.95.0 → 5.96.1

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 (145) hide show
  1. package/README.md +1 -1
  2. package/lib/AsyncDependenciesBlock.js +1 -1
  3. package/lib/BannerPlugin.js +2 -1
  4. package/lib/Chunk.js +30 -0
  5. package/lib/ChunkGraph.js +11 -6
  6. package/lib/ChunkGroup.js +2 -2
  7. package/lib/CleanPlugin.js +4 -5
  8. package/lib/CodeGenerationResults.js +6 -5
  9. package/lib/Compilation.js +71 -48
  10. package/lib/Compiler.js +7 -5
  11. package/lib/ConcatenationScope.js +7 -20
  12. package/lib/ContextModule.js +7 -8
  13. package/lib/CssModule.js +25 -21
  14. package/lib/DefinePlugin.js +14 -8
  15. package/lib/DelegatedModule.js +3 -3
  16. package/lib/DllModule.js +4 -4
  17. package/lib/DynamicEntryPlugin.js +29 -22
  18. package/lib/EvalDevToolModulePlugin.js +5 -2
  19. package/lib/EvalSourceMapDevToolPlugin.js +5 -2
  20. package/lib/ExternalModule.js +40 -7
  21. package/lib/ExternalModuleFactoryPlugin.js +33 -9
  22. package/lib/FileSystemInfo.js +12 -8
  23. package/lib/Generator.js +5 -4
  24. package/lib/HotModuleReplacementPlugin.js +8 -6
  25. package/lib/IgnorePlugin.js +19 -1
  26. package/lib/LoaderOptionsPlugin.js +3 -1
  27. package/lib/Module.js +9 -8
  28. package/lib/ModuleSourceTypesConstants.js +100 -0
  29. package/lib/NormalModule.js +27 -17
  30. package/lib/NormalModuleFactory.js +38 -22
  31. package/lib/OptionsApply.js +12 -1
  32. package/lib/ProgressPlugin.js +50 -10
  33. package/lib/RawModule.js +3 -4
  34. package/lib/RuntimeModule.js +3 -4
  35. package/lib/RuntimePlugin.js +11 -4
  36. package/lib/RuntimeTemplate.js +13 -42
  37. package/lib/SourceMapDevToolPlugin.js +10 -7
  38. package/lib/Watching.js +2 -2
  39. package/lib/WebpackOptionsApply.js +42 -21
  40. package/lib/asset/AssetGenerator.js +347 -194
  41. package/lib/asset/AssetModulesPlugin.js +2 -1
  42. package/lib/asset/AssetSourceGenerator.js +82 -27
  43. package/lib/asset/RawDataUrlModule.js +5 -4
  44. package/lib/buildChunkGraph.js +2 -2
  45. package/lib/cache/PackFileCacheStrategy.js +69 -31
  46. package/lib/cache/ResolverCachePlugin.js +248 -173
  47. package/lib/config/defaults.js +134 -126
  48. package/lib/container/ContainerEntryModule.js +3 -4
  49. package/lib/container/ContainerPlugin.js +8 -0
  50. package/lib/container/FallbackModule.js +2 -2
  51. package/lib/container/HoistContainerReferencesPlugin.js +250 -0
  52. package/lib/container/ModuleFederationPlugin.js +38 -1
  53. package/lib/container/RemoteModule.js +4 -2
  54. package/lib/container/RemoteRuntimeModule.js +4 -2
  55. package/lib/css/CssExportsGenerator.js +16 -12
  56. package/lib/css/CssGenerator.js +22 -16
  57. package/lib/css/CssLoadingRuntimeModule.js +7 -6
  58. package/lib/css/CssModulesPlugin.js +122 -77
  59. package/lib/css/CssParser.js +655 -526
  60. package/lib/css/walkCssTokens.js +1168 -338
  61. package/lib/debug/ProfilingPlugin.js +5 -0
  62. package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
  63. package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
  64. package/lib/dependencies/CssExportDependency.js +3 -3
  65. package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
  66. package/lib/dependencies/CssUrlDependency.js +33 -3
  67. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
  68. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
  69. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
  70. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
  71. package/lib/dependencies/ImportParserPlugin.js +9 -7
  72. package/lib/dependencies/LoaderPlugin.js +19 -0
  73. package/lib/dependencies/SystemPlugin.js +2 -1
  74. package/lib/dependencies/URLPlugin.js +7 -1
  75. package/lib/dependencies/WorkerPlugin.js +1 -1
  76. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
  77. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  78. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  79. package/lib/hmr/LazyCompilationPlugin.js +16 -4
  80. package/lib/hmr/lazyCompilationBackend.js +1 -7
  81. package/lib/index.js +37 -7
  82. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  83. package/lib/javascript/JavascriptGenerator.js +8 -8
  84. package/lib/javascript/JavascriptModulesPlugin.js +126 -73
  85. package/lib/javascript/JavascriptParser.js +338 -117
  86. package/lib/json/JsonGenerator.js +5 -5
  87. package/lib/library/EnableLibraryPlugin.js +2 -2
  88. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  89. package/lib/library/UmdLibraryPlugin.js +16 -8
  90. package/lib/logging/Logger.js +11 -11
  91. package/lib/logging/createConsoleLogger.js +14 -14
  92. package/lib/logging/truncateArgs.js +1 -1
  93. package/lib/node/NodeWatchFileSystem.js +3 -1
  94. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
  95. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  96. package/lib/node/nodeConsole.js +11 -8
  97. package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
  98. package/lib/optimize/ConcatenatedModule.js +43 -145
  99. package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
  100. package/lib/optimize/InnerGraphPlugin.js +57 -16
  101. package/lib/optimize/LimitChunkCountPlugin.js +2 -4
  102. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  103. package/lib/optimize/RealContentHashPlugin.js +1 -1
  104. package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
  105. package/lib/rules/RuleSetCompiler.js +2 -2
  106. package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
  107. package/lib/schemes/DataUriPlugin.js +1 -1
  108. package/lib/serialization/BinaryMiddleware.js +32 -19
  109. package/lib/serialization/ObjectMiddleware.js +23 -9
  110. package/lib/serialization/SerializerMiddleware.js +3 -2
  111. package/lib/serialization/types.js +2 -2
  112. package/lib/sharing/ConsumeSharedModule.js +2 -3
  113. package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
  114. package/lib/sharing/ProvideSharedModule.js +2 -3
  115. package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
  116. package/lib/stats/StatsFactory.js +12 -12
  117. package/lib/stats/StatsPrinter.js +7 -7
  118. package/lib/util/AsyncQueue.js +17 -1
  119. package/lib/util/IterableHelpers.js +1 -1
  120. package/lib/util/SetHelpers.js +1 -1
  121. package/lib/util/cleverMerge.js +48 -24
  122. package/lib/util/concatenate.js +227 -0
  123. package/lib/util/create-schema-validation.js +22 -9
  124. package/lib/util/deprecation.js +86 -28
  125. package/lib/util/fs.js +9 -9
  126. package/lib/util/hash/wasm-hash.js +12 -1
  127. package/lib/util/magicComment.js +21 -0
  128. package/lib/util/makeSerializable.js +24 -1
  129. package/lib/util/memoize.js +2 -1
  130. package/lib/util/runtime.js +4 -1
  131. package/lib/util/semver.js +130 -23
  132. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
  133. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  134. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
  135. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
  136. package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
  137. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
  138. package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
  139. package/lib/web/FetchCompileWasmPlugin.js +1 -2
  140. package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
  141. package/package.json +18 -19
  142. package/schemas/WebpackOptions.check.js +1 -1
  143. package/schemas/WebpackOptions.json +8 -2
  144. package/types.d.ts +801 -259
  145. package/lib/util/mergeScope.js +0 -76
@@ -9,12 +9,14 @@ const { RawSource } = require("webpack-sources");
9
9
  const ConcatenationScope = require("../ConcatenationScope");
10
10
  const { UsageState } = require("../ExportsInfo");
11
11
  const Generator = require("../Generator");
12
+ const { JS_TYPES } = require("../ModuleSourceTypesConstants");
12
13
  const RuntimeGlobals = require("../RuntimeGlobals");
13
14
 
14
15
  /** @typedef {import("webpack-sources").Source} Source */
15
16
  /** @typedef {import("../ExportsInfo")} ExportsInfo */
16
17
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
17
18
  /** @typedef {import("../Module").ConcatenationBailoutReasonContext} ConcatenationBailoutReasonContext */
19
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
18
20
  /** @typedef {import("../NormalModule")} NormalModule */
19
21
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
20
22
  /** @typedef {import("./JsonData")} JsonData */
@@ -103,15 +105,13 @@ const createObjectForExportsInfo = (data, exportsInfo, runtime) => {
103
105
  return reducedData;
104
106
  };
105
107
 
106
- const TYPES = new Set(["javascript"]);
107
-
108
108
  class JsonGenerator extends Generator {
109
109
  /**
110
110
  * @param {NormalModule} module fresh module
111
- * @returns {Set<string>} available types (do not mutate)
111
+ * @returns {SourceTypes} available types (do not mutate)
112
112
  */
113
113
  getTypes(module) {
114
- return TYPES;
114
+ return JS_TYPES;
115
115
  }
116
116
 
117
117
  /**
@@ -141,7 +141,7 @@ class JsonGenerator extends Generator {
141
141
  /**
142
142
  * @param {NormalModule} module module for which the code should be generated
143
143
  * @param {GenerateContext} generateContext context for generate
144
- * @returns {Source} generated code
144
+ * @returns {Source | null} generated code
145
145
  */
146
146
  generate(
147
147
  module,
@@ -52,8 +52,8 @@ class EnableLibraryPlugin {
52
52
  throw new Error(
53
53
  `Library type "${type}" is not enabled. ` +
54
54
  "EnableLibraryPlugin need to be used to enable this type of library. " +
55
- `This usually happens through the "output.enabledLibraryTypes" option. ` +
56
- `If you are using a function as entry which sets "library", you need to add all potential library types to "output.enabledLibraryTypes". ` +
55
+ 'This usually happens through the "output.enabledLibraryTypes" option. ' +
56
+ 'If you are using a function as entry which sets "library", you need to add all potential library types to "output.enabledLibraryTypes". ' +
57
57
  `These types are enabled: ${Array.from(
58
58
  getEnabledTypes(compiler)
59
59
  ).join(", ")}`
@@ -55,7 +55,7 @@ class ExportPropertyLibraryPlugin extends AbstractLibraryPlugin {
55
55
  */
56
56
  parseOptions(library) {
57
57
  return {
58
- export: library.export
58
+ export: /** @type {string | string[]} */ (library.export)
59
59
  };
60
60
  }
61
61
 
@@ -64,10 +64,10 @@ const accessorAccess = (base, accessor, joinWith = ", ") => {
64
64
 
65
65
  /**
66
66
  * @typedef {object} UmdLibraryPluginParsed
67
- * @property {string | string[]} name
67
+ * @property {string | string[] | undefined} name
68
68
  * @property {LibraryCustomUmdObject} names
69
- * @property {string | LibraryCustomUmdCommentObject} auxiliaryComment
70
- * @property {boolean} namedDefine
69
+ * @property {string | LibraryCustomUmdCommentObject | undefined} auxiliaryComment
70
+ * @property {boolean | undefined} namedDefine
71
71
  */
72
72
 
73
73
  /**
@@ -92,7 +92,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
92
92
  * @returns {T | false} preprocess as needed by overriding
93
93
  */
94
94
  parseOptions(library) {
95
- /** @type {LibraryName} */
95
+ /** @type {LibraryName | undefined} */
96
96
  let name;
97
97
  /** @type {LibraryCustomUmdObject} */
98
98
  let names;
@@ -192,7 +192,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
192
192
  request =
193
193
  /** @type {RequestRecord} */
194
194
  (request).root;
195
- return `root${accessorToObjectAccess([].concat(request))}`;
195
+ return `root${accessorToObjectAccess(/** @type {string[]} */ ([]).concat(request))}`;
196
196
  })
197
197
  .join(", ")
198
198
  );
@@ -250,7 +250,10 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
250
250
  */
251
251
  const libraryName = library =>
252
252
  JSON.stringify(
253
- replaceKeys(/** @type {string[]} */ ([]).concat(library).pop())
253
+ replaceKeys(
254
+ /** @type {string} */
255
+ (/** @type {string[]} */ ([]).concat(library).pop())
256
+ )
254
257
  );
255
258
 
256
259
  let amdFactory;
@@ -312,12 +315,17 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
312
315
  "commonjs"
313
316
  )} else if(typeof exports === 'object')\n` +
314
317
  ` exports[${libraryName(
315
- names.commonjs || names.root
318
+ /** @type {string | string[]} */
319
+ (names.commonjs || names.root)
316
320
  )}] = factory(${externalsRequireArray(
317
321
  "commonjs"
318
322
  )});\n${getAuxiliaryComment("root")} else\n` +
319
323
  ` ${replaceKeys(
320
- accessorAccess("root", names.root || names.commonjs)
324
+ accessorAccess(
325
+ "root",
326
+ /** @type {string | string[]} */
327
+ (names.root || names.commonjs)
328
+ )
321
329
  )} = factory(${externalsRootArray(externals)});\n`
322
330
  : ` else {\n${
323
331
  externals.length > 0
@@ -37,7 +37,7 @@ const TIMERS_AGGREGATES_SYMBOL = Symbol("webpack logger aggregated times");
37
37
 
38
38
  class WebpackLogger {
39
39
  /**
40
- * @param {function(LogTypeEnum, any[]=): void} log log function
40
+ * @param {function(LogTypeEnum, EXPECTED_ANY[]=): void} log log function
41
41
  * @param {function(string | function(): string): WebpackLogger} getChildLogger function to create child logger
42
42
  */
43
43
  constructor(log, getChildLogger) {
@@ -46,43 +46,43 @@ class WebpackLogger {
46
46
  }
47
47
 
48
48
  /**
49
- * @param {...any} args args
49
+ * @param {...EXPECTED_ANY} args args
50
50
  */
51
51
  error(...args) {
52
52
  this[LOG_SYMBOL](LogType.error, args);
53
53
  }
54
54
 
55
55
  /**
56
- * @param {...any} args args
56
+ * @param {...EXPECTED_ANY} args args
57
57
  */
58
58
  warn(...args) {
59
59
  this[LOG_SYMBOL](LogType.warn, args);
60
60
  }
61
61
 
62
62
  /**
63
- * @param {...any} args args
63
+ * @param {...EXPECTED_ANY} args args
64
64
  */
65
65
  info(...args) {
66
66
  this[LOG_SYMBOL](LogType.info, args);
67
67
  }
68
68
 
69
69
  /**
70
- * @param {...any} args args
70
+ * @param {...EXPECTED_ANY} args args
71
71
  */
72
72
  log(...args) {
73
73
  this[LOG_SYMBOL](LogType.log, args);
74
74
  }
75
75
 
76
76
  /**
77
- * @param {...any} args args
77
+ * @param {...EXPECTED_ANY} args args
78
78
  */
79
79
  debug(...args) {
80
80
  this[LOG_SYMBOL](LogType.debug, args);
81
81
  }
82
82
 
83
83
  /**
84
- * @param {any} assertion assertion
85
- * @param {...any} args args
84
+ * @param {EXPECTED_ANY} assertion assertion
85
+ * @param {...EXPECTED_ANY} args args
86
86
  */
87
87
  assert(assertion, ...args) {
88
88
  if (!assertion) {
@@ -99,21 +99,21 @@ class WebpackLogger {
99
99
  }
100
100
 
101
101
  /**
102
- * @param {...any} args args
102
+ * @param {...EXPECTED_ANY} args args
103
103
  */
104
104
  status(...args) {
105
105
  this[LOG_SYMBOL](LogType.status, args);
106
106
  }
107
107
 
108
108
  /**
109
- * @param {...any} args args
109
+ * @param {...EXPECTED_ANY} args args
110
110
  */
111
111
  group(...args) {
112
112
  this[LOG_SYMBOL](LogType.group, args);
113
113
  }
114
114
 
115
115
  /**
116
- * @param {...any} args args
116
+ * @param {...EXPECTED_ANY} args args
117
117
  */
118
118
  groupCollapsed(...args) {
119
119
  this[LOG_SYMBOL](LogType.groupCollapsed, args);
@@ -12,24 +12,24 @@ const { LogType } = require("./Logger");
12
12
  /** @typedef {import("./Logger").LogTypeEnum} LogTypeEnum */
13
13
 
14
14
  /** @typedef {function(string): boolean} FilterFunction */
15
- /** @typedef {function(string, LogTypeEnum, any[]=): void} LoggingFunction */
15
+ /** @typedef {function(string, LogTypeEnum, EXPECTED_ANY[]=): void} LoggingFunction */
16
16
 
17
17
  /**
18
18
  * @typedef {object} LoggerConsole
19
19
  * @property {function(): void} clear
20
20
  * @property {function(): void} trace
21
- * @property {(...args: any[]) => void} info
22
- * @property {(...args: any[]) => void} log
23
- * @property {(...args: any[]) => void} warn
24
- * @property {(...args: any[]) => void} error
25
- * @property {(...args: any[]) => void=} debug
26
- * @property {(...args: any[]) => void=} group
27
- * @property {(...args: any[]) => void=} groupCollapsed
28
- * @property {(...args: any[]) => void=} groupEnd
29
- * @property {(...args: any[]) => void=} status
30
- * @property {(...args: any[]) => void=} profile
31
- * @property {(...args: any[]) => void=} profileEnd
32
- * @property {(...args: any[]) => void=} logTime
21
+ * @property {(...args: EXPECTED_ANY[]) => void} info
22
+ * @property {(...args: EXPECTED_ANY[]) => void} log
23
+ * @property {(...args: EXPECTED_ANY[]) => void} warn
24
+ * @property {(...args: EXPECTED_ANY[]) => void} error
25
+ * @property {(...args: EXPECTED_ANY[]) => void=} debug
26
+ * @property {(...args: EXPECTED_ANY[]) => void=} group
27
+ * @property {(...args: EXPECTED_ANY[]) => void=} groupCollapsed
28
+ * @property {(...args: EXPECTED_ANY[]) => void=} groupEnd
29
+ * @property {(...args: EXPECTED_ANY[]) => void=} status
30
+ * @property {(...args: EXPECTED_ANY[]) => void=} profile
31
+ * @property {(...args: EXPECTED_ANY[]) => void=} profileEnd
32
+ * @property {(...args: EXPECTED_ANY[]) => void=} logTime
33
33
  */
34
34
 
35
35
  /**
@@ -95,7 +95,7 @@ module.exports = ({ level = "info", debug = false, console }) => {
95
95
  /**
96
96
  * @param {string} name name of the logger
97
97
  * @param {LogTypeEnum} type type of the log entry
98
- * @param {any[]=} args arguments of the log entry
98
+ * @param {EXPECTED_ANY[]=} args arguments of the log entry
99
99
  * @returns {void}
100
100
  */
101
101
  const logger = (name, type, args) => {
@@ -16,7 +16,7 @@ const arraySum = array => {
16
16
  };
17
17
 
18
18
  /**
19
- * @param {any[]} args items to be truncated
19
+ * @param {EXPECTED_ANY[]} args items to be truncated
20
20
  * @param {number} maxLength maximum length of args including spaces between
21
21
  * @returns {string[]} truncated args
22
22
  */
@@ -22,6 +22,7 @@ class NodeWatchFileSystem {
22
22
  this.watcherOptions = {
23
23
  aggregateTimeout: 0
24
24
  };
25
+ /** @type {Watchpack | null} */
25
26
  this.watcher = new Watchpack(this.watcherOptions);
26
27
  }
27
28
 
@@ -82,7 +83,8 @@ class NodeWatchFileSystem {
82
83
  */
83
84
  (changes, removals) => {
84
85
  // pause emitting events (avoids clearing aggregated changes and removals on timeout)
85
- this.watcher.pause();
86
+ /** @type {Watchpack} */
87
+ (this.watcher).pause();
86
88
 
87
89
  const fs = this.inputFileSystem;
88
90
  if (fs && fs.purge) {
@@ -90,26 +90,28 @@ class ReadFileCompileAsyncWasmPlugin {
90
90
 
91
91
  compilation.hooks.runtimeRequirementInTree
92
92
  .for(RuntimeGlobals.instantiateWasm)
93
- .tap("ReadFileCompileAsyncWasmPlugin", (chunk, set) => {
94
- if (!isEnabledForChunk(chunk)) return;
95
- const chunkGraph = compilation.chunkGraph;
96
- if (
97
- !chunkGraph.hasModuleInGraph(
93
+ .tap(
94
+ "ReadFileCompileAsyncWasmPlugin",
95
+ (chunk, set, { chunkGraph }) => {
96
+ if (!isEnabledForChunk(chunk)) return;
97
+ if (
98
+ !chunkGraph.hasModuleInGraph(
99
+ chunk,
100
+ m => m.type === WEBASSEMBLY_MODULE_TYPE_ASYNC
101
+ )
102
+ ) {
103
+ return;
104
+ }
105
+ set.add(RuntimeGlobals.publicPath);
106
+ compilation.addRuntimeModule(
98
107
  chunk,
99
- m => m.type === WEBASSEMBLY_MODULE_TYPE_ASYNC
100
- )
101
- ) {
102
- return;
108
+ new AsyncWasmLoadingRuntimeModule({
109
+ generateLoadBinaryCode,
110
+ supportsStreaming: false
111
+ })
112
+ );
103
113
  }
104
- set.add(RuntimeGlobals.publicPath);
105
- compilation.addRuntimeModule(
106
- chunk,
107
- new AsyncWasmLoadingRuntimeModule({
108
- generateLoadBinaryCode,
109
- supportsStreaming: false
110
- })
111
- );
112
- });
114
+ );
113
115
  }
114
116
  );
115
117
  }
@@ -81,9 +81,8 @@ class ReadFileCompileWasmPlugin {
81
81
 
82
82
  compilation.hooks.runtimeRequirementInTree
83
83
  .for(RuntimeGlobals.ensureChunkHandlers)
84
- .tap("ReadFileCompileWasmPlugin", (chunk, set) => {
84
+ .tap("ReadFileCompileWasmPlugin", (chunk, set, { chunkGraph }) => {
85
85
  if (!isEnabledForChunk(chunk)) return;
86
- const chunkGraph = compilation.chunkGraph;
87
86
  if (
88
87
  !chunkGraph.hasModuleInGraph(
89
88
  chunk,
@@ -67,7 +67,7 @@ module.exports = ({ colors, appendOnly, stream }) => {
67
67
  * @param {string} prefix prefix
68
68
  * @param {string} colorPrefix color prefix
69
69
  * @param {string} colorSuffix color suffix
70
- * @returns {(function(...any[]): void)} function to write with colors
70
+ * @returns {(function(...EXPECTED_ANY[]): void)} function to write with colors
71
71
  */
72
72
  const writeColored =
73
73
  (prefix, colorPrefix, colorSuffix) =>
@@ -128,13 +128,16 @@ module.exports = ({ colors, appendOnly, stream }) => {
128
128
  profile: console.profile && (name => console.profile(name)),
129
129
  profileEnd: console.profileEnd && (name => console.profileEnd(name)),
130
130
  clear:
131
- !appendOnly &&
132
- console.clear &&
133
- (() => {
134
- clearStatusMessage();
135
- console.clear();
136
- writeStatusMessage();
137
- }),
131
+ /** @type {() => void} */
132
+ (
133
+ !appendOnly &&
134
+ console.clear &&
135
+ (() => {
136
+ clearStatusMessage();
137
+ console.clear();
138
+ writeStatusMessage();
139
+ })
140
+ ),
138
141
  status: appendOnly
139
142
  ? writeColored("<s> ", "", "")
140
143
  : (name, ...args) => {
@@ -92,10 +92,12 @@ class AggressiveSplittingPlugin {
92
92
  "AggressiveSplittingPlugin",
93
93
  compilation => {
94
94
  let needAdditionalSeal = false;
95
+ /** @typedef {{ id?: NonNullable<Chunk["id"]>, hash?: NonNullable<Chunk["hash"]>, modules: Module[], size: number }} SplitData */
96
+ /** @type {SplitData[]} */
95
97
  let newSplits;
96
98
  /** @type {Set<Chunk>} */
97
99
  let fromAggressiveSplittingSet;
98
- /** @type {Map<Chunk, TODO>} */
100
+ /** @type {Map<Chunk, SplitData>} */
99
101
  let chunkSplitDataMap;
100
102
  compilation.hooks.optimize.tap("AggressiveSplittingPlugin", () => {
101
103
  newSplits = [];
@@ -139,6 +141,10 @@ class AggressiveSplittingPlugin {
139
141
  const minSize = /** @type {number} */ (this.options.minSize);
140
142
  const maxSize = /** @type {number} */ (this.options.maxSize);
141
143
 
144
+ /**
145
+ * @param {SplitData} splitData split data
146
+ * @returns {boolean} true when applied, otherwise false
147
+ */
142
148
  const applySplit = splitData => {
143
149
  // Cannot split if id is already taken
144
150
  if (splitData.id !== undefined && usedIds.has(splitData.id)) {
@@ -190,7 +196,7 @@ class AggressiveSplittingPlugin {
190
196
  moveModuleBetween(chunkGraph, chunk, newChunk)(module);
191
197
  }
192
198
  chunk.split(newChunk);
193
- chunk.name = null;
199
+ chunk.name = /** @type {TODO} */ (null);
194
200
  }
195
201
  fromAggressiveSplittingSet.add(newChunk);
196
202
  chunkSplitDataMap.set(newChunk, splitData);
@@ -245,6 +251,7 @@ class AggressiveSplittingPlugin {
245
251
  selectedModules.push(module);
246
252
  }
247
253
  if (selectedModules.length === 0) continue;
254
+ /** @type {SplitData} */
248
255
  const splitData = {
249
256
  modules: selectedModules
250
257
  .map(m => moduleToNameMap.get(m))
@@ -266,6 +273,7 @@ class AggressiveSplittingPlugin {
266
273
  records => {
267
274
  // 4. save made splittings to records
268
275
  const allSplits = new Set();
276
+ /** @type {Set<SplitData>} */
269
277
  const invalidSplits = new Set();
270
278
 
271
279
  // Check if some splittings are invalid
@@ -284,17 +292,23 @@ class AggressiveSplittingPlugin {
284
292
  }
285
293
 
286
294
  if (invalidSplits.size > 0) {
287
- records.aggressiveSplits = records.aggressiveSplits.filter(
288
- splitData => !invalidSplits.has(splitData)
289
- );
295
+ records.aggressiveSplits =
296
+ /** @type {SplitData[]} */
297
+ (records.aggressiveSplits).filter(
298
+ splitData => !invalidSplits.has(splitData)
299
+ );
290
300
  needAdditionalSeal = true;
291
301
  } else {
292
302
  // set hash and id values on all (new) splittings
293
303
  for (const chunk of compilation.chunks) {
294
304
  const splitData = chunkSplitDataMap.get(chunk);
295
305
  if (splitData !== undefined) {
296
- splitData.hash = chunk.hash;
297
- splitData.id = chunk.id;
306
+ splitData.hash =
307
+ /** @type {NonNullable<Chunk["hash"]>} */
308
+ (chunk.hash);
309
+ splitData.id =
310
+ /** @type {NonNullable<Chunk["id"]>} */
311
+ (chunk.id);
298
312
  allSplits.add(splitData);
299
313
  // set flag for stats
300
314
  recordedChunks.add(chunk);