webpack 5.85.0 → 5.88.1

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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (249) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +150 -99
  3. package/lib/AsyncDependenciesBlock.js +3 -3
  4. package/lib/BannerPlugin.js +2 -1
  5. package/lib/CaseSensitiveModulesWarning.js +3 -1
  6. package/lib/Chunk.js +35 -17
  7. package/lib/ChunkGraph.js +4 -4
  8. package/lib/ChunkGroup.js +20 -9
  9. package/lib/CompatibilityPlugin.js +50 -30
  10. package/lib/Compilation.js +2 -1
  11. package/lib/Compiler.js +10 -9
  12. package/lib/ConcatenationScope.js +2 -2
  13. package/lib/ConditionalInitFragment.js +11 -1
  14. package/lib/ConstPlugin.js +73 -32
  15. package/lib/ContextModule.js +8 -3
  16. package/lib/ContextModuleFactory.js +1 -0
  17. package/lib/ContextReplacementPlugin.js +13 -0
  18. package/lib/DelegatedModule.js +15 -3
  19. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  20. package/lib/DependenciesBlock.js +1 -1
  21. package/lib/Dependency.js +11 -5
  22. package/lib/DependencyTemplates.js +1 -1
  23. package/lib/DllEntryPlugin.js +11 -1
  24. package/lib/DllModule.js +6 -0
  25. package/lib/DllReferencePlugin.js +13 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/ErrorHelpers.js +1 -0
  28. package/lib/EvalSourceMapDevToolPlugin.js +6 -1
  29. package/lib/ExportsInfo.js +22 -4
  30. package/lib/ExportsInfoApiPlugin.js +14 -5
  31. package/lib/ExternalModule.js +20 -8
  32. package/lib/FileSystemInfo.js +52 -24
  33. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  34. package/lib/FlagDependencyUsagePlugin.js +3 -1
  35. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  36. package/lib/Generator.js +7 -0
  37. package/lib/HotModuleReplacementPlugin.js +8 -0
  38. package/lib/InitFragment.js +28 -5
  39. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  40. package/lib/LibManifestPlugin.js +20 -4
  41. package/lib/Module.js +14 -3
  42. package/lib/ModuleDependencyError.js +4 -2
  43. package/lib/ModuleDependencyWarning.js +4 -2
  44. package/lib/ModuleGraph.js +31 -24
  45. package/lib/ModuleGraphConnection.js +19 -6
  46. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  47. package/lib/ModuleNotFoundError.js +5 -2
  48. package/lib/ModuleProfile.js +1 -0
  49. package/lib/ModuleRestoreError.js +2 -0
  50. package/lib/ModuleStoreError.js +2 -1
  51. package/lib/ModuleTypeConstants.js +7 -0
  52. package/lib/MultiWatching.js +4 -0
  53. package/lib/NodeStuffPlugin.js +32 -6
  54. package/lib/ProgressPlugin.js +71 -15
  55. package/lib/ProvidePlugin.js +13 -4
  56. package/lib/RawModule.js +3 -1
  57. package/lib/RequireJsStuffPlugin.js +7 -0
  58. package/lib/RuntimeGlobals.js +5 -0
  59. package/lib/RuntimeModule.js +3 -3
  60. package/lib/RuntimePlugin.js +6 -3
  61. package/lib/RuntimeTemplate.js +22 -4
  62. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  63. package/lib/SourceMapDevToolPlugin.js +7 -2
  64. package/lib/UseStrictPlugin.js +10 -3
  65. package/lib/Watching.js +62 -25
  66. package/lib/WebpackError.js +6 -5
  67. package/lib/WebpackIsIncludedPlugin.js +6 -4
  68. package/lib/WebpackOptionsApply.js +4 -2
  69. package/lib/WebpackOptionsDefaulter.js +10 -3
  70. package/lib/asset/AssetGenerator.js +2 -1
  71. package/lib/asset/AssetParser.js +11 -6
  72. package/lib/asset/AssetSourceParser.js +8 -3
  73. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  74. package/lib/buildChunkGraph.js +37 -21
  75. package/lib/cache/IdleFileCachePlugin.js +2 -1
  76. package/lib/cache/PackFileCacheStrategy.js +53 -22
  77. package/lib/config/browserslistTargetHandler.js +7 -7
  78. package/lib/config/defaults.js +43 -26
  79. package/lib/container/RemoteRuntimeModule.js +1 -1
  80. package/lib/css/CssExportsGenerator.js +9 -0
  81. package/lib/css/CssGenerator.js +1 -1
  82. package/lib/css/CssLoadingRuntimeModule.js +43 -19
  83. package/lib/css/CssModulesPlugin.js +42 -14
  84. package/lib/css/CssParser.js +22 -0
  85. package/lib/dependencies/AMDDefineDependency.js +34 -4
  86. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  87. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  88. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  89. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  90. package/lib/dependencies/CommonJsPlugin.js +13 -8
  91. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  92. package/lib/dependencies/ConstDependency.js +2 -2
  93. package/lib/dependencies/ContextDependency.js +7 -2
  94. package/lib/dependencies/CssImportDependency.js +1 -1
  95. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  96. package/lib/dependencies/CssUrlDependency.js +3 -3
  97. package/lib/dependencies/DllEntryDependency.js +5 -0
  98. package/lib/dependencies/DynamicExports.js +10 -6
  99. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  100. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  101. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  102. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  103. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  104. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  105. package/lib/dependencies/HarmonyExports.js +9 -5
  106. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +40 -27
  107. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  108. package/lib/dependencies/HarmonyImportSpecifierDependency.js +31 -21
  109. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  110. package/lib/dependencies/ImportDependency.js +5 -3
  111. package/lib/dependencies/ImportEagerDependency.js +5 -3
  112. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  113. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  114. package/lib/dependencies/ImportParserPlugin.js +62 -25
  115. package/lib/dependencies/ImportWeakDependency.js +5 -3
  116. package/lib/dependencies/JsonExportsDependency.js +1 -1
  117. package/lib/dependencies/ModuleDependency.js +1 -1
  118. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  119. package/lib/dependencies/ProvidedDependency.js +4 -1
  120. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  121. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  122. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  123. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  124. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  125. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  126. package/lib/dependencies/SystemPlugin.js +17 -5
  127. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  128. package/lib/dependencies/URLDependency.js +2 -2
  129. package/lib/dependencies/URLPlugin.js +9 -4
  130. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  131. package/lib/dependencies/WorkerPlugin.js +59 -22
  132. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  134. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  135. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  136. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  137. package/lib/javascript/BasicEvaluatedExpression.js +28 -19
  138. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  139. package/lib/javascript/JavascriptModulesPlugin.js +25 -5
  140. package/lib/javascript/JavascriptParser.js +157 -85
  141. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  142. package/lib/json/JsonData.js +2 -2
  143. package/lib/json/JsonParser.js +25 -12
  144. package/lib/library/AmdLibraryPlugin.js +2 -2
  145. package/lib/library/AssignLibraryPlugin.js +13 -1
  146. package/lib/library/EnableLibraryPlugin.js +4 -0
  147. package/lib/library/SystemLibraryPlugin.js +1 -1
  148. package/lib/library/UmdLibraryPlugin.js +20 -2
  149. package/lib/logging/runtime.js +1 -1
  150. package/lib/logging/truncateArgs.js +4 -0
  151. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  152. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -1
  153. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  154. package/lib/optimize/AggressiveMergingPlugin.js +8 -0
  155. package/lib/optimize/AggressiveSplittingPlugin.js +9 -2
  156. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -0
  157. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -5
  158. package/lib/optimize/InnerGraph.js +5 -5
  159. package/lib/optimize/InnerGraphPlugin.js +2 -1
  160. package/lib/optimize/LimitChunkCountPlugin.js +29 -4
  161. package/lib/optimize/MangleExportsPlugin.js +1 -1
  162. package/lib/optimize/MinMaxSizeWarning.js +5 -0
  163. package/lib/optimize/ModuleConcatenationPlugin.js +59 -2
  164. package/lib/optimize/RealContentHashPlugin.js +80 -30
  165. package/lib/optimize/RemoveParentModulesPlugin.js +6 -0
  166. package/lib/optimize/RuntimeChunkPlugin.js +9 -1
  167. package/lib/optimize/SideEffectsFlagPlugin.js +10 -1
  168. package/lib/optimize/SplitChunksPlugin.js +71 -31
  169. package/lib/performance/SizeLimitsPlugin.js +7 -4
  170. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  171. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  172. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  173. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  174. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  175. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  176. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  177. package/lib/rules/RuleSetCompiler.js +3 -3
  178. package/lib/rules/UseEffectRulePlugin.js +6 -4
  179. package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
  180. package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
  181. package/lib/runtime/BaseUriRuntimeModule.js +3 -3
  182. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  183. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  184. package/lib/runtime/CompatRuntimeModule.js +7 -2
  185. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  186. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  187. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  188. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  189. package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
  190. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
  191. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  192. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  193. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
  194. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  195. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  196. package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
  197. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  198. package/lib/runtime/NonceRuntimeModule.js +1 -1
  199. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  200. package/lib/runtime/PublicPathRuntimeModule.js +4 -2
  201. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  202. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  203. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
  204. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
  205. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  206. package/lib/serialization/BinaryMiddleware.js +143 -1
  207. package/lib/serialization/ErrorObjectSerializer.js +3 -0
  208. package/lib/serialization/ObjectMiddleware.js +9 -3
  209. package/lib/serialization/types.js +1 -1
  210. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  211. package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
  212. package/lib/sharing/ProvideSharedDependency.js +11 -0
  213. package/lib/sharing/ProvideSharedModule.js +4 -0
  214. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  215. package/lib/sharing/ShareRuntimeModule.js +12 -5
  216. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  217. package/lib/sharing/utils.js +32 -5
  218. package/lib/util/AsyncQueue.js +4 -2
  219. package/lib/util/ParallelismFactorCalculator.js +10 -0
  220. package/lib/util/Semaphore.js +1 -1
  221. package/lib/util/StackedCacheMap.js +1 -1
  222. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  223. package/lib/util/createHash.js +30 -9
  224. package/lib/util/deprecation.js +10 -3
  225. package/lib/util/deterministicGrouping.js +50 -11
  226. package/lib/util/findGraphRoots.js +4 -2
  227. package/lib/util/memoize.js +3 -3
  228. package/lib/util/processAsyncTree.js +7 -1
  229. package/lib/util/registerExternalSerializer.js +1 -1
  230. package/lib/util/runtime.js +84 -21
  231. package/lib/util/semver.js +1 -0
  232. package/lib/util/smartGrouping.js +1 -1
  233. package/lib/validateSchema.js +6 -2
  234. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
  235. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  236. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
  237. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  238. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  239. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  240. package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
  241. package/lib/webpack.js +11 -2
  242. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
  243. package/module.d.ts +1 -0
  244. package/package.json +5 -4
  245. package/schemas/WebpackOptions.check.js +1 -1
  246. package/schemas/WebpackOptions.json +52 -6
  247. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  248. package/schemas/plugins/css/CssParserOptions.json +1 -1
  249. package/types.d.ts +606 -292
