webpack 5.93.0 → 5.95.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 (344) hide show
  1. package/README.md +8 -5
  2. package/bin/webpack.js +6 -7
  3. package/hot/log.js +1 -2
  4. package/hot/only-dev-server.js +1 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +4 -3
  8. package/lib/AbstractMethodError.js +10 -5
  9. package/lib/AutomaticPrefetchPlugin.js +1 -1
  10. package/lib/BannerPlugin.js +12 -6
  11. package/lib/Cache.js +8 -10
  12. package/lib/CacheFacade.js +3 -3
  13. package/lib/CaseSensitiveModulesWarning.js +5 -7
  14. package/lib/Chunk.js +14 -11
  15. package/lib/ChunkGraph.js +58 -36
  16. package/lib/ChunkGroup.js +2 -3
  17. package/lib/ChunkTemplate.js +43 -0
  18. package/lib/CleanPlugin.js +10 -11
  19. package/lib/CodeGenerationResults.js +6 -5
  20. package/lib/CommentCompilationWarning.js +0 -1
  21. package/lib/Compilation.js +223 -191
  22. package/lib/Compiler.js +81 -82
  23. package/lib/ConcatenationScope.js +3 -6
  24. package/lib/ConditionalInitFragment.js +6 -7
  25. package/lib/ConstPlugin.js +7 -15
  26. package/lib/ContextExclusionPlugin.js +3 -3
  27. package/lib/ContextModule.js +33 -20
  28. package/lib/ContextModuleFactory.js +89 -44
  29. package/lib/ContextReplacementPlugin.js +10 -9
  30. package/lib/DefinePlugin.js +75 -68
  31. package/lib/DelegatedModule.js +7 -3
  32. package/lib/DelegatedModuleFactoryPlugin.js +36 -22
  33. package/lib/DelegatedPlugin.js +4 -0
  34. package/lib/DependenciesBlock.js +0 -1
  35. package/lib/Dependency.js +10 -14
  36. package/lib/DllEntryPlugin.js +4 -2
  37. package/lib/DllModuleFactory.js +1 -0
  38. package/lib/DllPlugin.js +9 -7
  39. package/lib/DllReferencePlugin.js +30 -15
  40. package/lib/EntryPlugin.js +1 -3
  41. package/lib/EnvironmentPlugin.js +6 -2
  42. package/lib/ErrorHelpers.js +11 -12
  43. package/lib/EvalDevToolModulePlugin.js +10 -12
  44. package/lib/EvalSourceMapDevToolPlugin.js +15 -13
  45. package/lib/ExportsInfo.js +185 -120
  46. package/lib/ExternalModule.js +41 -15
  47. package/lib/ExternalModuleFactoryPlugin.js +23 -10
  48. package/lib/FileSystemInfo.js +791 -422
  49. package/lib/FlagAllModulesAsUsedPlugin.js +1 -1
  50. package/lib/FlagDependencyExportsPlugin.js +12 -11
  51. package/lib/FlagDependencyUsagePlugin.js +1 -1
  52. package/lib/Generator.js +2 -5
  53. package/lib/GraphHelpers.js +3 -2
  54. package/lib/HookWebpackError.js +8 -10
  55. package/lib/HotModuleReplacementPlugin.js +78 -64
  56. package/lib/IgnoreErrorModuleFactory.js +3 -3
  57. package/lib/IgnorePlugin.js +1 -3
  58. package/lib/IgnoreWarningsPlugin.js +6 -9
  59. package/lib/InitFragment.js +2 -3
  60. package/lib/LibManifestPlugin.js +4 -3
  61. package/lib/MainTemplate.js +72 -19
  62. package/lib/Module.js +25 -9
  63. package/lib/ModuleBuildError.js +4 -11
  64. package/lib/ModuleDependencyError.js +5 -5
  65. package/lib/ModuleDependencyWarning.js +5 -5
  66. package/lib/ModuleError.js +1 -5
  67. package/lib/ModuleFilenameHelpers.js +29 -46
  68. package/lib/ModuleGraph.js +7 -6
  69. package/lib/ModuleGraphConnection.js +6 -6
  70. package/lib/ModuleInfoHeaderPlugin.js +82 -30
  71. package/lib/ModuleParseError.js +8 -9
  72. package/lib/ModuleRestoreError.js +1 -1
  73. package/lib/ModuleStoreError.js +1 -1
  74. package/lib/ModuleTemplate.js +33 -1
  75. package/lib/ModuleTypeConstants.js +21 -22
  76. package/lib/ModuleWarning.js +1 -5
  77. package/lib/MultiCompiler.js +24 -26
  78. package/lib/MultiStats.js +73 -31
  79. package/lib/MultiWatching.js +1 -1
  80. package/lib/NormalModule.js +130 -69
  81. package/lib/NormalModuleFactory.js +53 -49
  82. package/lib/OptimizationStages.js +3 -3
  83. package/lib/ProgressPlugin.js +9 -9
  84. package/lib/ProvidePlugin.js +4 -4
  85. package/lib/RuntimeGlobals.js +71 -70
  86. package/lib/RuntimeModule.js +1 -1
  87. package/lib/RuntimePlugin.js +24 -12
  88. package/lib/RuntimeTemplate.js +40 -44
  89. package/lib/SizeFormatHelpers.js +2 -4
  90. package/lib/SourceMapDevToolPlugin.js +42 -34
  91. package/lib/Stats.js +5 -11
  92. package/lib/Template.js +18 -24
  93. package/lib/TemplatedPathPlugin.js +21 -13
  94. package/lib/WarnDeprecatedOptionPlugin.js +0 -1
  95. package/lib/WatchIgnorePlugin.js +26 -9
  96. package/lib/Watching.js +10 -5
  97. package/lib/WebpackOptionsApply.js +84 -62
  98. package/lib/asset/AssetGenerator.js +107 -42
  99. package/lib/asset/AssetModulesPlugin.js +29 -23
  100. package/lib/asset/AssetSourceGenerator.js +2 -7
  101. package/lib/async-modules/AwaitDependenciesInitFragment.js +6 -7
  102. package/lib/buildChunkGraph.js +93 -81
  103. package/lib/cache/IdleFileCachePlugin.js +4 -4
  104. package/lib/cache/MemoryWithGcCachePlugin.js +5 -5
  105. package/lib/cache/PackFileCacheStrategy.js +51 -50
  106. package/lib/cache/ResolverCachePlugin.js +6 -6
  107. package/lib/cache/mergeEtags.js +16 -21
  108. package/lib/cli.js +148 -104
  109. package/lib/config/browserslistTargetHandler.js +16 -13
  110. package/lib/config/defaults.js +32 -28
  111. package/lib/config/normalization.js +335 -344
  112. package/lib/config/target.js +42 -52
  113. package/lib/container/ContainerEntryModule.js +2 -2
  114. package/lib/container/ContainerPlugin.js +1 -1
  115. package/lib/container/RemoteRuntimeModule.js +11 -8
  116. package/lib/container/options.js +18 -4
  117. package/lib/css/CssExportsGenerator.js +26 -24
  118. package/lib/css/CssGenerator.js +9 -4
  119. package/lib/css/CssLoadingRuntimeModule.js +10 -10
  120. package/lib/css/CssModulesPlugin.js +127 -47
  121. package/lib/css/CssParser.js +20 -18
  122. package/lib/css/walkCssTokens.js +80 -95
  123. package/lib/debug/ProfilingPlugin.js +19 -20
  124. package/lib/dependencies/AMDDefineDependency.js +1 -1
  125. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +83 -47
  126. package/lib/dependencies/AMDRequireArrayDependency.js +9 -10
  127. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +22 -16
  128. package/lib/dependencies/AMDRuntimeModules.js +2 -2
  129. package/lib/dependencies/CommonJsDependencyHelpers.js +6 -2
  130. package/lib/dependencies/CommonJsExportRequireDependency.js +37 -41
  131. package/lib/dependencies/CommonJsExportsDependency.js +0 -1
  132. package/lib/dependencies/CommonJsExportsParserPlugin.js +19 -23
  133. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -1
  134. package/lib/dependencies/CommonJsImportsParserPlugin.js +52 -61
  135. package/lib/dependencies/CommonJsSelfReferenceDependency.js +6 -8
  136. package/lib/dependencies/ConstDependency.js +1 -1
  137. package/lib/dependencies/ContextDependency.js +7 -2
  138. package/lib/dependencies/ContextDependencyHelpers.js +31 -34
  139. package/lib/dependencies/ContextElementDependency.js +35 -8
  140. package/lib/dependencies/CriticalDependencyWarning.js +1 -1
  141. package/lib/dependencies/CssExportDependency.js +7 -7
  142. package/lib/dependencies/CssImportDependency.js +0 -2
  143. package/lib/dependencies/CssLocalIdentifierDependency.js +3 -3
  144. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  145. package/lib/dependencies/CssUrlDependency.js +4 -5
  146. package/lib/dependencies/DynamicExports.js +5 -5
  147. package/lib/dependencies/ExportsInfoDependency.js +1 -2
  148. package/lib/dependencies/HarmonyAcceptImportDependency.js +1 -1
  149. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -5
  150. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +27 -16
  151. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  152. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +107 -64
  153. package/lib/dependencies/HarmonyExports.js +2 -2
  154. package/lib/dependencies/HarmonyImportDependency.js +2 -4
  155. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +19 -4
  156. package/lib/dependencies/HarmonyImportSpecifierDependency.js +40 -15
  157. package/lib/dependencies/ImportDependency.js +1 -1
  158. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +5 -5
  159. package/lib/dependencies/ImportMetaPlugin.js +11 -13
  160. package/lib/dependencies/ImportParserPlugin.js +39 -44
  161. package/lib/dependencies/JsonExportsDependency.js +22 -18
  162. package/lib/dependencies/LoaderPlugin.js +47 -36
  163. package/lib/dependencies/LocalModule.js +1 -1
  164. package/lib/dependencies/LocalModulesHelpers.js +4 -4
  165. package/lib/dependencies/ModuleDecoratorDependency.js +1 -1
  166. package/lib/dependencies/ProvidedDependency.js +1 -1
  167. package/lib/dependencies/PureExpressionDependency.js +6 -6
  168. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  169. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  170. package/lib/dependencies/SystemPlugin.js +1 -1
  171. package/lib/dependencies/URLDependency.js +3 -3
  172. package/lib/dependencies/URLPlugin.js +66 -12
  173. package/lib/dependencies/WorkerPlugin.js +25 -24
  174. package/lib/dependencies/processExportInfo.js +3 -1
  175. package/lib/electron/ElectronTargetPlugin.js +1 -0
  176. package/lib/esm/ModuleChunkFormatPlugin.js +3 -3
  177. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +7 -3
  178. package/lib/formatLocation.js +1 -2
  179. package/lib/hmr/HotModuleReplacement.runtime.js +4 -5
  180. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -0
  181. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +9 -12
  182. package/lib/hmr/LazyCompilationPlugin.js +27 -12
  183. package/lib/hmr/lazyCompilationBackend.js +64 -40
  184. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -3
  185. package/lib/ids/DeterministicChunkIdsPlugin.js +2 -4
  186. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  187. package/lib/ids/HashedModuleIdsPlugin.js +5 -1
  188. package/lib/ids/IdHelpers.js +29 -39
  189. package/lib/ids/SyncModuleIdsPlugin.js +7 -2
  190. package/lib/index.js +1 -5
  191. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +5 -4
  192. package/lib/javascript/BasicEvaluatedExpression.js +4 -19
  193. package/lib/javascript/ChunkHelpers.js +1 -1
  194. package/lib/javascript/CommonJsChunkFormatPlugin.js +3 -2
  195. package/lib/javascript/EnableChunkLoadingPlugin.js +7 -6
  196. package/lib/javascript/JavascriptGenerator.js +23 -7
  197. package/lib/javascript/JavascriptModulesPlugin.js +133 -86
  198. package/lib/javascript/JavascriptParser.js +179 -200
  199. package/lib/javascript/JavascriptParserHelpers.js +20 -21
  200. package/lib/javascript/StartupHelpers.js +41 -13
  201. package/lib/json/JsonGenerator.js +7 -13
  202. package/lib/json/JsonModulesPlugin.js +1 -4
  203. package/lib/json/JsonParser.js +5 -3
  204. package/lib/library/AmdLibraryPlugin.js +12 -16
  205. package/lib/library/AssignLibraryPlugin.js +8 -10
  206. package/lib/library/EnableLibraryPlugin.js +15 -14
  207. package/lib/library/JsonpLibraryPlugin.js +2 -1
  208. package/lib/library/ModernModuleLibraryPlugin.js +8 -6
  209. package/lib/library/ModuleLibraryPlugin.js +2 -1
  210. package/lib/library/SystemLibraryPlugin.js +2 -1
  211. package/lib/library/UmdLibraryPlugin.js +66 -92
  212. package/lib/logging/Logger.js +32 -4
  213. package/lib/logging/createConsoleLogger.js +12 -13
  214. package/lib/logging/runtime.js +7 -8
  215. package/lib/logging/truncateArgs.js +5 -8
  216. package/lib/node/NodeWatchFileSystem.js +3 -18
  217. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -2
  218. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +1 -0
  219. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -2
  220. package/lib/node/nodeConsole.js +22 -22
  221. package/lib/optimize/AggressiveMergingPlugin.js +2 -4
  222. package/lib/optimize/AggressiveSplittingPlugin.js +16 -19
  223. package/lib/optimize/ConcatenatedModule.js +81 -51
  224. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  225. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -3
  226. package/lib/optimize/InnerGraph.js +17 -17
  227. package/lib/optimize/InnerGraphPlugin.js +8 -7
  228. package/lib/optimize/LimitChunkCountPlugin.js +2 -3
  229. package/lib/optimize/MangleExportsPlugin.js +1 -0
  230. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
  231. package/lib/optimize/MinMaxSizeWarning.js +1 -1
  232. package/lib/optimize/ModuleConcatenationPlugin.js +54 -78
  233. package/lib/optimize/RealContentHashPlugin.js +7 -10
  234. package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
  235. package/lib/optimize/SideEffectsFlagPlugin.js +6 -2
  236. package/lib/optimize/SplitChunksPlugin.js +34 -30
  237. package/lib/performance/SizeLimitsPlugin.js +2 -2
  238. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +1 -1
  239. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +1 -1
  240. package/lib/rules/BasicEffectRulePlugin.js +3 -1
  241. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  242. package/lib/rules/ObjectMatcherRulePlugin.js +4 -1
  243. package/lib/rules/RuleSetCompiler.js +41 -22
  244. package/lib/rules/UseEffectRulePlugin.js +36 -32
  245. package/lib/runtime/AsyncModuleRuntimeModule.js +1 -1
  246. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  247. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +2 -2
  248. package/lib/runtime/DefinePropertyGettersRuntimeModule.js +1 -1
  249. package/lib/runtime/EnsureChunkRuntimeModule.js +10 -11
  250. package/lib/runtime/GetChunkFilenameRuntimeModule.js +11 -17
  251. package/lib/runtime/LoadScriptRuntimeModule.js +17 -18
  252. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +1 -3
  253. package/lib/schemes/DataUriPlugin.js +1 -1
  254. package/lib/schemes/HttpUriPlugin.js +241 -126
  255. package/lib/serialization/BinaryMiddleware.js +44 -28
  256. package/lib/serialization/DateObjectSerializer.js +1 -0
  257. package/lib/serialization/ErrorObjectSerializer.js +2 -0
  258. package/lib/serialization/FileMiddleware.js +154 -106
  259. package/lib/serialization/MapObjectSerializer.js +2 -1
  260. package/lib/serialization/NullPrototypeObjectSerializer.js +3 -2
  261. package/lib/serialization/ObjectMiddleware.js +52 -56
  262. package/lib/serialization/PlainObjectSerializer.js +32 -6
  263. package/lib/serialization/RegExpObjectSerializer.js +1 -0
  264. package/lib/serialization/Serializer.js +4 -5
  265. package/lib/serialization/SerializerMiddleware.js +6 -6
  266. package/lib/serialization/SetObjectSerializer.js +2 -1
  267. package/lib/sharing/ConsumeSharedPlugin.js +116 -97
  268. package/lib/sharing/ConsumeSharedRuntimeModule.js +4 -4
  269. package/lib/sharing/ProvideForSharedDependency.js +0 -1
  270. package/lib/sharing/ProvideSharedPlugin.js +2 -2
  271. package/lib/sharing/resolveMatchedConfigs.js +2 -1
  272. package/lib/sharing/utils.js +15 -27
  273. package/lib/stats/DefaultStatsFactoryPlugin.js +424 -281
  274. package/lib/stats/DefaultStatsPresetPlugin.js +73 -18
  275. package/lib/stats/DefaultStatsPrinterPlugin.js +370 -101
  276. package/lib/stats/StatsFactory.js +127 -56
  277. package/lib/stats/StatsPrinter.js +75 -44
  278. package/lib/util/ArrayHelpers.js +8 -4
  279. package/lib/util/ArrayQueue.js +1 -1
  280. package/lib/util/AsyncQueue.js +31 -12
  281. package/lib/util/IterableHelpers.js +3 -4
  282. package/lib/util/LazyBucketSortedSet.js +60 -44
  283. package/lib/util/LazySet.js +13 -0
  284. package/lib/util/MapHelpers.js +1 -3
  285. package/lib/util/ParallelismFactorCalculator.js +1 -1
  286. package/lib/util/Queue.js +1 -1
  287. package/lib/util/Semaphore.js +4 -7
  288. package/lib/util/SetHelpers.js +5 -5
  289. package/lib/util/SortableSet.js +4 -3
  290. package/lib/util/StackedCacheMap.js +4 -6
  291. package/lib/util/StackedMap.js +1 -3
  292. package/lib/util/StringXor.js +0 -5
  293. package/lib/util/TupleQueue.js +1 -1
  294. package/lib/util/TupleSet.js +15 -5
  295. package/lib/util/URLAbsoluteSpecifier.js +7 -7
  296. package/lib/util/WeakTupleMap.js +19 -21
  297. package/lib/util/binarySearchBounds.js +5 -12
  298. package/lib/util/chainedImports.js +1 -1
  299. package/lib/util/cleverMerge.js +21 -19
  300. package/lib/util/comparators.js +57 -52
  301. package/lib/util/compileBooleanMatcher.js +3 -6
  302. package/lib/util/conventions.js +8 -11
  303. package/lib/util/createHash.js +9 -6
  304. package/lib/util/deprecation.js +22 -12
  305. package/lib/util/deterministicGrouping.js +19 -26
  306. package/lib/util/findGraphRoots.js +2 -2
  307. package/lib/util/fs.js +32 -32
  308. package/lib/util/hash/md4.js +2 -2
  309. package/lib/util/hash/wasm-hash.js +7 -7
  310. package/lib/util/hash/xxhash64.js +2 -2
  311. package/lib/util/identifier.js +81 -59
  312. package/lib/util/memoize.js +8 -10
  313. package/lib/util/mergeScope.js +6 -9
  314. package/lib/util/nonNumericOnlyHash.js +2 -2
  315. package/lib/util/numberHash.js +1 -6
  316. package/lib/util/objectToMap.js +0 -1
  317. package/lib/util/propertyAccess.js +2 -5
  318. package/lib/util/propertyName.js +1 -3
  319. package/lib/util/registerExternalSerializer.js +1 -1
  320. package/lib/util/runtime.js +109 -113
  321. package/lib/util/semver.js +29 -27
  322. package/lib/util/serialization.js +16 -1
  323. package/lib/util/smartGrouping.js +5 -5
  324. package/lib/util/source.js +1 -1
  325. package/lib/wasm/EnableWasmLoadingPlugin.js +5 -4
  326. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
  327. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -6
  328. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  329. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +20 -19
  330. package/lib/wasm-sync/WebAssemblyGenerator.js +14 -29
  331. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +1 -1
  332. package/lib/wasm-sync/WebAssemblyUtils.js +2 -2
  333. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -3
  334. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -1
  335. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  336. package/package.json +18 -17
  337. package/schemas/WebpackOptions.check.js +1 -1
  338. package/schemas/WebpackOptions.json +5 -0
  339. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  340. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  341. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  342. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  343. package/schemas/plugins/container/ModuleFederationPlugin.json +1 -0
  344. package/types.d.ts +681 -355
