webpack 5.104.1 → 5.105.4

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 (333) hide show
  1. package/README.md +2 -2
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +85 -15
  4. package/lib/AbstractMethodError.js +1 -0
  5. package/lib/AsyncDependenciesBlock.js +17 -2
  6. package/lib/AsyncDependencyToInitialChunkError.js +3 -0
  7. package/lib/AutomaticPrefetchPlugin.js +1 -1
  8. package/lib/BannerPlugin.js +5 -1
  9. package/lib/CacheFacade.js +2 -2
  10. package/lib/CaseSensitiveModulesWarning.js +1 -0
  11. package/lib/Chunk.js +9 -5
  12. package/lib/ChunkGraph.js +30 -9
  13. package/lib/ChunkGroup.js +6 -3
  14. package/lib/ChunkRenderError.js +9 -2
  15. package/lib/CleanPlugin.js +5 -1
  16. package/lib/CodeGenerationError.js +7 -1
  17. package/lib/CodeGenerationResults.js +10 -3
  18. package/lib/CommentCompilationWarning.js +2 -1
  19. package/lib/Compilation.js +294 -244
  20. package/lib/Compiler.js +4 -3
  21. package/lib/ConcatenationScope.js +2 -1
  22. package/lib/ConcurrentCompilationError.js +3 -3
  23. package/lib/ContextModule.js +255 -112
  24. package/lib/ContextModuleFactory.js +14 -2
  25. package/lib/DefinePlugin.js +15 -8
  26. package/lib/DelegatedModule.js +6 -0
  27. package/lib/DelegatedModuleFactoryPlugin.js +2 -0
  28. package/lib/Dependency.js +7 -2
  29. package/lib/DependencyTemplates.js +3 -2
  30. package/lib/DllModule.js +2 -0
  31. package/lib/DllReferencePlugin.js +1 -0
  32. package/lib/DotenvPlugin.js +11 -5
  33. package/lib/DynamicEntryPlugin.js +8 -1
  34. package/lib/EnvironmentNotSupportAsyncWarning.js +2 -0
  35. package/lib/EvalDevToolModulePlugin.js +3 -0
  36. package/lib/EvalSourceMapDevToolPlugin.js +25 -14
  37. package/lib/ExportsInfo.js +8 -34
  38. package/lib/ExternalModule.js +18 -2
  39. package/lib/ExternalModuleFactoryPlugin.js +9 -2
  40. package/lib/ExternalsPlugin.js +2 -1
  41. package/lib/FalseIIFEUmdWarning.js +1 -0
  42. package/lib/FileSystemInfo.js +49 -25
  43. package/lib/FlagDependencyExportsPlugin.js +8 -1
  44. package/lib/FlagDependencyUsagePlugin.js +9 -7
  45. package/lib/HarmonyLinkingError.js +1 -0
  46. package/lib/HookWebpackError.js +2 -0
  47. package/lib/HotModuleReplacementPlugin.js +16 -2
  48. package/lib/IgnoreWarningsPlugin.js +5 -2
  49. package/lib/InitFragment.js +1 -0
  50. package/lib/InvalidDependenciesModuleWarning.js +1 -0
  51. package/lib/LibManifestPlugin.js +1 -0
  52. package/lib/ManifestPlugin.js +8 -1
  53. package/lib/Module.js +51 -8
  54. package/lib/ModuleBuildError.js +3 -1
  55. package/lib/ModuleDependencyError.js +1 -0
  56. package/lib/ModuleDependencyWarning.js +1 -0
  57. package/lib/ModuleError.js +4 -1
  58. package/lib/ModuleFilenameHelpers.js +4 -2
  59. package/lib/ModuleGraph.js +3 -0
  60. package/lib/ModuleGraphConnection.js +10 -10
  61. package/lib/ModuleHashingError.js +2 -0
  62. package/lib/ModuleInfoHeaderPlugin.js +6 -1
  63. package/lib/ModuleNotFoundError.js +1 -0
  64. package/lib/ModuleParseError.js +5 -1
  65. package/lib/ModuleProfile.js +1 -1
  66. package/lib/ModuleRestoreError.js +2 -0
  67. package/lib/ModuleSourceTypeConstants.js +1 -11
  68. package/lib/ModuleStoreError.js +2 -0
  69. package/lib/ModuleWarning.js +3 -1
  70. package/lib/MultiCompiler.js +11 -7
  71. package/lib/MultiStats.js +5 -5
  72. package/lib/MultiWatching.js +2 -2
  73. package/lib/NoModeWarning.js +1 -0
  74. package/lib/NodeStuffInWebError.js +1 -0
  75. package/lib/NormalModule.js +28 -5
  76. package/lib/NormalModuleFactory.js +20 -4
  77. package/lib/OptionsApply.js +3 -1
  78. package/lib/ProgressPlugin.js +4 -0
  79. package/lib/RawModule.js +2 -0
  80. package/lib/RuntimeModule.js +28 -1
  81. package/lib/RuntimePlugin.js +7 -9
  82. package/lib/RuntimeTemplate.js +14 -7
  83. package/lib/SourceMapDevToolModuleOptionsPlugin.js +1 -0
  84. package/lib/SourceMapDevToolPlugin.js +40 -25
  85. package/lib/Stats.js +3 -2
  86. package/lib/Template.js +10 -5
  87. package/lib/TemplatedPathPlugin.js +4 -2
  88. package/lib/UnhandledSchemeError.js +1 -0
  89. package/lib/UnsupportedFeatureWarning.js +3 -0
  90. package/lib/WarnDeprecatedOptionPlugin.js +1 -0
  91. package/lib/WatchIgnorePlugin.js +1 -1
  92. package/lib/Watching.js +5 -0
  93. package/lib/WebpackError.js +4 -0
  94. package/lib/WebpackOptionsApply.js +74 -44
  95. package/lib/asset/AssetBytesGenerator.js +1 -0
  96. package/lib/asset/AssetGenerator.js +18 -3
  97. package/lib/asset/AssetModulesPlugin.js +48 -2
  98. package/lib/asset/AssetParser.js +4 -0
  99. package/lib/asset/AssetSourceGenerator.js +1 -0
  100. package/lib/asset/RawDataUrlModule.js +9 -1
  101. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -1
  102. package/lib/buildChunkGraph.js +31 -2
  103. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  104. package/lib/cache/PackFileCacheStrategy.js +41 -8
  105. package/lib/cache/getLazyHashedEtag.js +13 -4
  106. package/lib/cache/mergeEtags.js +3 -1
  107. package/lib/cli.js +3 -1
  108. package/lib/config/defaults.js +65 -44
  109. package/lib/config/normalization.js +96 -0
  110. package/lib/container/ContainerEntryDependency.js +3 -0
  111. package/lib/container/ContainerEntryModule.js +7 -0
  112. package/lib/container/ContainerExposedDependency.js +1 -0
  113. package/lib/container/FallbackDependency.js +1 -0
  114. package/lib/container/FallbackItemDependency.js +1 -0
  115. package/lib/container/FallbackModule.js +4 -0
  116. package/lib/container/HoistContainerReferencesPlugin.js +6 -0
  117. package/lib/container/ModuleFederationPlugin.js +1 -1
  118. package/lib/container/RemoteModule.js +42 -1
  119. package/lib/css/CssGenerator.js +38 -4
  120. package/lib/css/CssModulesPlugin.js +33 -30
  121. package/lib/css/CssParser.js +12 -9
  122. package/lib/debug/ProfilingPlugin.js +1 -0
  123. package/lib/dependencies/AMDDefineDependency.js +3 -1
  124. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -0
  125. package/lib/dependencies/AMDPlugin.js +1 -1
  126. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +7 -1
  127. package/lib/dependencies/CachedConstDependency.js +1 -0
  128. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -0
  129. package/lib/dependencies/CommonJsExportRequireDependency.js +5 -0
  130. package/lib/dependencies/CommonJsFullRequireDependency.js +2 -0
  131. package/lib/dependencies/CommonJsImportsParserPlugin.js +315 -506
  132. package/lib/dependencies/CommonJsRequireContextDependency.js +2 -2
  133. package/lib/dependencies/CommonJsSelfReferenceDependency.js +1 -0
  134. package/lib/dependencies/ConstDependency.js +1 -0
  135. package/lib/dependencies/ContextDependencyHelpers.js +11 -4
  136. package/lib/dependencies/ContextElementDependency.js +1 -0
  137. package/lib/dependencies/CreateRequireParserPlugin.js +356 -0
  138. package/lib/dependencies/CriticalDependencyWarning.js +1 -0
  139. package/lib/dependencies/CssIcssExportDependency.js +7 -4
  140. package/lib/dependencies/CssIcssSymbolDependency.js +1 -0
  141. package/lib/dependencies/CssUrlDependency.js +2 -3
  142. package/lib/dependencies/ExternalModuleInitFragment.js +4 -1
  143. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +0 -9
  144. package/lib/dependencies/HarmonyAcceptDependency.js +3 -0
  145. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +3 -1
  146. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +4 -8
  147. package/lib/dependencies/HarmonyExportExpressionDependency.js +4 -0
  148. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +8 -1
  149. package/lib/dependencies/HarmonyExportInitFragment.js +17 -3
  150. package/lib/dependencies/HarmonyExportSpecifierDependency.js +4 -0
  151. package/lib/dependencies/HarmonyImportDependency.js +31 -1
  152. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +217 -49
  153. package/lib/dependencies/HarmonyImportSideEffectDependency.js +11 -5
  154. package/lib/dependencies/HarmonyImportSpecifierDependency.js +22 -3
  155. package/lib/dependencies/HarmonyModulesPlugin.js +4 -0
  156. package/lib/dependencies/ImportDependency.js +1 -0
  157. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  158. package/lib/dependencies/ImportMetaPlugin.js +53 -11
  159. package/lib/dependencies/ImportParserPlugin.js +8 -23
  160. package/lib/dependencies/ImportPhase.js +4 -0
  161. package/lib/dependencies/LoaderPlugin.js +3 -0
  162. package/lib/dependencies/ModuleDecoratorDependency.js +1 -0
  163. package/lib/dependencies/ModuleDependency.js +1 -0
  164. package/lib/dependencies/ModuleInitFragmentDependency.js +87 -0
  165. package/lib/dependencies/ProvidedDependency.js +1 -0
  166. package/lib/dependencies/RequireContextPlugin.js +1 -0
  167. package/lib/dependencies/RequireEnsureDependenciesBlock.js +1 -1
  168. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +7 -2
  169. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -0
  170. package/lib/dependencies/WorkerDependency.js +9 -3
  171. package/lib/dependencies/WorkerPlugin.js +1 -0
  172. package/lib/dependencies/getFunctionExpression.js +3 -1
  173. package/lib/electron/ElectronTargetPlugin.js +3 -1
  174. package/lib/errors/BuildCycleError.js +4 -1
  175. package/lib/esm/ModuleChunkFormatPlugin.js +6 -4
  176. package/lib/esm/ModuleChunkLoadingPlugin.js +1 -0
  177. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -0
  178. package/lib/hmr/LazyCompilationPlugin.js +5 -0
  179. package/lib/hmr/lazyCompilationBackend.js +3 -2
  180. package/lib/ids/ChunkModuleIdRangePlugin.js +9 -7
  181. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -0
  182. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -0
  183. package/lib/ids/HashedModuleIdsPlugin.js +3 -8
  184. package/lib/ids/IdHelpers.js +10 -8
  185. package/lib/ids/NamedChunkIdsPlugin.js +7 -5
  186. package/lib/ids/NamedModuleIdsPlugin.js +1 -0
  187. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
  188. package/lib/ids/OccurrenceModuleIdsPlugin.js +18 -10
  189. package/lib/ids/SyncModuleIdsPlugin.js +30 -20
  190. package/lib/javascript/BasicEvaluatedExpression.js +1 -0
  191. package/lib/javascript/EnableChunkLoadingPlugin.js +5 -2
  192. package/lib/javascript/JavascriptModulesPlugin.js +104 -30
  193. package/lib/javascript/JavascriptParser.js +48 -15
  194. package/lib/json/JsonGenerator.js +1 -0
  195. package/lib/json/JsonParser.js +9 -2
  196. package/lib/library/AbstractLibraryPlugin.js +4 -1
  197. package/lib/library/AmdLibraryPlugin.js +2 -1
  198. package/lib/library/AssignLibraryPlugin.js +6 -2
  199. package/lib/library/EnableLibraryPlugin.js +1 -0
  200. package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
  201. package/lib/library/JsonpLibraryPlugin.js +1 -1
  202. package/lib/library/ModuleLibraryPlugin.js +130 -13
  203. package/lib/library/SystemLibraryPlugin.js +4 -1
  204. package/lib/library/UmdLibraryPlugin.js +4 -3
  205. package/lib/logging/Logger.js +9 -5
  206. package/lib/logging/createConsoleLogger.js +4 -0
  207. package/lib/logging/truncateArgs.js +1 -1
  208. package/lib/node/CommonJsChunkLoadingPlugin.js +6 -4
  209. package/lib/node/NodeEnvironmentPlugin.js +1 -0
  210. package/lib/node/NodeTargetPlugin.js +10 -1
  211. package/lib/node/NodeTemplatePlugin.js +1 -0
  212. package/lib/node/NodeWatchFileSystem.js +6 -0
  213. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -0
  214. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
  215. package/lib/node/ReadFileCompileWasmPlugin.js +1 -0
  216. package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -0
  217. package/lib/node/nodeConsole.js +18 -1
  218. package/lib/optimize/AggressiveMergingPlugin.js +2 -1
  219. package/lib/optimize/AggressiveSplittingPlugin.js +15 -6
  220. package/lib/optimize/ConcatenatedModule.js +36 -19
  221. package/lib/optimize/FlagIncludedChunksPlugin.js +11 -1
  222. package/lib/optimize/InnerGraph.js +5 -3
  223. package/lib/optimize/InnerGraphPlugin.js +25 -25
  224. package/lib/optimize/LimitChunkCountPlugin.js +3 -2
  225. package/lib/optimize/MangleExportsPlugin.js +14 -2
  226. package/lib/optimize/MergeDuplicateChunksPlugin.js +5 -1
  227. package/lib/optimize/MinChunkSizePlugin.js +5 -2
  228. package/lib/optimize/ModuleConcatenationPlugin.js +23 -5
  229. package/lib/optimize/RealContentHashPlugin.js +37 -27
  230. package/lib/optimize/RemoveParentModulesPlugin.js +12 -3
  231. package/lib/optimize/RuntimeChunkPlugin.js +3 -5
  232. package/lib/optimize/SideEffectsFlagPlugin.js +3 -0
  233. package/lib/optimize/SplitChunksPlugin.js +23 -5
  234. package/lib/performance/AssetsOverSizeLimitWarning.js +7 -2
  235. package/lib/performance/EntrypointsOverSizeLimitWarning.js +7 -2
  236. package/lib/performance/NoAsyncChunksWarning.js +1 -0
  237. package/lib/performance/SizeLimitsPlugin.js +7 -6
  238. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +2 -0
  239. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -1
  240. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -0
  241. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -0
  242. package/lib/rules/BasicEffectRulePlugin.js +2 -0
  243. package/lib/rules/BasicMatcherRulePlugin.js +3 -0
  244. package/lib/rules/ObjectMatcherRulePlugin.js +5 -1
  245. package/lib/rules/RuleSetCompiler.js +6 -0
  246. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -0
  247. package/lib/runtime/ChunkNameRuntimeModule.js +1 -0
  248. package/lib/runtime/CompatRuntimeModule.js +1 -0
  249. package/lib/runtime/EnsureChunkRuntimeModule.js +1 -0
  250. package/lib/runtime/GetChunkFilenameRuntimeModule.js +5 -0
  251. package/lib/runtime/GetFullHashRuntimeModule.js +1 -0
  252. package/lib/runtime/GetMainFilenameRuntimeModule.js +2 -0
  253. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -0
  254. package/lib/runtime/LoadScriptRuntimeModule.js +2 -0
  255. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +16 -32
  256. package/lib/runtime/PublicPathRuntimeModule.js +1 -0
  257. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -0
  258. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -0
  259. package/lib/runtime/StartupEntrypointRuntimeModule.js +1 -0
  260. package/lib/runtime/ToBinaryRuntimeModule.js +14 -6
  261. package/lib/schemes/HttpUriPlugin.js +39 -20
  262. package/lib/schemes/VirtualUrlPlugin.js +28 -2
  263. package/lib/serialization/BinaryMiddleware.js +4 -0
  264. package/lib/serialization/FileMiddleware.js +9 -4
  265. package/lib/serialization/ObjectMiddleware.js +34 -11
  266. package/lib/serialization/PlainObjectSerializer.js +2 -0
  267. package/lib/sharing/ConsumeSharedModule.js +78 -1
  268. package/lib/sharing/ConsumeSharedPlugin.js +5 -4
  269. package/lib/sharing/ProvideSharedModule.js +4 -0
  270. package/lib/sharing/ProvideSharedPlugin.js +24 -25
  271. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  272. package/lib/sharing/utils.js +8 -6
  273. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -12
  274. package/lib/stats/DefaultStatsPrinterPlugin.js +6 -5
  275. package/lib/stats/StatsFactory.js +2 -2
  276. package/lib/url/URLParserPlugin.js +5 -3
  277. package/lib/util/AppendOnlyStackedSet.js +78 -0
  278. package/lib/util/Hash.js +1 -0
  279. package/lib/util/IterableHelpers.js +1 -0
  280. package/lib/util/LazyBucketSortedSet.js +1 -0
  281. package/lib/util/LazySet.js +1 -0
  282. package/lib/util/ParallelismFactorCalculator.js +1 -0
  283. package/lib/util/SortableSet.js +1 -0
  284. package/lib/util/StringXor.js +1 -0
  285. package/lib/util/binarySearchBounds.js +15 -8
  286. package/lib/util/chainedImports.js +1 -1
  287. package/lib/util/cleverMerge.js +6 -1
  288. package/lib/util/comparators.js +21 -1
  289. package/lib/util/compileBooleanMatcher.js +3 -3
  290. package/lib/util/concatenate.js +3 -2
  291. package/lib/util/conventions.js +3 -2
  292. package/lib/util/deterministicGrouping.js +13 -1
  293. package/lib/util/extractSourceMap.js +12 -13
  294. package/lib/util/findGraphRoots.js +79 -109
  295. package/lib/util/fs.js +15 -19
  296. package/lib/util/hash/BatchedHash.js +4 -0
  297. package/lib/util/hash/BulkUpdateHash.js +8 -1
  298. package/lib/util/hash/hash-digest.js +1 -0
  299. package/lib/util/hash/wasm-hash.js +18 -2
  300. package/lib/util/identifier.js +7 -2
  301. package/lib/util/magicComment.js +1 -1
  302. package/lib/util/propertyName.js +1 -1
  303. package/lib/util/registerExternalSerializer.js +1 -0
  304. package/lib/util/runtime.js +15 -1
  305. package/lib/util/semver.js +1 -0
  306. package/lib/util/serialization.js +2 -2
  307. package/lib/wasm/EnableWasmLoadingPlugin.js +2 -0
  308. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +11 -3
  309. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -0
  310. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -2
  311. package/lib/wasm-sync/UnsupportedWebAssemblyFeatureError.js +5 -1
  312. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +3 -0
  313. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +2 -0
  314. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +7 -3
  315. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -2
  316. package/lib/wasm-sync/WebAssemblyParser.js +3 -1
  317. package/lib/web/FetchCompileWasmPlugin.js +1 -0
  318. package/lib/web/JsonpChunkLoadingPlugin.js +1 -0
  319. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -0
  320. package/lib/webpack.js +16 -4
  321. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  322. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -0
  323. package/package.json +40 -40
  324. package/schemas/WebpackOptions.check.js +1 -1
  325. package/schemas/WebpackOptions.json +121 -55
  326. package/schemas/plugins/BannerPlugin.json +2 -2
  327. package/schemas/plugins/IgnorePlugin.json +1 -1
  328. package/schemas/plugins/ManifestPlugin.json +3 -3
  329. package/schemas/plugins/ProgressPlugin.json +1 -1
  330. package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
  331. package/schemas/plugins/schemes/HttpUriPlugin.json +1 -1
  332. package/schemas/plugins/schemes/VirtualUrlPlugin.json +3 -3
  333. package/types.d.ts +677 -230
