webpack 5.107.1 → 5.108.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 (360) hide show
  1. package/hot/dev-server.js +2 -0
  2. package/lib/APIPlugin.js +8 -4
  3. package/lib/CacheFacade.js +7 -0
  4. package/lib/Chunk.js +4 -0
  5. package/lib/ChunkGraph.js +30 -9
  6. package/lib/CircularModulesPlugin.js +190 -0
  7. package/lib/CleanPlugin.js +2 -1
  8. package/lib/Compilation.js +396 -65
  9. package/lib/Compiler.js +52 -14
  10. package/lib/ConcatenationScope.js +10 -3
  11. package/lib/ContextExclusionPlugin.js +1 -0
  12. package/lib/ContextModule.js +92 -47
  13. package/lib/ContextModuleFactory.js +45 -38
  14. package/lib/ContextReplacementPlugin.js +4 -0
  15. package/lib/DefinePlugin.js +89 -15
  16. package/lib/Dependency.js +111 -7
  17. package/lib/EntryOptionPlugin.js +39 -2
  18. package/lib/EntryPlugin.js +2 -0
  19. package/lib/ExportsInfo.js +314 -73
  20. package/lib/ExternalModule.js +82 -34
  21. package/lib/ExternalModuleFactoryPlugin.js +1 -0
  22. package/lib/ExternalsPlugin.js +1 -0
  23. package/lib/FileSystemInfo.js +173 -23
  24. package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
  25. package/lib/FlagDependencyExportsPlugin.js +23 -0
  26. package/lib/FlagDependencyUsagePlugin.js +87 -5
  27. package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
  28. package/lib/Generator.js +8 -0
  29. package/lib/HotModuleReplacementPlugin.js +65 -28
  30. package/lib/IgnorePlugin.js +1 -0
  31. package/lib/InitFragment.js +5 -0
  32. package/lib/JavascriptMetaInfoPlugin.js +7 -5
  33. package/lib/LazyBarrel.js +361 -0
  34. package/lib/LoaderTargetPlugin.js +1 -0
  35. package/lib/Module.js +21 -42
  36. package/lib/ModuleGraph.js +3 -2
  37. package/lib/ModuleProfile.js +27 -1
  38. package/lib/ModuleTemplate.js +2 -0
  39. package/lib/MultiCompiler.js +16 -0
  40. package/lib/MultiStats.js +1 -0
  41. package/lib/MultiWatching.js +2 -0
  42. package/lib/NodeStuffPlugin.js +22 -17
  43. package/lib/NormalModule.js +557 -77
  44. package/lib/NormalModuleReplacementPlugin.js +2 -0
  45. package/lib/PrefetchPlugin.js +2 -0
  46. package/lib/ProgressPlugin.js +9 -1
  47. package/lib/ProvidePlugin.js +1 -0
  48. package/lib/RawModule.js +20 -16
  49. package/lib/RecordIdsPlugin.js +1 -0
  50. package/lib/RuntimeGlobals.js +5 -0
  51. package/lib/RuntimePlugin.js +58 -26
  52. package/lib/RuntimeTemplate.js +278 -21
  53. package/lib/SelfModuleFactory.js +1 -0
  54. package/lib/SourceMapDevToolPlugin.js +105 -30
  55. package/lib/Stats.js +1 -0
  56. package/lib/Template.js +8 -2
  57. package/lib/TemplatedPathPlugin.js +473 -131
  58. package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
  59. package/lib/WarnDeprecatedOptionPlugin.js +4 -0
  60. package/lib/WarnNoModeSetPlugin.js +1 -0
  61. package/lib/WatchIgnorePlugin.js +1 -0
  62. package/lib/Watching.js +9 -0
  63. package/lib/WebpackOptionsApply.js +50 -5
  64. package/lib/asset/AssetBytesGenerator.js +11 -3
  65. package/lib/asset/AssetGenerator.js +47 -22
  66. package/lib/asset/AssetModule.js +47 -0
  67. package/lib/asset/AssetModulesPlugin.js +14 -14
  68. package/lib/asset/AssetParser.js +2 -2
  69. package/lib/asset/AssetSourceGenerator.js +8 -0
  70. package/lib/asset/RawDataUrlModule.js +12 -13
  71. package/lib/buildChunkGraph.js +88 -9
  72. package/lib/bun/BunTargetPlugin.js +48 -0
  73. package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
  74. package/lib/cache/AddManagedPathsPlugin.js +3 -0
  75. package/lib/cache/IdleFileCachePlugin.js +4 -0
  76. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  77. package/lib/cache/PackFileCacheStrategy.js +1 -0
  78. package/lib/cache/ResolverCachePlugin.js +2 -0
  79. package/lib/cache/getLazyHashedEtag.js +9 -2
  80. package/lib/cache/mergeEtags.js +2 -0
  81. package/lib/cli.js +109 -19
  82. package/lib/config/browserslistTargetHandler.js +99 -0
  83. package/lib/config/defaults.js +147 -7
  84. package/lib/config/defineConfig.js +31 -0
  85. package/lib/config/normalization.js +5 -0
  86. package/lib/config/target.js +181 -2
  87. package/lib/container/ContainerEntryModule.js +15 -14
  88. package/lib/container/ContainerExposedDependency.js +2 -2
  89. package/lib/container/ContainerReferencePlugin.js +1 -1
  90. package/lib/container/FallbackDependency.js +5 -7
  91. package/lib/container/FallbackModule.js +10 -9
  92. package/lib/container/RemoteModule.js +20 -10
  93. package/lib/container/RemoteRuntimeModule.js +14 -12
  94. package/lib/css/CssGenerator.js +353 -327
  95. package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
  96. package/lib/css/CssLoadingRuntimeModule.js +118 -47
  97. package/lib/css/CssModule.js +52 -23
  98. package/lib/css/CssModulesPlugin.js +107 -124
  99. package/lib/css/CssParser.js +2759 -2205
  100. package/lib/css/syntax.js +2859 -0
  101. package/lib/debug/ProfilingPlugin.js +2 -0
  102. package/lib/deno/DenoTargetPlugin.js +47 -0
  103. package/lib/dependencies/AMDDefineDependency.js +22 -17
  104. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
  105. package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
  106. package/lib/dependencies/AMDRequireContextDependency.js +7 -11
  107. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
  108. package/lib/dependencies/AMDRequireDependency.js +24 -20
  109. package/lib/dependencies/CachedConstDependency.js +3 -0
  110. package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
  111. package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
  112. package/lib/dependencies/CommonJsExportsDependency.js +21 -16
  113. package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
  114. package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
  115. package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
  116. package/lib/dependencies/CommonJsPlugin.js +1 -1
  117. package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
  118. package/lib/dependencies/CommonJsRequireDependency.js +42 -11
  119. package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
  120. package/lib/dependencies/ConstDependency.js +16 -11
  121. package/lib/dependencies/ContextDependency.js +4 -0
  122. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
  123. package/lib/dependencies/ContextElementDependency.js +23 -14
  124. package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
  125. package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
  126. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  127. package/lib/dependencies/CssIcssExportDependency.js +512 -574
  128. package/lib/dependencies/CssIcssImportDependency.js +9 -9
  129. package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
  130. package/lib/dependencies/CssImportDependency.js +25 -1
  131. package/lib/dependencies/CssUrlDependency.js +23 -14
  132. package/lib/dependencies/DllEntryDependency.js +9 -13
  133. package/lib/dependencies/ExportBindingInitFragment.js +164 -0
  134. package/lib/dependencies/ExportsInfoDependency.js +12 -12
  135. package/lib/dependencies/ExternalModuleDependency.js +8 -5
  136. package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
  137. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
  138. package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
  139. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
  140. package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
  141. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
  142. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
  143. package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
  144. package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
  145. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
  146. package/lib/dependencies/HarmonyExportInitFragment.js +22 -20
  147. package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
  148. package/lib/dependencies/HarmonyExports.js +4 -1
  149. package/lib/dependencies/HarmonyImportDependency.js +24 -0
  150. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
  151. package/lib/dependencies/HarmonyImportGuard.js +254 -0
  152. package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
  153. package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
  154. package/lib/dependencies/HarmonyLinkingError.js +1 -0
  155. package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
  156. package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +267 -154
  157. package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
  158. package/lib/dependencies/HtmlInlineScriptDependency.js +20 -27
  159. package/lib/dependencies/HtmlInlineStyleDependency.js +62 -11
  160. package/lib/dependencies/HtmlSourceDependency.js +18 -0
  161. package/lib/dependencies/ImportContextDependency.js +5 -9
  162. package/lib/dependencies/ImportDependency.js +44 -2
  163. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
  164. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
  165. package/lib/dependencies/ImportMetaPlugin.js +74 -30
  166. package/lib/dependencies/ImportParserPlugin.js +19 -0
  167. package/lib/dependencies/ImportWeakDependency.js +1 -0
  168. package/lib/dependencies/JsonExportsDependency.js +9 -9
  169. package/lib/dependencies/LoaderImportDependency.js +1 -0
  170. package/lib/dependencies/LocalModule.js +11 -12
  171. package/lib/dependencies/LocalModuleDependency.js +11 -13
  172. package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
  173. package/lib/dependencies/ModuleDependency.js +7 -0
  174. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
  175. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
  176. package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
  177. package/lib/dependencies/ProvidedDependency.js +31 -27
  178. package/lib/dependencies/PureExpressionDependency.js +7 -9
  179. package/lib/dependencies/RequireEnsureDependency.js +12 -13
  180. package/lib/dependencies/RequireHeaderDependency.js +3 -4
  181. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
  182. package/lib/dependencies/RequireResolveContextDependency.js +7 -11
  183. package/lib/dependencies/RequireResolveDependency.js +1 -0
  184. package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
  185. package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
  186. package/lib/dependencies/StaticExportsDependency.js +10 -10
  187. package/lib/dependencies/SystemPlugin.js +2 -0
  188. package/lib/dependencies/URLContextDependency.js +5 -7
  189. package/lib/dependencies/URLDependency.js +14 -16
  190. package/lib/dependencies/UnsupportedDependency.js +8 -13
  191. package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
  192. package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
  193. package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
  194. package/lib/dependencies/WorkerDependency.js +19 -8
  195. package/lib/dependencies/WorkerPlugin.js +40 -10
  196. package/lib/dependencies/processExportInfo.js +13 -11
  197. package/lib/dll/DelegatedModule.js +29 -15
  198. package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
  199. package/lib/dll/DelegatedPlugin.js +1 -0
  200. package/lib/dll/DllEntryPlugin.js +3 -0
  201. package/lib/dll/DllModule.js +3 -2
  202. package/lib/dll/DllPlugin.js +16 -0
  203. package/lib/dll/DllReferencePlugin.js +3 -0
  204. package/lib/dll/LibManifestPlugin.js +1 -0
  205. package/lib/electron/ElectronTargetPlugin.js +22 -4
  206. package/lib/errors/ConcurrentCompilationError.js +1 -0
  207. package/lib/errors/HookWebpackError.js +11 -13
  208. package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
  209. package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
  210. package/lib/errors/JSONParseError.js +9 -8
  211. package/lib/errors/ModuleBuildError.js +16 -13
  212. package/lib/errors/ModuleDependencyError.js +8 -1
  213. package/lib/errors/ModuleDependencyWarning.js +8 -1
  214. package/lib/errors/ModuleError.js +5 -11
  215. package/lib/errors/ModuleHashingError.js +4 -0
  216. package/lib/errors/ModuleNotFoundError.js +3 -0
  217. package/lib/errors/ModuleParseError.js +5 -11
  218. package/lib/errors/ModuleRestoreError.js +2 -0
  219. package/lib/errors/ModuleStoreError.js +3 -0
  220. package/lib/errors/ModuleWarning.js +7 -11
  221. package/lib/errors/NodeStuffInWebError.js +1 -0
  222. package/lib/errors/NonErrorEmittedError.js +2 -0
  223. package/lib/errors/UnhandledSchemeError.js +1 -0
  224. package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
  225. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
  226. package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
  227. package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
  228. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
  229. package/lib/hmr/LazyCompilationPlugin.js +134 -6
  230. package/lib/html/HtmlGenerator.js +292 -50
  231. package/lib/html/HtmlModule.js +40 -0
  232. package/lib/html/HtmlModulesPlugin.js +287 -60
  233. package/lib/html/HtmlParser.js +1108 -1099
  234. package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
  235. package/lib/ids/IdHelpers.js +4 -2
  236. package/lib/index.js +19 -0
  237. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  238. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
  239. package/lib/javascript/JavascriptGenerator.js +6 -2
  240. package/lib/javascript/JavascriptModule.js +54 -0
  241. package/lib/javascript/JavascriptModulesPlugin.js +257 -102
  242. package/lib/javascript/JavascriptParser.js +286 -159
  243. package/lib/json/JsonModule.js +40 -0
  244. package/lib/json/JsonModulesPlugin.js +7 -0
  245. package/lib/json/JsonParser.js +4 -2
  246. package/lib/library/AssignLibraryPlugin.js +5 -3
  247. package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
  248. package/lib/library/FalseIIFEUmdWarning.js +1 -0
  249. package/lib/library/ModuleLibraryPlugin.js +54 -29
  250. package/lib/library/SystemLibraryPlugin.js +3 -3
  251. package/lib/node/NodeTargetPlugin.js +1 -0
  252. package/lib/node/NodeWatchFileSystem.js +38 -22
  253. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
  254. package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
  255. package/lib/optimize/ConcatenatedModule.js +397 -78
  256. package/lib/optimize/ConstExportsPlugin.js +211 -0
  257. package/lib/optimize/InlineExports.js +178 -0
  258. package/lib/optimize/InnerGraph.js +372 -275
  259. package/lib/optimize/InnerGraphPlugin.js +196 -99
  260. package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
  261. package/lib/optimize/RealContentHashPlugin.js +14 -1
  262. package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
  263. package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
  264. package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
  265. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
  266. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
  267. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
  268. package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
  269. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  270. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
  271. package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
  272. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
  273. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
  274. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
  275. package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
  276. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  277. package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
  278. package/lib/runtime/WorkerRuntimeModule.js +33 -0
  279. package/lib/schemes/HttpUriPlugin.js +3 -2
  280. package/lib/serialization/AggregateErrorSerializer.js +7 -6
  281. package/lib/serialization/ArraySerializer.js +4 -8
  282. package/lib/serialization/BinaryMiddleware.js +538 -468
  283. package/lib/serialization/DateObjectSerializer.js +2 -2
  284. package/lib/serialization/ErrorObjectSerializer.js +7 -6
  285. package/lib/serialization/MapObjectSerializer.js +5 -9
  286. package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
  287. package/lib/serialization/ObjectMiddleware.js +50 -13
  288. package/lib/serialization/PlainObjectSerializer.js +9 -8
  289. package/lib/serialization/RegExpObjectSerializer.js +2 -2
  290. package/lib/serialization/Serializer.js +1 -0
  291. package/lib/serialization/SetObjectSerializer.js +4 -8
  292. package/lib/sharing/ConsumeSharedModule.js +6 -7
  293. package/lib/sharing/ConsumeSharedPlugin.js +1 -0
  294. package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
  295. package/lib/sharing/ProvideSharedDependency.js +30 -15
  296. package/lib/sharing/ProvideSharedModule.js +30 -11
  297. package/lib/sharing/ProvideSharedPlugin.js +4 -2
  298. package/lib/sharing/SharePlugin.js +3 -0
  299. package/lib/sharing/ShareRuntimeModule.js +18 -16
  300. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  301. package/lib/sharing/utils.js +1 -1
  302. package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
  303. package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
  304. package/lib/stats/StatsFactory.js +11 -9
  305. package/lib/stats/StatsPrinter.js +9 -2
  306. package/lib/url/URLParserPlugin.js +5 -2
  307. package/lib/util/AsyncQueue.js +10 -0
  308. package/lib/util/LazyBucketSortedSet.js +5 -0
  309. package/lib/util/LazySet.js +6 -4
  310. package/lib/util/LocConverter.js +11 -1
  311. package/lib/util/Semaphore.js +1 -0
  312. package/lib/util/SourceProcessor.js +106 -0
  313. package/lib/util/TupleSet.js +1 -0
  314. package/lib/util/WeakTupleMap.js +27 -1
  315. package/lib/util/chainedImports.js +3 -3
  316. package/lib/util/comparators.js +2 -2
  317. package/lib/util/concatenate.js +31 -7
  318. package/lib/util/createHash.js +0 -1
  319. package/lib/util/deterministicGrouping.js +19 -12
  320. package/lib/util/extractSourceMap.js +1 -1
  321. package/lib/util/findGraphRoots.js +2 -0
  322. package/lib/util/fs.js +16 -6
  323. package/lib/util/hash/DebugHash.js +1 -0
  324. package/lib/util/hash/hash-digest.js +24 -15
  325. package/lib/util/identifier.js +7 -0
  326. package/lib/util/internalSerializables.js +11 -2
  327. package/lib/util/magicComment.js +42 -0
  328. package/lib/util/makeSerializable.js +1 -0
  329. package/lib/util/nonNumericOnlyHash.js +30 -1
  330. package/lib/util/property.js +7 -1
  331. package/lib/util/publicPathPlaceholder.js +64 -0
  332. package/lib/util/registerExternalSerializer.js +4 -4
  333. package/lib/wasm-async/AsyncWasmModule.js +77 -0
  334. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
  335. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
  336. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  337. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
  338. package/lib/wasm-sync/SyncWasmModule.js +39 -0
  339. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
  340. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
  341. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
  342. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  343. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  344. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
  345. package/lib/wasm-sync/WebAssemblyParser.js +7 -3
  346. package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
  347. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
  348. package/package.json +36 -28
  349. package/schemas/WebpackOptions.check.js +1 -1
  350. package/schemas/WebpackOptions.json +212 -3
  351. package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
  352. package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
  353. package/schemas/plugins/HtmlParserOptions.check.js +6 -0
  354. package/schemas/plugins/HtmlParserOptions.json +3 -0
  355. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  356. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  357. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  358. package/types.d.ts +1592 -314
  359. package/lib/css/walkCssTokens.js +0 -2020
  360. package/lib/util/AppendOnlyStackedSet.js +0 -93
