webpack 5.90.2 → 5.91.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 (182) hide show
  1. package/README.md +5 -5
  2. package/bin/webpack.js +5 -1
  3. package/lib/APIPlugin.js +8 -4
  4. package/lib/AutomaticPrefetchPlugin.js +1 -1
  5. package/lib/BannerPlugin.js +3 -1
  6. package/lib/Cache.js +7 -1
  7. package/lib/CacheFacade.js +3 -3
  8. package/lib/ChunkGraph.js +32 -18
  9. package/lib/ChunkGroup.js +14 -14
  10. package/lib/CleanPlugin.js +7 -5
  11. package/lib/Compilation.js +263 -94
  12. package/lib/Compiler.js +199 -83
  13. package/lib/ConditionalInitFragment.js +4 -5
  14. package/lib/ContextModule.js +4 -1
  15. package/lib/ContextModuleFactory.js +4 -2
  16. package/lib/ContextReplacementPlugin.js +3 -2
  17. package/lib/CssModule.js +0 -3
  18. package/lib/DefinePlugin.js +4 -2
  19. package/lib/DelegatedModule.js +2 -1
  20. package/lib/Dependency.js +4 -2
  21. package/lib/DependencyTemplate.js +7 -2
  22. package/lib/DllModule.js +3 -1
  23. package/lib/DllReferencePlugin.js +6 -2
  24. package/lib/EntryOptionPlugin.js +4 -1
  25. package/lib/EntryPlugin.js +6 -1
  26. package/lib/Entrypoint.js +1 -1
  27. package/lib/ExportsInfo.js +1 -4
  28. package/lib/ExternalModule.js +120 -25
  29. package/lib/ExternalModuleFactoryPlugin.js +37 -2
  30. package/lib/FileSystemInfo.js +1 -1
  31. package/lib/Generator.js +2 -1
  32. package/lib/HookWebpackError.js +2 -2
  33. package/lib/InitFragment.js +5 -3
  34. package/lib/LibManifestPlugin.js +15 -7
  35. package/lib/Module.js +54 -5
  36. package/lib/ModuleFilenameHelpers.js +1 -1
  37. package/lib/ModuleGraph.js +56 -27
  38. package/lib/ModuleGraphConnection.js +2 -1
  39. package/lib/MultiCompiler.js +61 -17
  40. package/lib/NodeStuffPlugin.js +14 -3
  41. package/lib/NormalModule.js +239 -86
  42. package/lib/NormalModuleFactory.js +163 -32
  43. package/lib/NormalModuleReplacementPlugin.js +5 -1
  44. package/lib/ProvidePlugin.js +3 -1
  45. package/lib/RawModule.js +4 -2
  46. package/lib/ResolverFactory.js +5 -1
  47. package/lib/RuntimeModule.js +6 -5
  48. package/lib/RuntimePlugin.js +1 -0
  49. package/lib/RuntimeTemplate.js +102 -34
  50. package/lib/SourceMapDevToolPlugin.js +4 -1
  51. package/lib/Stats.js +12 -5
  52. package/lib/TemplatedPathPlugin.js +32 -6
  53. package/lib/Watching.js +67 -60
  54. package/lib/WebpackError.js +6 -6
  55. package/lib/WebpackOptionsApply.js +18 -5
  56. package/lib/asset/RawDataUrlModule.js +5 -2
  57. package/lib/async-modules/AwaitDependenciesInitFragment.js +2 -2
  58. package/lib/buildChunkGraph.js +220 -392
  59. package/lib/cache/IdleFileCachePlugin.js +8 -3
  60. package/lib/cache/MemoryCachePlugin.js +1 -1
  61. package/lib/cache/MemoryWithGcCachePlugin.js +6 -2
  62. package/lib/cache/PackFileCacheStrategy.js +49 -16
  63. package/lib/cache/ResolverCachePlugin.js +14 -6
  64. package/lib/cache/getLazyHashedEtag.js +1 -1
  65. package/lib/config/defaults.js +24 -1
  66. package/lib/config/normalization.js +3 -1
  67. package/lib/container/ContainerEntryDependency.js +2 -1
  68. package/lib/container/ContainerEntryModule.js +5 -2
  69. package/lib/container/ContainerPlugin.js +14 -10
  70. package/lib/container/FallbackModule.js +3 -2
  71. package/lib/container/RemoteModule.js +2 -1
  72. package/lib/container/RemoteRuntimeModule.js +12 -3
  73. package/lib/css/CssExportsGenerator.js +34 -17
  74. package/lib/css/CssGenerator.js +20 -2
  75. package/lib/css/CssLoadingRuntimeModule.js +212 -96
  76. package/lib/css/CssModulesPlugin.js +47 -13
  77. package/lib/debug/ProfilingPlugin.js +27 -2
  78. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +9 -5
  79. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +4 -1
  80. package/lib/dependencies/CommonJsDependencyHelpers.js +2 -1
  81. package/lib/dependencies/CommonJsExportRequireDependency.js +33 -18
  82. package/lib/dependencies/CommonJsExportsDependency.js +13 -5
  83. package/lib/dependencies/CommonJsExportsParserPlugin.js +20 -15
  84. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -2
  85. package/lib/dependencies/ContextDependencyHelpers.js +49 -29
  86. package/lib/dependencies/ContextElementDependency.js +8 -1
  87. package/lib/dependencies/CssLocalIdentifierDependency.js +63 -8
  88. package/lib/dependencies/CssUrlDependency.js +5 -3
  89. package/lib/dependencies/ExportsInfoDependency.js +4 -3
  90. package/lib/dependencies/ExternalModuleInitFragment.js +5 -3
  91. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +4 -4
  92. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +43 -23
  93. package/lib/dependencies/HarmonyExportHeaderDependency.js +1 -1
  94. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +73 -32
  95. package/lib/dependencies/HarmonyExportInitFragment.js +10 -2
  96. package/lib/dependencies/HarmonyImportDependency.js +28 -12
  97. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +44 -16
  98. package/lib/dependencies/HarmonyImportSideEffectDependency.js +7 -6
  99. package/lib/dependencies/HarmonyImportSpecifierDependency.js +21 -10
  100. package/lib/dependencies/ImportDependency.js +9 -2
  101. package/lib/dependencies/ImportEagerDependency.js +4 -2
  102. package/lib/dependencies/ImportMetaContextDependency.js +7 -0
  103. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +25 -14
  104. package/lib/dependencies/ImportParserPlugin.js +12 -4
  105. package/lib/dependencies/ImportWeakDependency.js +4 -2
  106. package/lib/dependencies/LoaderDependency.js +2 -1
  107. package/lib/dependencies/LoaderImportDependency.js +2 -1
  108. package/lib/dependencies/ModuleDependency.js +4 -5
  109. package/lib/dependencies/PureExpressionDependency.js +4 -1
  110. package/lib/dependencies/RequireContextPlugin.js +1 -1
  111. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +26 -14
  112. package/lib/dependencies/RequireEnsureDependency.js +1 -1
  113. package/lib/dependencies/URLDependency.js +7 -4
  114. package/lib/dependencies/WorkerDependency.js +1 -1
  115. package/lib/dependencies/WorkerPlugin.js +6 -5
  116. package/lib/dependencies/getFunctionExpression.js +3 -1
  117. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +2 -1
  118. package/lib/hmr/LazyCompilationPlugin.js +2 -1
  119. package/lib/javascript/BasicEvaluatedExpression.js +2 -2
  120. package/lib/javascript/ChunkHelpers.js +2 -2
  121. package/lib/javascript/JavascriptParser.js +169 -57
  122. package/lib/javascript/JavascriptParserHelpers.js +1 -1
  123. package/lib/javascript/StartupHelpers.js +22 -5
  124. package/lib/logging/Logger.js +27 -2
  125. package/lib/logging/createConsoleLogger.js +11 -7
  126. package/lib/node/NodeEnvironmentPlugin.js +13 -7
  127. package/lib/node/NodeWatchFileSystem.js +37 -26
  128. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +2 -1
  129. package/lib/node/RequireChunkLoadingRuntimeModule.js +2 -1
  130. package/lib/node/nodeConsole.js +24 -1
  131. package/lib/optimize/AggressiveSplittingPlugin.js +1 -0
  132. package/lib/optimize/ConcatenatedModule.js +140 -55
  133. package/lib/optimize/EnsureChunkConditionsPlugin.js +1 -1
  134. package/lib/optimize/InnerGraph.js +7 -2
  135. package/lib/optimize/InnerGraphPlugin.js +36 -13
  136. package/lib/optimize/ModuleConcatenationPlugin.js +12 -2
  137. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  138. package/lib/optimize/RuntimeChunkPlugin.js +6 -1
  139. package/lib/optimize/SideEffectsFlagPlugin.js +46 -15
  140. package/lib/optimize/SplitChunksPlugin.js +2 -2
  141. package/lib/performance/SizeLimitsPlugin.js +11 -0
  142. package/lib/rules/ObjectMatcherRulePlugin.js +4 -0
  143. package/lib/runtime/EnsureChunkRuntimeModule.js +2 -1
  144. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +2 -1
  145. package/lib/serialization/FileMiddleware.js +1 -0
  146. package/lib/serialization/ObjectMiddleware.js +2 -0
  147. package/lib/serialization/Serializer.js +19 -0
  148. package/lib/sharing/ConsumeSharedModule.js +3 -2
  149. package/lib/sharing/ConsumeSharedPlugin.js +17 -3
  150. package/lib/sharing/ConsumeSharedRuntimeModule.js +9 -2
  151. package/lib/sharing/ProvideSharedModule.js +2 -1
  152. package/lib/sharing/ProvideSharedPlugin.js +12 -5
  153. package/lib/sharing/resolveMatchedConfigs.js +2 -2
  154. package/lib/sharing/utils.js +13 -6
  155. package/lib/util/StackedCacheMap.js +26 -0
  156. package/lib/util/WeakTupleMap.js +57 -13
  157. package/lib/util/cleverMerge.js +24 -11
  158. package/lib/util/comparators.js +34 -14
  159. package/lib/util/conventions.js +129 -0
  160. package/lib/util/fs.js +379 -65
  161. package/lib/util/hash/BatchedHash.js +3 -0
  162. package/lib/util/hash/xxhash64.js +2 -2
  163. package/lib/util/memoize.js +2 -0
  164. package/lib/util/runtime.js +1 -1
  165. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -2
  166. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +15 -6
  167. package/lib/wasm-sync/WebAssemblyGenerator.js +27 -6
  168. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +2 -1
  169. package/lib/wasm-sync/WebAssemblyParser.js +7 -4
  170. package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -1
  171. package/lib/webpack.js +11 -5
  172. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +2 -1
  173. package/package.json +25 -26
  174. package/schemas/WebpackOptions.check.js +1 -1
  175. package/schemas/WebpackOptions.json +69 -8
  176. package/schemas/plugins/BannerPlugin.check.js +1 -1
  177. package/schemas/plugins/BannerPlugin.json +5 -1
  178. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
  179. package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
  180. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
  181. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  182. package/types.d.ts +1772 -673