@@ -5,13 +5,16 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ const { SyncWaterfallHook, SyncHook } = require("tapable");
8
9
  const {
9
10
  ConcatSource,
10
11
  PrefixSource,
11
12
  ReplaceSource,
12
13
  CachedSource
13
14
  } = require("webpack-sources");
15
+ const Compilation = require("../Compilation");
14
16
  const CssModule = require("../CssModule");
17
+ const { tryRunOrWebpackError } = require("../HookWebpackError");
15
18
  const HotUpdateChunk = require("../HotUpdateChunk");
16
19
  const {
17
20
  CSS_MODULE_TYPE,
@@ -39,17 +42,31 @@ const CssGenerator = require("./CssGenerator");
39
42
  const CssParser = require("./CssParser");
40
43
 
41
44
  /** @typedef {import("webpack-sources").Source} Source */
42
- /** @typedef {import("../../declarations/WebpackOptions").Output} OutputOptions */
45
+ /** @typedef {import("../../declarations/WebpackOptions").OutputNormalized} OutputOptions */
43
46
  /** @typedef {import("../Chunk")} Chunk */
44
47
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
45
48
  /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
46
- /** @typedef {import("../Compilation")} Compilation */
49
+ /** @typedef {import("../Compilation").ChunkHashContext} ChunkHashContext */
47
50
  /** @typedef {import("../Compiler")} Compiler */
48
51
  /** @typedef {import("../CssModule").Inheritance} Inheritance */
49
52
  /** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
50
53
  /** @typedef {import("../Module")} Module */
54
+ /** @typedef {import("../Template").RuntimeTemplate} RuntimeTemplate */
55
+ /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
56
+ /** @typedef {import("../util/Hash")} Hash */
51
57
  /** @typedef {import("../util/memoize")} Memoize */
52
58
 
59
+ /**
60
+ * @typedef {object} ChunkRenderContext
61
+ * @property {RuntimeTemplate} runtimeTemplate runtime template
62
+ */
63
+
64
+ /**
65
+ * @typedef {object} CompilationHooks
66
+ * @property {SyncWaterfallHook<[Source, Module, ChunkRenderContext]>} renderModulePackage
67
+ * @property {SyncHook<[Chunk, Hash, ChunkHashContext]>} chunkHash
68
+ */
69
+
53
70
  const getCssLoadingRuntimeModule = memoize(() =>
54
71
  require("./CssLoadingRuntimeModule")
55
72
  );
@@ -120,6 +137,9 @@ const validateParserOptions = {
120
137
  )
121
138
  };
