webpack 5.99.5 → 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 (169) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +2 -2
  3. package/lib/AutomaticPrefetchPlugin.js +21 -22
  4. package/lib/BannerPlugin.js +31 -35
  5. package/lib/Cache.js +1 -1
  6. package/lib/Chunk.js +12 -9
  7. package/lib/CleanPlugin.js +5 -3
  8. package/lib/Compilation.js +45 -35
  9. package/lib/Compiler.js +6 -4
  10. package/lib/ContextExclusionPlugin.js +4 -2
  11. package/lib/ContextModule.js +2 -1
  12. package/lib/ContextReplacementPlugin.js +5 -3
  13. package/lib/DelegatedPlugin.js +4 -2
  14. package/lib/DllEntryPlugin.js +4 -2
  15. package/lib/DllPlugin.js +5 -3
  16. package/lib/DllReferencePlugin.js +56 -60
  17. package/lib/DynamicEntryPlugin.js +4 -2
  18. package/lib/EntryOptionPlugin.js +3 -1
  19. package/lib/EntryPlugin.js +4 -2
  20. package/lib/EnvironmentPlugin.js +4 -2
  21. package/lib/EvalDevToolModulePlugin.js +9 -7
  22. package/lib/EvalSourceMapDevToolPlugin.js +137 -138
  23. package/lib/ExternalsPlugin.js +3 -1
  24. package/lib/FlagDependencyExportsPlugin.js +2 -1
  25. package/lib/HotModuleReplacementPlugin.js +3 -3
  26. package/lib/IgnorePlugin.js +6 -4
  27. package/lib/IgnoreWarningsPlugin.js +4 -2
  28. package/lib/LibManifestPlugin.js +3 -4
  29. package/lib/LoaderOptionsPlugin.js +4 -2
  30. package/lib/LoaderTargetPlugin.js +4 -2
  31. package/lib/Module.js +29 -14
  32. package/lib/ModuleFilenameHelpers.js +1 -1
  33. package/lib/ModuleGraph.js +15 -10
  34. package/lib/ModuleInfoHeaderPlugin.js +11 -12
  35. package/lib/MultiCompiler.js +5 -3
  36. package/lib/NoEmitOnErrorsPlugin.js +5 -3
  37. package/lib/NormalModule.js +6 -2
  38. package/lib/NormalModuleReplacementPlugin.js +33 -36
  39. package/lib/PlatformPlugin.js +3 -1
  40. package/lib/PrefetchPlugin.js +5 -3
  41. package/lib/ProgressPlugin.js +23 -26
  42. package/lib/RecordIdsPlugin.js +73 -103
  43. package/lib/RuntimePlugin.js +34 -32
  44. package/lib/SourceMapDevToolPlugin.js +8 -6
  45. package/lib/Template.js +1 -1
  46. package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
  47. package/lib/WarnNoModeSetPlugin.js +3 -1
  48. package/lib/WatchIgnorePlugin.js +3 -1
  49. package/lib/WebpackError.js +11 -3
  50. package/lib/WebpackOptionsApply.js +22 -5
  51. package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
  52. package/lib/buildChunkGraph.js +7 -2
  53. package/lib/cache/IdleFileCachePlugin.js +12 -13
  54. package/lib/cache/MemoryCachePlugin.js +2 -1
  55. package/lib/cache/MemoryWithGcCachePlugin.js +10 -7
  56. package/lib/cache/PackFileCacheStrategy.js +13 -21
  57. package/lib/cache/ResolverCachePlugin.js +22 -22
  58. package/lib/cli.js +8 -4
  59. package/lib/config/defaults.js +2 -2
  60. package/lib/config/normalization.js +9 -3
  61. package/lib/config/target.js +6 -6
  62. package/lib/container/ContainerReferencePlugin.js +24 -26
  63. package/lib/container/ModuleFederationPlugin.js +2 -1
  64. package/lib/css/CssGenerator.js +1 -1
  65. package/lib/css/CssModulesPlugin.js +6 -4
  66. package/lib/css/CssParser.js +1 -1
  67. package/lib/debug/ProfilingPlugin.js +1 -1
  68. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  69. package/lib/dependencies/CssIcssImportDependency.js +3 -2
  70. package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
  71. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  72. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  73. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
  74. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
  75. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
  76. package/lib/dependencies/JsonExportsDependency.js +1 -1
  77. package/lib/dependencies/LoaderPlugin.js +5 -3
  78. package/lib/dependencies/LocalModulesHelpers.js +1 -1
  79. package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
  80. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
  81. package/lib/dependencies/RequireResolveDependency.js +1 -1
  82. package/lib/dependencies/WorkerPlugin.js +2 -2
  83. package/lib/esm/ModuleChunkLoadingPlugin.js +76 -57
  84. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
  85. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  86. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
  87. package/lib/hmr/LazyCompilationPlugin.js +17 -18
  88. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
  89. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  90. package/lib/ids/DeterministicModuleIdsPlugin.js +48 -49
  91. package/lib/ids/HashedModuleIdsPlugin.js +4 -2
  92. package/lib/ids/NamedChunkIdsPlugin.js +6 -4
  93. package/lib/ids/NamedModuleIdsPlugin.js +6 -4
  94. package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
  95. package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
  96. package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
  97. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
  98. package/lib/index.js +1 -1
  99. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  100. package/lib/javascript/JavascriptParser.js +670 -688
  101. package/lib/library/EnableLibraryPlugin.js +15 -2
  102. package/lib/library/ModuleLibraryPlugin.js +66 -43
  103. package/lib/logging/createConsoleLogger.js +0 -1
  104. package/lib/node/CommonJsChunkLoadingPlugin.js +71 -75
  105. package/lib/node/NodeEnvironmentPlugin.js +3 -1
  106. package/lib/node/NodeTemplatePlugin.js +2 -2
  107. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
  108. package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
  109. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  110. package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
  111. package/lib/optimize/ConcatenatedModule.js +12 -15
  112. package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
  113. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  114. package/lib/optimize/MangleExportsPlugin.js +15 -16
  115. package/lib/optimize/MinChunkSizePlugin.js +4 -2
  116. package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
  117. package/lib/optimize/RealContentHashPlugin.js +4 -2
  118. package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
  119. package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
  120. package/lib/optimize/RuntimeChunkPlugin.js +17 -18
  121. package/lib/optimize/SplitChunksPlugin.js +9 -6
  122. package/lib/performance/SizeLimitsPlugin.js +3 -1
  123. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
  124. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
  125. package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
  126. package/lib/schemes/DataUriPlugin.js +5 -3
  127. package/lib/schemes/FileUriPlugin.js +5 -3
  128. package/lib/schemes/HttpUriPlugin.js +32 -39
  129. package/lib/serialization/AggregateErrorSerializer.js +42 -0
  130. package/lib/serialization/BinaryMiddleware.js +22 -38
  131. package/lib/serialization/ErrorObjectSerializer.js +7 -2
  132. package/lib/serialization/FileMiddleware.js +29 -33
  133. package/lib/serialization/ObjectMiddleware.js +42 -30
  134. package/lib/serialization/Serializer.js +29 -18
  135. package/lib/serialization/SerializerMiddleware.js +105 -72
  136. package/lib/serialization/SingleItemMiddleware.js +4 -5
  137. package/lib/sharing/ProvideSharedPlugin.js +6 -4
  138. package/lib/stats/DefaultStatsFactoryPlugin.js +128 -57
  139. package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
  140. package/lib/stats/DefaultStatsPrinterPlugin.js +486 -334
  141. package/lib/stats/StatsFactory.js +47 -10
  142. package/lib/stats/StatsPrinter.js +52 -31
  143. package/lib/util/ArrayQueue.js +1 -1
  144. package/lib/util/AsyncQueue.js +1 -1
  145. package/lib/util/TupleQueue.js +9 -7
  146. package/lib/util/TupleSet.js +37 -18
  147. package/lib/util/WeakTupleMap.js +50 -37
  148. package/lib/util/cleverMerge.js +2 -2
  149. package/lib/util/comparators.js +1 -1
  150. package/lib/util/concatenate.js +4 -2
  151. package/lib/util/createHash.js +1 -1
  152. package/lib/util/fs.js +1 -1
  153. package/lib/util/makeSerializable.js +1 -1
  154. package/lib/util/runtime.js +1 -0
  155. package/lib/util/serialization.js +50 -42
  156. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  157. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
  158. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  159. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
  160. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
  161. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  162. package/lib/web/FetchCompileWasmPlugin.js +2 -2
  163. package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
  164. package/lib/webpack.js +1 -1
  165. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
  166. package/package.json +4 -3
  167. package/schemas/WebpackOptions.check.js +1 -1
  168. package/schemas/WebpackOptions.json +24 -2
  169. package/types.d.ts +273 -128
