webpack 5.83.1 → 5.85.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.

Potentially problematic release.


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

Files changed (232) hide show
  1. package/README.md +2 -2
  2. package/lib/AsyncDependenciesBlock.js +2 -2
  3. package/lib/AutomaticPrefetchPlugin.js +1 -0
  4. package/lib/BannerPlugin.js +4 -0
  5. package/lib/CacheFacade.js +4 -0
  6. package/lib/ChunkGroup.js +5 -1
  7. package/lib/CleanPlugin.js +30 -7
  8. package/lib/CompatibilityPlugin.js +4 -3
  9. package/lib/Compilation.js +3 -3
  10. package/lib/Compiler.js +1 -1
  11. package/lib/ContextModule.js +3 -3
  12. package/lib/ContextModuleFactory.js +1 -1
  13. package/lib/DefinePlugin.js +11 -2
  14. package/lib/DllEntryPlugin.js +5 -0
  15. package/lib/DllModule.js +1 -1
  16. package/lib/DllModuleFactory.js +1 -1
  17. package/lib/EvalSourceMapDevToolPlugin.js +3 -1
  18. package/lib/HookWebpackError.js +1 -1
  19. package/lib/IgnoreErrorModuleFactory.js +1 -1
  20. package/lib/MainTemplate.js +2 -2
  21. package/lib/Module.js +21 -9
  22. package/lib/ModuleFactory.js +1 -1
  23. package/lib/ModuleTypeConstants.js +2 -1
  24. package/lib/NormalModuleFactory.js +1 -1
  25. package/lib/NormalModuleReplacementPlugin.js +4 -2
  26. package/lib/NullFactory.js +1 -1
  27. package/lib/PrefetchPlugin.js +4 -0
  28. package/lib/RecordIdsPlugin.js +4 -4
  29. package/lib/RuntimeModule.js +5 -5
  30. package/lib/RuntimePlugin.js +4 -0
  31. package/lib/RuntimeTemplate.js +7 -7
  32. package/lib/SelfModuleFactory.js +12 -0
  33. package/lib/SourceMapDevToolPlugin.js +9 -2
  34. package/lib/Template.js +3 -2
  35. package/lib/UseStrictPlugin.js +4 -0
  36. package/lib/WarnDeprecatedOptionPlugin.js +7 -0
  37. package/lib/WatchIgnorePlugin.js +4 -0
  38. package/lib/WebpackOptionsApply.js +2 -1
  39. package/lib/asset/AssetGenerator.js +7 -2
  40. package/lib/asset/AssetModulesPlugin.js +7 -1
  41. package/lib/asset/AssetParser.js +4 -1
  42. package/lib/asset/RawDataUrlModule.js +5 -3
  43. package/lib/async-modules/InferAsyncModulesPlugin.js +1 -1
  44. package/lib/cache/PackFileCacheStrategy.js +7 -1
  45. package/lib/config/browserslistTargetHandler.js +3 -3
  46. package/lib/config/defaults.js +240 -73
  47. package/lib/config/normalization.js +104 -71
  48. package/lib/config/target.js +37 -10
  49. package/lib/container/ContainerEntryModule.js +4 -0
  50. package/lib/container/ContainerEntryModuleFactory.js +1 -1
  51. package/lib/container/FallbackDependency.js +7 -0
  52. package/lib/container/FallbackItemDependency.js +3 -0
  53. package/lib/container/FallbackModule.js +5 -1
  54. package/lib/container/FallbackModuleFactory.js +1 -1
  55. package/lib/container/RemoteModule.js +4 -0
  56. package/lib/container/RemoteRuntimeModule.js +2 -1
  57. package/lib/container/RemoteToExternalDependency.js +3 -0
  58. package/lib/css/CssParser.js +168 -73
  59. package/lib/debug/ProfilingPlugin.js +11 -0
  60. package/lib/dependencies/AMDDefineDependency.js +12 -6
  61. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -2
  62. package/lib/dependencies/AMDPlugin.js +7 -0
  63. package/lib/dependencies/AMDRequireArrayDependency.js +5 -0
  64. package/lib/dependencies/AMDRequireContextDependency.js +6 -0
  65. package/lib/dependencies/AMDRequireDependenciesBlock.js +6 -0
  66. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +8 -2
  67. package/lib/dependencies/AMDRequireDependency.js +8 -1
  68. package/lib/dependencies/AMDRequireItemDependency.js +6 -0
  69. package/lib/dependencies/CachedConstDependency.js +6 -0
  70. package/lib/dependencies/CommonJsExportRequireDependency.js +11 -0
  71. package/lib/dependencies/CommonJsExportsDependency.js +8 -0
  72. package/lib/dependencies/CommonJsExportsParserPlugin.js +2 -2
  73. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -1
  74. package/lib/dependencies/CommonJsPlugin.js +28 -12
  75. package/lib/dependencies/CommonJsRequireContextDependency.js +8 -0
  76. package/lib/dependencies/CommonJsRequireDependency.js +7 -0
  77. package/lib/dependencies/CommonJsSelfReferenceDependency.js +8 -0
  78. package/lib/dependencies/ConstDependency.js +2 -1
  79. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  80. package/lib/dependencies/CreateScriptUrlDependency.js +2 -1
  81. package/lib/dependencies/CriticalDependencyWarning.js +3 -0
  82. package/lib/dependencies/CssImportDependency.js +2 -1
  83. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -1
  84. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  85. package/lib/dependencies/CssUrlDependency.js +12 -2
  86. package/lib/dependencies/DelegatedSourceDependency.js +3 -0
  87. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  88. package/lib/dependencies/HarmonyAcceptDependency.js +2 -1
  89. package/lib/dependencies/HarmonyAcceptImportDependency.js +3 -0
  90. package/lib/dependencies/HarmonyDetectionParserPlugin.js +16 -0
  91. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
  92. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -0
  93. package/lib/dependencies/HarmonyExportExpressionDependency.js +8 -0
  94. package/lib/dependencies/HarmonyExportHeaderDependency.js +5 -0
  95. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
  96. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  97. package/lib/dependencies/HarmonyExports.js +3 -1
  98. package/lib/dependencies/HarmonyImportDependency.js +2 -1
  99. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +18 -5
  100. package/lib/dependencies/HarmonyImportSideEffectDependency.js +6 -0
  101. package/lib/dependencies/HarmonyImportSpecifierDependency.js +86 -6
  102. package/lib/dependencies/HarmonyModulesPlugin.js +12 -0
  103. package/lib/dependencies/ImportContextDependency.js +6 -0
  104. package/lib/dependencies/ImportDependency.js +2 -1
  105. package/lib/dependencies/ImportEagerDependency.js +2 -1
  106. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +32 -13
  107. package/lib/dependencies/ImportMetaContextPlugin.js +7 -0
  108. package/lib/dependencies/ImportMetaHotAcceptDependency.js +6 -0
  109. package/lib/dependencies/ImportMetaHotDeclineDependency.js +6 -0
  110. package/lib/dependencies/ImportParserPlugin.js +5 -0
  111. package/lib/dependencies/ImportPlugin.js +7 -0
  112. package/lib/dependencies/ImportWeakDependency.js +2 -1
  113. package/lib/dependencies/LocalModule.js +16 -0
  114. package/lib/dependencies/LocalModuleDependency.js +7 -0
  115. package/lib/dependencies/LocalModulesHelpers.js +18 -0
  116. package/lib/dependencies/ModuleHotAcceptDependency.js +6 -0
  117. package/lib/dependencies/ModuleHotDeclineDependency.js +6 -0
  118. package/lib/dependencies/PrefetchDependency.js +3 -0
  119. package/lib/dependencies/ProvidedDependency.js +2 -1
  120. package/lib/dependencies/PureExpressionDependency.js +2 -1
  121. package/lib/dependencies/RequireContextDependency.js +6 -0
  122. package/lib/dependencies/RequireContextPlugin.js +7 -0
  123. package/lib/dependencies/RequireEnsureDependenciesBlock.js +4 -0
  124. package/lib/dependencies/RequireEnsureDependency.js +8 -2
  125. package/lib/dependencies/RequireEnsureItemDependency.js +3 -0
  126. package/lib/dependencies/RequireEnsurePlugin.js +14 -0
  127. package/lib/dependencies/RequireHeaderDependency.js +5 -1
  128. package/lib/dependencies/RequireIncludeDependency.js +5 -0
  129. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
  130. package/lib/dependencies/RequireIncludePlugin.js +14 -0
  131. package/lib/dependencies/RequireResolveContextDependency.js +8 -0
  132. package/lib/dependencies/RequireResolveDependency.js +6 -0
  133. package/lib/dependencies/RequireResolveHeaderDependency.js +4 -0
  134. package/lib/dependencies/SystemPlugin.js +10 -1
  135. package/lib/dependencies/URLDependency.js +3 -2
  136. package/lib/dependencies/URLPlugin.js +7 -5
  137. package/lib/dependencies/UnsupportedDependency.js +5 -0
  138. package/lib/dependencies/WebAssemblyExportImportedDependency.js +6 -0
  139. package/lib/dependencies/WebpackIsIncludedDependency.js +5 -0
  140. package/lib/dependencies/WorkerDependency.js +2 -1
  141. package/lib/dependencies/WorkerPlugin.js +30 -3
  142. package/lib/dependencies/getFunctionExpression.js +7 -0
  143. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -1
  144. package/lib/esm/ModuleChunkFormatPlugin.js +15 -7
  145. package/lib/esm/ModuleChunkLoadingPlugin.js +9 -0
  146. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +14 -9
  147. package/lib/hmr/LazyCompilationPlugin.js +1 -1
  148. package/lib/ids/ChunkModuleIdRangePlugin.js +11 -0
  149. package/lib/ids/DeterministicChunkIdsPlugin.js +11 -2
  150. package/lib/ids/DeterministicModuleIdsPlugin.js +11 -7
  151. package/lib/ids/HashedModuleIdsPlugin.js +8 -1
  152. package/lib/ids/IdHelpers.js +6 -0
  153. package/lib/ids/NamedChunkIdsPlugin.js +13 -1
  154. package/lib/ids/NamedModuleIdsPlugin.js +14 -3
  155. package/lib/ids/OccurrenceChunkIdsPlugin.js +6 -2
  156. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  157. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
  158. package/lib/javascript/BasicEvaluatedExpression.js +11 -1
  159. package/lib/javascript/ChunkHelpers.js +2 -2
  160. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  161. package/lib/javascript/EnableChunkLoadingPlugin.js +4 -0
  162. package/lib/javascript/JavascriptModulesPlugin.js +36 -31
  163. package/lib/javascript/JavascriptParser.js +586 -192
  164. package/lib/javascript/StartupHelpers.js +2 -2
  165. package/lib/json/JsonGenerator.js +7 -5
  166. package/lib/json/JsonParser.js +1 -1
  167. package/lib/library/AbstractLibraryPlugin.js +4 -0
  168. package/lib/library/AssignLibraryPlugin.js +6 -4
  169. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  170. package/lib/library/ModuleLibraryPlugin.js +6 -3
  171. package/lib/library/SystemLibraryPlugin.js +1 -0
  172. package/lib/library/UmdLibraryPlugin.js +4 -0
  173. package/lib/node/CommonJsChunkLoadingPlugin.js +17 -2
  174. package/lib/node/NodeTemplatePlugin.js +10 -2
  175. package/lib/node/NodeWatchFileSystem.js +1 -1
  176. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +6 -3
  177. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +8 -0
  178. package/lib/node/ReadFileCompileWasmPlugin.js +19 -2
  179. package/lib/node/RequireChunkLoadingRuntimeModule.js +6 -3
  180. package/lib/optimize/ConcatenatedModule.js +1 -1
  181. package/lib/optimize/InnerGraphPlugin.js +11 -4
  182. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  183. package/lib/runtime/AutoPublicPathRuntimeModule.js +5 -1
  184. package/lib/runtime/BaseUriRuntimeModule.js +5 -1
  185. package/lib/runtime/EnsureChunkRuntimeModule.js +3 -0
  186. package/lib/runtime/GetChunkFilenameRuntimeModule.js +35 -16
  187. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  188. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  189. package/lib/runtime/PublicPathRuntimeModule.js +5 -0
  190. package/lib/runtime/StartupChunkDependenciesPlugin.js +15 -0
  191. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +4 -1
  192. package/lib/runtime/StartupEntrypointRuntimeModule.js +8 -5
  193. package/lib/serialization/ArraySerializer.js +22 -6
  194. package/lib/serialization/BinaryMiddleware.js +21 -0
  195. package/lib/serialization/DateObjectSerializer.js +15 -4
  196. package/lib/serialization/ErrorObjectSerializer.js +20 -8
  197. package/lib/serialization/FileMiddleware.js +17 -0
  198. package/lib/serialization/MapObjectSerializer.js +24 -8
  199. package/lib/serialization/NullPrototypeObjectSerializer.js +25 -8
  200. package/lib/serialization/ObjectMiddleware.js +23 -0
  201. package/lib/serialization/PlainObjectSerializer.js +23 -12
  202. package/lib/serialization/RegExpObjectSerializer.js +16 -5
  203. package/lib/serialization/SetObjectSerializer.js +21 -6
  204. package/lib/sharing/ProvideSharedModuleFactory.js +1 -1
  205. package/lib/sharing/ShareRuntimeModule.js +1 -1
  206. package/lib/util/createHash.js +1 -1
  207. package/lib/util/makeSerializable.js +7 -0
  208. package/lib/util/serialization.js +10 -0
  209. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  210. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +9 -1
  211. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +13 -3
  212. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +19 -2
  213. package/lib/wasm-async/AsyncWebAssemblyParser.js +3 -0
  214. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +25 -1
  215. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +14 -5
  216. package/lib/wasm-sync/WebAssemblyGenerator.js +18 -5
  217. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  218. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +12 -1
  219. package/lib/wasm-sync/WebAssemblyParser.js +9 -2
  220. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  221. package/lib/web/FetchCompileAsyncWasmPlugin.js +9 -0
  222. package/lib/web/FetchCompileWasmPlugin.js +19 -2
  223. package/lib/web/JsonpChunkLoadingPlugin.js +9 -0
  224. package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -1
  225. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +9 -0
  226. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -2
  227. package/package.json +3 -3
  228. package/schemas/WebpackOptions.check.js +1 -1
  229. package/schemas/WebpackOptions.json +12 -0
  230. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  231. package/schemas/plugins/SourceMapDevToolPlugin.json +4 -0
  232. package/types.d.ts +655 -290
