webpack 5.90.3 → 5.92.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (257) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +6 -3
  3. package/lib/APIPlugin.js +14 -6
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +8 -2
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/Chunk.js +7 -4
  9. package/lib/ChunkGraph.js +52 -25
  10. package/lib/ChunkGroup.js +23 -17
  11. package/lib/CleanPlugin.js +8 -6
  12. package/lib/Compilation.js +295 -120
  13. package/lib/Compiler.js +223 -87
  14. package/lib/ConcatenationScope.js +3 -3
  15. package/lib/ConditionalInitFragment.js +4 -5
  16. package/lib/ContextModule.js +95 -41
  17. package/lib/ContextModuleFactory.js +4 -2
  18. package/lib/ContextReplacementPlugin.js +3 -2
  19. package/lib/DefinePlugin.js +18 -6
  20. package/lib/Dependency.js +12 -10
  21. package/lib/DependencyTemplate.js +17 -7
  22. package/lib/DllModule.js +1 -0
  23. package/lib/DllReferencePlugin.js +7 -3
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/EvalDevToolModulePlugin.js +11 -0
  28. package/lib/ExportsInfo.js +23 -8
  29. package/lib/ExternalModule.js +160 -35
  30. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  31. package/lib/FileSystemInfo.js +69 -42
  32. package/lib/FlagDependencyExportsPlugin.js +21 -7
  33. package/lib/Generator.js +4 -4
  34. package/lib/HookWebpackError.js +2 -2
  35. package/lib/HotModuleReplacementPlugin.js +108 -45
  36. package/lib/IgnorePlugin.js +4 -1
  37. package/lib/InitFragment.js +5 -3
  38. package/lib/LibManifestPlugin.js +17 -9
  39. package/lib/Module.js +41 -14
  40. package/lib/ModuleFactory.js +3 -3
  41. package/lib/ModuleFilenameHelpers.js +30 -17
  42. package/lib/ModuleGraph.js +60 -31
  43. package/lib/ModuleGraphConnection.js +2 -1
  44. package/lib/MultiCompiler.js +62 -9
  45. package/lib/NodeStuffPlugin.js +14 -3
  46. package/lib/NormalModule.js +13 -13
  47. package/lib/NormalModuleFactory.js +18 -9
  48. package/lib/NormalModuleReplacementPlugin.js +5 -1
  49. package/lib/Parser.js +1 -1
  50. package/lib/PlatformPlugin.js +39 -0
  51. package/lib/ProgressPlugin.js +1 -1
  52. package/lib/ProvidePlugin.js +3 -1
  53. package/lib/RawModule.js +2 -1
  54. package/lib/RecordIdsPlugin.js +4 -4
  55. package/lib/ResolverFactory.js +6 -4
  56. package/lib/RuntimeModule.js +4 -4
  57. package/lib/RuntimePlugin.js +1 -0
  58. package/lib/RuntimeTemplate.js +124 -52
  59. package/lib/SourceMapDevToolPlugin.js +4 -1
  60. package/lib/Stats.js +11 -4
  61. package/lib/Template.js +5 -5
  62. package/lib/TemplatedPathPlugin.js +48 -7
  63. package/lib/Watching.js +67 -60
  64. package/lib/WebpackError.js +6 -6
  65. package/lib/WebpackOptionsApply.js +18 -5
  66. package/lib/asset/AssetGenerator.js +15 -0
  67. package/lib/asset/RawDataUrlModule.js +3 -1
  68. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  69. package/lib/buildChunkGraph.js +120 -67
  70. package/lib/cache/IdleFileCachePlugin.js +8 -3
  71. package/lib/cache/MemoryCachePlugin.js +1 -1
  72. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  73. package/lib/cache/PackFileCacheStrategy.js +51 -18
  74. package/lib/cache/ResolverCachePlugin.js +22 -14
  75. package/lib/cache/getLazyHashedEtag.js +2 -2
  76. package/lib/cli.js +5 -5
  77. package/lib/config/browserslistTargetHandler.js +7 -1
  78. package/lib/config/defaults.js +108 -34
  79. package/lib/config/normalization.js +3 -1
  80. package/lib/config/target.js +18 -11
  81. package/lib/container/ContainerEntryDependency.js +2 -1
  82. package/lib/container/ContainerEntryModule.js +4 -2
  83. package/lib/container/ContainerPlugin.js +14 -10
  84. package/lib/container/FallbackModule.js +1 -1
  85. package/lib/container/RemoteRuntimeModule.js +12 -3
  86. package/lib/css/CssExportsGenerator.js +68 -25
  87. package/lib/css/CssGenerator.js +34 -6
  88. package/lib/css/CssLoadingRuntimeModule.js +217 -98
  89. package/lib/css/CssModulesPlugin.js +238 -107
  90. package/lib/css/CssParser.js +24 -15
  91. package/lib/css/walkCssTokens.js +1 -1
  92. package/lib/debug/ProfilingPlugin.js +28 -3
  93. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  94. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  95. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  96. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  97. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  98. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  99. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  100. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  101. package/lib/dependencies/ContextElementDependency.js +8 -1
  102. package/lib/dependencies/CssExportDependency.js +2 -2
  103. package/lib/dependencies/CssLocalIdentifierDependency.js +71 -9
  104. package/lib/dependencies/CssUrlDependency.js +10 -7
  105. package/lib/dependencies/ExportsInfoDependency.js +5 -4
  106. package/lib/dependencies/ExternalModuleDependency.js +4 -2
  107. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  108. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  109. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  110. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  111. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  112. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  113. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  114. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +70 -19
  115. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  116. package/lib/dependencies/HarmonyImportSpecifierDependency.js +47 -35
  117. package/lib/dependencies/ImportDependency.js +9 -2
  118. package/lib/dependencies/ImportEagerDependency.js +4 -2
  119. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  120. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  121. package/lib/dependencies/ImportMetaPlugin.js +1 -1
  122. package/lib/dependencies/ImportParserPlugin.js +15 -5
  123. package/lib/dependencies/ImportWeakDependency.js +4 -2
  124. package/lib/dependencies/LoaderDependency.js +2 -1
  125. package/lib/dependencies/LoaderImportDependency.js +2 -1
  126. package/lib/dependencies/LoaderPlugin.js +2 -2
  127. package/lib/dependencies/ModuleDependency.js +4 -5
  128. package/lib/dependencies/PureExpressionDependency.js +64 -47
  129. package/lib/dependencies/RequireContextPlugin.js +1 -1
  130. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  131. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  132. package/lib/dependencies/URLDependency.js +7 -4
  133. package/lib/dependencies/WorkerDependency.js +1 -1
  134. package/lib/dependencies/WorkerPlugin.js +2 -1
  135. package/lib/dependencies/getFunctionExpression.js +3 -1
  136. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -3
  137. package/lib/hmr/LazyCompilationPlugin.js +2 -2
  138. package/lib/ids/ChunkModuleIdRangePlugin.js +1 -1
  139. package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
  140. package/lib/ids/DeterministicModuleIdsPlugin.js +1 -1
  141. package/lib/ids/IdHelpers.js +6 -6
  142. package/lib/ids/NamedChunkIdsPlugin.js +1 -1
  143. package/lib/ids/NamedModuleIdsPlugin.js +1 -1
  144. package/lib/ids/SyncModuleIdsPlugin.js +2 -2
  145. package/lib/index.js +11 -0
  146. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  147. package/lib/javascript/ChunkHelpers.js +2 -2
  148. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  149. package/lib/javascript/JavascriptGenerator.js +0 -1
  150. package/lib/javascript/JavascriptModulesPlugin.js +174 -17
  151. package/lib/javascript/JavascriptParser.js +204 -71
  152. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  153. package/lib/javascript/StartupHelpers.js +22 -5
  154. package/lib/library/AbstractLibraryPlugin.js +2 -2
  155. package/lib/library/AmdLibraryPlugin.js +2 -2
  156. package/lib/library/AssignLibraryPlugin.js +3 -3
  157. package/lib/library/ExportPropertyLibraryPlugin.js +2 -2
  158. package/lib/library/JsonpLibraryPlugin.js +2 -2
  159. package/lib/library/ModuleLibraryPlugin.js +2 -2
  160. package/lib/library/SystemLibraryPlugin.js +2 -2
  161. package/lib/library/UmdLibraryPlugin.js +33 -12
  162. package/lib/logging/Logger.js +27 -2
  163. package/lib/logging/createConsoleLogger.js +13 -9
  164. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -1
  165. package/lib/node/NodeEnvironmentPlugin.js +14 -8
  166. package/lib/node/NodeTemplatePlugin.js +1 -1
  167. package/lib/node/NodeWatchFileSystem.js +37 -26
  168. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  169. package/lib/node/ReadFileCompileWasmPlugin.js +1 -1
  170. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/node/nodeConsole.js +24 -1
  172. package/lib/optimize/AggressiveMergingPlugin.js +1 -1
  173. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  174. package/lib/optimize/ConcatenatedModule.js +140 -121
  175. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  176. package/lib/optimize/InnerGraph.js +8 -3
  177. package/lib/optimize/InnerGraphPlugin.js +36 -13
  178. package/lib/optimize/LimitChunkCountPlugin.js +1 -2
  179. package/lib/optimize/ModuleConcatenationPlugin.js +13 -3
  180. package/lib/optimize/RealContentHashPlugin.js +3 -3
  181. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  182. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  183. package/lib/optimize/SideEffectsFlagPlugin.js +48 -17
  184. package/lib/optimize/SplitChunksPlugin.js +10 -10
  185. package/lib/performance/SizeLimitsPlugin.js +13 -2
  186. package/lib/rules/ObjectMatcherRulePlugin.js +15 -1
  187. package/lib/rules/RuleSetCompiler.js +9 -7
  188. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  189. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  190. package/lib/runtime/LoadScriptRuntimeModule.js +1 -1
  191. package/lib/runtime/StartupChunkDependenciesPlugin.js +1 -1
  192. package/lib/schemes/HttpUriPlugin.js +1 -1
  193. package/lib/serialization/BinaryMiddleware.js +4 -4
  194. package/lib/serialization/FileMiddleware.js +4 -3
  195. package/lib/serialization/NullPrototypeObjectSerializer.js +2 -2
  196. package/lib/serialization/ObjectMiddleware.js +8 -5
  197. package/lib/serialization/PlainObjectSerializer.js +2 -2
  198. package/lib/serialization/Serializer.js +19 -0
  199. package/lib/serialization/SerializerMiddleware.js +2 -2
  200. package/lib/serialization/SingleItemMiddleware.js +2 -2
  201. package/lib/serialization/types.js +1 -1
  202. package/lib/sharing/ConsumeSharedModule.js +2 -2
  203. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  204. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  205. package/lib/sharing/ProvideSharedPlugin.js +13 -6
  206. package/lib/sharing/resolveMatchedConfigs.js +3 -3
  207. package/lib/sharing/utils.js +13 -6
  208. package/lib/stats/DefaultStatsFactoryPlugin.js +20 -20
  209. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  210. package/lib/stats/StatsFactory.js +2 -2
  211. package/lib/stats/StatsPrinter.js +6 -6
  212. package/lib/util/ArrayQueue.js +14 -21
  213. package/lib/util/AsyncQueue.js +1 -1
  214. package/lib/util/Queue.js +8 -2
  215. package/lib/util/SortableSet.js +16 -4
  216. package/lib/util/StackedCacheMap.js +26 -0
  217. package/lib/util/TupleQueue.js +8 -2
  218. package/lib/util/WeakTupleMap.js +57 -13
  219. package/lib/util/binarySearchBounds.js +1 -1
  220. package/lib/util/cleverMerge.js +26 -13
  221. package/lib/util/comparators.js +37 -15
  222. package/lib/util/conventions.js +129 -0
  223. package/lib/util/createHash.js +3 -5
  224. package/lib/util/deprecation.js +3 -3
  225. package/lib/util/deterministicGrouping.js +2 -2
  226. package/lib/util/findGraphRoots.js +1 -1
  227. package/lib/util/fs.js +383 -69
  228. package/lib/util/hash/BatchedHash.js +3 -0
  229. package/lib/util/hash/xxhash64.js +2 -2
  230. package/lib/util/identifier.js +5 -5
  231. package/lib/util/mergeScope.js +79 -0
  232. package/lib/util/runtime.js +2 -17
  233. package/lib/util/semver.js +3 -0
  234. package/lib/util/smartGrouping.js +3 -3
  235. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +4 -2
  236. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
  237. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  238. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +3 -3
  239. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +16 -7
  240. package/lib/wasm-sync/WebAssemblyGenerator.js +40 -19
  241. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
  242. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  243. package/lib/wasm-sync/WebAssemblyUtils.js +2 -1
  244. package/lib/web/FetchCompileWasmPlugin.js +1 -1
  245. package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -2
  246. package/lib/webpack.js +19 -6
  247. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  248. package/package.json +40 -39
  249. package/schemas/WebpackOptions.check.js +1 -1
  250. package/schemas/WebpackOptions.json +97 -8
  251. package/schemas/plugins/BannerPlugin.check.js +1 -1
  252. package/schemas/plugins/BannerPlugin.json +5 -1
  253. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  254. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  255. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  256. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  257. package/types.d.ts +1826 -639
