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
@@ -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
  /**
@@ -165,7 +165,7 @@ const encodeDataUri = (encoding, source) => {
165
165
  };
166
166
 
167
167
  /**
168
- * @param {string} encoding encoding
168
+ * @param {"base64" | false} encoding encoding
169
169
  * @param {string} content content
170
170
  * @returns {Buffer} decoded content
171
171
  */
@@ -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
 
@@ -475,7 +475,6 @@ class AssetGenerator extends Generator {
475
475
  module
476
476
  });
477
477
  } else {
478
- /** @type {"base64" | false | undefined} */
479
478
  let encoding =
480
479
  /** @type {AssetGeneratorDataUrlOptions} */
481
480
  (this.dataUrlOptions).encoding;
@@ -498,12 +497,15 @@ class AssetGenerator extends Generator {
498
497
  module.resourceResolveData.encoding === encoding &&
499
498
  decodeDataUriContent(
500
499
  module.resourceResolveData.encoding,
501
- module.resourceResolveData.encodedContent
500
+ /** @type {string} */ (module.resourceResolveData.encodedContent)
502
501
  ).equals(source.buffer())
503
502
  ) {
504
503
  encodedContent = module.resourceResolveData.encodedContent;
505
504
  } else {
506
- encodedContent = encodeDataUri(encoding, source);
505
+ encodedContent = encodeDataUri(
506
+ /** @type {"base64" | false} */ (encoding),
507
+ source
508
+ );
507
509
  }
508
510
 
509
511
  encodedSource = `data:${mimeType}${
@@ -655,6 +657,7 @@ class AssetGenerator extends Generator {
655
657
  * @returns {SourceTypes} available types (do not mutate)
656
658
  */
657
659
  getTypes(module) {
660
+ /** @type {Set<string>} */
658
661
  const sourceTypes = new Set();
659
662
  const connections = this._moduleGraph.getIncomingConnections(module);
660
663
 
@@ -667,27 +670,25 @@ class AssetGenerator extends Generator {
667
670
  }
668
671
 
669
672
  if ((module.buildInfo && module.buildInfo.dataUrl) || this.emit === false) {
670
- if (sourceTypes) {
673
+ if (sourceTypes.size > 0) {
671
674
  if (sourceTypes.has("javascript") && sourceTypes.has("css")) {
672
675
  return JS_AND_CSS_URL_TYPES;
673
- } else if (sourceTypes.has("javascript")) {
674
- return JS_TYPES;
675
676
  } else if (sourceTypes.has("css")) {
676
677
  return CSS_URL_TYPES;
677
678
  }
679
+ return JS_TYPES;
678
680
  }
679
681
 
680
682
  return NO_TYPES;
681
683
  }
682
684
 
683
- if (sourceTypes) {
685
+ if (sourceTypes.size > 0) {
684
686
  if (sourceTypes.has("javascript") && sourceTypes.has("css")) {
685
687
  return ASSET_AND_JS_AND_CSS_URL_TYPES;
686
- } else if (sourceTypes.has("javascript")) {
687
- return ASSET_AND_JS_TYPES;
688
688
  } else if (sourceTypes.has("css")) {
689
689
  return ASSET_AND_CSS_URL_TYPES;
690
690
  }
691
+ return ASSET_AND_JS_TYPES;
691
692
  }
692
693
 
693
694
  return ASSET_TYPES;
@@ -122,6 +122,7 @@ class AssetSourceGenerator extends Generator {
122
122
  * @returns {SourceTypes} available types (do not mutate)
123
123
  */
124
124
  getTypes(module) {
125
+ /** @type {Set<string>} */
125
126
  const sourceTypes = new Set();
126
127
  const connections = this._moduleGraph.getIncomingConnections(module);
127
128
 
@@ -133,12 +134,13 @@ class AssetSourceGenerator extends Generator {
133
134
  sourceTypes.add(connection.originModule.type.split("/")[0]);
134
135
  }
135
136
 
136
- if (sourceTypes.has("javascript") && sourceTypes.has("css")) {
137
- return JS_AND_CSS_URL_TYPES;
138
- } else if (sourceTypes.has("javascript")) {
137
+ if (sourceTypes.size > 0) {
138
+ if (sourceTypes.has("javascript") && sourceTypes.has("css")) {
139
+ return JS_AND_CSS_URL_TYPES;
140
+ } else if (sourceTypes.has("css")) {
141
+ return CSS_URL_TYPES;
142
+ }
139
143
  return JS_TYPES;
140
- } else if (sourceTypes.has("css")) {
141
- return CSS_URL_TYPES;
142
144
  }
143
145
 
144
146
  return NO_TYPES;
@@ -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);
@@ -53,7 +53,7 @@ class CssUrlDependency extends ModuleDependency {
53
53
 
54
54
  /**
55
55
  * @param {string} context context directory
56
- * @returns {Module | null} a module
56
+ * @returns {Module} ignored module
57
57
  */
58
58
  createIgnoredModule(context) {
59
59
  return getIgnoredRawDataUrlModule();
@@ -58,7 +58,7 @@ class ModuleDependency extends Dependency {
58
58
 
59
59
  /**
60
60
  * @param {string} context context directory
61
- * @returns {Module | null} a module
61
+ * @returns {Module} ignored module
62
62
  */
63
63
  createIgnoredModule(context) {
64
64
  return new RawModule(
@@ -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
 
@@ -109,7 +109,10 @@ module.exports = class RequireEnsureDependenciesBlockParserPlugin {
109
109
  }
110
110
  if (successExpression) {
111
111
  if (successExpression.fn.body.type === "BlockStatement") {
112
+ // Opt-out of Dead Control Flow detection for this block
113
+ const oldTerminated = parser.scope.terminated;
112
114
  parser.walkStatement(successExpression.fn.body);
115
+ parser.scope.terminated = oldTerminated;
113
116
  } else {
114
117
  parser.walkExpression(successExpression.fn.body);
115
118
  }
@@ -72,7 +72,7 @@ class URLDependency extends ModuleDependency {
72
72
 
73
73
  /**
74
74
  * @param {string} context context directory
75
- * @returns {Module | null} a module
75
+ * @returns {Module} ignored module
76
76
  */
77
77
  createIgnoredModule(context) {
78
78
  return getIgnoredRawDataUrlModule();
@@ -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);
@@ -216,9 +216,9 @@ class ModuleChunkLoadingRuntimeModule extends RuntimeModule {
216
216
  "// setup Promise in chunk cache",
217
217
  `var promise = ${importFunctionName}(${
218
218
  compilation.outputOptions.publicPath === "auto"
219
- ? ""
220
- : `${RuntimeGlobals.publicPath} + `
221
- }${JSON.stringify(rootOutputDir)} + ${
219
+ ? JSON.stringify(rootOutputDir)
220
+ : RuntimeGlobals.publicPath
221
+ } + ${
222
222
  RuntimeGlobals.getChunkScriptFilename
223
223
  }(chunkId)).then(installChunk, ${runtimeTemplate.basicFunction(
224
224
  "e",
@@ -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(
@@ -578,7 +578,9 @@ class JavascriptParser extends Parser {
578
578
  /** @type {SyncBailHook<[ThrowStatement | ReturnStatement], boolean | void>} */
579
579
  terminate: new SyncBailHook(["statement"]),
580
580
  /** @type {SyncBailHook<[Program, Comment[]], boolean | void>} */
581
- finish: new SyncBailHook(["ast", "comments"])
581
+ finish: new SyncBailHook(["ast", "comments"]),
582
+ /** @type {SyncBailHook<[Statement], boolean | void>} */
583
+ unusedStatement: new SyncBailHook(["statement"])
582
584
  });
583
585
  this.sourceType = sourceType;
584
586
  /** @type {ScopeInfo} */
@@ -1939,8 +1941,13 @@ class JavascriptParser extends Parser {
1939
1941
  for (let index = 0, len = statements.length; index < len; index++) {
1940
1942
  const statement = statements[index];
1941
1943
 
1942
- if (onlyFunctionDeclaration && statement.type !== "FunctionDeclaration")
1944
+ if (
1945
+ onlyFunctionDeclaration &&
1946
+ statement.type !== "FunctionDeclaration" &&
1947
+ this.hooks.unusedStatement.call(/** @type {Statement} */ (statement))
1948
+ ) {
1943
1949
  continue;
1950
+ }
1944
1951
 
1945
1952
  this.walkStatement(statement);
1946
1953
 
@@ -2852,11 +2859,18 @@ class JavascriptParser extends Parser {
2852
2859
  for (let i = 0; i < properties.length; i++) {
2853
2860
  const property = properties[i];
2854
2861
  if (property.type !== "Property") return;
2855
- if (property.shorthand && property.value.type === "Identifier") {
2856
- this.scope.inShorthand = property.value.name;
2862
+ if (property.shorthand) {
2863
+ if (property.value.type === "Identifier") {
2864
+ this.scope.inShorthand = property.value.name;
2865
+ } else if (
2866
+ property.value.type === "AssignmentPattern" &&
2867
+ property.value.left.type === "Identifier"
2868
+ ) {
2869
+ this.scope.inShorthand = property.value.left.name;
2870
+ }
2857
2871
  }
2858
2872
  const key = property.key;
2859
- if (key.type === "Identifier") {
2873
+ if (key.type === "Identifier" && !property.computed) {
2860
2874
  props.add({
2861
2875
  id: key.name,
2862
2876
  range: key.range,
@@ -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)
@@ -82,7 +82,10 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
82
82
  for (const chunk of compilation.chunkGraph.getModuleChunksIterable(
83
83
  module
84
84
  )) {
85
- if (!chunk.hasRuntime()) {
85
+ if (
86
+ !chunk.hasRuntime() ||
87
+ compilation.chunkGraph.getNumberOfEntryModules(chunk) > 1
88
+ ) {
86
89
  return false;
87
90
  }
88
91
  }
@@ -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`;