@@ -17,7 +17,9 @@ class ChunkPrefetchFunctionRuntimeModule extends RuntimeModule {
17
17
  */
18
18
  constructor(type, runtimeFunction, runtimeHandlers) {
19
19
  super(`chunk ${type} function`);
20
+ /** @type {string} */
20
21
  this.runtimeFunction = runtimeFunction;
22
+ /** @type {string} */
21
23
  this.runtimeHandlers = runtimeHandlers;
22
24
  }
23
25
 
@@ -9,14 +9,16 @@ const RuntimeModule = require("../RuntimeModule");
9
9
  const Template = require("../Template");
10
10
 
11
11
  /** @typedef {import("../Chunk")} Chunk */
12
+ /** @typedef {import("../Chunk").ChunkChildOfTypeInOrder} ChunkChildOfTypeInOrder */
12
13
  /** @typedef {import("../Compilation")} Compilation */
13
14
 
14
15
  class ChunkPrefetchStartupRuntimeModule extends RuntimeModule {
15
16
  /**
16
- * @param {{ onChunks: Chunk[], chunks: Set<Chunk> }[]} startupChunks chunk ids to trigger when chunks are loaded
17
+ * @param {ChunkChildOfTypeInOrder[]} startupChunks chunk ids to trigger when chunks are loaded
17
18
  */
18
19
  constructor(startupChunks) {
19
20
  super("startup prefetch", RuntimeModule.STAGE_TRIGGER);
21
+ /** @type {ChunkChildOfTypeInOrder[]} */
20
22
  this.startupChunks = startupChunks;
21
23
  }
22
24
 
@@ -17,6 +17,7 @@ class ChunkPrefetchTriggerRuntimeModule extends RuntimeModule {
17
17
  */
18
18
  constructor(chunkMap) {
19
19
  super("chunk prefetch trigger", RuntimeModule.STAGE_TRIGGER);
20
+ /** @type {ChunkChildIdsByOrdersMap} */
20
21
  this.chunkMap = chunkMap;
21
22
  }
22
23
 
@@ -17,6 +17,7 @@ class ChunkPreloadTriggerRuntimeModule extends RuntimeModule {
17
17
  */
18
18
  constructor(chunkMap) {
19
19
  super("chunk preload trigger", RuntimeModule.STAGE_TRIGGER);
20
+ /** @type {ChunkChildIdsByOrdersMap} */
20
21
  this.chunkMap = chunkMap;
21
22
  }
22
23
 
@@ -24,7 +24,9 @@ class BasicEffectRulePlugin {
24
24
  * @param {string=} effectType the effect type
25
25
  */
26
26
  constructor(ruleProperty, effectType) {
27
+ /** @type {BasicEffectRuleKeys} */
27
28
  this.ruleProperty = ruleProperty;
29
+ /** @type {string | BasicEffectRuleKeys} */
28
30
  this.effectType = effectType || ruleProperty;
29
31
  }
30
32
 
@@ -27,8 +27,11 @@ class BasicMatcherRulePlugin {
27
27
  * @param {boolean=} invert if true, inverts the condition
28
28
  */
29
29
  constructor(ruleProperty, dataProperty, invert) {
30
+ /** @type {BasicMatcherRuleKeys} */
30
31
  this.ruleProperty = ruleProperty;
32
+ /** @type {string | BasicMatcherRuleKeys} */
31
33
  this.dataProperty = dataProperty || ruleProperty;
34
+ /** @type {boolean} */
32
35
  this.invert = invert || false;
33
36
  }
34
37
 
@@ -18,18 +18,22 @@
18
18
  */
19
19
 
20
20
  /** @typedef {KeysOfTypes<RuleSetRule, { [k: string]: RuleSetConditionOrConditions }>} ObjectMatcherRuleKeys */
21
+ /** @typedef {keyof EffectData} DataProperty */
21
22
 
22
23
  const PLUGIN_NAME = "ObjectMatcherRulePlugin";
23
24
 
24
25
  class ObjectMatcherRulePlugin {
25
26
  /**
26
27
  * @param {ObjectMatcherRuleKeys} ruleProperty the rule property
27
- * @param {keyof EffectData=} dataProperty the data property
28
+ * @param {DataProperty=} dataProperty the data property
28
29
  * @param {RuleConditionFunction=} additionalConditionFunction need to check
29
30
  */
30
31
  constructor(ruleProperty, dataProperty, additionalConditionFunction) {
32
+ /** @type {ObjectMatcherRuleKeys} */
31
33
  this.ruleProperty = ruleProperty;
34
+ /** @type {DataProperty | ObjectMatcherRuleKeys} */
32
35
  this.dataProperty = dataProperty || ruleProperty;
36
+ /** @type {RuleConditionFunction | undefined} */
33
37
  this.additionalConditionFunction = additionalConditionFunction;
34
38
  }
35
39
 
@@ -9,6 +9,7 @@ const { SyncHook } = require("tapable");
9
9
 
10
10
  /** @typedef {import("enhanced-resolve").ResolveRequest} ResolveRequest */
11
11
  /** @typedef {import("../../declarations/WebpackOptions").Falsy} Falsy */
12
+ /** @typedef {import("../../declarations/WebpackOptions").RuleSetUseItem} RuleSetUseItem */
12
13
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetLoaderOptions} RuleSetLoaderOptions */
13
14
  /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
14
15
 
@@ -87,6 +88,9 @@ const { SyncHook } = require("tapable");
87
88
 
88
89
  /** @typedef {Set<string>} UnhandledProperties */
89
90
 
91
+ /** @typedef {(data: EffectData) => (RuleSetUseItem | (Falsy | RuleSetUseItem)[])} RuleSetUseFn */
92
+ /** @typedef {(value: string) => boolean} RuleSetConditionFn */
93
+
90
94
  /** @typedef {{ apply: (ruleSetCompiler: RuleSetCompiler) => void }} RuleSetPlugin */
91
95
 
92
96
  class RuleSetCompiler {
@@ -116,6 +120,7 @@ class RuleSetCompiler {
116
120
  * @returns {RuleSet} compiled RuleSet
117
121
  */
118
122
  compile(ruleSet) {
123
+ /** @type {References} */
119
124
  const refs = new Map();
120
125
  const rules = this.compileRules("ruleSet", ruleSet, refs);
121
126
 
@@ -327,6 +332,7 @@ class RuleSetCompiler {
327
332
  );
328
333
  }
329
334
 
335
+ /** @type {Condition[]} */
330
336
  const conditions = [];
331
337
  for (const key of Object.keys(condition)) {
332
338
  const value = condition[key];
@@ -16,6 +16,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
16
16
  */
17
17
  constructor(deferInterop = false) {
18
18
  super("async module");
19
+ /** @type {boolean} */
19
20
  this._deferInterop = deferInterop;
20
21
  }
21
22
 
@@ -13,6 +13,7 @@ class ChunkNameRuntimeModule extends RuntimeModule {
13
13
  */
14
14
  constructor(chunkName) {
15
15
  super("chunkName");
16
+ /** @type {string} */
16
17
  this.chunkName = chunkName;
17
18
  }
18
19
 
@@ -14,6 +14,7 @@ const RuntimeModule = require("../RuntimeModule");
14
14
  class CompatRuntimeModule extends RuntimeModule {
15
15
  constructor() {
16
16
  super("compat", RuntimeModule.STAGE_ATTACH);
17
+ /** @type {boolean} */
17
18
  this.fullHash = true;
18
19
  }
19
20
 
@@ -17,6 +17,7 @@ class EnsureChunkRuntimeModule extends RuntimeModule {
17
17
  */
18
18
  constructor(runtimeRequirements) {
19
19
  super("ensure chunk");
20
+ /** @type {ReadOnlyRuntimeRequirements} */
20
21
  this.runtimeRequirements = runtimeRequirements;
21
22
  }
22
23
 
@@ -26,10 +26,15 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
26
26
  */
27
27
  constructor(contentType, name, global, getFilenameForChunk, allChunks) {
28
28
  super(`get ${name} chunk filename`);
29
+ /** @type {string} */
29
30
  this.contentType = contentType;
31
+ /** @type {string} */
30
32
  this.global = global;
33
+ /** @type {(chunk: Chunk) => TemplatePath | false} */
31
34
  this.getFilenameForChunk = getFilenameForChunk;
35
+ /** @type {boolean} */
32
36
  this.allChunks = allChunks;
37
+ /** @type {boolean} */
33
38
  this.dependentHash = true;
34
39
  }
35
40
 
@@ -12,6 +12,7 @@ const RuntimeModule = require("../RuntimeModule");
12
12
  class GetFullHashRuntimeModule extends RuntimeModule {
13
13
  constructor() {
14
14
  super("getFullHash");
15
+ /** @type {boolean} */
15
16
  this.fullHash = true;
16
17
  }
17
18
 
@@ -19,7 +19,9 @@ class GetMainFilenameRuntimeModule extends RuntimeModule {
19
19
  */
20
20
  constructor(name, global, filename) {
21
21
  super(`get ${name} filename`);
22
+ /** @type {string} */
22
23
  this.global = global;
24
+ /** @type {string} */
23
25
  this.filename = filename;
24
26
  }
25
27
 
@@ -17,6 +17,7 @@ class GetTrustedTypesPolicyRuntimeModule extends HelperRuntimeModule {
17
17
  */
18
18
  constructor(runtimeRequirements) {
19
19
  super("trusted types policy");
20
+ /** @type {ReadOnlyRuntimeRequirements} */
20
21
  this.runtimeRequirements = runtimeRequirements;
21
22
  }
22
23
 
@@ -47,7 +47,9 @@ class LoadScriptRuntimeModule extends HelperRuntimeModule {
47
47
  */
48
48
  constructor(withCreateScriptUrl, withFetchPriority) {
49
49
  super("load script");
50
+ /** @type {boolean | undefined} */
50
51
  this._withCreateScriptUrl = withCreateScriptUrl;
52
+ /** @type {boolean | undefined} */
51
53
  this._withFetchPriority = withFetchPriority;
52
54
  }
53
55
 
@@ -17,11 +17,12 @@ const HelperRuntimeModule = require("./HelperRuntimeModule");
17
17
  * @returns {string} mode
18
18
  */
19
19
  function getMakeDeferredNamespaceModeFromExportsType(exportsType) {
20
- if (exportsType === "namespace") return `/* ${exportsType} */ 0`;
21
- if (exportsType === "default-only") return `/* ${exportsType} */ 1`;
20
+ // number is from createFakeNamespaceObject mode ^ 1
21
+ if (exportsType === "namespace") return `/* ${exportsType} */ 8`;
22
+ if (exportsType === "default-only") return `/* ${exportsType} */ 0`;
22
23
  if (exportsType === "default-with-named") return `/* ${exportsType} */ 2`;
23
- if (exportsType === "dynamic") return `/* ${exportsType} */ 3`;
24
- return "";
24
+ if (exportsType === "dynamic") return `/* ${exportsType} */ 6`;
25
+ throw new Error(`Unknown exports type: ${exportsType}`);
25
26
  }
26
27
 
27
28
  /**
@@ -52,6 +53,7 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
52
53
  */
53
54
  constructor(hasAsyncRuntime) {
54
55
  super("make optimized deferred namespace object");
56
+ /** @type {boolean} */
55
57
  this.hasAsyncRuntime = hasAsyncRuntime;
56
58
  }
57
59
 
@@ -66,10 +68,6 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
66
68
  // Note: must be a function (not arrow), because this is used in body!
67
69
  `${fn} = function(moduleId, mode${hasAsync ? ", asyncDeps" : ""}) {`,
68
70
  Template.indent([
69
- "// mode: 0 => namespace (esm)",
70
- "// mode: 1 => default-only (esm strict cjs)",
71
- "// mode: 2 => default-with-named (esm-cjs compat)",
72
- "// mode: 3 => dynamic (if exports has __esModule, then esm, otherwise default-with-named)",
73
71
  "var r = this;",
74
72
  hasAsync ? "var isAsync = asyncDeps && asyncDeps.length;" : "",
75
73
  "var obj = {",
@@ -83,7 +81,7 @@ class MakeOptimizedDeferredNamespaceObjectRuntimeModule extends HelperRuntimeMod
83
81
  // if exportsType is "namespace" we can generate the most optimized code,
84
82
  // on the second access, we can avoid trigger the getter.
85
83
  // we can also do this if exportsType is "dynamic" and there is a "__esModule" property on it.
86
- 'if(mode == 0 || (mode == 3 && exports.__esModule)) Object.defineProperty(this, "a", { value: exports });',
84
+ 'if(mode & 8 || (mode & 4 && exports.__esModule)) Object.defineProperty(this, "a", { value: exports });',
87
85
  "return exports;"
88
86
  ]),
89
87
  "}"
@@ -105,6 +103,7 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
105
103
  */
106
104
  constructor(hasAsyncRuntime) {
107
105
  super("make deferred namespace object");
106
+ /** @type {boolean} */
108
107
  this.hasAsyncRuntime = hasAsyncRuntime;
109
108
  }
110
109
 
@@ -120,11 +119,6 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
120
119
  ? "init?.();"
121
120
  : "if (init) init();";
122
121
  return `${fn} = ${runtimeTemplate.basicFunction("moduleId, mode", [
123
- "// mode: 0 => namespace (esm)",
124
- "// mode: 1 => default-only (esm strict cjs)",
125
- "// mode: 2 => default-with-named (esm-cjs compat)",
126
- "// mode: 3 => dynamic (if exports has __esModule, then esm, otherwise default-with-named)",
127
- "",
128
122
  "var cachedModule = __webpack_module_cache__[moduleId];",
129
123
  "if (cachedModule && cachedModule.error === undefined) {",
130
124
  Template.indent([
@@ -132,10 +126,8 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
132
126
  hasAsync
133
127
  ? `if (${RuntimeGlobals.asyncModuleExportSymbol} in exports) exports = exports[${RuntimeGlobals.asyncModuleExportSymbol}];`
134
128
  : "",
135
- "if (mode == 0) return exports;",
136
- `if (mode == 1) return ${RuntimeGlobals.createFakeNamespaceObject}(exports);`,
137
- `if (mode == 2) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 2);`,
138
- `if (mode == 3) return ${RuntimeGlobals.createFakeNamespaceObject}(exports, 6);` // 2 | 4
129
+ "if (mode & 8) return exports;",
130
+ `return ${RuntimeGlobals.createFakeNamespaceObject}(exports, mode);`
139
131
  ]),
140
132
  "}",
141
133
  "",
@@ -145,7 +137,7 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
145
137
  ? `if (${RuntimeGlobals.asyncModuleExportSymbol} in ns) ns = ns[${RuntimeGlobals.asyncModuleExportSymbol}];`
146
138
  : "",
147
139
  "init = null;",
148
- "if (mode == 0 || mode == 3 && ns.__esModule && typeof ns === 'object') {",
140
+ "if (mode & 8 || mode & 4 && ns.__esModule && typeof ns === 'object') {",
149
141
  Template.indent([
150
142
  "delete handler.defineProperty;",
151
143
  "delete handler.deleteProperty;",
@@ -155,17 +147,9 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
155
147
  "delete handler.ownKeys;",
156
148
  "delete handler.getOwnPropertyDescriptor;"
157
149
  ]),
158
- "} else if (mode == 1) {",
159
- Template.indent([
160
- `ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns);`
161
- ]),
162
- "} else if (mode == 2) {",
163
- Template.indent([
164
- `ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns, 2);`
165
- ]),
166
- "} else if (mode == 3) {",
150
+ "} else {",
167
151
  Template.indent([
168
- `ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns, 6);`
152
+ `ns = ${RuntimeGlobals.createFakeNamespaceObject}(ns, mode);`
169
153
  ]),
170
154
  "}"
171
155
  ])};`,
@@ -211,14 +195,14 @@ class MakeDeferredNamespaceObjectRuntimeModule extends HelperRuntimeModule {
211
195
  `getOwnPropertyDescriptor: ${runtimeTemplate.basicFunction("_, name", [
212
196
  "switch (name) {",
213
197
  Template.indent([
214
- 'case "__esModule": return { value: true, configurable: !!mode };',
215
- 'case Symbol.toStringTag: return { value: "Deferred Module", configurable: !!mode };',
198
+ 'case "__esModule": return { value: true, configurable: !(mode & 8) };',
199
+ 'case Symbol.toStringTag: return { value: "Deferred Module", configurable: !(mode & 8) };',
216
200
  'case "then": return undefined;'
217
201
  ]),
218
202
  "}",
219
203
  init,
220
204
  "var desc = Reflect.getOwnPropertyDescriptor(ns, name);",
221
- 'if (mode == 2 && name == "default" && !desc) {',
205
+ 'if (mode & 2 && name == "default" && !desc) {',
222
206
  Template.indent("desc = { value: ns, configurable: true };"),
223
207
  "}",
224
208
  "return desc;"
@@ -16,6 +16,7 @@ class PublicPathRuntimeModule extends RuntimeModule {
16
16
  */
17
17
  constructor(publicPath) {
18
18
  super("publicPath", RuntimeModule.STAGE_BASIC);
19
+ /** @type {PublicPath} */
19
20
  this.publicPath = publicPath;
20
21
  }
21
22
 
@@ -25,7 +25,9 @@ class StartupChunkDependenciesPlugin {
25
25
  * @param {Options} options options
26
26
  */
27
27
  constructor(options) {
28
+ /** @type {ChunkLoadingType} */
28
29
  this.chunkLoading = options.chunkLoading;
30
+ /** @type {boolean} */
29
31
  this.asyncChunkLoading =
30
32
  typeof options.asyncChunkLoading === "boolean"
31
33
  ? options.asyncChunkLoading
@@ -19,6 +19,7 @@ class StartupChunkDependenciesRuntimeModule extends RuntimeModule {
19
19
  */
20
20
  constructor(asyncChunkLoading) {
21
21
  super("startup chunk dependencies", RuntimeModule.STAGE_TRIGGER);
22
+ /** @type {boolean} */
22
23
  this.asyncChunkLoading = asyncChunkLoading;
23
24
  }
24
25
 
@@ -15,6 +15,7 @@ class StartupEntrypointRuntimeModule extends RuntimeModule {
15
15
  */
16
16
  constructor(asyncChunkLoading) {
17
17
  super("startup entrypoint");
18
+ /** @type {boolean} */
18
19
  this.asyncChunkLoading = asyncChunkLoading;
19
20
  }
20
21
 
@@ -29,30 +29,38 @@ class ToBinaryRuntimeModule extends RuntimeModule {
29
29
  const isNodePlatform = compilation.compiler.platform.node;
30
30
  const isWebPlatform = compilation.compiler.platform.web;
31
31
  const isNeutralPlatform = runtimeTemplate.isNeutralPlatform();
32
+ const toImmutableBytes = runtimeTemplate.basicFunction("value", [
33
+ runtimeTemplate.destructureObject(["buffer"], "value"),
34
+ `${runtimeTemplate.renderConst()} throwErr = ${runtimeTemplate.basicFunction("", ["throw new TypeError('ArrayBuffer is immutable');"])};`,
35
+ "Object.defineProperties(buffer, { immutable: { value: true }, resize: { value: throwErr }, transfer: { value: throwErr }, transferToFixedLength: { value: throwErr } });",
36
+ "Object.freeze(buffer);",
37
+ "return value;"
38
+ ]);
32
39
 
33
40
  return Template.asString([
34
41
  "// define to binary helper",
42
+ `${runtimeTemplate.renderConst()} toImmutableBytes = ${toImmutableBytes}`,
35
43
  `${fn} = ${isNeutralPlatform ? "typeof Buffer !== 'undefined' ? " : ""}${
36
44
  isNodePlatform || isNeutralPlatform
37
- ? `${runtimeTemplate.returningFunction("new Uint8Array(Buffer.from(base64, 'base64'))", "base64")}`
45
+ ? `${runtimeTemplate.returningFunction("toImmutableBytes(new Uint8Array(Buffer.from(base64, 'base64')))", "base64")}`
38
46
  : ""
39
47
  } ${isNeutralPlatform ? ": " : ""}${
40
48
  isWebPlatform || isNeutralPlatform
41
49
  ? `(${runtimeTemplate.basicFunction("", [
42
- "var table = new Uint8Array(128);",
50
+ `${runtimeTemplate.renderConst()} table = new Uint8Array(128);`,
43
51
  "for (var i = 0; i < 64; i++) table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;",
44
52
  `return ${runtimeTemplate.basicFunction("base64", [
45
- "var n = base64.length, bytes = new Uint8Array((n - (base64[n - 1] == '=') - (base64[n - 2] == '=')) * 3 / 4 | 0);",
53
+ `${runtimeTemplate.renderConst()} n = base64.length, bytes = new Uint8Array((n - (base64[n - 1] == '=') - (base64[n - 2] == '=')) * 3 / 4 | 0);`,
46
54
  "for (var i = 0, j = 0; i < n;) {",
47
55
  Template.indent([
48
- "var c0 = table[base64.charCodeAt(i++)], c1 = table[base64.charCodeAt(i++)];",
49
- "var c2 = table[base64.charCodeAt(i++)], c3 = table[base64.charCodeAt(i++)];",
56
+ `${runtimeTemplate.renderConst()} c0 = table[base64.charCodeAt(i++)], c1 = table[base64.charCodeAt(i++)];`,
57
+ `${runtimeTemplate.renderConst()} c2 = table[base64.charCodeAt(i++)], c3 = table[base64.charCodeAt(i++)];`,
50
58
  "bytes[j++] = (c0 << 2) | (c1 >> 4);",
51
59
  "bytes[j++] = (c1 << 4) | (c2 >> 2);",
52
60
  "bytes[j++] = (c2 << 6) | c3;"
53
61
  ]),
54
62
  "}",
55
- "return bytes"
63
+ "return toImmutableBytes(bytes)"
56
64
  ])}`
57
65
  ])})();`
58
66
  : ""
@@ -36,12 +36,20 @@ const getHttps = memoize(() => require("https"));
36
36
 
37
37
  const MAX_REDIRECTS = 5;
38
38
 
39
+ /** @typedef {(url: URL, requestOptions: RequestOptions, callback: (incomingMessage: IncomingMessage) => void) => EventEmitter} Fetch */
40
+
41
+ /**
42
+ * @typedef {object} EventsMap
43
+ * @property {[Error]} error
44
+ */
45
+
39
46
  /**
40
47
  * @param {typeof import("http") | typeof import("https")} request request
41
48
  * @param {string | URL | undefined} proxy proxy
42
- * @returns {(url: URL, requestOptions: RequestOptions, callback: (incomingMessage: IncomingMessage) => void) => EventEmitter} fn
49
+ * @returns {Fetch} fn
43
50
  */
44
51
  const proxyFetch = (request, proxy) => (url, options, callback) => {
52
+ /** @type {EventEmitter<EventsMap>} */
45
53
  const eventEmitter = new EventEmitter();
46
54
 
47
55
  /**
@@ -104,9 +112,7 @@ const validate = createSchemaValidation(
104
112
  * @returns {string} safe path
105
113
  */
106
114
  const toSafePath = (str) =>
107
- str
108
- .replace(/^[^a-zA-Z0-9]+|[^a-zA-Z0-9]+$/g, "")
109
- .replace(/[^a-zA-Z0-9._-]+/g, "_");
115
+ str.replace(/^[^a-z0-9]+|[^a-z0-9]+$/gi, "").replace(/[^a-z0-9._-]+/gi, "_");
110
116
 
111
117
  /**
112
118
  * @param {Buffer} content content
@@ -220,6 +226,7 @@ const sanitizeUrlForError = (href) => {
220
226
 
221
227
  class Lockfile {
222
228
  constructor() {
229
+ /** @type {number} */
223
230
  this.version = 1;
224
231
  /** @type {Map<string, LockfileEntry | "ignore" | "no-cache">} */
225
232
  this.entries = new Map();
@@ -430,6 +437,8 @@ const cachedWithKey = (fn, forceFn = fn) => {
430
437
  /** @typedef {FetchResultMeta & { entry: LockfileEntry, content: Buffer }} ContentFetchResult */
431
438
  /** @typedef {RedirectFetchResult | ContentFetchResult} FetchResult */
432
439
 
440
+ /** @typedef {(uri: string) => boolean} AllowedUriFn */
441
+
433
442
  const PLUGIN_NAME = "HttpUriPlugin";
434
443
 
435
444
  class HttpUriPlugin {
@@ -438,12 +447,8 @@ class HttpUriPlugin {
438
447
  */
439
448
  constructor(options) {
440
449
  validate(options);
441
- this._lockfileLocation = options.lockfileLocation;
442
- this._cacheLocation = options.cacheLocation;
443
- this._upgrade = options.upgrade;
444
- this._frozen = options.frozen;
445
- this._allowedUris = options.allowedUris;
446
- this._proxy = options.proxy;
450
+ /** @type {HttpUriPluginOptions} */
451
+ this.options = options;
447
452
  }
448
453
 
449
454
  /**
@@ -453,7 +458,10 @@ class HttpUriPlugin {
453
458
  */
454
459
  apply(compiler) {
455
460
  const proxy =
456
- this._proxy || process.env.http_proxy || process.env.HTTP_PROXY;
461
+ this.options.proxy || process.env.http_proxy || process.env.HTTP_PROXY;
462
+ /**
463
+ * @type {{ scheme: "http" | "https", fetch: Fetch }[]}
464
+ */
457
465
  const schemes = [
458
466
  {
459
467
  scheme: "http",
@@ -477,7 +485,7 @@ class HttpUriPlugin {
477
485
  const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
478
486
  /** @type {string} */
479
487
  const lockfileLocation =
480
- this._lockfileLocation ||
488
+ this.options.lockfileLocation ||
481
489
  join(
482
490
  intermediateFs,
483
491
  compiler.context,
@@ -487,15 +495,15 @@ class HttpUriPlugin {
487
495
  );
488
496
  /** @type {string | false} */
489
497
  const cacheLocation =
490
- this._cacheLocation !== undefined
491
- ? this._cacheLocation
498
+ this.options.cacheLocation !== undefined
499
+ ? this.options.cacheLocation
492
500
  : `${lockfileLocation}.data`;
493
- const upgrade = this._upgrade || false;
494
- const frozen = this._frozen || false;
501
+ const upgrade = this.options.upgrade || false;
502
+ const frozen = this.options.frozen || false;
495
503
  const hashFunction = "sha512";
496
504
  const hashDigest = "hex";
497
505
  const hashDigestLength = 20;
498
- const allowedUris = this._allowedUris;
506
+ const allowedUris = this.options.allowedUris;
499
507
 
500
508
  let warnedAboutEol = false;
501
509
 
@@ -660,6 +668,7 @@ class HttpUriPlugin {
660
668
  * @returns {string} absolute, validated redirect target
661
669
  */
662
670
  const validateRedirectLocation = (location, base) => {
671
+ /** @type {URL} */
663
672
  let nextUrl;
664
673
  try {
665
674
  nextUrl = new URL(location, base);
@@ -707,6 +716,7 @@ class HttpUriPlugin {
707
716
 
708
717
  if ("location" in result) {
709
718
  // Validate redirect target before following
719
+ /** @type {string} */
710
720
  let absolute;
711
721
  try {
712
722
  absolute = validateRedirectLocation(result.location, url);
@@ -845,6 +855,7 @@ class HttpUriPlugin {
845
855
  res.statusCode >= 301 &&
846
856
  res.statusCode <= 308
847
857
  ) {
858
+ /** @type {string} */
848
859
  let absolute;
849
860
  try {
850
861
  absolute = validateRedirectLocation(location, url);
@@ -891,9 +902,15 @@ class HttpUriPlugin {
891
902
  stream = stream.pipe(createInflate());
892
903
  }
893
904
 
894
- stream.on("data", (chunk) => {
895
- bufferArr.push(chunk);
896
- });
905
+ stream.on(
906
+ "data",
907
+ /**
908
+ * @param {Buffer} chunk chunk
909
+ */
910
+ (chunk) => {
911
+ bufferArr.push(chunk);
912
+ }
913
+ );
897
914
 
898
915
  stream.on("end", () => {
899
916
  if (!res.complete) {
@@ -953,6 +970,7 @@ class HttpUriPlugin {
953
970
  * @returns {boolean} true when allowed, otherwise false
954
971
  */
955
972
  const isAllowed = (uri) => {
973
+ /** @type {URL} */
956
974
  let parsedUri;
957
975
  try {
958
976
  // Parse the URI to prevent userinfo bypass attacks
@@ -963,6 +981,7 @@ class HttpUriPlugin {
963
981
  }
964
982
  for (const allowed of allowedUris) {
965
983
  if (typeof allowed === "string") {
984
+ /** @type {URL} */
966
985
  let parsedAllowed;
967
986
  try {
968
987
  parsedAllowed = new URL(allowed);
@@ -58,17 +58,19 @@ function normalizeModule(virtualConfig) {
58
58
  return virtualConfig;
59
59
  }
60
60
 
61
+ /** @typedef {{ [key: string]: VirtualModuleConfig }} NormalizedModules */
62
+
61
63
  /**
62
64
  * Normalizes all virtual modules with the given scheme
63
65
  * @param {VirtualModules} virtualConfigs The virtual modules to normalize
64
66
  * @param {string} scheme The URL scheme to use
65
- * @returns {{ [key: string]: VirtualModuleConfig }} The normalized virtual modules
67
+ * @returns {NormalizedModules} The normalized virtual modules
66
68
  */
67
69
  function normalizeModules(virtualConfigs, scheme) {
68
70
  return Object.keys(virtualConfigs).reduce((pre, id) => {
69
71
  pre[toVid(id, scheme)] = normalizeModule(virtualConfigs[id]);
70
72
  return pre;
71
- }, /** @type {{ [key: string]: VirtualModuleConfig }} */ ({}));
73
+ }, /** @type {NormalizedModules} */ ({}));
72
74
  }
73
75
 
74
76
  /**
@@ -105,7 +107,9 @@ class VirtualUrlPlugin {
105
107
  * @param {string=} scheme The URL scheme to use
106
108
  */
107
109
  constructor(modules, scheme) {
110
+ /** @type {string} */
108
111
  this.scheme = scheme || DEFAULT_SCHEME;
112
+ /** @type {NormalizedModules} */
109
113
  this.modules = normalizeModules(modules, this.scheme);
110
114
  }
111
115
 
@@ -122,6 +126,27 @@ class VirtualUrlPlugin {
122
126
  compiler.hooks.compilation.tap(
123
127
  PLUGIN_NAME,
124
128
  (compilation, { normalModuleFactory }) => {
129
+ compilation.hooks.assetPath.tap(
130
+ { name: PLUGIN_NAME, before: "TemplatedPathPlugin" },
131
+ (path, data) => {
132
+ if (data.filename && this.modules[data.filename]) {
133
+ /**
134
+ * @param {string} str path
135
+ * @returns {string} safe path
136
+ */
137
+ const toSafePath = (str) =>
138
+ `__${str
139
+ .replace(/:/g, "__")
140
+ .replace(/^[^a-z0-9]+|[^a-z0-9]+$/gi, "")
141
+ .replace(/[^a-z0-9._-]+/gi, "_")}`;
142
+
143
+ // filename: virtual:logo.svg -> __virtual__logo.svg
144
+ data.filename = toSafePath(data.filename);
145
+ }
146
+ return path;
147
+ }
148
+ );
149
+
125
150
  normalModuleFactory.hooks.resolveForScheme
126
151
  .for(scheme)
127
152
  .tap(PLUGIN_NAME, (resourceData) => {
@@ -135,6 +160,7 @@ class VirtualUrlPlugin {
135
160
  const type = virtualConfig.type;
136
161
  resourceData.path = path + type;
137
162
  resourceData.resource = path;
163
+ resourceData.context = compiler.context;
138
164
 
139
165
  if (virtualConfig.version) {
140
166
  const cacheKey = toCacheKey(resourceData.resource, scheme);