webpack 5.86.0 → 5.88.0

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 (207) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +1 -1
  3. package/lib/AsyncDependenciesBlock.js +3 -3
  4. package/lib/CaseSensitiveModulesWarning.js +3 -1
  5. package/lib/ChunkGraph.js +4 -4
  6. package/lib/ChunkGroup.js +10 -3
  7. package/lib/CompatibilityPlugin.js +50 -30
  8. package/lib/Compilation.js +2 -1
  9. package/lib/Compiler.js +3 -1
  10. package/lib/ConcatenationScope.js +2 -2
  11. package/lib/ConditionalInitFragment.js +11 -1
  12. package/lib/ConstPlugin.js +57 -29
  13. package/lib/ContextModule.js +4 -1
  14. package/lib/ContextReplacementPlugin.js +13 -0
  15. package/lib/DelegatedModule.js +15 -3
  16. package/lib/DelegatedModuleFactoryPlugin.js +6 -0
  17. package/lib/Dependency.js +11 -5
  18. package/lib/DllEntryPlugin.js +11 -1
  19. package/lib/DllReferencePlugin.js +13 -1
  20. package/lib/Entrypoint.js +1 -1
  21. package/lib/ErrorHelpers.js +1 -0
  22. package/lib/EvalSourceMapDevToolPlugin.js +4 -0
  23. package/lib/ExportsInfo.js +17 -3
  24. package/lib/ExportsInfoApiPlugin.js +14 -5
  25. package/lib/ExternalModule.js +5 -0
  26. package/lib/FlagAllModulesAsUsedPlugin.js +6 -1
  27. package/lib/FlagDependencyUsagePlugin.js +3 -1
  28. package/lib/FlagEntryExportAsUsedPlugin.js +4 -0
  29. package/lib/HotModuleReplacementPlugin.js +8 -0
  30. package/lib/InitFragment.js +28 -5
  31. package/lib/JavascriptMetaInfoPlugin.js +11 -6
  32. package/lib/LibManifestPlugin.js +20 -4
  33. package/lib/Module.js +7 -2
  34. package/lib/ModuleDependencyError.js +4 -2
  35. package/lib/ModuleDependencyWarning.js +4 -2
  36. package/lib/ModuleGraph.js +31 -24
  37. package/lib/ModuleGraphConnection.js +19 -6
  38. package/lib/ModuleInfoHeaderPlugin.js +9 -2
  39. package/lib/ModuleNotFoundError.js +5 -2
  40. package/lib/ModuleProfile.js +1 -0
  41. package/lib/ModuleRestoreError.js +2 -0
  42. package/lib/ModuleStoreError.js +2 -1
  43. package/lib/ModuleTypeConstants.js +7 -0
  44. package/lib/MultiWatching.js +4 -0
  45. package/lib/NodeStuffPlugin.js +32 -6
  46. package/lib/ProvidePlugin.js +13 -4
  47. package/lib/RawModule.js +3 -1
  48. package/lib/RequireJsStuffPlugin.js +7 -0
  49. package/lib/RuntimeGlobals.js +5 -0
  50. package/lib/RuntimeModule.js +3 -3
  51. package/lib/RuntimePlugin.js +6 -3
  52. package/lib/RuntimeTemplate.js +22 -4
  53. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -0
  54. package/lib/SourceMapDevToolPlugin.js +7 -2
  55. package/lib/UseStrictPlugin.js +10 -3
  56. package/lib/WebpackError.js +6 -5
  57. package/lib/WebpackIsIncludedPlugin.js +6 -4
  58. package/lib/WebpackOptionsApply.js +1 -1
  59. package/lib/WebpackOptionsDefaulter.js +10 -3
  60. package/lib/asset/AssetGenerator.js +2 -1
  61. package/lib/asset/AssetParser.js +11 -6
  62. package/lib/asset/AssetSourceParser.js +8 -3
  63. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -0
  64. package/lib/cache/IdleFileCachePlugin.js +2 -1
  65. package/lib/cache/PackFileCacheStrategy.js +35 -14
  66. package/lib/config/browserslistTargetHandler.js +7 -7
  67. package/lib/config/defaults.js +43 -26
  68. package/lib/container/RemoteRuntimeModule.js +1 -1
  69. package/lib/css/CssLoadingRuntimeModule.js +30 -13
  70. package/lib/css/CssModulesPlugin.js +5 -2
  71. package/lib/css/CssParser.js +22 -0
  72. package/lib/dependencies/AMDDefineDependency.js +34 -4
  73. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +5 -0
  74. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  75. package/lib/dependencies/CommonJsExportsParserPlugin.js +14 -4
  76. package/lib/dependencies/CommonJsImportsParserPlugin.js +169 -59
  77. package/lib/dependencies/CommonJsPlugin.js +13 -8
  78. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  79. package/lib/dependencies/ConstDependency.js +2 -2
  80. package/lib/dependencies/ContextDependency.js +7 -2
  81. package/lib/dependencies/CssImportDependency.js +1 -1
  82. package/lib/dependencies/CssLocalIdentifierDependency.js +5 -0
  83. package/lib/dependencies/CssUrlDependency.js +3 -3
  84. package/lib/dependencies/DllEntryDependency.js +5 -0
  85. package/lib/dependencies/DynamicExports.js +10 -6
  86. package/lib/dependencies/ExportsInfoDependency.js +14 -4
  87. package/lib/dependencies/HarmonyCompatibilityDependency.js +2 -1
  88. package/lib/dependencies/HarmonyDetectionParserPlugin.js +3 -1
  89. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -5
  90. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +2 -0
  91. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +4 -4
  92. package/lib/dependencies/HarmonyExports.js +9 -5
  93. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +32 -17
  94. package/lib/dependencies/HarmonyImportSideEffectDependency.js +1 -2
  95. package/lib/dependencies/HarmonyImportSpecifierDependency.js +19 -9
  96. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -3
  97. package/lib/dependencies/ImportDependency.js +5 -3
  98. package/lib/dependencies/ImportEagerDependency.js +5 -3
  99. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +19 -0
  100. package/lib/dependencies/ImportMetaPlugin.js +31 -15
  101. package/lib/dependencies/ImportParserPlugin.js +62 -25
  102. package/lib/dependencies/ImportWeakDependency.js +5 -3
  103. package/lib/dependencies/ModuleDependency.js +1 -1
  104. package/lib/dependencies/ModuleDependencyTemplateAsId.js +2 -1
  105. package/lib/dependencies/ProvidedDependency.js +4 -1
  106. package/lib/dependencies/RequireContextDependencyParserPlugin.js +13 -5
  107. package/lib/dependencies/RequireEnsureDependenciesBlock.js +5 -2
  108. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +6 -1
  109. package/lib/dependencies/RequireHeaderDependency.js +4 -0
  110. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +26 -5
  111. package/lib/dependencies/RequireResolveHeaderDependency.js +9 -0
  112. package/lib/dependencies/SystemPlugin.js +17 -5
  113. package/lib/dependencies/SystemRuntimeModule.js +1 -1
  114. package/lib/dependencies/URLDependency.js +2 -2
  115. package/lib/dependencies/URLPlugin.js +9 -4
  116. package/lib/dependencies/WebAssemblyImportDependency.js +1 -1
  117. package/lib/dependencies/WorkerPlugin.js +59 -22
  118. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -1
  119. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
  120. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  121. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  122. package/lib/ids/SyncModuleIdsPlugin.js +1 -0
  123. package/lib/javascript/BasicEvaluatedExpression.js +23 -15
  124. package/lib/javascript/CommonJsChunkFormatPlugin.js +6 -2
  125. package/lib/javascript/JavascriptParser.js +135 -63
  126. package/lib/javascript/JavascriptParserHelpers.js +37 -15
  127. package/lib/logging/runtime.js +1 -1
  128. package/lib/logging/truncateArgs.js +4 -0
  129. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -6
  130. package/lib/node/RequireChunkLoadingRuntimeModule.js +10 -6
  131. package/lib/optimize/InnerGraph.js +1 -1
  132. package/lib/optimize/InnerGraphPlugin.js +2 -1
  133. package/lib/performance/SizeLimitsPlugin.js +7 -4
  134. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +4 -2
  135. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +3 -1
  136. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +6 -3
  137. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +4 -2
  138. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +4 -2
  139. package/lib/rules/BasicEffectRulePlugin.js +4 -0
  140. package/lib/rules/BasicMatcherRulePlugin.js +5 -0
  141. package/lib/rules/RuleSetCompiler.js +3 -3
  142. package/lib/rules/UseEffectRulePlugin.js +6 -4
  143. package/lib/runtime/AsyncModuleRuntimeModule.js +8 -5
  144. package/lib/runtime/AutoPublicPathRuntimeModule.js +4 -2
  145. package/lib/runtime/BaseUriRuntimeModule.js +3 -3
  146. package/lib/runtime/ChunkNameRuntimeModule.js +1 -1
  147. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +5 -2
  148. package/lib/runtime/CompatRuntimeModule.js +7 -2
  149. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +5 -2
  150. package/lib/runtime/CreateScriptRuntimeModule.js +4 -2
  151. package/lib/runtime/CreateScriptUrlRuntimeModule.js +4 -2
  152. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +5 -2
  153. package/lib/runtime/EnsureChunkRuntimeModule.js +15 -4
  154. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -10
  155. package/lib/runtime/GetFullHashRuntimeModule.js +4 -3
  156. package/lib/runtime/GetMainFilenameRuntimeModule.js +5 -2
  157. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +4 -2
  158. package/lib/runtime/GlobalRuntimeModule.js +1 -1
  159. package/lib/runtime/HasOwnPropertyRuntimeModule.js +5 -2
  160. package/lib/runtime/LoadScriptRuntimeModule.js +64 -48
  161. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +5 -2
  162. package/lib/runtime/NonceRuntimeModule.js +1 -1
  163. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -2
  164. package/lib/runtime/PublicPathRuntimeModule.js +4 -2
  165. package/lib/runtime/RelativeUrlRuntimeModule.js +5 -2
  166. package/lib/runtime/RuntimeIdRuntimeModule.js +6 -2
  167. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -3
  168. package/lib/runtime/StartupEntrypointRuntimeModule.js +3 -2
  169. package/lib/runtime/SystemContextRuntimeModule.js +1 -1
  170. package/lib/serialization/ObjectMiddleware.js +6 -3
  171. package/lib/sharing/ConsumeSharedFallbackDependency.js +3 -0
  172. package/lib/sharing/ConsumeSharedRuntimeModule.js +14 -5
  173. package/lib/sharing/ProvideSharedDependency.js +11 -0
  174. package/lib/sharing/ProvideSharedModule.js +4 -0
  175. package/lib/sharing/ProvideSharedPlugin.js +22 -21
  176. package/lib/sharing/ShareRuntimeModule.js +12 -5
  177. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  178. package/lib/sharing/utils.js +32 -5
  179. package/lib/util/AsyncQueue.js +4 -2
  180. package/lib/util/ParallelismFactorCalculator.js +10 -0
  181. package/lib/util/Semaphore.js +1 -1
  182. package/lib/util/createHash.js +30 -9
  183. package/lib/util/deprecation.js +10 -3
  184. package/lib/util/deterministicGrouping.js +50 -11
  185. package/lib/util/findGraphRoots.js +4 -2
  186. package/lib/util/memoize.js +3 -3
  187. package/lib/util/processAsyncTree.js +7 -1
  188. package/lib/util/registerExternalSerializer.js +1 -1
  189. package/lib/util/runtime.js +14 -1
  190. package/lib/util/smartGrouping.js +1 -1
  191. package/lib/validateSchema.js +6 -2
  192. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +6 -2
  193. package/lib/wasm-async/AsyncWebAssemblyParser.js +7 -3
  194. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +14 -7
  195. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +3 -1
  196. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  197. package/lib/wasm-sync/WebAssemblyParser.js +6 -2
  198. package/lib/web/JsonpChunkLoadingRuntimeModule.js +14 -4
  199. package/lib/webpack.js +11 -2
  200. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +15 -16
  201. package/module.d.ts +1 -0
  202. package/package.json +5 -4
  203. package/schemas/WebpackOptions.check.js +1 -1
  204. package/schemas/WebpackOptions.json +39 -5
  205. package/schemas/plugins/css/CssGeneratorOptions.json +1 -1
  206. package/schemas/plugins/css/CssParserOptions.json +1 -1
  207. package/types.d.ts +519 -222
