webpack 5.99.7 → 5.99.8

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 (132) hide show
  1. package/lib/Compilation.js +12 -7
  2. package/lib/ContextModule.js +1 -1
  3. package/lib/ContextModuleFactory.js +1 -2
  4. package/lib/ContextReplacementPlugin.js +2 -1
  5. package/lib/DefinePlugin.js +2 -2
  6. package/lib/DelegatedModule.js +18 -8
  7. package/lib/DelegatedModuleFactoryPlugin.js +9 -7
  8. package/lib/EvalSourceMapDevToolPlugin.js +1 -1
  9. package/lib/ExportsInfo.js +35 -16
  10. package/lib/ExternalModule.js +6 -5
  11. package/lib/FileSystemInfo.js +2 -2
  12. package/lib/LibManifestPlugin.js +2 -2
  13. package/lib/ModuleFilenameHelpers.js +8 -4
  14. package/lib/NormalModule.js +8 -7
  15. package/lib/SourceMapDevToolPlugin.js +2 -3
  16. package/lib/WebpackOptionsApply.js +1 -4
  17. package/lib/asset/AssetGenerator.js +2 -2
  18. package/lib/config/defaults.js +10 -6
  19. package/lib/config/normalization.js +5 -5
  20. package/lib/css/CssModulesPlugin.js +2 -2
  21. package/lib/debug/ProfilingPlugin.js +18 -21
  22. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
  23. package/lib/dependencies/ContextElementDependency.js +1 -1
  24. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  25. package/lib/dependencies/RequireContextPlugin.js +2 -1
  26. package/lib/dependencies/WorkerPlugin.js +2 -2
  27. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
  28. package/lib/index.js +11 -0
  29. package/lib/javascript/JavascriptModulesPlugin.js +2 -2
  30. package/lib/json/JsonModulesPlugin.js +4 -4
  31. package/lib/library/AbstractLibraryPlugin.js +1 -1
  32. package/lib/node/nodeConsole.js +3 -2
  33. package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
  34. package/lib/optimize/ConcatenatedModule.js +3 -1
  35. package/lib/optimize/ModuleConcatenationPlugin.js +2 -2
  36. package/lib/optimize/RuntimeChunkPlugin.js +5 -6
  37. package/lib/optimize/SideEffectsFlagPlugin.js +9 -6
  38. package/lib/optimize/SplitChunksPlugin.js +2 -2
  39. package/lib/rules/BasicEffectRulePlugin.js +1 -2
  40. package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
  41. package/lib/rules/RuleSetCompiler.js +19 -5
  42. package/lib/rules/UseEffectRulePlugin.js +4 -6
  43. package/lib/schemes/HttpUriPlugin.js +154 -149
  44. package/lib/util/createHash.js +3 -3
  45. package/package.json +33 -29
  46. package/schemas/WebpackOptions.check.d.ts +1 -1
  47. package/schemas/WebpackOptions.check.js +2 -2
  48. package/schemas/WebpackOptions.json +243 -24
  49. package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
  50. package/schemas/plugins/BannerPlugin.check.js +1 -1
  51. package/schemas/plugins/DllPlugin.check.d.ts +1 -1
  52. package/schemas/plugins/DllPlugin.check.js +1 -1
  53. package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
  54. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  55. package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
  56. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  57. package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
  58. package/schemas/plugins/IgnorePlugin.check.js +1 -1
  59. package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
  60. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  61. package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
  62. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  63. package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
  64. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  65. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  66. package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
  67. package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
  68. package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
  69. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  70. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
  71. package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
  72. package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
  73. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  74. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
  75. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  76. package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
  77. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  78. package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
  79. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  80. package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
  81. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  82. package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
  83. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  84. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
  85. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  86. package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
  87. package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
  88. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
  89. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  90. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
  91. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  92. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
  93. package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
  94. package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
  95. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  96. package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
  97. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  98. package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
  99. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  100. package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
  101. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  102. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
  103. package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
  104. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
  105. package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
  106. package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
  107. package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
  108. package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
  109. package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
  110. package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
  111. package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
  112. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
  113. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  114. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
  115. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  116. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
  117. package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
  118. package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
  119. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  120. package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
  121. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  122. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
  123. package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
  124. package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
  125. package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
  126. package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
  127. package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
  128. package/types.d.ts +437 -150
  129. package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
  130. package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
  131. package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
  132. package/schemas/plugins/JsonModulesPluginParser.json +0 -16
@@ -33,6 +33,7 @@ const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
33
33
  /** @typedef {import("../../declarations/WebpackOptions").AssetModuleFilename} AssetModuleFilename */
