@depup/webpack 5.109.0-depup.0 → 5.110.1-depup.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 (641) hide show
  1. package/README.md +7 -7
  2. package/bin/webpack.js +12 -0
  3. package/changes.json +10 -10
  4. package/lib/APIPlugin.js +123 -17
  5. package/lib/AsyncDependenciesBlock.js +10 -7
  6. package/lib/AutomaticPrefetchPlugin.js +1 -1
  7. package/lib/BannerPlugin.js +10 -6
  8. package/lib/CacheFacade.js +6 -6
  9. package/lib/Chunk.js +14 -11
  10. package/lib/ChunkGraph.js +43 -32
  11. package/lib/ChunkGroup.js +7 -7
  12. package/lib/ChunkTemplate.js +35 -44
  13. package/lib/CircularModulesPlugin.js +205 -28
  14. package/lib/CleanPlugin.js +15 -16
  15. package/lib/CodeGenerationResults.js +11 -8
  16. package/lib/CompatibilityPlugin.js +38 -7
  17. package/lib/Compilation.js +709 -414
  18. package/lib/Compiler.js +69 -42
  19. package/lib/ConcatenationScope.js +117 -8
  20. package/lib/ConditionalInitFragment.js +3 -3
  21. package/lib/ConstPlugin.js +13 -11
  22. package/lib/ContextExclusionPlugin.js +1 -1
  23. package/lib/ContextModule.js +146 -54
  24. package/lib/ContextModuleFactory.js +46 -14
  25. package/lib/ContextReplacementPlugin.js +12 -14
  26. package/lib/DefinePlugin.js +168 -57
  27. package/lib/DependenciesBlock.js +9 -6
  28. package/lib/Dependency.js +36 -16
  29. package/lib/DependencyTemplate.js +11 -12
  30. package/lib/DependencyTemplates.js +3 -3
  31. package/lib/DotenvPlugin.js +50 -13
  32. package/lib/DynamicEntryPlugin.js +8 -4
  33. package/lib/EntryOptionPlugin.js +8 -4
  34. package/lib/EntryPlugin.js +2 -2
  35. package/lib/Entrypoint.js +6 -2
  36. package/lib/EnvironmentPlugin.js +2 -2
  37. package/lib/EvalDevToolModulePlugin.js +8 -4
  38. package/lib/EvalSourceMapDevToolPlugin.js +15 -8
  39. package/lib/ExportsInfo.js +123 -19
  40. package/lib/ExportsInfoApiPlugin.js +2 -4
  41. package/lib/ExternalModule.js +242 -84
  42. package/lib/ExternalModuleFactoryPlugin.js +97 -38
  43. package/lib/ExternalsPlugin.js +10 -6
  44. package/lib/FileSystemInfo.js +116 -42
  45. package/lib/FlagAllModulesAsUsedPlugin.js +2 -3
  46. package/lib/FlagDependencyExportsPlugin.js +76 -19
  47. package/lib/FlagDependencyUsagePlugin.js +63 -57
  48. package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
  49. package/lib/Generator.js +36 -15
  50. package/lib/HotModuleReplacementPlugin.js +16 -44
  51. package/lib/IgnorePlugin.js +8 -4
  52. package/lib/IgnoreWarningsPlugin.js +2 -2
  53. package/lib/InitFragment.js +28 -36
  54. package/lib/JavascriptMetaInfoPlugin.js +35 -4
  55. package/lib/LazyBarrel.js +3 -4
  56. package/lib/LibraryTemplatePlugin.js +10 -6
  57. package/lib/LoaderOptionsPlugin.js +7 -3
  58. package/lib/LoaderTargetPlugin.js +1 -1
  59. package/lib/MainTemplate.js +49 -42
  60. package/lib/ManifestPlugin.js +12 -11
  61. package/lib/Module.js +62 -33
  62. package/lib/ModuleFactory.js +3 -3
  63. package/lib/ModuleFilenameHelpers.js +22 -6
  64. package/lib/ModuleGraph.js +195 -21
  65. package/lib/ModuleGraphConnection.js +6 -13
  66. package/lib/ModuleInfoHeaderPlugin.js +8 -10
  67. package/lib/ModuleTemplate.js +62 -63
  68. package/lib/MultiCompiler.js +130 -64
  69. package/lib/MultiStats.js +40 -9
  70. package/lib/MultiWatching.js +3 -3
  71. package/lib/NoEmitOnErrorsPlugin.js +1 -1
  72. package/lib/NodeStuffPlugin.js +29 -19
  73. package/lib/NormalModule.js +221 -156
  74. package/lib/NormalModuleFactory.js +563 -112
  75. package/lib/NormalModuleReplacementPlugin.js +5 -8
  76. package/lib/NullFactory.js +6 -2
  77. package/lib/OptionsApply.js +7 -3
  78. package/lib/Parser.js +7 -3
  79. package/lib/PlatformPlugin.js +2 -2
  80. package/lib/PrefetchPlugin.js +1 -1
  81. package/lib/ProgressPlugin.js +16 -13
  82. package/lib/ProvidePlugin.js +3 -5
  83. package/lib/RawModule.js +25 -17
  84. package/lib/RecordIdsPlugin.js +3 -3
  85. package/lib/RequestShortener.js +1 -1
  86. package/lib/ResolverFactory.js +2 -2
  87. package/lib/RuntimeGlobals.js +22 -10
  88. package/lib/RuntimeModule.js +29 -19
  89. package/lib/RuntimePlugin.js +346 -256
  90. package/lib/RuntimeTemplate.js +2792 -352
  91. package/lib/SelfModuleFactory.js +7 -3
  92. package/lib/SourceMapDevToolModuleOptionsPlugin.js +6 -2
  93. package/lib/SourceMapDevToolPlugin.js +30 -20
  94. package/lib/Stats.js +3 -4
  95. package/lib/Template.js +55 -25
  96. package/lib/TemplatedPathPlugin.js +96 -14
  97. package/lib/UseStrictPlugin.js +4 -6
  98. package/lib/WarnCaseSensitiveModulesPlugin.js +4 -4
  99. package/lib/WarnDeprecatedOptionPlugin.js +1 -1
  100. package/lib/WarnNoModeSetPlugin.js +1 -1
  101. package/lib/WatchIgnorePlugin.js +8 -6
  102. package/lib/Watching.js +8 -8
  103. package/lib/WebpackIsIncludedPlugin.js +2 -4
  104. package/lib/WebpackOptionsApply.js +308 -18
  105. package/lib/WebpackOptionsDefaulter.js +6 -2
  106. package/lib/asset/AssetBytesGenerator.js +12 -10
  107. package/lib/asset/AssetBytesParser.js +2 -4
  108. package/lib/asset/AssetGenerator.js +188 -95
  109. package/lib/asset/AssetModule.js +7 -3
  110. package/lib/asset/AssetModulesPlugin.js +110 -38
  111. package/lib/asset/AssetParser.js +9 -7
  112. package/lib/asset/AssetSourceGenerator.js +60 -13
  113. package/lib/asset/AssetSourceParser.js +2 -4
  114. package/lib/asset/RawDataUrlModule.js +24 -16
  115. package/lib/asset/WebManifestGenerator.js +8 -10
  116. package/lib/asset/WebManifestParser.js +24 -10
  117. package/lib/async-modules/AsyncModuleHelpers.js +2 -2
  118. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  119. package/lib/async-modules/InferAsyncModulesPlugin.js +2 -2
  120. package/lib/async-modules/isGeneratorLowered.js +4 -4
  121. package/lib/buildChunkGraph.js +36 -27
  122. package/lib/bun/BunTargetPlugin.js +1 -1
  123. package/lib/cache/AddBuildDependenciesPlugin.js +1 -1
  124. package/lib/cache/AddManagedPathsPlugin.js +1 -1
  125. package/lib/cache/IdleFileCachePlugin.js +2 -2
  126. package/lib/cache/MemoryCachePlugin.js +18 -10
  127. package/lib/cache/MemoryWithGcCachePlugin.js +34 -22
  128. package/lib/cache/PackFileCacheStrategy.js +289 -28
  129. package/lib/cache/ResolverCachePlugin.js +38 -18
  130. package/lib/cache/getLazyHashedEtag.js +1 -2
  131. package/lib/cache/mergeEtags.js +1 -1
  132. package/lib/cli.js +1 -3
  133. package/lib/config/browserslistTargetHandler.js +41 -5
  134. package/lib/config/defaults.js +282 -81
  135. package/lib/config/defineConfig.js +10 -2
  136. package/lib/config/getClaimedAssetTypes.js +65 -0
  137. package/lib/config/normalization.js +36 -16
  138. package/lib/config/target.js +46 -3
  139. package/lib/container/ContainerEntryDependency.js +1 -1
  140. package/lib/container/ContainerEntryModule.js +24 -15
  141. package/lib/container/ContainerEntryModuleFactory.js +7 -3
  142. package/lib/container/ContainerPlugin.js +9 -10
  143. package/lib/container/ContainerReferencePlugin.js +6 -2
  144. package/lib/container/FallbackDependency.js +1 -1
  145. package/lib/container/FallbackModule.js +24 -17
  146. package/lib/container/FallbackModuleFactory.js +7 -3
  147. package/lib/container/HoistContainerReferencesPlugin.js +53 -66
  148. package/lib/container/ModuleFederationPlugin.js +7 -18
  149. package/lib/container/RemoteModule.js +27 -19
  150. package/lib/container/RemoteRuntimeModule.js +10 -8
  151. package/lib/container/moduleFederationHooks.js +32 -0
  152. package/lib/css/CssGenerator.js +178 -44
  153. package/lib/css/CssInjectStyleRuntimeModule.js +7 -5
  154. package/lib/css/CssLoadingRuntimeModule.js +82 -36
  155. package/lib/css/CssModule.js +10 -7
  156. package/lib/css/CssModulesPlugin.js +197 -106
  157. package/lib/css/CssParser.js +1248 -618
  158. package/lib/css/CssServerStylesRuntimeModule.js +54 -0
  159. package/lib/css/cssMinify.js +168 -0
  160. package/lib/css/data.js +5324 -0
  161. package/lib/css/syntax.js +10396 -952
  162. package/lib/debug/ProfilingPlugin.js +14 -9
  163. package/lib/deno/DenoTargetPlugin.js +1 -1
  164. package/lib/dependencies/AMDDefineDependency.js +112 -87
  165. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +30 -17
  166. package/lib/dependencies/AMDPlugin.js +9 -7
  167. package/lib/dependencies/AMDRequireArrayDependency.js +5 -5
  168. package/lib/dependencies/AMDRequireContextDependency.js +2 -2
  169. package/lib/dependencies/AMDRequireDependenciesBlock.js +1 -1
  170. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +25 -14
  171. package/lib/dependencies/AMDRequireDependency.js +8 -7
  172. package/lib/dependencies/AMDRequireItemDependency.js +1 -1
  173. package/lib/dependencies/AMDRuntimeModules.js +21 -1
  174. package/lib/dependencies/BuildTimeConstDependency.js +102 -0
  175. package/lib/dependencies/CachedConstDependency.js +11 -8
  176. package/lib/dependencies/CommonJsDependencyHelpers.js +67 -46
  177. package/lib/dependencies/CommonJsExportRequireDependency.js +140 -45
  178. package/lib/dependencies/CommonJsExportsDependency.js +53 -49
  179. package/lib/dependencies/CommonJsExportsParserPlugin.js +207 -25
  180. package/lib/dependencies/CommonJsFullRequireDependency.js +140 -26
  181. package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -48
  182. package/lib/dependencies/CommonJsObjectExportDependency.js +188 -0
  183. package/lib/dependencies/CommonJsPlugin.js +35 -6
  184. package/lib/dependencies/CommonJsRequireContextDependency.js +5 -6
  185. package/lib/dependencies/CommonJsRequireDependency.js +156 -27
  186. package/lib/dependencies/CommonJsSelfReferenceDependency.js +63 -38
  187. package/lib/dependencies/ConstDependency.js +8 -9
  188. package/lib/dependencies/ContextDependency.js +12 -8
  189. package/lib/dependencies/ContextDependencyHelpers.js +14 -9
  190. package/lib/dependencies/ContextDependencyTemplateAsId.js +4 -4
  191. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -4
  192. package/lib/dependencies/ContextElementDependency.js +31 -12
  193. package/lib/dependencies/CreateRequireParserPlugin.js +12 -7
  194. package/lib/dependencies/CreateScriptUrlDependency.js +4 -4
  195. package/lib/dependencies/CssIcssExportDependency.js +56 -28
  196. package/lib/dependencies/CssIcssImportDependency.js +17 -13
  197. package/lib/dependencies/CssIcssSymbolDependency.js +9 -10
  198. package/lib/dependencies/CssImportDependency.js +18 -9
  199. package/lib/dependencies/CssUrlDependency.js +17 -13
  200. package/lib/dependencies/DllEntryDependency.js +1 -1
  201. package/lib/dependencies/DynamicExports.js +2 -2
  202. package/lib/dependencies/ExportBindingInitFragment.js +36 -9
  203. package/lib/dependencies/ExportsInfoDependency.js +7 -8
  204. package/lib/dependencies/ExternalModuleDependency.js +9 -5
  205. package/lib/dependencies/ExternalModuleInitFragment.js +2 -2
  206. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +8 -5
  207. package/lib/dependencies/HarmonyAcceptDependency.js +5 -5
  208. package/lib/dependencies/HarmonyCompatibilityDependency.js +52 -17
  209. package/lib/dependencies/HarmonyDetectionParserPlugin.js +11 -7
  210. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +15 -11
  211. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +78 -12
  212. package/lib/dependencies/HarmonyExportExpressionDependency.js +23 -18
  213. package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -7
  214. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +159 -71
  215. package/lib/dependencies/HarmonyExportInitFragment.js +18 -6
  216. package/lib/dependencies/HarmonyExportSpecifierDependency.js +51 -14
  217. package/lib/dependencies/HarmonyExports.js +7 -4
  218. package/lib/dependencies/HarmonyImportDependency.js +28 -20
  219. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +31 -24
  220. package/lib/dependencies/HarmonyImportGuard.js +21 -30
  221. package/lib/dependencies/HarmonyImportSideEffectDependency.js +38 -9
  222. package/lib/dependencies/HarmonyImportSpecifierDependency.js +106 -55
  223. package/lib/dependencies/HarmonyModulesPlugin.js +7 -3
  224. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -3
  225. package/lib/dependencies/HtmlEntryDependency.js +37 -29
  226. package/lib/dependencies/HtmlInlineHtmlDependency.js +7 -8
  227. package/lib/dependencies/HtmlInlineScriptDependency.js +11 -8
  228. package/lib/dependencies/HtmlInlineStyleDependency.js +7 -10
  229. package/lib/dependencies/HtmlSourceDependency.js +22 -14
  230. package/lib/dependencies/ImportContextDependency.js +2 -2
  231. package/lib/dependencies/ImportDependency.js +24 -20
  232. package/lib/dependencies/ImportEagerDependency.js +6 -9
  233. package/lib/dependencies/ImportMetaContextDependency.js +2 -2
  234. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +14 -13
  235. package/lib/dependencies/ImportMetaContextPlugin.js +7 -3
  236. package/lib/dependencies/ImportMetaGlobDependency.js +2 -2
  237. package/lib/dependencies/ImportMetaGlobDependencyParserPlugin.js +2 -3
  238. package/lib/dependencies/ImportMetaGlobHelpers.js +19 -22
  239. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -1
  240. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -1
  241. package/lib/dependencies/ImportMetaPlugin.js +154 -71
  242. package/lib/dependencies/ImportMetaResolveDependency.js +3 -4
  243. package/lib/dependencies/ImportParserPlugin.js +49 -35
  244. package/lib/dependencies/ImportPhase.js +12 -5
  245. package/lib/dependencies/ImportPlugin.js +7 -3
  246. package/lib/dependencies/ImportWeakDependency.js +6 -9
  247. package/lib/dependencies/JsonExportsDependency.js +11 -7
  248. package/lib/dependencies/LoaderDependency.js +2 -2
  249. package/lib/dependencies/LoaderImportDependency.js +2 -2
  250. package/lib/dependencies/LoaderPlugin.js +11 -7
  251. package/lib/dependencies/LocalModuleDependency.js +5 -5
  252. package/lib/dependencies/LocalModulesHelpers.js +1 -1
  253. package/lib/dependencies/ModuleDecoratorDependency.js +6 -7
  254. package/lib/dependencies/ModuleDependency.js +9 -6
  255. package/lib/dependencies/ModuleDependencyTemplateAsId.js +4 -4
  256. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +3 -3
  257. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  258. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -1
  259. package/lib/dependencies/ModuleInitFragmentDependency.js +24 -10
  260. package/lib/dependencies/NullDependency.js +3 -3
  261. package/lib/dependencies/ProvidedDependency.js +14 -10
  262. package/lib/dependencies/PureExpressionDependency.js +9 -10
  263. package/lib/dependencies/RequireContextDependency.js +2 -2
  264. package/lib/dependencies/RequireContextDependencyParserPlugin.js +2 -4
  265. package/lib/dependencies/RequireContextPlugin.js +8 -4
  266. package/lib/dependencies/RequireEnsureDependenciesBlock.js +2 -2
  267. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +5 -8
  268. package/lib/dependencies/RequireEnsureDependency.js +8 -7
  269. package/lib/dependencies/RequireEnsurePlugin.js +7 -3
  270. package/lib/dependencies/RequireHeaderDependency.js +51 -12
  271. package/lib/dependencies/RequireIncludeDependency.js +6 -6
  272. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +2 -3
  273. package/lib/dependencies/RequireIncludePlugin.js +7 -3
  274. package/lib/dependencies/RequireJsStuffPlugin.js +7 -3
  275. package/lib/dependencies/RequireResolveContextDependency.js +2 -2
  276. package/lib/dependencies/RequireResolveDependency.js +4 -4
  277. package/lib/dependencies/RequireResolveHeaderDependency.js +4 -4
  278. package/lib/dependencies/RuntimeRequirementsDependency.js +5 -6
  279. package/lib/dependencies/StaticExportsDependency.js +2 -2
  280. package/lib/dependencies/SystemPlugin.js +10 -6
  281. package/lib/dependencies/SystemRuntimeModule.js +10 -0
  282. package/lib/dependencies/TopLevelAwaitDependency.js +11 -7
  283. package/lib/dependencies/URLContextDependency.js +2 -2
  284. package/lib/dependencies/URLDependency.js +110 -64
  285. package/lib/dependencies/URLPlugin.js +7 -3
  286. package/lib/dependencies/UnsupportedDependency.js +4 -4
  287. package/lib/dependencies/WebAssemblyExportImportedDependency.js +3 -4
  288. package/lib/dependencies/WebAssemblyImportDependency.js +5 -5
  289. package/lib/dependencies/WebpackIsIncludedDependency.js +6 -6
  290. package/lib/dependencies/WorkerAndWorkletPlugin.js +46 -28
  291. package/lib/dependencies/WorkerDependency.js +28 -22
  292. package/lib/dependencies/WorkletDependency.js +15 -14
  293. package/lib/dependencies/getFunctionExpression.js +8 -4
  294. package/lib/dependencies/processExportInfo.js +5 -5
  295. package/lib/dll/DelegatedModule.js +34 -22
  296. package/lib/dll/DelegatedModuleFactoryPlugin.js +15 -7
  297. package/lib/dll/DelegatedPlugin.js +2 -2
  298. package/lib/dll/DllEntryPlugin.js +2 -2
  299. package/lib/dll/DllModule.js +22 -15
  300. package/lib/dll/DllModuleFactory.js +7 -3
  301. package/lib/dll/DllPlugin.js +7 -5
  302. package/lib/dll/DllReferencePlugin.js +10 -7
  303. package/lib/dll/LibManifestPlugin.js +5 -5
  304. package/lib/electron/ElectronTargetPlugin.js +53 -49
  305. package/lib/errors/AsyncChunkWaterfallWarning.js +36 -0
  306. package/lib/errors/AsyncDependencyToInitialChunkError.js +2 -2
  307. package/lib/errors/BroadContextsWarning.js +43 -0
  308. package/lib/errors/BuildCycleError.js +1 -1
  309. package/lib/errors/CacheEffectivenessWarning.js +55 -0
  310. package/lib/errors/ChunkRenderError.js +1 -1
  311. package/lib/errors/CircularDependenciesWarning.js +38 -0
  312. package/lib/errors/CodeGenerationError.js +1 -1
  313. package/lib/errors/CommentCompilationWarning.js +1 -1
  314. package/lib/errors/ConflictingResourceHintsWarning.js +35 -0
  315. package/lib/errors/DuplicateModulesWarning.js +45 -0
  316. package/lib/errors/DynamicExportsWarning.js +30 -0
  317. package/lib/errors/EmbeddedSourceMapsWarning.js +25 -0
  318. package/lib/errors/EntrypointOverlapWarning.js +45 -0
  319. package/lib/errors/EnvironmentNotSupportAsyncWarning.js +2 -2
  320. package/lib/errors/EvalUsageWarning.js +28 -0
  321. package/lib/errors/HookWebpackError.js +5 -5
  322. package/lib/errors/HotspotsWarning.js +57 -0
  323. package/lib/errors/IgnoreErrorModuleFactory.js +7 -3
  324. package/lib/errors/InlinedAssetsWarning.js +36 -0
  325. package/lib/errors/InvalidDependenciesModuleWarning.js +1 -1
  326. package/lib/errors/LargeModulesWarning.js +45 -0
  327. package/lib/errors/LegacyJavascriptWarning.js +48 -0
  328. package/lib/errors/MissingSideEffectsWarning.js +36 -0
  329. package/lib/errors/MixedExportsWarning.js +41 -0
  330. package/lib/errors/ModuleDependencyError.js +13 -16
  331. package/lib/errors/ModuleDependencyWarning.js +5 -15
  332. package/lib/errors/ModuleHashingError.js +1 -1
  333. package/lib/errors/ModuleNotFoundError.js +2 -2
  334. package/lib/errors/ModuleParseError.js +1 -2
  335. package/lib/errors/ModuleRestoreError.js +1 -1
  336. package/lib/errors/ModuleStoreError.js +1 -1
  337. package/lib/errors/NodeStuffInWebError.js +1 -1
  338. package/lib/errors/OsDependentRuleWarning.js +31 -0
  339. package/lib/errors/PureAnnotationsWarning.js +36 -0
  340. package/lib/errors/RedundantDynamicImportWarning.js +31 -0
  341. package/lib/errors/ScopeHoistingBailoutsWarning.js +41 -0
  342. package/lib/errors/SplitChunksCappedWarning.js +41 -0
  343. package/lib/errors/TinyChunksWarning.js +40 -0
  344. package/lib/errors/TopLevelThisWarning.js +34 -0
  345. package/lib/errors/UnsplitVendorsWarning.js +42 -0
  346. package/lib/errors/UnsupportedFeatureWarning.js +1 -1
  347. package/lib/errors/UnusedAliasesWarning.js +29 -0
  348. package/lib/errors/UnusedDefinesWarning.js +29 -0
  349. package/lib/errors/UnusedExternalsWarning.js +29 -0
  350. package/lib/errors/UnusedReexportsWarning.js +42 -0
  351. package/lib/errors/UnusedRuleWarning.js +29 -0
  352. package/lib/errors/WebpackError.js +9 -5
  353. package/lib/errors/deriveStackFromNestedError.js +90 -0
  354. package/lib/esm/ExportWebpackRequireRuntimeModule.js +2 -0
  355. package/lib/esm/ModuleChunkFormatPlugin.js +37 -19
  356. package/lib/esm/ModuleChunkLoadingPlugin.js +89 -51
  357. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +170 -71
  358. package/lib/hmr/HotModuleReplacement.runtime.js +24 -5
  359. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  360. package/lib/hmr/LazyCompilationPlugin.js +45 -24
  361. package/lib/hmr/lazyCompilationBackend.js +28 -10
  362. package/lib/hmr/parserHooks.js +56 -0
  363. package/lib/html/HtmlGenerator.js +299 -79
  364. package/lib/html/HtmlModule.js +7 -3
  365. package/lib/html/HtmlModulesPlugin.js +312 -174
  366. package/lib/html/HtmlParser.js +31 -86
  367. package/lib/html/data.js +1928 -0
  368. package/lib/html/htmlMinify.js +288 -0
  369. package/lib/html/syntax.js +7819 -3331
  370. package/lib/ids/ChunkModuleIdRangePlugin.js +3 -3
  371. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  372. package/lib/ids/DeterministicModuleIdsPlugin.js +2 -2
  373. package/lib/ids/HashedModuleIdsPlugin.js +6 -2
  374. package/lib/ids/IdHelpers.js +31 -18
  375. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  376. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  377. package/lib/ids/NaturalChunkIdsPlugin.js +2 -2
  378. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  379. package/lib/ids/OccurrenceChunkIdsPlugin.js +7 -3
  380. package/lib/ids/OccurrenceModuleIdsPlugin.js +7 -3
  381. package/lib/ids/SyncModuleIdsPlugin.js +4 -4
  382. package/lib/index.js +10 -0
  383. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +3 -3
  384. package/lib/javascript/BasicEvaluatedExpression.js +18 -14
  385. package/lib/javascript/ChunkFormatHelpers.js +6 -6
  386. package/lib/javascript/ChunkHelpers.js +1 -1
  387. package/lib/javascript/CommonJsChunkFormatPlugin.js +11 -5
  388. package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
  389. package/lib/javascript/JavascriptGenerator.js +65 -165
  390. package/lib/javascript/JavascriptModule.js +9 -3
  391. package/lib/javascript/JavascriptModulesPlugin.js +181 -162
  392. package/lib/javascript/JavascriptParser.js +291 -112
  393. package/lib/javascript/JavascriptParserHelpers.js +10 -7
  394. package/lib/javascript/ScopeAnalyzer.js +1094 -0
  395. package/lib/javascript/StartupHelpers.js +55 -9
  396. package/lib/javascript/syntax.js +3403 -300
  397. package/lib/json/JsonData.js +8 -4
  398. package/lib/json/JsonGenerator.js +38 -16
  399. package/lib/json/JsonModule.js +7 -3
  400. package/lib/json/JsonModulesPlugin.js +1 -1
  401. package/lib/json/JsonParser.js +5 -6
  402. package/lib/library/AbstractLibraryPlugin.js +20 -14
  403. package/lib/library/AmdLibraryPlugin.js +11 -7
  404. package/lib/library/AssignLibraryPlugin.js +19 -13
  405. package/lib/library/EnableLibraryPlugin.js +2 -2
  406. package/lib/library/ExportPropertyLibraryPlugin.js +15 -8
  407. package/lib/library/JsonpLibraryPlugin.js +11 -7
  408. package/lib/library/ModuleLibraryPlugin.js +256 -64
  409. package/lib/library/SystemLibraryPlugin.js +12 -8
  410. package/lib/library/UmdLibraryPlugin.js +62 -25
  411. package/lib/loaders/LoaderRunner.js +14 -1
  412. package/lib/loaders/loadLoader.js +8 -4
  413. package/lib/logging/createConsoleLogger.js +7 -4
  414. package/lib/node/CommonJsChunkLoadingPlugin.js +36 -22
  415. package/lib/node/NodeEnvironmentPlugin.js +17 -3
  416. package/lib/node/NodeSourcePlugin.js +1 -1
  417. package/lib/node/NodeTargetPlugin.js +4 -3
  418. package/lib/node/NodeTemplatePlugin.js +1 -1
  419. package/lib/node/NodeWatchFileSystem.js +70 -9
  420. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +35 -38
  421. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +81 -20
  422. package/lib/node/ReadFileCompileWasmPlugin.js +37 -17
  423. package/lib/node/RequireChunkLoadingRuntimeModule.js +35 -38
  424. package/lib/node/nodeConsole.js +7 -3
  425. package/lib/optimize/AggressiveMergingPlugin.js +21 -17
  426. package/lib/optimize/AggressiveSplittingPlugin.js +9 -6
  427. package/lib/optimize/ConcatenatedModule.js +996 -477
  428. package/lib/optimize/ConstExportsPlugin.js +11 -7
  429. package/lib/optimize/EnsureChunkConditionsPlugin.js +3 -3
  430. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -4
  431. package/lib/optimize/InlineExports.js +9 -5
  432. package/lib/optimize/InnerGraph.js +28 -12
  433. package/lib/optimize/InnerGraphPlugin.js +23 -18
  434. package/lib/optimize/LimitChunkCountPlugin.js +7 -3
  435. package/lib/optimize/MangleExportsPlugin.js +7 -8
  436. package/lib/optimize/MergeDuplicateChunksPlugin.js +7 -3
  437. package/lib/optimize/MinChunkSizePlugin.js +7 -3
  438. package/lib/optimize/ModuleConcatenationPlugin.js +124 -59
  439. package/lib/optimize/RealContentHashPlugin.js +20 -13
  440. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
  441. package/lib/optimize/RemoveParentModulesPlugin.js +4 -4
  442. package/lib/optimize/RuntimeChunkPlugin.js +2 -2
  443. package/lib/optimize/SideEffectsFlagPlugin.js +262 -39
  444. package/lib/optimize/SplitChunksPlugin.js +232 -68
  445. package/lib/performance/AssetsOverSizeLimitWarning.js +10 -2
  446. package/lib/performance/AsyncChunkWaterfallsPlugin.js +136 -0
  447. package/lib/performance/BroadContextsPlugin.js +142 -0
  448. package/lib/performance/CacheEffectivenessPlugin.js +125 -0
  449. package/lib/performance/ConflictingResourceHintsPlugin.js +99 -0
  450. package/lib/performance/DuplicateModulesPlugin.js +93 -0
  451. package/lib/performance/DuplicatePackagesPlugin.js +119 -0
  452. package/lib/performance/DuplicatePackagesWarning.js +84 -0
  453. package/lib/performance/DynamicExportsPlugin.js +120 -0
  454. package/lib/performance/EmbeddedSourceMapsPlugin.js +71 -0
  455. package/lib/performance/EntrypointOverlapPlugin.js +122 -0
  456. package/lib/performance/EntrypointsOverSizeLimitWarning.js +1 -1
  457. package/lib/performance/EvalUsagePlugin.js +115 -0
  458. package/lib/performance/HotspotsPlugin.js +296 -0
  459. package/lib/performance/InlinedAssetsPlugin.js +99 -0
  460. package/lib/performance/LargeModulesPlugin.js +126 -0
  461. package/lib/performance/LegacyJavascriptPlugin.js +139 -0
  462. package/lib/performance/MissingSideEffectsPlugin.js +138 -0
  463. package/lib/performance/MixedExportsPlugin.js +136 -0
  464. package/lib/performance/OsDependentRuleWarningPlugin.js +178 -0
  465. package/lib/performance/PureAnnotationsPlugin.js +219 -0
  466. package/lib/performance/RedundantDynamicImportsPlugin.js +225 -0
  467. package/lib/performance/RuntimeInLargeChunkWarning.js +27 -0
  468. package/lib/performance/ScopeHoistingBailoutsPlugin.js +164 -0
  469. package/lib/performance/SizeLimitsPlugin.js +139 -7
  470. package/lib/performance/SplitChunksCappedPlugin.js +99 -0
  471. package/lib/performance/TinyChunksPlugin.js +128 -0
  472. package/lib/performance/TopLevelThisPlugin.js +208 -0
  473. package/lib/performance/UnsplitVendorsPlugin.js +112 -0
  474. package/lib/performance/UnusedAliasesPlugin.js +253 -0
  475. package/lib/performance/UnusedDefinesPlugin.js +87 -0
  476. package/lib/performance/UnusedExternalsPlugin.js +110 -0
  477. package/lib/performance/UnusedReexportsPlugin.js +159 -0
  478. package/lib/performance/UnusedRuleWarningPlugin.js +105 -0
  479. package/lib/performance/getModuleSize.js +22 -0
  480. package/lib/performance/getSourceModules.js +22 -0
  481. package/lib/performance/hasOnlyUnusedExports.js +40 -0
  482. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +24 -10
  483. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +63 -46
  484. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +2 -3
  485. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +2 -2
  486. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +2 -2
  487. package/lib/prefetch/ResourceHintPlugin.js +377 -136
  488. package/lib/prefetch/ResourceHintRuntimeModule.js +1 -21
  489. package/lib/prefetch/StartupAssetHintRuntimeModule.js +10 -133
  490. package/lib/prefetch/parseResourceHintOptions.js +31 -4
  491. package/lib/rules/BasicEffectRulePlugin.js +2 -2
  492. package/lib/rules/BasicMatcherRulePlugin.js +8 -4
  493. package/lib/rules/GlobMatcherRulePlugin.js +68 -0
  494. package/lib/rules/ObjectMatcherRulePlugin.js +12 -5
  495. package/lib/rules/RuleSetCompiler.js +146 -12
  496. package/lib/rules/UseEffectRulePlugin.js +18 -11
  497. package/lib/runtime/AsyncModuleGeneratorRuntimeModule.js +11 -1
  498. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  499. package/lib/runtime/AutoPublicPathRuntimeModule.js +15 -20
  500. package/lib/runtime/BaseUriRuntimeModule.js +33 -7
  501. package/lib/runtime/ChunkNameRuntimeModule.js +10 -0
  502. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +11 -1
  503. package/lib/runtime/CompatRuntimeModule.js +5 -3
  504. package/lib/runtime/ConcatenationWrapRuntimeModule.js +90 -0
  505. package/lib/runtime/ConstructRequireRuntimeModule.js +52 -0
  506. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +8 -6
  507. package/lib/runtime/CreateScriptRuntimeModule.js +11 -1
  508. package/lib/runtime/CreateScriptUrlRuntimeModule.js +11 -1
  509. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +56 -38
  510. package/lib/runtime/EnsureChunkRuntimeModule.js +18 -2
  511. package/lib/runtime/GetChunkFilenameRuntimeModule.js +62 -37
  512. package/lib/runtime/GetFullHashRuntimeModule.js +12 -2
  513. package/lib/runtime/GetMainFilenameRuntimeModule.js +12 -2
  514. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -2
  515. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +16 -3
  516. package/lib/runtime/GlobalRuntimeModule.js +18 -0
  517. package/lib/runtime/HasOwnPropertyRuntimeModule.js +12 -2
  518. package/lib/runtime/LoadScriptRuntimeModule.js +2 -2
  519. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +23 -6
  520. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +22 -6
  521. package/lib/runtime/NonceRuntimeModule.js +10 -0
  522. package/lib/runtime/OnChunksLoadedRuntimeModule.js +5 -3
  523. package/lib/runtime/PublicPathRuntimeModule.js +12 -2
  524. package/lib/runtime/RelativeUrlRuntimeModule.js +11 -1
  525. package/lib/runtime/RuntimeIdRuntimeModule.js +12 -2
  526. package/lib/runtime/SetAnonymousDefaultNameRuntimeModule.js +11 -1
  527. package/lib/runtime/StartupChunkDependenciesPlugin.js +18 -9
  528. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -3
  529. package/lib/runtime/StartupEntrypointRuntimeModule.js +21 -4
  530. package/lib/runtime/SystemContextRuntimeModule.js +10 -0
  531. package/lib/runtime/ToBinaryRuntimeModule.js +1 -1
  532. package/lib/runtime/WorkerRuntimeModule.js +11 -1
  533. package/lib/runtime/baseUri.js +63 -0
  534. package/lib/schemes/DataUriPlugin.js +1 -1
  535. package/lib/schemes/FileUriPlugin.js +1 -1
  536. package/lib/schemes/HttpUriPlugin.js +24 -15
  537. package/lib/schemes/VirtualUrlPlugin.js +13 -7
  538. package/lib/serialization/AggregateErrorSerializer.js +1 -1
  539. package/lib/serialization/BinaryMiddleware.js +274 -942
  540. package/lib/serialization/ErrorObjectSerializer.js +1 -1
  541. package/lib/serialization/FileMiddleware.js +305 -66
  542. package/lib/serialization/ObjectMiddleware.js +139 -114
  543. package/lib/serialization/PlainObjectSerializer.js +19 -16
  544. package/lib/sharing/ConsumeSharedModule.js +30 -21
  545. package/lib/sharing/ConsumeSharedPlugin.js +18 -10
  546. package/lib/sharing/ConsumeSharedRuntimeModule.js +6 -9
  547. package/lib/sharing/ProvideSharedModule.js +25 -16
  548. package/lib/sharing/ProvideSharedModuleFactory.js +7 -3
  549. package/lib/sharing/ProvideSharedPlugin.js +8 -4
  550. package/lib/sharing/SharePlugin.js +17 -5
  551. package/lib/sharing/ShareRuntimeModule.js +4 -4
  552. package/lib/sharing/resolveMatchedConfigs.js +9 -6
  553. package/lib/sharing/utils.js +1 -3
  554. package/lib/stats/DefaultStatsFactoryPlugin.js +253 -226
  555. package/lib/stats/DefaultStatsPresetPlugin.js +17 -8
  556. package/lib/stats/DefaultStatsPrinterPlugin.js +60 -192
  557. package/lib/stats/StatsFactory.js +56 -35
  558. package/lib/stats/StatsPrinter.js +16 -12
  559. package/lib/typescript/TypeScriptPlugin.js +12 -14
  560. package/lib/url/URLParserPlugin.js +26 -13
  561. package/lib/util/AsyncQueue.js +4 -3
  562. package/lib/util/Hash.js +5 -1
  563. package/lib/util/LazySet.js +35 -22
  564. package/lib/util/LocConverter.js +36 -13
  565. package/lib/util/SourceProcessor.js +1050 -24
  566. package/lib/util/StringXor.js +1 -1
  567. package/lib/util/chainedImports.js +9 -5
  568. package/lib/util/cleverMerge.js +1 -1
  569. package/lib/util/comparators.js +45 -14
  570. package/lib/util/concatenate.js +203 -77
  571. package/lib/util/conventions.js +5 -1
  572. package/lib/util/createHash.js +2 -2
  573. package/lib/util/createHooksRegistry.js +8 -10
  574. package/lib/util/dataURL.js +225 -1
  575. package/lib/util/extractSourceMap.js +4 -3
  576. package/lib/util/findCaseMismatch.js +139 -0
  577. package/lib/util/formatLocation.js +1 -2
  578. package/lib/util/fs.js +22 -5
  579. package/lib/util/globUtils.js +298 -24
  580. package/lib/util/hash/BatchedHash.js +5 -1
  581. package/lib/util/hash/BulkUpdateHash.js +5 -1
  582. package/lib/util/hash/DebugHash.js +5 -1
  583. package/lib/util/hash/hash-digest.js +6 -2
  584. package/lib/util/identifier.js +25 -1
  585. package/lib/util/implicitTypeLoaderFallback.js +1 -1
  586. package/lib/util/internalSerializables.js +6 -0
  587. package/lib/util/lazyModule.js +56 -0
  588. package/lib/util/makeSerializable.js +7 -3
  589. package/lib/util/matchAlias.js +25 -0
  590. package/lib/util/mimeTypes.js +11 -5
  591. package/lib/util/nonNumericOnlyHash.js +4 -3
  592. package/lib/util/parseJson.js +5 -3
  593. package/lib/util/preloadModuleType.js +32 -0
  594. package/lib/util/registerExternalSerializer.js +7 -5
  595. package/lib/util/runtime.js +2 -2
  596. package/lib/util/semver.js +1 -1
  597. package/lib/util/serialization.js +28 -28
  598. package/lib/util/source.js +2 -2
  599. package/lib/util/traverseDestructuringAssignmentProperties.js +6 -2
  600. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -8
  601. package/lib/wasm/wasmModuleFilename.js +54 -0
  602. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +41 -21
  603. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +43 -21
  604. package/lib/wasm-async/AsyncWasmModule.js +3 -3
  605. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +4 -5
  606. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +57 -17
  607. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +34 -18
  608. package/lib/wasm-async/AsyncWebAssemblyParser.js +9 -8
  609. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +34 -8
  610. package/lib/wasm-sync/SyncWasmModule.js +2 -2
  611. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +18 -13
  612. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +4 -5
  613. package/lib/wasm-sync/WebAssemblyGenerator.js +18 -17
  614. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +4 -4
  615. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -7
  616. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +24 -11
  617. package/lib/wasm-sync/WebAssemblyParser.js +4 -6
  618. package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
  619. package/lib/web/FetchCompileAsyncWasmPlugin.js +101 -19
  620. package/lib/web/FetchCompileWasmPlugin.js +46 -16
  621. package/lib/web/JsonpChunkLoadingPlugin.js +47 -23
  622. package/lib/web/JsonpChunkLoadingRuntimeModule.js +50 -20
  623. package/lib/web/JsonpTemplatePlugin.js +2 -2
  624. package/lib/webpack.js +22 -11
  625. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +60 -26
  626. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -32
  627. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -1
  628. package/module.d.ts +1 -0
  629. package/package.json +37 -30
  630. package/schemas/WebpackOptions.check.js +1 -1
  631. package/schemas/WebpackOptions.json +780 -91
  632. package/schemas/plugins/HtmlParserOptions.check.js +1 -1
  633. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  634. package/schemas/plugins/container/ContainerPlugin.json +10 -0
  635. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  636. package/schemas/plugins/container/ModuleFederationPlugin.json +10 -0
  637. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  638. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  639. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  640. package/types.d.ts +4013 -738
  641. package/lib/runtime/CommonJsWrapRuntimeModule.js +0 -37