package/README.md CHANGED
@@ -676,5 +676,5 @@ Before we started using OpenCollective, donations were made anonymously. Now tha
676
676
  [builds2-url]: https://dev.azure.com/webpack/webpack/_build/latest?definitionId=3&branchName=main
677
677
  [dependency-review-url]: https://github.com/webpack/webpack/actions/workflows/dependency-review.yml
678
678
  [dependency-review]: https://github.com/webpack/webpack/actions/workflows/dependency-review.yml/badge.svg
679
- [cover]: https://codecov.io/gh/webpack/webpack/branch/master/graph/badge.svg?token=mDP3mQJNnn
679
+ [cover]: https://codecov.io/gh/webpack/webpack/graph/badge.svg?token=mDP3mQJNnn
680
680
  [cover-url]: https://codecov.io/gh/webpack/webpack
package/lib/APIPlugin.js CHANGED
@@ -134,12 +134,12 @@ const PLUGIN_NAME = "APIPlugin";
134
134
 
135
135
  /**
136
136
  * @typedef {object} APIPluginOptions
137
- * @property {boolean} [module] the output filename
137
+ * @property {boolean=} module the output filename
138
138
  */
139
139
 
140
140
  class APIPlugin {
141
141
  /**
142
- * @param {APIPluginOptions} [options] options
142
+ * @param {APIPluginOptions=} options options
143
143
  */
144
144
  constructor(options = {}) {
145
145
  this.options = options;
@@ -11,6 +11,8 @@ const PrefetchDependency = require("./dependencies/PrefetchDependency");
11
11
 
12
12
  /** @typedef {import("./Compiler")} Compiler */
13
13
 
14
+ const PLUGIN_NAME = "AutomaticPrefetchPlugin";
15
+
14
16
  class AutomaticPrefetchPlugin {
15
17
  /**
16
18
  * Apply the plugin
@@ -19,7 +21,7 @@ class AutomaticPrefetchPlugin {
19
21
  */
20
22
  apply(compiler) {
21
23
  compiler.hooks.compilation.tap(
22
- "AutomaticPrefetchPlugin",
24
+ PLUGIN_NAME,
23
25
  (compilation, { normalModuleFactory }) => {
24
26
  compilation.dependencyFactories.set(
25
27
  PrefetchDependency,
@@ -29,7 +31,7 @@ class AutomaticPrefetchPlugin {
29
31
  );
30
32
  /** @type {{context: string | null, request: string}[] | null} */
31
33
  let lastModules = null;
32
- compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => {
34
+ compiler.hooks.afterCompile.tap(PLUGIN_NAME, compilation => {
33
35
  lastModules = [];
34
36
 
35
37
  for (const m of compilation.modules) {
@@ -41,26 +43,23 @@ class AutomaticPrefetchPlugin {
41
43
  }
42
44
  }
43
45
  });
44
- compiler.hooks.make.tapAsync(
45
- "AutomaticPrefetchPlugin",
46
- (compilation, callback) => {
47
- if (!lastModules) return callback();
48
- asyncLib.each(
49
- lastModules,
50
- (m, callback) => {
51
- compilation.addModuleChain(
52
- m.context || compiler.context,
53
- new PrefetchDependency(`!!${m.request}`),
54
- callback
55
- );
56
- },
57
- err => {
58
- lastModules = null;
59
- callback(err);
60
- }
61
- );
62
- }
63
- );
46
+ compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => {
47
+ if (!lastModules) return callback();
48
+ asyncLib.each(
49
+ lastModules,
50
+ (m, callback) => {
51
+ compilation.addModuleChain(
52
+ m.context || compiler.context,
53
+ new PrefetchDependency(`!!${m.request}`),
54
+ callback
55
+ );
56
+ },
57
+ err => {
58
+ lastModules = null;
59
+ callback(err);
60
+ }
61
+ );
62
+ });
64
63
  }
65
64
  }
66
65
  module.exports = AutomaticPrefetchPlugin;
@@ -44,6 +44,8 @@ const wrapComment = str => {
44
44
  .trimEnd()}\n */`;
45
45
  };
46
46
 
47
+ const PLUGIN_NAME = "BannerPlugin";
48
+
47
49
  class BannerPlugin {
48
50
  /**
49
51
  * @param {BannerPluginArgument} options options object
@@ -91,47 +93,41 @@ class BannerPlugin {
91
93
  const stage =
92
94
  this.options.stage || Compilation.PROCESS_ASSETS_STAGE_ADDITIONS;
93
95
 
94
- compiler.hooks.compilation.tap("BannerPlugin", compilation => {
95
- compilation.hooks.processAssets.tap(
96
- {
97
- name: "BannerPlugin",
98
- stage
99
- },
100
- () => {
101
- for (const chunk of compilation.chunks) {
102
- if (options.entryOnly && !chunk.canBeInitial()) {
96
+ compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
97
+ compilation.hooks.processAssets.tap({ name: PLUGIN_NAME, stage }, () => {
98
+ for (const chunk of compilation.chunks) {
99
+ if (options.entryOnly && !chunk.canBeInitial()) {
100
+ continue;
101
+ }
102
+
103
+ for (const file of chunk.files) {
104
+ if (!matchObject(file)) {
103
105
  continue;
104
106
  }
105
107
 
106
- for (const file of chunk.files) {
107
- if (!matchObject(file)) {
108
- continue;
108
+ /** @type {PathData} */
109
+ const data = { chunk, filename: file };
110
+
111
+ const comment = compilation.getPath(
112
+ /** @type {TemplatePath} */
113
+ (banner),
114
+ data
115
+ );
116
+
117
+ compilation.updateAsset(file, old => {
118
+ const cached = cache.get(old);
119
+ if (!cached || cached.comment !== comment) {
120
+ const source = options.footer
121
+ ? new ConcatSource(old, "\n", comment)
122
+ : new ConcatSource(comment, "\n", old);
123
+ cache.set(old, { source, comment });
124
+ return source;
109
125
  }
110
-
111
- /** @type {PathData} */
112
- const data = { chunk, filename: file };
113
-
114
- const comment = compilation.getPath(
115
- /** @type {TemplatePath} */
116
- (banner),
117
- data
118
- );
119
-
120
- compilation.updateAsset(file, old => {
121
- const cached = cache.get(old);
122
- if (!cached || cached.comment !== comment) {
123
- const source = options.footer
124
- ? new ConcatSource(old, "\n", comment)
125
- : new ConcatSource(comment, "\n", old);
126
- cache.set(old, { source, comment });
127
- return source;
128
- }
129
- return cached.source;
130
- });
131
- }
126
+ return cached.source;
127
+ });
132
128
  }
133
129
  }
134
- );
130
+ });
135
131
  });
136
132
  }
137
133
  }
package/lib/Cache.js CHANGED
@@ -26,7 +26,7 @@ const {
26
26
  * @returns {void}
27
27
  */
28
28
 
29
- /** @typedef {TODO} Data */
29
+ /** @typedef {EXPECTED_ANY} Data */
30
30
 
31
31
  /**
32
32
  * @callback GotHandler
package/lib/Chunk.js CHANGED
@@ -34,7 +34,9 @@ const { mergeRuntime } = require("./util/runtime");
34
34
  /** @typedef {import("./util/Hash")} Hash */
35
35
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
36
36
 
37
+ /** @typedef {string | null} ChunkName */
37
38
  /** @typedef {number | string} ChunkId */
39
+ /** @typedef {SortableSet<string>} IdNameHints */
38
40
 
39
41
  const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files");
40
42
 
@@ -46,9 +48,9 @@ const ChunkFilesSet = createArrayToSetDeprecationSet("chunk.files");
46
48
  /**
47
49
  * @deprecated
48
50
  * @typedef {object} ChunkMaps
49
- * @property {Record<string|number, string>} hash
50
- * @property {Record<string|number, Record<string, string>>} contentHash
51
- * @property {Record<string|number, string>} name
51
+ * @property {Record<string | number, string>} hash
52
+ * @property {Record<string | number, Record<string, string>>} contentHash
53
+ * @property {Record<string | number, string>} name
52
54
  */
53
55
 
54
56
  /**
@@ -66,7 +68,7 @@ let debugId = 1000;
66
68
  */
67
69
  class Chunk {
68
70
  /**
69
- * @param {(string | null)=} name of chunk being created, is optional (for subclasses)
71
+ * @param {ChunkName=} name of chunk being created, is optional (for subclasses)
70
72
  * @param {boolean} backCompat enable backward-compatibility
71
73
  */
72
74
  constructor(name, backCompat = true) {
@@ -76,9 +78,9 @@ class Chunk {
76
78
  this.ids = null;
77
79
  /** @type {number} */
78
80
  this.debugId = debugId++;
79
- /** @type {string | null | undefined} */
81
+ /** @type {ChunkName | undefined} */
80
82
  this.name = name;
81
- /** @type {SortableSet<string>} */
83
+ /** @type {IdNameHints} */
82
84
  this.idNameHints = new SortableSet();
83
85
  /** @type {boolean} */
84
86
  this.preventIntegration = false;
@@ -696,7 +698,7 @@ class Chunk {
696
698
  /**
697
699
  * @param {ChunkGraph} chunkGraph the chunk graph
698
700
  * @param {ChunkFilterPredicate=} filterFn function used to filter chunks
699
- * @returns {Record<string, (string | number)[]>} a record object of names to lists of child ids(?)
701
+ * @returns {Record<string, ChunkId[]>} a record object of names to lists of child ids(?)
700
702
  */
701
703
  getChildIdsByOrders(chunkGraph, filterFn) {
702
704
  /** @type {Map<string, {order: number, group: ChunkGroup}[]>} */
@@ -717,7 +719,8 @@ class Chunk {
717
719
  /** @type {number} */
718
720
  (
719
721
  childGroup.options[
720
- /** @type {keyof ChunkGroupOptions} */ (key)
722
+ /** @type {keyof ChunkGroupOptions} */
723
+ (key)
721
724
  ]
722
725
  ),
723
726
  group: childGroup
@@ -735,7 +738,7 @@ class Chunk {
735
738
  if (cmp !== 0) return cmp;
736
739
  return a.group.compareTo(chunkGraph, b.group);
737
740
  });
738
- /** @type {Set<string | number>} */
741
+ /** @type {Set<ChunkId>} */
739
742
  const chunkIdSet = new Set();
740
743
  for (const item of list) {
741
744
  for (const chunk of item.group.chunks) {
@@ -296,6 +296,8 @@ const applyDiff = (fs, outputPath, dry, logger, diff, isKept, callback) => {
296
296
  /** @type {WeakMap<Compilation, CleanPluginCompilationHooks>} */
297
297
  const compilationHooksMap = new WeakMap();
298
298
 
299
+ const PLUGIN_NAME = "CleanPlugin";
300
+
299
301
  class CleanPlugin {
300
302
  /**
301
303
  * @param {Compilation} compilation the compilation
@@ -349,18 +351,18 @@ class CleanPlugin {
349
351
 
350
352
  compiler.hooks.emit.tapAsync(
351
353
  {
352
- name: "CleanPlugin",
354
+ name: PLUGIN_NAME,
353
355
  stage: 100
354
356
  },
355
357
  (compilation, callback) => {
356
358
  const hooks = CleanPlugin.getCompilationHooks(compilation);
357
- const logger = compilation.getLogger("webpack.CleanPlugin");
359
+ const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
358
360
  const fs = /** @type {OutputFileSystem} */ (compiler.outputFileSystem);
359
361
 
360
362
  if (!fs.readdir) {
361
363
  return callback(
362
364
  new Error(
363
- "CleanPlugin: Output filesystem doesn't support listing directories (readdir)"
365
+ `${PLUGIN_NAME}: Output filesystem doesn't support listing directories (readdir)`
364
366
  )
365
367
  );
366
368
  }
@@ -94,10 +94,13 @@ const { isSourceEqual } = require("./util/source");
94
94
  /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
95
95
  /** @typedef {import("./Cache")} Cache */
96
96
  /** @typedef {import("./CacheFacade")} CacheFacade */
97
+ /** @typedef {import("./Chunk").ChunkName} ChunkName */
97
98
  /** @typedef {import("./Chunk").ChunkId} ChunkId */
98
99
  /** @typedef {import("./ChunkGroup").ChunkGroupOptions} ChunkGroupOptions */
99
100
  /** @typedef {import("./Compiler")} Compiler */
100
101
  /** @typedef {import("./Compiler").CompilationParams} CompilationParams */
102
+ /** @typedef {import("./Compiler").MemCache} MemCache */
103
+ /** @typedef {import("./Compiler").WeakReferences} WeakReferences */
101
104
  /** @typedef {import("./Compiler").ModuleMemCachesItem} ModuleMemCachesItem */
102
105
  /** @typedef {import("./DependenciesBlock")} DependenciesBlock */
103
106
  /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
@@ -106,6 +109,7 @@ const { isSourceEqual } = require("./util/source");
106
109
  /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
107
110
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
108
111
  /** @typedef {import("./Module").ValueCacheVersions} ValueCacheVersions */
112
+ /** @typedef {import("./Module").RuntimeRequirements} RuntimeRequirements */
109
113
  /** @typedef {import("./NormalModule").NormalModuleCompilationHooks} NormalModuleCompilationHooks */
110
114
  /** @typedef {import("./Module").FactoryMeta} FactoryMeta */
111
115
  /** @typedef {import("./Module").CodeGenerationResult} CodeGenerationResult */
@@ -132,7 +136,6 @@ const { isSourceEqual } = require("./util/source");
132
136
  * @typedef {import("./util/deprecation").FakeHook<T>} FakeHook<T>
133
137
  */
134
138
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
135
- /** @typedef {WeakMap<Dependency, Module>} References */
136
139
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
137
140
  /**
138
141
  * @callback Callback
@@ -168,12 +171,6 @@ const { isSourceEqual } = require("./util/source");
168
171
  * @returns {void}
169
172
  */
170
173
 
171
- /**
172
- * @callback DepBlockVarDependenciesCallback
173
- * @param {Dependency} dependency
174
- * @returns {any}
175
- */
176
-
177
174
  /** @typedef {new (...args: EXPECTED_ANY[]) => Dependency} DepConstructor */
178
175
 
179
176
  /** @typedef {Record<string, Source>} CompilationAssets */
@@ -235,17 +232,17 @@ const { isSourceEqual } = require("./util/source");
235
232
 
236
233
  /**
237
234
  * @typedef {object} ExecuteModuleObject
238
- * @property {string} [id] module id
235
+ * @property {string=} id module id
239
236
  * @property {ExecuteModuleExports} exports exports
240
237
  * @property {boolean} loaded is loaded
241
- * @property {Error} [error] error
238
+ * @property {Error=} error error
242
239
  */
243
240
 
244
241
  /**
245
242
  * @typedef {object} ExecuteModuleArgument
246
243
  * @property {Module} module
247
244
  * @property {ExecuteModuleObject=} moduleObject
248
- * @property {any} preparedInfo
245
+ * @property {TODO} preparedInfo
249
246
  * @property {CodeGenerationResult} codeGenerationResult
250
247
  */
251
248
 
@@ -253,7 +250,7 @@ const { isSourceEqual } = require("./util/source");
253
250
 
254
251
  /**
255
252
  * @typedef {object} ExecuteOptions
256
- * @property {string} [id] module id
253
+ * @property {string=} id module id
257
254
  * @property {ExecuteModuleObject} module module
258
255
  * @property {WebpackRequire} require require function
259
256
  */
@@ -333,6 +330,8 @@ const { isSourceEqual } = require("./util/source");
333
330
  * @property {string=} url
334
331
  */
335
332
 
333
+ /** @typedef {"module" | "chunk" | "root-of-chunk" | "nested"} ExcludeModulesType */
334
+
336
335
  /**
337
336
  * @typedef {object} KnownNormalizedStatsOptions
338
337
  * @property {string} context
@@ -349,7 +348,7 @@ const { isSourceEqual } = require("./util/source");
349
348
  * @property {boolean} groupAssetsByExtension
350
349
  * @property {number} assetsSpace
351
350
  * @property {((value: string, asset: StatsAsset) => boolean)[]} excludeAssets
352
- * @property {((name: string, module: StatsModule, type: "module" | "chunk" | "root-of-chunk" | "nested") => boolean)[]} excludeModules
351
+ * @property {((name: string, module: StatsModule, type: ExcludeModulesType) => boolean)[]} excludeModules
353
352
  * @property {((warning: StatsError, textValue: string) => boolean)[]} warningsFilter
354
353
  * @property {boolean} cachedModules
355
354
  * @property {boolean} orphanModules
@@ -459,10 +458,10 @@ const compareErrors = concatComparators(byModule, byLocation, byMessage);
459
458
 
460
459
  /**
461
460
  * @typedef {object} KnownUnsafeCacheData
462
- * @property {FactoryMeta} [factoryMeta] factory meta
463
- * @property {ResolveOptions} [resolveOptions] resolve options
464
- * @property {ParserOptions} [parserOptions]
465
- * @property {GeneratorOptions} [generatorOptions]
461
+ * @property {FactoryMeta=} factoryMeta factory meta
462
+ * @property {ResolveOptions=} resolveOptions resolve options
463
+ * @property {ParserOptions=} parserOptions
464
+ * @property {GeneratorOptions=} generatorOptions
466
465
  */
467
466
 
468
467
  /** @typedef {KnownUnsafeCacheData & Record<string, EXPECTED_ANY>} UnsafeCacheData */
@@ -477,7 +476,8 @@ const unsafeCacheDependencies = new WeakMap();
477
476
  /** @type {WeakMap<ModuleWithRestoreFromUnsafeCache, UnsafeCacheData>} */
478
477
  const unsafeCacheData = new WeakMap();
479
478
 
480
- /** @typedef {Map<Module, WeakTupleMap<any, any>>} ModuleMemCaches */
479
+ /** @typedef {{ id: ModuleId, modules?: Map<Module, string | number | undefined>, blocks?: (string | number | null)[] }} References */
480
+ /** @typedef {Map<Module, WeakTupleMap<EXPECTED_ANY[], EXPECTED_ANY>>} ModuleMemCaches */
481
481
 
482
482
  class Compilation {
483
483
  /**
@@ -690,7 +690,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
690
690
  processAssetsHook.tapAsync(
691
691
  getOptions(options),
692
692
  (assets, callback) =>
693
- /** @type {any} */ (fn)(...getArgs(), callback)
693
+ /** @type {TODO} */ (fn)(...getArgs(), callback)
694
694
  );
695
695
  },
696
696
  /** @type {AsyncSeriesHook<T>["tapPromise"]} */
@@ -973,9 +973,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
973
973
  /** @type {SyncBailHook<[string, LogEntry], boolean | void>} */
974
974
  log: new SyncBailHook(["origin", "logEntry"]),
975
975
 
976
- /** @type {SyncWaterfallHook<[WebpackError[]]>} */
976
+ /** @type {SyncWaterfallHook<[Error[]]>} */
977
977
  processWarnings: new SyncWaterfallHook(["warnings"]),
978
- /** @type {SyncWaterfallHook<[WebpackError[]]>} */
978
+ /** @type {SyncWaterfallHook<[Error[]]>} */
979
979
  processErrors: new SyncWaterfallHook(["errors"]),
980
980
 
981
981
  /** @type {HookMap<SyncHook<[Partial<NormalizedStatsOptions>, CreateStatsOptionsContext]>>} */
@@ -1049,6 +1049,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1049
1049
  };
