webpack 5.90.3 → 5.92.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 (257) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +14 -6
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +8 -2
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/Chunk.js +7 -4
  9. package/lib/ChunkGraph.js +52 -25
  10. package/lib/ChunkGroup.js +23 -17
  11. package/lib/CleanPlugin.js +8 -6
  12. package/lib/Compilation.js +295 -120
  13. package/lib/Compiler.js +223 -87
  14. package/lib/ConcatenationScope.js +3 -3
  15. package/lib/ConditionalInitFragment.js +4 -5
  16. package/lib/ContextModule.js +95 -41
  17. package/lib/ContextModuleFactory.js +4 -2
  18. package/lib/ContextReplacementPlugin.js +3 -2
  19. package/lib/DefinePlugin.js +18 -6
  20. package/lib/Dependency.js +12 -10
  21. package/lib/DependencyTemplate.js +17 -7
  22. package/lib/DllModule.js +1 -0
  23. package/lib/DllReferencePlugin.js +7 -3
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/EvalDevToolModulePlugin.js +11 -0
  28. package/lib/ExportsInfo.js +23 -8
  29. package/lib/ExternalModule.js +160 -35
  30. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  31. package/lib/FileSystemInfo.js +69 -42
  32. package/lib/FlagDependencyExportsPlugin.js +21 -7
  33. package/lib/Generator.js +4 -4
  34. package/lib/HookWebpackError.js +2 -2
  35. package/lib/HotModuleReplacementPlugin.js +108 -45
  36. package/lib/IgnorePlugin.js +4 -1
  37. package/lib/InitFragment.js +5 -3
  38. package/lib/LibManifestPlugin.js +17 -9
  39. package/lib/Module.js +41 -14
  40. package/lib/ModuleFactory.js +3 -3
  41. package/lib/ModuleFilenameHelpers.js +30 -17
  42. package/lib/ModuleGraph.js +60 -31
  43. package/lib/ModuleGraphConnection.js +2 -1
  44. package/lib/MultiCompiler.js +62 -9
  45. package/lib/NodeStuffPlugin.js +14 -3
  46. package/lib/NormalModule.js +13 -13
  47. package/lib/NormalModuleFactory.js +18 -9
  48. package/lib/NormalModuleReplacementPlugin.js +5 -1
  49. package/lib/Parser.js +1 -1
  50. package/lib/PlatformPlugin.js +39 -0
  51. package/lib/ProgressPlugin.js +1 -1
  52. package/lib/ProvidePlugin.js +3 -1
  53. package/lib/RawModule.js +2 -1
  54. package/lib/RecordIdsPlugin.js +4 -4
  55. package/lib/ResolverFactory.js +6 -4
  56. package/lib/RuntimeModule.js +4 -4
  57. package/lib/RuntimePlugin.js +1 -0
  58. package/lib/RuntimeTemplate.js +124 -52
  59. package/lib/SourceMapDevToolPlugin.js +4 -1
  60. package/lib/Stats.js +11 -4
  61. package/lib/Template.js +5 -5
  62. package/lib/TemplatedPathPlugin.js +48 -7
  63. package/lib/Watching.js +67 -60
  64. package/lib/WebpackError.js +6 -6
  65. package/lib/WebpackOptionsApply.js +18 -5
  66. package/lib/asset/AssetGenerator.js +15 -0
  67. package/lib/asset/RawDataUrlModule.js +3 -1
  68. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  69. package/lib/buildChunkGraph.js +120 -67
  70. package/lib/cache/IdleFileCachePlugin.js +8 -3
  71. package/lib/cache/MemoryCachePlugin.js +1 -1
  72. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  73. package/lib/cache/PackFileCacheStrategy.js +51 -18
  74. package/lib/cache/ResolverCachePlugin.js +22 -14
  75. package/lib/cache/getLazyHashedEtag.js +2 -2
  76. package/lib/cli.js +5 -5
  77. package/lib/config/browserslistTargetHandler.js +7 -1
  78. package/lib/config/defaults.js +108 -34
  79. package/lib/config/normalization.js +3 -1
  80. package/lib/config/target.js +18 -11
  81. package/lib/container/ContainerEntryDependency.js +2 -1
  82. package/lib/container/ContainerEntryModule.js +4 -2
  83. package/lib/container/ContainerPlugin.js +14 -10
  84. package/lib/container/FallbackModule.js +1 -1
  85. package/lib/container/RemoteRuntimeModule.js +12 -3
  86. package/lib/css/CssExportsGenerator.js +68 -25
  87. package/lib/css/CssGenerator.js +34 -6
  88. package/lib/css/CssLoadingRuntimeModule.js +217 -98
  89. package/lib/css/CssModulesPlugin.js +238 -107
  90. package/lib/css/CssParser.js +24 -15
  91. package/lib/css/walkCssTokens.js +1 -1
  92. package/lib/debug/ProfilingPlugin.js +28 -3
  93. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  94. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  95. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  96. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  97. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  98. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  99. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  100. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  101. package/lib/dependencies/ContextElementDependency.js +8 -1
  102. package/lib/dependencies/CssExportDependency.js +2 -2
  103. package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
  104. package/lib/dependencies/CssUrlDependency.js +10 -7
  105. package/lib/dependencies/ExportsInfoDependency.js +5 -4
  106. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  107. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  108. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  109. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  110. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  111. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  112. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  113. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  114. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
  115. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  116. package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
  117. package/lib/dependencies/ImportDependency.js +9 -2
  118. package/lib/dependencies/ImportEagerDependency.js +4 -2
  119. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  120. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  121. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  122. package/lib/dependencies/ImportParserPlugin.js +15 -5
  123. package/lib/dependencies/ImportWeakDependency.js +4 -2
  124. package/lib/dependencies/LoaderDependency.js +2 -1
  125. package/lib/dependencies/LoaderImportDependency.js +2 -1
  126. package/lib/dependencies/LoaderPlugin.js +2 -2
  127. package/lib/dependencies/ModuleDependency.js +4 -5
  128. package/lib/dependencies/PureExpressionDependency.js +64 -47
  129. package/lib/dependencies/RequireContextPlugin.js +1 -1
  130. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  131. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  132. package/lib/dependencies/URLDependency.js +7 -4
  133. package/lib/dependencies/WorkerDependency.js +1 -1
  134. package/lib/dependencies/WorkerPlugin.js +2 -1
  135. package/lib/dependencies/getFunctionExpression.js +3 -1
  136. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
  137. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  138. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  139. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  140. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  141. package/lib/ids/IdHelpers.js +6 -6
  142. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  143. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  144. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  145. package/lib/index.js +11 -0
  146. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  147. package/lib/javascript/ChunkHelpers.js +2 -2
  148. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  149. package/lib/javascript/JavascriptGenerator.js +0 -1
  150. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  151. package/lib/javascript/JavascriptParser.js +204 -71
  152. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  153. package/lib/javascript/StartupHelpers.js +22 -5
  154. package/lib/library/AbstractLibraryPlugin.js +2 -2
  155. package/lib/library/AmdLibraryPlugin.js +2 -2
  156. package/lib/library/AssignLibraryPlugin.js +3 -3
  157. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  158. package/lib/library/JsonpLibraryPlugin.js +2 -2
  159. package/lib/library/ModuleLibraryPlugin.js +2 -2
  160. package/lib/library/SystemLibraryPlugin.js +2 -2
  161. package/lib/library/UmdLibraryPlugin.js +33 -12
  162. package/lib/logging/Logger.js +27 -2
  163. package/lib/logging/createConsoleLogger.js +13 -9
  164. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  165. package/lib/node/NodeEnvironmentPlugin.js +14 -8
  166. package/lib/node/NodeTemplatePlugin.js +1 -1
  167. package/lib/node/NodeWatchFileSystem.js +37 -26
  168. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  169. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  170. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/node/nodeConsole.js +24 -1
  172. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  173. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  174. package/lib/optimize/ConcatenatedModule.js +140 -121
  175. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  176. package/lib/optimize/InnerGraph.js +8 -3
  177. package/lib/optimize/InnerGraphPlugin.js +36 -13
  178. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  179. package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
  180. package/lib/optimize/RealContentHashPlugin.js +3 -3
  181. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  182. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  183. package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
  184. package/lib/optimize/SplitChunksPlugin.js +10 -10
  185. package/lib/performance/SizeLimitsPlugin.js +13 -2
  186. package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
  187. package/lib/rules/RuleSetCompiler.js +9 -7
  188. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  189. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  190. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  191. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  192. package/lib/schemes/HttpUriPlugin.js +1 -1
  193. package/lib/serialization/BinaryMiddleware.js +4 -4
  194. package/lib/serialization/FileMiddleware.js +4 -3
  195. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  196. package/lib/serialization/ObjectMiddleware.js +8 -5
  197. package/lib/serialization/PlainObjectSerializer.js +2 -2
  198. package/lib/serialization/Serializer.js +19 -0
  199. package/lib/serialization/SerializerMiddleware.js +2 -2
  200. package/lib/serialization/SingleItemMiddleware.js +2 -2
  201. package/lib/serialization/types.js +1 -1
  202. package/lib/sharing/ConsumeSharedModule.js +2 -2
  203. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  204. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  205. package/lib/sharing/ProvideSharedPlugin.js +13 -6
  206. package/lib/sharing/resolveMatchedConfigs.js +3 -3
  207. package/lib/sharing/utils.js +13 -6
  208. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  209. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  210. package/lib/stats/StatsFactory.js +2 -2
  211. package/lib/stats/StatsPrinter.js +6 -6
  212. package/lib/util/ArrayQueue.js +14 -21
  213. package/lib/util/AsyncQueue.js +1 -1
  214. package/lib/util/Queue.js +8 -2
  215. package/lib/util/SortableSet.js +16 -4
  216. package/lib/util/StackedCacheMap.js +26 -0
  217. package/lib/util/TupleQueue.js +8 -2
  218. package/lib/util/WeakTupleMap.js +57 -13
  219. package/lib/util/binarySearchBounds.js +1 -1
  220. package/lib/util/cleverMerge.js +26 -13
  221. package/lib/util/comparators.js +37 -15
  222. package/lib/util/conventions.js +129 -0
  223. package/lib/util/createHash.js +3 -5
  224. package/lib/util/deprecation.js +3 -3
  225. package/lib/util/deterministicGrouping.js +2 -2
  226. package/lib/util/findGraphRoots.js +1 -1
  227. package/lib/util/fs.js +383 -69
  228. package/lib/util/hash/BatchedHash.js +3 -0
  229. package/lib/util/hash/xxhash64.js +2 -2
  230. package/lib/util/identifier.js +5 -5
  231. package/lib/util/mergeScope.js +79 -0
  232. package/lib/util/runtime.js +2 -17
  233. package/lib/util/semver.js +3 -0
  234. package/lib/util/smartGrouping.js +3 -3
  235. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  236. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  237. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  238. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  239. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
  240. package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
  241. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  242. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  243. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  244. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  245. package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
  246. package/lib/webpack.js +19 -6
  247. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  248. package/package.json +40 -39
  249. package/schemas/WebpackOptions.check.js +1 -1
  250. package/schemas/WebpackOptions.json +97 -8
  251. package/schemas/plugins/BannerPlugin.check.js +1 -1
  252. package/schemas/plugins/BannerPlugin.json +5 -1
  253. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  254. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  255. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  256. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  257. package/types.d.ts +1826 -639
