webpack 5.107.2 → 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 (357) 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 +25 -11
  10. package/lib/ConcatenationScope.js +10 -3
  11. package/lib/ContextExclusionPlugin.js +1 -0
  12. package/lib/ContextModule.js +92 -47
  13. package/lib/ContextReplacementPlugin.js +4 -0
  14. package/lib/DefinePlugin.js +89 -15
  15. package/lib/Dependency.js +111 -7
  16. package/lib/EntryOptionPlugin.js +39 -2
  17. package/lib/EntryPlugin.js +2 -0
  18. package/lib/ExportsInfo.js +314 -73
  19. package/lib/ExternalModule.js +82 -34
  20. package/lib/ExternalModuleFactoryPlugin.js +1 -0
  21. package/lib/ExternalsPlugin.js +1 -0
  22. package/lib/FileSystemInfo.js +173 -23
  23. package/lib/FlagAllModulesAsUsedPlugin.js +1 -5
  24. package/lib/FlagDependencyExportsPlugin.js +23 -0
  25. package/lib/FlagDependencyUsagePlugin.js +87 -5
  26. package/lib/FlagEntryExportAsUsedPlugin.js +2 -0
  27. package/lib/Generator.js +8 -0
  28. package/lib/HotModuleReplacementPlugin.js +65 -28
  29. package/lib/IgnorePlugin.js +1 -0
  30. package/lib/InitFragment.js +5 -0
  31. package/lib/JavascriptMetaInfoPlugin.js +7 -5
  32. package/lib/LazyBarrel.js +361 -0
  33. package/lib/LoaderTargetPlugin.js +1 -0
  34. package/lib/Module.js +21 -42
  35. package/lib/ModuleGraph.js +3 -2
  36. package/lib/ModuleProfile.js +27 -1
  37. package/lib/ModuleTemplate.js +2 -0
  38. package/lib/MultiCompiler.js +2 -0
  39. package/lib/MultiStats.js +1 -0
  40. package/lib/MultiWatching.js +2 -0
  41. package/lib/NodeStuffPlugin.js +22 -17
  42. package/lib/NormalModule.js +142 -80
  43. package/lib/NormalModuleReplacementPlugin.js +2 -0
  44. package/lib/PrefetchPlugin.js +2 -0
  45. package/lib/ProgressPlugin.js +8 -0
  46. package/lib/ProvidePlugin.js +1 -0
  47. package/lib/RawModule.js +20 -16
  48. package/lib/RecordIdsPlugin.js +1 -0
  49. package/lib/RuntimeGlobals.js +5 -0
  50. package/lib/RuntimePlugin.js +58 -26
  51. package/lib/RuntimeTemplate.js +278 -21
  52. package/lib/SelfModuleFactory.js +1 -0
  53. package/lib/SourceMapDevToolPlugin.js +3 -5
  54. package/lib/Stats.js +1 -0
  55. package/lib/Template.js +8 -2
  56. package/lib/TemplatedPathPlugin.js +473 -131
  57. package/lib/WarnCaseSensitiveModulesPlugin.js +1 -0
  58. package/lib/WarnDeprecatedOptionPlugin.js +4 -0
  59. package/lib/WarnNoModeSetPlugin.js +1 -0
  60. package/lib/WatchIgnorePlugin.js +1 -0
  61. package/lib/Watching.js +9 -0
  62. package/lib/WebpackOptionsApply.js +50 -5
  63. package/lib/asset/AssetBytesGenerator.js +11 -3
  64. package/lib/asset/AssetGenerator.js +47 -22
  65. package/lib/asset/AssetModule.js +47 -0
  66. package/lib/asset/AssetModulesPlugin.js +14 -14
  67. package/lib/asset/AssetParser.js +2 -2
  68. package/lib/asset/AssetSourceGenerator.js +8 -0
  69. package/lib/asset/RawDataUrlModule.js +12 -13
  70. package/lib/buildChunkGraph.js +64 -7
  71. package/lib/bun/BunTargetPlugin.js +48 -0
  72. package/lib/cache/AddBuildDependenciesPlugin.js +1 -0
  73. package/lib/cache/AddManagedPathsPlugin.js +3 -0
  74. package/lib/cache/IdleFileCachePlugin.js +4 -0
  75. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  76. package/lib/cache/PackFileCacheStrategy.js +1 -0
  77. package/lib/cache/ResolverCachePlugin.js +2 -0
  78. package/lib/cache/mergeEtags.js +2 -0
  79. package/lib/cli.js +109 -19
  80. package/lib/config/browserslistTargetHandler.js +99 -0
  81. package/lib/config/defaults.js +147 -7
  82. package/lib/config/defineConfig.js +31 -0
  83. package/lib/config/normalization.js +5 -0
  84. package/lib/config/target.js +181 -2
  85. package/lib/container/ContainerEntryModule.js +15 -14
  86. package/lib/container/ContainerExposedDependency.js +2 -2
  87. package/lib/container/ContainerReferencePlugin.js +1 -1
  88. package/lib/container/FallbackDependency.js +5 -7
  89. package/lib/container/FallbackModule.js +10 -9
  90. package/lib/container/RemoteModule.js +20 -10
  91. package/lib/container/RemoteRuntimeModule.js +14 -12
  92. package/lib/css/CssGenerator.js +353 -327
  93. package/lib/css/CssInjectStyleRuntimeModule.js +36 -8
  94. package/lib/css/CssLoadingRuntimeModule.js +118 -47
  95. package/lib/css/CssModule.js +52 -23
  96. package/lib/css/CssModulesPlugin.js +107 -124
  97. package/lib/css/CssParser.js +2759 -2205
  98. package/lib/css/syntax.js +2859 -0
  99. package/lib/debug/ProfilingPlugin.js +2 -0
  100. package/lib/deno/DenoTargetPlugin.js +47 -0
  101. package/lib/dependencies/AMDDefineDependency.js +22 -17
  102. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +1 -0
  103. package/lib/dependencies/AMDRequireArrayDependency.js +7 -11
  104. package/lib/dependencies/AMDRequireContextDependency.js +7 -11
  105. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +1 -0
  106. package/lib/dependencies/AMDRequireDependency.js +24 -20
  107. package/lib/dependencies/CachedConstDependency.js +3 -0
  108. package/lib/dependencies/CommonJsDependencyHelpers.js +1 -0
  109. package/lib/dependencies/CommonJsExportRequireDependency.js +79 -31
  110. package/lib/dependencies/CommonJsExportsDependency.js +21 -16
  111. package/lib/dependencies/CommonJsExportsParserPlugin.js +230 -7
  112. package/lib/dependencies/CommonJsFullRequireDependency.js +27 -19
  113. package/lib/dependencies/CommonJsImportsParserPlugin.js +51 -16
  114. package/lib/dependencies/CommonJsPlugin.js +1 -1
  115. package/lib/dependencies/CommonJsRequireContextDependency.js +10 -13
  116. package/lib/dependencies/CommonJsRequireDependency.js +42 -11
  117. package/lib/dependencies/CommonJsSelfReferenceDependency.js +22 -14
  118. package/lib/dependencies/ConstDependency.js +16 -11
  119. package/lib/dependencies/ContextDependency.js +4 -0
  120. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -1
  121. package/lib/dependencies/ContextElementDependency.js +23 -14
  122. package/lib/dependencies/CreateRequireParserPlugin.js +1 -0
  123. package/lib/dependencies/CreateScriptUrlDependency.js +5 -7
  124. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  125. package/lib/dependencies/CssIcssExportDependency.js +512 -574
  126. package/lib/dependencies/CssIcssImportDependency.js +9 -9
  127. package/lib/dependencies/CssIcssSymbolDependency.js +22 -15
  128. package/lib/dependencies/CssImportDependency.js +25 -1
  129. package/lib/dependencies/CssUrlDependency.js +23 -14
  130. package/lib/dependencies/DllEntryDependency.js +9 -13
  131. package/lib/dependencies/ExportBindingInitFragment.js +164 -0
  132. package/lib/dependencies/ExportsInfoDependency.js +12 -12
  133. package/lib/dependencies/ExternalModuleDependency.js +8 -5
  134. package/lib/dependencies/ExternalModuleInitFragment.js +7 -5
  135. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +13 -10
  136. package/lib/dependencies/HarmonyAcceptDependency.js +11 -11
  137. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -0
  138. package/lib/dependencies/HarmonyDetectionParserPlugin.js +47 -22
  139. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +28 -2
  140. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +46 -22
  141. package/lib/dependencies/HarmonyExportExpressionDependency.js +107 -30
  142. package/lib/dependencies/HarmonyExportHeaderDependency.js +7 -9
  143. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +109 -31
  144. package/lib/dependencies/HarmonyExportInitFragment.js +18 -15
  145. package/lib/dependencies/HarmonyExportSpecifierDependency.js +83 -18
  146. package/lib/dependencies/HarmonyExports.js +4 -1
  147. package/lib/dependencies/HarmonyImportDependency.js +24 -0
  148. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +110 -74
  149. package/lib/dependencies/HarmonyImportGuard.js +254 -0
  150. package/lib/dependencies/HarmonyImportSideEffectDependency.js +18 -1
  151. package/lib/dependencies/HarmonyImportSpecifierDependency.js +118 -14
  152. package/lib/dependencies/HarmonyLinkingError.js +1 -0
  153. package/lib/dependencies/HarmonyModulesPlugin.js +1 -0
  154. package/lib/dependencies/{HtmlScriptSrcDependency.js → HtmlEntryDependency.js} +261 -109
  155. package/lib/dependencies/HtmlInlineHtmlDependency.js +107 -0
  156. package/lib/dependencies/HtmlInlineScriptDependency.js +17 -13
  157. package/lib/dependencies/HtmlInlineStyleDependency.js +45 -11
  158. package/lib/dependencies/ImportContextDependency.js +5 -9
  159. package/lib/dependencies/ImportDependency.js +44 -2
  160. package/lib/dependencies/ImportMetaHotAcceptDependency.js +1 -0
  161. package/lib/dependencies/ImportMetaHotDeclineDependency.js +1 -0
  162. package/lib/dependencies/ImportMetaPlugin.js +74 -30
  163. package/lib/dependencies/ImportParserPlugin.js +19 -0
  164. package/lib/dependencies/ImportWeakDependency.js +1 -0
  165. package/lib/dependencies/JsonExportsDependency.js +9 -9
  166. package/lib/dependencies/LoaderImportDependency.js +1 -0
  167. package/lib/dependencies/LocalModule.js +11 -12
  168. package/lib/dependencies/LocalModuleDependency.js +11 -13
  169. package/lib/dependencies/ModuleDecoratorDependency.js +9 -9
  170. package/lib/dependencies/ModuleDependency.js +7 -0
  171. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -0
  172. package/lib/dependencies/ModuleHotDeclineDependency.js +1 -0
  173. package/lib/dependencies/ModuleInitFragmentDependency.js +15 -11
  174. package/lib/dependencies/ProvidedDependency.js +31 -27
  175. package/lib/dependencies/PureExpressionDependency.js +7 -9
  176. package/lib/dependencies/RequireEnsureDependency.js +12 -13
  177. package/lib/dependencies/RequireHeaderDependency.js +3 -4
  178. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -0
  179. package/lib/dependencies/RequireResolveContextDependency.js +7 -11
  180. package/lib/dependencies/RequireResolveDependency.js +1 -0
  181. package/lib/dependencies/RequireResolveHeaderDependency.js +3 -5
  182. package/lib/dependencies/RuntimeRequirementsDependency.js +6 -7
  183. package/lib/dependencies/StaticExportsDependency.js +10 -10
  184. package/lib/dependencies/SystemPlugin.js +2 -0
  185. package/lib/dependencies/URLContextDependency.js +5 -7
  186. package/lib/dependencies/URLDependency.js +14 -16
  187. package/lib/dependencies/UnsupportedDependency.js +8 -13
  188. package/lib/dependencies/WebAssemblyExportImportedDependency.js +11 -16
  189. package/lib/dependencies/WebAssemblyImportDependency.js +14 -16
  190. package/lib/dependencies/WebpackIsIncludedDependency.js +1 -0
  191. package/lib/dependencies/WorkerDependency.js +19 -8
  192. package/lib/dependencies/WorkerPlugin.js +22 -6
  193. package/lib/dependencies/processExportInfo.js +13 -11
  194. package/lib/dll/DelegatedModule.js +29 -15
  195. package/lib/dll/DelegatedModuleFactoryPlugin.js +1 -0
  196. package/lib/dll/DelegatedPlugin.js +1 -0
  197. package/lib/dll/DllEntryPlugin.js +3 -0
  198. package/lib/dll/DllModule.js +3 -2
  199. package/lib/dll/DllPlugin.js +16 -0
  200. package/lib/dll/DllReferencePlugin.js +3 -0
  201. package/lib/dll/LibManifestPlugin.js +1 -0
  202. package/lib/electron/ElectronTargetPlugin.js +22 -4
  203. package/lib/errors/ConcurrentCompilationError.js +1 -0
  204. package/lib/errors/HookWebpackError.js +11 -13
  205. package/lib/errors/IgnoreErrorModuleFactory.js +1 -0
  206. package/lib/errors/InvalidDependenciesModuleWarning.js +2 -0
  207. package/lib/errors/JSONParseError.js +9 -8
  208. package/lib/errors/ModuleBuildError.js +16 -13
  209. package/lib/errors/ModuleDependencyError.js +8 -1
  210. package/lib/errors/ModuleDependencyWarning.js +8 -1
  211. package/lib/errors/ModuleError.js +5 -11
  212. package/lib/errors/ModuleHashingError.js +4 -0
  213. package/lib/errors/ModuleNotFoundError.js +3 -0
  214. package/lib/errors/ModuleParseError.js +5 -11
  215. package/lib/errors/ModuleRestoreError.js +2 -0
  216. package/lib/errors/ModuleStoreError.js +3 -0
  217. package/lib/errors/ModuleWarning.js +7 -11
  218. package/lib/errors/NodeStuffInWebError.js +1 -0
  219. package/lib/errors/NonErrorEmittedError.js +2 -0
  220. package/lib/errors/UnhandledSchemeError.js +1 -0
  221. package/lib/esm/ModuleChunkLoadingPlugin.js +0 -1
  222. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +28 -23
  223. package/lib/hmr/HotModuleReplacement.runtime.js +175 -30
  224. package/lib/hmr/HotModuleReplacementRuntimeModule.js +7 -0
  225. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +173 -26
  226. package/lib/hmr/LazyCompilationPlugin.js +30 -6
  227. package/lib/html/HtmlGenerator.js +217 -23
  228. package/lib/html/HtmlModule.js +40 -0
  229. package/lib/html/HtmlModulesPlugin.js +219 -55
  230. package/lib/html/HtmlParser.js +1108 -1099
  231. package/lib/html/{walkHtmlTokens.js → syntax.js} +4701 -212
  232. package/lib/ids/IdHelpers.js +4 -2
  233. package/lib/index.js +19 -0
  234. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  235. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -0
  236. package/lib/javascript/JavascriptGenerator.js +6 -2
  237. package/lib/javascript/JavascriptModule.js +54 -0
  238. package/lib/javascript/JavascriptModulesPlugin.js +257 -102
  239. package/lib/javascript/JavascriptParser.js +285 -158
  240. package/lib/json/JsonModule.js +40 -0
  241. package/lib/json/JsonModulesPlugin.js +7 -0
  242. package/lib/json/JsonParser.js +4 -2
  243. package/lib/library/AssignLibraryPlugin.js +5 -3
  244. package/lib/library/ExportPropertyLibraryPlugin.js +1 -0
  245. package/lib/library/FalseIIFEUmdWarning.js +1 -0
  246. package/lib/library/ModuleLibraryPlugin.js +24 -5
  247. package/lib/library/SystemLibraryPlugin.js +3 -3
  248. package/lib/node/NodeTargetPlugin.js +1 -0
  249. package/lib/node/NodeWatchFileSystem.js +1 -0
  250. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +10 -9
  251. package/lib/node/RequireChunkLoadingRuntimeModule.js +18 -16
  252. package/lib/optimize/ConcatenatedModule.js +395 -77
  253. package/lib/optimize/ConstExportsPlugin.js +211 -0
  254. package/lib/optimize/InlineExports.js +178 -0
  255. package/lib/optimize/InnerGraph.js +372 -275
  256. package/lib/optimize/InnerGraphPlugin.js +196 -99
  257. package/lib/optimize/ModuleConcatenationPlugin.js +56 -25
  258. package/lib/optimize/RealContentHashPlugin.js +14 -1
  259. package/lib/optimize/SideEffectsFlagPlugin.js +234 -64
  260. package/lib/runtime/AsyncModuleRuntimeModule.js +32 -30
  261. package/lib/runtime/AutoPublicPathRuntimeModule.js +11 -5
  262. package/lib/runtime/CompatGetDefaultExportRuntimeModule.js +1 -1
  263. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +6 -4
  264. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +33 -4
  265. package/lib/runtime/GetChunkFilenameRuntimeModule.js +82 -3
  266. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  267. package/lib/runtime/HasOwnPropertyRuntimeModule.js +1 -1
  268. package/lib/runtime/LoadScriptRuntimeModule.js +18 -13
  269. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +39 -26
  270. package/lib/runtime/MakeNamespaceObjectRuntimeModule.js +1 -1
  271. package/lib/runtime/OnChunksLoadedRuntimeModule.js +4 -4
  272. package/lib/runtime/RelativeUrlRuntimeModule.js +3 -2
  273. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -1
  274. package/lib/runtime/StartupEntrypointRuntimeModule.js +4 -3
  275. package/lib/runtime/WorkerRuntimeModule.js +33 -0
  276. package/lib/schemes/HttpUriPlugin.js +3 -2
  277. package/lib/serialization/AggregateErrorSerializer.js +7 -6
  278. package/lib/serialization/ArraySerializer.js +4 -8
  279. package/lib/serialization/BinaryMiddleware.js +538 -468
  280. package/lib/serialization/DateObjectSerializer.js +2 -2
  281. package/lib/serialization/ErrorObjectSerializer.js +7 -6
  282. package/lib/serialization/MapObjectSerializer.js +5 -9
  283. package/lib/serialization/NullPrototypeObjectSerializer.js +7 -9
  284. package/lib/serialization/ObjectMiddleware.js +50 -13
  285. package/lib/serialization/PlainObjectSerializer.js +9 -8
  286. package/lib/serialization/RegExpObjectSerializer.js +2 -2
  287. package/lib/serialization/Serializer.js +1 -0
  288. package/lib/serialization/SetObjectSerializer.js +4 -8
  289. package/lib/sharing/ConsumeSharedModule.js +6 -7
  290. package/lib/sharing/ConsumeSharedPlugin.js +1 -0
  291. package/lib/sharing/ConsumeSharedRuntimeModule.js +46 -41
  292. package/lib/sharing/ProvideSharedDependency.js +30 -15
  293. package/lib/sharing/ProvideSharedModule.js +30 -11
  294. package/lib/sharing/ProvideSharedPlugin.js +4 -2
  295. package/lib/sharing/SharePlugin.js +3 -0
  296. package/lib/sharing/ShareRuntimeModule.js +18 -16
  297. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  298. package/lib/sharing/utils.js +1 -1
  299. package/lib/stats/DefaultStatsFactoryPlugin.js +4 -6
  300. package/lib/stats/DefaultStatsPrinterPlugin.js +14 -14
  301. package/lib/stats/StatsFactory.js +11 -9
  302. package/lib/stats/StatsPrinter.js +9 -2
  303. package/lib/url/URLParserPlugin.js +5 -2
  304. package/lib/util/AsyncQueue.js +10 -0
  305. package/lib/util/LazyBucketSortedSet.js +5 -0
  306. package/lib/util/LazySet.js +6 -4
  307. package/lib/util/LocConverter.js +11 -1
  308. package/lib/util/Semaphore.js +1 -0
  309. package/lib/util/SourceProcessor.js +106 -0
  310. package/lib/util/TupleSet.js +1 -0
  311. package/lib/util/WeakTupleMap.js +27 -1
  312. package/lib/util/chainedImports.js +3 -3
  313. package/lib/util/comparators.js +2 -2
  314. package/lib/util/concatenate.js +31 -7
  315. package/lib/util/createHash.js +0 -1
  316. package/lib/util/deterministicGrouping.js +19 -12
  317. package/lib/util/extractSourceMap.js +1 -1
  318. package/lib/util/findGraphRoots.js +2 -0
  319. package/lib/util/fs.js +10 -5
  320. package/lib/util/hash/DebugHash.js +1 -0
  321. package/lib/util/hash/hash-digest.js +24 -15
  322. package/lib/util/identifier.js +7 -0
  323. package/lib/util/internalSerializables.js +11 -2
  324. package/lib/util/magicComment.js +42 -0
  325. package/lib/util/makeSerializable.js +1 -0
  326. package/lib/util/nonNumericOnlyHash.js +30 -1
  327. package/lib/util/property.js +7 -1
  328. package/lib/util/publicPathPlaceholder.js +64 -0
  329. package/lib/util/registerExternalSerializer.js +4 -4
  330. package/lib/wasm-async/AsyncWasmModule.js +77 -0
  331. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
  332. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -96
  333. package/lib/wasm-async/AsyncWebAssemblyParser.js +1 -1
  334. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +1 -1
  335. package/lib/wasm-sync/SyncWasmModule.js +39 -0
  336. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +1 -0
  337. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +6 -3
  338. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -1
  339. package/lib/wasm-sync/WebAssemblyGenerator.js +1 -0
  340. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  341. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +10 -0
  342. package/lib/wasm-sync/WebAssemblyParser.js +7 -3
  343. package/lib/web/JsonpChunkLoadingRuntimeModule.js +45 -39
  344. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +11 -10
  345. package/package.json +35 -27
  346. package/schemas/WebpackOptions.check.js +1 -1
  347. package/schemas/WebpackOptions.json +212 -3
  348. package/schemas/plugins/HtmlGeneratorOptions.check.js +1 -1
  349. package/schemas/plugins/HtmlParserOptions.check.d.ts +7 -0
  350. package/schemas/plugins/HtmlParserOptions.check.js +6 -0
  351. package/schemas/plugins/HtmlParserOptions.json +3 -0
  352. package/schemas/plugins/css/CssAutoOrModuleParserOptions.check.js +1 -1
  353. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  354. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  355. package/types.d.ts +1456 -290
  356. package/lib/css/walkCssTokens.js +0 -2020
  357. package/lib/util/AppendOnlyStackedSet.js +0 -93