34
34
  /** @typedef {import("../../declarations/WebpackOptions").AssetModuleOutputPath} AssetModuleOutputPath */
35
35
  /** @typedef {import("../../declarations/WebpackOptions").AssetResourceGeneratorOptions} AssetResourceGeneratorOptions */
36
+ /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
36
37
  /** @typedef {import("../../declarations/WebpackOptions").RawPublicPath} RawPublicPath */
37
38
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
38
39
  /** @typedef {import("../Compilation")} Compilation */
@@ -51,7 +52,6 @@ const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
51
52
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
52
53
  /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
53
54
  /** @typedef {import("../util/Hash")} Hash */
54
- /** @typedef {import("../util/createHash").Algorithm} Algorithm */
55
55
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
56
56
 
57
57
  /**
@@ -232,7 +232,7 @@ class AssetGenerator extends Generator {
232
232
  */
233
233
  static getFullContentHash(module, runtimeTemplate) {
234
234
  const hash = createHash(
235
- /** @type {Algorithm} */
235
+ /** @type {HashFunction} */
236
236
  (runtimeTemplate.outputOptions.hashFunction)
237
237
  );
238
238
 
@@ -648,11 +648,14 @@ const applyModuleDefaults = (
648
648
  "unsafeCache",
649
649
  /**
650
650
  * @param {Module} module module
651
- * @returns {boolean | null | string} true, if we want to cache the module
651
+ * @returns {boolean} true, if we want to cache the module
652
652
  */
653
653
  module => {
654
654
  const name = module.nameForCondition();
655
- return name && NODE_MODULES_REGEXP.test(name);
655
+ if (!name) {
656
+ return false;
657
+ }
658
+ return NODE_MODULES_REGEXP.test(name);
656
659
  }
657
660
  );
658
661
  } else {
@@ -683,7 +686,8 @@ const applyModuleDefaults = (
683
686
  F(module.parser, "javascript", () => ({}));
684
687
  F(module.parser, JSON_MODULE_TYPE, () => ({}));
685
688
  D(
686
- module.parser[JSON_MODULE_TYPE],
689
+ /** @type {NonNullable<ParserOptionsByModuleTypeKnown[JSON_MODULE_TYPE]>} */
690
+ (module.parser[JSON_MODULE_TYPE]),
687
691
  "exportsDepth",
688
692
  mode === "development" ? 1 : Infinity
689
693
  );
@@ -1551,7 +1555,7 @@ const applyOptimizationDefaults = (
1551
1555
  passes: 2
1552
1556
  }
1553
1557
  }
1554
- }).apply(/** @type {TODO} */ (compiler));
1558
+ }).apply(/** @type {EXPECTED_ANY} */ (compiler));
1555
1559
  }
1556
1560
  }
1557
1561
  ]);
@@ -1726,8 +1730,8 @@ const getResolveLoaderDefaults = ({ cache }) => {
1726
1730
  const applyInfrastructureLoggingDefaults = infrastructureLogging => {
1727
1731
  F(infrastructureLogging, "stream", () => process.stderr);
1728
1732
  const tty =
1729
- /** @type {EXPECTED_ANY} */ (infrastructureLogging.stream).isTTY &&
1730
- process.env.TERM !== "dumb";
1733
+ /** @type {NonNullable<InfrastructureLogging["stream"]>} */
1734
+ (infrastructureLogging.stream).isTTY && process.env.TERM !== "dumb";
1731
1735
  D(infrastructureLogging, "level", "info");
1732
1736
  D(infrastructureLogging, "debug", false);
1733
1737
  D(infrastructureLogging, "colors", tty);
@@ -549,16 +549,16 @@ const getNormalizedOptimizationRuntimeChunk = runtimeChunk => {
549
549
  }
550
550
  if (runtimeChunk === true || runtimeChunk === "multiple") {
551
551
  return {
552
- /**
553
- * @param {Entrypoint} entrypoint entrypoint
554
- * @returns {string} runtime chunk name
555
- */
556
552
  name: entrypoint => `runtime~${entrypoint.name}`
557
553
  };
558
554
  }
559
555
  const { name } = runtimeChunk;
560
556
  return {
561
- name: typeof name === "function" ? name : () => name
557
+ name:
558
+ typeof name === "function"
559
+ ? /** @type {Exclude<OptimizationRuntimeChunkNormalized, false>["name"]} */
560
+ (name)
561
+ : () => /** @type {string} */ (name)
562
562
  };
563
563
  };
564
564
 
@@ -48,6 +48,7 @@ const CssGenerator = require("./CssGenerator");
48
48
  const CssParser = require("./CssParser");
49
49
 
50
50
  /** @typedef {import("webpack-sources").Source} Source */
51
+ /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
51
52
  /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
52
53
  /** @typedef {import("../Chunk")} Chunk */
53
54
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
@@ -60,7 +61,6 @@ const CssParser = require("./CssParser");
60
61
  /** @typedef {import("../Template").RuntimeTemplate} RuntimeTemplate */
61
62
  /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
62
63
  /** @typedef {import("../util/Hash")} Hash */
63
- /** @typedef {import("../util/createHash").Algorithm} Algorithm */
64
64
  /** @typedef {import("../util/memoize")} Memoize */
65
65
 
66
66
  /**
@@ -444,7 +444,7 @@ class CssModulesPlugin {
444
444
  hashFunction
445
445
  }
446
446
  } = compilation;
447
- const hash = createHash(/** @type {Algorithm} */ (hashFunction));
447
+ const hash = createHash(/** @type {HashFunction} */ (hashFunction));
448
448
  if (hashSalt) hash.update(hashSalt);
