webpack 5.98.0 → 5.99.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 (251) hide show
  1. package/README.md +7 -3
  2. package/lib/AsyncDependenciesBlock.js +3 -1
  3. package/lib/BannerPlugin.js +1 -1
  4. package/lib/Cache.js +9 -7
  5. package/lib/CacheFacade.js +5 -5
  6. package/lib/Chunk.js +2 -2
  7. package/lib/ChunkGraph.js +21 -16
  8. package/lib/ChunkTemplate.js +6 -6
  9. package/lib/CleanPlugin.js +10 -10
  10. package/lib/CodeGenerationResults.js +4 -3
  11. package/lib/CompatibilityPlugin.js +4 -1
  12. package/lib/Compilation.js +326 -152
  13. package/lib/Compiler.js +13 -18
  14. package/lib/ConditionalInitFragment.js +1 -1
  15. package/lib/ConstPlugin.js +5 -3
  16. package/lib/ContextModule.js +4 -2
  17. package/lib/ContextModuleFactory.js +3 -3
  18. package/lib/ContextReplacementPlugin.js +43 -16
  19. package/lib/DefinePlugin.js +25 -24
  20. package/lib/DelegatedModule.js +4 -2
  21. package/lib/DelegatedModuleFactoryPlugin.js +2 -1
  22. package/lib/Dependency.js +19 -13
  23. package/lib/DependencyTemplates.js +4 -3
  24. package/lib/DllModule.js +4 -2
  25. package/lib/DllModuleFactory.js +2 -2
  26. package/lib/DllReferencePlugin.js +2 -1
  27. package/lib/DynamicEntryPlugin.js +1 -1
  28. package/lib/EnvironmentPlugin.js +4 -2
  29. package/lib/ExportsInfo.js +72 -40
  30. package/lib/ExternalModule.js +14 -5
  31. package/lib/ExternalModuleFactoryPlugin.js +24 -12
  32. package/lib/FileSystemInfo.js +129 -94
  33. package/lib/FlagDependencyExportsPlugin.js +6 -4
  34. package/lib/FlagDependencyUsagePlugin.js +1 -1
  35. package/lib/Generator.js +29 -1
  36. package/lib/HookWebpackError.js +2 -2
  37. package/lib/HotModuleReplacementPlugin.js +3 -9
  38. package/lib/IgnoreErrorModuleFactory.js +2 -2
  39. package/lib/IgnorePlugin.js +0 -5
  40. package/lib/InitFragment.js +1 -1
  41. package/lib/LoaderOptionsPlugin.js +8 -5
  42. package/lib/MainTemplate.js +7 -7
  43. package/lib/Module.js +40 -17
  44. package/lib/ModuleBuildError.js +3 -1
  45. package/lib/ModuleDependencyError.js +4 -3
  46. package/lib/ModuleDependencyWarning.js +4 -3
  47. package/lib/ModuleFactory.js +9 -3
  48. package/lib/ModuleFilenameHelpers.js +13 -13
  49. package/lib/ModuleGraph.js +20 -14
  50. package/lib/ModuleGraphConnection.js +7 -13
  51. package/lib/ModuleNotFoundError.js +1 -1
  52. package/lib/ModuleParseError.js +2 -1
  53. package/lib/ModuleSourceTypesConstants.js +11 -0
  54. package/lib/ModuleTemplate.js +5 -5
  55. package/lib/ModuleTypeConstants.js +15 -0
  56. package/lib/MultiCompiler.js +4 -4
  57. package/lib/MultiStats.js +1 -1
  58. package/lib/NormalModule.js +101 -54
  59. package/lib/NormalModuleFactory.js +38 -33
  60. package/lib/NormalModuleReplacementPlugin.js +3 -2
  61. package/lib/NullFactory.js +2 -2
  62. package/lib/Parser.js +4 -3
  63. package/lib/ProgressPlugin.js +1 -2
  64. package/lib/RawModule.js +4 -2
  65. package/lib/RecordIdsPlugin.js +6 -2
  66. package/lib/RequestShortener.js +3 -1
  67. package/lib/ResolverFactory.js +12 -9
  68. package/lib/RuntimeModule.js +4 -2
  69. package/lib/RuntimeTemplate.js +2 -1
  70. package/lib/SelfModuleFactory.js +2 -2
  71. package/lib/SourceMapDevToolPlugin.js +0 -8
  72. package/lib/Template.js +6 -5
  73. package/lib/TemplatedPathPlugin.js +15 -12
  74. package/lib/WebpackOptionsApply.js +1 -1
  75. package/lib/asset/AssetGenerator.js +237 -170
  76. package/lib/asset/AssetModulesPlugin.js +50 -8
  77. package/lib/asset/AssetSourceGenerator.js +18 -0
  78. package/lib/asset/RawDataUrlModule.js +4 -2
  79. package/lib/buildChunkGraph.js +14 -4
  80. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  81. package/lib/cache/PackFileCacheStrategy.js +137 -121
  82. package/lib/cache/ResolverCachePlugin.js +15 -7
  83. package/lib/cache/getLazyHashedEtag.js +4 -3
  84. package/lib/cli.js +23 -15
  85. package/lib/config/defaults.js +93 -26
  86. package/lib/config/normalization.js +14 -13
  87. package/lib/config/target.js +8 -8
  88. package/lib/container/ContainerEntryModule.js +4 -2
  89. package/lib/container/ContainerEntryModuleFactory.js +2 -2
  90. package/lib/container/FallbackModule.js +4 -2
  91. package/lib/container/FallbackModuleFactory.js +2 -2
  92. package/lib/container/RemoteModule.js +4 -2
  93. package/lib/container/options.js +5 -5
  94. package/lib/css/CssGenerator.js +71 -9
  95. package/lib/css/CssModulesPlugin.js +30 -5
  96. package/lib/css/CssParser.js +37 -17
  97. package/lib/css/walkCssTokens.js +17 -17
  98. package/lib/debug/ProfilingPlugin.js +98 -38
  99. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +10 -4
  100. package/lib/dependencies/AMDPlugin.js +5 -2
  101. package/lib/dependencies/AMDRequireArrayDependency.js +4 -3
  102. package/lib/dependencies/AMDRequireContextDependency.js +2 -1
  103. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +15 -7
  104. package/lib/dependencies/AMDRuntimeModules.js +3 -1
  105. package/lib/dependencies/CommonJsExportRequireDependency.js +4 -5
  106. package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -3
  107. package/lib/dependencies/CommonJsImportsParserPlugin.js +8 -7
  108. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
  109. package/lib/dependencies/ContextDependencyHelpers.js +13 -6
  110. package/lib/dependencies/CssIcssExportDependency.js +15 -12
  111. package/lib/dependencies/CssIcssImportDependency.js +4 -1
  112. package/lib/dependencies/CssLocalIdentifierDependency.js +17 -14
  113. package/lib/dependencies/ExportsInfoDependency.js +6 -1
  114. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +5 -5
  115. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +22 -15
  116. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +23 -8
  117. package/lib/dependencies/HarmonyExportSpecifierDependency.js +2 -2
  118. package/lib/dependencies/HarmonyImportDependency.js +8 -6
  119. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -14
  120. package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -5
  121. package/lib/dependencies/ImportContextDependency.js +2 -1
  122. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +8 -4
  123. package/lib/dependencies/JsonExportsDependency.js +24 -8
  124. package/lib/dependencies/LoaderPlugin.js +4 -14
  125. package/lib/dependencies/RequireContextDependency.js +2 -1
  126. package/lib/dependencies/RequireContextDependencyParserPlugin.js +6 -3
  127. package/lib/dependencies/RequireEnsureDependenciesBlock.js +3 -2
  128. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +11 -5
  129. package/lib/dependencies/RequireResolveContextDependency.js +1 -1
  130. package/lib/dependencies/WebAssemblyExportImportedDependency.js +1 -1
  131. package/lib/dependencies/WorkerDependency.js +6 -3
  132. package/lib/dependencies/WorkerPlugin.js +100 -41
  133. package/lib/esm/ModuleChunkFormatPlugin.js +5 -0
  134. package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
  135. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
  136. package/lib/hmr/LazyCompilationPlugin.js +32 -24
  137. package/lib/hmr/lazyCompilationBackend.js +1 -1
  138. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  139. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  140. package/lib/ids/IdHelpers.js +15 -14
  141. package/lib/ids/SyncModuleIdsPlugin.js +9 -5
  142. package/lib/index.js +5 -5
  143. package/lib/javascript/BasicEvaluatedExpression.js +6 -6
  144. package/lib/javascript/JavascriptGenerator.js +11 -1
  145. package/lib/javascript/JavascriptModulesPlugin.js +51 -31
  146. package/lib/javascript/JavascriptParser.js +272 -188
  147. package/lib/javascript/JavascriptParserHelpers.js +10 -9
  148. package/lib/javascript/StartupHelpers.js +4 -1
  149. package/lib/json/JsonData.js +4 -4
  150. package/lib/json/JsonGenerator.js +54 -22
  151. package/lib/json/JsonModulesPlugin.js +16 -2
  152. package/lib/json/JsonParser.js +8 -4
  153. package/lib/library/AbstractLibraryPlugin.js +7 -3
  154. package/lib/library/AssignLibraryPlugin.js +29 -1
  155. package/lib/library/EnableLibraryPlugin.js +7 -10
  156. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  157. package/lib/library/ModuleLibraryPlugin.js +121 -15
  158. package/lib/logging/Logger.js +2 -2
  159. package/lib/logging/createConsoleLogger.js +4 -4
  160. package/lib/node/NodeEnvironmentPlugin.js +6 -2
  161. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -2
  162. package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
  163. package/lib/node/nodeConsole.js +3 -1
  164. package/lib/optimize/AggressiveSplittingPlugin.js +1 -1
  165. package/lib/optimize/ConcatenatedModule.js +19 -12
  166. package/lib/optimize/InnerGraph.js +3 -2
  167. package/lib/optimize/InnerGraphPlugin.js +13 -7
  168. package/lib/optimize/LimitChunkCountPlugin.js +20 -0
  169. package/lib/optimize/ModuleConcatenationPlugin.js +10 -7
  170. package/lib/optimize/RealContentHashPlugin.js +8 -4
  171. package/lib/optimize/SideEffectsFlagPlugin.js +4 -2
  172. package/lib/optimize/SplitChunksPlugin.js +87 -65
  173. package/lib/rules/BasicEffectRulePlugin.js +9 -1
  174. package/lib/rules/BasicMatcherRulePlugin.js +15 -4
  175. package/lib/rules/ObjectMatcherRulePlugin.js +12 -3
  176. package/lib/rules/RuleSetCompiler.js +25 -14
  177. package/lib/rules/UseEffectRulePlugin.js +47 -17
  178. package/lib/runtime/GetChunkFilenameRuntimeModule.js +6 -6
  179. package/lib/schemes/HttpUriPlugin.js +38 -17
  180. package/lib/serialization/BinaryMiddleware.js +52 -19
  181. package/lib/serialization/FileMiddleware.js +78 -48
  182. package/lib/serialization/ObjectMiddleware.js +78 -29
  183. package/lib/serialization/PlainObjectSerializer.js +1 -1
  184. package/lib/serialization/Serializer.js +15 -10
  185. package/lib/serialization/SerializerMiddleware.js +80 -41
  186. package/lib/serialization/SingleItemMiddleware.js +10 -7
  187. package/lib/serialization/types.js +1 -1
  188. package/lib/sharing/ConsumeSharedModule.js +4 -2
  189. package/lib/sharing/ProvideSharedModule.js +4 -2
  190. package/lib/sharing/ProvideSharedModuleFactory.js +5 -3
  191. package/lib/sharing/utils.js +2 -2
  192. package/lib/stats/DefaultStatsFactoryPlugin.js +80 -78
  193. package/lib/stats/DefaultStatsPresetPlugin.js +43 -23
  194. package/lib/stats/DefaultStatsPrinterPlugin.js +85 -43
  195. package/lib/stats/StatsFactory.js +11 -11
  196. package/lib/stats/StatsPrinter.js +7 -7
  197. package/lib/util/ArrayHelpers.js +2 -4
  198. package/lib/util/ArrayQueue.js +1 -1
  199. package/lib/util/AsyncQueue.js +4 -4
  200. package/lib/util/IterableHelpers.js +1 -1
  201. package/lib/util/LazyBucketSortedSet.js +41 -23
  202. package/lib/util/LazySet.js +3 -2
  203. package/lib/util/MapHelpers.js +1 -1
  204. package/lib/util/ParallelismFactorCalculator.js +1 -1
  205. package/lib/util/Semaphore.js +3 -3
  206. package/lib/util/SetHelpers.js +1 -1
  207. package/lib/util/SortableSet.js +9 -7
  208. package/lib/util/TupleQueue.js +9 -8
  209. package/lib/util/TupleSet.js +2 -2
  210. package/lib/util/WeakTupleMap.js +12 -11
  211. package/lib/util/binarySearchBounds.js +2 -1
  212. package/lib/util/cleverMerge.js +84 -54
  213. package/lib/util/comparators.js +22 -21
  214. package/lib/util/compileBooleanMatcher.js +3 -3
  215. package/lib/util/concatenate.js +6 -4
  216. package/lib/util/create-schema-validation.js +4 -4
  217. package/lib/util/createHash.js +2 -2
  218. package/lib/util/deprecation.js +35 -33
  219. package/lib/util/deterministicGrouping.js +6 -6
  220. package/lib/util/findGraphRoots.js +1 -1
  221. package/lib/util/fs.js +39 -39
  222. package/lib/util/hash/wasm-hash.js +2 -2
  223. package/lib/util/identifier.js +15 -18
  224. package/lib/util/makeSerializable.js +1 -1
  225. package/lib/util/memoize.js +4 -1
  226. package/lib/util/objectToMap.js +3 -2
  227. package/lib/util/processAsyncTree.js +2 -2
  228. package/lib/util/propertyName.js +0 -1
  229. package/lib/util/registerExternalSerializer.js +15 -18
  230. package/lib/util/removeBOM.js +25 -0
  231. package/lib/util/runtime.js +34 -27
  232. package/lib/util/serialization.js +5 -16
  233. package/lib/util/smartGrouping.js +3 -3
  234. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  235. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +11 -0
  236. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +10 -0
  237. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -0
  238. package/lib/wasm-sync/WebAssemblyGenerator.js +28 -12
  239. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +10 -0
  240. package/lib/wasm-sync/WebAssemblyParser.js +9 -4
  241. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -0
  242. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -25
  243. package/package.json +19 -17
  244. package/schemas/WebpackOptions.check.js +1 -1
  245. package/schemas/WebpackOptions.json +48 -13
  246. package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +7 -0
  247. package/schemas/plugins/JsonModulesPluginGenerator.check.js +6 -0
  248. package/schemas/plugins/JsonModulesPluginGenerator.json +11 -0
  249. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  250. package/types.d.ts +918 -615
  251. package/lib/library/ModernModuleLibraryPlugin.js +0 -144