@@ -0,0 +1,79 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /** @typedef {import("eslint-scope").Reference} Reference */
9
+ /** @typedef {import("eslint-scope").Variable} Variable */
10
+ /** @typedef {import("../javascript/JavascriptParser").AnyNode} AnyNode */
11
+ /** @typedef {import("../javascript/JavascriptParser").Program} Program */
12
+
13
+ /**
14
+ * @param {Variable} variable variable
15
+ * @returns {Reference[]} references
16
+ */
17
+ const getAllReferences = variable => {
18
+ let set = variable.references;
19
+ // Look for inner scope variables too (like in class Foo { t() { Foo } })
20
+ const identifiers = new Set(variable.identifiers);
21
+ for (const scope of variable.scope.childScopes) {
22
+ for (const innerVar of scope.variables) {
23
+ if (innerVar.identifiers.some(id => identifiers.has(id))) {
24
+ set = set.concat(innerVar.references);
25
+ break;
26
+ }
27
+ }
28
+ }
29
+ return set;
30
+ };
31
+
32
+ /**
33
+ * @param {Program | Program[]} ast ast
34
+ * @param {AnyNode} node node
35
+ * @returns {undefined | AnyNode[]} result
36
+ */
37
+ const getPathInAst = (ast, node) => {
38
+ if (ast === node) {
39
+ return [];
40
+ }
41
+
42
+ const nr = node.range;
43
+
44
+ const enterNode = n => {
45
+ if (!n) return undefined;
46
+ const r = n.range;
47
+ if (r) {
48
+ if (r[0] <= nr[0] && r[1] >= nr[1]) {
49
+ const path = getPathInAst(n, node);
50
+ if (path) {
51
+ path.push(n);
52
+ return path;
53
+ }
54
+ }
55
+ }
56
+ return undefined;
57
+ };
58
+
59
+ if (Array.isArray(ast)) {
60
+ for (let i = 0; i < ast.length; i++) {
61
+ const enterResult = enterNode(ast[i]);
62
+ if (enterResult !== undefined) return enterResult;
63
+ }
64
+ } else if (ast && typeof ast === "object") {
65
+ const keys = Object.keys(ast);
66
+ for (let i = 0; i < keys.length; i++) {
67
+ const value = ast[keys[i]];
68
+ if (Array.isArray(value)) {
69
+ const pathResult = getPathInAst(value, node);
70
+ if (pathResult !== undefined) return pathResult;
71
+ } else if (value && typeof value === "object") {
72
+ const enterResult = enterNode(value);
73
+ if (enterResult !== undefined) return enterResult;
74
+ }
75
+ }
76
+ }
77
+ };
78
+
79
+ module.exports = { getAllReferences, getPathInAst };
@@ -229,22 +229,6 @@ const mergeRuntime = (a, b) => {
229
229
  };