@@ -4,110 +4,45 @@
4
4
 
5
5
  "use strict";
6
6
 
7
+ const { deserialize: v8Deserialize, serialize: v8Serialize } = require("v8");
7
8
  const memoize = require("../util/memoize");
8
9
  const SerializerMiddleware = require("./SerializerMiddleware");
9
10
 
10
- /** @typedef {import("./types").BufferSerializableType} BufferSerializableType */
11
11
  /** @typedef {import("./types").PrimitiveSerializableType} PrimitiveSerializableType */
12
+ /** @import { BufferSerializableType } from "./types" */
12
13
 
13
14
  /*
14
15
  Format:
15
16
 
16
17
  File -> Section*
17
18
 
18
- Section -> NullsSection |
19
- BooleansSection |
20
- F64NumbersSection |
21
- I32NumbersSection |
22
- I8NumbersSection |
23
- ShortStringSection |
24
- BigIntSection |
25
- I32BigIntSection |
26
- I8BigIntSection
27
- StringSection |
28
- BufferSection |
29
- NopSection
19
+ Section -> ValuesSection | LazySection
30
20
 
21
+ ValuesSection ->
22
+ ValuesHeaderByte u32:payloadSize u32:bufferCount (u32:valueIndex u32:bufferSize)*
23
+ payload buffer*
24
+ LazySection ->
25
+ LazyHeaderByte u32:count u32:size*
31
26
 
32
-
33
- NullsSection ->
34
- NullHeaderByte | Null2HeaderByte | Null3HeaderByte |
35
- Nulls8HeaderByte 0xnn (n:count - 4) |
36
- Nulls32HeaderByte n:ui32 (n:count - 260) |
37
- BooleansSection -> TrueHeaderByte | FalseHeaderByte | BooleansSectionHeaderByte BooleansCountAndBitsByte
38
- F64NumbersSection -> F64NumbersSectionHeaderByte f64*
39
- I32NumbersSection -> I32NumbersSectionHeaderByte i32*
40
- I8NumbersSection -> I8NumbersSectionHeaderByte i8*
41
- ShortStringSection -> ShortStringSectionHeaderByte ascii-byte*
42
- StringSection -> StringSectionHeaderByte i32:length utf8-byte*
43
- BufferSection -> BufferSectionHeaderByte i32:length byte*
44
- NopSection --> NopSectionHeaderByte
45
- BigIntSection -> BigIntSectionHeaderByte i32:length ascii-byte*
46
- I32BigIntSection -> I32BigIntSectionHeaderByte i32
47
- I8BigIntSection -> I8BigIntSectionHeaderByte i8
48
-
49
- ShortStringSectionHeaderByte -> 0b1nnn_nnnn (n:length)
50
-
51
- F64NumbersSectionHeaderByte -> 0b001n_nnnn (n:count - 1)
52
- I32NumbersSectionHeaderByte -> 0b010n_nnnn (n:count - 1)
53
- I8NumbersSectionHeaderByte -> 0b011n_nnnn (n:count - 1)
54
-
55
- NullsSectionHeaderByte -> 0b0001_nnnn (n:count - 1)
56
- BooleansCountAndBitsByte ->
57
- 0b0000_1xxx (count = 3) |
58
- 0b0001_xxxx (count = 4) |
59
- 0b001x_xxxx (count = 5) |
60
- 0b01xx_xxxx (count = 6) |
61
- 0b1nnn_nnnn (n:count - 7, 7 <= count <= 133)
62
- 0xff n:ui32 (n:count, 134 <= count < 2^32)
63
-
64
- StringSectionHeaderByte -> 0b0000_1110
65
- BufferSectionHeaderByte -> 0b0000_1111
66
- NopSectionHeaderByte -> 0b0000_1011
67
- BigIntSectionHeaderByte -> 0b0001_1010
68
- I32BigIntSectionHeaderByte -> 0b0001_1100
69
- I8BigIntSectionHeaderByte -> 0b0001_1011
70
- FalseHeaderByte -> 0b0000_1100
71
- TrueHeaderByte -> 0b0000_1101
72
-
73
- RawNumber -> n (n <= 10)
74
-
27
+ ValuesHeaderByte -> 0xf1
28
+ LazyHeaderByte -> 0xf2
75
29
  */