@@ -7,7 +7,7 @@
7
7
 
8
8
  const { register } = require("./serialization");
9
9
 
10
- const Position = /** @type {TODO} */ (require("acorn")).Position;
10
+ const Position = require("acorn").Position;
11
11
  const SourceLocation = require("acorn").SourceLocation;
12
12
  const ValidationError = require("schema-utils").ValidationError;
13
13
  const {
@@ -23,10 +23,8 @@ const {
23
23
  /** @typedef {import("acorn").Position} Position */
24
24
  /** @typedef {import("../Dependency").RealDependencyLocation} RealDependencyLocation */
25
25
  /** @typedef {import("../Dependency").SourcePosition} SourcePosition */
26
- /** @typedef {import("./serialization").ObjectDeserializerContext} ObjectDeserializerContext */
27
- /** @typedef {import("./serialization").ObjectSerializerContext} ObjectSerializerContext */
28
-
29
- /** @typedef {ObjectSerializerContext & { writeLazy?: (value: any) => void }} WebpackObjectSerializerContext */
26
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
27
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
30
28
 
31
29
  const CURRENT_MODULE = "webpack/lib/util/registerExternalSerializer";
32
30
 
@@ -37,7 +35,7 @@ register(
37
35
  new (class CachedSourceSerializer {
38
36
  /**
39
37
  * @param {CachedSource} source the cached source to be serialized
40
- * @param {WebpackObjectSerializerContext} context context
38
+ * @param {ObjectSerializerContext} context context
41
39
  * @returns {void}
42
40
  */
43
41
  serialize(source, { write, writeLazy }) {
@@ -68,7 +66,7 @@ register(
68
66
  new (class RawSourceSerializer {
69
67
  /**
70
68
  * @param {RawSource} source the raw source to be serialized
71
- * @param {WebpackObjectSerializerContext} context context
69
+ * @param {ObjectSerializerContext} context context
72
70
  * @returns {void}
73
71
  */
74
72
  serialize(source, { write }) {
@@ -95,7 +93,7 @@ register(
95
93
  new (class ConcatSourceSerializer {
96
94
  /**
97
95
  * @param {ConcatSource} source the concat source to be serialized
98
- * @param {WebpackObjectSerializerContext} context context
96
+ * @param {ObjectSerializerContext} context context
99
97
  * @returns {void}
100
98
  */
101
99
  serialize(source, { write }) {
@@ -121,7 +119,7 @@ register(
121
119
  new (class PrefixSourceSerializer {
122
120
  /**
123
121
  * @param {PrefixSource} source the prefix source to be serialized
124
- * @param {WebpackObjectSerializerContext} context context
122
+ * @param {ObjectSerializerContext} context context
125
123
  * @returns {void}
126
124
  */
127
125
  serialize(source, { write }) {
@@ -146,7 +144,7 @@ register(
146
144
  new (class ReplaceSourceSerializer {
147
145
  /**
148
146
  * @param {ReplaceSource} source the replace source to be serialized
149
- * @param {WebpackObjectSerializerContext} context context
147
+ * @param {ObjectSerializerContext} context context
150
148
  * @returns {void}
151
149
  */
152
150
  serialize(source, { write }) {
@@ -196,7 +194,7 @@ register(
196
194
  new (class OriginalSourceSerializer {
197
195
  /**
198
196
  * @param {OriginalSource} source the original source to be serialized
199
- * @param {WebpackObjectSerializerContext} context context
197
+ * @param {ObjectSerializerContext} context context
200
198
  * @returns {void}
201
199
  */
202
200
  serialize(source, { write }) {
@@ -223,7 +221,7 @@ register(
223
221
  new (class SourceLocationSerializer {
224
222
  /**
225
223
  * @param {SourceLocation} loc the location to be serialized
226
- * @param {WebpackObjectSerializerContext} context context
224
+ * @param {ObjectSerializerContext} context context
227
225
  * @returns {void}
228
226
  */
229
227
  serialize(loc, { write }) {
@@ -259,7 +257,7 @@ register(
259
257
  new (class PositionSerializer {
260
258
  /**
261
259
  * @param {Position} pos the position to be serialized
262
- * @param {WebpackObjectSerializerContext} context context
260
+ * @param {ObjectSerializerContext} context context
263
261
  * @returns {void}
264
262
  */
265
263
  serialize(pos, { write }) {
@@ -287,7 +285,7 @@ register(
287
285
  new (class SourceMapSourceSerializer {
288
286
  /**
289
287
  * @param {SourceMapSource} source the source map source to be serialized
290
- * @param {WebpackObjectSerializerContext} context context
288
+ * @param {ObjectSerializerContext} context context
291
289
  * @returns {void}
292
290
  */
293
291
  serialize(source, { write }) {
@@ -310,10 +308,9 @@ register(
310
308
  CURRENT_MODULE,
311
309
  "schema-utils/ValidationError",
312
310
  new (class ValidationErrorSerializer {
313
- // TODO error should be ValidationError, but this fails the type checks
314
311
  /**
315
- * @param {TODO} error the source map source to be serialized
316
- * @param {WebpackObjectSerializerContext} context context
312
+ * @param {ValidationError} error the source map source to be serialized
313
+ * @param {ObjectSerializerContext} context context
317
314
  * @returns {void}
318
315
  */
319
316
  serialize(error, { write }) {
@@ -328,7 +325,7 @@ register(
328
325
 
329
326
  /**
330
327
  * @param {ObjectDeserializerContext} context context
331
- * @returns {TODO} error
328
+ * @returns {ValidationError} error
332
329
  */
333
330
  deserialize({ read }) {
334
331
  return new ValidationError(read(), read(), read());
@@ -0,0 +1,25 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /**
9
+ * @param {string | Buffer} strOrBuffer string or buffer
10
+ * @returns {string | Buffer} result without BOM
11
+ */
12
+ module.exports = strOrBuffer => {
13
+ if (typeof strOrBuffer === "string" && strOrBuffer.charCodeAt(0) === 0xfeff) {
14
+ return strOrBuffer.substr(1);
15
+ } else if (
16
+ Buffer.isBuffer(strOrBuffer) &&
17
+ strOrBuffer[0] === 0xef &&
18
+ strOrBuffer[1] === 0xbb &&
19
+ strOrBuffer[2] === 0xbf
20
+ ) {
21
+ return strOrBuffer.subarray(3);
22
+ }
23
+
24
+ return strOrBuffer;
25
+ };
@@ -52,7 +52,7 @@ module.exports.getEntryRuntime = (compilation, name, options) => {
52
52
 
53
53
  /**
54
54
  * @param {RuntimeSpec} runtime runtime
55
- * @param {function(string | undefined): void} fn functor
55
+ * @param {(runtime: string | undefined) => void} fn functor
56
56
  * @param {boolean} deterministicOrder enforce a deterministic order
57
57
  * @returns {void}
58
58
  */
@@ -394,7 +394,7 @@ module.exports.subtractRuntimeCondition = (a, b, runtime) => {
394
394
 
395
395
  /**
396
396
  * @param {RuntimeSpec} runtime runtime
397
- * @param {function(RuntimeSpec=): boolean} filter filter function
397
+ * @param {(runtime?: RuntimeSpec) => boolean} filter filter function
398
398
  * @returns {boolean | RuntimeSpec} true/false if filter is constant for all runtimes, otherwise runtimes that are active
399
399
  */
400
400
  module.exports.filterRuntime = (runtime, filter) => {
@@ -424,24 +424,25 @@ module.exports.filterRuntime = (runtime, filter) => {
424
424
 
425
425
  /**
426
426
  * @template T
427
+ * @template [R=T]
427
428
  */
428
429
  class RuntimeSpecMap {
429
430
  /**
430
- * @param {RuntimeSpecMap<T>=} clone copy form this
431
+ * @param {RuntimeSpecMap<T, R>=} clone copy form this
431
432
  */
432
433
  constructor(clone) {
433
434
  this._mode = clone ? clone._mode : 0; // 0 = empty, 1 = single entry, 2 = map
434
435
  /** @type {RuntimeSpec} */
435
436
  this._singleRuntime = clone ? clone._singleRuntime : undefined;
436
- /** @type {T | undefined} */
437
+ /** @type {R | undefined} */
437
438
  this._singleValue = clone ? clone._singleValue : undefined;
438
- /** @type {RuntimeSpecMapInnerMap<T> | undefined} */
439
+ /** @type {RuntimeSpecMapInnerMap<R> | undefined} */
439
440
  this._map = clone && clone._map ? new Map(clone._map) : undefined;
440
441
  }
441
442
 
442
443
  /**
443
444
  * @param {RuntimeSpec} runtime the runtimes
444
- * @returns {T | undefined} value
445
+ * @returns {R | undefined} value
445
446
  */
446
447
  get(runtime) {
447
448
  switch (this._mode) {
@@ -452,7 +453,7 @@ class RuntimeSpecMap {
452
453
  ? this._singleValue
453
454
  : undefined;
454
455
  default:
455
- return /** @type {RuntimeSpecMapInnerMap<T>} */ (this._map).get(
456
+ return /** @type {RuntimeSpecMapInnerMap<R>} */ (this._map).get(
456
457
  getRuntimeKey(runtime)
457
458
  );
458
459
  }
@@ -469,7 +470,7 @@ class RuntimeSpecMap {
469
470
  case 1:
470
471
  return runtimeEqual(this._singleRuntime, runtime);
471
472
  default:
472
- return /** @type {RuntimeSpecMapInnerMap<T>} */ (this._map).has(
473
+ return /** @type {RuntimeSpecMapInnerMap<R>} */ (this._map).has(
473
474
  getRuntimeKey(runtime)
474
475
  );
475
476
  }
@@ -477,7 +478,7 @@ class RuntimeSpecMap {
477
478
 
478
479
  /**
479
480
  * @param {RuntimeSpec} runtime the runtimes
480
- * @param {T} value the value
481
+ * @param {R} value the value
481
482
  */
482
483
  set(runtime, value) {
483
484
  switch (this._mode) {
@@ -495,21 +496,21 @@ class RuntimeSpecMap {
495
496
  this._map = new Map();
496
497
  this._map.set(
497
498
  getRuntimeKey(this._singleRuntime),
498
- /** @type {T} */ (this._singleValue)
499
+ /** @type {R} */ (this._singleValue)
499
500
  );
500
501
  this._singleRuntime = undefined;
501
502
  this._singleValue = undefined;
502
503
  /* falls through */
503
504
  default:
504
- /** @type {RuntimeSpecMapInnerMap<T>} */
505
+ /** @type {RuntimeSpecMapInnerMap<R>} */
505
506
  (this._map).set(getRuntimeKey(runtime), value);
506
507
  }
507
508
  }
508
509
 
509
510
  /**
510
511
  * @param {RuntimeSpec} runtime the runtimes
511
- * @param {() => TODO} computer function to compute the value
512
- * @returns {TODO} true, when the runtime was deleted
512
+ * @param {() => R} computer function to compute the value
513
+ * @returns {R} the new value
513
514
  */
514
515
  provide(runtime, computer) {
515
516
  switch (this._mode) {
@@ -519,13 +520,14 @@ class RuntimeSpecMap {
519
520
  return (this._singleValue = computer());
520
521
  case 1: {
521
522
  if (runtimeEqual(this._singleRuntime, runtime)) {
522
- return /** @type {T} */ (this._singleValue);
523
+ return /** @type {R} */ (this._singleValue);
523
524
  }
524
525
  this._mode = 2;
525
526
  this._map = new Map();
526
527
  this._map.set(
527
528
  getRuntimeKey(this._singleRuntime),
528
- /** @type {T} */ (this._singleValue)
529
+ /** @type {R} */
530
+ (this._singleValue)
529
531
  );
530
532
  this._singleRuntime = undefined;
531
533
  this._singleValue = undefined;
@@ -535,10 +537,12 @@ class RuntimeSpecMap {
535
537
  }
536
538
  default: {
537
539
  const key = getRuntimeKey(runtime);
538
- const value = /** @type {Map<string, T>} */ (this._map).get(key);
540
+ const value =
541
+ /** @type {RuntimeSpecMapInnerMap<R>} */
542
+ (this._map).get(key);
539
543
  if (value !== undefined) return value;
540
544
  const newValue = computer();
541
- /** @type {Map<string, T>} */
545
+ /** @type {RuntimeSpecMapInnerMap<R>} */
542
546
  (this._map).set(key, newValue);
543
547
  return newValue;
544
548
  }
@@ -560,14 +564,14 @@ class RuntimeSpecMap {
560
564
  }
561
565
  return;
562
566
  default:
563
- /** @type {RuntimeSpecMapInnerMap<T>} */
567
+ /** @type {RuntimeSpecMapInnerMap<R>} */
564
568
  (this._map).delete(getRuntimeKey(runtime));
565
569
  }
566
570
  }
567
571
 
568
572
  /**
569
573
  * @param {RuntimeSpec} runtime the runtimes
570
- * @param {function(T | undefined): T} fn function to update the value
574
+ * @param {(value: R | undefined) => R} fn function to update the value
571
575
  */
572
576
  update(runtime, fn) {
573
577
  switch (this._mode) {
@@ -584,7 +588,8 @@ class RuntimeSpecMap {
584
588
  this._map = new Map();
585
589
  this._map.set(
586
590
  getRuntimeKey(this._singleRuntime),
587
- /** @type {T} */ (this._singleValue)
591
+ /** @type {R} */
592
+ (this._singleValue)
588
593
  );
589
594
  this._singleRuntime = undefined;
590
595
  this._singleValue = undefined;
@@ -594,10 +599,12 @@ class RuntimeSpecMap {
594
599
  }
595
600
  default: {
596
601
  const key = getRuntimeKey(runtime);
597
- const oldValue = /** @type {Map<string, T>} */ (this._map).get(key);
602
+ const oldValue =
603
+ /** @type {RuntimeSpecMapInnerMap<R>} */
604
+ (this._map).get(key);
598
605
  const newValue = fn(oldValue);
599
606
  if (newValue !== oldValue)
600
- /** @type {RuntimeSpecMapInnerMap<T>} */
607
+ /** @type {RuntimeSpecMapInnerMap<R>} */
601
608
  (this._map).set(key, newValue);
602
609
  }
603
610
  }
@@ -611,7 +618,7 @@ class RuntimeSpecMap {
611
618
  return [this._singleRuntime];
612
619
  default:
613
620
  return Array.from(
614
- /** @type {RuntimeSpecMapInnerMap<T>} */
621
+ /** @type {RuntimeSpecMapInnerMap<R>} */
615
622
  (this._map).keys(),
616
623
  keyToRuntime
617
624
  );
@@ -619,16 +626,16 @@ class RuntimeSpecMap {
619
626
  }
620
627
 
621
628
  /**
622
- * @returns {IterableIterator<T>} values
629
+ * @returns {IterableIterator<R>} values
623
630
  */
624
631
  values() {
625
632
  switch (this._mode) {
626
633
  case 0:
627
634
  return [][Symbol.iterator]();
628
635
  case 1:
629
- return [/** @type {T} */ (this._singleValue)][Symbol.iterator]();
636
+ return [/** @type {R} */ (this._singleValue)][Symbol.iterator]();
630
637
  default:
631
- return /** @type {Map<string, T>} */ (this._map).values();
638
+ return /** @type {RuntimeSpecMapInnerMap<R>} */ (this._map).values();
632
639
  }
633
640
  }
634
641
 
@@ -637,7 +644,7 @@ class RuntimeSpecMap {
637
644
  return /** @type {number} */ (this._mode);
638
645
  }
639
646
 
640
- return /** @type {Map<string, T>} */ (this._map).size;
647
+ return /** @type {RuntimeSpecMapInnerMap<R>} */ (this._map).size;
641
648
  }
642
649
  }
643
650
 
@@ -4,12 +4,11 @@
4
4
 
5
5
  "use strict";
6
6
 
7
+ const { DEFAULTS } = require("../config/defaults");
7
8
  const memoize = require("./memoize");
8
9
 
9
10
  /** @typedef {import("../serialization/BinaryMiddleware").MEASURE_END_OPERATION_TYPE} MEASURE_END_OPERATION */
10
11
  /** @typedef {import("../serialization/BinaryMiddleware").MEASURE_START_OPERATION_TYPE} MEASURE_START_OPERATION */
11
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
12
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
13
12
  /** @typedef {import("../serialization/Serializer")} Serializer */
14
13
  /** @typedef {typeof import("../util/Hash")} Hash */
15
14
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
@@ -47,6 +46,7 @@ const registerSerializers = memoize(() => {
47
46
  if (loader) {
48
47
  loader();
49
48
  } else {
49
+ // eslint-disable-next-line no-console
50
50
  console.warn(`${req} not found in internalSerializables`);
51
51
  }
52
52
  return true;
@@ -91,17 +91,14 @@ module.exports = {
91
91
  return (buffersSerializer = new Serializer([
92
92
  new SingleItemMiddleware(),
93
93
  new (getObjectMiddleware())(context => {
94
- if (context.write) {
95
- /**
96
- * @param {any} value value
97
- */
94
+ if ("write" in context) {
98
95
  context.writeLazy = value => {
99
96
  context.write(
100
97
  SerializerMiddleware.createLazy(value, binaryMiddleware)
101
98
  );
102
99
  };
103
100
  }
104
- }, "md4"),
101
+ }, DEFAULTS.HASH_FUNCTION),
105
102
  binaryMiddleware
106
103
  ]));
107
104
  },
@@ -121,20 +118,12 @@ module.exports = {
121
118
  return new Serializer([
122
119
  new SingleItemMiddleware(),
123
120
  new (getObjectMiddleware())(context => {
124
- if (context.write) {
125
- /**
126
- * @param {any} value value
127
- */
121
+ if ("write" in context) {
128
122
  context.writeLazy = value => {
129
123
  context.write(
130
124
  SerializerMiddleware.createLazy(value, binaryMiddleware)
131
125
  );
132
126
  };
133
- /**
134
- * @param {any} value value
135
- * @param {object=} options lazy options
136
- * @returns {function(): Promise<any> | any} lazy function
137
- */
138
127
  context.writeSeparate = (value, options) => {
139
128
  const lazy = SerializerMiddleware.createLazy(
140
129
  value,
@@ -16,9 +16,9 @@
16
16
  * @template T
17
17
  * @template R
18
18
  * @typedef {object} GroupConfig
19
- * @property {function(T): string[] | undefined} getKeys
20
- * @property {function(string, (R | T)[], T[]): R} createGroup
21
- * @property {function(string, T[]): GroupOptions=} getOptions
19
+ * @property {(item: T) => string[] | undefined} getKeys
20
+ * @property {(key: string, children: (R | T)[], items: T[]) => R} createGroup
21
+ * @property {(name: string, items: T[]) => GroupOptions=} getOptions
22
22
  */
23
23
 
24
24
  /**
@@ -14,9 +14,9 @@ const Template = require("../Template");
14
14
 
15
15
  /**
16
16
  * @typedef {object} AsyncWasmLoadingRuntimeModuleOptions
17
- * @property {(function(string): string)=} generateBeforeLoadBinaryCode
18
- * @property {function(string): string} generateLoadBinaryCode
19
- * @property {(function(): string)=} generateBeforeInstantiateStreaming
17
+ * @property {((wasmModuleSrcPath: string) => string)=} generateBeforeLoadBinaryCode
18
+ * @property {(wasmModuleSrcPath: string) => string} generateLoadBinaryCode
19
+ * @property {(() => string)=} generateBeforeInstantiateStreaming
20
20
  * @property {boolean} supportsStreaming
21
21
  */
22
22
 
@@ -5,6 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { RawSource } = require("webpack-sources");
8
9
  const Generator = require("../Generator");
9
10
  const { WEBASSEMBLY_TYPES } = require("../ModuleSourceTypesConstants");
10
11
 
@@ -56,6 +57,16 @@ class AsyncWebAssemblyGenerator extends Generator {
56
57
  generate(module, generateContext) {
57
58
  return /** @type {Source} */ (module.originalSource());
58
59
  }
60
+
61
+ /**
62
+ * @param {Error} error the error
63
+ * @param {NormalModule} module module for which the code should be generated
64
+ * @param {GenerateContext} generateContext context for generate
65
+ * @returns {Source | null} generated code
66
+ */
67
+ generateError(error, module, generateContext) {
68
+ return new RawSource(error.message);
69
+ }
59
70
  }
60
71
 
61
72
  module.exports = AsyncWebAssemblyGenerator;
@@ -201,6 +201,16 @@ class AsyncWebAssemblyJavascriptGenerator extends Generator {
201
201
 
202
202
  return InitFragment.addToSource(source, initFragments, generateContext);
203
203
  }
204
+
205
+ /**
206
+ * @param {Error} error the error
207
+ * @param {NormalModule} module module for which the code should be generated
208
+ * @param {GenerateContext} generateContext context for generate
209
+ * @returns {Source | null} generated code
210
+ */
211
+ generateError(error, module, generateContext) {
212
+ return new RawSource(`throw new Error(${JSON.stringify(error.message)});`);
213
+ }
204
214
  }
205
215
 
206
216
  module.exports = AsyncWebAssemblyJavascriptGenerator;
@@ -42,6 +42,10 @@ class UniversalCompileAsyncWasmPlugin {
42
42
  Template.indent(["return fallback();"]),
43
43
  "}"
44
44
  ]);
45
+ /**
46
+ * @param {string} path path
47
+ * @returns {string} code
48
+ */
45
49
  const generateBeforeLoadBinaryCode = path =>
46
50
  Template.asString([
47
51
  "var useFetch = typeof document !== 'undefined' || typeof self !== 'undefined';",
@@ -30,6 +30,8 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
30
30
  /** @typedef {import("@webassemblyjs/ast").ModuleImport} ModuleImport */
31
31
  /** @typedef {import("@webassemblyjs/ast").ModuleExport} ModuleExport */
32
32
  /** @typedef {import("@webassemblyjs/ast").Global} Global */
33
+ /** @typedef {import("@webassemblyjs/ast").AST} AST */
34
+ /** @typedef {import("@webassemblyjs/ast").GlobalType} GlobalType */
33
35
  /**
34
36
  * @template T
35
37
  * @typedef {import("@webassemblyjs/ast").NodePath<T>} NodePath
@@ -42,7 +44,7 @@ const WebAssemblyExportImportedDependency = require("../dependencies/WebAssembly
42
44
  /**
43
45
  * @template T
44
46
  * @param {((prev: ArrayBuffer) => ArrayBuffer)[]} fns transforms
45
- * @returns {Function} composed transform
47
+ * @returns {ArrayBufferTransform} composed transform
46
48
  */
47
49
  const compose = (...fns) =>
48
50
  fns.reduce(
@@ -53,7 +55,7 @@ const compose = (...fns) =>
53
55
  /**
54
56
  * Removes the start instruction
55
57
  * @param {object} state state
56
- * @param {object} state.ast Module's ast
58
+ * @param {AST} state.ast Module's ast
57
59
  * @returns {ArrayBufferTransform} transform
58
60
  */
59
61
  const removeStartFunc = state => bin =>
@@ -65,7 +67,7 @@ const removeStartFunc = state => bin =>
65
67
 
66
68
  /**
67
69
  * Get imported globals
68
- * @param {object} ast Module's AST
70
+ * @param {AST} ast Module's AST
69
71
  * @returns {t.ModuleImport[]} - nodes
70
72
  */
71
73
  const getImportedGlobals = ast => {
@@ -85,7 +87,7 @@ const getImportedGlobals = ast => {
85
87
 
86
88
  /**
87
89
  * Get the count for imported func
88
- * @param {object} ast Module's AST
90
+ * @param {AST} ast Module's AST
89
91
  * @returns {number} - count
90
92
  */
91
93
  const getCountImportedFunc = ast => {
@@ -104,7 +106,7 @@ const getCountImportedFunc = ast => {
104
106
 
105
107
  /**
106
108
  * Get next type index
107
- * @param {object} ast Module's AST
109
+ * @param {AST} ast Module's AST
108
110
  * @returns {t.Index} - index
109
111
  */
110
112
  const getNextTypeIndex = ast => {
@@ -122,7 +124,7 @@ const getNextTypeIndex = ast => {
122
124
  * The Func section metadata provide information for implemented funcs
123
125
  * in order to have the correct index we shift the index by number of external
124
126
  * functions.
125
- * @param {object} ast Module's AST
127
+ * @param {AST} ast Module's AST
126
128
  * @param {number} countImportedFunc number of imported funcs
127
129
  * @returns {t.Index} - index
128
130
  */
@@ -168,7 +170,7 @@ const createDefaultInitForGlobal = globalType => {
168
170
  *
169
171
  * Note that globals will become mutable.
170
172
  * @param {object} state transformation state
171
- * @param {object} state.ast Module's ast
173
+ * @param {AST} state.ast Module's ast
172
174
  * @param {t.Instruction[]} state.additionalInitCode list of addition instructions for the init function
173
175
  * @returns {ArrayBufferTransform} transform
174
176
  */
@@ -180,7 +182,9 @@ const rewriteImportedGlobals = state => bin => {
180
182
  bin = editWithAST(state.ast, bin, {
181
183
  ModuleImport(path) {
182
184
  if (t.isGlobalType(path.node.descr)) {
183
- const globalType = /** @type {TODO} */ (path.node.descr);
185
+ const globalType =
186
+ /** @type {GlobalType} */
187
+ (path.node.descr);
184
188
 
185
189
  globalType.mutability = "var";
186
190
 
@@ -238,7 +242,7 @@ const rewriteImportedGlobals = state => bin => {
238
242
  /**
239
243
  * Rewrite the export names
240
244
  * @param {object} state state
241
- * @param {object} state.ast Module's ast
245
+ * @param {AST} state.ast Module's ast
242
246
  * @param {Module} state.module Module
243
247
  * @param {ModuleGraph} state.moduleGraph module graph
244
248
  * @param {Set<string>} state.externalExports Module
@@ -272,7 +276,7 @@ const rewriteExportNames =
272
276
  /**
273
277
  * Mangle import names and modules
274
278
  * @param {object} state state
275
- * @param {object} state.ast Module's ast
279
+ * @param {AST} state.ast Module's ast
276
280
  * @param {Map<string, UsedWasmDependency>} state.usedDependencyMap mappings to mangle names
277
281
  * @returns {ArrayBufferTransform} transform
278
282
  */
@@ -300,7 +304,7 @@ const rewriteImports =
300
304
  *
301
305
  * The init function fills the globals given input arguments.
302
306
  * @param {object} state transformation state
303
- * @param {object} state.ast Module's ast
307
+ * @param {AST} state.ast Module's ast
304
308
  * @param {t.Identifier} state.initFuncId identifier of the init function
305
309
  * @param {t.Index} state.startAtFuncOffset index of the start function
306
310
  * @param {t.ModuleImport[]} state.importedGlobals list of imported globals
@@ -442,7 +446,9 @@ class WebAssemblyGenerator extends Generator {
442
446
  * @returns {Source | null} generated code
443
447
  */
444
448
  generate(module, { moduleGraph, runtime }) {
445
- const bin = /** @type {Source} */ (module.originalSource()).source();
449
+ const bin =
450
+ /** @type {Buffer} */
451
+ (/** @type {Source} */ (module.originalSource()).source());
446
452
 
447
453
  const initFuncId = t.identifier("");
448
454
 
@@ -515,6 +521,16 @@ class WebAssemblyGenerator extends Generator {
515
521
 
516
522
  return new RawSource(newBuf);
517
523
  }
524
+
525
+ /**
526
+ * @param {Error} error the error
527
+ * @param {NormalModule} module module for which the code should be generated
528
+ * @param {GenerateContext} generateContext context for generate
529
+ * @returns {Source | null} generated code
530
+ */
531
+ generateError(error, module, generateContext) {
532
+ return new RawSource(error.message);
533
+ }
518
534
  }
519
535
 
520
536
  module.exports = WebAssemblyGenerator;
@@ -212,6 +212,16 @@ class WebAssemblyJavascriptGenerator extends Generator {
212
212
  );
213
213
  return InitFragment.addToSource(source, initFragments, generateContext);
214
214
  }
215
+
216
+ /**
217
+ * @param {Error} error the error
218
+ * @param {NormalModule} module module for which the code should be generated
219
+ * @param {GenerateContext} generateContext context for generate
220
+ * @returns {Source | null} generated code
221
+ */
222
+ generateError(error, module, generateContext) {
223
+ return new RawSource(`throw new Error(${JSON.stringify(error.message)});`);
224
+ }
215
225
  }
216
226
 
217
227
  module.exports = WebAssemblyJavascriptGenerator;