230
230
  exports.mergeRuntime = mergeRuntime;
231
231
 
232
- /**
233
- * @param {RuntimeSpec[]} runtimes first
234
- * @param {RuntimeSpec} runtime second
235
- * @returns {RuntimeSpec} merged
236
- */
237
- exports.deepMergeRuntime = (runtimes, runtime) => {
238
- if (!Array.isArray(runtimes)) {
239
- return runtime;
240
- }
241
- let merged = runtime;
242
- for (const r of runtimes) {
243
- merged = mergeRuntime(runtime, r);
244
- }
245
- return merged;
246
- };
247
-
248
232
  /**
249
233
  * @param {RuntimeCondition} a first
250
234
  * @param {RuntimeCondition} b second
@@ -390,6 +374,7 @@ const subtractRuntime = (a, b) => {
390
374
  }
391
375
  const set = new SortableSet(a);
392
376
  set.delete(b);
377
+ return set;
393
378
  } else {
394
379
  const set = new SortableSet();
395
380
  for (const item of a) {
@@ -445,7 +430,7 @@ exports.filterRuntime = (runtime, filter) => {
445
430
  /**
446
431
  * @template T
447
432
  * @typedef {Map<string, T>} RuntimeSpecMapInnerMap
448
- * */
433
+ */
449
434
 