76
30
 
77
- const LAZY_HEADER = 0x0b;
78
- const TRUE_HEADER = 0x0c;
79
- const FALSE_HEADER = 0x0d;
80
- const BOOLEANS_HEADER = 0x0e;
81
- const NULL_HEADER = 0x10;
82
- const NULL2_HEADER = 0x11;
83
- const NULL3_HEADER = 0x12;
84
- const NULLS8_HEADER = 0x13;
85
- const NULLS32_HEADER = 0x14;
86
- const NULL_AND_I8_HEADER = 0x15;
87
- const NULL_AND_I16_HEADER = 0x19;
88
- const NULL_AND_I32_HEADER = 0x16;
89
- const NULL_AND_TRUE_HEADER = 0x17;
90
- const NULL_AND_FALSE_HEADER = 0x18;
91
- const BIGINT_HEADER = 0x1a;
92
- const BIGINT_I8_HEADER = 0x1b;
93
- const BIGINT_I32_HEADER = 0x1c;
94
- const STRING_HEADER = 0x1e;
95
- const BUFFER_HEADER = 0x1f;
96
- const I8_HEADER = 0x60;
97
- const I32_HEADER = 0x40;
98
- const F64_HEADER = 0x20;
99
- const SHORT_STRING_HEADER = 0x80;
100
-
101
- /** Uplift high-order bits */
102
- const NUMBERS_HEADER_MASK = 0xe0; // 0b1010_0000
103
- const NUMBERS_COUNT_MASK = 0x1f; // 0b0001_1111
104
- const SHORT_STRING_LENGTH_MASK = 0x7f; // 0b0111_1111
31
+ const VALUES_HEADER = 0xf1;
32
+ const LAZY_HEADER = 0xf2;
105
33
 