@@ -28,8 +28,11 @@ const getDefaultTarget = (context) => {
28
28
  * @property {boolean | null=} browser browser platform, running in a normal web browser
29
29
  * @property {boolean | null=} webworker (Web)Worker platform, running in a web/shared/service worker
30
30
  * @property {boolean | null=} node node platform, require of node built-in modules is available
31
+ * @property {boolean | null=} deno deno platform, node built-in modules (via the `node:` specifier) and web APIs are available
32
+ * @property {boolean | null=} bun bun platform, bun and node built-in modules are available
31
33
  * @property {boolean | null=} nwjs nwjs platform, require of legacy nw.gui is available
32
34
  * @property {boolean | null=} electron electron platform, require of some electron built-in modules is available
35
+ * @property {boolean | null=} universal universal ESM target spanning both web and node (target `"universal"` or `["web", "node"]`)
33
36
  */
34
37
 
35
38
  /**
@@ -46,6 +49,7 @@ const getDefaultTarget = (context) => {
46
49
  * @property {boolean | null} require has require function available
47
50
  * @property {boolean | null} nodeBuiltins has node.js built-in modules available
48
51
  * @property {boolean | null} nodePrefixForCoreModules node.js allows to use `node:` prefix for core modules
52
+ * @property {boolean | null} nodeBuiltinModuleGetter node.js exposes `process.getBuiltinModule()` to synchronously load core modules
49
53
  * @property {boolean | null} importMetaDirnameAndFilename node.js allows to use `import.meta.dirname` and `import.meta.filename`
50
54
  * @property {boolean | null} document has document available (allows script tags)
51
55
  * @property {boolean | null} importScripts has importScripts available
@@ -58,8 +62,12 @@ const getDefaultTarget = (context) => {
58
62
  * Defines the ecma target properties type used by this module.
59
63
  * @typedef {object} EcmaTargetProperties
60
64
  * @property {boolean | null} globalThis has globalThis variable available
65
+ * @property {boolean | null} symbol `Symbol` is available
66
+ * @property {boolean | null} hasOwn `Object.hasOwn` is available
61
67
  * @property {boolean | null} bigIntLiteral big int literal syntax is available
62
- * @property {boolean | null} const const and let variable declarations are available
68
+ * @property {boolean | null} const const variable declarations are available
69
+ * @property {boolean | null} let let variable declarations are available
70
+ * @property {boolean | null} logicalAssignment logical assignment operators (`||=`, `&&=`, `??=`) are available
63
71
  * @property {boolean | null} methodShorthand object method shorthand is available
64
72
  * @property {boolean | null} arrowFunction arrow functions are available
65
73
  * @property {boolean | null} forOf for of iteration is available
@@ -68,6 +76,7 @@ const getDefaultTarget = (context) => {
68
76
  * @property {boolean | null} dynamicImportInWorker async import() is available when creating a worker
69
77
  * @property {boolean | null} module ESM syntax is available (when in module)
70
78
  * @property {boolean | null} optionalChaining optional chaining is available
79
+ * @property {boolean | null} spread spread and rest in array/object literals and calls is available
71
80
  * @property {boolean | null} templateLiteral template literal is available
72
81
  * @property {boolean | null} asyncFunction async functions and await are available
73
82
  */
@@ -133,6 +142,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
133
142
  /^web$/,
134
143
  () => ({
135
144
  node: false,
145
+ deno: false,
146
+ bun: false,
136
147
  web: true,
137
148
  webworker: null,
138
149
  browser: true,
@@ -154,6 +165,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
154
165
  /^webworker$/,
155
166
  () => ({
156
167
  node: false,
168
+ deno: false,
169
+ bun: false,
157
170
  web: true,
158
171
  webworker: true,
159
172
  browser: true,
@@ -169,6 +182,39 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
169
182
  global: false
170
183
  })
171
184
  ],
185
+ [
186
+ "universal",
187
+ "Universal target running in browser, web worker, Node.js, Electron and NW.js. Output is always ECMAScript modules.",
188
+ /^universal$/,
189
+ // merged web + webworker + node + electron + nwjs properties; output is
190
+ // always ESM, so `require` (sync CommonJS) is never available
191
+ () => ({
192
+ node: null,
193
+ deno: null,
194
+ bun: null,
195
+ web: null,
196
+ webworker: null,
197
+ browser: null,
198
+ electron: null,
199
+ nwjs: null,
200
+
201
+ electronMain: null,
202
+ electronPreload: null,
203
+ electronRenderer: null,
204
+
205
+ document: null,
206
+ importScriptsInWorker: null,
207
+ fetchWasm: null,
208
+ nodeBuiltins: null,
209
+ importScripts: null,
210
+ require: false,
211
+ global: null,
212
+
213
+ module: true,
214
+ dynamicImport: true,
215
+ dynamicImportInWorker: true
216
+ })
217
+ ],
172
218
  [
173
219
  "[async-]node[X[.Y]]",
174
220
  "Node.js in version X.Y. The 'async-' prefix will load chunks asynchronously via 'fs' and 'vm' instead of 'require()'. Examples: node14.5, async-node10.",
@@ -178,6 +224,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
178
224
  // see https://node.green/
179
225
  return {
180
226
  node: true,
227
+ deno: false,
228
+ bun: false,
181
229
  web: false,
182
230
  webworker: false,
183
231
  browser: false,
@@ -188,6 +236,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
188
236
  nodeBuiltins: true,
189
237
  // v16.0.0, v14.18.0
190
238
  nodePrefixForCoreModules: Number(major) < 15 ? v(14, 18) : v(16),
239
+ // v22.3.0, backported to v20.16.0; use the conservative single threshold
240
+ nodeBuiltinModuleGetter: v(22, 3),
191
241
  // Added in: v21.2.0, v20.11.0, but Node.js will output experimental warning, we don't want it
192
242
  // v24.0.0, v22.16.0 - This property is no longer experimental.
193
243
  importMetaDirnameAndFilename: v(22, 16),
@@ -198,9 +248,14 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
198
248
  importScriptsInWorker: false,
199
249
 
200
250
  globalThis: v(12),
251
+ symbol: v(0, 12),
252
+ hasOwn: v(16, 9),
201
253
  const: v(6),
254
+ let: v(6),
255
+ logicalAssignment: v(15),
202
256
  templateLiteral: v(4),
203
257
  optionalChaining: v(14),
258
+ spread: v(8, 3),
204
259
  methodShorthand: v(4),
205
260
  arrowFunction: v(6),
206
261
  asyncFunction: v(7, 6),
@@ -213,6 +268,108 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
213
268
  };
214
269
  }
215
270
  ],
271
+ [
272
+ "deno[X[.Y]]",
273
+ "Deno in version X.Y. Emits ESM output; node.js built-ins are available via the required 'node:' specifier and web APIs (fetch, WebAssembly, ...) are available too. Examples: deno2, deno1.40.",
274
+ /^deno((\d+)(?:\.(\d+))?)?$/,
275
+ (_, major, minor) => {
276
+ const v = versionDependent(major, minor);
277
+ // Deno ships a modern V8, so syntax features are available since 1.0.
278
+ return {
279
+ node: true,
280
+ deno: true,
281
+ web: true,
282
+ webworker: false,
283
+ browser: false,
284
+ electron: false,
285
+ nwjs: false,
286
+
287
+ require: false,
288
+ nodeBuiltins: true,
289
+ // Deno only resolves node.js core modules through the `node:` specifier
290
+ nodePrefixForCoreModules: true,
291
+ // process.getBuiltinModule() - v2.1.0
292
+ nodeBuiltinModuleGetter: v(2, 1),
293
+ // import.meta.dirname / import.meta.filename - v1.40.0
294
+ importMetaDirnameAndFilename: v(1, 40),
295
+ global: false,
296
+ document: false,
297
+ fetchWasm: true,
298
+ importScripts: false,
299
+ importScriptsInWorker: false,
300
+
301
+ globalThis: true,
302
+ symbol: true,
303
+ hasOwn: true,
304
+ bigIntLiteral: true,
305
+ const: true,
306
+ let: true,
307
+ logicalAssignment: true,
308
+ methodShorthand: true,
309
+ arrowFunction: true,
310
+ forOf: true,
311
+ destructuring: true,
312
+ dynamicImport: true,
313
+ dynamicImportInWorker: true,
314
+ module: true,
315
+ optionalChaining: true,
316
+ spread: true,
317
+ templateLiteral: true,
318
+ asyncFunction: true
319
+ };
320
+ }
321
+ ],
322
+ [
323
+ "bun[X[.Y]]",
324
+ "Bun in version X.Y. Output is always ECMAScript modules. Examples: bun, bun1.1.",
325
+ /^bun((\d+)(?:\.(\d+))?)?$/,
326
+ () => ({
327
+ // Bun is a modern, Node.js-compatible runtime; every released version
328
+ // supports the full modern ECMAScript feature set, so the version is
329
+ // accepted but does not gate any feature. Output is always ESM, so sync
330
+ // CommonJS `require` is never available.
331
+ node: true,
332
+ bun: true,
333
+ web: false,
334
+ webworker: false,
335
+ browser: false,
336
+ electron: false,
337
+ nwjs: false,
338
+
339
+ require: false,
340
+ nodeBuiltins: true,
341
+ nodePrefixForCoreModules: true,
342
+ nodeBuiltinModuleGetter: true,
343
+ importMetaDirnameAndFilename: true,
344
+ // Bun implements web-standard globals; use `globalThis` and load wasm
345
+ // via `fetch()` (Bun's fetch resolves `file:` URLs) like the deno target,
346
+ // instead of proprietary `Bun.*` runtime APIs.
347
+ global: false,
348
+ document: false,
349
+ fetchWasm: true,
350
+ importScripts: false,
351
+ importScriptsInWorker: false,
352
+
353
+ globalThis: true,
354
+ symbol: true,
355
+ hasOwn: true,
356
+ const: true,
357
+ let: true,
358
+ logicalAssignment: true,
359
+ templateLiteral: true,
360
+ optionalChaining: true,
361
+ spread: true,
362
+ methodShorthand: true,
363
+ arrowFunction: true,
364
+ asyncFunction: true,
365
+ forOf: true,
366
+ destructuring: true,
367
+ bigIntLiteral: true,
368
+ dynamicImport: true,
369
+ dynamicImportInWorker: true,
370
+ module: true
371
+ })
372
+ ],
216
373
  [
217
374
  "electron[X[.Y]]-main/preload/renderer",
218
375
  "Electron in version X.Y. Script is running in main, preload resp. renderer context.",
@@ -222,6 +379,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
222
379
  // see https://node.green/ + https://github.com/electron/releases
223
380
  return {
224
381
  node: true,
382
+ deno: false,
383
+ bun: false,
225
384
  web: context !== "main",
226
385
  webworker: false,
227
386
  browser: false,
@@ -247,9 +406,15 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
247
406
  importScriptsInWorker: true,
248
407
 
249
408
  globalThis: v(5),
409
+ symbol: v(0, 24),
410
+ hasOwn: v(16),
250
411
  const: v(1, 1),
412
+ let: v(1, 1),
413
+ // 10.0.0 - Chromium 85
414
+ logicalAssignment: v(10),
251
415
  templateLiteral: v(1, 1),
252
416
  optionalChaining: v(8),
417
+ spread: v(2),
253
418
  methodShorthand: v(1, 1),
254
419
  arrowFunction: v(1, 1),
255
420
  asyncFunction: v(1, 7),
@@ -258,7 +423,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
258
423
  bigIntLiteral: v(4),
259
424
  dynamicImport: v(11),
260
425
  dynamicImportInWorker: v(11),
261
- module: v(11)
426
+ // 28.0.0 - ESM support was added
427
+ module: v(28)
262
428
  };
263
429
  }
264
430
  ],