@@ -6,6 +6,8 @@
6
6
 
7
7
  const { register } = require("./serialization");
8
8
 
9
+ /** @typedef {import("../serialization/ObjectMiddleware").Constructor} Constructor */
10
+
9
11
  class ClassSerializer {
10
12
  constructor(Constructor) {
11
13
  this.Constructor = Constructor;
@@ -25,6 +27,11 @@ class ClassSerializer {
25
27
  }
26
28
  }
27
29
 
30
+ /**
31
+ * @param {Constructor} Constructor the constructor
32
+ * @param {string} request the request which will be required when deserializing
33
+ * @param {string | null} [name] the name to make multiple serializer unique when sharing a request
34
+ */
28
35
  module.exports = (Constructor, request, name = null) => {
29
36
  register(Constructor, request, name, new ClassSerializer(Constructor));
30
37
  };
@@ -11,6 +11,8 @@ const memoize = require("./memoize");
11
11
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
12
12
  /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
13
13
  /** @typedef {import("../serialization/Serializer")} Serializer */
14
+ /** @typedef {typeof import("../util/Hash")} Hash */
15
+ /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
14
16
 
15
17
  const getBinaryMiddleware = memoize(() =>
16
18
  require("../serialization/BinaryMiddleware")
@@ -72,6 +74,9 @@ module.exports = {
72
74
  get MEASURE_END_OPERATION() {
73
75
  return getBinaryMiddleware().MEASURE_END_OPERATION;
74
76
  },
77
+ /**
78
+ * @returns {Serializer} buffer serializer
79
+ */
75
80
  get buffersSerializer() {
76
81
  if (buffersSerializer !== undefined) return buffersSerializer;
77
82
  registerSerializers();
@@ -93,6 +98,11 @@ module.exports = {
93
98
  binaryMiddleware
94
99
  ]));
95
100
  },
101
+ /**
102
+ * @param {IntermediateFileSystem} fs filesystem
103
+ * @param {string | Hash} hashFunction hash function to use
104
+ * @returns {Serializer} file serializer
105
+ */
96
106
  createFileSerializer: (fs, hashFunction) => {
97
107
  registerSerializers();
98
108
  const Serializer = getSerializer();
@@ -9,7 +9,16 @@ const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const RuntimeModule = require("../RuntimeModule");
10
10
  const Template = require("../Template");
11
11
 
12
+ /**
13
+ * @typedef {Object} AsyncWasmLoadingRuntimeModuleOptions
14
+ * @property {function(string): string} generateLoadBinaryCode
15
+ * @property {boolean} supportsStreaming
16
+ */
17
+
12
18
  class AsyncWasmLoadingRuntimeModule extends RuntimeModule {
19
+ /**
20
+ * @param {AsyncWasmLoadingRuntimeModuleOptions} options options
21
+ */
13
22
  constructor({ generateLoadBinaryCode, supportsStreaming }) {
14
23
  super("wasm loading", RuntimeModule.STAGE_NORMAL);
15
24
  this.generateLoadBinaryCode = generateLoadBinaryCode;
@@ -13,7 +13,15 @@ const Generator = require("../Generator");
13
13
 
14
14
  const TYPES = new Set(["webassembly"]);
15
15
 
16
+ /**
17
+ * @typedef {Object} AsyncWebAssemblyGeneratorOptions
18
+ * @property {boolean} [mangleImports] mangle imports
19
+ */
20
+
16
21
  class AsyncWebAssemblyGenerator extends Generator {
22
+ /**
23
+ * @param {AsyncWebAssemblyGeneratorOptions} options options
24
+ */
17
25
  constructor(options) {
18
26
  super();
19
27
  this.options = options;
@@ -46,7 +54,7 @@ class AsyncWebAssemblyGenerator extends Generator {
46
54
  * @returns {Source} generated code
47
55
  */
48
56
  generate(module, generateContext) {
49
- return module.originalSource();
57
+ return /** @type {Source} */ (module.originalSource());
50
58
  }
51
59
  }
52
60
 
@@ -13,6 +13,7 @@ const Template = require("../Template");
13
13
  const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
14
14
 
15
15
  /** @typedef {import("webpack-sources").Source} Source */
16
+ /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
16
17
  /** @typedef {import("../DependencyTemplates")} DependencyTemplates */
17
18
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
18
19
  /** @typedef {import("../Module")} Module */
@@ -21,7 +22,14 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
21
22
 
22
23
  const TYPES = new Set(["webassembly"]);
23
24
 
25
+ /**
26
+ * @typedef {{ request: string, importVar: string }} ImportObjRequestItem
27
+ */
28
+
24
29
  class AsyncWebAssemblyJavascriptGenerator extends Generator {
30
+ /**
31
+ * @param {OutputOptions["webassemblyModuleFilename"]} filenameTemplate template for the WebAssembly module filename
32
+ */
25
33
  constructor(filenameTemplate) {
26
34
  super();
27
35
  this.filenameTemplate = filenameTemplate;
@@ -61,9 +69,9 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
61
69
  runtimeRequirements.add(RuntimeGlobals.moduleId);
62
70
  runtimeRequirements.add(RuntimeGlobals.exports);
63
71
  runtimeRequirements.add(RuntimeGlobals.instantiateWasm);
64
- /** @type {InitFragment[]} */
72
+ /** @type {InitFragment<InitFragment<string>>[]} */
65
73
  const initFragments = [];
66
- /** @type {Map<Module, { request: string, importVar: string }>} */
74
+ /** @type {Map<Module, ImportObjRequestItem>} */
67
75
  const depModules = new Map();
68
76
  /** @type {Map<string, WebAssemblyImportDependency[]>} */
69
77
  const wasmDepsByRequest = new Map();
@@ -113,7 +121,9 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
113
121
  ([request, deps]) => {
114
122
  const exportItems = deps.map(dep => {
115
123
  const importedModule = moduleGraph.getModule(dep);
116
- const importVar = depModules.get(importedModule).importVar;
124
+ const importVar =
125
+ /** @type {ImportObjRequestItem} */
126
+ (depModules.get(importedModule)).importVar;
117
127
  return `${JSON.stringify(
118
128
  dep.name
119
129
  )}: ${runtimeTemplate.exportFromImport({
@@ -15,6 +15,7 @@ const { compareModulesByIdentifier } = require("../util/comparators");
15
15
  const memoize = require("../util/memoize");
16
16
 
17
17
  /** @typedef {import("webpack-sources").Source} Source */
18
+ /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
18
19
  /** @typedef {import("../Chunk")} Chunk */
19
20
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
20
21
  /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
@@ -25,6 +26,7 @@ const memoize = require("../util/memoize");
25
26
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
26
27
  /** @typedef {import("../Template").RenderManifestEntry} RenderManifestEntry */
27
28
  /** @typedef {import("../Template").RenderManifestOptions} RenderManifestOptions */
29
+ /** @typedef {import("../WebpackError")} WebpackError */
28
30
 
29
31
  const getAsyncWebAssemblyGenerator = memoize(() =>
30
32
  require("./AsyncWebAssemblyGenerator")
@@ -51,6 +53,11 @@ const getAsyncWebAssemblyParser = memoize(() =>
51
53
  * @property {SyncWaterfallHook<[Source, Module, WebAssemblyRenderContext]>} renderModuleContent
52
54
  */
53
55
 
56
+ /**
57
+ * @typedef {Object} AsyncWebAssemblyModulesPluginOptions
58
+ * @property {boolean} [mangleImports] mangle imports
59
+ */
60
+
54
61
  /** @type {WeakMap<Compilation, CompilationHooks>} */
55
62
  const compilationHooksMap = new WeakMap();
56
63
 
@@ -81,6 +88,9 @@ class AsyncWebAssemblyModulesPlugin {
81
88
  return hooks;
82
89
  }
83
90
 
91
+ /**
92
+ * @param {AsyncWebAssemblyModulesPluginOptions} options options
93
+ */
84
94
  constructor(options) {
85
95
  this.options = options;
86
96
  }
@@ -140,7 +150,8 @@ class AsyncWebAssemblyModulesPlugin {
140
150
  )) {
141
151
  if (module.type === WEBASSEMBLY_MODULE_TYPE_ASYNC) {
142
152
  const filenameTemplate =
143
- outputOptions.webassemblyModuleFilename;
153
+ /** @type {NonNullable<OutputOptions["webassemblyModuleFilename"]>} */
154
+ (outputOptions.webassemblyModuleFilename);
144
155
 
145
156
  result.push({
146
157
  render: () =>
@@ -178,6 +189,12 @@ class AsyncWebAssemblyModulesPlugin {
178
189
  );
179
190
  }
180
191
 
192
+ /**
193
+ * @param {Module} module the rendered module
194
+ * @param {WebAssemblyRenderContext} renderContext options object
195
+ * @param {CompilationHooks} hooks hooks
196
+ * @returns {Source} the newly generated source from rendering
197
+ */
181
198
  renderModule(module, renderContext, hooks) {
182
199
  const { codeGenerationResults, chunk } = renderContext;
183
200
  try {
@@ -192,7 +209,7 @@ class AsyncWebAssemblyModulesPlugin {
192
209
  "AsyncWebAssemblyModulesPlugin.getCompilationHooks().renderModuleContent"
193
210
  );
194
211
  } catch (e) {
195
- e.module = module;
212
+ /** @type {WebpackError} */ (e).module = module;
196
213
  throw e;
197
214
  }
198
215
  }
@@ -23,6 +23,9 @@ const decoderOpts = {
23
23
  };
24
24
 
25
25
  class WebAssemblyParser extends Parser {
26
+ /**
27
+ * @param {{}=} options parser options
28
+ */
26
29
  constructor(options) {
27
30
  super();
28
31
  this.hooks = Object.freeze({});
@@ -10,14 +10,22 @@ const Template = require("../Template");
10
10
  const { compareModulesByIdentifier } = require("../util/comparators");
11
11
  const WebAssemblyUtils = require("./WebAssemblyUtils");
12
12
 
13
+ /** @typedef {import("../Chunk")} Chunk */
13
14
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
14
15
  /** @typedef {import("../Compilation")} Compilation */
15
16
  /** @typedef {import("../Module")} Module */
17
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
16
18
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
17
19
 
18
20
  // TODO webpack 6 remove the whole folder
19
21
 
20
22
  // Get all wasm modules
23
+ /**
24
+ * @param {ModuleGraph} moduleGraph the module graph
25
+ * @param {ChunkGraph} chunkGraph the chunk graph
26
+ * @param {Chunk} chunk the chunk
27
+ * @returns {Module[]} all wasm modules
28
+ */
21
29
  const getAllWasmModules = (moduleGraph, chunkGraph, chunk) => {
22
30
  const wasmModules = chunk.getAllAsyncChunks();
23
31
  const array = [];
@@ -39,7 +47,7 @@ const getAllWasmModules = (moduleGraph, chunkGraph, chunk) => {
39
47
  * generates the import object function for a module
40
48
  * @param {ChunkGraph} chunkGraph the chunk graph
41
49
  * @param {Module} module the module
42
- * @param {boolean} mangle mangle imports
50
+ * @param {boolean | undefined} mangle mangle imports
43
51
  * @param {string[]} declarations array where declarations are pushed to
44
52
  * @param {RuntimeSpec} runtime the runtime
45
53
  * @returns {string} source code
@@ -188,7 +196,18 @@ const generateImportObject = (
188
196
  }
189
197
  };
190
198
 
199
+ /**
200
+ * @typedef {Object} WasmChunkLoadingRuntimeModuleOptions
201
+ * @property {(path: string) => string} generateLoadBinaryCode
202
+ * @property {boolean} [supportsStreaming]
203
+ * @property {boolean} [mangleImports]
204
+ * @property {Set<string>} runtimeRequirements
205
+ */
206
+
191
207
  class WasmChunkLoadingRuntimeModule extends RuntimeModule {
208
+ /**
209
+ * @param {WasmChunkLoadingRuntimeModuleOptions} options options
210
+ */
192
211
  constructor({
193
212
  generateLoadBinaryCode,
194
213
  supportsStreaming,
@@ -213,6 +232,7 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
213
232
  RuntimeGlobals.hmrDownloadUpdateHandlers
214
233
  );
215
234
  const wasmModules = getAllWasmModules(moduleGraph, chunkGraph, chunk);
235
+ /** @type {string[]} */
216
236
  const declarations = [];
217
237
  const importObjects = wasmModules.map(module => {
218
238
  return generateImportObject(
@@ -226,6 +246,10 @@ class WasmChunkLoadingRuntimeModule extends RuntimeModule {
226
246
  const chunkModuleIdMap = chunkGraph.getChunkModuleIdMap(chunk, m =>
227
247
  m.type.startsWith("webassembly")
228
248
  );
249
+ /**
250
+ * @param {string} content content
251
+ * @returns {string} created import object
252
+ */
229
253
  const createImportObject = content =>
230
254
  mangleImports
231
255
  ? `{ ${JSON.stringify(WebAssemblyUtils.MANGLED_MODULE)}: ${content} }`
@@ -9,6 +9,8 @@ const formatLocation = require("../formatLocation");
9
9
  const UnsupportedWebAssemblyFeatureError = require("./UnsupportedWebAssemblyFeatureError");
10
10
 
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
+ /** @typedef {import("../Dependency")} Dependency */
13
+ /** @typedef {import("../Module")} Module */
12
14
 
13
15
  class WasmFinalizeExportsPlugin {
14
16
  /**
@@ -37,12 +39,13 @@ class WasmFinalizeExportsPlugin {
37
39
  // 2. is active and referenced by a non-WebAssembly module
38
40
  if (
39
41
  connection.isTargetActive(undefined) &&
40
- connection.originModule.type.startsWith("webassembly") ===
42
+ /** @type {Module} */
43
+ (connection.originModule).type.startsWith("webassembly") ===
41
44
  false
42
45
  ) {
43
46
  const referencedExports =
44
47
  compilation.getDependencyReferencedExports(
45
- connection.dependency,
48
+ /** @type {Dependency} */ (connection.dependency),
46
49
  undefined
47
50
  );
48
51
 
@@ -61,9 +64,15 @@ class WasmFinalizeExportsPlugin {
61
64
  // 4. error
62
65
  const error = new UnsupportedWebAssemblyFeatureError(
63
66
  `Export "${name}" with ${jsIncompatibleExports[name]} can only be used for direct wasm to wasm dependencies\n` +
64
- `It's used from ${connection.originModule.readableIdentifier(
65
- compilation.requestShortener
66
- )} at ${formatLocation(connection.dependency.loc)}.`
67
+ `It's used from ${
68
+ /** @type {Module} */
69
+ (connection.originModule).readableIdentifier(
70
+ compilation.requestShortener
71
+ )
72
+ } at ${formatLocation(
73
+ /** @type {Dependency} */ (connection.dependency)
74
+ .loc
75
+ )}.`
67
76
  );
68
77
  error.module = module;
69
78
  compilation.errors.push(error);
@@ -27,7 +27,7 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
27
27
  /** @typedef {import("./WebAssemblyUtils").UsedWasmDependency} UsedWasmDependency */
28
28
 
29
29
  /**
30
- * @typedef {(ArrayBuffer) => ArrayBuffer} ArrayBufferTransform
30
+ * @typedef {(buf: ArrayBuffer) => ArrayBuffer} ArrayBufferTransform
31
31
  */
32
32
 
33
33
  /**
@@ -62,9 +62,10 @@ const removeStartFunc = state => bin => {
62
62
  * Get imported globals
63
63
  *
64
64
  * @param {Object} ast Module's AST
65
- * @returns {Array<t.ModuleImport>} - nodes
65
+ * @returns {t.ModuleImport[]} - nodes
66
66
  */
67
67
  const getImportedGlobals = ast => {
68
+ /** @type {t.ModuleImport[]} */
68
69
  const importedGlobals = [];
69
70
 
70
71
  t.traverse(ast, {
@@ -318,7 +319,10 @@ const addInitFunction =
318
319
  `${importedGlobal.module}.${importedGlobal.name}`
319
320
  );
320
321
 
321
- return t.funcParam(importedGlobal.descr.valtype, id);
322
+ return t.funcParam(
323
+ /** @type {string} */ (importedGlobal.descr.valtype),
324
+ id
325
+ );
322
326
  });
323
327
 
324
328
  const funcBody = [];
@@ -344,6 +348,7 @@ const addInitFunction =
344
348
 
345
349
  funcBody.push(t.instruction("end"));
346
350
 
351
+ /** @type {string[]} */
347
352
  const funcResults = [];
348
353
 
349
354
  // Code section
@@ -369,7 +374,7 @@ const addInitFunction =
369
374
  * Extract mangle mappings from module
370
375
  * @param {ModuleGraph} moduleGraph module graph
371
376
  * @param {Module} module current module
372
- * @param {boolean} mangle mangle imports
377
+ * @param {boolean | undefined} mangle mangle imports
373
378
  * @returns {Map<string, UsedWasmDependency>} mappings to mangled names
374
379
  */
375
380
  const getUsedDependencyMap = (moduleGraph, module, mangle) => {
@@ -390,7 +395,15 @@ const getUsedDependencyMap = (moduleGraph, module, mangle) => {
390
395
 
391
396
  const TYPES = new Set(["webassembly"]);
392
397
 
398
+ /**
399
+ * @typedef {Object} WebAssemblyGeneratorOptions
400
+ * @property {boolean} [mangleImports] mangle imports
401
+ */
402
+
393
403
  class WebAssemblyGenerator extends Generator {
404
+ /**
405
+ * @param {WebAssemblyGeneratorOptions} options options
406
+ */
394
407
  constructor(options) {
395
408
  super();
396
409
  this.options = options;
@@ -423,7 +436,7 @@ class WebAssemblyGenerator extends Generator {
423
436
  * @returns {Source} generated code
424
437
  */
425
438
  generate(module, { moduleGraph, runtime }) {
426
- const bin = module.originalSource().source();
439
+ const bin = /** @type {Source} */ (module.originalSource()).source();
427
440
 
428
441
  const initFuncId = t.identifier("");
429
442
 
@@ -55,7 +55,7 @@ class WebAssemblyJavascriptGenerator extends Generator {
55
55
  runtimeRequirements,
56
56
  runtime
57
57
  } = generateContext;
58
- /** @type {InitFragment[]} */
58
+ /** @type {InitFragment<InitFragment<string>>[]} */
59
59
  const initFragments = [];
60
60
 
61
61
  const exportsInfo = moduleGraph.getExportsInfo(module);
@@ -14,6 +14,7 @@ const memoize = require("../util/memoize");
14
14
  const WebAssemblyInInitialChunkError = require("./WebAssemblyInInitialChunkError");
15
15
 
16
16
  /** @typedef {import("webpack-sources").Source} Source */
17
+ /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
17
18
  /** @typedef {import("../Compiler")} Compiler */
18
19
  /** @typedef {import("../Module")} Module */
19
20
  /** @typedef {import("../ModuleTemplate")} ModuleTemplate */
@@ -29,7 +30,15 @@ const getWebAssemblyParser = memoize(() => require("./WebAssemblyParser"));
29
30
 
30
31
  const PLUGIN_NAME = "WebAssemblyModulesPlugin";
31
32
 
33
+ /**
34
+ * @typedef {Object} WebAssemblyModulesPluginOptions
35
+ * @property {boolean} [mangleImports] mangle imports
36
+ */
37
+
32
38
  class WebAssemblyModulesPlugin {
39
+ /**
40
+ * @param {WebAssemblyModulesPluginOptions} options options
41
+ */
33
42
  constructor(options) {
34
43
  this.options = options;
35
44
  }
@@ -83,7 +92,9 @@ class WebAssemblyModulesPlugin {
83
92
  compareModulesByIdentifier
84
93
  )) {
85
94
  if (module.type === WEBASSEMBLY_MODULE_TYPE_SYNC) {
86
- const filenameTemplate = outputOptions.webassemblyModuleFilename;
95
+ const filenameTemplate =
96
+ /** @type {NonNullable<OutputOptions["webassemblyModuleFilename"]>} */
97
+ (outputOptions.webassemblyModuleFilename);
87
98
 
88
99
  result.push({
89
100
  render: () =>
@@ -61,6 +61,9 @@ const decoderOpts = {
61
61
  };
62
62
 
63
63
  class WebAssemblyParser extends Parser {
64
+ /**
65
+ * @param {{}=} options parser options
66
+ */
64
67
  constructor(options) {
65
68
  super();
66
69
  this.hooks = Object.freeze({});
@@ -88,10 +91,12 @@ class WebAssemblyParser extends Parser {
88
91
  const moduleContext = moduleContextFromModuleAST(module);
89
92
 
90
93
  // extract imports and exports
94
+ /** @type {string[]} */
91
95
  const exports = [];
92
96
  let jsIncompatibleExports = (state.module.buildMeta.jsIncompatibleExports =
93
97
  undefined);
94
98
 
99
+ /** @type {TODO[]} */
95
100
  const importedGlobals = [];
96
101
  t.traverse(module, {
97
102
  ModuleExport({ node }) {
@@ -157,12 +162,14 @@ class WebAssemblyParser extends Parser {
157
162
  } else if (t.isTable(node.descr) === true) {
158
163
  onlyDirectImport = "Table";
159
164
  } else if (t.isFuncImportDescr(node.descr) === true) {
160
- const incompatibleType = getJsIncompatibleType(node.descr.signature);
165
+ const incompatibleType = getJsIncompatibleType(
166
+ /** @type {t.Signature} */ (node.descr.signature)
167
+ );
161
168
  if (incompatibleType) {
162
169
  onlyDirectImport = `Non-JS-compatible Func Signature (${incompatibleType})`;
163
170
  }
164
171
  } else if (t.isGlobalType(node.descr) === true) {
165
- const type = node.descr.valtype;
172
+ const type = /** @type {string} */ (node.descr.valtype);
166
173
  if (!JS_COMPAT_TYPES.has(type)) {
167
174
  onlyDirectImport = `Non-JS-compatible Global Type (${type})`;
168
175
  }
@@ -22,7 +22,7 @@ const MANGLED_MODULE = "a";
22
22
  /**
23
23
  * @param {ModuleGraph} moduleGraph the module graph
24
24
  * @param {Module} module the module
25
- * @param {boolean} mangle mangle module and export names
25
+ * @param {boolean | undefined} mangle mangle module and export names
26
26
  * @returns {UsedWasmDependency[]} used dependencies and (mangled) name
27
27
  */
28
28
  const getUsedDependencies = (moduleGraph, module, mangle) => {
@@ -9,6 +9,7 @@ const { WEBASSEMBLY_MODULE_TYPE_ASYNC } = require("../ModuleTypeConstants");
9
9
  const RuntimeGlobals = require("../RuntimeGlobals");
10
10
  const AsyncWasmLoadingRuntimeModule = require("../wasm-async/AsyncWasmLoadingRuntimeModule");
11
11
 
12
+ /** @typedef {import("../Chunk")} Chunk */
12
13
  /** @typedef {import("../Compiler")} Compiler */
13
14
 
14
15
  class FetchCompileAsyncWasmPlugin {
@@ -22,6 +23,10 @@ class FetchCompileAsyncWasmPlugin {
22
23
  "FetchCompileAsyncWasmPlugin",
23
24
  compilation => {
24
25
  const globalWasmLoading = compilation.outputOptions.wasmLoading;
26
+ /**
27
+ * @param {Chunk} chunk chunk
28
+ * @returns {boolean} true, if wasm loading is enabled for the chunk
29
+ */
25
30
  const isEnabledForChunk = chunk => {
26
31
  const options = chunk.getEntryOptions();
27
32
  const wasmLoading =
@@ -30,6 +35,10 @@ class FetchCompileAsyncWasmPlugin {
30
35
  : globalWasmLoading;
31
36
  return wasmLoading === "fetch";
32
37
  };
38
+ /**
39
+ * @param {string} path path to the wasm file
40
+ * @returns {string} code to load the wasm file
41
+ */
33
42
  const generateLoadBinaryCode = path =>
34
43
  `fetch(${RuntimeGlobals.publicPath} + ${path})`;
35
44
 
@@ -9,15 +9,24 @@ const { WEBASSEMBLY_MODULE_TYPE_SYNC } = require("../ModuleTypeConstants");
9
9
  const RuntimeGlobals = require("../RuntimeGlobals");
10
10
  const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRuntimeModule");
11
11
 
12
+ /** @typedef {import("../Chunk")} Chunk */
12
13
  /** @typedef {import("../Compiler")} Compiler */
13
14
 
14
15
  // TODO webpack 6 remove
15
16
 
16
17
  const PLUGIN_NAME = "FetchCompileWasmPlugin";
17
18
 
19
+ /**
20
+ * @typedef {Object} FetchCompileWasmPluginOptions
21
+ * @property {boolean} [mangleImports] mangle imports
22
+ */
23
+
18
24
  class FetchCompileWasmPlugin {
19
- constructor(options) {
20
- this.options = options || {};
25
+ /**
26
+ * @param {FetchCompileWasmPluginOptions} [options] options
27
+ */
28
+ constructor(options = {}) {
29
+ this.options = options;
21
30
  }
22
31
 
23
32
  /**
@@ -28,6 +37,10 @@ class FetchCompileWasmPlugin {
28
37
  apply(compiler) {
29
38
  compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
30
39
  const globalWasmLoading = compilation.outputOptions.wasmLoading;
40
+ /**
41
+ * @param {Chunk} chunk chunk
42
+ * @returns {boolean} true, if wasm loading is enabled for the chunk
43
+ */
31
44
  const isEnabledForChunk = chunk => {
32
45
  const options = chunk.getEntryOptions();
33
46
  const wasmLoading =
@@ -36,6 +49,10 @@ class FetchCompileWasmPlugin {
36
49
  : globalWasmLoading;
37
50
  return wasmLoading === "fetch";
38
51
  };
52
+ /**
53
+ * @param {string} path path to the wasm file
54
+ * @returns {string} code to load the wasm file
55
+ */
39
56
  const generateLoadBinaryCode = path =>
40
57
  `fetch(${RuntimeGlobals.publicPath} + ${path})`;
41
58
 
@@ -8,6 +8,7 @@
8
8
  const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const JsonpChunkLoadingRuntimeModule = require("./JsonpChunkLoadingRuntimeModule");
10
10
 
11
+ /** @typedef {import("../Chunk")} Chunk */
11
12
  /** @typedef {import("../Compiler")} Compiler */
12
13
 
13
14
  class JsonpChunkLoadingPlugin {
@@ -21,6 +22,10 @@ class JsonpChunkLoadingPlugin {
21
22
  "JsonpChunkLoadingPlugin",
22
23
  compilation => {
23
24
  const globalChunkLoading = compilation.outputOptions.chunkLoading;
25
+ /**
26
+ * @param {Chunk} chunk chunk
27
+ * @returns {boolean} true, if wasm loading is enabled for the chunk
28
+ */
24
29
  const isEnabledForChunk = chunk => {
25
30
  const options = chunk.getEntryOptions();
26
31
  const chunkLoading =
@@ -30,6 +35,10 @@ class JsonpChunkLoadingPlugin {
30
35
  return chunkLoading === "jsonp";
31
36
  };
32
37
  const onceForChunkSet = new WeakSet();
38
+ /**
39
+ * @param {Chunk} chunk chunk
40
+ * @param {Set<string>} set runtime requirements
41
+ */
33
42
  const handler = (chunk, set) => {
34
43
  if (onceForChunkSet.has(chunk)) return;
35
44
  onceForChunkSet.add(chunk);
@@ -46,6 +46,9 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
46
46
  return hooks;
47
47
  }
48
48
 
49
+ /**
50
+ * @param {Set<string>} runtimeRequirements runtime requirements
51
+ */
49
52
  constructor(runtimeRequirements) {
50
53
  super("jsonp chunk loading", RuntimeModule.STAGE_ATTACH);
51
54
  this._runtimeRequirements = runtimeRequirements;
@@ -426,7 +429,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
426
429
  "}"
427
430
  ]),
428
431
  "}",
429
- "if(runtime) var result = runtime(__webpack_require__);"
432
+ `if(runtime) var result = runtime(${RuntimeGlobals.require});`
430
433
  ]),
431
434
  "}",
432
435
  "if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);",
@@ -9,6 +9,7 @@ const RuntimeGlobals = require("../RuntimeGlobals");
9
9
  const StartupChunkDependenciesPlugin = require("../runtime/StartupChunkDependenciesPlugin");
10
10
  const ImportScriptsChunkLoadingRuntimeModule = require("./ImportScriptsChunkLoadingRuntimeModule");
11
11
 
12
+ /** @typedef {import("../Chunk")} Chunk */
12
13
  /** @typedef {import("../Compiler")} Compiler */
13
14
 
14
15
  class ImportScriptsChunkLoadingPlugin {
@@ -26,6 +27,10 @@ class ImportScriptsChunkLoadingPlugin {
26
27
  "ImportScriptsChunkLoadingPlugin",
27
28
  compilation => {
28
29
  const globalChunkLoading = compilation.outputOptions.chunkLoading;
30
+ /**
31
+ * @param {Chunk} chunk chunk
32
+ * @returns {boolean} true, if wasm loading is enabled for the chunk
33
+ */
29
34
  const isEnabledForChunk = chunk => {
30
35
  const options = chunk.getEntryOptions();
31
36
  const chunkLoading =
@@ -35,6 +40,10 @@ class ImportScriptsChunkLoadingPlugin {
35
40
  return chunkLoading === "import-scripts";
36
41
  };
37
42
  const onceForChunkSet = new WeakSet();
43
+ /**
44
+ * @param {Chunk} chunk chunk
45
+ * @param {Set<string>} set runtime requirements
46
+ */
38
47
  const handler = (chunk, set) => {
39
48
  if (onceForChunkSet.has(chunk)) return;
40
49
  onceForChunkSet.add(chunk);