106
34
  const HEADER_SIZE = 1;
107
- const I8_SIZE = 1;
108
- const I16_SIZE = 2;
109
35
  const I32_SIZE = 4;
110
- const F64_SIZE = 8;
36
+
37
+ /** A values section is closed once its payload is estimated to reach this size. */
38
+ const MAX_SECTION_SIZE = 16 * 1024 * 1024;
39
+ /** Assumed encoded size of a value that isn't a string, for that estimate. */
40
+ const ESTIMATED_VALUE_SIZE = 4;
41
+
42
+ const EMPTY_BUFFER = Buffer.alloc(0);
43
+
44
+ /** Highest V8 value serialization format version this Node.js can read. */
45
+ const V8_FORMAT_VERSION = v8Serialize(null)[1];
111
46
 
112
47
  const MEASURE_START_OPERATION = Symbol("MEASURE_START_OPERATION");
113
48
  const MEASURE_END_OPERATION = Symbol("MEASURE_END_OPERATION");
@@ -115,30 +50,6 @@ const MEASURE_END_OPERATION = Symbol("MEASURE_END_OPERATION");
115
50
  /** @typedef {typeof MEASURE_START_OPERATION} MEASURE_START_OPERATION_TYPE */
116
51
  /** @typedef {typeof MEASURE_END_OPERATION} MEASURE_END_OPERATION_TYPE */