@@ -271,6 +437,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
271
437
  // see https://node.green/ + https://github.com/nwjs/nw.js/blob/nw48/CHANGELOG.md
272
438
  return {
273
439
  node: true,
440
+ deno: false,
441
+ bun: false,
274
442
  web: true,
275
443
  webworker: null,
276
444
  browser: false,
@@ -286,9 +454,15 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
286
454
  require: false,
287
455
 
288
456
  globalThis: v(0, 43),
457
+ symbol: v(0, 12),
458
+ hasOwn: v(0, 58),
289
459
  const: v(0, 15),
460
+ let: v(0, 15),
461
+ // 0.48.0 - Chromium 85
462
+ logicalAssignment: v(0, 48),
290
463
  templateLiteral: v(0, 13),
291
464
  optionalChaining: v(0, 44),
465
+ spread: v(0, 23),
292
466
  methodShorthand: v(0, 15),
293
467
  arrowFunction: v(0, 15),
294
468
  asyncFunction: v(0, 21),
@@ -310,8 +484,11 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
310
484
  if (v < 1000) v += 2009;
311
485
  return {
312
486
  const: v >= 2015,
487
+ let: v >= 2015,
488
+ logicalAssignment: v >= 2021,
313
489
  templateLiteral: v >= 2015,
314
490
  optionalChaining: v >= 2020,
491
+ spread: v >= 2018,
315
492
  methodShorthand: v >= 2015,
316
493
  arrowFunction: v >= 2015,
317
494
  forOf: v >= 2015,
@@ -319,6 +496,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
319
496
  module: v >= 2015,
320
497
  asyncFunction: v >= 2017,
321
498
  globalThis: v >= 2020,
499
+ symbol: v >= 2015,
500
+ hasOwn: v >= 2022,
322
501
  bigIntLiteral: v >= 2020,
323
502
  dynamicImport: v >= 2020,
324
503
  dynamicImportInWorker: v >= 2020
@@ -32,8 +32,8 @@ const ContainerExposedDependency = require("./ContainerExposedDependency");
32
32
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
33
33
  /** @typedef {import("../RequestShortener")} RequestShortener */
34
34
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
35
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
36
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
35
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[string, ExposesList, string]>} ObjectDeserializerContext */
36
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[string, ExposesList, string]>} ObjectSerializerContext */
37
37
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
38
38
 