@@ -7,6 +7,8 @@
7
7
 
8
8
  const DelegatedModule = require("./DelegatedModule");
9
9
 
10
+ /** @typedef {import("./NormalModuleFactory")} NormalModuleFactory */
11
+
10
12
  // options.source
11
13
  // options.type
12
14
  // options.context
@@ -20,6 +22,10 @@ class DelegatedModuleFactoryPlugin {
20
22
  options.extensions = options.extensions || ["", ".js", ".json", ".wasm"];
21
23
  }
22
24
 
25
+ /**
26
+ * @param {NormalModuleFactory} normalModuleFactory the normal module factory
27
+ * @returns {void}
28
+ */
23
29
  apply(normalModuleFactory) {
24
30
  const scope = this.options.scope;
25
31
  if (scope) {
package/lib/Dependency.js CHANGED
@@ -89,9 +89,9 @@ const getIgnoredModule = memoize(() => {
89
89
 
90
90
  class Dependency {
91
91
  constructor() {
92
- /** @type {Module} */
92
+ /** @type {Module | undefined} */
93
93
  this._parentModule = undefined;
94
- /** @type {DependenciesBlock} */
94
+ /** @type {DependenciesBlock | undefined} */
95
95
  this._parentDependenciesBlock = undefined;
96
96
  /** @type {number} */
97
97
  this._parentDependenciesBlockIndex = -1;
@@ -174,6 +174,12 @@ class Dependency {
174
174
  this._loc = loc;
175
175
  }
176
176
 
177
+ /**
178
+ * @param {number} startLine start line
179
+ * @param {number} startColumn start column
180
+ * @param {number} endLine end line
181
+ * @param {number} endColumn end column
182
+ */
177
183
  setLoc(startLine, startColumn, endLine, endColumn) {
178
184
  this._locSL = startLine;
179
185
  this._locSC = startColumn;
@@ -247,7 +253,7 @@ class Dependency {
247
253
  /**
248
254
  * Returns warnings
249
255
  * @param {ModuleGraph} moduleGraph module graph
250
- * @returns {WebpackError[]} warnings
256
+ * @returns {WebpackError[] | null | undefined} warnings
251
257
  */
252
258
  getWarnings(moduleGraph) {
253
259
  return null;
@@ -256,7 +262,7 @@ class Dependency {
256
262
  /**
257
263
  * Returns errors
258
264
  * @param {ModuleGraph} moduleGraph module graph
259
- * @returns {WebpackError[]} errors
265
+ * @returns {WebpackError[] | null | undefined} errors
260
266
  */
261
267
  getErrors(moduleGraph) {
262
268
  return null;
@@ -288,7 +294,7 @@ class Dependency {
288
294
 
289
295
  /**
290
296
  * @param {string} context context directory
291
- * @returns {Module} a module
297
+ * @returns {Module | null} a module
292
298
  */
293
299
  createIgnoredModule(context) {
294
300
  return getIgnoredModule();
@@ -9,6 +9,8 @@ const DllModuleFactory = require("./DllModuleFactory");
9
9
  const DllEntryDependency = require("./dependencies/DllEntryDependency");
10
10
  const EntryDependency = require("./dependencies/EntryDependency");
11
11
 
12
+ /** @typedef {import("./Compiler")} Compiler */
13
+
12
14
  class DllEntryPlugin {
13
15
  /**
14
16
  * @param {string} context context
@@ -21,6 +23,11 @@ class DllEntryPlugin {
21
23
  this.options = options;
22
24
  }
23
25
 
26
+ /**
27
+ * Apply the plugin
28
+ * @param {Compiler} compiler the compiler instance
29
+ * @returns {void}
30
+ */
24
31
  apply(compiler) {
25
32
  compiler.hooks.compilation.tap(
26
33
  "DllEntryPlugin",
@@ -51,7 +58,10 @@ class DllEntryPlugin {
51
58
  this.options.name
52
59
  ),
53
60
  this.options,
54
- callback
61
+ error => {
62
+ if (error) return callback(error);
63
+ callback();
64
+ }
55
65
  );
56
66
  });
57
67
  }
@@ -16,6 +16,7 @@ const makePathsRelative = require("./util/identifier").makePathsRelative;
16
16
  /** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
17
17
  /** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
18
18
  /** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsManifest} DllReferencePluginOptionsManifest */
19
+ /** @typedef {import("./Compiler")} Compiler */
19
20
 
20
21
  const validate = createSchemaValidation(
21
22
  require("../schemas/plugins/DllReferencePlugin.check.js"),
@@ -37,6 +38,11 @@ class DllReferencePlugin {
37
38
  this._compilationData = new WeakMap();
38
39
  }
39
40
 
41
+ /**
42
+ * Apply the plugin
43
+ * @param {Compiler} compiler the compiler instance
44
+ * @returns {void}
45
+ */
40
46
  apply(compiler) {
41
47
  compiler.hooks.compilation.tap(
42
48
  "DllReferencePlugin",
@@ -140,7 +146,9 @@ class DllReferencePlugin {
140
146
  // If there was an error parsing the manifest file, add the
141
147
  // error as a compilation error to make the compilation fail.
142
148
  if (data.error) {
143
- compilation.errors.push(data.error);
149
+ compilation.errors.push(
150
+ /** @type {DllManifestError} */ (data.error)
151
+ );
144
152
  }
145
153
  compilation.fileDependencies.add(manifest);
146
154
  }
@@ -151,6 +159,10 @@ class DllReferencePlugin {
151
159
  }
152
160
 
153
161
  class DllManifestError extends WebpackError {
162
+ /**
163
+ * @param {string} filename filename of the manifest
164
+ * @param {string} message error message
165
+ */
154
166
  constructor(filename, message) {
155
167
  super();
156
168
 
package/lib/Entrypoint.js CHANGED
@@ -83,7 +83,7 @@ class Entrypoint extends ChunkGroup {
83
83
  * @returns {Chunk} chunk
84
84
  */
85
85
  getEntrypointChunk() {
86
- return this._entrypointChunk;
86
+ return /** @type {Chunk} */ (this._entrypointChunk);
87
87
  }
88
88
 
89
89
  /**
@@ -45,6 +45,7 @@ const cutOffMultilineMessage = (stack, message) => {
45
45
  const stackSplitByLines = stack.split("\n");
46
46
  const messageSplitByLines = message.split("\n");
47
47
 
48
+ /** @type {string[]} */
48
49
  const result = [];
49
50
 
50
51
  stackSplitByLines.forEach((line, idx) => {
@@ -82,6 +82,10 @@ class EvalSourceMapDevToolPlugin {
82
82
  return cachedSource;
83
83
  }
84
84
 
85
+ /**
86
+ * @param {Source} r result
87
+ * @returns {Source} result
88
+ */
85
89
  const result = r => {
86
90
  cache.set(source, r);
87
91
  return r;
@@ -14,6 +14,8 @@ const { forEachRuntime } = require("./util/runtime");
14
14
  /** @typedef {import("./Module")} Module */
15
15
  /** @typedef {import("./ModuleGraph")} ModuleGraph */
16
16
  /** @typedef {import("./ModuleGraphConnection")} ModuleGraphConnection */
17
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
18
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
17
19
  /** @typedef {import("./util/Hash")} Hash */
18
20
 
19
21
  /** @typedef {typeof UsageState.OnlyPropertiesUsed | typeof UsageState.NoInfo | typeof UsageState.Unknown | typeof UsageState.Used} RuntimeUsageStateType */
@@ -44,6 +46,9 @@ class RestoreProvidedData {
44
46
  this.otherTerminalBinding = otherTerminalBinding;
45
47
  }
46
48
 
49
+ /**
50
+ * @param {ObjectSerializerContext} context context
51
+ */
47
52
  serialize({ write }) {
48
53
  write(this.exports);
49
54
  write(this.otherProvided);
@@ -51,6 +56,10 @@ class RestoreProvidedData {
51
56
  write(this.otherTerminalBinding);
52
57
  }
53
58
 
59
+ /**
60
+ * @param {ObjectDeserializerContext} context context
61
+ * @returns {RestoreProvidedData} RestoreProvidedData
62
+ */
54
63
  static deserialize({ read }) {
55
64
  return new RestoreProvidedData(read(), read(), read(), read());
56
65
  }
@@ -301,7 +310,12 @@ class ExportsInfo {
301
310
  changed = true;
302
311
  }
303
312
  if (targetKey) {
304
- exportInfo.setTarget(targetKey, targetModule, [exportInfo.name], -1);
313
+ exportInfo.setTarget(
314
+ targetKey,
315
+ /** @type {ModuleGraphConnection} */ (targetModule),
316
+ [exportInfo.name],
317
+ -1
318
+ );
305
319
  }
306
320
  }
307
321
  if (this._redirectTo !== undefined) {
@@ -331,7 +345,7 @@ class ExportsInfo {
331
345
  if (targetKey) {
332
346
  this._otherExportsInfo.setTarget(
333
347
  targetKey,
334
- targetModule,
348
+ /** @type {ModuleGraphConnection} */ (targetModule),
335
349
  undefined,
336
350
  priority
337
351
  );
@@ -1226,7 +1240,7 @@ class ExportInfo {
1226
1240
  /**
1227
1241
  * @param {ModuleGraph} moduleGraph the module graph
1228
1242
  * @param {function(Module): boolean} validTargetModuleFilter a valid target module
1229
- * @param {Set<ExportInfo> | undefined} alreadyVisited set of already visited export info to avoid circular references
1243
+ * @param {Set<ExportInfo>} alreadyVisited set of already visited export info to avoid circular references
1230
1244
  * @returns {{ module: Module, export: string[] | undefined } | undefined | false} the target, undefined when there is no target, false when no target is valid
1231
1245
  */
1232
1246
  _findTarget(moduleGraph, validTargetModuleFilter, alreadyVisited) {
@@ -14,7 +14,9 @@ const ConstDependency = require("./dependencies/ConstDependency");
14
14
  const ExportsInfoDependency = require("./dependencies/ExportsInfoDependency");
15
15
 
16
16
  /** @typedef {import("./Compiler")} Compiler */
17
+ /** @typedef {import("./Dependency").DependencyLocation} DependencyLocation */
17
18
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
19
+ /** @typedef {import("./javascript/JavascriptParser").Range} Range */
18
20
 
19
21
  const PLUGIN_NAME = "ExportsInfoApiPlugin";
20
22
 
@@ -43,20 +45,27 @@ class ExportsInfoApiPlugin {
43
45
  const dep =
44
46
  members.length >= 2
45
47
  ? new ExportsInfoDependency(
46
- expr.range,
48
+ /** @type {Range} */ (expr.range),
47
49
  members.slice(0, -1),
48
50
  members[members.length - 1]
49
51
  )
50
- : new ExportsInfoDependency(expr.range, null, members[0]);
51
- dep.loc = expr.loc;
52
+ : new ExportsInfoDependency(
53
+ /** @type {Range} */ (expr.range),
54
+ null,
55
+ members[0]
56
+ );
57
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
52
58
  parser.state.module.addDependency(dep);
53
59
  return true;
54
60
  });
55
61
  parser.hooks.expression
56
62
  .for("__webpack_exports_info__")
57
63
  .tap(PLUGIN_NAME, expr => {
58
- const dep = new ConstDependency("true", expr.range);
59
- dep.loc = expr.loc;
64
+ const dep = new ConstDependency(
65
+ "true",
66
+ /** @type {Range} */ (expr.range)
67
+ );
68
+ dep.loc = /** @type {DependencyLocation} */ (expr.loc);
60
69
  parser.state.module.addPresentationalDependency(dep);
61
70
  return true;
62
71
  });
@@ -384,6 +384,11 @@ const getSourceForDefaultCase = (optional, request, runtimeTemplate) => {
384
384
  };
385
385
 
386
386
  class ExternalModule extends Module {
387
+ /**
388
+ * @param {string | string[] | Record<string, string | string[]>} request request
389
+ * @param {TODO} type type
390
+ * @param {string} userRequest user request
391
+ */
387
392
  constructor(request, type, userRequest) {
388
393
  super(JAVASCRIPT_MODULE_TYPE_DYNAMIC, null);
389
394
 
@@ -8,10 +8,14 @@
8
8
  const { getEntryRuntime, mergeRuntimeOwned } = require("./util/runtime");
9
9
 
10
10
  /** @typedef {import("./Compiler")} Compiler */
11
+ /** @typedef {import("./Module").FactoryMeta} FactoryMeta */
11
12
  /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
12
13
 
13
14
  const PLUGIN_NAME = "FlagAllModulesAsUsedPlugin";
14
15
  class FlagAllModulesAsUsedPlugin {
16
+ /**
17
+ * @param {string} explanation explanation
18
+ */
15
19
  constructor(explanation) {
16
20
  this.explanation = explanation;
17
21
  }
@@ -40,7 +44,8 @@ class FlagAllModulesAsUsedPlugin {
40
44
  if (module.factoryMeta === undefined) {
41
45
  module.factoryMeta = {};
42
46
  }
43
- module.factoryMeta.sideEffectFree = false;
47
+ /** @type {FactoryMeta} */
48
+ (module.factoryMeta).sideEffectFree = false;
44
49
  }
45
50
  });
46
51
  });
@@ -332,7 +332,9 @@ class FlagDependencyUsagePlugin {
332
332
  }
333
333
 
334
334
  while (queue.length) {
335
- const [module, runtime] = queue.dequeue();
335
+ const [module, runtime] = /** @type {[Module, RuntimeSpec]} */ (
336
+ queue.dequeue()
337
+ );
336
338
  processModule(module, runtime, false);
337
339
  }
338
340
  logger.timeEnd("trace exports usage in graph");
@@ -12,6 +12,10 @@ const { getEntryRuntime } = require("./util/runtime");
12
12
  const PLUGIN_NAME = "FlagEntryExportAsUsedPlugin";
13
13
 
14
14
  class FlagEntryExportAsUsedPlugin {
15
+ /**
16
+ * @param {boolean} nsObjectUsed true, if the ns object is used
17
+ * @param {string} explanation explanation for the reason
18
+ */
15
19
  constructor(nsObjectUsed, explanation) {
16
20
  this.nsObjectUsed = nsObjectUsed;
17
21
  this.explanation = explanation;
@@ -189,6 +189,10 @@ class HotModuleReplacementPlugin {
189
189
  return true;
190
190
  };
191
191
 
192
+ /**
193
+ * @param {JavascriptParser} parser the parser
194
+ * @returns {void}
195
+ */
192
196
  const applyModuleHot = parser => {
193
197
  parser.hooks.evaluateIdentifier.for("module.hot").tap(
194
198
  {
@@ -221,6 +225,10 @@ class HotModuleReplacementPlugin {
221
225
  .tap(PLUGIN_NAME, createHMRExpressionHandler(parser));
222
226
  };
223
227
 
228
+ /**
229
+ * @param {JavascriptParser} parser the parser
230
+ * @returns {void}
231
+ */
224
232
  const applyImportMetaHot = parser => {
225
233
  parser.hooks.evaluateIdentifier
226
234
  .for("import.meta.webpackHot")
@@ -10,17 +10,21 @@ const makeSerializable = require("./util/makeSerializable");
10
10
 
11
11
  /** @typedef {import("webpack-sources").Source} Source */
12
12
  /** @typedef {import("./Generator").GenerateContext} GenerateContext */
13
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
14
+ /** @typedef {import("./serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
13
15
 
14
16
  /**
15
- * @param {InitFragment} fragment the init fragment
17
+ * @template T
18
+ * @param {InitFragment<T>} fragment the init fragment
16
19
  * @param {number} index index
17
- * @returns {[InitFragment, number]} tuple with both
20
+ * @returns {[InitFragment<T>, number]} tuple with both
18
21
  */
19
22
  const extractFragmentIndex = (fragment, index) => [fragment, index];
20
23
 
21
24
  /**
22
- * @param {[InitFragment, number]} a first pair
23
- * @param {[InitFragment, number]} b second pair
25
+ * @template T
26
+ * @param {[InitFragment<T>, number]} a first pair
27
+ * @param {[InitFragment<T>, number]} b second pair
24
28
  * @returns {number} sort value
25
29
  */
26
30
  const sortFragmentWithIndex = ([a, i], [b, j]) => {
@@ -66,6 +70,14 @@ class InitFragment {
66
70
  return this.endContent;
67
71
  }
68
72
 
73
+ /**
74
+ * @template Context
75
+ * @template T
76
+ * @param {Source} source sources
77
+ * @param {InitFragment<T>[]} initFragments init fragments
78
+ * @param {Context} context context
79
+ * @returns {Source} source
80
+ */
69
81
  static addToSource(source, initFragments, context) {
70
82
  if (initFragments.length > 0) {
71
83
  // Sort fragments by position. If 2 fragments have the same position,
@@ -77,7 +89,12 @@ class InitFragment {
77
89
  // Deduplicate fragments. If a fragment has no key, it is always included.
78
90
  const keyedFragments = new Map();
79
91
  for (const [fragment] of sortedFragments) {
80
- if (typeof fragment.mergeAll === "function") {
92
+ if (
93
+ typeof (
94
+ /** @type {InitFragment<T> & { mergeAll?: (fragments: InitFragment[]) => InitFragment[] }} */
95
+ (fragment).mergeAll
96
+ ) === "function"
97
+ ) {
81
98
  if (!fragment.key) {
82
99
  throw new Error(
83
100
  `InitFragment with mergeAll function must have a valid key: ${fragment.constructor.name}`
@@ -125,6 +142,9 @@ class InitFragment {
125
142
  }
126
143
  }
127
144
 
145
+ /**
146
+ * @param {ObjectSerializerContext} context context
147
+ */
128
148
  serialize(context) {
129
149
  const { write } = context;
130
150
 
@@ -135,6 +155,9 @@ class InitFragment {
135
155
  write(this.endContent);
136
156
  }
137
157
 
158
+ /**
159
+ * @param {ObjectDeserializerContext} context context
160
+ */
138
161
  deserialize(context) {
139
162
  const { read } = context;
140
163
 
@@ -13,6 +13,7 @@ const {
13
13
  const InnerGraph = require("./optimize/InnerGraph");
14
14
 
15
15
  /** @typedef {import("./Compiler")} Compiler */
16
+ /** @typedef {import("./Module").BuildInfo} BuildInfo */
16
17
  /** @typedef {import("./javascript/JavascriptParser")} JavascriptParser */
17
18
 
18
19
  const PLUGIN_NAME = "JavascriptMetaInfoPlugin";
@@ -33,8 +34,11 @@ class JavascriptMetaInfoPlugin {
33
34
  */
34
35
  const handler = parser => {
35
36
  parser.hooks.call.for("eval").tap(PLUGIN_NAME, () => {
36
- parser.state.module.buildInfo.moduleConcatenationBailout = "eval()";
37
- parser.state.module.buildInfo.usingEval = true;
37
+ const buildInfo =
38
+ /** @type {BuildInfo} */
39
+ (parser.state.module.buildInfo);
40
+ buildInfo.moduleConcatenationBailout = "eval()";
41
+ buildInfo.usingEval = true;
38
42
  const currentSymbol = InnerGraph.getTopLevelSymbol(parser.state);
39
43
  if (currentSymbol) {
40
44
  InnerGraph.addUsage(parser.state, null, currentSymbol);
@@ -43,11 +47,12 @@ class JavascriptMetaInfoPlugin {
43
47
  }
44
48
  });
45
49
  parser.hooks.finish.tap(PLUGIN_NAME, () => {
46
- let topLevelDeclarations =
47
- parser.state.module.buildInfo.topLevelDeclarations;
50
+ const buildInfo =
51
+ /** @type {BuildInfo} */
52
+ (parser.state.module.buildInfo);
53
+ let topLevelDeclarations = buildInfo.topLevelDeclarations;
48
54
  if (topLevelDeclarations === undefined) {
49
- topLevelDeclarations =
50
- parser.state.module.buildInfo.topLevelDeclarations = new Set();
55
+ topLevelDeclarations = buildInfo.topLevelDeclarations = new Set();
51
56
  }
52
57
  for (const name of parser.scope.definitions.asSet()) {
53
58
  const freeInfo = parser.getFreeInfoFromVariable(name);
@@ -12,15 +12,29 @@ const { compareModulesById } = require("./util/comparators");
12
12
  const { dirname, mkdirp } = require("./util/fs");
13
13
 
14
14
  /** @typedef {import("./Compiler")} Compiler */
15
+ /** @typedef {import("./Module").BuildMeta} BuildMeta */
15
16
 
16
17
  /**
17
18
  * @typedef {Object} ManifestModuleData
18
19
  * @property {string | number} id
19
- * @property {Object} buildMeta
20
- * @property {boolean | string[]} exports
20
+ * @property {BuildMeta} buildMeta
21
+ * @property {boolean | string[] | undefined} exports
22
+ */
23
+
24
+ /**
25
+ * @typedef {Object} LibManifestPluginOptions
26
+ * @property {string=} context Context of requests in the manifest file (defaults to the webpack context).
27
+ * @property {boolean=} entryOnly If true, only entry points will be exposed (default: true).
28
+ * @property {boolean=} format If true, manifest json file (output) will be formatted.
29
+ * @property {string=} name Name of the exposed dll function (external name, use value of 'output.library').
30
+ * @property {string} path Absolute path to the manifest json file (output).
31
+ * @property {string=} type Type of the dll bundle (external type, use value of 'output.libraryTarget').
21
32
  */
22
33
 
23
34
  class LibManifestPlugin {
35
+ /**
36
+ * @param {LibManifestPluginOptions} options the options
37
+ */
24
38
  constructor(options) {
25
39
  this.options = options;
26
40
  }
@@ -67,7 +81,9 @@ class LibManifestPlugin {
67
81
  continue;
68
82
  }
69
83
  const ident = module.libIdent({
70
- context: this.options.context || compiler.options.context,
84
+ context:
85
+ this.options.context ||
86
+ /** @type {string} */ (compiler.options.context),
71
87
  associatedObjectForCache: compiler.root
72
88
  });
73
89
  if (ident) {
@@ -76,7 +92,7 @@ class LibManifestPlugin {
76
92
  /** @type {ManifestModuleData} */
77
93
  const data = {
78
94
  id: chunkGraph.getModuleId(module),
79
- buildMeta: module.buildMeta,
95
+ buildMeta: /** @type {BuildMeta} */ (module.buildMeta),
80
96
  exports: Array.isArray(providedExports)
81
97
  ? providedExports
82
98
  : undefined
package/lib/Module.js CHANGED
@@ -109,6 +109,11 @@ const makeSerializable = require("./util/makeSerializable");
109
109
  /** @typedef {KnownBuildMeta & Record<string, any>} BuildMeta */
110
110
  /** @typedef {Record<string, any>} BuildInfo */
111
111
 
112
+ /**
113
+ * @typedef {Object} FactoryMeta
114
+ * @property {boolean=} sideEffectFree
115
+ */
116
+
112
117
  const EMPTY_RESOLVE_OPTIONS = {};
113
118
 
114
119
  let debugId = 1000;
@@ -159,7 +164,7 @@ class Module extends DependenciesBlock {
159
164
  // Info from Factory
160
165
  /** @type {ResolveOptions | undefined} */
161
166
  this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
162
- /** @type {object | undefined} */
167
+ /** @type {FactoryMeta | undefined} */
163
168
  this.factoryMeta = undefined;
164
169
  // TODO refactor this -> options object filled from Factory
165
170
  // TODO webpack 6: use an enum
@@ -439,7 +444,7 @@ class Module extends DependenciesBlock {
439
444
 
440
445
  /**
441
446
  * @param {ModuleGraph} moduleGraph the module graph
442
- * @param {boolean} strict the importing module is strict
447
+ * @param {boolean | undefined} strict the importing module is strict
443
448
  * @returns {"namespace" | "default-only" | "default-with-named" | "dynamic"} export type
444
449
  * "namespace": Exports is already a namespace object. namespace = exports.
445
450
  * "dynamic": Check at runtime if __esModule is set. When set: namespace = { ...exports, default: exports }. When not set: namespace = { default: exports }.
@@ -23,7 +23,7 @@ class ModuleDependencyError extends WebpackError {
23
23
  this.name = "ModuleDependencyError";
24
24
  this.details =
25
25
  err && !(/** @type {any} */ (err).hideStack)
26
- ? err.stack.split("\n").slice(1).join("\n")
26
+ ? /** @type {string} */ (err.stack).split("\n").slice(1).join("\n")
27
27
  : undefined;
28
28
  this.module = module;
29
29
  this.loc = loc;
@@ -32,7 +32,9 @@ class ModuleDependencyError extends WebpackError {
32
32
 
33
33
  if (err && /** @type {any} */ (err).hideStack) {
34
34
  this.stack =
35
- err.stack.split("\n").slice(1).join("\n") + "\n\n" + this.stack;
35
+ /** @type {string} */ (err.stack).split("\n").slice(1).join("\n") +
36
+ "\n\n" +
37
+ this.stack;
36
38
  }
37
39
  }
38
40
  }
@@ -23,7 +23,7 @@ class ModuleDependencyWarning extends WebpackError {
23
23
  this.name = "ModuleDependencyWarning";
24
24
  this.details =
25
25
  err && !(/** @type {any} */ (err).hideStack)
26
- ? err.stack.split("\n").slice(1).join("\n")
26
+ ? /** @type {string} */ (err.stack).split("\n").slice(1).join("\n")
27
27
  : undefined;
28
28
  this.module = module;
29
29
  this.loc = loc;
@@ -32,7 +32,9 @@ class ModuleDependencyWarning extends WebpackError {
32
32
 
33
33
  if (err && /** @type {any} */ (err).hideStack) {
34
34
  this.stack =
35
- err.stack.split("\n").slice(1).join("\n") + "\n\n" + this.stack;
35
+ /** @type {string} */ (err.stack).split("\n").slice(1).join("\n") +
36
+ "\n\n" +
37
+ this.stack;
36
38
  }
37
39
  }
38
40
  }