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
@@ -21,14 +21,23 @@ const { relative } = require("./util/fs");
21
21
  const { parseResource } = require("./util/identifier");
22
22
 
23
23
  /** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
24
+ /** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
25
+ /** @typedef {import("../declarations/WebpackOptions").NodeOptions} NodeOptions */
24
26
  /** @typedef {import("./Compiler")} Compiler */
25
27
  /** @typedef {import("./Dependency")} Dependency */
28
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
26
29
  /** @typedef {import("./DependencyTemplates")} DependencyTemplates */
30
+ /** @typedef {import("./NormalModule")} NormalModule */
27
31
  /** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
32
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
33
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
28
34
 
29
35
  const PLUGIN_NAME = "NodeStuffPlugin";
30
36
 
31
37
  class NodeStuffPlugin {
38
+ /**
39
+ * @param {NodeOptions} options options
40
+ */
32
41
  constructor(options) {
33
42
  this.options = options;
34
43
  }
@@ -43,6 +52,11 @@ class NodeStuffPlugin {
43
52
  compiler.hooks.compilation.tap(
44
53
  PLUGIN_NAME,
45
54
  (compilation, { normalModuleFactory }) => {
55
+ /**
56
+ * @param {JavascriptParser} parser the parser
57
+ * @param {JavascriptParserOptions} parserOptions options
58
+ * @returns {void}
59
+ */
46
60
  const handler = (parser, parserOptions) => {
47
61
  if (parserOptions.node === false) return;
48
62
 
@@ -56,10 +70,10 @@ class NodeStuffPlugin {
56
70
  parser.hooks.expression.for("global").tap(PLUGIN_NAME, expr => {
57
71
  const dep = new ConstDependency(
58
72
  RuntimeGlobals.global,
59
- expr.range,
73
+ /** @type {Range} */ (expr.range),
60
74
  [RuntimeGlobals.global]
61
75
  );
62
- dep.loc = expr.loc;
76
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
63
77
  parser.state.module.addPresentationalDependency(dep);
64
78
 
65
79
  // TODO webpack 6 remove
@@ -76,25 +90,31 @@ class NodeStuffPlugin {
76
90
  parser.hooks.rename.for("global").tap(PLUGIN_NAME, expr => {
77
91
  const dep = new ConstDependency(
78
92
  RuntimeGlobals.global,
79
- expr.range,
93
+ /** @type {Range} */ (expr.range),
80
94
  [RuntimeGlobals.global]
81
95
  );
82
- dep.loc = expr.loc;
96
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
83
97
  parser.state.module.addPresentationalDependency(dep);
84
98
  return false;
85
99
  });
86
100
  }
87
101
 
102
+ /**
103
+ * @param {string} expressionName expression name
104
+ * @param {(module: NormalModule) => string} fn function
105
+ * @param {string=} warning warning
106
+ * @returns {void}
107
+ */
88
108
  const setModuleConstant = (expressionName, fn, warning) => {
89
109
  parser.hooks.expression
90
110
  .for(expressionName)
91
111
  .tap(PLUGIN_NAME, expr => {
92
112
  const dep = new CachedConstDependency(
93
113
  JSON.stringify(fn(parser.state.module)),
94
- expr.range,
114
+ /** @type {Range} */ (expr.range),
95
115
  expressionName
96
116
  );
97
- dep.loc = expr.loc;
117
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
98
118
  parser.state.module.addPresentationalDependency(dep);
99
119
 
100
120
  // TODO webpack 6 remove
@@ -108,6 +128,12 @@ class NodeStuffPlugin {
108
128
  });
109
129
  };
110
130
 
131
+ /**
132
+ * @param {string} expressionName expression name
133
+ * @param {string} value value
134
+ * @param {string=} warning warning
135
+ * @returns {void}
136
+ */
111
137
  const setConstant = (expressionName, value, warning) =>
112
138
  setModuleConstant(expressionName, () => value, warning);
113
139
 
@@ -11,9 +11,20 @@ const NormalModule = require("./NormalModule");
11
11
  const createSchemaValidation = require("./util/create-schema-validation");
12
12
  const { contextify } = require("./util/identifier");
13
13
 
14
+ /** @typedef {import("tapable").Tap} Tap */
14
15
  /** @typedef {import("../declarations/plugins/ProgressPlugin").HandlerFunction} HandlerFunction */
15
16
  /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginArgument} ProgressPluginArgument */
16
17
  /** @typedef {import("../declarations/plugins/ProgressPlugin").ProgressPluginOptions} ProgressPluginOptions */
18
+ /** @typedef {import("./Dependency")} Dependency */
19
+ /** @typedef {import("./Entrypoint").EntryOptions} EntryOptions */
20
+ /** @typedef {import("./Module")} Module */
21
+ /** @typedef {import("./logging/Logger").Logger} Logger */
22
+
23
+ /**
24
+ * @typedef {Object} CountsData
25
+ * @property {number} modulesCount modules count
26
+ * @property {number} dependenciesCount dependencies count
27
+ */
17
28
 
18
29
  const validate = createSchemaValidation(
19
30
  require("../schemas/plugins/ProgressPlugin.check.js"),
@@ -23,14 +34,31 @@ const validate = createSchemaValidation(
23
34
  baseDataPath: "options"
24
35
  }
25
36
  );
37
+
38
+ /**
39
+ * @param {number} a a
40
+ * @param {number} b b
41
+ * @param {number} c c
42
+ * @returns {number} median
43
+ */
26
44
  const median3 = (a, b, c) => {
27
45
  return a + b + c - Math.max(a, b, c) - Math.min(a, b, c);
28
46
  };
29
47
 
48
+ /**
49
+ * @param {boolean | null | undefined} profile need profile
50
+ * @param {Logger} logger logger
51
+ * @returns {defaultHandler} default handler
52
+ */
30
53
  const createDefaultHandler = (profile, logger) => {
31
- /** @type {{ value: string, time: number }[]} */
54
+ /** @type {{ value: string | undefined, time: number }[]} */
32
55
  const lastStateInfo = [];
33
56
 
57
+ /**
58
+ * @param {number} percentage percentage
59
+ * @param {string} msg message
60
+ * @param {...string} args additional arguments
61
+ */
34
62
  const defaultHandler = (percentage, msg, ...args) => {
35
63
  if (profile) {
36
64
  if (percentage === 0) {
@@ -95,18 +123,18 @@ const createDefaultHandler = (profile, logger) => {
95
123
 
96
124
  /**
97
125
  * @callback ReportProgress
98
- * @param {number} p
99
- * @param {...string} [args]
126
+ * @param {number} p percentage
127
+ * @param {...string} args additional arguments
100
128
  * @returns {void}
101
129
  */
102
130
 
103
- /** @type {WeakMap<Compiler,ReportProgress>} */
131
+ /** @type {WeakMap<Compiler, ReportProgress | undefined>} */
104
132
  const progressReporters = new WeakMap();
105
133
 
106
134
  class ProgressPlugin {
107
135
  /**
108
136
  * @param {Compiler} compiler the current compiler
109
- * @returns {ReportProgress} a progress reporter, if any
137
+ * @returns {ReportProgress | undefined} a progress reporter, if any
110
138
  */
111
139
  static getReporter(compiler) {
112
140
  return progressReporters.get(compiler);
@@ -288,6 +316,9 @@ class ProgressPlugin {
288
316
  };
289
317
 
290
318
  // only used when showActiveModules is set
319
+ /**
320
+ * @param {Module} module the module
321
+ */
291
322
  const moduleBuild = module => {
292
323
  const ident = module.identifier();
293
324
  if (ident) {
@@ -297,11 +328,18 @@ class ProgressPlugin {
297
328
  }
298
329
  };
299
330
 
331
+ /**
332
+ * @param {Dependency} entry entry dependency
333
+ * @param {EntryOptions} options options object
334
+ */
300
335
  const entryAdd = (entry, options) => {
301
336
  entriesCount++;
302
337
  if (entriesCount < 5 || entriesCount % 10 === 0) updateThrottled();
303
338
  };
304
339
 
340
+ /**
341
+ * @param {Module} module the module
342
+ */
305
343
  const moduleDone = module => {
306
344
  doneModules++;
307
345
  if (showActiveModules) {
@@ -321,6 +359,10 @@ class ProgressPlugin {
321
359
  if (doneModules < 50 || doneModules % 100 === 0) updateThrottled();
322
360
  };
323
361
 
362
+ /**
363
+ * @param {Dependency} entry entry dependency
364
+ * @param {EntryOptions} options options object
365
+ */
324
366
  const entryDone = (entry, options) => {
325
367
  doneEntries++;
326
368
  update();
@@ -330,6 +372,7 @@ class ProgressPlugin {
330
372
  .getCache("ProgressPlugin")
331
373
  .getItemCache("counts", null);
332
374
 
375
+ /** @type {Promise<CountsData> | undefined} */
333
376
  let cacheGetPromise;
334
377
 
335
378
  compiler.hooks.beforeCompile.tap("ProgressPlugin", () => {
@@ -352,15 +395,17 @@ class ProgressPlugin {
352
395
 
353
396
  compiler.hooks.afterCompile.tapPromise("ProgressPlugin", compilation => {
354
397
  if (compilation.compiler.isChild()) return Promise.resolve();
355
- return cacheGetPromise.then(async oldData => {
356
- if (
357
- !oldData ||
358
- oldData.modulesCount !== modulesCount ||
359
- oldData.dependenciesCount !== dependenciesCount
360
- ) {
361
- await cache.storePromise({ modulesCount, dependenciesCount });
398
+ return /** @type {Promise<CountsData>} */ (cacheGetPromise).then(
399
+ async oldData => {
400
+ if (
401
+ !oldData ||
402
+ oldData.modulesCount !== modulesCount ||
403
+ oldData.dependenciesCount !== dependenciesCount
404
+ ) {
405
+ await cache.storePromise({ modulesCount, dependenciesCount });
406
+ }
362
407
  }
363
- });
408
+ );
364
409
  });
365
410
 
366
411
  compiler.hooks.compilation.tap("ProgressPlugin", compilation => {
@@ -463,9 +508,9 @@ class ProgressPlugin {
463
508
  };
464
509
  const numberOfHooks = Object.keys(hooks).length;
465
510
  Object.keys(hooks).forEach((name, idx) => {
466
- const title = hooks[name];
511
+ const title = hooks[/** @type {keyof typeof hooks} */ (name)];
467
512
  const percentage = (idx / numberOfHooks) * 0.25 + 0.7;
468
- compilation.hooks[name].intercept({
513
+ compilation.hooks[/** @type {keyof typeof hooks} */ (name)].intercept({
469
514
  name: "ProgressPlugin",
470
515
  call() {
471
516
  handler(percentage, "sealing", title);
@@ -500,6 +545,12 @@ class ProgressPlugin {
500
545
  handler(0.65, "building");
501
546
  }
502
547
  });
548
+ /**
549
+ * @param {TODO} hook hook
550
+ * @param {number} progress progress from 0 to 1
551
+ * @param {string} category category
552
+ * @param {string} name name
553
+ */
503
554
  const interceptHook = (hook, progress, category, name) => {
504
555
  hook.intercept({
505
556
  name: "ProgressPlugin",
@@ -516,6 +567,9 @@ class ProgressPlugin {
516
567
  error() {
517
568
  handler(progress, category, name);
518
569
  },
570
+ /**
571
+ * @param {Tap} tap tap
572
+ */
519
573
  tap(tap) {
520
574
  progressReporters.set(compiler, (p, ...args) => {
521
575
  handler(progress, category, name, tap.name, ...args);
@@ -610,4 +664,6 @@ ProgressPlugin.defaultOptions = {
610
664
  entries: true
611
665
  };
612
666
 
667
+ ProgressPlugin.createDefaultHandler = createDefaultHandler;
668
+
613
669
  module.exports = ProgressPlugin;
@@ -14,7 +14,11 @@ const ConstDependency = require("./dependencies/ConstDependency");
14
14
  const ProvidedDependency = require("./dependencies/ProvidedDependency");
15
15
  const { approve } = require("./javascript/JavascriptParserHelpers");
16
16
 
17
+ /** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
17
18
  /** @typedef {import("./Compiler")} Compiler */
19
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
20
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
21
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
18
22
 
19
23
  const PLUGIN_NAME = "ProvidePlugin";
20
24
 
@@ -48,6 +52,11 @@ class ProvidePlugin {
48
52
  ProvidedDependency,
49
53
  new ProvidedDependency.Template()
50
54
  );
55
+ /**
56
+ * @param {JavascriptParser} parser the parser
57
+ * @param {JavascriptParserOptions} parserOptions options
58
+ * @returns {void}
59
+ */
51
60
  const handler = (parser, parserOptions) => {
52
61
  Object.keys(definitions).forEach(name => {
53
62
  const request = [].concat(definitions[name]);
@@ -67,9 +76,9 @@ class ProvidePlugin {
67
76
  request[0],
68
77
  nameIdentifier,
69
78
  request.slice(1),
70
- expr.range
79
+ /** @type {Range} */ (expr.range)
71
80
  );
72
- dep.loc = expr.loc;
81
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
73
82
  parser.state.module.addDependency(dep);
74
83
  return true;
75
84
  });
@@ -82,9 +91,9 @@ class ProvidePlugin {
82
91
  request[0],
83
92
  nameIdentifier,
84
93
  request.slice(1),
85
- expr.callee.range
94
+ /** @type {Range} */ (expr.callee.range)
86
95
  );
87
- dep.loc = expr.callee.loc;
96
+ dep.loc = /** @type {DependencyLocation} */ (expr.callee.loc);
88
97
  parser.state.module.addDependency(dep);
89
98
  parser.walkExpressions(expr.arguments);
90
99
  return true;
package/lib/RawModule.js CHANGED
@@ -72,7 +72,9 @@ class RawModule extends Module {
72
72
  * @returns {string} a user readable identifier of the module
73
73
  */
74
74
  readableIdentifier(requestShortener) {
75
- return requestShortener.shorten(this.readableIdentifierStr);
75
+ return /** @type {string} */ (
76
+ requestShortener.shorten(this.readableIdentifierStr)
77
+ );
76
78
  }
77
79
 
78
80
  /**
@@ -15,7 +15,9 @@ const {
15
15
  toConstantDependency
16
16
  } = require("./javascript/JavascriptParserHelpers");
17
17
 
18
+ /** @typedef {import("../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
18
19
  /** @typedef {import("./Compiler")} Compiler */
20
+ /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
19
21
 
20
22
  const PLUGIN_NAME = "RequireJsStuffPlugin";
21
23
 
@@ -33,6 +35,11 @@ module.exports = class RequireJsStuffPlugin {
33
35
  ConstDependency,
34
36
  new ConstDependency.Template()
35
37
  );
38
+ /**
39
+ * @param {JavascriptParser} parser the parser
40
+ * @param {JavascriptParserOptions} parserOptions options
41
+ * @returns {void}
42
+ */
36
43
  const handler = (parser, parserOptions) => {
37
44
  if (
38
45
  parserOptions.requireJs === undefined ||
@@ -188,6 +188,11 @@ exports.createScriptUrl = "__webpack_require__.tu";
188
188
  */
189
189
  exports.getTrustedTypesPolicy = "__webpack_require__.tt";
190
190
 
191
+ /**
192
+ * a flag when a chunk has a fetch priority
193
+ */
194
+ exports.hasFetchPriority = "has fetch priority";
195
+
191
196
  /**
192
197
  * the chunk name of the chunk with the runtime
193
198
  */
@@ -166,7 +166,7 @@ class RuntimeModule extends Module {
166
166
  /* istanbul ignore next */
167
167
  /**
168
168
  * @abstract
169
- * @returns {string} runtime code
169
+ * @returns {string | null} runtime code
170
170
  */
171
171
  generate() {
172
172
  const AbstractMethodError = require("./AbstractMethodError");
@@ -174,11 +174,11 @@ class RuntimeModule extends Module {
174
174
  }
175
175
 
176
176
  /**
177
- * @returns {string} runtime code
177
+ * @returns {string | null} runtime code
178
178
  */
179
179
  getGeneratedCode() {
180
180
  if (this._cachedGeneratedCode) {
181
- return this._cachedGeneratedCode;
181
+ return /** @type {string | null} */ (this._cachedGeneratedCode);
182
182
  }
183
183
  return (this._cachedGeneratedCode = this.generate());
184
184
  }
@@ -128,7 +128,8 @@ class RuntimePlugin {
128
128
  });
129
129
  }
130
130
  for (const req of Object.keys(TREE_DEPENDENCIES)) {
131
- const deps = TREE_DEPENDENCIES[req];
131
+ const deps =
132
+ TREE_DEPENDENCIES[/** @type {keyof TREE_DEPENDENCIES} */ (req)];
132
133
  compilation.hooks.runtimeRequirementInTree
133
134
  .for(req)
134
135
  .tap("RuntimePlugin", (chunk, set) => {
@@ -136,7 +137,8 @@ class RuntimePlugin {
136
137
  });
137
138
  }
138
139
  for (const req of Object.keys(MODULE_DEPENDENCIES)) {
139
- const deps = MODULE_DEPENDENCIES[req];
140
+ const deps =
141
+ MODULE_DEPENDENCIES[/** @type {keyof MODULE_DEPENDENCIES} */ (req)];
140
142
  compilation.hooks.runtimeRequirementInModule
141
143
  .for(req)
142
144
  .tap("RuntimePlugin", (chunk, set) => {
@@ -377,9 +379,10 @@ class RuntimePlugin {
377
379
  if (withCreateScriptUrl) {
378
380
  set.add(RuntimeGlobals.createScriptUrl);
379
381
  }
382
+ const withFetchPriority = set.has(RuntimeGlobals.hasFetchPriority);
380
383
  compilation.addRuntimeModule(
381
384
  chunk,
382
- new LoadScriptRuntimeModule(withCreateScriptUrl)
385
+ new LoadScriptRuntimeModule(withCreateScriptUrl, withFetchPriority)
383
386
  );
384
387
  return true;
385
388
  });
@@ -396,7 +396,7 @@ class RuntimeTemplate {
396
396
 
397
397
  /**
398
398
  * @param {Object} options options object
399
- * @param {Module} options.module the module
399
+ * @param {Module | null} options.module the module
400
400
  * @param {ChunkGraph} options.chunkGraph the chunk graph
401
401
  * @param {string} options.request the request that should be printed as comment
402
402
  * @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
@@ -439,7 +439,7 @@ class RuntimeTemplate {
439
439
 
440
440
  /**
441
441
  * @param {Object} options options object
442
- * @param {Module} options.module the module
442
+ * @param {Module | null} options.module the module
443
443
  * @param {ChunkGraph} options.chunkGraph the chunk graph
444
444
  * @param {string} options.request the request that should be printed as comment
445
445
  * @param {boolean=} options.weak if the dependency is weak (will create a nice error message)
@@ -939,11 +939,29 @@ class RuntimeTemplate {
939
939
  if (chunks.length === 1) {
940
940
  const chunkId = JSON.stringify(chunks[0].id);
941
941
  runtimeRequirements.add(RuntimeGlobals.ensureChunk);
942
- return `${RuntimeGlobals.ensureChunk}(${comment}${chunkId})`;
942
+
943
+ const fetchPriority = chunkGroup.options.fetchPriority;
944
+
945
+ if (fetchPriority) {
946
+ runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
947
+ }
948
+
949
+ return `${RuntimeGlobals.ensureChunk}(${comment}${chunkId}${
950
+ fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
951
+ })`;
943
952
  } else if (chunks.length > 0) {
944
953
  runtimeRequirements.add(RuntimeGlobals.ensureChunk);
954
+
955
+ const fetchPriority = chunkGroup.options.fetchPriority;
956
+
957
+ if (fetchPriority) {
958
+ runtimeRequirements.add(RuntimeGlobals.hasFetchPriority);
959
+ }
960
+
945
961
  const requireChunkId = chunk =>
946
- `${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)})`;
962
+ `${RuntimeGlobals.ensureChunk}(${JSON.stringify(chunk.id)}${
963
+ fetchPriority ? `, ${JSON.stringify(fetchPriority)}` : ""
964
+ })`;
947
965
  return `Promise.all(${comment.trim()}[${chunks
948
966
  .map(requireChunkId)
949
967
  .join(", ")}])`;
@@ -7,9 +7,13 @@
7
7
 
8
8
  const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin");
9
9
 
10
+ /** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
10
11
  /** @typedef {import("./Compilation")} Compilation */
11
12
 
12
13
  class SourceMapDevToolModuleOptionsPlugin {
14
+ /**
15
+ * @param {SourceMapDevToolPluginOptions} options options
16
+ */
13
17
  constructor(options) {
14
18
  this.options = options;
15
19
  }
@@ -22,6 +22,7 @@ const { makePathsAbsolute } = require("./util/identifier");
22
22
  /** @typedef {import("./Cache").Etag} Etag */
23
23
  /** @typedef {import("./CacheFacade").ItemCacheFacade} ItemCacheFacade */
24
24
  /** @typedef {import("./Chunk")} Chunk */
25
+ /** @typedef {import("./Compilation").Asset} Asset */
25
26
  /** @typedef {import("./Compilation").AssetInfo} AssetInfo */
26
27
  /** @typedef {import("./Compilation").PathData} PathData */
27
28
  /** @typedef {import("./Compiler")} Compiler */
@@ -227,7 +228,9 @@ class SourceMapDevToolPlugin {
227
228
  asyncLib.each(
228
229
  files,
229
230
  (file, callback) => {
230
- const asset = compilation.getAsset(file);
231
+ const asset =
232
+ /** @type {Readonly<Asset>} */
233
+ (compilation.getAsset(file));
231
234
  if (asset.info.related && asset.info.related.sourceMap) {
232
235
  fileIndex++;
233
236
  return callback();
@@ -363,7 +366,9 @@ class SourceMapDevToolPlugin {
363
366
  // find modules with conflicting source names
364
367
  for (let idx = 0; idx < allModules.length; idx++) {
365
368
  const module = allModules[idx];
366
- let sourceName = moduleToSourceNameMapping.get(module);
369
+ let sourceName =
370
+ /** @type {string} */
371
+ (moduleToSourceNameMapping.get(module));
367
372
  let hasName = conflictDetectionSet.has(sourceName);
368
373
  if (!hasName) {
369
374
  conflictDetectionSet.add(sourceName);
@@ -13,7 +13,10 @@ const {
13
13
  const ConstDependency = require("./dependencies/ConstDependency");
14
14
 
15
15
  /** @typedef {import("./Compiler")} Compiler */
16
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
17
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
16
18
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
19
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
17
20
 
18
21
  const PLUGIN_NAME = "UseStrictPlugin";
19
22
 
@@ -42,10 +45,14 @@ class UseStrictPlugin {
42
45
  // Remove "use strict" expression. It will be added later by the renderer again.
43
46
  // This is necessary in order to not break the strict mode when webpack prepends code.
44
47
  // @see https://github.com/webpack/webpack/issues/1970
45
- const dep = new ConstDependency("", firstNode.range);
46
- dep.loc = firstNode.loc;
48
+ const dep = new ConstDependency(
49
+ "",
50
+ /** @type {Range} */ (firstNode.range)
51
+ );
52
+ dep.loc = /** @type {DependencyLocation} */ (firstNode.loc);
47
53
  parser.state.module.addPresentationalDependency(dep);
48
- parser.state.module.buildInfo.strict = true;
54
+ /** @type {BuildInfo} */
55
+ (parser.state.module.buildInfo).strict = true;
49
56
  }
50
57
  });
51
58
  };