450
435
  /**
451
436
  * @template T
@@ -153,6 +153,9 @@ exports.parseRange = str => {
153
153
  }
154
154
  return [1, ...remainder.slice(1)];
155
155
  case "~":
156
+ if (remainder.length === 2 && remainder[0] === 0) {
157
+ return [1, ...remainder.slice(1)];
158
+ }
156
159
  return [2, ...remainder.slice(1)];
157
160
  case ">=":
158
161
  return remainder;
@@ -6,7 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  /**
9
- * @typedef {Object} GroupOptions
9
+ * @typedef {object} GroupOptions
10
10
  * @property {boolean=} groupChildren
11
11
  * @property {boolean=} force
12
12
  * @property {number=} targetGroupCount
@@ -15,7 +15,7 @@
15
15
  /**
16
16
  * @template T
17
17
  * @template R
18
- * @typedef {Object} GroupConfig
18
+ * @typedef {object} GroupConfig
19
19
  * @property {function(T): string[]} getKeys
20
20
  * @property {function(string, (R | T)[], T[]): R} createGroup
21
21
  * @property {function(string, T[]): GroupOptions=} getOptions
@@ -24,7 +24,7 @@
24
24
  /**
25
25
  * @template T
26
26
  * @template R
27
- * @typedef {Object} ItemWithGroups
27
+ * @typedef {object} ItemWithGroups
28
28
  * @property {T} item
29
29
  * @property {Set<Group<T, R>>} groups
30
30
  */
@@ -13,7 +13,7 @@ const Template = require("../Template");
13
13
  /** @typedef {import("../Compilation")} Compilation */
14
14
 
15
15
  /**
16
- * @typedef {Object} AsyncWasmLoadingRuntimeModuleOptions
16
+ * @typedef {object} AsyncWasmLoadingRuntimeModuleOptions
17
17
  * @property {function(string): string} generateLoadBinaryCode
18
18
  * @property {boolean} supportsStreaming
19
19
  */