122
139
 
140
+ /** @type {WeakMap<Compilation, CompilationHooks>} */
141
+ const compilationHooksMap = new WeakMap();
142
+
123
143
  /**
124
144
  * @param {string} str string
125
145
  * @param {boolean=} omitOptionalUnderscore if true, optional underscore is not added
@@ -128,7 +148,7 @@ const validateParserOptions = {
128
148
  const escapeCss = (str, omitOptionalUnderscore) => {
129
149
  const escaped = `${str}`.replace(
130
150
  // cspell:word uffff
131
- /[^a-zA-Z0-9_\u0081-\uffff-]/g,
151
+ /[^a-zA-Z0-9_\u0081-\uFFFF-]/g,
132
152
  s => `\\${s}`
133
153
  );
134
154
  return !omitOptionalUnderscore && /^(?!--)[0-9_-]/.test(escaped)
@@ -140,13 +160,13 @@ const escapeCss = (str, omitOptionalUnderscore) => {
140
160
  * @param {string} str string
141
161
  * @returns {string} encoded string
142
162
  */
143
- const LZWEncode = str => {
163
+ const lzwEncode = str => {
144
164
  /** @type {Map<string, string>} */
145
165
  const map = new Map();
146
166
  let encoded = "";
147
167
  let phrase = str[0];
148
168
  let code = 256;
149
- let maxCode = "\uffff".charCodeAt(0);
169
+ const maxCode = "\uFFFF".charCodeAt(0);
150
170
  for (let i = 1; i < str.length; i++) {
151
171
  const c = str[i];
152
172
  if (map.has(phrase + c)) {
@@ -165,9 +185,34 @@ const LZWEncode = str => {
165
185
  return encoded;
166
186
  };
167
187
 
168
- const plugin = "CssModulesPlugin";
188
+ const PLUGIN_NAME = "CssModulesPlugin";
169
189
 
170
190
  class CssModulesPlugin {
191
+ /**
192
+ * @param {Compilation} compilation the compilation
193
+ * @returns {CompilationHooks} the attached hooks
194
+ */
195
+ static getCompilationHooks(compilation) {
196
+ if (!(compilation instanceof Compilation)) {
197
+ throw new TypeError(
198
+ "The 'compilation' argument must be an instance of Compilation"
199
+ );
200
+ }
201
+ let hooks = compilationHooksMap.get(compilation);
202
+ if (hooks === undefined) {
203
+ hooks = {
204
+ renderModulePackage: new SyncWaterfallHook([
205
+ "source",
206
+ "module",
207
+ "renderContext"
208
+ ]),
209
+ chunkHash: new SyncHook(["chunk", "hash", "context"])
210
+ };
211
+ compilationHooksMap.set(compilation, hooks);
212
+ }
213
+ return hooks;
214
+ }
215
+
171
216
  constructor() {
172
217
  /** @type {WeakMap<Source, { undoPath: string, inheritance: Inheritance, source: CachedSource }>} */
173
218
  this._moduleCache = new WeakMap();
@@ -180,8 +225,9 @@ class CssModulesPlugin {
180
225
  */
181
226
  apply(compiler) {
182
227
  compiler.hooks.compilation.tap(
183
- plugin,
228
+ PLUGIN_NAME,
184
229
  (compilation, { normalModuleFactory }) => {
230
+ const hooks = CssModulesPlugin.getCompilationHooks(compilation);
185
231
  const selfFactory = new SelfModuleFactory(compilation.moduleGraph);
186
232
  compilation.dependencyFactories.set(
187
233
  CssUrlDependency,
@@ -227,7 +273,7 @@ class CssModulesPlugin {
227
273
  ]) {
228
274
  normalModuleFactory.hooks.createParser
229
275
  .for(type)
230
- .tap(plugin, parserOptions => {
276
+ .tap(PLUGIN_NAME, parserOptions => {
231
277
  validateParserOptions[type](parserOptions);
232
278
  const { namedExports } = parserOptions;
233
279
 
@@ -251,7 +297,7 @@ class CssModulesPlugin {
251
297
  });
252
298
  normalModuleFactory.hooks.createGenerator
253
299
  .for(type)
254
- .tap(plugin, generatorOptions => {
300
+ .tap(PLUGIN_NAME, generatorOptions => {
255
301
  validateGeneratorOptions[type](generatorOptions);
256
302
 
257
303
  return generatorOptions.exportsOnly
@@ -268,7 +314,7 @@ class CssModulesPlugin {
268
314
  });
269
315
  normalModuleFactory.hooks.createModuleClass
270
316
  .for(type)
271
- .tap(plugin, (createData, resolveData) => {
317
+ .tap(PLUGIN_NAME, (createData, resolveData) => {
272
318
  if (resolveData.dependencies.length > 0) {
273
319
  // When CSS is imported from CSS there is only one dependency
274
320
  const dependency = resolveData.dependencies[0];
@@ -340,9 +386,18 @@ class CssModulesPlugin {
340
386
  }
341
387
  }
342
388
  });
389
+ compilation.hooks.chunkHash.tap(
390
+ "CssModulesPlugin",
391
+ (chunk, hash, context) => {
392
+ hooks.chunkHash.call(chunk, hash, context);
393
+ }
394
+ );
343
395
  compilation.hooks.contentHash.tap("CssModulesPlugin", chunk => {
344
396
  const {
345
397
  chunkGraph,
398
+ codeGenerationResults,
399
+ moduleGraph,
400
+ runtimeTemplate,
346
401
  outputOptions: {
347
402
  hashSalt,
348
403
  hashDigest,
@@ -350,19 +405,27 @@ class CssModulesPlugin {
350
405
  hashFunction
351
406
  }
352
407
  } = compilation;
353
- const modules = orderedCssModulesPerChunk.get(chunk);
354
- if (modules === undefined) return;
355
408
  const hash = createHash(hashFunction);
356
409
  if (hashSalt) hash.update(hashSalt);
357
- for (const module of modules) {
358
- hash.update(chunkGraph.getModuleHash(module, chunk.runtime));
410
+ hooks.chunkHash.call(chunk, hash, {
411
+ chunkGraph,
412
+ codeGenerationResults,
413
+ moduleGraph,
414
+ runtimeTemplate
415
+ });
416
+ const modules = orderedCssModulesPerChunk.get(chunk);
417
+ if (modules) {
418
+ for (const module of modules) {
419
+ hash.update(chunkGraph.getModuleHash(module, chunk.runtime));
420
+ }
359
421
  }
360
422
  const digest = /** @type {string} */ (hash.digest(hashDigest));
361
423
  chunk.contentHash.css = nonNumericOnlyHash(digest, hashDigestLength);
362
424
  });
363
- compilation.hooks.renderManifest.tap(plugin, (result, options) => {
425
+ compilation.hooks.renderManifest.tap(PLUGIN_NAME, (result, options) => {
364
426
  const { chunkGraph } = compilation;
365
- const { hash, chunk, codeGenerationResults } = options;
427
+ const { hash, chunk, codeGenerationResults, runtimeTemplate } =
428
+ options;
366
429
 
367
430
  if (chunk instanceof HotUpdateChunk) return result;
368
431
 
@@ -396,7 +459,9 @@ class CssModulesPlugin {
396
459
  cssHeadDataCompression:
397
460
  compilation.outputOptions.cssHeadDataCompression,
398
461
  undoPath,
399
- modules
462
+ modules,
463
+ runtimeTemplate,
464
+ hooks
400
465
  }),
401
466
  filename,
402
467
  info,
@@ -440,13 +505,13 @@ class CssModulesPlugin {
440
505
  };
441
506
  compilation.hooks.runtimeRequirementInTree
442
507
  .for(RuntimeGlobals.hasCssModules)
443
- .tap(plugin, handler);
508
+ .tap(PLUGIN_NAME, handler);
444
509
  compilation.hooks.runtimeRequirementInTree
445
510
  .for(RuntimeGlobals.ensureChunkHandlers)
446
- .tap(plugin, handler);
511
+ .tap(PLUGIN_NAME, handler);
447
512
  compilation.hooks.runtimeRequirementInTree
448
513
  .for(RuntimeGlobals.hmrDownloadUpdateHandlers)
449
- .tap(plugin, handler);
514
+ .tap(PLUGIN_NAME, handler);
450
515
  }
451
516
  );
452
517
  }
@@ -467,12 +532,10 @@ class CssModulesPlugin {
467
532
  // Lists are in reverse order to allow to use Array.pop()
468
533
  const modulesByChunkGroup = Array.from(chunk.groupsIterable, chunkGroup => {
469
534
  const sortedModules = modulesList
470
- .map(module => {
471
- return {
472
- module,
473
- index: chunkGroup.getModulePostOrderIndex(module)
474
- };
475
- })
535
+ .map(module => ({
536
+ module,
537
+ index: chunkGroup.getModulePostOrderIndex(module)
538
+ }))
476
539
  .filter(item => item.index !== undefined)
477
540
  .sort(
478
541
  (a, b) =>
@@ -489,10 +552,9 @@ class CssModulesPlugin {
489
552
  const compareModuleLists = ({ list: a }, { list: b }) => {
490
553
  if (a.length === 0) {
491
554
  return b.length === 0 ? 0 : 1;
492
- } else {
493
- if (b.length === 0) return -1;
494
- return compareModulesByIdentifier(a[a.length - 1], b[b.length - 1]);
495
555
  }
556
+ if (b.length === 0) return -1;
557
+ return compareModulesByIdentifier(a[a.length - 1], b[b.length - 1]);
496
558
  };
497
559
 
498
560
  modulesByChunkGroup.sort(compareModuleLists);
@@ -509,7 +571,7 @@ class CssModulesPlugin {
509
571
  }
510
572
  /** @type {Module} */
511
573
  let selectedModule = list[list.length - 1];
512
- let hasFailed = undefined;
574
+ let hasFailed;
513
575
  outer: for (;;) {
514
576
  for (const { list, set } of modulesByChunkGroup) {
515
577
  if (list.length === 0) continue;
@@ -602,6 +664,8 @@ class CssModulesPlugin {
602
664
  * @param {ChunkGraph} options.chunkGraph chunk graph
603
665
  * @param {CodeGenerationResults} options.codeGenerationResults code generation results
604
666
  * @param {CssModule} options.module css module
667
+ * @param {RuntimeTemplate} options.runtimeTemplate runtime template
668
+ * @param {CompilationHooks} options.hooks hooks
605
669
  * @returns {Source} css module source
606
670
  */
607
671
  renderModule({
@@ -610,7 +674,9 @@ class CssModulesPlugin {
610
674
  chunk,
611
675
  chunkGraph,
612
676
  codeGenerationResults,
613
- module
677
+ module,
678
+ hooks,
679
+ runtimeTemplate
614
680
  }) {
615
681
  const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
616
682
  const moduleSourceContent =
@@ -623,7 +689,7 @@ class CssModulesPlugin {
623
689
  const cacheEntry = this._moduleCache.get(moduleSourceContent);
624
690
 
625
691
  /** @type {Inheritance} */
626
- let inheritance = [[module.cssLayer, module.supports, module.media]];
692
+ const inheritance = [[module.cssLayer, module.supports, module.media]];
627
693
  if (module.inheritance) {
628
694
  inheritance.push(...module.inheritance);
629
695
  }
@@ -707,7 +773,7 @@ class CssModulesPlugin {
707
773
  codeGenResult.data && codeGenResult.data.get("css-exports");
708
774
  const exports = cssExportsData && cssExportsData.exports;
709
775
  const esModule = cssExportsData && cssExportsData.esModule;
710
- let moduleId = chunkGraph.getModuleId(module) + "";
776
+ let moduleId = String(chunkGraph.getModuleId(module));
711
777
 
712
778
  // When `optimization.moduleIds` is `named` the module id is a path, so we need to normalize it between platforms
713
779
  if (typeof moduleId === "string") {
@@ -724,7 +790,13 @@ class CssModulesPlugin {
724
790
  : ""
725
791
  }${esModule ? "&" : ""}${escapeCss(moduleId)}`
726
792
  );
727
- return source;
793
+ return tryRunOrWebpackError(
794
+ () =>
795
+ hooks.renderModulePackage.call(source, module, {
796
+ runtimeTemplate
797
+ }),
798
+ "CssModulesPlugin.getCompilationHooks().renderModulePackage"
799
+ );
728
800
  }
729
801
 
730
802
  /**
@@ -736,6 +808,8 @@ class CssModulesPlugin {
736
808
  * @param {ChunkGraph} options.chunkGraph chunk graph
737
809
  * @param {CodeGenerationResults} options.codeGenerationResults code generation results
738
810
  * @param {CssModule[]} options.modules ordered css modules
811
+ * @param {RuntimeTemplate} options.runtimeTemplate runtime template
812
+ * @param {CompilationHooks} options.hooks hooks
739
813
  * @returns {Source} generated source
740
814
  */
741
815
  renderChunk({
@@ -745,7 +819,9 @@ class CssModulesPlugin {
745
819
  chunk,
746
820
  chunkGraph,
747
821
  codeGenerationResults,
748
- modules
822
+ modules,
823
+ runtimeTemplate,
824
+ hooks
749
825
  }) {
750
826
  const source = new ConcatSource();
751
827
  /** @type {string[]} */
@@ -758,38 +834,40 @@ class CssModulesPlugin {
758
834
  chunk,
759
835
  chunkGraph,
760
836
  codeGenerationResults,
761
- module
837
+ module,
838
+ runtimeTemplate,
839
+ hooks
762
840
  });
763
841
  source.add(moduleSource);
764
- } catch (e) {
842
+ } catch (err) {
765
843
  /** @type {Error} */
766
- (e).message += `\nduring rendering of css ${module.identifier()}`;
767
- throw e;
844
+ (err).message += `\nduring rendering of css ${module.identifier()}`;
845
+ throw err;
768
846
  }
769
847
  }
770
848
  const metaDataStr = metaData.join(",");
771
849
  source.add(
772
850
  `head{--webpack-${escapeCss(
773
- (uniqueName ? uniqueName + "-" : "") + chunk.id,
851
+ (uniqueName ? `${uniqueName}-` : "") + chunk.id,
774
852
  true
775
- )}:${cssHeadDataCompression ? LZWEncode(metaDataStr) : metaDataStr};}`
853
+ )}:${cssHeadDataCompression ? lzwEncode(metaDataStr) : metaDataStr};}`
776
854
  );
855
+ chunk.rendered = true;
777
856
  return source;
778
857
  }
779
858
 
780
859
  /**
781
860
  * @param {Chunk} chunk chunk
782
861
  * @param {OutputOptions} outputOptions output options
783
- * @returns {Chunk["cssFilenameTemplate"] | OutputOptions["cssFilename"] | OutputOptions["cssChunkFilename"]} used filename template
862
+ * @returns {TemplatePath} used filename template
784
863
  */
785
864
  static getChunkFilenameTemplate(chunk, outputOptions) {
786
865
  if (chunk.cssFilenameTemplate) {
787
866
  return chunk.cssFilenameTemplate;
788
867
  } else if (chunk.canBeInitial()) {
789
- return outputOptions.cssFilename;
790
- } else {
791
- return outputOptions.cssChunkFilename;
868
+ return /** @type {TemplatePath} */ (outputOptions.cssFilename);
792
869
  }
870
+ return /** @type {TemplatePath} */ (outputOptions.cssChunkFilename);
793
871
  }
794
872
 
795
873
  /**
@@ -799,8 +877,10 @@ class CssModulesPlugin {
799
877
  */
800
878
  static chunkHasCss(chunk, chunkGraph) {
801
879
  return (
802
- !!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css") ||
803
- !!chunkGraph.getChunkModulesIterableBySourceType(chunk, "css-import")
880
+ Boolean(chunkGraph.getChunkModulesIterableBySourceType(chunk, "css")) ||
881
+ Boolean(
882
+ chunkGraph.getChunkModulesIterableBySourceType(chunk, "css-import")
883
+ )
804
884
  );
805
885
  }
806
886
  }
@@ -60,10 +60,9 @@ const normalizeUrl = (str, isString) => {
60
60
  // Unescape
61
61
  .replace(UNESCAPE, match => {
62
62
  if (match.length > 2) {
63
- return String.fromCharCode(parseInt(match.slice(1).trim(), 16));
64
- } else {
65
- return match[1];
63
+ return String.fromCharCode(Number.parseInt(match.slice(1).trim(), 16));
66
64
  }
65
+ return match[1];
67
66
  });
68
67
 
69
68
  if (/^data:/i.test(str)) {
@@ -74,7 +73,7 @@ const normalizeUrl = (str, isString) => {
74
73
  // Convert `url('%2E/img.png')` -> `url('./img.png')`
75
74
  try {
76
75
  str = decodeURIComponent(str);
77
- } catch (error) {
76
+ } catch (_err) {
78
77
  // Ignore
79
78
  }
80
79
  }
@@ -172,7 +171,7 @@ class CssParser extends Parser {
172
171
  } else if (typeof source === "object") {
173
172
  throw new Error("webpackAst is unexpected for the CssParser");
174
173
  }
175
- if (source[0] === "\ufeff") {
174
+ if (source[0] === "\uFEFF") {
176
175
  source = source.slice(1);
177
176
  }
178
177
 
@@ -193,7 +192,7 @@ class CssParser extends Parser {
193
192
  }
194
193
 
195
194
  const locConverter = new LocConverter(source);
196
- /** @type {Set<string>}*/
195
+ /** @type {Set<string>} */
197
196
  const declaredCssVariables = new Set();
198
197
  /** @type {number} */
199
198
  let scope = CSS_MODE_TOP_LEVEL;
@@ -202,13 +201,13 @@ class CssParser extends Parser {
202
201
  /** @type {boolean} */
203
202
  let allowImportAtRule = true;
204
203
  /** @type {"local" | "global" | undefined} */
205
- let modeData = undefined;
204
+ let modeData;
206
205
  /** @type {[number, number] | undefined} */
207
- let lastIdentifier = undefined;
206
+ let lastIdentifier;
208
207
  /** @type [string, number, number][] */
209
- let balanced = [];
208
+ const balanced = [];
210
209
  /** @type {undefined | { start: number, url?: string, urlStart?: number, urlEnd?: number, layer?: string, layerStart?: number, layerEnd?: number, supports?: string, supportsStart?: number, supportsEnd?: number, inSupports?:boolean, media?: string }} */
211
- let importData = undefined;
210
+ let importData;
212
211
  /** @type {boolean} */
213
212
  let inAnimationProperty = false;
214
213
  /** @type {boolean} */
@@ -251,7 +250,9 @@ class CssParser extends Parser {
251
250
  { length: charCodes.reduce((a, b) => Math.max(a, b), 0) + 1 },
252
251
  () => false
253
252
  );
254
- charCodes.forEach(cc => (arr[cc] = true));
253
+ for (const cc of charCodes) {
254
+ arr[cc] = true;
255
+ }
255
256
  return (input, pos) => {
256
257
  for (;;) {
257
258
  const cc = input.charCodeAt(pos);
@@ -320,7 +321,7 @@ class CssParser extends Parser {
320
321
  if (input.charCodeAt(pos) === CC_RIGHT_CURLY) break;
321
322
  pos = walkCssTokens.eatWhitespaceAndComments(input, pos);
322
323
  if (pos === input.length) return pos;
323
- let start = pos;
324
+ const start = pos;
324
325
  let name;
325
326
  [pos, name] = eatText(input, pos, eatExportName);
326
327
  if (pos === input.length) return pos;
@@ -424,11 +425,12 @@ class CssParser extends Parser {
424
425
  const eatKeyframes = eatUntil("{};/");
425
426
  const eatNameInVar = eatUntil(",)};/");
426
427
  walkCssTokens(source, {
427
- isSelector: () => {
428
- return isNextRulePrelude;
429
- },
428
+ isSelector: () => isNextRulePrelude,
430
429
  url: (input, start, end, contentStart, contentEnd) => {
431
- let value = normalizeUrl(input.slice(contentStart, contentEnd), false);
430
+ const value = normalizeUrl(
431
+ input.slice(contentStart, contentEnd),
432
+ false
433
+ );
432
434
 
433
435
  switch (scope) {
434
436
  case CSS_MODE_IN_AT_IMPORT: {
@@ -530,7 +532,7 @@ class CssParser extends Parser {
530
532
  (last[0].replace(/\\/g, "").toLowerCase() === "url" ||
531
533
  IMAGE_SET_FUNCTION.test(last[0].replace(/\\/g, "")))
532
534
  ) {
533
- let value = normalizeUrl(input.slice(start + 1, end - 1), true);
535
+ const value = normalizeUrl(input.slice(start + 1, end - 1), true);
534
536
 
535
537
  // Ignore `url()`, `url('')` and `url("")`, they are valid by spec
536
538
  if (value.length === 0) {
@@ -884,7 +886,7 @@ class CssParser extends Parser {
884
886
  }
885
887
 
886
888
  if (name === "var") {
887
- let pos = walkCssTokens.eatWhitespaceAndComments(input, end);
889
+ const pos = walkCssTokens.eatWhitespaceAndComments(input, end);
888
890
  if (pos === input.length) return pos;
889
891
  const [newPos, name] = eatText(input, pos, eatNameInVar);
890
892
  if (!name.startsWith("--")) return end;