webpack 5.99.7 → 5.99.9

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 (152) hide show
  1. package/README.md +0 -3
  2. package/lib/CacheFacade.js +2 -1
  3. package/lib/ChunkGraph.js +0 -1
  4. package/lib/ChunkGroup.js +13 -6
  5. package/lib/Compilation.js +22 -33
  6. package/lib/ConstPlugin.js +61 -43
  7. package/lib/ContextModule.js +1 -1
  8. package/lib/ContextModuleFactory.js +1 -2
  9. package/lib/ContextReplacementPlugin.js +2 -1
  10. package/lib/CssModule.js +0 -1
  11. package/lib/DefinePlugin.js +2 -2
  12. package/lib/DelegatedModule.js +18 -8
  13. package/lib/DelegatedModuleFactoryPlugin.js +9 -7
  14. package/lib/Dependency.js +10 -11
  15. package/lib/EvalSourceMapDevToolPlugin.js +1 -1
  16. package/lib/ExportsInfo.js +35 -16
  17. package/lib/ExternalModule.js +6 -5
  18. package/lib/FileSystemInfo.js +2 -4
  19. package/lib/LibManifestPlugin.js +2 -2
  20. package/lib/ModuleFilenameHelpers.js +8 -4
  21. package/lib/NormalModule.js +38 -19
  22. package/lib/NormalModuleFactory.js +23 -18
  23. package/lib/RuntimePlugin.js +1 -1
  24. package/lib/SourceMapDevToolPlugin.js +2 -3
  25. package/lib/WebpackOptionsApply.js +1 -4
  26. package/lib/asset/AssetGenerator.js +13 -12
  27. package/lib/asset/AssetSourceGenerator.js +7 -5
  28. package/lib/config/defaults.js +10 -6
  29. package/lib/config/normalization.js +5 -5
  30. package/lib/css/CssModulesPlugin.js +2 -2
  31. package/lib/debug/ProfilingPlugin.js +18 -21
  32. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
  33. package/lib/dependencies/ContextElementDependency.js +1 -1
  34. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  35. package/lib/dependencies/CssUrlDependency.js +1 -1
  36. package/lib/dependencies/ModuleDependency.js +1 -1
  37. package/lib/dependencies/RequireContextPlugin.js +2 -1
  38. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +3 -0
  39. package/lib/dependencies/URLDependency.js +1 -1
  40. package/lib/dependencies/WorkerPlugin.js +2 -2
  41. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +3 -3
  42. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
  43. package/lib/index.js +11 -0
  44. package/lib/javascript/JavascriptModulesPlugin.js +2 -2
  45. package/lib/javascript/JavascriptParser.js +19 -5
  46. package/lib/json/JsonModulesPlugin.js +4 -4
  47. package/lib/library/AbstractLibraryPlugin.js +1 -1
  48. package/lib/library/ModuleLibraryPlugin.js +4 -1
  49. package/lib/node/nodeConsole.js +3 -2
  50. package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
  51. package/lib/optimize/ConcatenatedModule.js +3 -1
  52. package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
  53. package/lib/optimize/RuntimeChunkPlugin.js +5 -6
  54. package/lib/optimize/SideEffectsFlagPlugin.js +12 -7
  55. package/lib/optimize/SplitChunksPlugin.js +2 -2
  56. package/lib/rules/BasicEffectRulePlugin.js +1 -2
  57. package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
  58. package/lib/rules/RuleSetCompiler.js +19 -5
  59. package/lib/rules/UseEffectRulePlugin.js +4 -6
  60. package/lib/schemes/DataUriPlugin.js +3 -1
  61. package/lib/schemes/HttpUriPlugin.js +154 -149
  62. package/lib/sharing/ProvideSharedPlugin.js +3 -1
  63. package/lib/stats/DefaultStatsPrinterPlugin.js +13 -13
  64. package/lib/util/createHash.js +3 -3
  65. package/package.json +45 -40
  66. package/schemas/WebpackOptions.check.d.ts +1 -1
  67. package/schemas/WebpackOptions.check.js +2 -2
  68. package/schemas/WebpackOptions.json +243 -24
  69. package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
  70. package/schemas/plugins/BannerPlugin.check.js +1 -1
  71. package/schemas/plugins/DllPlugin.check.d.ts +1 -1
  72. package/schemas/plugins/DllPlugin.check.js +1 -1
  73. package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
  74. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  75. package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
  76. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  77. package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
  78. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  79. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
  80. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  81. package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
  82. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  83. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
  84. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  85. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  86. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
  87. package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
  88. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
  89. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  90. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
  91. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  92. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
  93. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  94. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
  95. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  96. package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
  97. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  98. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
  99. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  100. package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
  101. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  102. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
  103. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  104. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
  105. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  106. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
  107. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  108. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
  109. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  110. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
  111. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  112. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
  113. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  114. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
  115. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  116. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
  117. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  118. package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
  119. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  120. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
  121. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  122. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
  123. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
  124. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
  125. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
  126. package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
  127. package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
  128. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  129. package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
  130. package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
  131. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  132. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
  133. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  134. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
  135. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  136. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
  137. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
  138. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
  139. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  140. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
  141. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  142. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
  143. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
  144. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
  145. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
  146. package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
  147. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  148. package/types.d.ts +468 -156
  149. package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
  150. package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
  151. package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
  152. package/schemas/plugins/JsonModulesPluginParser.json +0 -16