39
39
  /**
@@ -220,11 +220,12 @@ class ContainerEntryModule extends Module {
220
220
  );
221
221
  }
222
222
 
223
+ const cst = runtimeTemplate.renderConst();
223
224
  const source = Template.asString([
224
- "var moduleMap = {",
225
+ `${cst} moduleMap = {`,
225
226
  Template.indent(getters.join(",\n")),
226
227
  "};",
227
- `var get = ${runtimeTemplate.basicFunction("module, getScope", [
228
+ `${cst} get = ${runtimeTemplate.basicFunction("module, getScope", [
228
229
  `${RuntimeGlobals.currentRemoteGetScope} = getScope;`,
229
230
  // reusing the getScope variable to avoid creating a new var (and module is also used later)
230
231
  "getScope = (",
@@ -242,10 +243,10 @@ class ContainerEntryModule extends Module {
242
243
  `${RuntimeGlobals.currentRemoteGetScope} = undefined;`,
243
244
  "return getScope;"
244
245
  ])};`,
245
- `var init = ${runtimeTemplate.basicFunction("shareScope, initScope", [
246
+ `${cst} init = ${runtimeTemplate.basicFunction("shareScope, initScope", [
246
247
  `if (!${RuntimeGlobals.shareScopeMap}) return;`,
247
- `var name = ${JSON.stringify(this._shareScope)}`,
248
- `var oldScope = ${RuntimeGlobals.shareScopeMap}[name];`,
248
+ `${cst} name = ${JSON.stringify(this._shareScope)}`,
249
+ `${cst} oldScope = ${RuntimeGlobals.shareScopeMap}[name];`,
249
250
  'if(oldScope && oldScope !== shareScope) throw new Error("Container initialization failed as it has already been initialized with a different share scope");',
250
251
  `${RuntimeGlobals.shareScopeMap}[name] = shareScope;`,
251
252
  `return ${RuntimeGlobals.initializeSharing}(name, initScope);`
@@ -287,10 +288,7 @@ class ContainerEntryModule extends Module {
287
288
  * @param {ObjectSerializerContext} context context
288
289
  */
