webpack 5.99.5 → 5.99.6

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 (87) hide show
  1. package/README.md +1 -1
  2. package/lib/APIPlugin.js +2 -2
  3. package/lib/Cache.js +1 -1
  4. package/lib/Chunk.js +12 -9
  5. package/lib/Compilation.js +36 -27
  6. package/lib/Compiler.js +4 -3
  7. package/lib/ContextModule.js +2 -1
  8. package/lib/HotModuleReplacementPlugin.js +3 -3
  9. package/lib/Module.js +10 -2
  10. package/lib/ModuleFilenameHelpers.js +1 -1
  11. package/lib/ModuleGraph.js +15 -10
  12. package/lib/NormalModule.js +1 -1
  13. package/lib/PrefetchPlugin.js +1 -1
  14. package/lib/RecordIdsPlugin.js +1 -1
  15. package/lib/SourceMapDevToolPlugin.js +1 -1
  16. package/lib/Template.js +1 -1
  17. package/lib/WebpackOptionsApply.js +17 -2
  18. package/lib/buildChunkGraph.js +7 -2
  19. package/lib/cache/IdleFileCachePlugin.js +1 -1
  20. package/lib/cache/MemoryCachePlugin.js +2 -1
  21. package/lib/cache/MemoryWithGcCachePlugin.js +3 -2
  22. package/lib/cache/PackFileCacheStrategy.js +13 -21
  23. package/lib/cache/ResolverCachePlugin.js +14 -16
  24. package/lib/cli.js +3 -3
  25. package/lib/config/defaults.js +2 -2
  26. package/lib/config/target.js +6 -6
  27. package/lib/css/CssParser.js +1 -1
  28. package/lib/debug/ProfilingPlugin.js +1 -1
  29. package/lib/dependencies/ContextDependencyHelpers.js +1 -1
  30. package/lib/dependencies/CssIcssImportDependency.js +3 -2
  31. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  32. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  33. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
  34. package/lib/dependencies/JsonExportsDependency.js +1 -1
  35. package/lib/dependencies/LocalModulesHelpers.js +1 -1
  36. package/lib/dependencies/RequireResolveDependency.js +1 -1
  37. package/lib/dependencies/WorkerPlugin.js +2 -2
  38. package/lib/esm/ModuleChunkLoadingPlugin.js +20 -0
  39. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
  40. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  41. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  42. package/lib/ids/NamedChunkIdsPlugin.js +2 -2
  43. package/lib/ids/NamedModuleIdsPlugin.js +2 -2
  44. package/lib/index.js +1 -1
  45. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  46. package/lib/javascript/JavascriptParser.js +41 -37
  47. package/lib/library/EnableLibraryPlugin.js +15 -2
  48. package/lib/library/ModuleLibraryPlugin.js +6 -1
  49. package/lib/logging/createConsoleLogger.js +0 -1
  50. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -2
  51. package/lib/node/NodeTemplatePlugin.js +2 -2
  52. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
  53. package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
  54. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  55. package/lib/optimize/SplitChunksPlugin.js +2 -1
  56. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
  57. package/lib/serialization/BinaryMiddleware.js +22 -38
  58. package/lib/serialization/FileMiddleware.js +29 -33
  59. package/lib/serialization/ObjectMiddleware.js +29 -30
  60. package/lib/serialization/Serializer.js +29 -18
  61. package/lib/serialization/SerializerMiddleware.js +105 -72
  62. package/lib/serialization/SingleItemMiddleware.js +4 -5
  63. package/lib/stats/DefaultStatsFactoryPlugin.js +39 -24
  64. package/lib/stats/DefaultStatsPrinterPlugin.js +267 -80
  65. package/lib/stats/StatsFactory.js +47 -10
  66. package/lib/stats/StatsPrinter.js +52 -31
  67. package/lib/util/ArrayQueue.js +1 -1
  68. package/lib/util/AsyncQueue.js +1 -1
  69. package/lib/util/TupleQueue.js +9 -7
  70. package/lib/util/TupleSet.js +37 -18
  71. package/lib/util/WeakTupleMap.js +50 -37
  72. package/lib/util/cleverMerge.js +2 -2
  73. package/lib/util/comparators.js +1 -1
  74. package/lib/util/createHash.js +1 -1
  75. package/lib/util/fs.js +1 -1
  76. package/lib/util/makeSerializable.js +1 -1
  77. package/lib/util/runtime.js +1 -0
  78. package/lib/util/serialization.js +50 -42
  79. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  80. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
  81. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  82. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
  83. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  84. package/lib/web/FetchCompileWasmPlugin.js +2 -2
  85. package/lib/webpack.js +1 -1
  86. package/package.json +1 -1
  87. package/types.d.ts +125 -73
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;
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) {
@@ -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"]} */
@@ -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 = {
@@ -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,
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
@@ -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 */
@@ -376,11 +376,11 @@ class HotModuleReplacementPlugin {
376
376
  );
377
377
  }
378
378
  });