@@ -34,9 +34,18 @@ const RETURNS_TRUE = () => true;
34
34
 
35
35
  const CIRCULAR = Symbol("circular target");
36
36
 
37
+ /**
38
+ * @typedef {object} RestoreProvidedDataExports
39
+ * @property {ExportInfoName} name
40
+ * @property {ExportInfo["provided"]} provided
41
+ * @property {ExportInfo["canMangleProvide"]} canMangleProvide
42
+ * @property {ExportInfo["terminalBinding"]} terminalBinding
43
+ * @property {RestoreProvidedData | undefined} exportsInfo
44
+ */
45
+
37
46
  class RestoreProvidedData {
38
47
  /**
39
- * @param {TODO[]} exports exports
48
+ * @param {RestoreProvidedDataExports[]} exports exports
40
49
  * @param {ExportInfo["provided"]} otherProvided other provided
41
50
  * @param {ExportInfo["canMangleProvide"]} otherCanMangleProvide other can mangle provide
42
51
  * @param {ExportInfo["terminalBinding"]} otherTerminalBinding other terminal binding
@@ -78,7 +87,7 @@ makeSerializable(
78
87
  "RestoreProvidedData"
79
88
  );
80
89
 
81
- /** @typedef {Map<string, ExportInfo>} Exports */
90
+ /** @typedef {Map<ExportInfoName, ExportInfo>} Exports */
82
91
  /** @typedef {string | string[] | false} UsedName */
83
92
 
84
93
  class ExportsInfo {
@@ -131,6 +140,7 @@ class ExportsInfo {
131
140
  this._sortExports();
132
141
  }
133
142
  if (this._redirectTo !== undefined) {
143
+ /** @type {Exports} */
134
144
  const map = new Map(
135
145
  Array.from(this._redirectTo.orderedExports, item => [item.name, item])
136
146
  );
@@ -160,6 +170,7 @@ class ExportsInfo {
160
170
  */
161
171
  _sortExportsMap(exports) {
162
172
  if (exports.size > 1) {
173
+ /** @type {string[]} */
163
174
  const namesInOrder = [];
164
175
  for (const entry of exports.values()) {
165
176
  namesInOrder.push(entry.name);
@@ -229,7 +240,7 @@ class ExportsInfo {
229
240
  }
230
241
 
231
242
  /**
232
- * @param {string} name export name
243
+ * @param {ExportInfoName} name export name
233
244
  * @returns {ExportInfo} export info for this name
234
245
  */
235
246
  getOwnExportInfo(name) {
@@ -242,7 +253,7 @@ class ExportsInfo {
242
253
  }
243
254
 
244
255
  /**
245
- * @param {string} name export name
256
+ * @param {ExportInfoName} name export name
246
257
  * @returns {ExportInfo} export info for this name
247
258
  */
248
259
  getExportInfo(name) {
@@ -257,7 +268,7 @@ class ExportsInfo {
257
268
  }
258
269
 
259
270
  /**
260
- * @param {string} name export name
271
+ * @param {ExportInfoName} name export name
261
272
  * @returns {ExportInfo} export info for this name
262
273
  */
263
274
  getReadOnlyExportInfo(name) {
@@ -269,7 +280,7 @@ class ExportsInfo {
269
280
  }
270
281
 
271
282
  /**
272
- * @param {string[]} name export name
283
+ * @param {ExportInfoName[]} name export name
273
284
  * @returns {ExportInfo | undefined} export info for this name
274
285
  */
275
286
  getReadOnlyExportInfoRecursive(name) {
@@ -280,7 +291,7 @@ class ExportsInfo {
280
291
  }
281
292
 
282
293
  /**
283
- * @param {string[]=} name the export name
294
+ * @param {ExportInfoName[]=} name the export name
284
295
  * @returns {ExportsInfo | undefined} the nested exports info
285
296
  */
286
297
  getNestedExportsInfo(name) {
@@ -327,7 +338,8 @@ class ExportsInfo {
327
338
  if (targetKey) {
328
339
  exportInfo.setTarget(
329
340
  targetKey,
330
- /** @type {ModuleGraphConnection} */ (targetModule),
341
+ /** @type {ModuleGraphConnection} */
342
+ (targetModule),
331
343
  [exportInfo.name],
332
344
  -1
333
345
  );
@@ -552,6 +564,7 @@ class ExportsInfo {
552
564
  return true;
553
565
  }
554
566
  }
567
+ /** @type {string[]} */
555
568
  const array = [];
556
569
  if (!this._exportsAreOrdered) this._sortExports();
557
570
  for (const exportInfo of this._exports.values()) {
@@ -604,7 +617,7 @@ class ExportsInfo {
604
617
  }
605
618
 
606
619
  /**
607
- * @param {string | string[]} name the name of the export
620
+ * @param {ExportInfoName | ExportInfoName[]} name the name of the export
608
621
  * @returns {boolean | undefined | null} if the export is provided
609
622
  */
610
623
  isExportProvided(name) {
@@ -665,7 +678,7 @@ class ExportsInfo {
665
678
  }
666
679
 
667
680
  /**
668
- * @param {string | string[]} name export name
681
+ * @param {ExportInfoName | ExportInfoName[]} name export name
669
682
  * @param {RuntimeSpec} runtime check usage for this runtime only
670
683
  * @returns {UsageStateType} usage status
671
684
  */
@@ -683,7 +696,7 @@ class ExportsInfo {
683
696
  }
684
697
 
685
698
  /**
686
- * @param {string | string[]} name the export name
699
+ * @param {ExportInfoName | ExportInfoName[]} name the export name
687
700
  * @param {RuntimeSpec} runtime check usage for this runtime only
688
701
  * @returns {UsedName} the used name
689
702
  */
@@ -698,7 +711,7 @@ class ExportsInfo {
698
711
  const x = info.getUsedName(name[0], runtime);
699
712
  if (x === false) return false;
700
713
  const arr =
701
- /** @type {string[]} */
714
+ /** @type {ExportInfoName[]} */
702
715
  (x === name[0] && name.length === 1 ? name : [x]);
703
716
  if (name.length === 1) {
704
717
  return arr;
@@ -755,6 +768,7 @@ class ExportsInfo {
755
768
  const otherProvided = this._otherExportsInfo.provided;
756
769
  const otherCanMangleProvide = this._otherExportsInfo.canMangleProvide;
757
770
  const otherTerminalBinding = this._otherExportsInfo.terminalBinding;
771
+ /** @type {RestoreProvidedDataExports[]} */
758
772
  const exports = [];
759
773
  for (const exportInfo of this.orderedExports) {
760
774
  if (
@@ -827,19 +841,24 @@ class ExportsInfo {
827
841
  /** @typedef {(module: Module) => boolean} ValidTargetModuleFilter */
828
842
 
829
843
  /** @typedef {{ connection: ModuleGraphConnection, export: string[], priority: number }} TargetItem */
844
+
830
845
  /** @typedef {Map<Dependency | undefined, TargetItem>} Target */
831
846
 
847
+ /** @typedef {string} ExportInfoName */
848
+ /** @typedef {string | null} ExportInfoUsedName */
849
+ /** @typedef {boolean | null} ExportInfoProvided */
850
+
832
851
  class ExportInfo {
833
852
  /**
834
- * @param {string} name the original name of the export
853
+ * @param {ExportInfoName} name the original name of the export
835
854
  * @param {ExportInfo=} initFrom init values from this ExportInfo
836
855
  */
837
856
  constructor(name, initFrom) {
838
- /** @type {string} */
857
+ /** @type {ExportInfoName} */
839
858
  this.name = name;
840
859
  /**
841
860
  * @private
842
- * @type {string | null}
861
+ * @type {ExportInfoUsedName}
843
862
  */
844
863
  this._usedName = initFrom ? initFrom._usedName : null;
845
864
  /**
@@ -867,7 +886,7 @@ class ExportInfo {
867
886
  * false: it is not provided
868
887
  * null: only the runtime knows if it is provided
869
888
  * undefined: it was not determined if it is provided
870
- * @type {boolean | null | undefined}
889
+ * @type {ExportInfoProvided | undefined}
871
890
  */
872
891
  this.provided = initFrom ? initFrom.provided : undefined;
873
892
  /**
@@ -28,6 +28,7 @@ const propertyAccess = require("./util/propertyAccess");
28
28
  const { register } = require("./util/serialization");
29
29
 
30
30
  /** @typedef {import("webpack-sources").Source} Source */
31
+ /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
31
32
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
32
33
  /** @typedef {import("./Chunk")} Chunk */
33
34
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
@@ -58,7 +59,6 @@ const { register } = require("./util/serialization");
58
59
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
59
60
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
60
61
  /** @typedef {import("./util/Hash")} Hash */
61
- /** @typedef {typeof import("./util/Hash")} HashConstructor */
62
62
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
63
63
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
64
64
 
@@ -215,9 +215,10 @@ const getSourceForImportExternal = (
215
215
  };
216
216
 
217
217
  /**
218
- * @param {string} key key
219
- * @param {TODO | undefined} value value
220
- * @returns {undefined | string} replaced value
218
+ * @template {{ [key: string]: string }} T
219
+ * @param {keyof T} key key
220
+ * @param {T[keyof T]} value value
221
+ * @returns {undefined | T[keyof T]} replaced value
221
222
  */
222
223
  const importAssertionReplacer = (key, value) => {
223
224
  if (key === "_isLegacyAssert") {
@@ -235,7 +236,7 @@ class ModuleExternalInitFragment extends InitFragment {
235
236
  * @param {string} request import source
236
237
  * @param {string=} ident recomputed ident
237
238
  * @param {ImportDependencyMeta=} dependencyMeta the dependency meta
238
- * @param {string | HashConstructor=} hashFunction the hash function to use
239
+ * @param {HashFunction=} hashFunction the hash function to use
239
240
  */
240
241
  constructor(
241
242
  request,
@@ -24,7 +24,7 @@ const processAsyncTree = require("./util/processAsyncTree");
24
24
  /** @typedef {import("./logging/Logger").Logger} Logger */
25
25
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
26
26
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
27
- /** @typedef {typeof import("./util/Hash")} Hash */
27
+ /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
28
28
  /** @typedef {import("./util/fs").IStats} IStats */
29
29
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
30
30
  /** @typedef {import("./util/fs").PathLike} PathLike */
@@ -708,7 +708,6 @@ class SnapshotOptimization {
708
708
  };
709
709
  }
710
710
  this._map.set(path, newOptimizationEntry);
711
- continue;
712
711
  } else {
713
712
  optimizationEntries.add(optimizationEntry);
714
713
  }
@@ -742,7 +741,6 @@ class SnapshotOptimization {
742
741
  continue optimizationEntriesLabel;
743
742
  }
744
743
  nonSharedFiles.add(path);
745
- continue;
746
744
  }
747
745
  }
748
746
  if (nonSharedFiles.size === 0) {
@@ -1058,7 +1056,7 @@ class FileSystemInfo {
1058
1056
  * @param {Iterable<string | RegExp>=} options.managedPaths paths that are only managed by a package manager
1059
1057
  * @param {Iterable<string | RegExp>=} options.immutablePaths paths that are immutable
1060
1058
  * @param {Logger=} options.logger logger used to log invalid snapshots
1061
- * @param {string | Hash=} options.hashFunction the hash function to use
1059
+ * @param {HashFunction=} options.hashFunction the hash function to use
1062
1060
  */
1063
1061
  constructor(
1064
1062
  fs,
@@ -19,8 +19,8 @@ const { dirname, mkdirp } = require("./util/fs");
19
19
  /**
20
20
  * @typedef {object} ManifestModuleData
21
21
  * @property {string | number} id
22
- * @property {BuildMeta} buildMeta
23
- * @property {boolean | string[] | undefined} exports
22
+ * @property {BuildMeta=} buildMeta
23
+ * @property {boolean | string[]=} exports
24
24
  */
25
25
 
26
26
  /**
@@ -10,10 +10,11 @@ const { DEFAULTS } = require("./config/defaults");
10
10
  const createHash = require("./util/createHash");
11
11
  const memoize = require("./util/memoize");
12
12
 
13
+ /** @typedef {import("../declarations/WebpackOptions").DevtoolModuleFilenameTemplate} DevtoolModuleFilenameTemplate */
14
+ /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
13
15
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
14
16
  /** @typedef {import("./Module")} Module */
15
17
  /** @typedef {import("./RequestShortener")} RequestShortener */
16
- /** @typedef {typeof import("./util/Hash")} Hash */
17
18
 
18
19
  /** @typedef {string | RegExp | (string | RegExp)[]} Matcher */
19
20
  /** @typedef {{ test?: Matcher, include?: Matcher, exclude?: Matcher }} MatchObject */
@@ -76,7 +77,7 @@ const getBefore = (strFn, token) => () => {
76
77
  /**
77
78
  * Returns a function that returns a hash of the string
78
79
  * @param {ReturnStringCallback} strFn the function to get the string
79
- * @param {string | Hash=} hashFunction the hash function to use
80
+ * @param {HashFunction=} hashFunction the hash function to use
80
81
  * @returns {ReturnStringCallback} a function that returns the hash of the string
81
82
  */
82
83
  const getHash =
@@ -117,10 +118,13 @@ const lazyObject = obj => {
117
118
 
118
119
  const SQUARE_BRACKET_TAG_REGEXP = /\[\\*([\w-]+)\\*\]/gi;
119
120
 
121
+ /** @typedef {((context: TODO) => string)} ModuleFilenameTemplateFunction */
122
+ /** @typedef {string | ModuleFilenameTemplateFunction} ModuleFilenameTemplate */
123
+
120
124
  /**
121
125
  * @param {Module | string} module the module
122
- * @param {{ namespace?: string, moduleFilenameTemplate?: string | TODO }} options options
123
- * @param {{ requestShortener: RequestShortener, chunkGraph: ChunkGraph, hashFunction?: string | Hash }} contextInfo context info
126
+ * @param {{ namespace?: string, moduleFilenameTemplate?: ModuleFilenameTemplate }} options options
127
+ * @param {{ requestShortener: RequestShortener, chunkGraph: ChunkGraph, hashFunction?: HashFunction }} contextInfo context info
124
128
  * @returns {string} the filename
125
129
  */
126
130
  ModuleFilenameHelpers.createFilename = (
@@ -57,6 +57,7 @@ const memoize = require("./util/memoize");
57
57
  /** @typedef {import("../declarations/WebpackOptions").Mode} Mode */
58
58
  /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
59
59
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
60
+ /** @typedef {import("../declarations/WebpackOptions").NoParse} NoParse */
60
61
  /** @typedef {import("./ChunkGraph")} ChunkGraph */
61
62
  /** @typedef {import("./Compiler")} Compiler */
62
63
  /** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
@@ -80,11 +81,13 @@ const memoize = require("./util/memoize");
80
81
  /** @typedef {import("./ModuleTypeConstants").JavaScriptModuleTypes} JavaScriptModuleTypes */
81
82
  /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
82
83
  /** @typedef {import("./NormalModuleFactory").ResourceDataWithData} ResourceDataWithData */
84
+ /** @typedef {import("./NormalModuleFactory").ResourceSchemeData} ResourceSchemeData */
83
85
  /** @typedef {import("./Parser")} Parser */
84
86
  /** @typedef {import("./Parser").PreparsedAst} PreparsedAst */
85
87
  /** @typedef {import("./RequestShortener")} RequestShortener */
86
88
  /** @typedef {import("./ResolverFactory").ResolveContext} ResolveContext */
87
89
  /** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
90
+ /** @typedef {import("./ResolverFactory").ResolveRequest} ResolveRequest */
88
91
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
89
92
  /** @typedef {import("./logging/Logger").Logger} WebpackLogger */
90
93
  /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
@@ -92,7 +95,7 @@ const memoize = require("./util/memoize");
92
95
  /** @typedef {import("./util/Hash")} Hash */
93
96
  /** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
94
97
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
95
- /** @typedef {import("./util/createHash").Algorithm} Algorithm */
98
+ /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
96
99
  /** @typedef {import("./util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
97
100
  /**
98
101
  * @template T
@@ -249,7 +252,7 @@ makeSerializable(
249
252
  * @property {string} rawRequest request without resolving
250
253
  * @property {LoaderItem[]} loaders list of loaders
251
254
  * @property {string} resource path + query of the real resource
252
- * @property {TODO=} resourceResolveData resource resolve data
255
+ * @property {(ResourceSchemeData & Partial<ResolveRequest>)=} resourceResolveData resource resolve data
253
256
  * @property {string} context context directory for resolving
254
257
  * @property {string=} matchResource path + query of the matched resource (virtual)
255
258
  * @property {Parser} parser the parser used
@@ -586,12 +589,14 @@ class NormalModule extends Module {
586
589
  * @param {Compilation} compilation the compilation
587
590
  * @param {InputFileSystem} fs file system from reading
588
591
  * @param {NormalModuleCompilationHooks} hooks the hooks
589
- * @returns {import("../declarations/LoaderContext").NormalModuleLoaderContext<T>} loader context
592
+ * @returns {import("../declarations/LoaderContext").LoaderContext<T>} loader context
590
593
  */
591
594
  _createLoaderContext(resolver, options, compilation, fs, hooks) {
592
595
  const { requestShortener } = compilation.runtimeTemplate;
593
596
  const getCurrentLoaderName = () => {
594
- const currentLoader = this.getCurrentLoader(loaderContext);
597
+ const currentLoader = this.getCurrentLoader(
598
+ /** @type {LoaderContext<EXPECTED_ANY>} */ (loaderContext)
599
+ );
595
600
  if (!currentLoader) return "(not in loader scope)";
596
601
  return requestShortener.shorten(currentLoader.loader);
597
602
  };
@@ -600,13 +605,22 @@ class NormalModule extends Module {
600
605
  */
601
606
  const getResolveContext = () => ({
602
607
  fileDependencies: {
603
- add: d => /** @type {TODO} */ (loaderContext).addDependency(d)
608
+ add: d =>
609
+ /** @type {LoaderContext<EXPECTED_ANY>} */ (
610
+ loaderContext
611
+ ).addDependency(d)
604
612
  },
605
613
  contextDependencies: {
606
- add: d => /** @type {TODO} */ (loaderContext).addContextDependency(d)
614
+ add: d =>
615
+ /** @type {LoaderContext<EXPECTED_ANY>} */ (
616
+ loaderContext
617
+ ).addContextDependency(d)
607
618
  },
608
619
  missingDependencies: {
609
- add: d => /** @type {TODO} */ (loaderContext).addMissingDependency(d)
620
+ add: d =>
621
+ /** @type {LoaderContext<EXPECTED_ANY>} */ (
622
+ loaderContext
623
+ ).addMissingDependency(d)
610
624
  }
611
625
  });
612
626
  const getAbsolutify = memoize(() =>
@@ -649,13 +663,13 @@ class NormalModule extends Module {
649
663
  ? getContextifyInContext()(request)
650
664
  : getContextify()(context, request),
651
665
  /**
652
- * @param {(string | typeof import("./util/Hash"))=} type type
666
+ * @param {HashFunction=} type type
653
667
  * @returns {Hash} hash
654
668
  */
655
669
  createHash: type =>
656
670
  createHash(
657
671
  type ||
658
- /** @type {Algorithm} */
672
+ /** @type {HashFunction} */
659
673
  (compilation.outputOptions.hashFunction)
660
674
  )
661
675
  };
@@ -667,7 +681,9 @@ class NormalModule extends Module {
667
681
  * @returns {T} options
668
682
  */
669
683
  getOptions: schema => {
670
- const loader = this.getCurrentLoader(loaderContext);
684
+ const loader = this.getCurrentLoader(
685
+ /** @type {LoaderContext<EXPECTED_ANY>} */ (loaderContext)
686
+ );
671
687
 
672
688
  let { options } = /** @type {LoaderItem} */ (loader);
673
689
 
@@ -727,7 +743,9 @@ class NormalModule extends Module {
727
743
  );
728
744
  },
729
745
  getLogger: name => {
730
- const currentLoader = this.getCurrentLoader(loaderContext);
746
+ const currentLoader = this.getCurrentLoader(
747
+ /** @type {LoaderContext<EXPECTED_ANY>} */ (loaderContext)
748
+ );
731
749
  return compilation.getLogger(() =>
732
750
  [currentLoader && currentLoader.loader, name, this.identifier()]
733
751
  .filter(Boolean)
@@ -803,7 +821,7 @@ class NormalModule extends Module {
803
821
  webpack: true,
804
822
  sourceMap: Boolean(this.useSourceMap),
805
823
  mode: options.mode || "production",
806
- hashFunction: /** @type {TODO} */ (options.output.hashFunction),
824
+ hashFunction: /** @type {string} */ (options.output.hashFunction),
807
825
  hashDigest: /** @type {string} */ (options.output.hashDigest),
808
826
  hashDigestLength: /** @type {number} */ (options.output.hashDigestLength),
809
827
  hashSalt: /** @type {string} */ (options.output.hashSalt),
@@ -815,18 +833,19 @@ class NormalModule extends Module {
815
833
 
816
834
  Object.assign(loaderContext, options.loader);
817
835
 
836
+ // After `hooks.loader.call` is called, the loaderContext is typed as LoaderContext<EXPECTED_ANY>
818
837
  hooks.loader.call(
819
838
  /** @type {LoaderContext<EXPECTED_ANY>} */
820
839
  (loaderContext),
821
840
  this
822
841
  );
823
842
 
824
- return loaderContext;
843
+ return /** @type {LoaderContext<EXPECTED_ANY>} */ (loaderContext);
825
844
  }
826
845
 
827
846
  // TODO remove `loaderContext` in webpack@6
828
847
  /**
829
- * @param {TODO} loaderContext loader context
848
+ * @param {LoaderContext<EXPECTED_ANY>} loaderContext loader context
830
849
  * @param {number} index index
831
850
  * @returns {LoaderItem | null} loader
832
851
  */
@@ -997,7 +1016,7 @@ class NormalModule extends Module {
997
1016
  loaders: this.loaders,
998
1017
  context: loaderContext,
999
1018
  /**
1000
- * @param {LoaderContext<TODO>} loaderContext the loader context
1019
+ * @param {LoaderContext<EXPECTED_ANY>} loaderContext the loader context
1001
1020
  * @param {string} resourcePath the resource Path
1002
1021
  * @param {(err: Error | null, result?: string | Buffer) => void} callback callback
1003
1022
  */
@@ -1079,7 +1098,7 @@ class NormalModule extends Module {
1079
1098
  }
1080
1099
 
1081
1100
  /**
1082
- * @param {TODO} rule rule
1101
+ * @param {Exclude<NoParse, EXPECTED_ANY[]>} rule rule
1083
1102
  * @param {string} content content
1084
1103
  * @returns {boolean} result
1085
1104
  */
@@ -1097,7 +1116,7 @@ class NormalModule extends Module {
1097
1116
  }
1098
1117
 
1099
1118
  /**
1100
- * @param {TODO} noParseRule no parse rule
1119
+ * @param {undefined | NoParse} noParseRule no parse rule
1101
1120
  * @param {string} request request
1102
1121
  * @returns {boolean} check if module should not be parsed, returns "true" if the module should !not! be parsed, returns "false" if the module !must! be parsed
1103
1122
  */
@@ -1132,7 +1151,7 @@ class NormalModule extends Module {
1132
1151
  */
1133
1152
  _initBuildHash(compilation) {
1134
1153
  const hash = createHash(
1135
- /** @type {Algorithm} */
1154
+ /** @type {HashFunction} */
1136
1155
  (compilation.outputOptions.hashFunction)
1137
1156
  );
1138
1157
  if (this._source) {
@@ -1661,7 +1680,7 @@ class NormalModule extends Module {
1661
1680
 
1662
1681
  /**
1663
1682
  * @param {ObjectDeserializerContext} context context
1664
- * @returns {TODO} Module
1683
+ * @returns {NormalModule} module
1665
1684
  */
1666
1685
  static deserialize(context) {
1667
1686
  const obj = new NormalModule({
@@ -85,7 +85,15 @@ const {
85
85
  * @property {string=} context
86
86
  */
87
87
 
88
- /** @typedef {ResourceData & { data: Record<string, EXPECTED_ANY> }} ResourceDataWithData */
88
+ /**
89
+ * @typedef {object} ResourceSchemeData
90
+ * @property {string=} mimetype mime type of the resource
91
+ * @property {string=} parameters additional parameters for the resource
92
+ * @property {"base64" | false=} encoding encoding of the resource
93
+ * @property {string=} encodedContent encoded content of the resource
94
+ */
95
+
96
+ /** @typedef {ResourceData & { data: ResourceSchemeData & Partial<ResolveRequest> }} ResourceDataWithData */
89
97
 
90
98
  /**
91
99
  * @typedef {object} ParsedLoaderRequest
@@ -321,6 +329,7 @@ class NormalModuleFactory extends ModuleFactory {
321
329
  /** @type {Set<Module>} */
322
330
  this._restoredUnsafeCacheEntries = new Set();
323
331
 
332
+ /** @type {(resource: string) => import("./util/identifier").ParsedResource} */
324
333
  const cacheParseResource = parseResource.bindCache(
325
334
  associatedObjectForCache
326
335
  );
@@ -447,21 +456,22 @@ class NormalModuleFactory extends ModuleFactory {
447
456
  const matchResourceMatch = MATCH_RESOURCE_REGEX.exec(request);
448
457
  if (matchResourceMatch) {
449
458
  let matchResource = matchResourceMatch[1];
459
+ // Check if matchResource starts with ./ or ../
450
460
  if (matchResource.charCodeAt(0) === 46) {
451
- // 46 === ".", 47 === "/"
461
+ // 46 is "."
452
462
  const secondChar = matchResource.charCodeAt(1);
453
463
  if (
454
- secondChar === 47 ||
455
- (secondChar === 46 && matchResource.charCodeAt(2) === 47)
464
+ secondChar === 47 || // 47 is "/"
465
+ (secondChar === 46 && matchResource.charCodeAt(2) === 47) // "../"
456
466
  ) {
457
- // if matchResources startsWith ../ or ./
467
+ // Resolve relative path against context
458
468
  matchResource = join(this.fs, context, matchResource);
459
469
  }
460
470
  }
461
471
 
462
472
  matchResourceData = {
463
- resource: matchResource,
464
- .../** @type {TODO} */ (cacheParseResource(matchResource))
473
+ ...cacheParseResource(matchResource),
474
+ resource: matchResource
465
475
  };
466
476
  requestWithoutMatchResource = request.slice(
467
477
  matchResourceMatch[0].length
@@ -546,11 +556,7 @@ class NormalModuleFactory extends ModuleFactory {
546
556
 
547
557
  if (!resourceData) {
548
558
  // ignored
549
- return callback(
550
- null,
551
- /** @type {TODO} */
552
- (dependencies[0].createIgnoredModule(context))
553
- );
559
+ return callback(null, dependencies[0].createIgnoredModule(context));
554
560
  }
555
561
 
556
562
  const userRequest =
@@ -759,9 +765,9 @@ class NormalModuleFactory extends ModuleFactory {
759
765
  const defaultResolve = context => {
760
766
  if (/^($|\?)/.test(unresolvedResource)) {
761
767
  resourceData = {
768
+ ...cacheParseResource(unresolvedResource),
762
769
  resource: unresolvedResource,
763
- data: {},
764
- .../** @type {TODO} */ (cacheParseResource(unresolvedResource))
770
+ data: {}
765
771
  };
766
772
  continueCallback();
767
773
  }
@@ -791,12 +797,11 @@ class NormalModuleFactory extends ModuleFactory {
791
797
  /** @type {string} */
792
798
  (_resolvedResource);
793
799
  resourceData = {
800
+ ...cacheParseResource(resolvedResource),
794
801
  resource: resolvedResource,
795
802
  data:
796
803
  /** @type {ResolveRequest} */
797
- (resolvedResourceResolveData),
798
- .../** @type {TODO} */
799
- (cacheParseResource(resolvedResource))
804
+ (resolvedResourceResolveData)
800
805
  };
801
806
  }
802
807
  continueCallback();
@@ -1228,7 +1233,7 @@ If changing the source code is not an option there is also a resolve options cal
1228
1233
  }
1229
1234
  );
1230
1235
  },
1231
- /** @type {Callback<TODO>} */ (callback)
1236
+ /** @type {Callback<(LoaderItem | undefined)[]>} */ (callback)
1232
1237
  );
1233
1238
  }
1234
1239
 
@@ -292,7 +292,7 @@ class RuntimePlugin {
292
292
  ? compilation.outputOptions.filename
293
293
  : compilation.outputOptions.chunkFilename)
294
294
  ),
295
- false
295
+ set.has(RuntimeGlobals.hmrDownloadUpdateHandlers)
296
296
  )
297
297
  );
298
298
  return true;
@@ -19,6 +19,7 @@ const { makePathsAbsolute } = require("./util/identifier");
19
19
 
20
20
  /** @typedef {import("webpack-sources").MapOptions} MapOptions */
21
21
  /** @typedef {import("webpack-sources").Source} Source */
22
+ /** @typedef {import("../declarations/WebpackOptions").HashFunction} HashFunction */
22
23
  /** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
23
24
  /** @typedef {import("./Cache").Etag} Etag */
24
25
  /** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */
@@ -29,8 +30,6 @@ const { makePathsAbsolute } = require("./util/identifier");
29
30
  /** @typedef {import("./Module")} Module */
30
31
  /** @typedef {import("./NormalModule").SourceMap} SourceMap */
31
32
  /** @typedef {import("./TemplatedPathPlugin").TemplatePath} TemplatePath */
32
- /** @typedef {import("./util/Hash")} Hash */
33
- /** @typedef {import("./util/createHash").Algorithm} Algorithm */
34
33
  /** @typedef {import("./util/fs").OutputFileSystem} OutputFileSystem */
35
34
 
36
35
  const validate = createSchemaValidation(
@@ -489,7 +488,7 @@ class SourceMapDevToolPlugin {
489
488
  (
490
489
  usesContentHash &&
491
490
  createHash(
492
- /** @type {Algorithm} */
491
+ /** @type {HashFunction} */
493
492
  (compilation.outputOptions.hashFunction)
494
493
  )
495
494
  .update(sourceMapString)
@@ -504,10 +504,7 @@ class WebpackOptionsApply extends OptionsApply {
504
504
  }
505
505
  if (options.optimization.runtimeChunk) {
506
506
  const RuntimeChunkPlugin = require("./optimize/RuntimeChunkPlugin");
507
- new RuntimeChunkPlugin(
508
- /** @type {{ name?: (entrypoint: { name: string }) => string }} */
509
- (options.optimization.runtimeChunk)
510
- ).apply(compiler);
507
+ new RuntimeChunkPlugin(options.optimization.runtimeChunk).apply(compiler);
511
508
  }
512
509
  if (!options.optimization.emitOnErrors) {
513
510
  const NoEmitOnErrorsPlugin = require("./NoEmitOnErrorsPlugin");