289
290
  serialize(context) {
290
- const { write } = context;
291
- write(this._name);
292
- write(this._exposes);
293
- write(this._shareScope);
291
+ context.write(this._name).write(this._exposes).write(this._shareScope);
294
292
  super.serialize(context);
295
293
  }
296
294
 
@@ -300,9 +298,12 @@ class ContainerEntryModule extends Module {
300
298
  * @returns {ContainerEntryModule} deserialized container entry module
301
299
  */
302
300
  static deserialize(context) {
303
- const { read } = context;
304
- const obj = new ContainerEntryModule(read(), read(), read());
305
- obj.deserialize(context);
301
+ const name = context.read();
302
+ const c1 = context.rest;
303
+ const exposes = c1.read();
304
+ const c2 = c1.rest;
305
+ const obj = new ContainerEntryModule(name, exposes, c2.read());
306
+ obj.deserialize(c2.rest);
306
307
  return obj;
307
308
  }
308
309
  }
@@ -8,8 +8,8 @@
8
8
  const ModuleDependency = require("../dependencies/ModuleDependency");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
10
 
11
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
12
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
11
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[string]>} ObjectDeserializerContext */
12
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[string]>} ObjectSerializerContext */
13
13
 
14
14
  class ContainerExposedDependency extends ModuleDependency {
15
15
  /**
@@ -28,7 +28,7 @@ class ContainerReferencePlugin {
28
28
  * @param {ContainerReferencePluginOptions} options options
29
29
  */
30
30
  constructor(options) {
31
- /** @typedef {ContainerReferencePluginOptions} */
31
+ /** @type {ContainerReferencePluginOptions} */
32
32
  this.options = options;
33
33
  }
34
34
 
@@ -9,8 +9,8 @@ const Dependency = require("../Dependency");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
10
 
11
11
  /** @typedef {import("./RemoteModule").ExternalRequests} ExternalRequests */
12
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
13
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
12
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[ExternalRequests]>} ObjectDeserializerContext */
13
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[ExternalRequests]>} ObjectSerializerContext */
14
14
 