@@ -9,20 +9,26 @@ const UnsupportedFeatureWarning = require("../UnsupportedFeatureWarning");
9
9
  const ConstDependency = require("../dependencies/ConstDependency");
10
10
  const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
11
11
 
12
- /** @typedef {import("estree").Expression} ExpressionNode */
12
+ /** @typedef {import("estree").Expression} Expression */
13
13
  /** @typedef {import("estree").Node} Node */
14
+ /** @typedef {import("estree").SourceLocation} SourceLocation */
14
15
  /** @typedef {import("./JavascriptParser")} JavascriptParser */
16
+ /** @typedef {import("./JavascriptParser").Range} Range */
15
17
 
16
18
  /**
17
19
  * @param {JavascriptParser} parser the parser
18
20
  * @param {string} value the const value
19
21
  * @param {string[]=} runtimeRequirements runtime requirements
20
- * @returns {function(ExpressionNode): true} plugin function
22
+ * @returns {function(Expression): true} plugin function
21
23
  */
22
24
  exports.toConstantDependency = (parser, value, runtimeRequirements) => {
23
25
  return function constDependency(expr) {
24
- const dep = new ConstDependency(value, expr.range, runtimeRequirements);
25
- dep.loc = expr.loc;
26
+ const dep = new ConstDependency(
27
+ value,
28
+ /** @type {Range} */ (expr.range),
29
+ runtimeRequirements
30
+ );
31
+ dep.loc = /** @type {SourceLocation} */ (expr.loc);
26
32
  parser.state.module.addPresentationalDependency(dep);
27
33
  return true;
28
34
  };
@@ -30,33 +36,37 @@ exports.toConstantDependency = (parser, value, runtimeRequirements) => {
30
36
 
31
37
  /**
32
38
  * @param {string} value the string value
33
- * @returns {function(ExpressionNode): BasicEvaluatedExpression} plugin function
39
+ * @returns {function(Expression): BasicEvaluatedExpression} plugin function
34
40
  */
35
41
  exports.evaluateToString = value => {
36
42
  return function stringExpression(expr) {
37
- return new BasicEvaluatedExpression().setString(value).setRange(expr.range);
43
+ return new BasicEvaluatedExpression()
44
+ .setString(value)
45
+ .setRange(/** @type {Range} */ (expr.range));
38
46
  };
39
47
  };
40
48
 
41
49
  /**
42
50
  * @param {number} value the number value
43
- * @returns {function(ExpressionNode): BasicEvaluatedExpression} plugin function
51
+ * @returns {function(Expression): BasicEvaluatedExpression} plugin function
44
52
  */
45
53
  exports.evaluateToNumber = value => {
46
54
  return function stringExpression(expr) {
47
- return new BasicEvaluatedExpression().setNumber(value).setRange(expr.range);
55
+ return new BasicEvaluatedExpression()
56
+ .setNumber(value)
57
+ .setRange(/** @type {Range} */ (expr.range));
48
58
  };
49
59
  };
50
60
 
51
61
  /**
52
62
  * @param {boolean} value the boolean value
53
- * @returns {function(ExpressionNode): BasicEvaluatedExpression} plugin function
63
+ * @returns {function(Expression): BasicEvaluatedExpression} plugin function
54
64
  */
55
65
  exports.evaluateToBoolean = value => {
56
66
  return function booleanExpression(expr) {
57
67
  return new BasicEvaluatedExpression()
58
68
  .setBoolean(value)
59
- .setRange(expr.range);
69
+ .setRange(/** @type {Range} */ (expr.range));
60
70
  };
61
71
  };
62
72
 
@@ -65,14 +75,14 @@ exports.evaluateToBoolean = value => {
65
75
  * @param {string} rootInfo rootInfo
66
76
  * @param {function(): string[]} getMembers getMembers
67
77
  * @param {boolean|null=} truthy is truthy, null if nullish
68
- * @returns {function(ExpressionNode): BasicEvaluatedExpression} callback
78
+ * @returns {function(Expression): BasicEvaluatedExpression} callback
69
79
  */
70
80
  exports.evaluateToIdentifier = (identifier, rootInfo, getMembers, truthy) => {
71
81
  return function identifierExpression(expr) {
72
82
  let evaluatedExpression = new BasicEvaluatedExpression()
73
83
  .setIdentifier(identifier, rootInfo, getMembers)
74
84
  .setSideEffects(false)
75
- .setRange(expr.range);
85
+ .setRange(/** @type {Range} */ (expr.range));
76
86
  switch (truthy) {
77
87
  case true:
78
88
  evaluatedExpression.setTruthy();
@@ -89,14 +99,26 @@ exports.evaluateToIdentifier = (identifier, rootInfo, getMembers, truthy) => {
89
99
  };
90
100
  };
91
101
 
102
+ /**
103
+ * @param {JavascriptParser} parser the parser
104
+ * @param {string} message the message
105
+ * @returns {function(Expression): boolean | undefined} callback to handle unsupported expression
106
+ */
92
107
  exports.expressionIsUnsupported = (parser, message) => {
93
108
  return function unsupportedExpression(expr) {
94
- const dep = new ConstDependency("(void 0)", expr.range, null);
95
- dep.loc = expr.loc;
109
+ const dep = new ConstDependency(
110
+ "(void 0)",
111
+ /** @type {Range} */ (expr.range),
112
+ null
113
+ );
114
+ dep.loc = /** @type {SourceLocation} */ (expr.loc);
96
115
  parser.state.module.addPresentationalDependency(dep);
97
116
  if (!parser.state.module) return;
98
117
  parser.state.module.addWarning(
99
- new UnsupportedFeatureWarning(message, expr.loc)
118
+ new UnsupportedFeatureWarning(
119
+ message,
120
+ /** @type {SourceLocation} */ (expr.loc)
121
+ )
100
122
  );
101
123
  return true;
102
124
  };
@@ -40,14 +40,14 @@ class JsonData {
40
40
 
41
41
  /**
42
42
  * @param {Hash} hash hash to be updated
43
- * @returns {Hash} the updated hash
43
+ * @returns {void} the updated hash
44
44
  */
45
45
  updateHash(hash) {
46
46
  if (this._buffer === undefined && this._data !== undefined) {
47
47
  this._buffer = Buffer.from(JSON.stringify(this._data));
48
48
  }
49
49
 
50
- if (this._buffer) return hash.update(this._buffer);
50
+ if (this._buffer) hash.update(this._buffer);
51
51
  }
52
52
  }
53
53
 
@@ -5,16 +5,20 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const parseJson = require("json-parse-even-better-errors");
9
8
  const Parser = require("../Parser");
10
9
  const JsonExportsDependency = require("../dependencies/JsonExportsDependency");
10
+ const memoize = require("../util/memoize");
11
11
  const JsonData = require("./JsonData");
12
12
 
13
13
  /** @typedef {import("../../declarations/plugins/JsonModulesPluginParser").JsonModulesPluginParserOptions} JsonModulesPluginParserOptions */
14
+ /** @typedef {import("../Module").BuildInfo} BuildInfo */
15
+ /** @typedef {import("../Module").BuildMeta} BuildMeta */
14
16
  /** @typedef {import("../Parser").ParserState} ParserState */
15
17
  /** @typedef {import("../Parser").PreparsedAst} PreparsedAst */
16
18
  /** @typedef {import("./JsonModulesPlugin").RawJsonData} RawJsonData */
17
19
 
20
+ const getParseJson = memoize(() => require("json-parse-even-better-errors"));
21
+
18
22
  class JsonParser extends Parser {
19
23
  /**
20
24
  * @param {JsonModulesPluginParserOptions} options parser options
@@ -36,17 +40,26 @@ class JsonParser extends Parser {
36
40
 
37
41
  /** @type {NonNullable<JsonModulesPluginParserOptions["parse"]>} */
38
42
  const parseFn =
39
- typeof this.options.parse === "function" ? this.options.parse : parseJson;
40
- /** @type {Buffer | RawJsonData} */
41
- const data =
42
- typeof source === "object"
43
- ? source
44
- : parseFn(source[0] === "\ufeff" ? source.slice(1) : source);
45
- const jsonData = new JsonData(data);
46
- state.module.buildInfo.jsonData = jsonData;
47
- state.module.buildInfo.strict = true;
48
- state.module.buildMeta.exportsType = "default";
49
- state.module.buildMeta.defaultObject =
43
+ typeof this.options.parse === "function"
44
+ ? this.options.parse
45
+ : getParseJson();
46
+ /** @type {Buffer | RawJsonData | undefined} */
47
+ let data;
48
+ try {
49
+ data =
50
+ typeof source === "object"
51
+ ? source
52
+ : parseFn(source[0] === "\ufeff" ? source.slice(1) : source);
53
+ } catch (e) {
54
+ throw new Error(`Cannot parse JSON: ${/** @type {Error} */ (e).message}`);
55
+ }
56
+ const jsonData = new JsonData(/** @type {Buffer | RawJsonData} */ (data));
57
+ const buildInfo = /** @type {BuildInfo} */ (state.module.buildInfo);
58
+ buildInfo.jsonData = jsonData;
59
+ buildInfo.strict = true;
60
+ const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
61
+ buildMeta.exportsType = "default";
62
+ buildMeta.defaultObject =
50
63
  typeof data === "object" ? "redirect-warn" : false;
51
64
  state.module.addDependency(new JsonExportsDependency(jsonData));
52
65
  return state;
@@ -68,8 +68,8 @@ class AmdLibraryPlugin extends AbstractLibraryPlugin {
68
68
  }
69
69
  }
70
70
  return {
71
- name: /** @type {string=} */ (name),
72
- amdContainer: /** @type {string=} */ (amdContainer)
71
+ name: /** @type {string} */ (name),
72
+ amdContainer: /** @type {string} */ (amdContainer)
73
73
  };
74
74
  }
75
75
 
@@ -17,6 +17,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
17
17
  /** @typedef {import("../../declarations/WebpackOptions").LibraryOptions} LibraryOptions */
18
18
  /** @typedef {import("../../declarations/WebpackOptions").LibraryType} LibraryType */
19
19
  /** @typedef {import("../Chunk")} Chunk */
20
+ /** @typedef {import("../Compilation")} Compilation */
20
21
  /** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
21
22
  /** @typedef {import("../Compiler")} Compiler */
22
23
  /** @typedef {import("../Module")} Module */
@@ -59,6 +60,7 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
59
60
  let i = 1;
60
61
 
61
62
  // all properties printed so far (excluding base)
63
+ /** @type {string[] | undefined} */
62
64
  let propsSoFar;
63
65
 
64
66
  // if there is existingLength, print all properties until this position as property access
@@ -142,7 +144,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
142
144
  }
143
145
  }
144
146
  return {
145
- name: /** @type {string|string[]=} */ (name),
147
+ name: /** @type {string | string[]} */ (name),
146
148
  export: library.export
147
149
  };
148
150
  }
@@ -173,12 +175,22 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
173
175
  moduleGraph.addExtraReason(module, "used as library export");
174
176
  }
175
177
 
178
+ /**
179
+ * @param {Compilation} compilation the compilation
180
+ * @returns {string[]} the prefix
181
+ */
176
182
  _getPrefix(compilation) {
177
183
  return this.prefix === "global"
178
184
  ? [compilation.runtimeTemplate.globalObject]
179
185
  : this.prefix;
180
186
  }
181
187
 
188
+ /**
189
+ * @param {AssignLibraryPluginParsed} options the library options
190
+ * @param {Chunk} chunk the chunk
191
+ * @param {Compilation} compilation the compilation
192
+ * @returns {Array<string>} the resolved full name
193
+ */
182
194
  _getResolvedFullName(options, chunk, compilation) {
183
195
  const prefix = this._getPrefix(compilation);
184
196
  const fullName = options.name ? prefix.concat(options.name) : prefix;
@@ -12,6 +12,10 @@
12
12
  /** @type {WeakMap<Compiler, Set<LibraryType>>} */
13
13
  const enabledTypes = new WeakMap();
14
14
 
15
+ /**
16
+ * @param {Compiler} compiler the compiler instance
17
+ * @returns {Set<LibraryType>} enabled types
18
+ */
15
19
  const getEnabledTypes = compiler => {
16
20
  let set = enabledTypes.get(compiler);
17
21
  if (set === undefined) {
@@ -59,7 +59,7 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
59
59
  );
60
60
  }
61
61
  return {
62
- name: /** @type {string=} */ (name)
62
+ name: /** @type {string} */ (name)
63
63
  };
64
64
  }
65
65
 
@@ -148,6 +148,10 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
148
148
  requiredExternals = externals;
149
149
  }