@@ -9,12 +9,13 @@ const Cache = require("../Cache");
9
9
  const ProgressPlugin = require("../ProgressPlugin");
10
10
 
11
11
  /** @typedef {import("../Compiler")} Compiler */
12
+ /** @typedef {import("./PackFileCacheStrategy")} PackFileCacheStrategy */
12
13
 
13
14
  const BUILD_DEPENDENCIES_KEY = Symbol();
14
15
 
15
16
  class IdleFileCachePlugin {
16
17
  /**
17
- * @param {TODO} strategy cache strategy
18
+ * @param {PackFileCacheStrategy} strategy cache strategy
18
19
  * @param {number} idleTimeout timeout
19
20
  * @param {number} idleTimeoutForInitialStore initial timeout
20
21
  * @param {number} idleTimeoutAfterLargeChanges timeout after changes
@@ -93,7 +94,9 @@ class IdleFileCachePlugin {
93
94
  { name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK },
94
95
  dependencies => {
95
96
  pendingIdleTasks.set(BUILD_DEPENDENCIES_KEY, () =>
96
- strategy.storeBuildDependencies(dependencies)
97
+ Promise.resolve().then(() =>
98
+ strategy.storeBuildDependencies(dependencies)
99
+ )
97
100
  );
98
101
  }
99
102
  );
@@ -227,7 +230,9 @@ class IdleFileCachePlugin {
227
230
  compiler.hooks.done.tap("IdleFileCachePlugin", stats => {
228
231
  // 10% build overhead is ignored, as it's not cacheable
229
232
  timeSpendInBuild *= 0.9;
230
- timeSpendInBuild += stats.endTime - stats.startTime;
233
+ timeSpendInBuild +=
234
+ /** @type {number} */ (stats.endTime) -
235
+ /** @type {number} */ (stats.startTime);
231
236
  });