15
15
  class FallbackDependency extends Dependency {
16
16
  /**
@@ -44,8 +44,7 @@ class FallbackDependency extends Dependency {
44
44
  * @param {ObjectSerializerContext} context context
45
45
  */
46
46
  serialize(context) {
47
- const { write } = context;
48
- write(this.requests);
47
+ context.write(this.requests);
49
48
  super.serialize(context);
50
49
  }
51
50
 
@@ -55,9 +54,8 @@ class FallbackDependency extends Dependency {
55
54
  * @returns {FallbackDependency} deserialize fallback dependency
56
55
  */
57
56
  static deserialize(context) {
58
- const { read } = context;
59
- const obj = new FallbackDependency(read());
60
- obj.deserialize(context);
57
+ const obj = new FallbackDependency(context.read());
58
+ obj.deserialize(context.rest);
61
59
  return obj;
62
60
  }
63
61
  }
@@ -32,8 +32,8 @@ const FallbackItemDependency = require("./FallbackItemDependency");
32
32
  /** @typedef {import("../Module").SourceTypes} SourceTypes */
33
33
  /** @typedef {import("../RequestShortener")} RequestShortener */
34
34
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
35
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
36
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
35
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[ExternalRequests]>} ObjectDeserializerContext */
36
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[ExternalRequests]>} ObjectSerializerContext */
37
37
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
38
38
  /** @typedef {import("./RemoteModule").ExternalRequests} ExternalRequests */