150
150
 
151
+ /**
152
+ * @param {string} str the string to replace
153
+ * @returns {string} the replaced keys
154
+ */
151
155
  const replaceKeys = str => {
152
156
  return compilation.getPath(str, {
153
157
  chunk
@@ -178,6 +182,10 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
178
182
  );
179
183
  };
180
184
 
185
+ /**
186
+ * @param {string} type the type
187
+ * @returns {string} external require array
188
+ */
181
189
  const externalsRequireArray = type => {
182
190
  return replaceKeys(
183
191
  externals
@@ -185,7 +193,9 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
185
193
  let expr;
186
194
  let request = m.request;
187
195
  if (typeof request === "object") {
188
- request = request[type];
196
+ request =
197
+ /** @type {Record<string, string | string[]>} */
198
+ (request)[type];
189
199
  }
190
200
  if (request === undefined) {
191
201
  throw new Error(
@@ -246,6 +256,10 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
246
256
 
247
257
  const { auxiliaryComment, namedDefine, names } = options;
248
258
 
259
+ /**
260
+ * @param {keyof LibraryCustomUmdCommentObject} type type
261
+ * @returns {string} comment
262
+ */
249
263
  const getAuxiliaryComment = type => {
250
264
  if (auxiliaryComment) {
251
265
  if (typeof auxiliaryComment === "string")
@@ -299,7 +313,11 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
299
313
  " else\n" +
300
314
  " " +
301
315
  replaceKeys(
302
- accessorAccess("root", names.root || names.commonjs)
316
+ accessorAccess(
317
+ "root",
318
+ /** @type {string | string[]} */ (names.root) ||
319
+ /** @type {string} */ (names.commonjs)
320
+ )
303
321
  ) +
304
322
  " = factory(" +
305
323
  externalsRootArray(externals) +
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const SyncBailHook = require("tapable/lib/SyncBailHook");
8
+ const { SyncBailHook } = require("tapable");
9
9
  const { Logger } = require("./Logger");
10
10
  const createConsoleLogger = require("./createConsoleLogger");
11
11
 
@@ -5,6 +5,10 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /**
9
+ * @param {Array<number>} array array of numbers
10
+ * @returns {number} sum of all numbers in array
11
+ */
8
12
  const arraySum = array => {
9
13
  let sum = 0;
10
14
  for (const item of array) sum += item;
@@ -16,6 +16,8 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
16
16
  const { getUndoPath } = require("../util/identifier");
17
17
 
18
18
  /** @typedef {import("../Chunk")} Chunk */
19
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
20
+ /** @typedef {import("../Compilation")} Compilation */
19
21
 
20
22
  class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
21
23
  /**
@@ -46,11 +48,13 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
46
48
  }
47
49
 
48
50
  /**
49
- * @returns {string} runtime code
51
+ * @returns {string | null} runtime code
50
52
  */
51
53
  generate() {
52
- const { chunkGraph, chunk } = this;
53
- const { runtimeTemplate } = this.compilation;
54
+ const compilation = /** @type {Compilation} */ (this.compilation);
55
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
56
+ const chunk = /** @type {Chunk} */ (this.chunk);
57
+ const { runtimeTemplate } = compilation;
54
58
  const fn = RuntimeGlobals.ensureChunkHandlers;
55
59
  const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI);
56
60
  const withExternalInstallChunk = this.runtimeRequirements.has(
@@ -72,8 +76,8 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
72
76
  const hasJsMatcher = compileBooleanMatcher(conditionMap);
73
77
  const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
74
78
 
75
- const outputName = this.compilation.getPath(
76
- getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
79
+ const outputName = compilation.getPath(
80
+ getChunkFilenameTemplate(chunk, compilation.outputOptions),
77
81
  {
78
82
  chunk,
79
83
  contentHashType: "javascript"
@@ -81,7 +85,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
81
85
  );
82
86
  const rootOutputDir = getUndoPath(
83
87
  outputName,
84
- /** @type {string} */ (this.compilation.outputOptions.path),
88
+ /** @type {string} */ (compilation.outputOptions.path),
85
89
  false
86
90
  );
87
91
 
@@ -40,6 +40,7 @@ class ReadFileCompileAsyncWasmPlugin {
40
40
  : globalWasmLoading;
41
41
  return wasmLoading === this._type;
42
42
  };
43
+ const { importMetaName } = compilation.outputOptions;
43
44
  /**
44
45
  * @type {(path: string) => string}
45
46
  */
@@ -48,7 +49,7 @@ class ReadFileCompileAsyncWasmPlugin {
48
49
  Template.asString([
49
50
  "Promise.all([import('fs'), import('url')]).then(([{ readFile }, { URL }]) => new Promise((resolve, reject) => {",
50
51
  Template.indent([
51
- `readFile(new URL(${path}, import.meta.url), (err, buffer) => {`,
52
+ `readFile(new URL(${path}, ${importMetaName}.url), (err, buffer) => {`,
52
53
  Template.indent([
53
54
  "if (err) return reject(err);",
54
55
  "",
@@ -16,6 +16,8 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
16
16
  const { getUndoPath } = require("../util/identifier");
17
17
 
18
18
  /** @typedef {import("../Chunk")} Chunk */
19
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
20
+ /** @typedef {import("../Compilation")} Compilation */
19
21
 
20
22
  class RequireChunkLoadingRuntimeModule extends RuntimeModule {
21
23
  /**
@@ -46,11 +48,13 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
46
48
  }
47
49
 
48
50
  /**
49
- * @returns {string} runtime code
51
+ * @returns {string | null} runtime code
50
52
  */
51
53
  generate() {
52
- const { chunkGraph, chunk } = this;
53
- const { runtimeTemplate } = this.compilation;
54
+ const compilation = /** @type {Compilation} */ (this.compilation);
55
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
56
+ const chunk = /** @type {Chunk} */ (this.chunk);
57
+ const { runtimeTemplate } = compilation;
54
58
  const fn = RuntimeGlobals.ensureChunkHandlers;
55
59
  const withBaseURI = this.runtimeRequirements.has(RuntimeGlobals.baseURI);
56
60
  const withExternalInstallChunk = this.runtimeRequirements.has(
@@ -72,8 +76,8 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
72
76
  const hasJsMatcher = compileBooleanMatcher(conditionMap);
73
77
  const initialChunkIds = getInitialChunkIds(chunk, chunkGraph, chunkHasJs);
74
78
 
75
- const outputName = this.compilation.getPath(
76
- getChunkFilenameTemplate(chunk, this.compilation.outputOptions),
79
+ const outputName = compilation.getPath(
80
+ getChunkFilenameTemplate(chunk, compilation.outputOptions),
77
81
  {
78
82
  chunk,
79
83
  contentHashType: "javascript"
@@ -81,7 +85,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
81
85
  );
82
86
  const rootOutputDir = getUndoPath(
83
87
  outputName,
84
- /** @type {string} */ (this.compilation.outputOptions.path),
88
+ /** @type {string} */ (compilation.outputOptions.path),
85
89
  true
86
90
  );
87
91
 
@@ -10,7 +10,15 @@ const { STAGE_ADVANCED } = require("../OptimizationStages");
10
10
  /** @typedef {import("../Chunk")} Chunk */
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
12
 
13
+ /**
14
+ * @typedef {Object} AggressiveMergingPluginOptions
15
+ * @property {number=} minSizeReduce minimal size reduction to trigger merging
16
+ */
17
+
13
18
  class AggressiveMergingPlugin {
19
+ /**
20
+ * @param {AggressiveMergingPluginOptions=} [options] options object
21
+ */
14
22
  constructor(options) {
15
23
  if (
16
24
  (options !== undefined && typeof options !== "object") ||
@@ -30,6 +30,12 @@ const validate = createSchemaValidation(
30
30
  }
31
31
  );
32
32
 
33
+ /**
34
+ * @param {ChunkGraph} chunkGraph the chunk graph
35
+ * @param {Chunk} oldChunk the old chunk
36
+ * @param {Chunk} newChunk the new chunk
37
+ * @returns {(module: Module) => void} function to move module between chunks
38
+ */
33
39
  const moveModuleBetween = (chunkGraph, oldChunk, newChunk) => {
34
40
  return module => {
35
41
  chunkGraph.disconnectChunkAndModule(oldChunk, module);
@@ -92,6 +98,7 @@ class AggressiveSplittingPlugin {
92
98
  compilation => {
93
99
  let needAdditionalSeal = false;
94
100
  let newSplits;
101
+ /** @type {Set<Chunk>} */
95
102
  let fromAggressiveSplittingSet;
96
103
  let chunkSplitDataMap;
97
104
  compilation.hooks.optimize.tap("AggressiveSplittingPlugin", () => {
@@ -133,8 +140,8 @@ class AggressiveSplittingPlugin {
133
140
  ? recordedSplits.concat(newSplits)
134
141
  : recordedSplits;
135
142
 
136
- const minSize = this.options.minSize;
137
- const maxSize = this.options.maxSize;
143
+ const minSize = /** @type {number} */ (this.options.minSize);
144
+ const maxSize = /** @type {number} */ (this.options.maxSize);
138
145
 
139
146
  const applySplit = splitData => {
140
147
  // Cannot split if id is already taken
@@ -21,6 +21,9 @@ class EnsureChunkConditionsPlugin {
21
21
  compiler.hooks.compilation.tap(
22
22
  "EnsureChunkConditionsPlugin",
23
23
  compilation => {
24
+ /**
25
+ * @param {Iterable<Chunk>} chunks the chunks
26
+ */
24
27
  const handler = chunks => {
25
28
  const chunkGraph = compilation.chunkGraph;
26
29
  // These sets are hoisted here to save memory
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  /** @typedef {import("../Chunk")} Chunk */
9
+ /** @typedef {import("../Chunk").ChunkId} ChunkId */
9
10
  /** @typedef {import("../Compiler")} Compiler */
10
11
  /** @typedef {import("../Module")} Module */
11
12
 
@@ -61,13 +62,15 @@ class FlagIncludedChunksPlugin {
61
62
  for (const chunk of chunks) {
62
63
  let hash = 0;
63
64
  for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
64
- hash |= moduleBits.get(module);
65
+ hash |= /** @type {number} */ (moduleBits.get(module));
65
66
  }
66
67
  chunkModulesHash.set(chunk, hash);
67
68
  }
68
69
 
69
70
  for (const chunkA of chunks) {
70
- const chunkAHash = chunkModulesHash.get(chunkA);
71
+ const chunkAHash =
72
+ /** @type {number} */
73
+ (chunkModulesHash.get(chunkA));
71
74
  const chunkAModulesCount =
72
75
  chunkGraph.getNumberOfChunkModules(chunkA);
73
76
  if (chunkAModulesCount === 0) continue;
@@ -81,7 +84,7 @@ class FlagIncludedChunksPlugin {
81
84
  bestModule = module;
82
85
  }
83
86
  loopB: for (const chunkB of chunkGraph.getModuleChunksIterable(
84
- bestModule
87
+ /** @type {Module} */ (bestModule)
85
88
  )) {
86
89
  // as we iterate the same iterables twice
87
90
  // skip if we find ourselves
@@ -100,14 +103,17 @@ class FlagIncludedChunksPlugin {
100
103
  // is chunkA in chunkB?
101
104
 
102
105
  // we do a cheap check for the hash value
103
- const chunkBHash = chunkModulesHash.get(chunkB);
106
+ const chunkBHash =
107
+ /** @type {number} */
108
+ (chunkModulesHash.get(chunkB));
104
109
  if ((chunkBHash & chunkAHash) !== chunkAHash) continue;
105
110
 
106
111
  // compare all modules
107
112
  for (const m of chunkGraph.getChunkModulesIterable(chunkA)) {
108
113
  if (!chunkGraph.isModuleInChunk(m, chunkB)) continue loopB;
109
114
  }
110
- chunkB.ids.push(chunkA.id);
115
+ /** @type {ChunkId[]} */
116
+ (chunkB.ids).push(/** @type {ChunkId} */ (chunkA.id));
111
117
  }
112
118
  }
113
119
  }
@@ -16,7 +16,7 @@ const { UsageState } = require("../ExportsInfo");
16
16
  /** @typedef {import("../javascript/JavascriptParser")} JavascriptParser */
17
17
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
18
18
 
19
- /** @typedef {Map<TopLevelSymbol | null, Set<string | TopLevelSymbol> | true>} InnerGraph */
19
+ /** @typedef {Map<TopLevelSymbol | null, Set<string | TopLevelSymbol> | true | undefined>} InnerGraph */
20
20
  /** @typedef {function(boolean | Set<string> | undefined): void} UsageCallback */
21
21
 
22
22
  /**
@@ -34,7 +34,7 @@ const topLevelSymbolTag = Symbol("top level symbol");
34
34
 
35
35
  /**
36
36
  * @param {ParserState} parserState parser state
37
- * @returns {State} state
37
+ * @returns {State | undefined} state
38
38
  */
39
39
  function getState(parserState) {
40
40
  return parserStateMap.get(parserState);
@@ -235,7 +235,7 @@ exports.onUsage = (state, onUsageCallback) => {
235
235
 
236
236
  /**
237
237
  * @param {ParserState} state parser state
238
- * @param {TopLevelSymbol} symbol the symbol
238
+ * @param {TopLevelSymbol | undefined} symbol the symbol
239
239
  */
240
240
  exports.setTopLevelSymbol = (state, symbol) => {
241
241
  const innerGraphState = getState(state);
@@ -260,7 +260,7 @@ exports.getTopLevelSymbol = state => {
260
260
  /**
261
261
  * @param {JavascriptParser} parser parser
262
262
  * @param {string} name name of variable
263
- * @returns {TopLevelSymbol} symbol
263
+ * @returns {TopLevelSymbol | undefined} symbol
264
264
  */
265
265
  exports.tagTopLevelSymbol = (parser, name) => {
266
266
  const innerGraphState = getState(parser.state);
@@ -309,7 +309,7 @@ exports.isDependencyUsedByExports = (
309
309
 
310
310
  /**
311
311
  * @param {Dependency} dependency the dependency
312
- * @param {Set<string> | boolean} usedByExports usedByExports info
312
+ * @param {Set<string> | boolean | undefined} usedByExports usedByExports info
313
313
  * @param {ModuleGraph} moduleGraph moduleGraph
314
314
  * @returns {null | false | function(ModuleGraphConnection, RuntimeSpec): ConnectionState} function to determine if the connection is active
315
315
  */
@@ -16,6 +16,7 @@ const InnerGraph = require("./InnerGraph");
16
16
  /** @typedef {import("estree").ClassExpression} ClassExpressionNode */
17
17
  /** @typedef {import("estree").Node} Node */
18
18
  /** @typedef {import("estree").VariableDeclarator} VariableDeclaratorNode */
19
+ /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
19
20
  /** @typedef {import("../Compiler")} Compiler */
20
21
  /** @typedef {import("../Dependency")} Dependency */
21
22
  /** @typedef {import("../dependencies/HarmonyImportSpecifierDependency")} HarmonyImportSpecifierDependency */
@@ -46,7 +47,7 @@ class InnerGraphPlugin {
46
47
 
47
48
  /**
48
49
  * @param {JavascriptParser} parser the parser
49
- * @param {Object} parserOptions options
50
+ * @param {JavascriptParserOptions} parserOptions options
50
51
  * @returns {void}
51
52
  */
52
53
  const handler = (parser, parserOptions) => {