379
- /** @type {TupleSet<[Module, Chunk]>} */
379
+ /** @type {TupleSet<Module, Chunk>} */
380
380
  const updatedModules = new TupleSet();
381
- /** @type {TupleSet<[Module, Chunk]>} */
381
+ /** @type {TupleSet<Module, Chunk>} */
382
382
  const fullHashModules = new TupleSet();
383
- /** @type {TupleSet<[Module, RuntimeSpec]>} */
383
+ /** @type {TupleSet<Module, RuntimeSpec>} */
384
384
  const nonCodeGeneratedModules = new TupleSet();
385
385
  compilation.hooks.fullHash.tap(PLUGIN_NAME, hash => {
386
386
  const chunkGraph = compilation.chunkGraph;
package/lib/Module.js CHANGED
@@ -42,12 +42,20 @@ const makeSerializable = require("./util/makeSerializable");
42
42
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
43
43
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
44
44
  /** @typedef {import("./util/Hash")} Hash */
45
- /** @template T @typedef {import("./util/LazySet")<T>} LazySet<T> */
46
- /** @template T @typedef {import("./util/SortableSet")<T>} SortableSet<T> */
47
45
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
48
46
  /** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
49
47
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
50
48
 
49
+ /**
50
+ * @template T
51
+ * @typedef {import("./util/LazySet")<T>} LazySet<T>
52
+ */
53
+
54
+ /**
55
+ * @template T
56
+ * @typedef {import("./util/SortableSet")<T>} SortableSet<T>
57
+ */
58
+
51
59
  /**
52
60
  * @typedef {object} SourceContext
53
61
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
@@ -262,7 +262,7 @@ ModuleFilenameHelpers.createFilename = (
262
262
  * @template T
263
263
  * @param {T[]} array the array with duplicates to be replaced
264
264
  * @param {(duplicateItem: T, duplicateItemIndex: number, numberOfTimesReplaced: number) => T} fn callback function to generate new values for the duplicate items
265
- * @param {(firstElement:T, nextElement:T) => -1 | 0 | 1} [comparator] optional comparator function to sort the duplicate items
265
+ * @param {(firstElement:T, nextElement:T) => -1 | 0 | 1=} comparator optional comparator function to sort the duplicate items
266
266
  * @returns {T[]} the array with duplicates replaced
267
267
  * @example
268
268
  * ```js
@@ -143,7 +143,7 @@ class ModuleGraph {
143
143
  */
144
144
  this._metaMap = new WeakMap();
145
145
  /**
146
- * @type {WeakTupleMap<any[], any> | undefined}
146
+ * @type {WeakTupleMap<EXPECTED_ANY[], EXPECTED_ANY> | undefined}
147
147
  * @private
148
148
  */
149
149
  this._cache = undefined;
@@ -797,10 +797,10 @@ class ModuleGraph {
797
797
 
798
798
  /**
799
799
  * @template T
800
- * @template V
801
- * @param {(moduleGraph: ModuleGraph, ...args: T[]) => V} fn computer
800
+ * @template R
801
+ * @param {(moduleGraph: ModuleGraph, ...args: T[]) => R} fn computer
802
802
  * @param {...T} args arguments
803
- * @returns {V} computed value or cached
803
+ * @returns {R} computed value or cached
804
804
  */
805
805
  cached(fn, ...args) {
806
806
  if (this._cache === undefined) return fn(this, ...args);
@@ -815,16 +815,21 @@ class ModuleGraph {
815
815
  }
816
816
 
817
817
  /**
818
- * @param {Dependency} dependency dependency
819
- * @param {...any} args arguments, last argument is a function called with moduleGraph, dependency, ...args
820
- * @returns {any} computed value or cached
818
+ * @template {Dependency} D
819
+ * @template {EXPECTED_ANY[]} ARGS
820
+ * @template R
821
+ * @param {D} dependency dependency
822
+ * @param {[...ARGS, (moduleGraph: ModuleGraph, dependency: D, ...args: ARGS) => R]} args arguments, last argument is a function called with moduleGraph, dependency, ...args
823
+ * @returns {R} computed value or cached
821
824
  */
822
825
  dependencyCacheProvide(dependency, ...args) {
823
- /** @type {(moduleGraph: ModuleGraph, dependency: Dependency, ...args: any[]) => any} */
824
- const fn = args.pop();
826
+ const fn =
827
+ /** @type {(moduleGraph: ModuleGraph, dependency: D, ...args: EXPECTED_ANY[]) => R} */
828
+ (args.pop());
825
829
  if (this._moduleMemCaches && this._cacheStage) {
826
830
  const memCache = this._moduleMemCaches.get(
827
- /** @type {Module} */ (this.getParentModule(dependency))
831
+ /** @type {Module} */
832
+ (this.getParentModule(dependency))
828
833
  );
829
834
  if (memCache !== undefined) {
830
835
  return memCache.provide(dependency, this._cacheStage, ...args, () =>
@@ -663,7 +663,7 @@ class NormalModule extends Module {
663
663
  const loaderContext = {
664
664
  version: 2,
665
665
  /**
666
- * @param {import("../declarations/LoaderContext").Schema} [schema] schema
666
+ * @param {import("../declarations/LoaderContext").Schema=} schema schema
667
667
  * @returns {T} options
668
668
  */
669
669
  getOptions: schema => {
@@ -12,7 +12,7 @@ const PrefetchDependency = require("./dependencies/PrefetchDependency");
12
12
  class PrefetchPlugin {
13
13
  /**
14
14
  * @param {string} context context or request if context is not set
15
- * @param {string} [request] request
15
+ * @param {string=} request request
16
16
  */
17
17
  constructor(context, request) {
18
18
  if (request) {
@@ -39,7 +39,7 @@ const identifierUtils = require("./util/identifier");
39
39
 
40
40
  class RecordIdsPlugin {
41
41
  /**
42
- * @param {RecordIdsPluginOptions} [options] object
42
+ * @param {RecordIdsPluginOptions=} options object
43
43
  */
44
44
  constructor(options) {
45
45
  this.options = options || {};
@@ -133,7 +133,7 @@ const getTaskForFile = (
133
133
 
134
134
  class SourceMapDevToolPlugin {
135
135
  /**
136
- * @param {SourceMapDevToolPluginOptions} [options] options object
136
+ * @param {SourceMapDevToolPluginOptions=} options options object
137
137
  * @throws {Error} throws error, if got more than 1 arguments
138
138
  */
139
139
  constructor(options = {}) {
package/lib/Template.js CHANGED
@@ -250,7 +250,7 @@ class Template {
250
250
 
251
251
  /**
252
252
  * @typedef {object} WithId
253
- * @property {string|number} id
253
+ * @property {string | number} id
254
254
  */
255
255
 
256
256
  /**
@@ -48,6 +48,7 @@ const WorkerPlugin = require("./dependencies/WorkerPlugin");
48
48
 
49
49
  const InferAsyncModulesPlugin = require("./async-modules/InferAsyncModulesPlugin");
50
50
 
51
+ const FlagDependencyExportsPlugin = require("./FlagDependencyExportsPlugin");
51
52
  const JavascriptMetaInfoPlugin = require("./JavascriptMetaInfoPlugin");
52
53
  const DefaultStatsFactoryPlugin = require("./stats/DefaultStatsFactoryPlugin");
53
54
  const DefaultStatsPresetPlugin = require("./stats/DefaultStatsPresetPlugin");
@@ -236,9 +237,24 @@ class WebpackOptionsApply extends OptionsApply {
236
237
  (options.output.enabledLibraryTypes);
237
238
 
238
239
  if (enabledLibraryTypes.length > 0) {
240
+ let once = true;
239
241
  for (const type of enabledLibraryTypes) {
240
242
  const EnableLibraryPlugin = require("./library/EnableLibraryPlugin");
241
- new EnableLibraryPlugin(type).apply(compiler);
243
+ new EnableLibraryPlugin(type, {
244
+ // eslint-disable-next-line no-loop-func
245
+ additionalApply: () => {
246
+ if (!once) return;
247
+ once = false;
248
+ // We rely on `exportInfo` to generate the `export statement` in certain library bundles.
249
+ // Therefore, we ignore the disabling of `optimization.providedExport` and continue to apply `FlagDependencyExportsPlugin`.
250
+ if (
251
+ ["module", "commonjs-static", "modern-module"].includes(type) &&
252
+ !options.optimization.providedExports
253
+ ) {
254
+ new FlagDependencyExportsPlugin().apply(compiler);
255
+ }
256
+ }
257
+ }).apply(compiler);
242
258
  }
243
259
  }
244
260
 
@@ -458,7 +474,6 @@ class WebpackOptionsApply extends OptionsApply {
458
474
  ).apply(compiler);
459
475
  }
460
476
  if (options.optimization.providedExports) {
461
- const FlagDependencyExportsPlugin = require("./FlagDependencyExportsPlugin");
462
477
  new FlagDependencyExportsPlugin().apply(compiler);
463
478
  }
464
479
  if (options.optimization.usedExports) {
@@ -256,6 +256,7 @@ const visitModules = (
256
256
  ) => {
257
257
  const { moduleGraph, chunkGraph, moduleMemCaches } = compilation;
258
258
 
259
+ /** @type {Map<RuntimeSpec, BlockModulesMap>} */
259
260
  const blockModulesRuntimeMap = new Map();
260
261
 
261
262
  /** @type {BlockModulesMap | undefined} */
@@ -288,11 +289,12 @@ const visitModules = (
288
289
  /**
289
290
  * @param {DependenciesBlock} block block
290
291
  * @param {RuntimeSpec} runtime runtime
291
- * @returns {BlockModulesInFlattenTuples} block modules in flatten tuples
292
+ * @returns {BlockModulesInFlattenTuples | undefined} block modules in flatten tuples
292
293
  */
293
294
  const getBlockModules = (block, runtime) => {
294
295
  blockModulesMap = blockModulesRuntimeMap.get(runtime);
295
296
  if (blockModulesMap === undefined) {
297
+ /** @type {BlockModulesMap} */
296
298
  blockModulesMap = new Map();
297
299
  blockModulesRuntimeMap.set(runtime, blockModulesMap);
298
300
  }
@@ -301,6 +303,7 @@ const visitModules = (
301
303
  const module = /** @type {Module} */ (block.getRootBlock());
302
304
  const memCache = moduleMemCaches && moduleMemCaches.get(module);
303
305
  if (memCache !== undefined) {
306
+ /** @type {BlockModulesMap} */
304
307
  const map = memCache.provide(
305
308
  "bundleChunkGraph.blockModules",
306
309
  runtime,
@@ -1162,7 +1165,9 @@ const visitModules = (
1162
1165
  * @param {BlocksWithNestedBlocks} visited visited dependencies blocks
1163
1166
  */
1164
1167
  const process = (current, visited) => {
1165
- const blockModules = getBlockModules(current, runtime);
1168
+ const blockModules =
1169
+ /** @type {BlockModulesInFlattenTuples} */
1170
+ (getBlockModules(current, runtime));
1166
1171
  for (let i = 0, len = blockModules.length; i < len; i += 3) {
1167
1172
  const activeState = /** @type {ConnectionState} */ (
1168
1173
  blockModules[i + 1]
@@ -129,7 +129,7 @@ class IdleFileCachePlugin {
129
129
  }
130
130
  );
131
131
 
132
- /** @type {Promise<any>} */
132
+ /** @type {Promise<TODO>} */
133
133
  let currentIdlePromise = resolvedPromise;
134
134
  let isIdle = false;
135
135
  let isInitialStore = true;
@@ -8,6 +8,7 @@
8
8
  const Cache = require("../Cache");
9
9
 
10
10
  /** @typedef {import("webpack-sources").Source} Source */
11
+ /** @typedef {import("../Cache").Data} Data */
11
12
  /** @typedef {import("../Cache").Etag} Etag */
12
13
  /** @typedef {import("../Compiler")} Compiler */
13
14
  /** @typedef {import("../Module")} Module */
@@ -19,7 +20,7 @@ class MemoryCachePlugin {
19
20
  * @returns {void}
20
21
  */
21
22
  apply(compiler) {
22
- /** @type {Map<string, { etag: Etag | null, data: any } | null>} */
23
+ /** @type {Map<string, { etag: Etag | null, data: Data } | null>} */
23
24
  const cache = new Map();
24
25
  compiler.cache.hooks.store.tap(
25
26
  { name: "MemoryCachePlugin", stage: Cache.STAGE_MEMORY },