39
39
 
@@ -149,10 +149,12 @@ class FallbackModule extends Module {
149
149
  const ids = this.dependencies.map((dep) =>
150
150
  chunkGraph.getModuleId(/** @type {Module} */ (moduleGraph.getModule(dep)))
151
151
  );
152
+ const cst = runtimeTemplate.renderConst();
153
+ const lt = runtimeTemplate.renderLet();
152
154
  const code = Template.asString([
153
- `var ids = ${JSON.stringify(ids)};`,
154
- "var error, result, i = 0;",
155
- `var loop = ${runtimeTemplate.basicFunction("next", [
155
+ `${cst} ids = ${JSON.stringify(ids)};`,
156
+ `${lt} error, result, i = 0;`,
157
+ `${cst} loop = ${runtimeTemplate.basicFunction("next", [
156
158
  "while(i < ids.length) {",
157
159
  Template.indent([
158
160
  `try { next = ${RuntimeGlobals.require}(ids[i++]); } catch(e) { return handleError(e); }`,
@@ -161,11 +163,11 @@ class FallbackModule extends Module {
161
163
  "}",
162
164
  "if(error) throw error;"
163
165
  ])}`,
164
- `var handleResult = ${runtimeTemplate.basicFunction("result", [
166
+ `${cst} handleResult = ${runtimeTemplate.basicFunction("result", [
165
167
  "if(result) return result;",
166
168
  "return loop();"
167
169
  ])};`,
168
- `var handleError = ${runtimeTemplate.basicFunction("e", [
170
+ `${cst} handleError = ${runtimeTemplate.basicFunction("e", [
169
171
  "error = e;",
170
172
  "return loop();"
171
173
  ])};`,
@@ -182,8 +184,7 @@ class FallbackModule extends Module {
182
184
  * @param {ObjectSerializerContext} context context
183
185
  */
184
186
  serialize(context) {
185
- const { write } = context;
186
- write(this.requests);
187
+ context.write(this.requests);
187
188
  super.serialize(context);
188
189
  }
189
190
 
@@ -34,8 +34,8 @@ const RemoteToExternalDependency = require("./RemoteToExternalDependency");
34
34
  /** @typedef {import("../Module").ExportsType} ExportsType */
35
35
  /** @typedef {import("../RequestShortener")} RequestShortener */
36
36
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
37
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
38
- /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext} ObjectSerializerContext */
37
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[string, ExternalRequests, string, string]>} ObjectDeserializerContext */
38
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[string, ExternalRequests, string, string]>} ObjectSerializerContext */
39
39
  /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
40
40
  /** @typedef {import("../Module").BasicSourceTypes} BasicSourceTypes */
41
41
 
@@ -212,11 +212,11 @@ class RemoteModule extends Module {
212
212
  * @param {ObjectSerializerContext} context context
213
213
  */
214
214
  serialize(context) {
215
- const { write } = context;
216
- write(this.request);
217
- write(this.externalRequests);
218
- write(this.internalRequest);
219
- write(this.shareScope);
215
+ context
216
+ .write(this.request)
217
+ .write(this.externalRequests)
218
+ .write(this.internalRequest)
219
+ .write(this.shareScope);
220
220
  super.serialize(context);
221
221
  }
222
222
 
@@ -226,9 +226,19 @@ class RemoteModule extends Module {
226
226
  * @returns {RemoteModule} deserialized module
227
227
  */
228
228
  static deserialize(context) {
229
- const { read } = context;
230
- const obj = new RemoteModule(read(), read(), read(), read());
231
- obj.deserialize(context);
229
+ const request = context.read();
230
+ const c1 = context.rest;
231
+ const externalRequests = c1.read();
232
+ const c2 = c1.rest;
233
+ const internalRequest = c2.read();
234
+ const c3 = c2.rest;
235
+ const obj = new RemoteModule(
236
+ request,
237
+ externalRequests,
238
+ internalRequest,
239
+ c3.read()
240
+ );
241
+ obj.deserialize(c3.rest);
232
242
  return obj;
233
243
  }
234
244
  }
@@ -60,13 +60,15 @@ class RemoteRuntimeModule extends RuntimeModule {
60
60
  idToExternalAndNameMapping[id] = [shareScope, name, externalModuleId];
61
61
  }
62
62
  }
63
+ const cst = runtimeTemplate.renderConst();
64
+ const lt = runtimeTemplate.renderLet();
63
65
  return Template.asString([
64
- `var chunkMapping = ${JSON.stringify(
66
+ `${cst} chunkMapping = ${JSON.stringify(
65
67
  chunkToRemotesMapping,
66
68
  null,
67
69
  "\t"
68
70
  )};`,
69
- `var idToExternalAndNameMapping = ${JSON.stringify(
71
+ `${cst} idToExternalAndNameMapping = ${JSON.stringify(
70
72
  idToExternalAndNameMapping,
71
73
  null,
72
74
  "\t"
@@ -77,13 +79,13 @@ class RemoteRuntimeModule extends RuntimeModule {
77
79
  `if(${RuntimeGlobals.hasOwnProperty}(chunkMapping, chunkId)) {`,
78
80
  Template.indent([
79
81
  `chunkMapping[chunkId].forEach(${runtimeTemplate.basicFunction("id", [
80
- `var getScope = ${RuntimeGlobals.currentRemoteGetScope};`,
82
+ `${lt} getScope = ${RuntimeGlobals.currentRemoteGetScope};`,
81
83
  "if(!getScope) getScope = [];",
82
- "var data = idToExternalAndNameMapping[id];",
84
+ `${cst} data = idToExternalAndNameMapping[id];`,
83
85
  "if(getScope.indexOf(data) >= 0) return;",
84
86
  "getScope.push(data);",
85
87
  "if(data.p) return promises.push(data.p);",
86
- `var onError = ${runtimeTemplate.basicFunction("error", [
88
+ `${cst} onError = ${runtimeTemplate.basicFunction("error", [
87
89
  'if(!error) error = new Error("Container missing");',
88
90
  'if(typeof error.message === "string")',
89
91
  Template.indent(
@@ -94,15 +96,15 @@ class RemoteRuntimeModule extends RuntimeModule {
94
96
  }[id] = ${runtimeTemplate.basicFunction("", ["throw error;"])}`,
95
97
  "data.p = 0;"
96
98
  ])};`,
97
- `var handleFunction = ${runtimeTemplate.basicFunction(
99
+ `${cst} handleFunction = ${runtimeTemplate.basicFunction(
98
100
  "fn, arg1, arg2, d, next, first",
99
101
  [
100
102
  "try {",
101
103
  Template.indent([
102
- "var promise = fn(arg1, arg2);",
103
- "if(promise && promise.then) {",
104
+ `${cst} promise = fn(arg1, arg2);`,
105
+ `if(${runtimeTemplate.optionalChaining("promise", "then")}) {`,
104
106
  Template.indent([
105
- `var p = promise.then(${runtimeTemplate.returningFunction(
107
+ `${cst} p = promise.then(${runtimeTemplate.returningFunction(
106
108
  "next(result, d)",
107
109
  "result"
108
110
  )}, onError);`,
@@ -117,15 +119,15 @@ class RemoteRuntimeModule extends RuntimeModule {
117
119
  "}"
118
120
  ]
119
121
  )}`,
120
- `var onExternal = ${runtimeTemplate.returningFunction(
122
+ `${cst} onExternal = ${runtimeTemplate.returningFunction(
121
123
  `external ? handleFunction(${RuntimeGlobals.initializeSharing}, data[0], 0, external, onInitialized, first) : onError()`,
122
124
  "external, _, first"
123
125
  )};`,
124
- `var onInitialized = ${runtimeTemplate.returningFunction(
126
+ `${cst} onInitialized = ${runtimeTemplate.returningFunction(
125
127
  "handleFunction(external.get, data[1], getScope, 0, onFactory, first)",
126
128
  "_, external, first"
127
129
  )};`,
128
- `var onFactory = ${runtimeTemplate.basicFunction("factory", [
130
+ `${cst} onFactory = ${runtimeTemplate.basicFunction("factory", [
129
131
  "data.p = 1;",
130
132
  `${
131
133
  RuntimeGlobals.moduleFactories