232
237
  }
233
238
  }
@@ -19,7 +19,7 @@ class MemoryCachePlugin {
19
19
  * @returns {void}
20
20
  */
21
21
  apply(compiler) {
22
- /** @type {Map<string, { etag: Etag | null, data: any }>} */
22
+ /** @type {Map<string, { etag: Etag | null, data: any } | null>} */
23
23
  const cache = new Map();
24
24
  compiler.cache.hooks.store.tap(
25
25
  { name: "MemoryCachePlugin", stage: Cache.STAGE_MEMORY },
@@ -13,6 +13,10 @@ const Cache = require("../Cache");
13
13
  /** @typedef {import("../Module")} Module */
14
14
 
15
15
  class MemoryWithGcCachePlugin {
16
+ /**
17
+ * @param {Object} options Options
18
+ * @param {number} options.maxGenerations max generations
19
+ */
16
20
  constructor({ maxGenerations }) {
17
21
  this._maxGenerations = maxGenerations;
18
22
  }
@@ -23,9 +27,9 @@ class MemoryWithGcCachePlugin {
23
27
  */
24
28
  apply(compiler) {
25
29
  const maxGenerations = this._maxGenerations;
26
- /** @type {Map<string, { etag: Etag | null, data: any }>} */
30
+ /** @type {Map<string, { etag: Etag | null, data: any } | undefined | null>} */
27
31
  const cache = new Map();
28
- /** @type {Map<string, { entry: { etag: Etag | null, data: any }, until: number }>} */
32
+ /** @type {Map<string, { entry: { etag: Etag | null, data: any } | null, until: number }>} */
29
33
  const oldCache = new Map();
30
34
  let generation = 0;
31
35
  let cachePosition = 0;
@@ -28,13 +28,16 @@ const {
28
28
  /** @typedef {import("../util/fs").IntermediateFileSystem} IntermediateFileSystem */
29
29
 
30
30
  /** @typedef {Map<string, string | false>} ResolveResults */
31
+ /** @typedef {Set<string>} Items */
32
+ /** @typedef {Set<string>} BuildDependencies */
33
+ /** @typedef {Map<string, PackItemInfo>} ItemInfo */
31
34
 
32
35
  class PackContainer {
33
36
  /**
34
37
  * @param {Object} data stored data
35
38
  * @param {string} version version identifier
36
39
  * @param {Snapshot} buildSnapshot snapshot of all build dependencies
37
- * @param {Set<string>} buildDependencies list of all unresolved build dependencies captured
40
+ * @param {BuildDependencies} buildDependencies list of all unresolved build dependencies captured
38
41
  * @param {ResolveResults} resolveResults result of the resolved build dependencies
39
42
  * @param {Snapshot} resolveBuildDependenciesSnapshot snapshot of the dependencies of the build dependencies resolving
40
43
  */
@@ -54,13 +57,17 @@ class PackContainer {
54
57
  this.resolveBuildDependenciesSnapshot = resolveBuildDependenciesSnapshot;
55
58
  }
56
59
 
60
+ /**
61
+ * @param {ObjectSerializerContext} context context
62
+ */
57
63
  serialize({ write, writeLazy }) {
58
64
  write(this.version);
59
65
  write(this.buildSnapshot);
60
66
  write(this.buildDependencies);
61
67
  write(this.resolveResults);
62
68
  write(this.resolveBuildDependenciesSnapshot);
63
- writeLazy(this.data);
69
+ /** @type {NonNullable<ObjectSerializerContext["writeLazy"]>} */
70
+ (writeLazy)(this.data);
64
71
  }
65
72
 
66
73
  /**
@@ -104,13 +111,17 @@ class PackItemInfo {
104
111
  }
105
112
 
106
113
  class Pack {
114
+ /**
115
+ * @param {Logger} logger a logger
116
+ * @param {number} maxAge max age of cache items
117
+ */
107
118
  constructor(logger, maxAge) {
108
- /** @type {Map<string, PackItemInfo>} */
119
+ /** @type {ItemInfo} */
109
120
  this.itemInfo = new Map();
110
121
  /** @type {(string | undefined)[]} */
111
122
  this.requests = [];
112
123
  this.requestsTimeout = undefined;
113
- /** @type {Map<string, PackItemInfo>} */
124
+ /** @type {ItemInfo} */
114
125
  this.freshContent = new Map();
115
126
  /** @type {(undefined | PackContent)[]} */
116
127
  this.content = [];
@@ -224,12 +235,18 @@ class Pack {
224
235
  return i;
225
236
  }
226
237
 
238
+ /**
239
+ * @private
240
+ * @param {Items} items items
241
+ * @param {Items} usedItems used items
242
+ * @param {number} newLoc new location
243
+ */
227
244
  _gcAndUpdateLocation(items, usedItems, newLoc) {
228
245
  let count = 0;
229
246
  let lastGC;
230
247
  const now = Date.now();
231
248
  for (const identifier of items) {
232
- const info = this.itemInfo.get(identifier);
249
+ const info = /** @type {PackItemInfo} */ (this.itemInfo.get(identifier));
233
250
  if (now - info.lastAccess > this.maxAge) {
234
251
  this.itemInfo.delete(identifier);
235
252
  items.delete(identifier);
@@ -263,7 +280,7 @@ class Pack {
263
280
  const loc = this._findLocation();
264
281
  this.content[loc] = null; // reserve
265
282
  const pack = {
266
- /** @type {Set<string>} */
283
+ /** @type {Items} */
267
284
  items: new Set(),
268
285
  /** @type {Map<string, any>} */
269
286
  map: new Map(),
@@ -372,9 +389,9 @@ class Pack {
372
389
  }
373
390
 
374
391
  // 4. Determine merged items
375
- /** @type {Set<string>} */
392
+ /** @type {Items} */
376
393
  const mergedItems = new Set();
377
- /** @type {Set<string>} */
394
+ /** @type {Items} */
378
395
  const mergedUsedItems = new Set();
379
396
  /** @type {(function(Map<string, any>): Promise<void>)[]} */
380
397
  const addToMergedMap = [];
@@ -544,6 +561,9 @@ class Pack {
544
561
  }
545
562
  }
546
563
 
564
+ /**
565
+ * @param {ObjectSerializerContext} context context
566
+ */
547
567
  serialize({ write, writeSeparate }) {
548
568
  this._persistFreshContent();
549
569
  this._optimizeSmallContent();
@@ -571,6 +591,9 @@ class Pack {
571
591
  write(null); // null as marker of the end of items
572
592
  }
573
593
 
594
+ /**
595
+ * @param {ObjectDeserializerContext & { logger: Logger }} context context
596
+ */
574
597
  deserialize({ read, logger }) {
575
598
  this.logger = logger;
576
599
  {
@@ -629,6 +652,9 @@ class PackContentItems {
629
652
  this.map = map;
630
653
  }
631
654
 
655
+ /**
656
+ * @param {ObjectSerializerContext & { snapshot: TODO, rollback: TODO, logger: Logger, profile: boolean | undefined }} context context
657
+ */
632
658
  serialize({ write, snapshot, rollback, logger, profile }) {
633
659
  if (profile) {
634
660
  write(false);
@@ -695,6 +721,9 @@ class PackContentItems {
695
721
  }
696
722
  }
697
723
 
724
+ /**
725
+ * @param {ObjectDeserializerContext & { logger: Logger, profile: boolean | undefined }} context context
726
+ */
698
727
  deserialize({ read, logger, profile }) {
699
728
  if (read()) {
700
729
  this.map = read();
@@ -760,17 +789,17 @@ class PackContent {
760
789
  */
761
790
 
762
791
  /**
763
- * @param {Set<string>} items keys
764
- * @param {Set<string>} usedItems used keys
792
+ * @param {Items} items keys
793
+ * @param {Items} usedItems used keys
765
794
  * @param {PackContentItems | function(): Promise<PackContentItems>} dataOrFn sync or async content
766
795
  * @param {Logger=} logger logger for logging
767
796
  * @param {string=} lazyName name of dataOrFn for logging
768
797
  */
769
798
  constructor(items, usedItems, dataOrFn, logger, lazyName) {
770
799
  this.items = items;
771
- /** @type {function(): Promise<PackContentItems> | PackContentItems} */
800
+ /** @type {(function(): Promise<PackContentItems> | PackContentItems) | undefined} */
772
801
  this.lazy = typeof dataOrFn === "function" ? dataOrFn : undefined;
773
- /** @type {Map<string, any>} */
802
+ /** @type {Map<string, any> | undefined} */
774
803
  this.content = typeof dataOrFn === "function" ? undefined : dataOrFn.map;
775
804
  this.outdated = false;
776
805
  this.used = usedItems;
@@ -778,6 +807,10 @@ class PackContent {
778
807
  this.lazyName = lazyName;
779
808
  }
780
809
 
810
+ /**
811
+ * @param {string} identifier identifier
812
+ * @returns {string | Promise<string>} result
813
+ */
781
814
  get(identifier) {
782
815
  this.used.add(identifier);
783
816
  if (this.content) {
@@ -1049,7 +1082,7 @@ class PackFileCacheStrategy {
1049
1082
  ? ".pack.gz"
1050
1083
  : ".pack";
1051
1084
  this.snapshot = snapshot;
1052
- /** @type {Set<string>} */
1085
+ /** @type {BuildDependencies} */
1053
1086
  this.buildDependencies = new Set();
1054
1087
  /** @type {LazySet<string>} */
1055
1088
  this.newBuildDependencies = new LazySet();
@@ -1081,9 +1114,9 @@ class PackFileCacheStrategy {
1081
1114
  const { logger, profile, cacheLocation, version } = this;
1082
1115
  /** @type {Snapshot} */
1083
1116
  let buildSnapshot;
1084
- /** @type {Set<string>} */
1117
+ /** @type {BuildDependencies} */
1085
1118
  let buildDependencies;
1086
- /** @type {Set<string>} */
1119
+ /** @type {BuildDependencies} */
1087
1120
  let newBuildDependencies;
1088
1121
  /** @type {Snapshot} */
1089
1122
  let resolveBuildDependenciesSnapshot;
@@ -1272,7 +1305,7 @@ class PackFileCacheStrategy {
1272
1305
  }
1273
1306
 
1274
1307
  /**
1275
- * @param {LazySet<string>} dependencies dependencies to store
1308
+ * @param {LazySet<string> | Iterable<string>} dependencies dependencies to store
1276
1309
  */
1277
1310
  storeBuildDependencies(dependencies) {
1278
1311
  if (this.readonly) return;
@@ -8,7 +8,7 @@
8
8
  const LazySet = require("../util/LazySet");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
10
 
11
- /** @typedef {import("enhanced-resolve/lib/Resolver")} Resolver */
11
+ /** @typedef {import("enhanced-resolve").Resolver} Resolver */
12
12
  /** @typedef {import("../CacheFacade").ItemCacheFacade} ItemCacheFacade */
13
13
  /** @typedef {import("../Compiler")} Compiler */
14
14
  /** @typedef {import("../FileSystemInfo")} FileSystemInfo */
@@ -213,7 +213,10 @@ class ResolverCachePlugin {
213
213
  stage: -100
214
214
  },
215
215
  (request, resolveContext, callback) => {
216
- if (request._ResolverCachePluginCacheMiss || !fileSystemInfo) {
216
+ if (
217
+ /** @type {TODO} */ (request)._ResolverCachePluginCacheMiss ||
218
+ !fileSystemInfo
219
+ ) {
217
220
  return callback();
218
221
  }
219
222
  const withYield = typeof resolveContext.yield === "function";
@@ -225,7 +228,9 @@ class ResolverCachePlugin {
225
228
  const activeRequest = activeRequestsWithYield.get(identifier);
226
229
  if (activeRequest) {
227
230
  activeRequest[0].push(callback);
228
- activeRequest[1].push(resolveContext.yield);
231
+ activeRequest[1].push(
232
+ /** @type {TODO} */ (resolveContext.yield)
233
+ );
229
234
  return;
230
235
  }
231
236
  } else {
@@ -303,19 +308,22 @@ class ResolverCachePlugin {
303
308
  cachedResolves++;
304
309
  if (resolveContext.missingDependencies) {
305
310
  addAllToSet(
306
- resolveContext.missingDependencies,
311
+ /** @type {LazySet<string>} */
312
+ (resolveContext.missingDependencies),
307
313
  snapshot.getMissingIterable()
308
314
  );
309
315
  }
310
316
  if (resolveContext.fileDependencies) {
311
317
  addAllToSet(
312
- resolveContext.fileDependencies,
318
+ /** @type {LazySet<string>} */
319
+ (resolveContext.fileDependencies),
313
320
  snapshot.getFileIterable()
314
321
  );
315
322
  }
316
323
  if (resolveContext.contextDependencies) {
317
324
  addAllToSet(
318
- resolveContext.contextDependencies,
325
+ /** @type {LazySet<string>} */
326
+ (resolveContext.contextDependencies),
319
327
  snapshot.getContextIterable()
320
328
  );
321
329
  }
@@ -47,7 +47,7 @@ const mapObjects = new WeakMap();
47
47
 
48
48
  /**
49
49
  * @param {HashableObject} obj object with updateHash method
50
- * @param {string | HashConstructor} hashFunction the hash function to use
50
+ * @param {(string | HashConstructor)=} hashFunction the hash function to use
51
51
  * @returns {LazyHashedEtag} etag
52
52
  */
53
53
  const getter = (obj, hashFunction = "md4") => {
@@ -472,7 +472,6 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
472
472
  }
473
473
  return [];
474
474
  });
475
- F(snapshot, "unmanagedPaths", () => []);
476
475
  A(snapshot, "immutablePaths", () => {
477
476
  if (process.versions.pnp === "1") {
478
477
  const match =
@@ -494,6 +493,7 @@ const applySnapshotDefaults = (snapshot, { production, futureDefaults }) => {
494
493
  return [];
495
494
  });
496
495
  }
496
+ F(snapshot, "unmanagedPaths", () => []);
497
497
  F(snapshot, "resolveBuildDependencies", () => ({
498
498
  timestamp: true,
499
499
  hash: true
@@ -554,6 +554,7 @@ const applyCssGeneratorOptionsDefaults = (
554
554
  "exportsOnly",
555
555
  !targetProperties || !targetProperties.document
556
556
  );
557
+ D(generatorOptions, "exportsConvention", "as-is");
557
558
  };
558
559
 
559
560
  /**
@@ -641,6 +642,27 @@ const applyModuleDefaults = (
641
642
  (module.generator.css),
642
643
  { targetProperties }
643
644
  );
645
+
646
+ F(module.generator, "css/auto", () => ({}));
647
+ D(
648
+ module.generator["css/auto"],
649
+ "localIdentName",
650
+ "[uniqueName]-[id]-[local]"
651
+ );
652
+
653
+ F(module.generator, "css/module", () => ({}));
654
+ D(
655
+ module.generator["css/module"],
656
+ "localIdentName",
657
+ "[uniqueName]-[id]-[local]"
658
+ );
659
+
660
+ F(module.generator, "css/global", () => ({}));
661
+ D(
662
+ module.generator["css/global"],
663
+ "localIdentName",
664
+ "[uniqueName]-[id]-[local]"
665
+ );
644
666
  }
645
667
 
646
668
  A(module, "defaultRules", () => {
@@ -901,6 +923,7 @@ const applyOutputDefaults = (
901
923
  }
902
924
  return "[id].css";
903
925
  });
926
+ D(output, "cssHeadDataCompression", !development);
904
927
  D(output, "assetModuleFilename", "[hash][ext][query]");
905
928
  D(output, "webassemblyModuleFilename", "[hash].module.wasm");
906
929
  D(output, "compareBeforeEmit", true);
@@ -320,6 +320,7 @@ const getNormalizedWebpackOptions = config => {
320
320
  chunkLoadTimeout: output.chunkLoadTimeout,
321
321
  cssFilename: output.cssFilename,
322
322
  cssChunkFilename: output.cssChunkFilename,
323
+ cssHeadDataCompression: output.cssHeadDataCompression,
323
324
  clean: output.clean,
324
325
  compareBeforeEmit: output.compareBeforeEmit,
325
326
  crossOriginLoading: output.crossOriginLoading,
@@ -446,7 +447,8 @@ const getNormalizedWebpackOptions = config => {
446
447
  hash: module.hash
447
448
  })),
448
449
  immutablePaths: optionalNestedArray(snapshot.immutablePaths, p => [...p]),
449
- managedPaths: optionalNestedArray(snapshot.managedPaths, p => [...p])
450
+ managedPaths: optionalNestedArray(snapshot.managedPaths, p => [...p]),
451
+ unmanagedPaths: optionalNestedArray(snapshot.unmanagedPaths, p => [...p])
450
452
  })),
451
453
  stats: nestedConfig(config.stats, stats => {
452
454
  if (stats === false) {
@@ -9,11 +9,12 @@ const Dependency = require("../Dependency");
9
9
  const makeSerializable = require("../util/makeSerializable");
10
10
 
11
11
  /** @typedef {import("./ContainerEntryModule").ExposeOptions} ExposeOptions */
12
+ /** @typedef {import("./ContainerEntryModule").ExposesList} ExposesList */
12
13
 
13
14
  class ContainerEntryDependency extends Dependency {
14
15
  /**
15
16
  * @param {string} name entry name
16
- * @param {[string, ExposeOptions][]} exposes list of exposed modules
17
+ * @param {ExposesList} exposes list of exposed modules
17
18
  * @param {string} shareScope name of the share scope
18
19
  */
19
20
  constructor(name, exposes, shareScope) {
@@ -23,6 +23,7 @@ const ContainerExposedDependency = require("./ContainerExposedDependency");
23
23
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
24
24
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
25
25
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
26
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
26
27
  /** @typedef {import("../RequestShortener")} RequestShortener */
27
28
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
28
29
  /** @typedef {import("../WebpackError")} WebpackError */
@@ -38,12 +39,14 @@ const ContainerExposedDependency = require("./ContainerExposedDependency");
38
39
  * @property {string} name custom chunk name for the exposed module
39
40
  */
40
41
 
42
+ /** @typedef {[string, ExposeOptions][]} ExposesList */
43
+
41
44
  const SOURCE_TYPES = new Set(["javascript"]);
42
45
 
43
46
  class ContainerEntryModule extends Module {
44
47
  /**
45
48
  * @param {string} name container entry name
46
- * @param {[string, ExposeOptions][]} exposes list of exposed modules
49
+ * @param {ExposesList} exposes list of exposed modules
47
50
  * @param {string} shareScope name of the share scope
48
51
  */
49
52
  constructor(name, exposes, shareScope) {
@@ -54,7 +57,7 @@ class ContainerEntryModule extends Module {
54
57
  }
55
58
 
56
59
  /**
57
- * @returns {Set<string>} types available (do not mutate)
60
+ * @returns {SourceTypes} types available (do not mutate)
58
61
  */
59
62
  getSourceTypes() {
60
63
  return SOURCE_TYPES;
@@ -13,6 +13,8 @@ const { parseOptions } = require("./options");
13
13
 
14
14
  /** @typedef {import("../../declarations/plugins/container/ContainerPlugin").ContainerPluginOptions} ContainerPluginOptions */
15
15
  /** @typedef {import("../Compiler")} Compiler */
16
+ /** @typedef {import("./ContainerEntryModule").ExposeOptions} ExposeOptions */
17
+ /** @typedef {import("./ContainerEntryModule").ExposesList} ExposesList */
16
18
 
17
19
  const validate = createSchemaValidation(
18
20
  require("../../schemas/plugins/container/ContainerPlugin.check.js"),
@@ -41,16 +43,18 @@ class ContainerPlugin {
41
43
  },
42
44
  runtime: options.runtime,
43
45
  filename: options.filename || undefined,
44
- exposes: parseOptions(
45
- options.exposes,
46
- item => ({
47
- import: Array.isArray(item) ? item : [item],
48
- name: undefined
49
- }),
50
- item => ({
51
- import: Array.isArray(item.import) ? item.import : [item.import],
52
- name: item.name || undefined
53
- })
46
+ exposes: /** @type {ExposesList} */ (
47
+ parseOptions(
48
+ options.exposes,
49
+ item => ({
50
+ import: Array.isArray(item) ? item : [item],
51
+ name: undefined
52
+ }),
53
+ item => ({
54
+ import: Array.isArray(item.import) ? item.import : [item.import],
55
+ name: item.name || undefined
56
+ })
57
+ )
54
58
  )
55
59
  };
56
60
  }
@@ -22,6 +22,7 @@ const FallbackItemDependency = require("./FallbackItemDependency");
22
22
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
23
23
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
24
24
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
25
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
25
26
  /** @typedef {import("../RequestShortener")} RequestShortener */
26
27
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
27
28
  /** @typedef {import("../WebpackError")} WebpackError */
@@ -116,7 +117,7 @@ class FallbackModule extends Module {
116
117
  }
117
118
 
118
119
  /**
119
- * @returns {Set<string>} types available (do not mutate)
120
+ * @returns {SourceTypes} types available (do not mutate)
120
121
  */
121
122
  getSourceTypes() {
122
123
  return TYPES;
@@ -128,7 +129,7 @@ class FallbackModule extends Module {
128
129
  */
129
130
  codeGeneration({ runtimeTemplate, moduleGraph, chunkGraph }) {
130
131
  const ids = this.dependencies.map(dep =>
131
- chunkGraph.getModuleId(moduleGraph.getModule(dep))
132
+ chunkGraph.getModuleId(/** @type {Module} */ (moduleGraph.getModule(dep)))
132
133
  );
133
134
  const code = Template.asString([
134
135
  `var ids = ${JSON.stringify(ids)};`,
@@ -21,6 +21,7 @@ const RemoteToExternalDependency = require("./RemoteToExternalDependency");
21
21
  /** @typedef {import("../Module").CodeGenerationResult} CodeGenerationResult */
22
22
  /** @typedef {import("../Module").LibIdentOptions} LibIdentOptions */
23
23
  /** @typedef {import("../Module").NeedBuildContext} NeedBuildContext */
24
+ /** @typedef {import("../Module").SourceTypes} SourceTypes */
24
25
  /** @typedef {import("../RequestShortener")} RequestShortener */
25
26
  /** @typedef {import("../ResolverFactory").ResolverWithOptions} ResolverWithOptions */
26
27
  /** @typedef {import("../WebpackError")} WebpackError */
@@ -119,7 +120,7 @@ class RemoteModule extends Module {
119
120
  }
120
121
 
121
122
  /**
122
- * @returns {Set<string>} types available (do not mutate)
123
+ * @returns {SourceTypes} types available (do not mutate)
123
124
  */
124
125
  getSourceTypes() {
125
126
  return TYPES;
@@ -10,6 +10,9 @@ const RuntimeModule = require("../RuntimeModule");
10
10
  const Template = require("../Template");
11
11
 
12
12
  /** @typedef {import("../Chunk")} Chunk */
13
+ /** @typedef {import("../Chunk").ChunkId} ChunkId */
14
+ /** @typedef {import("../ChunkGraph")} ChunkGraph */
15
+ /** @typedef {import("../Compilation")} Compilation */
13
16
  /** @typedef {import("./RemoteModule")} RemoteModule */
14
17
 
15
18
  class RemoteRuntimeModule extends RuntimeModule {
@@ -21,17 +24,23 @@ class RemoteRuntimeModule extends RuntimeModule {
21
24
  * @returns {string | null} runtime code
22
25
  */
23
26
  generate() {
24
- const { compilation, chunkGraph } = this;
27
+ const compilation = /** @type {Compilation} */ (this.compilation);
28
+ const chunkGraph = /** @type {ChunkGraph} */ (this.chunkGraph);
25
29
  const { runtimeTemplate, moduleGraph } = compilation;
30
+ /** @type {Record<ChunkId, (string | number)[]>} */
26
31
  const chunkToRemotesMapping = {};
32
+ /** @type {Record<string | number, [string, string, string | number | null]>} */
27
33
  const idToExternalAndNameMapping = {};
28
- for (const chunk of this.chunk.getAllAsyncChunks()) {
34
+ for (const chunk of /** @type {Chunk} */ (this.chunk).getAllAsyncChunks()) {
29
35
  const modules = chunkGraph.getChunkModulesIterableBySourceType(
30
36
  chunk,
31
37
  "remote"
32
38
  );
33
39
  if (!modules) continue;
34
- const remotes = (chunkToRemotesMapping[chunk.id] = []);
40
+ /** @type {(string | number)[]} */
41
+ const remotes = (chunkToRemotesMapping[
42
+ /** @type {ChunkId} */ (chunk.id)
43
+ ] = []);
35
44
  for (const m of modules) {
36
45
  const module = /** @type {RemoteModule} */ (m);
37
46
  const name = module.internalRequest;
@@ -10,8 +10,11 @@ const { UsageState } = require("../ExportsInfo");
10
10
  const Generator = require("../Generator");
11
11
  const RuntimeGlobals = require("../RuntimeGlobals");
12
12
  const Template = require("../Template");
13
+ const { cssExportConvention } = require("../util/conventions");
13
14
 
14
15
  /** @typedef {import("webpack-sources").Source} Source */
16
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorExportsConvention} CssGeneratorExportsConvention */
17
+ /** @typedef {import("../../declarations/WebpackOptions").CssGeneratorLocalIdentName} CssGeneratorLocalIdentName */
15
18
  /** @typedef {import("../Dependency")} Dependency */
16
19
  /** @typedef {import("../Generator").GenerateContext} GenerateContext */
17
20
  /** @typedef {import("../Generator").UpdateHashContext} UpdateHashContext */
@@ -27,8 +30,16 @@ const Template = require("../Template");
27
30
  const TYPES = new Set(["javascript"]);
28
31
 
29
32
  class CssExportsGenerator extends Generator {
30
- constructor() {
33
+ /**
34
+ * @param {CssGeneratorExportsConvention} convention the convention of the exports name
35
+ * @param {CssGeneratorLocalIdentName | undefined} localIdentName css export local ident name
36
+ */
37
+ constructor(convention, localIdentName) {
31
38
  super();
39
+ /** @type {CssGeneratorExportsConvention} */
40
+ this.convention = convention;
41
+ /** @type {CssGeneratorLocalIdentName | undefined} */
42
+ this.localIdentName = localIdentName;
32
43
  }
33
44
 
34
45
  // TODO add getConcatenationBailoutReason to allow concatenation
@@ -43,6 +54,7 @@ class CssExportsGenerator extends Generator {
43
54
  const source = new ReplaceSource(new RawSource(""));
44
55
  /** @type {InitFragment<TODO>[]} */
45
56
  const initFragments = [];
57
+ /** @type {Map<string, string>} */
46
58
  const cssExports = new Map();
47
59
 
48
60
  generateContext.runtimeRequirements.add(RuntimeGlobals.module);
@@ -97,19 +109,21 @@ class CssExportsGenerator extends Generator {
97
109
  if (generateContext.concatenationScope) {
98
110
  const source = new ConcatSource();
99
111
  const usedIdentifiers = new Set();
100
- for (const [k, v] of cssExports) {
101
- let identifier = Template.toIdentifier(k);
102
- let i = 0;
103
- while (usedIdentifiers.has(identifier)) {
104
- identifier = Template.toIdentifier(k + i);
112
+ for (const [name, v] of cssExports) {
113
+ for (let k of cssExportConvention(name, this.convention)) {
114
+ let identifier = Template.toIdentifier(k);
115
+ let i = 0;
116
+ while (usedIdentifiers.has(identifier)) {
117
+ identifier = Template.toIdentifier(k + i);
118
+ }
119
+ usedIdentifiers.add(identifier);
120
+ generateContext.concatenationScope.registerExport(k, identifier);
121
+ source.add(
122
+ `${
123
+ generateContext.runtimeTemplate.supportsConst() ? "const" : "var"
124
+ } ${identifier} = ${JSON.stringify(v)};\n`
125
+ );
105
126
  }
106
- usedIdentifiers.add(identifier);
107
- generateContext.concatenationScope.registerExport(k, identifier);
108
- source.add(
109
- `${
110
- generateContext.runtimeTemplate.supportsConst ? "const" : "var"
111
- } ${identifier} = ${JSON.stringify(v)};\n`
112
- );
113
127
  }
114
128
  return source;
115
129
  } else {
@@ -123,13 +137,16 @@ class CssExportsGenerator extends Generator {
123
137
  RuntimeGlobals.makeNamespaceObject
124
138
  );
125
139
  }
140
+ const newCssExports = [];
141
+ for (let [k, v] of cssExports) {
142
+ for (let name of cssExportConvention(k, this.convention)) {
143
+ newCssExports.push(`\t${JSON.stringify(name)}: ${JSON.stringify(v)}`);
144
+ }
145
+ }
126
146
  return new RawSource(
127
147
  `${otherUsed ? `${RuntimeGlobals.makeNamespaceObject}(` : ""}${
128
148
  module.moduleArgument
129
- }.exports = {\n${Array.from(
130
- cssExports,
131
- ([k, v]) => `\t${JSON.stringify(k)}: ${JSON.stringify(v)}`
132
- ).join(",\n")}\n}${otherUsed ? ")" : ""};`
149
+ }.exports = {\n${newCssExports.join(",\n")}\n}${otherUsed ? ")" : ""};`
133
150
  );
134
151
  }
135
152
  }