@@ -69,7 +69,9 @@ class AsyncWasmLoadingRuntimeModule extends RuntimeModule {
69
69
  const concat = (/** @type {string[]} */ ...text) => text.join("");
70
70
  return [
71
71
  `var req = ${loader};`,
72
- `var fallback = ${runtimeTemplate.returningFunction(Template.asString(["req", Template.indent(fallback)]))};`,
72
+ `var fallback = ${runtimeTemplate.returningFunction(
73
+ Template.asString(["req", Template.indent(fallback)])
74
+ )};`,
73
75
  concat(
74
76
  "return req.then(",
75
77
  runtimeTemplate.basicFunction("res", [
@@ -14,7 +14,7 @@ const Generator = require("../Generator");
14
14
  const TYPES = new Set(["webassembly"]);
15
15
 
16
16
  /**
17
- * @typedef {Object} AsyncWebAssemblyGeneratorOptions
17
+ * @typedef {object} AsyncWebAssemblyGeneratorOptions
18
18
  * @property {boolean} [mangleImports] mangle imports
19
19
  */
20
20
 
@@ -77,7 +77,7 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
77
77
  const wasmDepsByRequest = new Map();
78
78
  for (const dep of module.dependencies) {
79
79
  if (dep instanceof WebAssemblyImportDependency) {
80
- const module = moduleGraph.getModule(dep);
80
+ const module = /** @type {Module} */ (moduleGraph.getModule(dep));
81
81
  if (!depModules.has(module)) {
82
82
  depModules.set(module, {
83
83
  request: dep.request,
@@ -120,7 +120,9 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
120
120
  wasmDepsByRequest,
121
121
  ([request, deps]) => {
122
122
  const exportItems = deps.map(dep => {
123
- const importedModule = moduleGraph.getModule(dep);
123
+ const importedModule =
124
+ /** @type {Module} */
125
+ (moduleGraph.getModule(dep));
124
126
  const importVar =
125
127
  /** @type {ImportObjRequestItem} */
126
128
  (depModules.get(importedModule)).importVar;
@@ -39,7 +39,7 @@ const getAsyncWebAssemblyParser = memoize(() =>
39
39
  );
40
40
 
41
41
  /**
42
- * @typedef {Object} WebAssemblyRenderContext
42
+ * @typedef {object} WebAssemblyRenderContext
43
43
  * @property {Chunk} chunk the chunk
44
44
  * @property {DependencyTemplates} dependencyTemplates the dependency templates
45
45
  * @property {RuntimeTemplate} runtimeTemplate the runtime template
@@ -49,12 +49,12 @@ const getAsyncWebAssemblyParser = memoize(() =>
49
49
  */
50
50
 
51
51
  /**
52
- * @typedef {Object} CompilationHooks
52
+ * @typedef {object} CompilationHooks
53
53
  * @property {SyncWaterfallHook<[Source, Module, WebAssemblyRenderContext]>} renderModuleContent
54
54
  */
55
55
 
56
56
  /**
57
- * @typedef {Object} AsyncWebAssemblyModulesPluginOptions
57
+ * @typedef {object} AsyncWebAssemblyModulesPluginOptions
58
58
  * @property {boolean} [mangleImports] mangle imports
59
59
  */
60
60
 
@@ -15,6 +15,7 @@ const WebAssemblyUtils = require("./WebAssemblyUtils");
15
15
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
16
16
  /** @typedef {import("../Compilation")} Compilation */
17
17
  /** @typedef {import("../Module")} Module */
18
+ /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
18
19
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
19
20
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
20
21
 
@@ -61,6 +62,7 @@ const generateImportObject = (
61
62
  runtime
62
63
  ) => {
63
64
  const moduleGraph = chunkGraph.moduleGraph;
65
+ /** @type {Map<string, string | number>} */
64
66
  const waitForInstances = new Map();
65
67
  const properties = [];
66
68
  const usedWasmDependencies = WebAssemblyUtils.getUsedDependencies(
@@ -85,7 +87,10 @@ const generateImportObject = (
85
87
 
86
88
  if (direct) {
87
89
  const instanceVar = `m${waitForInstances.size}`;
88
- waitForInstances.set(instanceVar, chunkGraph.getModuleId(importedModule));
90
+ waitForInstances.set(
91
+ instanceVar,
92
+ chunkGraph.getModuleId(/** @type {Module} */ (importedModule))
93
+ );
89
94
  properties.push({
90
95
  module,
91
96
  name,
@@ -99,20 +104,24 @@ const generateImportObject = (
99
104
  );
100
105
 
101
106
  const mod = `${RuntimeGlobals.moduleCache}[${JSON.stringify(
102
- chunkGraph.getModuleId(importedModule)
107
+ chunkGraph.getModuleId(/** @type {Module} */ (importedModule))
103
108
  )}]`;
104
109
  const modExports = `${mod}.exports`;
105
110
 
106
111
  const cache = `wasmImportedFuncCache${declarations.length}`;
107
112
  declarations.push(`var ${cache};`);
108
113
 
114
+ const modCode =
115
+ /** @type {Module} */
116
+ (importedModule).type.startsWith("webassembly")
117
+ ? `${mod} ? ${modExports}[${JSON.stringify(usedName)}] : `
118
+ : "";
119
+
109
120
  properties.push({
110
121
  module,
111
122
  name,
112
123
  value: Template.asString([
113
- (importedModule.type.startsWith("webassembly")
114
- ? `${mod} ? ${modExports}[${JSON.stringify(usedName)}] : `
115
- : "") + `function(${params}) {`,
124
+ modCode + `function(${params}) {`,
116
125
  Template.indent([
117
126
  `if(${cache} === undefined) ${cache} = ${modExports};`,
118
127
  `return ${cache}[${JSON.stringify(usedName)}](${params});`
@@ -201,11 +210,11 @@ const generateImportObject = (
201
210
  };
202
211
 
203
212
  /**
204
- * @typedef {Object} WasmChunkLoadingRuntimeModuleOptions
213
+ * @typedef {object} WasmChunkLoadingRuntimeModuleOptions
205
214
  * @property {(path: string) => string} generateLoadBinaryCode
206
215
  * @property {boolean} [supportsStreaming]
207
216
  * @property {boolean} [mangleImports]
208
- * @property {Set<string>} runtimeRequirements
217
+ * @property {ReadOnlyRuntimeRequirements} runtimeRequirements
209
218
  */
210
219
 
211
220
  class WasmChunkLoadingRuntimeModule extends RuntimeModule {
@@ -25,6 +25,14 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
25
25
  /** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
26
26
  /** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
27
27
  /** @typedef {import("./WebAssemblyUtils").UsedWasmDependency} UsedWasmDependency */
28
+ /** @typedef {import("@webassemblyjs/ast").Instruction} Instruction */
29
+ /** @typedef {import("@webassemblyjs/ast").ModuleImport} ModuleImport */
30
+ /** @typedef {import("@webassemblyjs/ast").ModuleExport} ModuleExport */
31
+ /** @typedef {import("@webassemblyjs/ast").Global} Global */
32
+ /**
33
+ * @template T
34
+ * @typedef {import("@webassemblyjs/ast").NodePath<T>} NodePath
35
+ */
28
36
 
29
37
  /**
30
38
  * @typedef {(buf: ArrayBuffer) => ArrayBuffer} ArrayBufferTransform
@@ -32,7 +40,7 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
32
40
 
33
41
  /**
34
42
  * @template T
35
- * @param {Function[]} fns transforms
43
+ * @param {((prev: ArrayBuffer) => ArrayBuffer)[]} fns transforms
36
44
  * @returns {Function} composed transform
37
45
  */
38
46
  const compose = (...fns) => {
@@ -47,7 +55,8 @@ const compose = (...fns) => {
47
55
  /**
48
56
  * Removes the start instruction
49
57
  *
50
- * @param {Object} state unused state
58
+ * @param {object} state state
59
+ * @param {object} state.ast Module's ast
51
60
  * @returns {ArrayBufferTransform} transform
52
61
  */
53
62
  const removeStartFunc = state => bin => {
@@ -61,7 +70,7 @@ const removeStartFunc = state => bin => {
61
70
  /**
62
71
  * Get imported globals
63
72
  *
64
- * @param {Object} ast Module's AST
73
+ * @param {object} ast Module's AST
65
74
  * @returns {t.ModuleImport[]} - nodes
66
75
  */
67
76
  const getImportedGlobals = ast => {
@@ -82,8 +91,8 @@ const getImportedGlobals = ast => {
82
91
  /**
83
92
  * Get the count for imported func
84
93
  *
85
- * @param {Object} ast Module's AST
86
- * @returns {Number} - count
94
+ * @param {object} ast Module's AST
95
+ * @returns {number} - count
87
96
  */
88
97
  const getCountImportedFunc = ast => {
89
98
  let count = 0;
@@ -102,7 +111,7 @@ const getCountImportedFunc = ast => {
102
111
  /**
103
112
  * Get next type index
104
113
  *
105
- * @param {Object} ast Module's AST
114
+ * @param {object} ast Module's AST
106
115
  * @returns {t.Index} - index
107
116
  */
108
117
  const getNextTypeIndex = ast => {
@@ -118,12 +127,12 @@ const getNextTypeIndex = ast => {
118
127
  /**
119
128
  * Get next func index
120
129
  *
121
- * The Func section metadata provide informations for implemented funcs
130
+ * The Func section metadata provide information for implemented funcs
122
131
  * in order to have the correct index we shift the index by number of external
123
132
  * functions.
124
133
  *
125
- * @param {Object} ast Module's AST
126
- * @param {Number} countImportedFunc number of imported funcs
134
+ * @param {object} ast Module's AST
135
+ * @param {number} countImportedFunc number of imported funcs
127
136
  * @returns {t.Index} - index
128
137
  */
129
138
  const getNextFuncIndex = (ast, countImportedFunc) => {
@@ -169,7 +178,9 @@ const createDefaultInitForGlobal = globalType => {
169
178
  *
170
179
  * Note that globals will become mutable.
171
180
  *
172
- * @param {Object} state unused state
181
+ * @param {object} state transformation state
182
+ * @param {object} state.ast Module's ast
183
+ * @param {t.Instruction[]} state.additionalInitCode list of addition instructions for the init function
173
184
  * @returns {ArrayBufferTransform} transform
174
185
  */
175
186
  const rewriteImportedGlobals = state => bin => {
@@ -180,7 +191,7 @@ const rewriteImportedGlobals = state => bin => {
180
191
  bin = editWithAST(state.ast, bin, {
181
192
  ModuleImport(path) {
182
193
  if (t.isGlobalType(path.node.descr)) {
183
- const globalType = path.node.descr;
194
+ const globalType = /** @type {TODO} */ (path.node.descr);
184
195
 
185
196
  globalType.mutability = "var";
186
197
 
@@ -197,6 +208,9 @@ const rewriteImportedGlobals = state => bin => {
197
208
 
198
209
  // in order to preserve non-imported global's order we need to re-inject
199
210
  // those as well
211
+ /**
212
+ * @param {NodePath<Global>} path path
213
+ */
200
214
  Global(path) {
201
215
  const { node } = path;
202
216
  const [init] = node.init;
@@ -234,8 +248,8 @@ const rewriteImportedGlobals = state => bin => {
234
248
 
235
249
  /**
236
250
  * Rewrite the export names
237
- * @param {Object} state state
238
- * @param {Object} state.ast Module's ast
251
+ * @param {object} state state
252
+ * @param {object} state.ast Module's ast
239
253
  * @param {Module} state.module Module
240
254
  * @param {ModuleGraph} state.moduleGraph module graph
241
255
  * @param {Set<string>} state.externalExports Module
@@ -246,6 +260,9 @@ const rewriteExportNames =
246
260
  ({ ast, moduleGraph, module, externalExports, runtime }) =>
247
261
  bin => {
248
262
  return editWithAST(ast, bin, {
263
+ /**
264
+ * @param {NodePath<ModuleExport>} path path
265
+ */
249
266
  ModuleExport(path) {
250
267
  const isExternal = externalExports.has(path.node.name);
251
268
  if (isExternal) {
@@ -259,15 +276,15 @@ const rewriteExportNames =
259
276
  path.remove();
260
277
  return;
261
278
  }
262
- path.node.name = usedName;
279
+ path.node.name = /** @type {string} */ (usedName);
263
280
  }
264
281
  });
265
282
  };
266
283
 
267
284
  /**
268
285
  * Mangle import names and modules
269
- * @param {Object} state state
270
- * @param {Object} state.ast Module's ast
286
+ * @param {object} state state
287
+ * @param {object} state.ast Module's ast
271
288
  * @param {Map<string, UsedWasmDependency>} state.usedDependencyMap mappings to mangle names
272
289
  * @returns {ArrayBufferTransform} transform
273
290
  */
@@ -275,6 +292,9 @@ const rewriteImports =
275
292
  ({ ast, usedDependencyMap }) =>
276
293
  bin => {
277
294
  return editWithAST(ast, bin, {
295
+ /**
296
+ * @param {NodePath<ModuleImport>} path path
297
+ */
278
298
  ModuleImport(path) {
279
299
  const result = usedDependencyMap.get(
280
300
  path.node.module + ":" + path.node.name
@@ -293,8 +313,8 @@ const rewriteImports =
293
313
  *
294
314
  * The init function fills the globals given input arguments.
295
315
  *
296
- * @param {Object} state transformation state
297
- * @param {Object} state.ast Module's ast
316
+ * @param {object} state transformation state
317
+ * @param {object} state.ast Module's ast
298
318
  * @param {t.Identifier} state.initFuncId identifier of the init function
299
319
  * @param {t.Index} state.startAtFuncOffset index of the start function
300
320
  * @param {t.ModuleImport[]} state.importedGlobals list of imported globals
@@ -326,6 +346,7 @@ const addInitFunction =
326
346
  );
327
347
  });
328
348
 
349
+ /** @type {Instruction[]} */
329
350
  const funcBody = [];
330
351
  importedGlobals.forEach((importedGlobal, index) => {
331
352
  const args = [t.indexLiteral(index)];
@@ -397,7 +418,7 @@ const getUsedDependencyMap = (moduleGraph, module, mangle) => {
397
418
  const TYPES = new Set(["webassembly"]);
398
419
 
399
420
  /**
400
- * @typedef {Object} WebAssemblyGeneratorOptions
421
+ * @typedef {object} WebAssemblyGeneratorOptions
401
422
  * @property {boolean} [mangleImports] mangle imports
402
423
  */
403
424
 
@@ -31,7 +31,7 @@ const getWebAssemblyParser = memoize(() => require("./WebAssemblyParser"));
31
31
  const PLUGIN_NAME = "WebAssemblyModulesPlugin";
32
32
 
33
33
  /**
34
- * @typedef {Object} WebAssemblyModulesPluginOptions
34
+ * @typedef {object} WebAssemblyModulesPluginOptions
35
35
  * @property {boolean} [mangleImports] mangle imports
36
36
  */
37
37
 
@@ -97,8 +97,9 @@ class WebAssemblyParser extends Parser {
97
97
  // extract imports and exports
98
98
  /** @type {string[]} */
99
99
  const exports = [];
100
- let jsIncompatibleExports = (state.module.buildMeta.jsIncompatibleExports =
101
- undefined);
100
+ const buildMeta = /** @type {BuildMeta} */ (state.module.buildMeta);
101
+ /** @type {Record<string, string> | undefined} */
102
+ let jsIncompatibleExports = (buildMeta.jsIncompatibleExports = undefined);
102
103
 
103
104
  /** @type {TODO[]} */
104
105
  const importedGlobals = [];
@@ -118,7 +119,8 @@ class WebAssemblyParser extends Parser {
118
119
  if (incompatibleType) {
119
120
  if (jsIncompatibleExports === undefined) {
120
121
  jsIncompatibleExports =
121
- state.module.buildMeta.jsIncompatibleExports = {};
122
+ /** @type {BuildMeta} */
123
+ (state.module.buildMeta).jsIncompatibleExports = {};
122
124
  }
123
125
  jsIncompatibleExports[node.name] = incompatibleType;
124
126
  }
@@ -127,7 +129,8 @@ class WebAssemblyParser extends Parser {
127
129
  exports.push(node.name);
128
130
 
129
131
  if (node.descr && node.descr.exportType === "Global") {
130
- const refNode = importedGlobals[node.descr.id.value];
132
+ const refNode =
133
+ importedGlobals[/** @type {TODO} */ (node.descr.id.value)];
131
134
  if (refNode) {
132
135
  const dep = new WebAssemblyExportImportedDependency(
133
136
  node.name,
@@ -11,7 +11,8 @@ const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDe
11
11
  /** @typedef {import("../Module")} Module */
12
12
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
13
13
 
14
- /** @typedef {Object} UsedWasmDependency
14
+ /**
15
+ * @typedef {object} UsedWasmDependency
15
16
  * @property {WebAssemblyImportDependency} dependency the dependency
16
17
  * @property {string} name the export name
17
18
  * @property {string} module the module name
@@ -17,7 +17,7 @@ const WasmChunkLoadingRuntimeModule = require("../wasm-sync/WasmChunkLoadingRunt
17
17
  const PLUGIN_NAME = "FetchCompileWasmPlugin";
18
18
 
19
19
  /**
20
- * @typedef {Object} FetchCompileWasmPluginOptions
20
+ * @typedef {object} FetchCompileWasmPluginOptions
21
21
  * @property {boolean} [mangleImports] mangle imports
22
22
  */
23
23
 
@@ -15,9 +15,10 @@ const compileBooleanMatcher = require("../util/compileBooleanMatcher");
15
15
 
16
16
  /** @typedef {import("../Chunk")} Chunk */
17
17
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
18
+ /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
18
19
 
19
20
  /**
20
- * @typedef {Object} JsonpCompilationPluginHooks
21
+ * @typedef {object} JsonpCompilationPluginHooks
21
22
  * @property {SyncWaterfallHook<[string, Chunk]>} linkPreload
22
23
  * @property {SyncWaterfallHook<[string, Chunk]>} linkPrefetch
23
24
  */
@@ -48,7 +49,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
48
49
  }
49
50
 
50
51
  /**
51
- * @param {Set<string>} runtimeRequirements runtime requirements
52
+ * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
52
53
  */
53
54
  constructor(runtimeRequirements) {
54
55
  super("jsonp chunk loading", RuntimeModule.STAGE_ATTACH);
package/lib/webpack.js CHANGED
@@ -31,7 +31,7 @@ const getValidateSchema = memoize(() => require("./validateSchema"));
31
31
  /**
32
32
  * @template T
33
33
  * @callback Callback
34
- * @param {(Error | null)=} err
34
+ * @param {Error | null} err
35
35
  * @param {T=} stats
36
36
  * @returns {void}
37
37
  */
@@ -42,7 +42,9 @@ const getValidateSchema = memoize(() => require("./validateSchema"));
42
42
  * @returns {MultiCompiler} a multi-compiler
43
43
  */
44
44
  const createMultiCompiler = (childOptions, options) => {
45
- const compilers = childOptions.map(options => createCompiler(options));
45
+ const compilers = childOptions.map((options, index) =>
46
+ createCompiler(options, index)
47
+ );
46
48
  const compiler = new MultiCompiler(compilers, options);
47
49
  for (const childCompiler of compilers) {
48
50
  if (childCompiler.options.dependencies) {
@@ -57,9 +59,10 @@ const createMultiCompiler = (childOptions, options) => {
57
59
 
58
60
  /**
59
61
  * @param {WebpackOptions} rawOptions options object
62
+ * @param {number} [compilerIndex] index of compiler
60
63
  * @returns {Compiler} a compiler
61
64
  */
62
- const createCompiler = rawOptions => {
65
+ const createCompiler = (rawOptions, compilerIndex) => {
63
66
  const options = getNormalizedWebpackOptions(rawOptions);
64
67
  applyWebpackOptionsBaseDefaults(options);
65
68
  const compiler = new Compiler(
@@ -79,7 +82,13 @@ const createCompiler = rawOptions => {
79
82
  }
80
83
  }
81
84
  }
82
- applyWebpackOptionsDefaults(options);
85
+ const resolvedDefaultOptions = applyWebpackOptionsDefaults(
86
+ options,
87
+ compilerIndex
88
+ );
89
+ if (resolvedDefaultOptions.platform) {
90
+ compiler.platform = resolvedDefaultOptions.platform;
91
+ }
83
92
  compiler.hooks.environment.call();
84
93
  compiler.hooks.afterEnvironment.call();
85
94
  new WebpackOptionsApply().process(options, compiler);
@@ -113,7 +122,7 @@ const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
113
122
  /**
114
123
  * @param {WebpackOptions | (ReadonlyArray<WebpackOptions> & MultiCompilerOptions)} options options
115
124
  * @param {Callback<Stats> & Callback<MultiStats>=} callback callback
116
- * @returns {Compiler | MultiCompiler} Compiler or MultiCompiler
125
+ * @returns {Compiler | MultiCompiler | null} Compiler or MultiCompiler
117
126
  */
118
127
  (options, callback) => {
119
128
  const create = () => {
@@ -156,7 +165,11 @@ const webpack = /** @type {WebpackFunctionSingle & WebpackFunctionMulti} */ (
156
165
  } else {
157
166
  compiler.run((err, stats) => {
158
167
  compiler.close(err2 => {
159
- callback(err || err2, stats);
168
+ callback(
169
+ err || err2,
170
+ /** @type {options extends WebpackOptions ? Stats : MultiStats} */
171
+ (stats)
172
+ );
160
173
  });
161
174
  });
162
175
  }
@@ -18,10 +18,11 @@ const { getUndoPath } = require("../util/identifier");
18
18
  /** @typedef {import("../Chunk")} Chunk */
19
19
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
20
20
  /** @typedef {import("../Compilation")} Compilation */
21
+ /** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
21
22
 
22
23
  class ImportScriptsChunkLoadingRuntimeModule extends RuntimeModule {
23
24
  /**
24
- * @param {Set<string>} runtimeRequirements runtime requirements
25
+ * @param {ReadOnlyRuntimeRequirements} runtimeRequirements runtime requirements
25
26
  * @param {boolean} withCreateScriptUrl with createScriptUrl support
26
27
  */
27
28
  constructor(runtimeRequirements, withCreateScriptUrl) {