@@ -81,7 +81,7 @@ const getName = (a, b, usedNames) => {
81
81
  * @returns {void}
82
82
  */
83
83
  const addSizeTo = (total, size) => {
84
- for (const key of Object.keys(size)) {
84
+ for (const key in size) {
85
85
  total[key] = (total[key] || 0) + size[key];
86
86
  }
87
87
  };
@@ -93,7 +93,7 @@ const addSizeTo = (total, size) => {
93
93
  * @returns {void}
94
94
  */
95
95
  const subtractSizeFrom = (total, size) => {
96
- for (const key of Object.keys(size)) {
96
+ for (const key in size) {
97
97
  total[key] -= size[key];
98
98
  }
99
99
  };
@@ -101,14 +101,15 @@ const subtractSizeFrom = (total, size) => {
101
101
  /**
102
102
  * Returns total size.
103
103
  * @template T
104
- * @param {Iterable<Node<T>>} nodes some nodes
104
+ * @param {Node<T>[]} nodes some nodes
105
+ * @param {number=} start start index
105
106
  * @returns {Sizes} total size
106
107
  */
107
- const sumSize = (nodes) => {
108
+ const sumSize = (nodes, start) => {
108
109
  /** @type {Sizes} */
109
110
  const sum = Object.create(null);
110
- for (const node of nodes) {
111
- addSizeTo(sum, node.size);
111
+ for (let i = start || 0; i < nodes.length; i++) {
112
+ addSizeTo(sum, nodes[i].size);
112
113
  }
113
114
  return sum;
114
115
  };
@@ -120,7 +121,7 @@ const sumSize = (nodes) => {
120
121
  * @returns {boolean} true, when size is too big
121
122
  */
122
123
  const isTooBig = (size, maxSize) => {
123
- for (const key of Object.keys(size)) {
124
+ for (const key in size) {
124
125
  const s = size[key];
125
126
  if (s === 0) continue;
126
127
  const maxSizeValue = maxSize[key];
@@ -136,7 +137,7 @@ const isTooBig = (size, maxSize) => {
136
137
  * @returns {boolean} true, when size is too small
137
138
  */
138
139
  const isTooSmall = (size, minSize) => {
139
- for (const key of Object.keys(size)) {
140
+ for (const key in size) {
140
141
  const s = size[key];
141
142
  if (s === 0) continue;
142
143
  const minSizeValue = minSize[key];
@@ -156,7 +157,7 @@ const isTooSmall = (size, minSize) => {
156
157
  const getTooSmallTypes = (size, minSize) => {
157
158
  /** @type {Types} */
158
159
  const types = new Set();
159
- for (const key of Object.keys(size)) {
160
+ for (const key in size) {
160
161
  const s = size[key];
161
162
  if (s === 0) continue;
162
163
  const minSizeValue = minSize[key];
@@ -174,7 +175,7 @@ const getTooSmallTypes = (size, minSize) => {
174
175
  */
175
176
  const getNumberOfMatchingSizeTypes = (size, types) => {
176
177
  let i = 0;
177
- for (const key of Object.keys(size)) {
178
+ for (const key in size) {
178
179
  if (size[/** @type {keyof T} */ (key)] !== 0 && types.has(key)) i++;
179
180
  }
180
181
  return i;
@@ -188,7 +189,7 @@ const getNumberOfMatchingSizeTypes = (size, types) => {
188
189
  */
189
190
  const selectiveSizeSum = (size, types) => {
190
191
  let sum = 0;
191
- for (const key of Object.keys(size)) {
192
+ for (const key in size) {
192
193
  if (size[key] !== 0 && types.has(key)) sum += size[key];
193
194
  }
194
195
  return sum;
@@ -206,8 +207,11 @@ class Node {
206
207
  * @param {Sizes} size size
207
208
  */
208
209
  constructor(item, key, size) {
210
+ /** @type {T} */
209
211
  this.item = item;
212
+ /** @type {string} */
210
213
  this.key = key;
214
+ /** @type {Sizes} */
211
215
  this.size = size;
212
216
  }
213
217
  }
@@ -226,8 +230,11 @@ class Group {
226
230
  * @param {Sizes=} size size of the group
227
231
  */
228
232
  constructor(nodes, similarities, size) {
233
+ /** @type {Node<T>[]} */
229
234
  this.nodes = nodes;
235
+ /** @type {Similarities | null} */
230
236
  this.similarities = similarities;
237
+ /** @type {Sizes} */
231
238
  this.size = size || sumSize(nodes);
232
239
  /** @type {string | undefined} */
233
240
  this.key = undefined;
@@ -483,7 +490,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
483
490
  let best = -1;
484
491
  let bestSimilarity = Infinity;
485
492
  let pos = left;
486
- const rightSize = sumSize(group.nodes.slice(pos));
493
+ const rightSize = sumSize(group.nodes, pos);
487
494
 
488
495
  // pos v v right
489
496
  // [ O O O ] O O O [ O O O ]
@@ -92,7 +92,7 @@ function getAbsolutePath(context, request, sourceRoot) {
92
92
  * @returns {boolean} true if value is a URL
93
93
  */
94
94
  function isURL(value) {
95
- return validProtocolPattern.test(value) && !path.win32.isAbsolute(value);
95
+ return validProtocolPattern.test(value) && !isAbsolute(value);
96
96
  }
97
97
 
98
98
  /**
@@ -26,6 +26,7 @@ class Node {
26
26
  * @param {T} item the value of the node
27
27
  */
28
28
  constructor(item) {
29
+ /** @type {T} */
29
30
  this.item = item;
30
31
  /** @type {Nodes<T>} */
31
32
  this.dependencies = new Set();
@@ -46,6 +47,7 @@ class SCC {
46
47
  constructor() {
47
48
  /** @type {Nodes<T>} */
48
49
  this.nodes = new Set();
50
+ /** @type {number} */
49
51
  this.marker = NO_MARKER;
50
52
  }
51
53
  }
package/lib/util/fs.js CHANGED
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const path = require("path");
9
+ const { ABSOLUTE_PATH_REGEXP } = require("./identifier");
9
10
 
10
11
  /** @typedef {import("../../declarations/WebpackOptions").WatchOptions} WatchOptions */
11
12
  /** @typedef {import("watchpack").Entry} Entry */
@@ -610,7 +611,9 @@ const mkdirp = (fs, p, callback) => {
610
611
  }
611
612
  fs.mkdir(p, (err) => {
612
613
  if (err) {
613
- if (err.code === "EEXIST") {
614
+ // EEXIST: parent already created it; EISDIR: memfs/BSD for an
615
+ // existing dir such as the root "/" (#10544)
616
+ if (err.code === "EEXIST" || err.code === "EISDIR") {
614
617
  callback();
615
618
  return;
616
619
  }
@@ -621,7 +624,7 @@ const mkdirp = (fs, p, callback) => {
621
624
  });
622
625
  });
623
626
  return;
624
- } else if (err.code === "EEXIST") {
627
+ } else if (err.code === "EEXIST" || err.code === "EISDIR") {
625
628
  callback();
626
629
  return;
627
630
  }
@@ -651,7 +654,10 @@ const mkdirpSync = (fs, p) => {
651
654
  mkdirpSync(fs, dir);
652
655
  fs.mkdirSync(p);
653
656
  return;
654
- } else if (/** @type {NodeJS.ErrnoException} */ (err).code === "EEXIST") {
657
+ } else if (
658
+ /** @type {NodeJS.ErrnoException} */ (err).code === "EEXIST" ||
659
+ /** @type {NodeJS.ErrnoException} */ (err).code === "EISDIR"
660
+ ) {
655
661
  return;
656
662
  }
657
663
  throw err;
@@ -730,8 +736,7 @@ const lstatReadlinkAbsolute = (fs, p, callback) => {
730
736
  * @param {string} pathname a path
731
737
  * @returns {boolean} is absolute
732
738
  */
733
- const isAbsolute = (pathname) =>
734
- path.posix.isAbsolute(pathname) || path.win32.isAbsolute(pathname);
739
+ const isAbsolute = (pathname) => ABSOLUTE_PATH_REGEXP.test(pathname);
735
740
 
736
741
  module.exports.dirname = dirname;
737
742
  module.exports.isAbsolute = isAbsolute;
@@ -13,6 +13,7 @@ const Hash = require("../Hash");
13
13
  class DebugHash extends Hash {
14
14
  constructor() {
15
15
  super();
16
+ /** @type {string} */
16
17
  this.string = "";
17
18
  }
18
19
 
@@ -42,7 +42,13 @@ const FF = BigInt("0xff");
42
42
  */
43
43
  const encode = (buffer, base) => {
44
44
  if (buffer.length === 0) return "";
45
- const bigIntBase = BigInt(ENCODE_TABLE[base].length);
45
+ const alphabet = ENCODE_TABLE[base];
46
+ const bigIntBase = BigInt(alphabet.length);
47
+ // Leading zero bytes are not significant in the BigInt below, so they would be
48
+ // lost; Base58Check-style, re-emit each as one leading alphabet[0] char. Keeps
49
+ // the encoding reversible and its length tracking the input (prefix-stable slices).
50
+ let zeros = 0;
51
+ while (zeros < buffer.length && buffer[zeros] === 0) zeros++;
46
52
  // Convert buffer to BigInt efficiently using bitwise operations
47
53
  let value = ZERO;
48
54
  for (let i = 0; i < buffer.length; i++) {
@@ -51,12 +57,13 @@ const encode = (buffer, base) => {
51
57
  // Convert to baseX string efficiently using array
52
58
  /** @type {string[]} */
53
59
  const digits = [];
54
- if (value === ZERO) return ENCODE_TABLE[base][0];
55
60
  while (value > ZERO) {
56
61
  const remainder = Number(value % bigIntBase);
57
- digits.push(ENCODE_TABLE[base][remainder]);
62
+ digits.push(alphabet[remainder]);
58
63
  value /= bigIntBase;
59
64
  }
65
+ // Pushed last so they land first after the reverse below.
66
+ for (let i = 0; i < zeros; i++) digits.push(alphabet[0]);
60
67
  return digits.reverse().join("");
61
68
  };
62
69
 
@@ -68,30 +75,32 @@ const encode = (buffer, base) => {
68
75
  */
69
76
  const decode = (data, base) => {
70
77
  if (data.length === 0) return Buffer.from("");
71
- const bigIntBase = BigInt(ENCODE_TABLE[base].length);
78
+ const alphabet = ENCODE_TABLE[base];
79
+ const bigIntBase = BigInt(alphabet.length);
80
+ // Leading alphabet[0] chars decode back to leading zero bytes (inverse of encode).
81
+ const zeroChar = alphabet[0];
82
+ let zeros = 0;
83
+ while (zeros < data.length && data[zeros] === zeroChar) zeros++;
72
84
  // Convert the baseX string to a BigInt value
73
85
  let value = ZERO;
74
86
  for (let i = 0; i < data.length; i++) {
75
- const digit = ENCODE_TABLE[base].indexOf(data[i]);
87
+ const digit = alphabet.indexOf(data[i]);
76
88
  if (digit === -1) {
77
89
  throw new Error(`Invalid character at position ${i}: ${data[i]}`);
78
90
  }
79
91
  value = value * bigIntBase + BigInt(digit);
80
92
  }
81
- // If value is 0, return a single-byte buffer with value 0
82
- if (value === ZERO) {
83
- return Buffer.alloc(1);
84
- }
85
- // Determine buffer size efficiently by counting bytes
93
+ // Significant byte count of the numeric part (excludes the leading zeros above)
86
94
  let temp = value;
87
- let byteLength = 0;
95
+ let numLength = 0;
88
96
  while (temp > ZERO) {
89
97
  temp >>= EIGHT;
90
- byteLength++;
98
+ numLength++;
91
99
  }
92
- // Create buffer and fill it from right to left
93
- const buffer = Buffer.alloc(byteLength);
94
- for (let i = byteLength - 1; i >= 0; i--) {
100
+ // Create buffer and fill the numeric part from right to left, leaving the
101
+ // leading `zeros` bytes as 0.
102
+ const buffer = Buffer.alloc(zeros + numLength);
103
+ for (let i = zeros + numLength - 1; i >= zeros; i--) {
95
104
  buffer[i] = Number(value & FF);
96
105
  value >>= EIGHT;
97
106
  }
@@ -6,6 +6,11 @@
6
6
 
7
7
  const path = require("path");
8
8
 
9
+ // Any absolute path: POSIX (/foo) and every Windows form — drive-letter (C:\,
10
+ // C:/), UNC (\\, //), rooted (\, /); equals posix||win32 isAbsolute.
11
+ const ABSOLUTE_PATH_REGEXP = /^(?:[a-z]:)?[\\/]/i;
12
+ // Windows drive-letter absolute path only (C:\ or C:/), where a leading "/" is
13
+ // NOT absolute — used where POSIX paths must stay relative to a base.
9
14
  const WINDOWS_ABS_PATH_REGEXP = /^[a-z]:[\\/]/i;
10
15
  const SEGMENTS_SPLIT_REGEXP = /([|!])/;
11
16
  const WINDOWS_PATH_SEPARATOR_REGEXP = /\\/g;
@@ -525,6 +530,8 @@ const escapeHashInPathRequest = (request) => {
525
530
  return pathPart.replace(HASH_REGEXP, "\0#") + request.slice(lastSep);
526
531
  };
527
532
 
533
+ module.exports.ABSOLUTE_PATH_REGEXP = ABSOLUTE_PATH_REGEXP;
534
+ module.exports.WINDOWS_ABS_PATH_REGEXP = WINDOWS_ABS_PATH_REGEXP;
528
535
  module.exports.absolutify = absolutify;
529
536
  module.exports.contextify = contextify;
530
537
  module.exports.escapeHashInPathRequest = escapeHashInPathRequest;
@@ -13,6 +13,7 @@
13
13
  module.exports = {
14
14
  AsyncDependenciesBlock: () => require("../AsyncDependenciesBlock"),
15
15
  ContextModule: () => require("../ContextModule"),
16
+ "asset/AssetModule": () => require("../asset/AssetModule"),
16
17
  "cache/PackFileCacheStrategy": () =>
17
18
  require("../cache/PackFileCacheStrategy"),
18
19
  "cache/ResolverCachePlugin": () => require("../cache/ResolverCachePlugin"),
@@ -108,12 +109,14 @@ module.exports = {
108
109
  require("../dependencies/HarmonyImportSpecifierDependency"),
109
110
  "dependencies/HarmonyEvaluatedImportSpecifierDependency": () =>
110
111
  require("../dependencies/HarmonyEvaluatedImportSpecifierDependency"),
112
+ "dependencies/HtmlInlineHtmlDependency": () =>
113
+ require("../dependencies/HtmlInlineHtmlDependency"),
111
114
  "dependencies/HtmlInlineScriptDependency": () =>
112
115
  require("../dependencies/HtmlInlineScriptDependency"),
113
116
  "dependencies/HtmlInlineStyleDependency": () =>
114
117
  require("../dependencies/HtmlInlineStyleDependency"),
115
- "dependencies/HtmlScriptSrcDependency": () =>
116
- require("../dependencies/HtmlScriptSrcDependency"),
118
+ "dependencies/HtmlEntryDependency": () =>
119
+ require("../dependencies/HtmlEntryDependency"),
117
120
  "dependencies/HtmlSourceDependency": () =>
118
121
  require("../dependencies/HtmlSourceDependency"),
119
122
  "dependencies/ImportContextDependency": () =>
@@ -183,9 +186,15 @@ module.exports = {
183
186
  require("../dependencies/WebpackIsIncludedDependency"),
184
187
  "dependencies/WorkerDependency": () =>
185
188
  require("../dependencies/WorkerDependency"),
189
+ "html/HtmlModule": () => require("../html/HtmlModule"),
190
+ "javascript/JavascriptModule": () =>
191
+ require("../javascript/JavascriptModule"),
186
192
  "json/JsonData": () => require("../json/JsonData"),
193
+ "json/JsonModule": () => require("../json/JsonModule"),
187
194
  "optimize/ConcatenatedModule": () =>
188
195
  require("../optimize/ConcatenatedModule"),
196
+ "wasm-async/AsyncWasmModule": () => require("../wasm-async/AsyncWasmModule"),
197
+ "wasm-sync/SyncWasmModule": () => require("../wasm-sync/SyncWasmModule"),
189
198
 
190
199
  DependenciesBlock: () => require("../DependenciesBlock"),
191
200
  ExternalModule: () => require("../ExternalModule"),
@@ -24,6 +24,48 @@ module.exports.createMagicCommentContext = () =>
24
24
  codeGeneration: { strings: false, wasm: false }
25
25
  });
26
26
 
27
+ // Whole-comment `webpackXxx: <bool|number|null>` pair — parsed without `vm`.
28
+ const MAGIC_COMMENT_FAST_PATH =
29
+ /^\s*(webpack[A-Z][A-Za-z]+)\s*:\s*(true|false|null|-?\d+(?:\.\d+)?)\s*$/;
30
+
31
+ /**
32
+ * Parse one magic comment's text into its options object. Values are detached
33
+ * from the vm context (RegExps recreated, other objects JSON-cloned). Throws
34
+ * when the comment body fails to evaluate.
35
+ * @param {string} value comment text (should already match `webpackCommentRegExp`)
36
+ * @param {import("vm").Context} context context from `createMagicCommentContext`
37
+ * @returns {Record<string, EXPECTED_ANY>} parsed options
38
+ */
39
+ module.exports.parseMagicComment = (value, context) => {
40
+ const fast = MAGIC_COMMENT_FAST_PATH.exec(value);
41
+ if (fast !== null) {
42
+ const raw = fast[2];
43
+ return {
44
+ [fast[1]]:
45
+ raw === "true"
46
+ ? true
47
+ : raw === "false"
48
+ ? false
49
+ : raw === "null"
50
+ ? null
51
+ : Number(raw)
52
+ };
53
+ }
54
+ /** @type {Record<string, EXPECTED_ANY>} */
55
+ const options = {};
56
+ for (let [key, val] of Object.entries(
57
+ getVm().runInContext(`(function(){return {${value}};})()`, context)
58
+ )) {
59
+ if (typeof val === "object" && val !== null) {
60
+ val =
61
+ val.constructor.name === "RegExp"
62
+ ? new RegExp(val)
63
+ : JSON.parse(JSON.stringify(val));
64
+ }
65
+ options[key] = val;
66
+ }
67
+ return options;
68
+ };
27
69
  module.exports.webpackCommentRegExp = new RegExp(
28
70
  /(^|\W)webpack[A-Z][A-Za-z]+:/
29
71
  );
@@ -27,6 +27,7 @@ class ClassSerializer {
27
27
  * @param {SerializableClassConstructor<T>} Constructor constructor
28
28
  */
29
29
  constructor(Constructor) {
30
+ /** @type {SerializableClassConstructor<T>} */
30
31
  this.Constructor = Constructor;
31
32
  }
32
33
 
@@ -5,6 +5,8 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /** @typedef {import("./Hash")} Hash */
9
+
8
10
  const A_CODE = "a".charCodeAt(0);
9
11
 
10
12
  /**
@@ -13,7 +15,7 @@ const A_CODE = "a".charCodeAt(0);
13
15
  * @param {number} hashLength hash length
14
16
  * @returns {string} returns hash that has at least one non numeric char
15
17
  */
16
- module.exports = (hash, hashLength) => {
18
+ const nonNumericOnlyHash = (hash, hashLength) => {
17
19
  if (hashLength < 1) return "";
18
20
  const slice = hash.slice(0, hashLength);
19
21
  if (/[^\d]/.test(slice)) return slice;
@@ -21,3 +23,30 @@ module.exports = (hash, hashLength) => {
21
23
  A_CODE + (Number.parseInt(hash[0], 10) % 6)
22
24
  )}${slice.slice(1)}`;
23
25
  };
26
+
27
+ /**
28
+ * Digests a hash and truncates it to a content-hash string (non-numeric first char).
29
+ * @param {Hash} hash hash
30
+ * @param {string} hashDigest digest encoding
31
+ * @param {number} hashDigestLength hash length
32
+ * @returns {string} content hash string
33
+ */
34
+ const digestNonNumericOnly = (hash, hashDigest, hashDigestLength) =>
35
+ nonNumericOnlyHash(hash.digest(hashDigest), hashDigestLength);
36
+
37
+ /**
38
+ * Digests a hash, returning both the truncated content-hash string and the full
39
+ * (untruncated) digest, so `[contenthash:<digest>]` can re-encode from full entropy.
40
+ * @param {Hash} hash hash
41
+ * @param {string} hashDigest digest encoding
42
+ * @param {number} hashDigestLength hash length
43
+ * @returns {[string, string]} content hash string and full digest
44
+ */
45
+ const digestNonNumericOnlyWithFull = (hash, hashDigest, hashDigestLength) => {
46
+ const full = /** @type {string} */ (hash.digest(hashDigest));
47
+ return [nonNumericOnlyHash(full, hashDigestLength), full];
48
+ };
49
+
50
+ module.exports = nonNumericOnlyHash;
51
+ module.exports.digestNonNumericOnly = digestNonNumericOnly;
52
+ module.exports.digestNonNumericOnlyWithFull = digestNonNumericOnlyWithFull;
@@ -83,7 +83,13 @@ const propertyAccess = (properties, start = 0) => {
83
83
  let str = "";
84
84
  for (let i = start; i < properties.length; i++) {
85
85
  const p = properties[i];
86
- if (`${Number(p)}` === p) {
86
+ // Only first chars 0-9, "-", "N", "I" can begin a canonical numeric form
87
+ // (number, NaN, Infinity); skip the Number() round-trip otherwise.
88
+ const c = p.charCodeAt(0);
89
+ if (
90
+ ((c >= 48 && c <= 57) || c === 45 || c === 78 || c === 73) &&
91
+ `${Number(p)}` === p
92
+ ) {
87
93
  str += `[${p}]`;
88
94
  } else if (SAFE_IDENTIFIER.test(p) && !RESERVED_IDENTIFIER.has(p)) {
89
95
  str += `.${p}`;
@@ -0,0 +1,64 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ */
4
+
5
+ "use strict";
6
+
7
+ // Placeholders embedded into asset `url()` / HTML chunk URLs at code-generation
8
+ // time, when the final public path can't be resolved yet, then substituted
9
+ // later once the information is available:
10
+ // - PUBLIC_PATH_AUTO — stands in for `output.publicPath: "auto"`; replaced
11
+ // with the per-output-file undo path (relative `../` segments back to the
12
+ // output root) during chunk/asset render.
13
+ // - PUBLIC_PATH_FULL_HASH — stands in for `[fullhash]`/`[hash]` in a public
14
+ // path before the compilation hash exists. Form: `<prefix><len>__`, where
15
+ // `<len>` is the requested hash length (`0` means the full hash). Replaced
16
+ // with the real hash (build-time, e.g. CSS `.css` files) or a runtime
17
+ // `__webpack_require__.h()` expression (inlined CSS in JS).
18
+ const PUBLIC_PATH_AUTO = "__WEBPACK_CSS_PUBLIC_PATH_AUTO__";
19
+ const PUBLIC_PATH_FULL_HASH = "__WEBPACK_CSS_PUBLIC_PATH_FULL_HASH_";
20
+
21
+ /**
22
+ * Scan `content` for `PUBLIC_PATH_FULL_HASH` placeholders and invoke `onMatch`
23
+ * once per well-formed occurrence. The placeholder spans the half-open range
24
+ * `[start, end)` and encodes the requested hash length (`0` means the full
25
+ * hash). Callers substitute the build-time hash or a runtime expression
26
+ * depending on context.
27
+ * @param {string} content text to scan
28
+ * @param {(start: number, end: number, length: number) => void} onMatch placeholder callback
29
+ * @returns {void}
30
+ */
31
+ const walkFullHashPlaceholders = (content, onMatch) => {
32
+ const prefix = PUBLIC_PATH_FULL_HASH;
33
+ const prefixLen = prefix.length;
34
+ const len = content.length;
35
+ let idx = content.indexOf(prefix);
36
+ while (idx !== -1) {
37
+ let digitEnd = idx + prefixLen;
38
+ while (digitEnd < len) {
39
+ const cc = content.charCodeAt(digitEnd);
40
+ if (cc < 48 || cc > 57) break;
41
+ digitEnd++;
42
+ }
43
+ // Well-formed placeholder: at least one digit followed by `__`.
44
+ if (
45
+ digitEnd > idx + prefixLen &&
46
+ digitEnd + 1 < len &&
47
+ content.charCodeAt(digitEnd) === 95 &&
48
+ content.charCodeAt(digitEnd + 1) === 95
49
+ ) {
50
+ const length = Number.parseInt(
51
+ content.slice(idx + prefixLen, digitEnd),
52
+ 10
53
+ );
54
+ onMatch(idx, digitEnd + 2, length);
55
+ idx = content.indexOf(prefix, digitEnd + 2);
56
+ } else {
57
+ idx = content.indexOf(prefix, idx + prefixLen);
58
+ }
59
+ }
60
+ };
61
+
62
+ module.exports.PUBLIC_PATH_AUTO = PUBLIC_PATH_AUTO;
63
+ module.exports.PUBLIC_PATH_FULL_HASH = PUBLIC_PATH_FULL_HASH;
64
+ module.exports.walkFullHashPlaceholders = walkFullHashPlaceholders;
@@ -234,7 +234,7 @@ register(
234
234
  /**
235
235
  * Serializes this instance into the provided serializer context.
236
236
  * @param {SourceLocation} loc the location to be serialized
237
- * @param {ObjectSerializerContext} context context
237
+ * @param {import("../serialization/ObjectMiddleware").ObjectSerializerContext<number[]>} context context
238
238
  * @returns {void}
239
239
  */
240
240
  serialize(loc, { write }) {
@@ -246,7 +246,7 @@ register(
246
246
 
247
247
  /**
248
248
  * Restores this instance from the provided deserializer context.
249
- * @param {ObjectDeserializerContext} context context
249
+ * @param {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<number[]>} context context
250
250
  * @returns {RealDependencyLocation} location
251
251
  */
252
252
  deserialize({ read }) {
@@ -272,7 +272,7 @@ register(
272
272
  /**
273
273
  * Serializes this instance into the provided serializer context.
274
274
  * @param {Position} pos the position to be serialized
275
- * @param {ObjectSerializerContext} context context
275
+ * @param {import("../serialization/ObjectMiddleware").ObjectSerializerContext<number[]>} context context
276
276
  * @returns {void}
277
277
  */
278
278
  serialize(pos, { write }) {
@@ -282,7 +282,7 @@ register(
282
282
 
283
283
  /**
284
284
  * Restores this instance from the provided deserializer context.
285
- * @param {ObjectDeserializerContext} context context
285
+ * @param {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<number[]>} context context
286
286
  * @returns {SourcePosition} position
287
287
  */
288
288
  deserialize({ read }) {
@@ -0,0 +1,77 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ */
4
+
5
+ "use strict";
6
+
7
+ const NormalModule = require("../NormalModule");
8
+ const makeSerializable = require("../util/makeSerializable");
9
+
10
+ /** @typedef {import("../Module")} Module */
11
+ /** @typedef {import("../NormalModule").NormalModuleCreateData} NormalModuleCreateData */
12
+ /** @typedef {import("../dependencies/ImportPhase").ImportPhaseName} ImportPhaseName */
13
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<[ImportPhaseName | undefined]>} ObjectDeserializerContext */
14
+ /** @typedef {import("../serialization/ObjectMiddleware").ObjectSerializerContext<[ImportPhaseName | undefined]>} ObjectSerializerContext */
15
+
16
+ /**
17
+ * Module class for `webassembly/async` modules. Wasm-specific properties should live here instead of `NormalModule`.
18
+ */
19
+ class AsyncWasmModule extends NormalModule {
20
+ /**
21
+ * @param {NormalModuleCreateData & { phase: ImportPhaseName | undefined }} options options object
22
+ */
23
+ constructor(options) {
24
+ super(options);
25
+ /** @type {ImportPhaseName | undefined} */
26
+ this.phase = options.phase;
27
+ }
28
+
29
+ /**
30
+ * Returns the unique identifier used to reference this module.
31
+ * @returns {string} a unique identifier of the module
32
+ */
33
+ identifier() {
34
+ let str = super.identifier();
35
+
36
+ if (this.phase) {
37
+ str = `${str}|${this.phase}`;
38
+ }
39
+
40
+ return str;
41
+ }
42
+
43
+ /**
44
+ * Assuming this module is in the cache. Update the (cached) module with
45
+ * the fresh module from the factory. Usually updates internal references
46
+ * and properties.
47
+ * @param {Module} module fresh module
48
+ * @returns {void}
49
+ */
50
+ updateCacheModule(module) {
51
+ super.updateCacheModule(module);
52
+ const m = /** @type {AsyncWasmModule} */ (module);
53
+ this.phase = m.phase;
54
+ }
55
+
56
+ /**
57
+ * Serializes this instance into the provided serializer context.
58
+ * @param {ObjectSerializerContext} context context
59
+ */
60
+ serialize(context) {
61
+ context.write(this.phase);
62
+ super.serialize(context);
63
+ }
64
+
65
+ /**
66
+ * Restores this instance from the provided deserializer context.
67
+ * @param {ObjectDeserializerContext} context context
68
+ */
69
+ deserialize(context) {
70
+ this.phase = context.read();
71
+ super.deserialize(context.rest);
72
+ }
73
+ }
74
+
75
+ makeSerializable(AsyncWasmModule, "webpack/lib/wasm-async/AsyncWasmModule");
76
+
77
+ module.exports = AsyncWasmModule;
@@ -14,7 +14,7 @@ const Template = require("../Template");
14
14
  const WebAssemblyImportDependency = require("../dependencies/WebAssemblyImportDependency");
15
15
 
16
16
  /** @typedef {import("webpack-sources").Source} Source */
17
- /** @typedef {import("./AsyncWebAssemblyModulesPlugin").AsyncWasmModuleClass} AsyncWasmModule */
17
+ /** @typedef {import("./AsyncWasmModule")} AsyncWasmModule */
18
18
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
19
19
  /** @typedef {import("../Module")} Module */
20
20
  /** @typedef {import("../Module").SourceType} SourceType */