117
52
 
118
- /**
119
- * Returns type of number for serialization.
120
- * @param {number} n number
121
- * @returns {0 | 1 | 2} type of number for serialization
122
- */
123
- const identifyNumber = (n) => {
124
- if (n === (n | 0)) {
125
- if (n <= 127 && n >= -128) return 0;
126
- if (n <= 2147483647 && n >= -2147483648) return 1;
127
- }
128
- return 2;
129
- };
130
-
131
- /**
132
- * Returns type of bigint for serialization.
133
- * @param {bigint} n bigint
134
- * @returns {0 | 1 | 2} type of bigint for serialization
135
- */
136
- const identifyBigInt = (n) => {
137
- if (n <= BigInt(127) && n >= BigInt(-128)) return 0;
138
- if (n <= BigInt(2147483647) && n >= BigInt(-2147483648)) return 1;
139
- return 2;
140
- };
141
-
142
53
  /** @typedef {PrimitiveSerializableType[]} DeserializedType */
143
54
  /** @typedef {BufferSerializableType[]} SerializedType} */
144
55
  /** @typedef {{ retainedBuffer?: (x: Buffer) => Buffer }} Context} */
@@ -150,34 +61,24 @@ const identifyBigInt = (n) => {
150
61
  * @typedef {import("./SerializerMiddleware").LazyFunction<LazyInputValue, LazyOutputValue, BinaryMiddleware, undefined>} LazyFunction
151
62
  */
152
63
 
153
- /**
154
- * Mutable read state of one `_deserialize` run; the module-level dispatch
155
- * table operates on this instead of per-call closures.
156
- */
64
+ /** Mutable read state of one `_deserialize` run. */
157
65
  class ReadState {
158
66
  /**
159
67
  * @param {SerializedType} data data
160
68
  * @param {Context} context context object
161
- * @param {BinaryMiddleware} middleware binary middleware
162
69
  */
163
- constructor(data, context, middleware) {
70
+ constructor(data, context) {
164
71
  /** @type {SerializedType} */
165
72
  this.data = data;
166
- /** @type {Context} */
167
- this.context = context;
168
- /** @type {BinaryMiddleware} */
169
- this.middleware = middleware;
170
73
  this.retainedBuffer = context.retainedBuffer || ((x) => x);
171
74
  /** @type {number} */
172
75
  this.currentDataItem = 0;
173
76
  /** @type {BufferSerializableType | null} */
174
- this.currentBuffer = data[0];
77
+ this.currentBuffer = data.length > 0 ? data[0] : null;
175
78
  /** @type {boolean} */
176
79
  this.currentIsBuffer = Buffer.isBuffer(this.currentBuffer);
177
80
  /** @type {number} */
178
81
  this.currentPosition = 0;
179
- /** @type {DeserializedType} */
180
- this.result = [];
181
82
  }
182
83
 
183
84
  /** Advances to the next data item (does not reset the position). */
@@ -228,6 +129,7 @@ class ReadState {
228
129
  * @returns {Buffer} buffer with bytes
229
130
  */
230
131
  read(n) {
132
+ if (n === 0) return EMPTY_BUFFER;
231
133
  this.ensureBuffer();
232
134
  const rem =
233
135
  /** @type {Buffer} */ (this.currentBuffer).length - this.currentPosition;
@@ -284,7 +186,7 @@ class ReadState {
284
186
  const byte =
285
187
  /** @type {Buffer} */
286
188
  (this.currentBuffer).readUInt8(this.currentPosition);
287
- this.currentPosition += I8_SIZE;
189
+ this.currentPosition += HEADER_SIZE;
288
190
  this.checkOverflow();
289
191
  return byte;
290
192
  }
@@ -305,365 +207,64 @@ class ReadState {
305
207
  }
306
208
  return this.read(I32_SIZE).readUInt32LE(0);
307
209
  }
308
-
309
- /**
310
- * Pushes the lowest n bits of data as booleans.
311
- * @param {number} data data
312
- * @param {number} n n
313
- */
314
- readBits(data, n) {
315
- let mask = 1;
316
- while (n !== 0) {
317
- this.result.push((data & mask) !== 0);
318
- mask <<= 1;
319
- n--;
320
- }
321
- }
322
210
  }
323
211
 
324
212
  /**
325
- * Deserialize handlers indexed by header byte; built once so each
326
- * `_deserialize` call doesn't rebuild 256 closures (hot on cache restore).
327
- * @type {((s: ReadState) => void)[]}
213
+ * Reads a section of values written by V8's value serializer.
214
+ * @param {ReadState} state read state
215
+ * @returns {DeserializedType} values of the section
328
216
  */
329
- const dispatchTable = Array.from({ length: 256 }, (_, header) => {
330
- switch (header) {
331
- case LAZY_HEADER:
332
- return (s) => {
333
- const count = s.readU32();
334
- /** @type {number[]} */
335
- const lengths = [];
336
- for (let i = 0; i < count; i++) lengths.push(s.readU32());
337
- /** @type {(Buffer | LazyFunction<SerializedType, DeserializedType>)[]} */
338
- const content = [];
339
- for (let l of lengths) {
340
- if (l === 0) {
341
- if (typeof s.currentBuffer !== "function") {
342
- throw new Error("Unexpected non-lazy element in stream");
343
- }
344
- content.push(s.currentBuffer);
345
- s.nextDataItem();
346
- } else {
347
- do {
348
- const buf = s.readUpTo(l);
349
- l -= buf.length;
350
- content.push(s.retainedBuffer(buf));
351
- } while (l > 0);
352
- }
353
- }
354
- s.result.push(s.middleware._createLazyDeserialized(content, s.context));
355
- };
356
- case BUFFER_HEADER:
357
- return (s) => {
358
- const len = s.readU32();
359
- s.result.push(s.retainedBuffer(s.read(len)));
360
- };
361
- case TRUE_HEADER:
362
- return (s) => s.result.push(true);
363
- case FALSE_HEADER:
364
- return (s) => s.result.push(false);
365
- case NULL3_HEADER:
366
- return (s) => s.result.push(null, null, null);
367
- case NULL2_HEADER:
368
- return (s) => s.result.push(null, null);
369
- case NULL_HEADER:
370
- return (s) => s.result.push(null);
371
- case NULL_AND_TRUE_HEADER:
372
- return (s) => s.result.push(null, true);
373
- case NULL_AND_FALSE_HEADER:
374
- return (s) => s.result.push(null, false);
375
- case NULL_AND_I8_HEADER:
376
- return (s) => {
377
- if (s.currentIsBuffer) {
378
- s.result.push(
379
- null,
380
- /** @type {Buffer} */ (s.currentBuffer).readInt8(s.currentPosition)
381
- );
382
- s.currentPosition += I8_SIZE;
383
- s.checkOverflow();
384
- } else {
385
- s.result.push(null, s.read(I8_SIZE).readInt8(0));
386
- }
387
- };
388
- case NULL_AND_I16_HEADER:
389
- return (s) => {
390
- s.result.push(null);
391
- if (s.isInCurrentBuffer(I16_SIZE)) {
392
- s.result.push(
393
- /** @type {Buffer} */ (s.currentBuffer).readInt16LE(
394
- s.currentPosition
395
- )
396
- );
397
- s.currentPosition += I16_SIZE;
398
- s.checkOverflow();
399
- } else {
400
- s.result.push(s.read(I16_SIZE).readInt16LE(0));
401
- }
402
- };
403
- case NULL_AND_I32_HEADER:
404
- return (s) => {
405
- s.result.push(null);
406
- if (s.isInCurrentBuffer(I32_SIZE)) {
407
- s.result.push(
408
- /** @type {Buffer} */ (s.currentBuffer).readInt32LE(
409
- s.currentPosition
410
- )
411
- );
412
- s.currentPosition += I32_SIZE;
413
- s.checkOverflow();
414
- } else {
415
- s.result.push(s.read(I32_SIZE).readInt32LE(0));
416
- }
417
- };
418
- case NULLS8_HEADER:
419
- return (s) => {
420
- const len = s.readU8() + 4;
421
- for (let i = 0; i < len; i++) {
422
- s.result.push(null);
423
- }
424
- };
425
- case NULLS32_HEADER:
426
- return (s) => {
427
- const len = s.readU32() + 260;
428
- for (let i = 0; i < len; i++) {
429
- s.result.push(null);
430
- }
431
- };
432
- case BOOLEANS_HEADER:
433
- return (s) => {
434
- const innerHeader = s.readU8();
435
- if ((innerHeader & 0xf0) === 0) {
436
- s.readBits(innerHeader, 3);
437
- } else if ((innerHeader & 0xe0) === 0) {
438
- s.readBits(innerHeader, 4);
439
- } else if ((innerHeader & 0xc0) === 0) {
440
- s.readBits(innerHeader, 5);
441
- } else if ((innerHeader & 0x80) === 0) {
442
- s.readBits(innerHeader, 6);
443
- } else if (innerHeader !== 0xff) {
444
- let count = (innerHeader & 0x7f) + 7;
445
- while (count > 8) {
446
- s.readBits(s.readU8(), 8);
447
- count -= 8;
448
- }
449
- s.readBits(s.readU8(), count);
450
- } else {
451
- let count = s.readU32();
452
- while (count > 8) {
453
- s.readBits(s.readU8(), 8);
454
- count -= 8;
455
- }
456
- s.readBits(s.readU8(), count);
457
- }
458
- };
459
- case STRING_HEADER:
460
- return (s) => {
461
- const len = s.readU32();
462
- if (s.isInCurrentBuffer(len) && s.currentPosition + len < 0x7fffffff) {
463
- s.result.push(
464
- /** @type {Buffer} */
465
- (s.currentBuffer).toString(
466
- undefined,
467
- s.currentPosition,
468
- s.currentPosition + len
469
- )
470
- );
471
- s.currentPosition += len;
472
- s.checkOverflow();
473
- } else {
474
- s.result.push(s.read(len).toString());
475
- }
476
- };
477
- case SHORT_STRING_HEADER:
478
- return (s) => s.result.push("");
479
- case SHORT_STRING_HEADER | 1:
480
- return (s) => {
481
- if (s.currentIsBuffer && s.currentPosition < 0x7ffffffe) {
482
- s.result.push(
483
- /** @type {Buffer} */
484
- (s.currentBuffer).toString(
485
- "latin1",
486
- s.currentPosition,
487
- s.currentPosition + 1
488
- )
489
- );
490
- s.currentPosition++;
491
- s.checkOverflow();
492
- } else {
493
- s.result.push(s.read(1).toString("latin1"));
494
- }
495
- };
496
- case I8_HEADER:
497
- return (s) => {
498
- if (s.currentIsBuffer) {
499
- s.result.push(
500
- /** @type {Buffer} */ (s.currentBuffer).readInt8(s.currentPosition)
501
- );
502
- s.currentPosition++;
503
- s.checkOverflow();
504
- } else {
505
- s.result.push(s.read(1).readInt8(0));
506
- }
507
- };
508
- case BIGINT_I8_HEADER: {
509
- const len = 1;
510
- return (s) => {
511
- const need = I8_SIZE * len;
512
-
513
- if (s.isInCurrentBuffer(need)) {
514
- for (let i = 0; i < len; i++) {
515
- const value =
516
- /** @type {Buffer} */
517
- (s.currentBuffer).readInt8(s.currentPosition);
518
- s.result.push(BigInt(value));
519
- s.currentPosition += I8_SIZE;
520
- }
521
- s.checkOverflow();
522
- } else {
523
- const buf = s.read(need);
524
- for (let i = 0; i < len; i++) {
525
- const value = buf.readInt8(i * I8_SIZE);
526
- s.result.push(BigInt(value));
527
- }
528
- }
529
- };
530
- }
531
- case BIGINT_I32_HEADER: {
532
- const len = 1;
533
- return (s) => {
534
- const need = I32_SIZE * len;
535
- if (s.isInCurrentBuffer(need)) {
536
- for (let i = 0; i < len; i++) {
537
- const value = /** @type {Buffer} */ (s.currentBuffer).readInt32LE(
538
- s.currentPosition
539
- );
540
- s.result.push(BigInt(value));
541
- s.currentPosition += I32_SIZE;
542
- }
543
- s.checkOverflow();
544
- } else {
545
- const buf = s.read(need);
546
- for (let i = 0; i < len; i++) {
547
- const value = buf.readInt32LE(i * I32_SIZE);
548
- s.result.push(BigInt(value));
549
- }
550
- }
551
- };
552
- }
553
- case BIGINT_HEADER: {
554
- return (s) => {
555
- const len = s.readU32();
556
- if (s.isInCurrentBuffer(len) && s.currentPosition + len < 0x7fffffff) {
557
- const value =
558
- /** @type {Buffer} */
559
- (s.currentBuffer).toString(
560
- undefined,
561
- s.currentPosition,
562
- s.currentPosition + len
563
- );
217
+ const readValuesSection = (state) => {
218
+ const payloadSize = state.readU32();
219
+ const bufferCount = state.readU32();
220
+ /** @type {number[]} */
221
+ const bufferInfo = [];
222
+ for (let i = 0; i < bufferCount * 2; i++) bufferInfo.push(state.readU32());
223
+ const payload = state.read(payloadSize);
224
+ // a V8 payload opens with 0xff and its format version, which only ever grows
225
+ if (payload[0] === 0xff && payload[1] > V8_FORMAT_VERSION) {
226
+ throw new Error(
227
+ `Data was written with V8 serialization format version ${payload[1]}, but this Node.js (${process.version}) only reads up to version ${V8_FORMAT_VERSION}`
228
+ );
229
+ }
230
+ const values = /** @type {DeserializedType} */ (v8Deserialize(payload));
231
+ for (let i = 0; i < bufferCount; i++) {
232
+ values[bufferInfo[i * 2]] = state.retainedBuffer(
233
+ state.read(bufferInfo[i * 2 + 1])
234
+ );
235
+ }
236
+ return values;
237
+ };
564
238
 
565
- s.result.push(BigInt(value));
566
- s.currentPosition += len;
567
- s.checkOverflow();
568
- } else {
569
- const value = s.read(len).toString();
570
- s.result.push(BigInt(value));
571
- }
572
- };
573
- }
574
- default:
575
- if (header <= 10) {
576
- return (s) => s.result.push(header);
577
- } else if ((header & SHORT_STRING_HEADER) === SHORT_STRING_HEADER) {
578
- const len = header & SHORT_STRING_LENGTH_MASK;
579
- return (s) => {
580
- if (
581
- s.isInCurrentBuffer(len) &&
582
- s.currentPosition + len < 0x7fffffff
583
- ) {
584
- s.result.push(
585
- /** @type {Buffer} */
586
- (s.currentBuffer).toString(
587
- "latin1",
588
- s.currentPosition,
589
- s.currentPosition + len
590
- )
591
- );
592
- s.currentPosition += len;
593
- s.checkOverflow();
594
- } else {
595
- s.result.push(s.read(len).toString("latin1"));
596
- }
597
- };
598
- } else if ((header & NUMBERS_HEADER_MASK) === F64_HEADER) {
599
- const len = (header & NUMBERS_COUNT_MASK) + 1;
600
- return (s) => {
601
- const need = F64_SIZE * len;
602
- if (s.isInCurrentBuffer(need)) {
603
- for (let i = 0; i < len; i++) {
604
- s.result.push(
605
- /** @type {Buffer} */ (s.currentBuffer).readDoubleLE(
606
- s.currentPosition
607
- )
608
- );
609
- s.currentPosition += F64_SIZE;
610
- }
611
- s.checkOverflow();
612
- } else {
613
- const buf = s.read(need);
614
- for (let i = 0; i < len; i++) {
615
- s.result.push(buf.readDoubleLE(i * F64_SIZE));
616
- }
617
- }
618
- };
619
- } else if ((header & NUMBERS_HEADER_MASK) === I32_HEADER) {
620
- const len = (header & NUMBERS_COUNT_MASK) + 1;
621
- return (s) => {
622
- const need = I32_SIZE * len;
623
- if (s.isInCurrentBuffer(need)) {
624
- for (let i = 0; i < len; i++) {
625
- s.result.push(
626
- /** @type {Buffer} */ (s.currentBuffer).readInt32LE(
627
- s.currentPosition
628
- )
629
- );
630
- s.currentPosition += I32_SIZE;
631
- }
632
- s.checkOverflow();
633
- } else {
634
- const buf = s.read(need);
635
- for (let i = 0; i < len; i++) {
636
- s.result.push(buf.readInt32LE(i * I32_SIZE));
637
- }
638
- }
639
- };
640
- } else if ((header & NUMBERS_HEADER_MASK) === I8_HEADER) {
641
- const len = (header & NUMBERS_COUNT_MASK) + 1;
642
- return (s) => {
643
- const need = I8_SIZE * len;
644
- if (s.isInCurrentBuffer(need)) {
645
- for (let i = 0; i < len; i++) {
646
- s.result.push(
647
- /** @type {Buffer} */ (s.currentBuffer).readInt8(
648
- s.currentPosition
649
- )
650
- );
651
- s.currentPosition += I8_SIZE;
652
- }
653
- s.checkOverflow();
654
- } else {
655
- const buf = s.read(need);
656
- for (let i = 0; i < len; i++) {
657
- s.result.push(buf.readInt8(i * I8_SIZE));
658
- }
659
- }
660
- };
239
+ /**
240
+ * Reads the content items of a lazy section.
241
+ * @param {ReadState} state read state
242
+ * @returns {SerializedType} content of the lazy value
243
+ */
244
+ const readLazySection = (state) => {
245
+ const count = state.readU32();
246
+ /** @type {number[]} */
247
+ const sizes = [];
248
+ for (let i = 0; i < count; i++) sizes.push(state.readU32());
249
+ /** @type {SerializedType} */
250
+ const content = [];
251
+ for (let size of sizes) {
252
+ if (size === 0) {
253
+ if (typeof state.currentBuffer !== "function") {
254
+ throw new Error("Unexpected non-lazy element in stream");
661
255
  }
662
- return (s) => {
663
- throw new Error(`Unexpected header byte 0x${header.toString(16)}`);
664
- };
256
+ content.push(state.currentBuffer);
257
+ state.nextDataItem();
258
+ } else {
259
+ do {
260
+ const buf = state.readUpTo(size);
261
+ size -= buf.length;
262
+ content.push(state.retainedBuffer(buf));
263
+ } while (size > 0);
264
+ }
665
265
  }
666
- });
266
+ return content;
267
+ };
667
268
 
668
269
  /**
669
270
  * Represents BinaryMiddleware.
@@ -696,497 +297,209 @@ class BinaryMiddleware extends SerializerMiddleware {
696
297
  * Returns serialized data.
697
298
  * @param {DeserializedType} data data
698
299
  * @param {Context} context context object
699
- * @param {{ leftOverBuffer: Buffer | null, allocationSize: number, increaseCounter: number }} allocationScope allocation scope
700
300
  * @returns {SerializedType} serialized data
701
301
  */
702
- _serialize(
703
- data,
704
- context,
705
- allocationScope = {
706
- allocationSize: 1024,
707
- increaseCounter: 0,
708
- leftOverBuffer: null
709
- }
710
- ) {
711
- /** @type {Buffer | null} */
712
- let leftOverBuffer = null;
713
- /** @type {BufferSerializableType[]} */
714
- let buffers = [];
715
- /** @type {Buffer | null} */
716
- let currentBuffer = allocationScope ? allocationScope.leftOverBuffer : null;
717
- allocationScope.leftOverBuffer = null;
718
- let currentPosition = 0;
719
- if (currentBuffer === null) {
720
- currentBuffer = Buffer.allocUnsafe(allocationScope.allocationSize);
721
- }
302
+ _serialize(data, context) {
303
+ /** @type {SerializedType} */
304
+ const result = [];
305
+ /** @type {number[]} */
306
+ const measureStack = [];
307
+ let writtenBytes = 0;
308
+ /** Index of the first value of the open section. */
309
+ let sectionStart = 0;
310
+ /** Estimated payload size of the open section. */
311
+ let sectionSize = 0;
722
312
  /**
723
- * Processes the provided bytes needed.
724
- * @param {number} bytesNeeded bytes needed
313
+ * Positions of the buffers of the open section, relative to `data`.
314
+ * @type {number[]}
725
315
  */
726
- const allocate = (bytesNeeded) => {
727
- if (currentBuffer !== null) {
728
- if (currentBuffer.length - currentPosition >= bytesNeeded) return;
729
- flush();
730
- }
731
- if (leftOverBuffer && leftOverBuffer.length >= bytesNeeded) {
732
- currentBuffer = leftOverBuffer;
733
- leftOverBuffer = null;
734
- } else {
735
- currentBuffer = Buffer.allocUnsafe(
736
- Math.max(bytesNeeded, allocationScope.allocationSize)
737
- );
738
- if (
739
- !(allocationScope.increaseCounter =
740
- (allocationScope.increaseCounter + 1) % 4) &&
741
- allocationScope.allocationSize < 16777216
742
- ) {
743
- allocationScope.allocationSize <<= 1;
744
- }
745
- }
746
- };
747
- const flush = () => {
748
- if (currentBuffer !== null) {
749
- if (currentPosition > 0) {
750
- buffers.push(
751
- Buffer.from(
752
- currentBuffer.buffer,
753
- currentBuffer.byteOffset,
754
- currentPosition
755
- )
756
- );
757
- }
758
- if (
759
- !leftOverBuffer ||
760
- leftOverBuffer.length < currentBuffer.length - currentPosition
761
- ) {
762
- leftOverBuffer = Buffer.from(
763
- currentBuffer.buffer,
764
- currentBuffer.byteOffset + currentPosition,
765
- currentBuffer.byteLength - currentPosition
766
- );
767
- }
768
-
769
- currentBuffer = null;
770
- currentPosition = 0;
771
- }
772
- };
316
+ let bufferIndices = [];
317
+ /** @type {Buffer[]} */
318
+ let buffers = [];
773
319
  /**
774
- * Processes the provided byte.
775
- * @param {number} byte byte
320
+ * Appends a buffer to the output.
321
+ * @param {Buffer} buffer buffer
776
322
  */
777
- const writeU8 = (byte) => {
778
- /** @type {Buffer} */
779
- (currentBuffer).writeUInt8(byte, currentPosition++);
323
+ const write = (buffer) => {
324
+ writtenBytes += buffer.length;
325
+ result.push(buffer);
780
326
  };
781
327
  /**
782
- * Processes the provided ui32.
783
- * @param {number} ui32 ui32
328
+ * Writes a values section for the given values.
329
+ * @param {DeserializedType} values values without their buffers
330
+ * @param {number[]} indices position of each buffer within `values`
331
+ * @param {Buffer[]} bufferList buffers in the order of `indices`
784
332
  */
785
- const writeU32 = (ui32) => {
786
- /** @type {Buffer} */
787
- (currentBuffer).writeUInt32LE(ui32, currentPosition);
788
- currentPosition += 4;
789
- };
790
- /** @type {number[]} */
791
- const measureStack = [];
792
- const measureStart = () => {
793
- measureStack.push(buffers.length, currentPosition);
333
+ const writeValuesSection = (values, indices, bufferList) => {
334
+ const payload = v8Serialize(values);
335
+ const header = Buffer.allocUnsafe(
336
+ HEADER_SIZE + I32_SIZE * (2 + indices.length * 2)
337
+ );
338
+ header[0] = VALUES_HEADER;
339
+ header.writeUInt32LE(payload.length, HEADER_SIZE);
340
+ header.writeUInt32LE(indices.length, HEADER_SIZE + I32_SIZE);
341
+ let offset = HEADER_SIZE + I32_SIZE * 2;
342
+ for (let i = 0; i < indices.length; i++) {
343
+ header.writeUInt32LE(indices[i], offset);
344
+ header.writeUInt32LE(bufferList[i].length, offset + I32_SIZE);
345
+ offset += I32_SIZE * 2;
346
+ }
347
+ write(header);
348
+ write(payload);
349
+ for (const buffer of bufferList) {
350
+ if (buffer.length > 0) write(buffer);
351
+ }
794
352
  };
795
353
  /**
796
- * Returns size.
797
- * @returns {number} size
354
+ * Closes the open values section before the value at `end`.
355
+ * @param {number} end index of the first value not in the section
798
356
  */
799
- const measureEnd = () => {
800
- const oldPos = /** @type {number} */ (measureStack.pop());
801
- const buffersIndex = /** @type {number} */ (measureStack.pop());
802
- let size = currentPosition - oldPos;
803
- for (let i = buffersIndex; i < buffers.length; i++) {
804
- size += buffers[i].length;
805
- }
806
- return size;
807
- };
808
- for (let i = 0; i < data.length; i++) {
809
- const thing = data[i];
810
- switch (typeof thing) {
811
- case "function": {
812
- if (!SerializerMiddleware.isLazy(thing)) {
813
- throw new Error(`Unexpected function ${thing}`);
814
- }
815
- /** @type {SerializedType | LazyFunction<SerializedType, DeserializedType> | undefined} */
816
- let serializedData =
817
- SerializerMiddleware.getLazySerializedValue(thing);
818
- if (serializedData === undefined) {
819
- if (SerializerMiddleware.isLazy(thing, this)) {
820
- flush();
821
- allocationScope.leftOverBuffer = leftOverBuffer;
822
- const result =
823
- /** @type {PrimitiveSerializableType[]} */
824
- (thing());
825
- const data = this._serialize(result, context, allocationScope);
826
- leftOverBuffer = allocationScope.leftOverBuffer;
827
- allocationScope.leftOverBuffer = null;
828
- SerializerMiddleware.setLazySerializedValue(thing, data);
829
- serializedData = data;
830
- } else {
831
- serializedData = this._serializeLazy(thing, context);
832
- flush();
833
- buffers.push(serializedData);
834
- break;
357
+ const flush = (end) => {
358
+ if (end > sectionStart) {
359
+ if (
360
+ sectionStart === 0 &&
361
+ end === data.length &&
362
+ // a frozen input can't take the placeholders, so it needs the copy
363
+ (bufferIndices.length === 0 || !Object.isFrozen(data))
364
+ ) {
365
+ // the section covers all values: swap the buffers out and back in
366
+ // instead of copying the whole array to place the placeholders
367
+ try {
368
+ for (let i = 0; i < bufferIndices.length; i++) {
369
+ data[bufferIndices[i]] = null;
835
370
  }
836
- } else if (typeof serializedData === "function") {
837
- flush();
838
- buffers.push(serializedData);
839
- break;
840
- }
841
- /** @type {number[]} */
842
- const lengths = [];
843
- for (const item of serializedData) {
844
- /** @type {undefined | number} */
845
- let last;
846
- if (typeof item === "function") {
847
- lengths.push(0);
848
- } else if (item.length === 0) {
849
- // ignore
850
- } else if (
851
- lengths.length > 0 &&
852
- (last = lengths[lengths.length - 1]) !== 0
853
- ) {
854
- const remaining = 0xffffffff - last;
855
- if (remaining >= item.length) {
856
- lengths[lengths.length - 1] += item.length;
857
- } else {
858
- lengths.push(item.length - remaining);
859
- lengths[lengths.length - 2] = 0xffffffff;
860
- }
861
- } else {
862
- lengths.push(item.length);
371
+ writeValuesSection(data, bufferIndices, buffers);
372
+ } finally {
373
+ for (let i = 0; i < bufferIndices.length; i++) {
374
+ data[bufferIndices[i]] = buffers[i];
863
375
  }
864
376
  }
865
- allocate(5 + lengths.length * 4);
866
- writeU8(LAZY_HEADER);
867
- writeU32(lengths.length);
868
- for (const l of lengths) {
869
- writeU32(l);
870
- }
871
- flush();
872
- for (const item of serializedData) {
873
- buffers.push(item);
377
+ } else {
378
+ const values = data.slice(sectionStart, end);
379
+ for (let i = 0; i < bufferIndices.length; i++) {
380
+ const index = bufferIndices[i] - sectionStart;
381
+ bufferIndices[i] = index;
382
+ values[index] = null;
874
383
  }
875
- break;
384
+ writeValuesSection(values, bufferIndices, buffers);
876
385
  }
877
- case "string": {
878
- const len = Buffer.byteLength(thing);
879
- if (len >= 128 || len !== thing.length) {
880
- allocate(len + HEADER_SIZE + I32_SIZE);
881
- writeU8(STRING_HEADER);
882
- writeU32(len);
883
- currentBuffer.write(thing, currentPosition);
884
- currentPosition += len;
885
- } else if (len >= 70) {
886
- allocate(len + HEADER_SIZE);
887
- writeU8(SHORT_STRING_HEADER | len);
888
-
889
- currentBuffer.write(thing, currentPosition, "latin1");
890
- currentPosition += len;
891
- } else {
892
- allocate(len + HEADER_SIZE);
893
- writeU8(SHORT_STRING_HEADER | len);
894
-
895
- for (let i = 0; i < len; i++) {
896
- currentBuffer[currentPosition++] = thing.charCodeAt(i);
897
- }
898
- }
899
- break;
386
+ if (bufferIndices.length > 0) {
387
+ bufferIndices = [];
388
+ buffers = [];
900
389
  }
901
- case "bigint": {
902
- const type = identifyBigInt(thing);
903
- if (type === 0 && thing >= 0 && thing <= BigInt(10)) {
904
- // shortcut for very small bigints
905
- allocate(HEADER_SIZE + I8_SIZE);
906
- writeU8(BIGINT_I8_HEADER);
907
- writeU8(Number(thing));
908
- break;
909
- }
910
-
911
- switch (type) {
912
- case 0: {
913
- let n = 1;
914
- allocate(HEADER_SIZE + I8_SIZE * n);
915
- writeU8(BIGINT_I8_HEADER | (n - 1));
916
- while (n > 0) {
917
- currentBuffer.writeInt8(
918
- Number(/** @type {bigint} */ (data[i])),
919
- currentPosition
920
- );
921
- currentPosition += I8_SIZE;
922
- n--;
923
- i++;
924
- }
925
- i--;
926
- break;
927
- }
928
- case 1: {
929
- let n = 1;
930
- allocate(HEADER_SIZE + I32_SIZE * n);
931
- writeU8(BIGINT_I32_HEADER | (n - 1));
932
- while (n > 0) {
933
- currentBuffer.writeInt32LE(
934
- Number(/** @type {bigint} */ (data[i])),
935
- currentPosition
936
- );
937
- currentPosition += I32_SIZE;
938
- n--;
939
- i++;
940
- }
941
- i--;
942
- break;
943
- }
944
- default: {
945
- const value = thing.toString();
946
- const len = Buffer.byteLength(value);
947
- allocate(len + HEADER_SIZE + I32_SIZE);
948
- writeU8(BIGINT_HEADER);
949
- writeU32(len);
950
- currentBuffer.write(value, currentPosition);
951
- currentPosition += len;
952
- break;
953
- }
390
+ }
391
+ sectionStart = end;
392
+ sectionSize = 0;
393
+ };
394
+ for (let i = 0; i < data.length; i++) {
395
+ const thing = data[i];
396
+ const type = typeof thing;
397
+ if (type === "string") {
398
+ sectionSize += /** @type {string} */ (thing).length;
399
+ } else if (type === "object") {
400
+ // buffers are appended to the section instead of entering the payload
401
+ if (thing !== null) {
402
+ if (!Buffer.isBuffer(thing)) {
403
+ throw new Error(`Unexpected object ${thing} in binary middleware`);
954
404
  }
955
- break;
405
+ bufferIndices.push(i);
406
+ buffers.push(thing);
407
+ // count placeholder + bytes so buffer-heavy runs still split
408
+ sectionSize += ESTIMATED_VALUE_SIZE + thing.length;
409
+ } else {
410
+ sectionSize += ESTIMATED_VALUE_SIZE;
956
411
  }
957
- case "number": {
958
- const type = identifyNumber(thing);
959
- if (type === 0 && thing >= 0 && thing <= 10) {
960
- // shortcut for very small numbers
961
- allocate(I8_SIZE);
962
- writeU8(thing);
963
- break;
964
- }
965
- /**
966
- * amount of numbers to write
967
- * @type {number}
968
- */
969
- let n = 1;
970
- for (; n < 32 && i + n < data.length; n++) {
971
- const item = data[i + n];
972
- if (typeof item !== "number") break;
973
- if (identifyNumber(item) !== type) break;
974
- }
975
- switch (type) {
976
- case 0:
977
- allocate(HEADER_SIZE + I8_SIZE * n);
978
- writeU8(I8_HEADER | (n - 1));
979
- while (n > 0) {
980
- currentBuffer.writeInt8(
981
- /** @type {number} */ (data[i]),
982
- currentPosition
983
- );
984
- currentPosition += I8_SIZE;
985
- n--;
986
- i++;
987
- }
988
- break;
989
- case 1:
990
- allocate(HEADER_SIZE + I32_SIZE * n);
991
- writeU8(I32_HEADER | (n - 1));
992
- while (n > 0) {
993
- currentBuffer.writeInt32LE(
994
- /** @type {number} */ (data[i]),
995
- currentPosition
996
- );
997
- currentPosition += I32_SIZE;
998
- n--;
999
- i++;
1000
- }
1001
- break;
1002
- case 2:
1003
- allocate(HEADER_SIZE + F64_SIZE * n);
1004
- writeU8(F64_HEADER | (n - 1));
1005
- while (n > 0) {
1006
- currentBuffer.writeDoubleLE(
1007
- /** @type {number} */ (data[i]),
1008
- currentPosition
1009
- );
1010
- currentPosition += F64_SIZE;
1011
- n--;
1012
- i++;
1013
- }
1014
- break;
1015
- }
1016
-
1017
- i--;
1018
- break;
412
+ } else if (type === "function") {
413
+ flush(i);
414
+ sectionStart = i + 1;
415
+ if (!SerializerMiddleware.isLazy(thing)) {
416
+ throw new Error(`Unexpected function ${thing}`);
1019
417
  }
1020
- case "boolean": {
1021
- let lastByte = thing === true ? 1 : 0;
1022
- /** @type {number[]} */
1023
- const bytes = [];
1024
- let count = 1;
1025
- /** @type {undefined | number} */
1026
- let n;
1027
- for (n = 1; n < 0xffffffff && i + n < data.length; n++) {
1028
- const item = data[i + n];
1029
- if (typeof item !== "boolean") break;
1030
- const pos = count & 0x7;
1031
- if (pos === 0) {
1032
- bytes.push(lastByte);
1033
- lastByte = item === true ? 1 : 0;
1034
- } else if (item === true) {
1035
- lastByte |= 1 << pos;
1036
- }
1037
- count++;
1038
- }
1039
- i += count - 1;
1040
- if (count === 1) {
1041
- allocate(HEADER_SIZE);
1042
- writeU8(lastByte === 1 ? TRUE_HEADER : FALSE_HEADER);
1043
- } else if (count === 2) {
1044
- allocate(HEADER_SIZE * 2);
1045
- writeU8(lastByte & 1 ? TRUE_HEADER : FALSE_HEADER);
1046
- writeU8(lastByte & 2 ? TRUE_HEADER : FALSE_HEADER);
1047
- } else if (count <= 6) {
1048
- allocate(HEADER_SIZE + I8_SIZE);
1049
- writeU8(BOOLEANS_HEADER);
1050
- writeU8((1 << count) | lastByte);
1051
- } else if (count <= 133) {
1052
- allocate(HEADER_SIZE + I8_SIZE + I8_SIZE * bytes.length + I8_SIZE);
1053
- writeU8(BOOLEANS_HEADER);
1054
- writeU8(0x80 | (count - 7));
1055
- for (const byte of bytes) writeU8(byte);
1056
- writeU8(lastByte);
418
+ /** @type {SerializedType | LazyFunction<SerializedType, DeserializedType> | undefined} */
419
+ let serializedData = SerializerMiddleware.getLazySerializedValue(thing);
420
+ if (serializedData === undefined) {
421
+ if (SerializerMiddleware.isLazy(thing, this)) {
422
+ serializedData = this._serialize(
423
+ /** @type {DeserializedType} */ (thing()),
424
+ context
425
+ );
426
+ SerializerMiddleware.setLazySerializedValue(thing, serializedData);
1057
427
  } else {
1058
- allocate(
1059
- HEADER_SIZE +
1060
- I8_SIZE +
1061
- I32_SIZE +
1062
- I8_SIZE * bytes.length +
1063
- I8_SIZE
428
+ result.push(
429
+ this._serializeLazy(
430
+ /** @type {LazyFunction<DeserializedType, SerializedType>} */
431
+ (thing),
432
+ context
433
+ )
1064
434
  );
1065
- writeU8(BOOLEANS_HEADER);
1066
- writeU8(0xff);
1067
- writeU32(count);
1068
- for (const byte of bytes) writeU8(byte);
1069
- writeU8(lastByte);
435
+ continue;
1070
436
  }
1071
- break;
437
+ } else if (typeof serializedData === "function") {
438
+ result.push(serializedData);
439
+ continue;
1072
440
  }
1073
- case "object": {
1074
- if (thing === null) {
1075
- /** @type {number} */
1076
- let n;
1077
- for (n = 1; n < 0x100000104 && i + n < data.length; n++) {
1078
- const item = data[i + n];
1079
- if (item !== null) break;
1080
- }
1081
- i += n - 1;
1082
- if (n === 1) {
1083
- if (i + 1 < data.length) {
1084
- const next = data[i + 1];
1085
- if (next === true) {
1086
- allocate(HEADER_SIZE);
1087
- writeU8(NULL_AND_TRUE_HEADER);
1088
- i++;
1089
- } else if (next === false) {
1090
- allocate(HEADER_SIZE);
1091
- writeU8(NULL_AND_FALSE_HEADER);
1092
- i++;
1093
- } else if (typeof next === "number") {
1094
- const type = identifyNumber(next);
1095
- if (type === 0) {
1096
- allocate(HEADER_SIZE + I8_SIZE);
1097
- writeU8(NULL_AND_I8_HEADER);
1098
- currentBuffer.writeInt8(next, currentPosition);
1099
- currentPosition += I8_SIZE;
1100
- i++;
1101
- } else if (type === 1) {
1102
- // `null` + i32 is 5 bytes; if the value also fits an
1103
- // i16, fuse it as 3 bytes instead (helps back-references)
1104
- if (next >= -32768 && next <= 32767) {
1105
- allocate(HEADER_SIZE + I16_SIZE);
1106
- writeU8(NULL_AND_I16_HEADER);
1107
- currentBuffer.writeInt16LE(next, currentPosition);
1108
- currentPosition += I16_SIZE;
1109
- } else {
1110
- allocate(HEADER_SIZE + I32_SIZE);
1111
- writeU8(NULL_AND_I32_HEADER);
1112
- currentBuffer.writeInt32LE(next, currentPosition);
1113
- currentPosition += I32_SIZE;
1114
- }
1115
- i++;
1116
- } else {
1117
- allocate(HEADER_SIZE);
1118
- writeU8(NULL_HEADER);
1119
- }
1120
- } else {
1121
- allocate(HEADER_SIZE);
1122
- writeU8(NULL_HEADER);
1123
- }
1124
- } else {
1125
- allocate(HEADER_SIZE);
1126
- writeU8(NULL_HEADER);
1127
- }
1128
- } else if (n === 2) {
1129
- allocate(HEADER_SIZE);
1130
- writeU8(NULL2_HEADER);
1131
- } else if (n === 3) {
1132
- allocate(HEADER_SIZE);
1133
- writeU8(NULL3_HEADER);
1134
- } else if (n < 260) {
1135
- allocate(HEADER_SIZE + I8_SIZE);
1136
- writeU8(NULLS8_HEADER);
1137
- writeU8(n - 4);
1138
- } else {
1139
- allocate(HEADER_SIZE + I32_SIZE);
1140
- writeU8(NULLS32_HEADER);
1141
- writeU32(n - 260);
1142
- }
1143
- } else if (Buffer.isBuffer(thing)) {
1144
- if (thing.length < 8192) {
1145
- allocate(HEADER_SIZE + I32_SIZE + thing.length);
1146
- writeU8(BUFFER_HEADER);
1147
- writeU32(thing.length);
1148
- thing.copy(currentBuffer, currentPosition);
1149
- currentPosition += thing.length;
441
+ /** @type {number[]} */
442
+ const sizes = [];
443
+ for (const item of serializedData) {
444
+ /** @type {undefined | number} */
445
+ let last;
446
+ if (typeof item === "function") {
447
+ sizes.push(0);
448
+ } else if (item.length === 0) {
449
+ // ignore
450
+ } else if (
451
+ sizes.length > 0 &&
452
+ (last = sizes[sizes.length - 1]) !== 0
453
+ ) {
454
+ const remaining = 0xffffffff - last;
455
+ if (remaining >= item.length) {
456
+ sizes[sizes.length - 1] += item.length;
1150
457
  } else {
1151
- allocate(HEADER_SIZE + I32_SIZE);
1152
- writeU8(BUFFER_HEADER);
1153
- writeU32(thing.length);
1154
- flush();
1155
- buffers.push(thing);
458
+ sizes.push(item.length - remaining);
459
+ sizes[sizes.length - 2] = 0xffffffff;
1156
460
  }
461
+ } else {
462
+ sizes.push(item.length);
1157
463
  }
1158
- break;
1159
464
  }
1160
- case "symbol": {
1161
- if (thing === MEASURE_START_OPERATION) {
1162
- measureStart();
1163
- } else if (thing === MEASURE_END_OPERATION) {
1164
- const size = measureEnd();
1165
- allocate(HEADER_SIZE + I32_SIZE);
1166
- writeU8(I32_HEADER);
1167
- currentBuffer.writeInt32LE(size, currentPosition);
1168
- currentPosition += I32_SIZE;
465
+ const header = Buffer.allocUnsafe(
466
+ HEADER_SIZE + I32_SIZE * (1 + sizes.length)
467
+ );
468
+ header[0] = LAZY_HEADER;
469
+ header.writeUInt32LE(sizes.length, HEADER_SIZE);
470
+ for (let j = 0; j < sizes.length; j++) {
471
+ header.writeUInt32LE(sizes[j], HEADER_SIZE + I32_SIZE * (1 + j));
472
+ }
473
+ write(header);
474
+ for (const item of serializedData) {
475
+ if (typeof item === "function") {
476
+ result.push(item);
477
+ } else {
478
+ write(item);
1169
479
  }
1170
- break;
1171
480
  }
1172
- default: {
1173
- throw new Error(
1174
- `Unknown typeof "${typeof thing}" in binary middleware`
1175
- );
481
+ continue;
482
+ } else if (type === "symbol") {
483
+ flush(i);
484
+ sectionStart = i + 1;
485
+ const operation =
486
+ /** @type {MEASURE_START_OPERATION_TYPE | MEASURE_END_OPERATION_TYPE} */
487
+ (/** @type {unknown} */ (thing));
488
+ if (operation === MEASURE_START_OPERATION) {
489
+ measureStack.push(writtenBytes);
490
+ } else if (operation === MEASURE_END_OPERATION) {
491
+ const size =
492
+ writtenBytes - /** @type {number} */ (measureStack.pop());
493
+ writeValuesSection([size], [], []);
1176
494
  }
495
+ continue;
496
+ } else {
497
+ sectionSize += ESTIMATED_VALUE_SIZE;
1177
498
  }
499
+ if (sectionSize >= MAX_SECTION_SIZE) flush(i + 1);
1178
500
  }
1179
- flush();
1180
-
1181
- allocationScope.leftOverBuffer = leftOverBuffer;
1182
-
1183
- // avoid leaking memory
1184
- currentBuffer = null;
1185
- leftOverBuffer = null;
1186
- allocationScope = /** @type {EXPECTED_ANY} */ (undefined);
1187
- const _buffers = buffers;
1188
- buffers = /** @type {EXPECTED_ANY} */ (undefined);
1189
- return _buffers;
501
+ flush(data.length);
502
+ return result;
1190
503
  }
1191
504
 
1192
505
  /**
@@ -1200,7 +513,7 @@ class BinaryMiddleware extends SerializerMiddleware {
1200
513
  }
1201
514
 
1202
515
  /**
1203
- * Create lazy deserialized. Internal, but called from the dispatch table.
516
+ * Create lazy deserialized.
1204
517
  * @param {SerializedType} content content
1205
518
  * @param {Context} context context object
1206
519
  * @returns {LazyFunction<DeserializedType, SerializedType>} lazy function
@@ -1234,20 +547,39 @@ class BinaryMiddleware extends SerializerMiddleware {
1234
547
  * @returns {DeserializedType} deserialized data
1235
548
  */
1236
549
  _deserialize(data, context) {
1237
- const state = new ReadState(data, context, this);
550
+ const state = new ReadState(data, context);
551
+ /** @type {DeserializedType | undefined} */
552
+ let result;
1238
553
  while (state.currentBuffer !== null) {
554
+ /** @type {DeserializedType} */
555
+ let part;
1239
556
  if (typeof state.currentBuffer === "function") {
1240
- state.result.push(this._deserializeLazy(state.currentBuffer, context));
557
+ part = [this._deserializeLazy(state.currentBuffer, context)];
1241
558
  state.nextDataItem();
1242
559
  } else {
1243
- dispatchTable[state.readU8()](state);
560
+ const header = state.readU8();
561
+ if (header === VALUES_HEADER) {
562
+ part = readValuesSection(state);
563
+ } else if (header === LAZY_HEADER) {
564
+ part = [
565
+ this._createLazyDeserialized(readLazySection(state), context)
566
+ ];
567
+ } else {
568
+ throw new Error(`Unexpected header byte 0x${header.toString(16)}`);
569
+ }
570
+ }
571
+ // a single-section stream needs no copying: reuse its array as the result
572
+ if (result === undefined) {
573
+ result = part;
574
+ } else {
575
+ for (let j = 0; j < part.length; j++) result.push(part[j]);
1244
576
  }
1245
577
  }
1246
- return state.result;
578
+ return result === undefined ? [] : result;
1247
579
  }
1248
580
  }
1249
581
 
1250
- module.exports = BinaryMiddleware;
582
+ BinaryMiddleware.MEASURE_END_OPERATION = MEASURE_END_OPERATION;
583
+ BinaryMiddleware.MEASURE_START_OPERATION = MEASURE_START_OPERATION;
1251
584
 
1252
- module.exports.MEASURE_END_OPERATION = MEASURE_END_OPERATION;
1253
- module.exports.MEASURE_START_OPERATION = MEASURE_START_OPERATION;
585
+ module.exports = BinaryMiddleware;