1050
1050
  defineRemovedModuleTemplates(this.moduleTemplates);
1051
1051
 
1052
+ // We need to think how implement types here
1052
1053
  /** @type {ModuleMemCaches | undefined} */
1053
1054
  this.moduleMemCaches = undefined;
1054
1055
  /** @type {ModuleMemCaches | undefined} */
@@ -1099,7 +1100,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1099
1100
  */
1100
1101
  this.creatingModuleDuringBuild = new WeakMap();
1101
1102
 
1102
- /** @type {Map<string, EntryData>} */
1103
+ /** @type {Map<Exclude<ChunkName, null>, EntryData>} */
1103
1104
  this.entries = new Map();
1104
1105
  /** @type {EntryData} */
1105
1106
  this.globalEntry = {
@@ -1142,9 +1143,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1142
1143
  this.assetsInfo = new Map();
1143
1144
  /** @type {Map<string, Map<string, Set<string>>>} */
1144
1145
  this._assetsRelatedIn = new Map();
1145
- /** @type {WebpackError[]} */
1146
+ /** @type {Error[]} */
1146
1147
  this.errors = [];
1147
- /** @type {WebpackError[]} */
1148
+ /** @type {Error[]} */
1148
1149
  this.warnings = [];
1149
1150
  /** @type {Compilation[]} */
1150
1151
  this.children = [];
@@ -2501,10 +2502,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2501
2502
 
2502
2503
  /**
2503
2504
  * @param {Module} module module
2504
- * @returns {References | undefined} references
2505
+ * @returns {WeakReferences | undefined} references
2505
2506
  */
2506
2507
  const computeReferences = module => {
2507
- /** @type {References | undefined} */
2508
+ /** @type {WeakReferences | undefined} */
2508
2509
  let references;
2509
2510
  for (const connection of moduleGraph.getOutgoingConnections(module)) {
2510
2511
  const d = connection.dependency;
@@ -2518,7 +2519,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2518
2519
 
2519
2520
  /**
2520
2521
  * @param {Module} module the module
2521
- * @param {References | undefined} references references
2522
+ * @param {WeakReferences | undefined} references references
2522
2523
  * @returns {boolean} true, when the references differ
2523
2524
  */
2524
2525
  const compareReferences = (module, references) => {
@@ -2540,6 +2541,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2540
2541
  if (buildInfo) {
2541
2542
  if (cachedMemCache.buildInfo !== buildInfo) {
2542
2543
  // use a new one
2544
+ /** @type {MemCache} */
2543
2545
  const memCache = new WeakTupleMap();
2544
2546
  moduleMemCaches.set(module, memCache);
2545
2547
  affectedModules.add(module);
@@ -2549,6 +2551,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2549
2551
  statChanged++;
2550
2552
  } else if (!compareReferences(module, cachedMemCache.references)) {
2551
2553
  // use a new one
2554
+ /** @type {MemCache} */
2552
2555
  const memCache = new WeakTupleMap();
2553
2556
  moduleMemCaches.set(module, memCache);
2554
2557
  affectedModules.add(module);
@@ -2639,6 +2642,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2639
2642
  } else {
2640
2643
  affectedModules.add(referencingModule);
2641
2644
  }
2645
+ /** @type {MemCache} */
2642
2646
  const memCache = new WeakTupleMap();
2643
2647
  const cache =
2644
2648
  /** @type {ModuleMemCachesItem} */
@@ -2671,7 +2675,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2671
2675
  let statNew = 0;
2672
2676
  /**
2673
2677
  * @param {Module} module module
2674
- * @returns {{ id: ModuleId, modules?: Map<Module, string | number | undefined>, blocks?: (string | number | null)[] }} references
2678
+ * @returns {References} references
2675
2679
  */
2676
2680
  const computeReferences = module => {
2677
2681
  const id = /** @type {ModuleId} */ (chunkGraph.getModuleId(module));
@@ -2741,9 +2745,10 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2741
2745
  };
2742
2746
 
2743
2747
  for (const [module, memCache] of moduleMemCaches) {
2744
- /** @type {{ references: { id: string | number, modules?: Map<Module, string | number | undefined>, blocks?: (string | number | null)[]}, memCache: WeakTupleMap<any[], any> }} */
2748
+ /** @type {{ references: References, memCache: MemCache } | undefined} */
2745
2749
  const cache = memCache.get(key);
2746
2750
  if (cache === undefined) {
2751
+ /** @type {WeakTupleMap<Module[], RuntimeRequirements | null> | undefined} */
2747
2752
  const memCache2 = new WeakTupleMap();
2748
2753
  memCache.set(key, {
2749
2754
  references: computeReferences(module),
@@ -2752,6 +2757,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
2752
2757
  moduleMemCaches2.set(module, memCache2);
2753
2758
  statNew++;
2754
2759
  } else if (!compareReferences(module, cache.references)) {
2760
+ /** @type {WeakTupleMap<Module[], RuntimeRequirements | null> | undefined} */
2755
2761
  const memCache = new WeakTupleMap();
2756
2762
  cache.references = computeReferences(module);
2757
2763
  cache.memCache = memCache;
@@ -3732,7 +3738,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3732
3738
  chunkGraph.addModuleRuntimeRequirements(
3733
3739
  module,
3734
3740
  runtime,
3735
- cached,
3741
+ /** @type {RuntimeRequirements} */
3742
+ (cached),
3736
3743
  false
3737
3744
  );
3738
3745
  }
@@ -3980,7 +3987,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
3980
3987
  /**
3981
3988
  * This method first looks to see if a name is provided for a new chunk,
3982
3989
  * and first looks to see if any named chunks already exist and reuse that chunk instead.
3983
- * @param {(string | null)=} name optional chunk name to be provided
3990
+ * @param {ChunkName=} name optional chunk name to be provided
3984
3991
  * @returns {Chunk} create a chunk (invoked during seal event)
3985
3992
  */
3986
3993
  addChunk(name) {
@@ -4237,7 +4244,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4237
4244
  const memCache = moduleMemCaches2 && moduleMemCaches2.get(module);
4238
4245
  for (const runtime of chunkGraph.getModuleRuntimes(module)) {
4239
4246
  if (memCache) {
4240
- const digest = memCache.get(`moduleHash-${getRuntimeKey(runtime)}`);
4247
+ const digest =
4248
+ /** @type {string} */
4249
+ (memCache.get(`moduleHash-${getRuntimeKey(runtime)}`));
4241
4250
  if (digest !== undefined) {
4242
4251
  chunkGraph.setModuleHashes(
4243
4252
  module,
@@ -5477,9 +5486,9 @@ This prevents using hashes of each other and should be avoided.`);
5477
5486
  if (strictModuleExceptionHandling) {
5478
5487
  if (id) delete moduleCache[id];
5479
5488
  } else if (strictModuleErrorHandling) {
5480
- moduleObject.error = /** @type {WebpackError} */ (
5481
- execErr
5482
- );
5489
+ moduleObject.error =
5490
+ /** @type {WebpackError} */
5491
+ (execErr);
5483
5492
  }
5484
5493
  if (!(/** @type {WebpackError} */ (execErr).module)) {
5485
5494
  /** @type {WebpackError} */
@@ -5506,7 +5515,8 @@ This prevents using hashes of each other and should be avoided.`);
5506
5515
  `Execution of module code from module graph (${
5507
5516
  /** @type {Module} */
5508
5517
  (module).readableIdentifier(this.requestShortener)
5509
- }) failed: ${message}`
5518
+ }) failed: ${message}`,
5519
+ { cause: execErr }
5510
5520
  );
5511
5521
  err.stack = stack;
5512
5522
  err.module = module;
package/lib/Compiler.js CHANGED
@@ -40,7 +40,7 @@ const { isSourceEqual } = require("./util/source");
40
40
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
41
41
  /** @typedef {import("../declarations/WebpackOptions").WebpackPluginInstance} WebpackPluginInstance */
42
42
  /** @typedef {import("./Chunk")} Chunk */
43
- /** @typedef {import("./Compilation").References} References */
43
+ /** @typedef {import("./ChunkGraph").ModuleId} ModuleId */
44
44
  /** @typedef {import("./Dependency")} Dependency */
45
45
  /** @typedef {import("./Module")} Module */
46
46
  /** @typedef {import("./Module").BuildInfo} BuildInfo */
@@ -90,10 +90,11 @@ const { isSourceEqual } = require("./util/source");
90
90
  */
91
91
 
92
92
  /** @typedef {{ sizeOnlySource: SizeOnlySource | undefined, writtenTo: Map<string, number> }} CacheEntry */
93
-
94
93
  /** @typedef {{ path: string, source: Source, size: number | undefined, waiting: ({ cacheEntry: CacheEntry, file: string }[] | undefined) }} SimilarEntry */
95
94
 
96
- /** @typedef {{ buildInfo: BuildInfo, references: References | undefined, memCache: import("./util/WeakTupleMap")<Module[], string> }} ModuleMemCachesItem */
95
+ /** @typedef {WeakMap<Dependency, Module>} WeakReferences */
96
+ /** @typedef {import("./util/WeakTupleMap")<EXPECTED_ANY[], EXPECTED_ANY>} MemCache */
97
+ /** @typedef {{ buildInfo: BuildInfo, references: WeakReferences | undefined, memCache: MemCache }} ModuleMemCachesItem */
97
98
 
98
99
  /**
99
100
  * @param {string[]} array an array
@@ -624,7 +625,8 @@ class Compiler {
624
625
  callback(err, entries, compilation);
625
626
  } catch (runAsChildErr) {
626
627
  const err = new WebpackError(
627
- `compiler.runAsChild callback error: ${runAsChildErr}`
628
+ `compiler.runAsChild callback error: ${runAsChildErr}`,
629
+ { cause: runAsChildErr }
628
630
  );
629
631
  err.details = /** @type {Error} */ (runAsChildErr).stack;
630
632
  /** @type {Compilation} */
@@ -7,6 +7,8 @@
7
7
  /** @typedef {import("./Compiler")} Compiler */
8
8
  /** @typedef {import("./ContextModuleFactory")} ContextModuleFactory */
9
9
 
10
+ const PLUGIN_NAME = "ContextExclusionPlugin";
11
+
10
12
  class ContextExclusionPlugin {
11
13
  /**
12
14
  * @param {RegExp} negativeMatcher Matcher regular expression
@@ -21,8 +23,8 @@ class ContextExclusionPlugin {
21
23
  * @returns {void}
22
24
  */
23
25
  apply(compiler) {
24
- compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", cmf => {
25
- cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files =>
26
+ compiler.hooks.contextModuleFactory.tap(PLUGIN_NAME, cmf => {
27
+ cmf.hooks.contextModuleFiles.tap(PLUGIN_NAME, files =>
26
28
  files.filter(filePath => !this.negativeMatcher.test(filePath))
27
29
  );
28
30
  });
@@ -29,6 +29,7 @@ const {
29
29
  const makeSerializable = require("./util/makeSerializable");
30
30
 
31
31
  /** @typedef {import("webpack-sources").Source} Source */
32
+ /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
32
33
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
33
34
  /** @typedef {import("./Chunk")} Chunk */
34
35
  /** @typedef {import("./Chunk").ChunkId} ChunkId */
@@ -83,7 +84,7 @@ const makeSerializable = require("./util/makeSerializable");
83
84
  * @property {false|string|string[]} resource
84
85
  * @property {string=} resourceQuery
85
86
  * @property {string=} resourceFragment
86
- * @property {TODO} resolveOptions
87
+ * @property {ResolveOptions=} resolveOptions
87
88
  */
88
89
 
89
90
  /** @typedef {ContextOptions & ContextModuleOptionsExtras} ContextModuleOptions */