@@ -5,7 +5,12 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { ConcatSource, PrefixSource } = require("webpack-sources");
8
+ const {
9
+ ConcatSource,
10
+ PrefixSource,
11
+ ReplaceSource,
12
+ CachedSource
13
+ } = require("webpack-sources");
9
14
  const CssModule = require("../CssModule");
10
15
  const HotUpdateChunk = require("../HotUpdateChunk");
11
16
  const {
@@ -26,6 +31,7 @@ const StaticExportsDependency = require("../dependencies/StaticExportsDependency
26
31
  const { compareModulesByIdentifier } = require("../util/comparators");
27
32
  const createSchemaValidation = require("../util/create-schema-validation");
28
33
  const createHash = require("../util/createHash");
34
+ const { getUndoPath } = require("../util/identifier");
29
35
  const memoize = require("../util/memoize");
30
36
  const nonNumericOnlyHash = require("../util/nonNumericOnlyHash");
31
37
  const CssExportsGenerator = require("./CssExportsGenerator");
@@ -39,6 +45,8 @@ const CssParser = require("./CssParser");
39
45
  /** @typedef {import("../CodeGenerationResults")} CodeGenerationResults */
40
46
  /** @typedef {import("../Compilation")} Compilation */
41
47
  /** @typedef {import("../Compiler")} Compiler */
48
+ /** @typedef {import("../CssModule").Inheritance} Inheritance */
49
+ /** @typedef {import("../DependencyTemplate").CssExportsData} CssExportsData */
42
50
  /** @typedef {import("../Module")} Module */
43
51
  /** @typedef {import("../util/memoize")} Memoize */
44
52
 
@@ -128,9 +136,43 @@ const escapeCss = (str, omitOptionalUnderscore) => {
128
136
  : escaped;
129
137
  };
130
138
 
139
+ /**
140
+ * @param {string} str string
141
+ * @returns {string} encoded string
142
+ */
143
+ const LZWEncode = str => {
144
+ /** @type {Map<string, string>} */
145
+ const map = new Map();
146
+ let encoded = "";
147
+ let phrase = str[0];
148
+ let code = 256;
149
+ let maxCode = "\uffff".charCodeAt(0);
150
+ for (let i = 1; i < str.length; i++) {
151
+ const c = str[i];
152
+ if (map.has(phrase + c)) {
153
+ phrase += c;
154
+ } else {
155
+ encoded += phrase.length > 1 ? map.get(phrase) : phrase;
156
+ map.set(phrase + c, String.fromCharCode(code));
157
+ phrase = c;
158
+ if (++code > maxCode) {
159
+ code = 256;
160
+ map.clear();
161
+ }
162
+ }
163
+ }
164
+ encoded += phrase.length > 1 ? map.get(phrase) : phrase;
165
+ return encoded;
166
+ };
167
+
131
168
  const plugin = "CssModulesPlugin";
132
169
 
133
170
  class CssModulesPlugin {
171
+ constructor() {
172
+ /** @type {WeakMap<Source, { undoPath: string, inheritance: Inheritance, source: CachedSource }>} */
173
+ this._moduleCache = new WeakMap();
174
+ }
175
+
134
176
  /**
135
177
  * Apply the plugin
136
178
  * @param {Compiler} compiler the compiler instance
@@ -190,12 +232,12 @@ class CssModulesPlugin {
190
232
  const { namedExports } = parserOptions;
191
233
 
192
234
  switch (type) {
193
- case CSS_MODULE_TYPE:
235
+ case CSS_MODULE_TYPE_GLOBAL:
194
236
  case CSS_MODULE_TYPE_AUTO:
195
237
  return new CssParser({
196
238
  namedExports
197
239
  });
198
- case CSS_MODULE_TYPE_GLOBAL:
240
+ case CSS_MODULE_TYPE:
199
241
  return new CssParser({
200
242
  allowModeSwitch: false,
201
243
  namedExports
@@ -213,8 +255,16 @@ class CssModulesPlugin {
213
255
  validateGeneratorOptions[type](generatorOptions);
214
256
 
215
257
  return generatorOptions.exportsOnly
216
- ? new CssExportsGenerator()
217
- : new CssGenerator();
258
+ ? new CssExportsGenerator(
259
+ generatorOptions.exportsConvention,
260
+ generatorOptions.localIdentName,
261
+ generatorOptions.esModule
262
+ )
263
+ : new CssGenerator(
264
+ generatorOptions.exportsConvention,
265
+ generatorOptions.localIdentName,
266
+ generatorOptions.esModule
267
+ );
218
268
  });
219
269
  normalModuleFactory.hooks.createModuleClass
220
270
  .for(type)
@@ -318,6 +368,23 @@ class CssModulesPlugin {
318
368
 
319
369
  /** @type {CssModule[] | undefined} */
320
370
  const modules = orderedCssModulesPerChunk.get(chunk);
371
+ const { path: filename, info } = compilation.getPathWithInfo(
372
+ CssModulesPlugin.getChunkFilenameTemplate(
373
+ chunk,
374
+ compilation.outputOptions
375
+ ),
376
+ {
377
+ hash,
378
+ runtime: chunk.runtime,
379
+ chunk,
380
+ contentHashType: "css"
381
+ }
382
+ );
383
+ const undoPath = getUndoPath(
384
+ filename,
385
+ compilation.outputOptions.path,
386
+ false
387
+ );
321
388
  if (modules !== undefined) {
322
389
  result.push({
323
390
  render: () =>
@@ -326,18 +393,13 @@ class CssModulesPlugin {
326
393
  chunkGraph,
327
394
  codeGenerationResults,
328
395
  uniqueName: compilation.outputOptions.uniqueName,
396
+ cssHeadDataCompression:
397
+ compilation.outputOptions.cssHeadDataCompression,
398
+ undoPath,
329
399
  modules
330
400
  }),
331
- filenameTemplate: CssModulesPlugin.getChunkFilenameTemplate(
332
- chunk,
333
- compilation.outputOptions
334
- ),
335
- pathOptions: {
336
- hash,
337
- runtime: chunk.runtime,
338
- chunk,
339
- contentHashType: "css"
340
- },
401
+ filename,
402
+ info,
341
403
  identifier: `css${chunk.id}`,
342
404
  hash: chunk.contentHash.css
343
405
  });
@@ -355,7 +417,7 @@ class CssModulesPlugin {
355
417
  options && options.chunkLoading !== undefined
356
418
  ? options.chunkLoading
357
419
  : globalChunkLoading;
358
- return chunkLoading === "jsonp";
420
+ return chunkLoading === "jsonp" || chunkLoading === "import";
359
421
  };
360
422
  const onceForChunkSet = new WeakSet();
361
423
  /**
@@ -468,19 +530,17 @@ class CssModulesPlugin {
468
530
  }
469
531
  if (hasFailed) {
470
532
  // There is a not resolve-able conflict with the selectedModule
471
- if (compilation) {
472
- // TODO print better warning
473
- compilation.warnings.push(
474
- new WebpackError(
475
- `chunk ${chunk.name || chunk.id}\nConflicting order between ${
476
- /** @type {Module} */
477
- (hasFailed).readableIdentifier(compilation.requestShortener)
478
- } and ${selectedModule.readableIdentifier(
479
- compilation.requestShortener
480
- )}`
481
- )
482
- );
483
- }
533
+ // TODO print better warning
534
+ compilation.warnings.push(
535
+ new WebpackError(
536
+ `chunk ${chunk.name || chunk.id}\nConflicting order between ${
537
+ /** @type {Module} */
538
+ (hasFailed).readableIdentifier(compilation.requestShortener)
539
+ } and ${selectedModule.readableIdentifier(
540
+ compilation.requestShortener
541
+ )}`
542
+ )
543
+ );
484
544
  selectedModule = /** @type {Module} */ (hasFailed);
485
545
  }
486
546
  // Insert the selected module into the final modules list
@@ -535,8 +595,143 @@ class CssModulesPlugin {
535
595
  }
536
596
 
537
597
  /**
538
- * @param {Object} options options
598
+ * @param {object} options options
599
+ * @param {string[]} options.metaData meta data
600
+ * @param {string} options.undoPath undo path for public path auto
601
+ * @param {Chunk} options.chunk chunk
602
+ * @param {ChunkGraph} options.chunkGraph chunk graph
603
+ * @param {CodeGenerationResults} options.codeGenerationResults code generation results
604
+ * @param {CssModule} options.module css module
605
+ * @returns {Source} css module source
606
+ */
607
+ renderModule({
608
+ metaData,
609
+ undoPath,
610
+ chunk,
611
+ chunkGraph,
612
+ codeGenerationResults,
613
+ module
614
+ }) {
615
+ const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
616
+ const moduleSourceContent =
617
+ /** @type {Source} */
618
+ (
619
+ codeGenResult.sources.get("css") ||
620
+ codeGenResult.sources.get("css-import")
621
+ );
622
+
623
+ const cacheEntry = this._moduleCache.get(moduleSourceContent);
624
+
625
+ /** @type {Inheritance} */
626
+ let inheritance = [[module.cssLayer, module.supports, module.media]];
627
+ if (module.inheritance) {
628
+ inheritance.push(...module.inheritance);
629
+ }
630
+
631
+ let source;
632
+ if (
633
+ cacheEntry &&
634
+ cacheEntry.undoPath === undoPath &&
635
+ cacheEntry.inheritance.every(([layer, supports, media], i) => {
636
+ const item = inheritance[i];
637
+ if (Array.isArray(item)) {
638
+ return layer === item[0] && supports === item[1] && media === item[2];
639
+ }
640
+ return false;
641
+ })
642
+ ) {
643
+ source = cacheEntry.source;
644
+ } else {
645
+ const moduleSourceCode = /** @type {string} */ (
646
+ moduleSourceContent.source()
647
+ );
648
+ const publicPathAutoRegex = new RegExp(
649
+ CssUrlDependency.PUBLIC_PATH_AUTO,
650
+ "g"
651
+ );
652
+ /** @type {Source} */
653
+ let moduleSource = new ReplaceSource(moduleSourceContent);
654
+ let match;
655
+ while ((match = publicPathAutoRegex.exec(moduleSourceCode))) {
656
+ /** @type {ReplaceSource} */ (moduleSource).replace(
657
+ match.index,
658
+ (match.index += match[0].length - 1),
659
+ undoPath
660
+ );
661
+ }
662
+
663
+ for (let i = 0; i < inheritance.length; i++) {
664
+ const layer = inheritance[i][0];
665
+ const supports = inheritance[i][1];
666
+ const media = inheritance[i][2];
667
+
668
+ if (media) {
669
+ moduleSource = new ConcatSource(
670
+ `@media ${media} {\n`,
671
+ new PrefixSource("\t", moduleSource),
672
+ "}\n"
673
+ );
674
+ }
675
+
676
+ if (supports) {
677
+ moduleSource = new ConcatSource(
678
+ `@supports (${supports}) {\n`,
679
+ new PrefixSource("\t", moduleSource),
680
+ "}\n"
681
+ );
682
+ }
683
+
684
+ // Layer can be anonymous
685
+ if (layer !== undefined && layer !== null) {
686
+ moduleSource = new ConcatSource(
687
+ `@layer${layer ? ` ${layer}` : ""} {\n`,
688
+ new PrefixSource("\t", moduleSource),
689
+ "}\n"
690
+ );
691
+ }
692
+ }
693
+
694
+ if (moduleSource) {
695
+ moduleSource = new ConcatSource(moduleSource, "\n");
696
+ }
697
+
698
+ source = new CachedSource(moduleSource);
699
+ this._moduleCache.set(moduleSourceContent, {
700
+ inheritance,
701
+ undoPath,
702
+ source
703
+ });
704
+ }
705
+ /** @type {CssExportsData | undefined} */
706
+ const cssExportsData =
707
+ codeGenResult.data && codeGenResult.data.get("css-exports");
708
+ const exports = cssExportsData && cssExportsData.exports;
709
+ const esModule = cssExportsData && cssExportsData.esModule;
710
+ let moduleId = chunkGraph.getModuleId(module) + "";
711
+
712
+ // When `optimization.moduleIds` is `named` the module id is a path, so we need to normalize it between platforms
713
+ if (typeof moduleId === "string") {
714
+ moduleId = moduleId.replace(/\\/g, "/");
715
+ }
716
+
717
+ metaData.push(
718
+ `${
719
+ exports
720
+ ? Array.from(
721
+ exports,
722
+ ([n, v]) => `${escapeCss(n)}:${escapeCss(v)}/`
723
+ ).join("")
724
+ : ""
725
+ }${esModule ? "&" : ""}${escapeCss(moduleId)}`
726
+ );
727
+ return source;
728
+ }
729
+
730
+ /**
731
+ * @param {object} options options
539
732
  * @param {string | undefined} options.uniqueName unique name
733
+ * @param {boolean | undefined} options.cssHeadDataCompression compress css head data
734
+ * @param {string} options.undoPath undo path for public path auto
540
735
  * @param {Chunk} options.chunk chunk
541
736
  * @param {ChunkGraph} options.chunkGraph chunk graph
542
737
  * @param {CodeGenerationResults} options.codeGenerationResults code generation results
@@ -545,6 +740,8 @@ class CssModulesPlugin {
545
740
  */
546
741
  renderChunk({
547
742
  uniqueName,
743
+ cssHeadDataCompression,
744
+ undoPath,
548
745
  chunk,
549
746
  chunkGraph,
550
747
  codeGenerationResults,
@@ -555,93 +752,27 @@ class CssModulesPlugin {
555
752
  const metaData = [];
556
753
  for (const module of modules) {
557
754
  try {
558
- const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
559
-
560
- let moduleSource =
561
- /** @type {Source} */
562
- (
563
- codeGenResult.sources.get("css") ||
564
- codeGenResult.sources.get("css-import")
565
- );
566
-
567
- let inheritance = [[module.cssLayer, module.supports, module.media]];
568
-
569
- if (module.inheritance) {
570
- inheritance.push(...module.inheritance);
571
- }
572
-
573
- for (let i = 0; i < inheritance.length; i++) {
574
- const layer = inheritance[i][0];
575
- const supports = inheritance[i][1];
576
- const media = inheritance[i][2];
577
-
578
- if (media) {
579
- moduleSource = new ConcatSource(
580
- `@media ${media} {\n`,
581
- new PrefixSource("\t", moduleSource),
582
- "}\n"
583
- );
584
- }
585
-
586
- if (supports) {
587
- moduleSource = new ConcatSource(
588
- `@supports (${supports}) {\n`,
589
- new PrefixSource("\t", moduleSource),
590
- "}\n"
591
- );
592
- }
593
-
594
- // Layer can be anonymous
595
- if (layer !== undefined && layer !== null) {
596
- moduleSource = new ConcatSource(
597
- `@layer${layer ? ` ${layer}` : ""} {\n`,
598
- new PrefixSource("\t", moduleSource),
599
- "}\n"
600
- );
601
- }
602
- }
603
-
604
- if (moduleSource) {
605
- source.add(moduleSource);
606
- source.add("\n");
607
- }
608
- /** @type {Map<string, string> | undefined} */
609
- const exports =
610
- codeGenResult.data && codeGenResult.data.get("css-exports");
611
- let moduleId = chunkGraph.getModuleId(module) + "";
612
-
613
- // When `optimization.moduleIds` is `named` the module id is a path, so we need to normalize it between platforms
614
- if (typeof moduleId === "string") {
615
- moduleId = moduleId.replace(/\\/g, "/");
616
- }
617
-
618
- metaData.push(
619
- `${
620
- exports
621
- ? Array.from(exports, ([n, v]) => {
622
- const shortcutValue = `${
623
- uniqueName ? uniqueName + "-" : ""
624
- }${moduleId}-${n}`;
625
- return v === shortcutValue
626
- ? `${escapeCss(n)}/`
627
- : v === "--" + shortcutValue
628
- ? `${escapeCss(n)}%`
629
- : `${escapeCss(n)}(${escapeCss(v)})`;
630
- }).join("")
631
- : ""
632
- }${escapeCss(moduleId)}`
633
- );
755
+ const moduleSource = this.renderModule({
756
+ metaData,
757
+ undoPath,
758
+ chunk,
759
+ chunkGraph,
760
+ codeGenerationResults,
761
+ module
762
+ });
763
+ source.add(moduleSource);
634
764
  } catch (e) {
635
765
  /** @type {Error} */
636
766
  (e).message += `\nduring rendering of css ${module.identifier()}`;
637
767
  throw e;
638
768
  }
639
769
  }
770
+ const metaDataStr = metaData.join(",");
640
771
  source.add(
641
772
  `head{--webpack-${escapeCss(
642
773
  (uniqueName ? uniqueName + "-" : "") + chunk.id,
643
774
  true
644
- )}:${metaData.join(",")};}`
775
+ )}:${cssHeadDataCompression ? LZWEncode(metaDataStr) : metaDataStr};}`
645
776
  );
646
777
  return source;
647
778
  }
@@ -600,11 +600,13 @@ class CssParser extends Parser {
600
600
 
601
601
  return newPos;
602
602
  }
603
- const { line: sl, column: sc } = locConverter.get(pos);
604
- const { line: el, column: ec } = locConverter.get(newPos);
605
- const dep = new CssLocalIdentifierDependency(name, [pos, newPos]);
606
- dep.setLoc(sl, sc, el, ec);
607
- module.addDependency(dep);
603
+ if (isLocalMode()) {
604
+ const { line: sl, column: sc } = locConverter.get(pos);
605
+ const { line: el, column: ec } = locConverter.get(newPos);
606
+ const dep = new CssLocalIdentifierDependency(name, [pos, newPos]);
607
+ dep.setLoc(sl, sc, el, ec);
608
+ module.addDependency(dep);
609
+ }
608
610
  pos = newPos;
609
611
  return pos + 1;
610
612
  } else if (this.allowModeSwitch && name === "@property") {
@@ -630,17 +632,19 @@ class CssParser extends Parser {
630
632
 
631
633
  return propertyNameEnd;
632
634
  }
633
- const { line: sl, column: sc } = locConverter.get(pos);
634
- const { line: el, column: ec } = locConverter.get(propertyNameEnd);
635
635
  const name = propertyName.slice(2);
636
- const dep = new CssLocalIdentifierDependency(
637
- name,
638
- [propertyNameStart, propertyNameEnd],
639
- "--"
640
- );
641
- dep.setLoc(sl, sc, el, ec);
642
- module.addDependency(dep);
643
636
  declaredCssVariables.add(name);
637
+ if (isLocalMode()) {
638
+ const { line: sl, column: sc } = locConverter.get(pos);
639
+ const { line: el, column: ec } = locConverter.get(propertyNameEnd);
640
+ const dep = new CssLocalIdentifierDependency(
641
+ name,
642
+ [propertyNameStart, propertyNameEnd],
643
+ "--"
644
+ );
645
+ dep.setLoc(sl, sc, el, ec);
646
+ module.addDependency(dep);
647
+ }
644
648
  pos = propertyNameEnd;
645
649
  return pos + 1;
646
650
  } else if (
@@ -710,7 +714,7 @@ class CssParser extends Parser {
710
714
  }
711
715
 
712
716
  const semicolonPos = end;
713
- end = walkCssTokens.eatWhiteLine(input, end + 1);
717
+ end = walkCssTokens.eatWhiteLine(input, end);
714
718
  const { line: sl, column: sc } = locConverter.get(start);
715
719
  const { line: el, column: ec } = locConverter.get(end);
716
720
  const lastEnd =
@@ -1030,6 +1034,11 @@ class CssParser extends Parser {
1030
1034
 
1031
1035
  module.buildInfo.strict = true;
1032
1036
  module.buildMeta.exportsType = this.namedExports ? "namespace" : "default";
1037
+
1038
+ if (!this.namedExports) {
1039
+ module.buildMeta.defaultObject = "redirect";
1040
+ }
1041
+
1033
1042
  module.addDependency(new StaticExportsDependency([], true));
1034
1043
  return state;
1035
1044
  }
@@ -6,7 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  /**
9
- * @typedef {Object} CssTokenCallbacks
9
+ * @typedef {object} CssTokenCallbacks
10
10
  * @property {function(string, number): boolean=} isSelector
11
11
  * @property {function(string, number, number, number, number): number=} url
12
12
  * @property {function(string, number, number): number=} string
@@ -17,9 +17,15 @@ const createSchemaValidation = require("../util/create-schema-validation");
17
17
  const { dirname, mkdirpSync } = require("../util/fs");
18
18
 
19
19
  /** @typedef {import("../../declarations/plugins/debug/ProfilingPlugin").ProfilingPluginOptions} ProfilingPluginOptions */
20
+ /** @typedef {import("../Compilation")} Compilation */
20
21
  /** @typedef {import("../Compiler")} Compiler */
22
+ /** @typedef {import("../ContextModuleFactory")} ContextModuleFactory */
23
+ /** @typedef {import("../ModuleFactory")} ModuleFactory */
24
+ /** @typedef {import("../NormalModuleFactory")} NormalModuleFactory */
21
25
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
22
26
 
27
+ /** @typedef {TODO} Inspector */
28
+
23
29
  const validate = createSchemaValidation(
24
30
  require("../../schemas/plugins/debug/ProfilingPlugin.check.js"),
25
31
  () => require("../../schemas/plugins/debug/ProfilingPlugin.json"),
@@ -28,6 +34,8 @@ const validate = createSchemaValidation(
28
34
  baseDataPath: "options"
29
35
  }
30
36
  );
37
+
38
+ /** @type {Inspector | undefined} */
31
39
  let inspector = undefined;
32
40
 
33
41
  try {
@@ -38,6 +46,9 @@ try {
38
46
  }
39
47
 
40
48
  class Profiler {
49
+ /**
50
+ * @param {Inspector} inspector inspector
51
+ */
41
52
  constructor(inspector) {
42
53
  this.session = undefined;
43
54
  this.inspector = inspector;
@@ -126,7 +137,7 @@ class Profiler {
126
137
 
127
138
  /**
128
139
  * an object that wraps Tracer and Profiler with a counter
129
- * @typedef {Object} Trace
140
+ * @typedef {object} Trace
130
141
  * @property {Tracer} trace instance of Tracer
131
142
  * @property {number} counter Counter
132
143
  * @property {Profiler} profiler instance of Profiler
@@ -140,7 +151,7 @@ class Profiler {
140
151
  */
141
152
  const createTrace = (fs, outputPath) => {
142
153
  const trace = new Tracer();
143
- const profiler = new Profiler(inspector);
154
+ const profiler = new Profiler(/** @type {Inspector} */ (inspector));
144
155
  if (/\/|\\/.test(outputPath)) {
145
156
  const dirPath = dirname(fs, outputPath);
146
157
  mkdirpSync(fs, dirPath);
@@ -216,7 +227,8 @@ class ProfilingPlugin {
216
227
  */
217
228
  apply(compiler) {
218
229
  const tracer = createTrace(
219
- compiler.intermediateFileSystem,
230
+ /** @type {IntermediateFileSystem} */
231
+ (compiler.intermediateFileSystem),
220
232
  this.outputPath
221
233
  );
222
234
  tracer.profiler.startProfiling();
@@ -320,6 +332,11 @@ class ProfilingPlugin {
320
332
  }
321
333
  }
322
334
 
335
+ /**
336
+ * @param {any} instance instance
337
+ * @param {Trace} tracer tracer
338
+ * @param {string} logLabel log label
339
+ */
323
340
  const interceptAllHooksFor = (instance, tracer, logLabel) => {
324
341
  if (Reflect.has(instance, "hooks")) {
325
342
  Object.keys(instance.hooks).forEach(hookName => {
@@ -331,6 +348,10 @@ const interceptAllHooksFor = (instance, tracer, logLabel) => {
331
348
  }
332
349
  };
333
350
 
351
+ /**
352
+ * @param {NormalModuleFactory} moduleFactory normal module factory
353
+ * @param {Trace} tracer tracer
354
+ */
334
355
  const interceptAllParserHooks = (moduleFactory, tracer) => {
335
356
  const moduleTypes = [
336
357
  JAVASCRIPT_MODULE_TYPE_AUTO,
@@ -350,6 +371,10 @@ const interceptAllParserHooks = (moduleFactory, tracer) => {
350
371
  });
351
372
  };
352
373
 
374
+ /**
375
+ * @param {Compilation} compilation compilation
376
+ * @param {Trace} tracer tracer
377
+ */
353
378
  const interceptAllJavascriptModulesPluginHooks = (compilation, tracer) => {
354
379
  interceptAllHooksFor(
355
380
  {
@@ -103,7 +103,7 @@ class AMDDefineDependencyParserPlugin {
103
103
  /** @type {string} */ (param.string)
104
104
  )
105
105
  )
106
- identifiers[idx] = param.string;
106
+ identifiers[/** @type {number} */ (idx)] = param.string;
107
107
  const result = this.processItem(parser, expr, param, namedModule);
108
108
  if (result === undefined) {
109
109
  this.processContext(parser, expr, param);
@@ -113,7 +113,8 @@ class AMDDefineDependencyParserPlugin {
113
113
  } else if (param.isConstArray()) {
114
114
  /** @type {(string | LocalModuleDependency | AMDRequireItemDependency)[]} */
115
115
  const deps = [];
116
- param.array.forEach((request, idx) => {
116
+ /** @type {string[]} */
117
+ (param.array).forEach((request, idx) => {
117
118
  let dep;
118
119
  let localModule;
119
120
  if (request === "require") {
@@ -151,7 +152,7 @@ class AMDDefineDependencyParserPlugin {
151
152
  * @param {CallExpression} expr call expression
152
153
  * @param {BasicEvaluatedExpression} param param
153
154
  * @param {string=} namedModule named module
154
- * @returns {boolean} result
155
+ * @returns {boolean | undefined} result
155
156
  */
156
157
  processItem(parser, expr, param, namedModule) {
157
158
  if (param.isConditional()) {
@@ -193,7 +194,10 @@ class AMDDefineDependencyParserPlugin {
193
194
  localModule.flagUsed();
194
195
  dep = new LocalModuleDependency(localModule, param.range, false);
195
196
  } else {
196
- dep = this.newRequireItemDependency(param.string, param.range);
197
+ dep = this.newRequireItemDependency(
198
+ /** @type {string} */ (param.string),
199
+ param.range
200
+ );
197
201
  dep.optional = !!parser.scope.inTry;
198
202
  parser.state.current.addDependency(dep);
199
203
  return true;
@@ -377,7 +381,7 @@ class AMDDefineDependencyParserPlugin {
377
381
  for (const [name, varInfo] of fnRenames) {
378
382
  parser.setVariable(name, varInfo);
379
383
  }
380
- parser.scope.inTry = inTry;
384
+ parser.scope.inTry = /** @type {boolean} */ (inTry);
381
385
  if (fn.callee.object.body.type === "BlockStatement") {
382
386
  parser.detectMode(fn.callee.object.body.body);
383
387
  const prev = parser.prevStatement;
@@ -21,6 +21,7 @@ const getFunctionExpression = require("./getFunctionExpression");
21
21
 
22
22
  /** @typedef {import("estree").CallExpression} CallExpression */
23
23
  /** @typedef {import("estree").Expression} Expression */
24
+ /** @typedef {import("estree").Identifier} Identifier */
24
25
  /** @typedef {import("estree").SourceLocation} SourceLocation */
25
26
  /** @typedef {import("estree").SpreadElement} SpreadElement */
26
27
  /** @typedef {import("../../declarations/WebpackOptions").JavascriptParserOptions} JavascriptParserOptions */
@@ -49,7 +50,9 @@ class AMDRequireDependenciesBlockParserPlugin {
49
50
  if (fnData) {
50
51
  parser.inScope(
51
52
  fnData.fn.params.filter(i => {
52
- return !["require", "module", "exports"].includes(i.name);
53
+ return !["require", "module", "exports"].includes(
54
+ /** @type {Identifier} */ (i).name
55
+ );
53
56
  }),
54
57
  () => {
55
58
  if (fnData.fn.body.type === "BlockStatement") {