449
449
  hooks.chunkHash.call(chunk, hash, {
450
450
  chunkGraph,
@@ -14,6 +14,7 @@ const {
14
14
  const createSchemaValidation = require("../util/create-schema-validation");
15
15
  const { dirname, mkdirpSync } = require("../util/fs");
16
16
 
17
+ /** @typedef {import("inspector").Session} Session */
17
18
  /** @typedef {import("tapable").FullTap} FullTap */
18
19
  /** @typedef {import("../../declarations/plugins/debug/ProfilingPlugin").ProfilingPluginOptions} ProfilingPluginOptions */
19
20
  /** @typedef {import("../Compilation")} Compilation */
@@ -25,8 +26,6 @@ const { dirname, mkdirpSync } = require("../util/fs");
25
26
  /** @typedef {import("../ResolverFactory")} ResolverFactory */
26
27
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
27
28
 
28
- /** @typedef {TODO} Inspector */
29
-
30
29
  const validate = createSchemaValidation(
31
30
  require("../../schemas/plugins/debug/ProfilingPlugin.check.js"),
32
31
  () => require("../../schemas/plugins/debug/ProfilingPlugin.json"),
@@ -36,6 +35,8 @@ const validate = createSchemaValidation(
36
35
  }
37
36
  );
38
37
 
38
+ /** @typedef {{ Session: typeof import("inspector").Session }} Inspector */
39
+
39
40
  /** @type {Inspector | undefined} */
40
41
  let inspector;
41
42
 
@@ -52,6 +53,7 @@ class Profiler {
52
53
  * @param {Inspector} inspector inspector
53
54
  */
54
55
  constructor(inspector) {
56
+ /** @type {undefined | Session} */
55
57
  this.session = undefined;
56
58
  this.inspector = inspector;
57
59
  this._startTime = 0;
@@ -67,8 +69,9 @@ class Profiler {
67
69
  }
68
70
 
69
71
  try {
70
- this.session = new inspector.Session();
71
- this.session.connect();
72
+ this.session = new /** @type {Inspector} */ (inspector).Session();
73
+ /** @type {Session} */
74
+ (this.session).connect();
72
75
  } catch (_) {
73
76
  this.session = undefined;
74
77
  return Promise.resolve();
@@ -88,27 +91,20 @@ class Profiler {
88
91
 
89
92
  /**
90
93
  * @param {string} method method name
91
- * @param {Record<string, EXPECTED_ANY>=} params params
92
- * @returns {Promise<TODO>} Promise for the result
94
+ * @param {EXPECTED_OBJECT=} params params
95
+ * @returns {Promise<EXPECTED_ANY | void>} Promise for the result
93
96
  */
94
97
  sendCommand(method, params) {
95
98
  if (this.hasSession()) {
96
99
  return new Promise((res, rej) => {
97
- this.session.post(
98
- method,
99
- params,
100
- /**
101
- * @param {Error | null} err error
102
- * @param {object} params params
103
- */
104
- (err, params) => {
105
- if (err !== null) {
106
- rej(err);
107
- } else {
108
- res(params);
109
- }
100
+ /** @type {Session} */
101
+ (this.session).post(method, params, (err, params) => {
102
+ if (err !== null) {
103
+ rej(err);
104
+ } else {
105
+ res(params);
110
106
  }
111
- );
107
+ });
112
108
  });
113
109
  }
114
110
  return Promise.resolve();
@@ -116,7 +112,8 @@ class Profiler {
116
112
 
117
113
  destroy() {
118
114
  if (this.hasSession()) {
119
- this.session.disconnect();
115
+ /** @type {Session} */
116
+ (this.session).disconnect();
120
117
  }
121
118
 
122
119
  return Promise.resolve();
@@ -204,7 +204,7 @@ class CommonJsImportsParserPlugin {
204
204
  {
205
205
  request: /** @type {string} */ (options.unknownContextRequest),
206
206
  recursive: /** @type {boolean} */ (options.unknownContextRecursive),
207
- regExp: /** @type {TODO} */ (options.unknownContextRegExp),
207
+ regExp: /** @type {RegExp} */ (options.unknownContextRegExp),
208
208
  mode: "sync"
209
209
  },
210
210
  /** @type {Range} */ (expr.range),
@@ -22,7 +22,7 @@ const ModuleDependency = require("./ModuleDependency");
22
22
  class ContextElementDependency extends ModuleDependency {
23
23
  /**
24
24
  * @param {string} request request
25
- * @param {string|undefined} userRequest user request
25
+ * @param {string | undefined} userRequest user request
26
26
  * @param {string | undefined} typePrefix type prefix
27
27
  * @param {string} category category
28
28
  * @param {(string[][] | null)=} referencedExports referenced exports
@@ -15,6 +15,7 @@ const NullDependency = require("./NullDependency");
15
15
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
16
16
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
17
17
  /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
18
+ /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
18
19
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
19
20
  /** @typedef {import("../CssModule")} CssModule */
20
21
  /** @typedef {import("../Dependency")} Dependency */
@@ -29,7 +30,6 @@ const NullDependency = require("./NullDependency");
29
30
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
30
31
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
31
32
  /** @typedef {import("../util/Hash")} Hash */
32
- /** @typedef {import("../util/createHash").Algorithm} Algorithm */
33
33
 
34
34
  const getCssParser = memoize(() => require("../css/CssParser"));
35
35
 
@@ -53,7 +53,7 @@ const getLocalIdent = (local, module, chunkGraph, runtimeTemplate) => {
53
53
  );
54
54
  const { hashFunction, hashDigest, hashDigestLength, hashSalt, uniqueName } =
55
55
  runtimeTemplate.outputOptions;
56
- const hash = createHash(/** @type {Algorithm} */ (hashFunction));
56
+ const hash = createHash(/** @type {HashFunction} */ (hashFunction));
57
57
 
58
58
  if (hashSalt) {
59
59
  hash.update(hashSalt);
@@ -80,7 +80,8 @@ class RequireContextPlugin {
80
80
  cachedSetProperty(
81
81
  options.resolveOptions || EMPTY_RESOLVE_OPTIONS,
82
82
  "dependencyType",
83
- /** @type {string} */ (options.category)
83
+ /** @type {string} */
84
+ (options.category)
84
85
  )
85
86
  ).options;
86
87
 
@@ -34,6 +34,7 @@ const WorkerDependency = require("./WorkerDependency");
34
34
  /** @typedef {import("estree").Property} Property */
35
35
  /** @typedef {import("estree").SpreadElement} SpreadElement */
36
36
  /** @typedef {import("../../declarations/WebpackOptions").ChunkLoading} ChunkLoading */
37
+ /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
37
38
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
38
39
  /** @typedef {import("../../declarations/WebpackOptions").OutputModule} OutputModule */
39
40
  /** @typedef {import("../../declarations/WebpackOptions").WasmLoading} WasmLoading */
@@ -47,7 +48,6 @@ const WorkerDependency = require("./WorkerDependency");
47
48
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
48
49
  /** @typedef {import("../javascript/JavascriptParser")} Parser */
49
50
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
50
- /** @typedef {import("../util/createHash").Algorithm} Algorithm */
51
51
  /** @typedef {import("./HarmonyImportDependencyParserPlugin").HarmonySettings} HarmonySettings */
52
52
 
53
53
  /**
@@ -376,7 +376,7 @@ class WorkerPlugin {
376
376
  parser.state.module.identifier()
377
377
  )}|${i}`;
378
378
  const hash = createHash(
379
- /** @type {Algorithm} */
379
+ /** @type {HashFunction} */
380
380
  (compilation.outputOptions.hashFunction)
381
381
  );
382
382
  hash.update(name);
@@ -117,7 +117,6 @@ module.exports = function () {
117
117
  for (var moduleId in currentUpdate) {
118
118
  if ($hasOwnProperty$(currentUpdate, moduleId)) {
119
119
  var newModuleFactory = currentUpdate[moduleId];
120
- /** @type {TODO} */
121
120
  var result = newModuleFactory
122
121
  ? getAffectedModuleEffects(moduleId)
123
122
  : {
package/lib/index.js CHANGED
@@ -11,20 +11,30 @@ const memoize = require("./util/memoize");
11
11
  /** @typedef {import("../declarations/WebpackOptions").Entry} Entry */
12
12
  /** @typedef {import("../declarations/WebpackOptions").EntryNormalized} EntryNormalized */
13
13
  /** @typedef {import("../declarations/WebpackOptions").EntryObject} EntryObject */
14
+ /** @typedef {import("../declarations/WebpackOptions").ExternalItem} ExternalItem */
15
+ /** @typedef {import("../declarations/WebpackOptions").ExternalItemFunction} ExternalItemFunction */
16
+ /** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionCallback} ExternalItemFunctionCallback */
14
17
  /** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionData} ExternalItemFunctionData */
18
+ /** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionDataGetResolve} ExternalItemFunctionDataGetResolve */
19
+ /** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionDataGetResolveCallbackResult} ExternalItemFunctionDataGetResolveCallbackResult */
20
+ /** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionDataGetResolveResult} ExternalItemFunctionDataGetResolveResult */
21
+ /** @typedef {import("../declarations/WebpackOptions").ExternalItemFunctionPromise} ExternalItemFunctionPromise */
15
22
  /** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectKnown} ExternalItemObjectKnown */
16
23
  /** @typedef {import("../declarations/WebpackOptions").ExternalItemObjectUnknown} ExternalItemObjectUnknown */
17
24
  /** @typedef {import("../declarations/WebpackOptions").ExternalItemValue} ExternalItemValue */
18
25
  /** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
19
26
  /** @typedef {import("../declarations/WebpackOptions").FileCacheOptions} FileCacheOptions */
27
+ /** @typedef {import("../declarations/WebpackOptions").GeneratorOptionsByModuleTypeKnown} GeneratorOptionsByModuleTypeKnown */
20
28
  /** @typedef {import("../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
21
29
  /** @typedef {import("../declarations/WebpackOptions").MemoryCacheOptions} MemoryCacheOptions */
22
30
  /** @typedef {import("../declarations/WebpackOptions").ModuleOptions} ModuleOptions */
31
+ /** @typedef {import("../declarations/WebpackOptions").ParserOptionsByModuleTypeKnown} ParserOptionsByModuleTypeKnown */
23
32
  /** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
24
33
  /** @typedef {import("../declarations/WebpackOptions").RuleSetCondition} RuleSetCondition */
25
34
  /** @typedef {import("../declarations/WebpackOptions").RuleSetConditionAbsolute} RuleSetConditionAbsolute */
26
35
  /** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
27
36
  /** @typedef {import("../declarations/WebpackOptions").RuleSetUse} RuleSetUse */
37
+ /** @typedef {import("../declarations/WebpackOptions").RuleSetUseFunction} RuleSetUseFunction */
28
38
  /** @typedef {import("../declarations/WebpackOptions").RuleSetUseItem} RuleSetUseItem */
29
39
  /** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */
30
40
  /** @typedef {import("../declarations/WebpackOptions").WebpackOptions} Configuration */
@@ -37,6 +47,7 @@ const memoize = require("./util/memoize");
37
47
  /** @typedef {import("./Compilation").EntryOptions} EntryOptions */
38
48
  /** @typedef {import("./Compilation").PathData} PathData */
39
49
  /** @typedef {import("./Compiler").AssetEmittedInfo} AssetEmittedInfo */
50
+ /** @typedef {import("./Entrypoint")} Entrypoint */
40
51
  /** @typedef {import("./MultiCompiler").MultiCompilerOptions} MultiCompilerOptions */
41
52
  /** @typedef {import("./MultiStats")} MultiStats */
42
53
  /** @typedef {import("./NormalModuleFactory").ResolveData} ResolveData */
@@ -52,6 +52,7 @@ const JavascriptParser = require("./JavascriptParser");
52
52
  /** @typedef {import("eslint-scope").Variable} Variable */
53
53
  /** @typedef {import("estree").Program} Program */
54
54
  /** @typedef {import("webpack-sources").Source} Source */
55
+ /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
55
56
  /** @typedef {import("../../declarations/WebpackOptions").Output} OutputOptions */
56
57
  /** @typedef {import("../Chunk")} Chunk */
57
58
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
@@ -69,7 +70,6 @@ const JavascriptParser = require("./JavascriptParser");
69
70
  /** @typedef {import("../WebpackError")} WebpackError */
70
71
  /** @typedef {import("../javascript/JavascriptParser").Range} Range */
71
72
  /** @typedef {import("../util/Hash")} Hash */
72
- /** @typedef {import("../util/createHash").Algorithm} Algorithm */
73
73
 
74
74
  /**
75
75
  * @param {Chunk} chunk a chunk
@@ -429,7 +429,7 @@ class JavascriptModulesPlugin {
429
429
  hashFunction
430
430
  }
431
431
  } = compilation;
432
- const hash = createHash(/** @type {Algorithm} */ (hashFunction));
432
+ const hash = createHash(/** @type {HashFunction} */ (hashFunction));
433
433
  if (hashSalt) hash.update(hashSalt);
434
434
  if (chunk.hasRuntime()) {
435
435
  this.updateHashWithBootstrap(
@@ -16,8 +16,8 @@ const JsonParser = require("./JsonParser");
16
16
  /** @typedef {import("../util/fs").JsonValue} JsonValue */
17
17
 
18
18
  const validate = createSchemaValidation(
19
- require("../../schemas/plugins/JsonModulesPluginParser.check.js"),
20
- () => require("../../schemas/plugins/JsonModulesPluginParser.json"),
19
+ require("../../schemas/plugins/json/JsonModulesPluginParser.check.js"),
20
+ () => require("../../schemas/plugins/json/JsonModulesPluginParser.json"),
21
21
  {
22
22
  name: "Json Modules Plugin",
23
23
  baseDataPath: "parser"
@@ -25,8 +25,8 @@ const validate = createSchemaValidation(
25
25
  );
26
26
 
27
27
  const validateGenerator = createSchemaValidation(
28
- require("../../schemas/plugins/JsonModulesPluginGenerator.check.js"),
29
- () => require("../../schemas/plugins/JsonModulesPluginGenerator.json"),
28
+ require("../../schemas/plugins/json/JsonModulesPluginGenerator.check.js"),
29
+ () => require("../../schemas/plugins/json/JsonModulesPluginGenerator.json"),
30
30
  {
31
31
  name: "Json Modules Plugin",
32
32
  baseDataPath: "generator"
@@ -93,7 +93,7 @@ class AbstractLibraryPlugin {
93
93
 
94
94
  /**
95
95
  * @param {Chunk} chunk chunk
96
- * @returns {TODO} options for the chunk
96
+ * @returns {T | false} options for the chunk
97
97
  */
98
98
  const getOptionsForChunk = chunk => {
99
99
  if (compilation.chunkGraph.getNumberOfEntryModules(chunk) === 0)
@@ -8,6 +8,7 @@
8
8
  const util = require("util");
9
9
  const truncateArgs = require("../logging/truncateArgs");
10
10
 
11
+ /** @typedef {import("../../declarations/WebpackOptions").InfrastructureLogging} InfrastructureLogging */
11
12
  /** @typedef {import("../logging/createConsoleLogger").LoggerConsole} LoggerConsole */
12
13
 
13
14
  /* eslint-disable no-console */
@@ -16,7 +17,7 @@ const truncateArgs = require("../logging/truncateArgs");
16
17
  * @param {object} options options
17
18
  * @param {boolean=} options.colors colors
18
19
  * @param {boolean=} options.appendOnly append only
19
- * @param {NodeJS.WritableStream} options.stream stream
20
+ * @param {NonNullable<InfrastructureLogging["stream"]>} options.stream stream
20
21
  * @returns {LoggerConsole} logger function
21
22
  */
22
23
  module.exports = ({ colors, appendOnly, stream }) => {
@@ -57,7 +58,7 @@ module.exports = ({ colors, appendOnly, stream }) => {
57
58
 
58
59
  const writeStatusMessage = () => {
59
60
  if (!currentStatusMessage) return;
60
- const l = /** @type {TODO} */ (stream).columns || 40;
61
+ const l = stream.columns || 40;
61
62
  const args = truncateArgs(currentStatusMessage, l - 1);
62
63
  const str = args.join(" ");
63
64
  const coloredStr = `\u001B[1m${str}\u001B[39m\u001B[22m`;
@@ -195,7 +195,7 @@ class AggressiveSplittingPlugin {
195
195
  moveModuleBetween(chunkGraph, chunk, newChunk)(module);
196
196
  }
197
197
  chunk.split(newChunk);
198
- chunk.name = /** @type {TODO} */ (null);
198
+ chunk.name = null;
199
199
  }
200
200
  fromAggressiveSplittingSet.add(newChunk);
201
201
  chunkSplitDataMap.set(newChunk, splitData);
@@ -1739,7 +1739,9 @@ ${defineGetters}`
1739
1739
  sourceType: "module"
1740
1740
  });
1741
1741
  } catch (_err) {
1742
- const err = /** @type {TODO} */ (_err);
1742
+ const err =
1743
+ /** @type {Error & { loc?: { line: number, column: number } }} */
1744
+ (_err);
1743
1745
  if (
1744
1746
  err.loc &&
1745
1747
  typeof err.loc === "object" &&
@@ -398,9 +398,9 @@ class ModuleConcatenationPlugin {
398
398
  newModule.build(
399
399
  compiler.options,
400
400
  compilation,
401
- /** @type {TODO} */
401
+ /** @type {EXPECTED_ANY} */
402
402
  (null),
403
- /** @type {TODO} */
403
+ /** @type {EXPECTED_ANY} */
404
404
  (null),
405
405
  err => {
406
406
  if (err) {
@@ -11,16 +11,15 @@
11
11
 
12
12
  const PLUGIN_NAME = "RuntimeChunkPlugin";
13
13
 
14
+ /** @typedef {(entrypoint: { name: string }) => string} RuntimeChunkFunction */
15
+
14
16
  class RuntimeChunkPlugin {
15
17
  /**
16
- * @param {{ name?: (entrypoint: { name: string }) => string }} options options
18
+ * @param {{ name?: RuntimeChunkFunction }=} options options
17
19
  */
18
20
  constructor(options) {
19
21
  this.options = {
20
- /**
21
- * @param {Entrypoint} entrypoint entrypoint name
22
- * @returns {string} runtime chunk name
23
- */
22
+ /** @type {RuntimeChunkFunction} */
24
23
  name: entrypoint => `runtime~${entrypoint.name}`,
25
24
  ...options
26
25
  };
@@ -41,7 +40,7 @@ class RuntimeChunkPlugin {
41
40
  if (data.options.runtime === undefined && !data.options.dependOn) {
42
41
  // Determine runtime chunk name
43
42
  let name =
44
- /** @type {string | ((entrypoint: { name: string }) => string)} */
43
+ /** @type {string | RuntimeChunkFunction} */
45
44
  (this.options.name);
46
45
  if (typeof name === "function") {
47
46
  name = name({ name: entryName });
@@ -145,7 +145,8 @@ class SideEffectsFlagPlugin {
145
145
  if (
146
146
  !parser.isPure(
147
147
  statement.expression,
148
- /** @type {Range} */ (statement.range)[0]
148
+ /** @type {Range} */
149
+ (statement.range)[0]
149
150
  )
150
151
  ) {
151
152
  sideEffectsStatement = statement;
@@ -157,7 +158,8 @@ class SideEffectsFlagPlugin {
157
158
  if (
158
159
  !parser.isPure(
159
160
  statement.test,
160
- /** @type {Range} */ (statement.range)[0]
161
+ /** @type {Range} */
162
+ (statement.range)[0]
161
163
  )
162
164
  ) {
163
165
  sideEffectsStatement = statement;
@@ -193,7 +195,8 @@ class SideEffectsFlagPlugin {
193
195
  if (
194
196
  !parser.isPure(
195
197
  statement.discriminant,
196
- /** @type {Range} */ (statement.range)[0]
198
+ /** @type {Range} */
199
+ (statement.range)[0]
197
200
  )
198
201
  ) {
199
202
  sideEffectsStatement = statement;
@@ -216,9 +219,9 @@ class SideEffectsFlagPlugin {
216
219
  case "ExportDefaultDeclaration":
217
220
  if (
218
221
  !parser.isPure(
219
- /** @type {TODO} */
220
- (statement.declaration),
221
- /** @type {Range} */ (statement.range)[0]
222
+ statement.declaration,
223
+ /** @type {Range} */
224
+ (statement.range)[0]
222
225
  )
223
226
  ) {
224
227
  sideEffectsStatement = statement;
@@ -21,6 +21,7 @@ const { makePathsRelative } = require("../util/identifier");
21
21
  const memoize = require("../util/memoize");
22
22
  const MinMaxSizeWarning = require("./MinMaxSizeWarning");
23
23
 
24
+ /** @typedef {import("../../declarations/WebpackOptions").HashFunction} HashFunction */
24
25
  /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksCacheGroup} OptimizationSplitChunksCacheGroup */
25
26
  /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksGetCacheGroups} OptimizationSplitChunksGetCacheGroups */
26
27
  /** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksOptions} OptimizationSplitChunksOptions */
@@ -33,7 +34,6 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
33
34
  /** @typedef {import("../Module")} Module */
34
35
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
35
36
  /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
36
- /** @typedef {import("../util/createHash").Algorithm} Algorithm */
37
37
  /** @typedef {import("../util/deterministicGrouping").GroupedItems<Module>} DeterministicGroupingGroupedItemsForModule */
38
38
  /** @typedef {import("../util/deterministicGrouping").Options<Module>} DeterministicGroupingOptionsForModule */
39
39
 
@@ -184,7 +184,7 @@ const hashFilename = (name, outputOptions) => {
184
184
  const digest =
185
185
  /** @type {string} */
186
186
  (
187
- createHash(/** @type {Algorithm} */ (outputOptions.hashFunction))
187
+ createHash(/** @type {HashFunction} */ (outputOptions.hashFunction))
188
188
  .update(name)
189
189
  .digest(outputOptions.hashDigest)
190
190
  );
@@ -37,8 +37,7 @@ class BasicEffectRulePlugin {
37
37
  if (unhandledProperties.has(this.ruleProperty)) {
38
38
  unhandledProperties.delete(this.ruleProperty);
39
39
 
40
- const value =
41
- rule[/** @type {keyof RuleSetRule} */ (this.ruleProperty)];
40
+ const value = rule[this.ruleProperty];
42
41
 
43
42
  result.effects.push({
44
43
  type: this.effectType,
@@ -8,6 +8,7 @@
8
8
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetConditionOrConditions} RuleSetConditionOrConditions */
9
9
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
10
10
  /** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
11
+ /** @typedef {import("./RuleSetCompiler").EffectData} EffectData */
11
12
  /** @typedef {import("./RuleSetCompiler").RuleCondition} RuleCondition */
12
13
  /** @typedef {import("./RuleSetCompiler").RuleConditionFunction} RuleConditionFunction */
13
14
 
@@ -22,7 +23,7 @@
22
23
  class ObjectMatcherRulePlugin {
23
24
  /**
24
25
  * @param {ObjectMatcherRuleKeys} ruleProperty the rule property
25
- * @param {string=} dataProperty the data property
26
+ * @param {keyof EffectData=} dataProperty the data property
26
27
  * @param {RuleConditionFunction=} additionalConditionFunction need to check
27
28
  */
28
29
  constructor(ruleProperty, dataProperty, additionalConditionFunction) {
@@ -13,7 +13,9 @@ const { SyncHook } = require("tapable");
13
13
 
14
14
  /** @typedef {(Falsy | RuleSetRule)[]} RuleSetRules */
15
15
 
16
- /** @typedef {(value: string | EffectData) => boolean} RuleConditionFunction */
16
+ /**
17
+ * @typedef {(value: EffectData[keyof EffectData]) => boolean} RuleConditionFunction
18
+ */
17
19
 
18
20
  /**
19
21
  * @typedef {object} RuleCondition
@@ -29,7 +31,19 @@ const { SyncHook } = require("tapable");
29
31
  */
30
32
 
31
33
  /**
32
- * @typedef {Record<string, TODO>} EffectData
34
+ * @typedef {object} EffectData
35
+ * @property {string=} resource
36
+ * @property {string=} realResource
37
+ * @property {string=} resourceQuery
38
+ * @property {string=} resourceFragment
39
+ * @property {string=} scheme
40
+ * @property {ImportAttributes=} assertions
41
+ * @property {string=} mimetype
42
+ * @property {string} dependency
43
+ * @property {Record<string, EXPECTED_ANY>} descriptionData
44
+ * @property {string=} compiler
45
+ * @property {string} issuer
46
+ * @property {string} issuerLayer
33
47
  */
34
48
 
35
49
  /**
@@ -102,7 +116,7 @@ class RuleSetCompiler {
102
116
  for (const condition of rule.conditions) {
103
117
  const p = condition.property;
104
118
  if (Array.isArray(p)) {
105
- /** @type {EffectData | string | undefined} */
119
+ /** @type {EffectData | EffectData[keyof EffectData] | undefined} */
106
120
  let current = data;
107
121
  for (const subProperty of p) {
108
122
  if (
@@ -110,7 +124,7 @@ class RuleSetCompiler {
110
124
  typeof current === "object" &&
111
125
  Object.prototype.hasOwnProperty.call(current, subProperty)
112
126
  ) {
113
- current = current[subProperty];
127
+ current = current[/** @type {keyof EffectData} */ (subProperty)];
114
128
  } else {
115
129
  current = undefined;
116
130
  break;
@@ -121,7 +135,7 @@ class RuleSetCompiler {
121
135
  continue;
122
136
  }
123
137
  } else if (p in data) {
124
- const value = data[p];
138
+ const value = data[/** @type {keyof EffectData} */ (p)];
125
139
  if (value !== undefined) {
126
140
  if (!condition.fn(value)) return false;
127
141
  continue;