webpack 5.102.1 → 5.104.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 (220) hide show
  1. package/README.md +121 -134
  2. package/hot/dev-server.js +18 -3
  3. package/hot/emitter-event-target.js +7 -0
  4. package/hot/lazy-compilation-node.js +45 -29
  5. package/hot/lazy-compilation-universal.js +18 -0
  6. package/hot/lazy-compilation-web.js +15 -5
  7. package/hot/load-http.js +7 -0
  8. package/hot/only-dev-server.js +19 -4
  9. package/lib/APIPlugin.js +6 -0
  10. package/lib/Chunk.js +1 -1
  11. package/lib/ChunkGraph.js +9 -7
  12. package/lib/ChunkGroup.js +8 -5
  13. package/lib/CleanPlugin.js +6 -3
  14. package/lib/CodeGenerationResults.js +2 -1
  15. package/lib/CompatibilityPlugin.js +28 -2
  16. package/lib/Compilation.js +58 -21
  17. package/lib/Compiler.js +3 -3
  18. package/lib/ConcatenationScope.js +0 -15
  19. package/lib/ContextModule.js +6 -3
  20. package/lib/ContextModuleFactory.js +6 -4
  21. package/lib/CssModule.js +6 -1
  22. package/lib/DefinePlugin.js +45 -14
  23. package/lib/DelegatedModule.js +7 -4
  24. package/lib/Dependency.js +8 -1
  25. package/lib/DependencyTemplate.js +1 -0
  26. package/lib/DllModule.js +6 -3
  27. package/lib/DotenvPlugin.js +462 -0
  28. package/lib/EnvironmentPlugin.js +19 -16
  29. package/lib/EvalSourceMapDevToolPlugin.js +16 -0
  30. package/lib/ExportsInfo.js +6 -2
  31. package/lib/ExternalModule.js +28 -35
  32. package/lib/ExternalModuleFactoryPlugin.js +11 -9
  33. package/lib/ExternalsPlugin.js +2 -1
  34. package/lib/FileSystemInfo.js +1 -1
  35. package/lib/Generator.js +10 -7
  36. package/lib/HookWebpackError.js +33 -4
  37. package/lib/HotModuleReplacementPlugin.js +22 -0
  38. package/lib/ManifestPlugin.js +235 -0
  39. package/lib/Module.js +27 -15
  40. package/lib/ModuleBuildError.js +1 -1
  41. package/lib/ModuleError.js +1 -1
  42. package/lib/ModuleFilenameHelpers.js +1 -1
  43. package/lib/ModuleGraph.js +29 -13
  44. package/lib/ModuleGraphConnection.js +2 -2
  45. package/lib/ModuleSourceTypeConstants.js +189 -0
  46. package/lib/ModuleTypeConstants.js +1 -4
  47. package/lib/ModuleWarning.js +1 -1
  48. package/lib/MultiCompiler.js +1 -1
  49. package/lib/NodeStuffPlugin.js +424 -116
  50. package/lib/NormalModule.js +23 -20
  51. package/lib/NormalModuleFactory.js +7 -10
  52. package/lib/Parser.js +1 -1
  53. package/lib/RawModule.js +7 -4
  54. package/lib/RuntimeGlobals.js +22 -4
  55. package/lib/RuntimeModule.js +1 -1
  56. package/lib/RuntimePlugin.js +27 -6
  57. package/lib/RuntimeTemplate.js +120 -57
  58. package/lib/SourceMapDevToolPlugin.js +26 -1
  59. package/lib/Template.js +17 -6
  60. package/lib/TemplatedPathPlugin.js +5 -6
  61. package/lib/WebpackError.js +0 -1
  62. package/lib/WebpackOptionsApply.js +67 -15
  63. package/lib/asset/AssetBytesGenerator.js +16 -12
  64. package/lib/asset/AssetGenerator.js +31 -26
  65. package/lib/asset/AssetSourceGenerator.js +16 -12
  66. package/lib/asset/RawDataUrlModule.js +6 -3
  67. package/lib/buildChunkGraph.js +4 -2
  68. package/lib/cache/PackFileCacheStrategy.js +6 -5
  69. package/lib/cli.js +2 -43
  70. package/lib/config/browserslistTargetHandler.js +24 -0
  71. package/lib/config/defaults.js +226 -61
  72. package/lib/config/normalization.js +4 -3
  73. package/lib/config/target.js +11 -0
  74. package/lib/container/ContainerEntryModule.js +6 -3
  75. package/lib/container/FallbackModule.js +6 -3
  76. package/lib/container/RemoteModule.js +1 -3
  77. package/lib/css/CssGenerator.js +304 -76
  78. package/lib/css/CssLoadingRuntimeModule.js +14 -4
  79. package/lib/css/CssMergeStyleSheetsRuntimeModule.js +56 -0
  80. package/lib/css/CssModulesPlugin.js +72 -67
  81. package/lib/css/CssParser.js +1726 -732
  82. package/lib/css/walkCssTokens.js +128 -11
  83. package/lib/dependencies/CachedConstDependency.js +24 -10
  84. package/lib/dependencies/CommonJsImportsParserPlugin.js +0 -9
  85. package/lib/dependencies/CommonJsPlugin.js +12 -0
  86. package/lib/dependencies/CommonJsRequireContextDependency.js +1 -1
  87. package/lib/dependencies/ContextDependencyHelpers.js +2 -2
  88. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +3 -1
  89. package/lib/dependencies/CssIcssExportDependency.js +389 -12
  90. package/lib/dependencies/CssIcssImportDependency.js +114 -51
  91. package/lib/dependencies/CssIcssSymbolDependency.js +31 -33
  92. package/lib/dependencies/CssImportDependency.js +17 -6
  93. package/lib/dependencies/CssUrlDependency.js +3 -2
  94. package/lib/dependencies/DynamicExports.js +7 -7
  95. package/lib/dependencies/ExternalModuleDependency.js +7 -4
  96. package/lib/dependencies/ExternalModuleInitFragment.js +3 -2
  97. package/lib/dependencies/ExternalModuleInitFragmentDependency.js +96 -0
  98. package/lib/dependencies/HarmonyAcceptDependency.js +6 -1
  99. package/lib/dependencies/HarmonyAcceptImportDependency.js +2 -1
  100. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +12 -1
  101. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +35 -23
  102. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +13 -9
  103. package/lib/dependencies/HarmonyExports.js +4 -4
  104. package/lib/dependencies/HarmonyImportDependency.js +28 -27
  105. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +28 -69
  106. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -3
  107. package/lib/dependencies/HarmonyImportSpecifierDependency.js +10 -8
  108. package/lib/dependencies/ImportDependency.js +8 -2
  109. package/lib/dependencies/ImportEagerDependency.js +6 -3
  110. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -1
  111. package/lib/dependencies/ImportMetaPlugin.js +154 -9
  112. package/lib/dependencies/ImportParserPlugin.js +21 -23
  113. package/lib/dependencies/ImportPhase.js +121 -0
  114. package/lib/dependencies/ImportWeakDependency.js +6 -3
  115. package/lib/dependencies/LocalModulesHelpers.js +3 -3
  116. package/lib/dependencies/ModuleDependency.js +5 -1
  117. package/lib/dependencies/ModuleHotAcceptDependency.js +1 -1
  118. package/lib/dependencies/WorkerPlugin.js +2 -2
  119. package/lib/dependencies/getFunctionExpression.js +1 -1
  120. package/lib/esm/ExportWebpackRequireRuntimeModule.js +1 -8
  121. package/lib/esm/ModuleChunkFormatPlugin.js +5 -4
  122. package/lib/hmr/HotModuleReplacement.runtime.js +2 -1
  123. package/lib/hmr/LazyCompilationPlugin.js +5 -3
  124. package/lib/ids/IdHelpers.js +20 -8
  125. package/lib/index.js +6 -0
  126. package/lib/javascript/ChunkHelpers.js +16 -5
  127. package/lib/javascript/JavascriptGenerator.js +105 -104
  128. package/lib/javascript/JavascriptModulesPlugin.js +80 -37
  129. package/lib/javascript/JavascriptParser.js +161 -44
  130. package/lib/json/JsonGenerator.js +5 -4
  131. package/lib/json/JsonParser.js +9 -2
  132. package/lib/library/AbstractLibraryPlugin.js +1 -1
  133. package/lib/library/AmdLibraryPlugin.js +4 -1
  134. package/lib/library/ExportPropertyLibraryPlugin.js +4 -1
  135. package/lib/library/ModuleLibraryPlugin.js +41 -23
  136. package/lib/library/SystemLibraryPlugin.js +8 -1
  137. package/lib/library/UmdLibraryPlugin.js +2 -2
  138. package/lib/logging/Logger.js +5 -4
  139. package/lib/logging/createConsoleLogger.js +2 -2
  140. package/lib/node/NodeTargetPlugin.js +9 -1
  141. package/lib/node/ReadFileCompileWasmPlugin.js +0 -2
  142. package/lib/optimize/ConcatenatedModule.js +208 -167
  143. package/lib/optimize/ModuleConcatenationPlugin.js +5 -4
  144. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  145. package/lib/optimize/SplitChunksPlugin.js +60 -46
  146. package/lib/rules/RuleSetCompiler.js +1 -1
  147. package/lib/runtime/AsyncModuleRuntimeModule.js +28 -18
  148. package/lib/runtime/AutoPublicPathRuntimeModule.js +8 -3
  149. package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -2
  150. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +89 -55
  151. package/lib/schemes/HttpUriPlugin.js +78 -7
  152. package/lib/serialization/AggregateErrorSerializer.js +1 -2
  153. package/lib/serialization/ObjectMiddleware.js +0 -2
  154. package/lib/serialization/SingleItemMiddleware.js +1 -1
  155. package/lib/sharing/ConsumeSharedModule.js +1 -1
  156. package/lib/sharing/ConsumeSharedPlugin.js +5 -3
  157. package/lib/sharing/ProvideSharedModule.js +1 -1
  158. package/lib/sharing/resolveMatchedConfigs.js +15 -9
  159. package/lib/sharing/utils.js +1 -1
  160. package/lib/stats/DefaultStatsFactoryPlugin.js +8 -5
  161. package/lib/stats/DefaultStatsPresetPlugin.js +1 -1
  162. package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
  163. package/lib/util/StringXor.js +1 -1
  164. package/lib/util/URLAbsoluteSpecifier.js +2 -2
  165. package/lib/util/binarySearchBounds.js +2 -2
  166. package/lib/util/comparators.js +54 -76
  167. package/lib/util/compileBooleanMatcher.js +78 -6
  168. package/lib/util/createHash.js +20 -199
  169. package/lib/util/deprecation.js +1 -1
  170. package/lib/util/deterministicGrouping.js +6 -3
  171. package/lib/util/fs.js +75 -75
  172. package/lib/util/hash/BatchedHash.js +10 -9
  173. package/lib/util/hash/BulkUpdateHash.js +138 -0
  174. package/lib/util/hash/DebugHash.js +75 -0
  175. package/lib/util/hash/hash-digest.js +216 -0
  176. package/lib/util/identifier.js +82 -17
  177. package/lib/util/internalSerializables.js +2 -6
  178. package/lib/util/runtime.js +3 -3
  179. package/lib/util/source.js +2 -2
  180. package/lib/wasm/EnableWasmLoadingPlugin.js +10 -4
  181. package/lib/wasm-async/AsyncWebAssemblyGenerator.js +3 -2
  182. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +11 -7
  183. package/lib/wasm-sync/WebAssemblyGenerator.js +9 -6
  184. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +11 -6
  185. package/lib/wasm-sync/WebAssemblyModulesPlugin.js +6 -2
  186. package/lib/web/FetchCompileWasmPlugin.js +0 -2
  187. package/lib/webpack.js +85 -82
  188. package/module.d.ts +5 -0
  189. package/package.json +34 -28
  190. package/schemas/WebpackOptions.check.js +1 -1
  191. package/schemas/WebpackOptions.json +160 -101
  192. package/schemas/plugins/{css/CssAutoParserOptions.check.d.ts → ManifestPlugin.check.d.ts} +1 -1
  193. package/schemas/plugins/ManifestPlugin.check.js +6 -0
  194. package/schemas/plugins/ManifestPlugin.json +98 -0
  195. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  196. package/schemas/plugins/SourceMapDevToolPlugin.json +16 -3
  197. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  198. package/schemas/plugins/container/ContainerReferencePlugin.json +4 -1
  199. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  200. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  201. package/schemas/plugins/container/ModuleFederationPlugin.json +4 -1
  202. package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
  203. package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
  204. package/schemas/plugins/css/CssParserOptions.check.js +1 -1
  205. package/schemas/plugins/json/JsonModulesPluginParser.check.js +1 -1
  206. package/types.d.ts +771 -436
  207. package/lib/ModuleSourceTypesConstants.js +0 -123
  208. package/lib/dependencies/CssLocalIdentifierDependency.js +0 -250
  209. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +0 -112
  210. package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +0 -7
  211. package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +0 -6
  212. package/schemas/plugins/css/CssAutoGeneratorOptions.json +0 -3
  213. package/schemas/plugins/css/CssAutoParserOptions.check.js +0 -6
  214. package/schemas/plugins/css/CssAutoParserOptions.json +0 -3
  215. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +0 -7
  216. package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +0 -6
  217. package/schemas/plugins/css/CssGlobalGeneratorOptions.json +0 -3
  218. package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +0 -7
  219. package/schemas/plugins/css/CssGlobalParserOptions.check.js +0 -6
  220. package/schemas/plugins/css/CssGlobalParserOptions.json +0 -3
@@ -8,7 +8,7 @@
8
8
  const asyncLib = require("neo-async");
9
9
  const ChunkGraph = require("../ChunkGraph");
10
10
  const ModuleGraph = require("../ModuleGraph");
11
- const { JS_TYPE } = require("../ModuleSourceTypesConstants");
11
+ const { JAVASCRIPT_TYPE } = require("../ModuleSourceTypeConstants");
12
12
  const { STAGE_DEFAULT } = require("../OptimizationStages");
13
13
  const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
14
14
  const { compareModulesByIdentifier } = require("../util/comparators");
@@ -460,7 +460,7 @@ class ModuleConcatenationPlugin {
460
460
  chunkGraph.disconnectChunkAndModule(chunk, m);
461
461
  } else {
462
462
  const newSourceTypes = new Set(sourceTypes);
463
- newSourceTypes.delete(JS_TYPE);
463
+ newSourceTypes.delete(JAVASCRIPT_TYPE);
464
464
  chunkGraph.setChunkModuleSourceTypes(
465
465
  chunk,
466
466
  m,
@@ -865,6 +865,7 @@ class ModuleConcatenationPlugin {
865
865
  }
866
866
 
867
867
  /** @typedef {Module | ((requestShortener: RequestShortener) => string)} Problem */
868
+ /** @typedef {Map<Module, Problem>} Warnings */
868
869
 
869
870
  class ConcatConfiguration {
870
871
  /**
@@ -877,7 +878,7 @@ class ConcatConfiguration {
877
878
  /** @type {Set<Module>} */
878
879
  this.modules = new Set();
879
880
  this.modules.add(rootModule);
880
- /** @type {Map<Module, Problem>} */
881
+ /** @type {Warnings} */
881
882
  this.warnings = new Map();
882
883
  }
883
884
 
@@ -909,7 +910,7 @@ class ConcatConfiguration {
909
910
  }
910
911
 
911
912
  /**
912
- * @returns {Map<Module, Problem>} warnings
913
+ * @returns {Warnings} warnings
913
914
  */
914
915
  getWarningsSorted() {
915
916
  return new Map(
@@ -45,7 +45,7 @@ const globToRegexpCache = new WeakMap();
45
45
 
46
46
  /**
47
47
  * @param {string} glob the pattern
48
- * @param {Map<string, RegExp>} cache the glob to RegExp cache
48
+ * @param {CacheItem} cache the glob to RegExp cache
49
49
  * @returns {RegExp} a regular expression
50
50
  */
51
51
  const globToRegexp = (glob, cache) => {
@@ -381,6 +381,7 @@ class SideEffectsFlagPlugin {
381
381
  for (const module of modules) {
382
382
  optimizeIncomingConnections(module);
383
383
  }
384
+ moduleGraph.finishUpdateParent();
384
385
  logger.timeEnd("update dependencies");
385
386
  }
386
387
  );
@@ -391,7 +392,7 @@ class SideEffectsFlagPlugin {
391
392
  /**
392
393
  * @param {string} moduleName the module name
393
394
  * @param {SideEffectsFlagValue} flagValue the flag value
394
- * @param {Map<string, RegExp>} cache cache for glob to regexp
395
+ * @param {CacheItem} cache cache for glob to regexp
395
396
  * @returns {boolean | undefined} true, when the module has side effects, undefined or false when not
396
397
  */
397
398
  static moduleHasSideEffects(moduleName, flagValue, cache) {
@@ -31,6 +31,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
31
31
  /** @typedef {import("../ChunkGroup")} ChunkGroup */
32
32
  /** @typedef {import("../Compiler")} Compiler */
33
33
  /** @typedef {import("../Module")} Module */
34
+ /** @typedef {import("../Module").SourceType} SourceType */
34
35
  /** @typedef {import("../ModuleGraph")} ModuleGraph */
35
36
  /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
36
37
  /** @typedef {import("../util/deterministicGrouping").GroupedItems<Module>} DeterministicGroupingGroupedItemsForModule */
@@ -42,22 +43,26 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
42
43
  * @returns {boolean | undefined}
43
44
  */
44
45
 
46
+ /** @typedef {number} Priority */
47
+ /** @typedef {number} Size */
48
+ /** @typedef {number} CountOfChunk */
49
+ /** @typedef {number} CountOfRequest */
50
+
45
51
  /**
46
52
  * @callback CombineSizeFunction
47
- * @param {number} a
48
- * @param {number} b
49
- * @returns {number}
53
+ * @param {Size} a
54
+ * @param {Size} b
55
+ * @returns {Size}
50
56
  */
51
57
 
52
- /** @typedef {string} SourceType */
53
58
  /** @typedef {SourceType[]} SourceTypes */
54
59
  /** @typedef {SourceType[]} DefaultSizeTypes */
55
- /** @typedef {Record<SourceType, number>} SplitChunksSizes */
60
+ /** @typedef {Record<SourceType, Size>} SplitChunksSizes */
56
61
 
57
62
  /**
58
63
  * @typedef {object} CacheGroupSource
59
64
  * @property {string} key
60
- * @property {number=} priority
65
+ * @property {Priority=} priority
61
66
  * @property {GetNameFn=} getName
62
67
  * @property {ChunkFilterFn=} chunksFilter
63
68
  * @property {boolean=} enforce
@@ -67,9 +72,9 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
67
72
  * @property {SplitChunksSizes} enforceSizeThreshold
68
73
  * @property {SplitChunksSizes} maxAsyncSize
69
74
  * @property {SplitChunksSizes} maxInitialSize
70
- * @property {number=} minChunks
71
- * @property {number=} maxAsyncRequests
72
- * @property {number=} maxInitialRequests
75
+ * @property {CountOfChunk=} minChunks
76
+ * @property {CountOfRequest=} maxAsyncRequests
77
+ * @property {CountOfRequest=} maxInitialRequests
73
78
  * @property {TemplatePath=} filename
74
79
  * @property {string=} idHint
75
80
  * @property {string=} automaticNameDelimiter
@@ -80,7 +85,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
80
85
  /**
81
86
  * @typedef {object} CacheGroup
82
87
  * @property {string} key
83
- * @property {number} priority
88
+ * @property {Priority} priority
84
89
  * @property {GetNameFn=} getName
85
90
  * @property {ChunkFilterFn} chunksFilter
86
91
  * @property {SplitChunksSizes} minSize
@@ -89,9 +94,9 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
89
94
  * @property {SplitChunksSizes} enforceSizeThreshold
90
95
  * @property {SplitChunksSizes} maxAsyncSize
91
96
  * @property {SplitChunksSizes} maxInitialSize
92
- * @property {number} minChunks
93
- * @property {number} maxAsyncRequests
94
- * @property {number} maxInitialRequests
97
+ * @property {CountOfChunk} minChunks
98
+ * @property {CountOfRequest} maxAsyncRequests
99
+ * @property {CountOfRequest} maxInitialRequests
95
100
  * @property {TemplatePath=} filename
96
101
  * @property {string} idHint
97
102
  * @property {string} automaticNameDelimiter
@@ -143,9 +148,9 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
143
148
  * @property {SplitChunksSizes} enforceSizeThreshold
144
149
  * @property {SplitChunksSizes} maxInitialSize
145
150
  * @property {SplitChunksSizes} maxAsyncSize
146
- * @property {number} minChunks
147
- * @property {number} maxAsyncRequests
148
- * @property {number} maxInitialRequests
151
+ * @property {CountOfChunk} minChunks
152
+ * @property {CountOfRequest} maxAsyncRequests
153
+ * @property {CountOfRequest} maxInitialRequests
149
154
  * @property {boolean} hidePathInfo
150
155
  * @property {TemplatePath=} filename
151
156
  * @property {string} automaticNameDelimiter
@@ -155,15 +160,17 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
155
160
  * @property {FallbackCacheGroup} fallbackCacheGroup
156
161
  */
157
162
 
163
+ /** @typedef {Set<Chunk>} ChunkSet */
164
+
158
165
  /**
159
166
  * @typedef {object} ChunksInfoItem
160
167
  * @property {SortableSet<Module>} modules
161
168
  * @property {CacheGroup} cacheGroup
162
169
  * @property {number} cacheGroupIndex
163
170
  * @property {string=} name
164
- * @property {Record<SourceType, number>} sizes
165
- * @property {Set<Chunk>} chunks
166
- * @property {Set<Chunk>} reusableChunks
171
+ * @property {SplitChunksSizes} sizes
172
+ * @property {ChunkSet} chunks
173
+ * @property {ChunkSet} reusableChunks
167
174
  * @property {Set<bigint | Chunk>} chunksKeys
168
175
  */
169
176
 
@@ -195,7 +202,7 @@ const hashFilename = (name, outputOptions) => {
195
202
 
196
203
  /**
197
204
  * @param {Chunk} chunk the chunk
198
- * @returns {number} the number of requests
205
+ * @returns {CountOfRequest} the number of requests
199
206
  */
200
207
  const getRequests = (chunk) => {
201
208
  let requests = 0;
@@ -209,7 +216,7 @@ const getRequests = (chunk) => {
209
216
  * @template {object} T
210
217
  * @template {object} R
211
218
  * @param {T} obj obj an object
212
- * @param {function(T[keyof T], keyof T): T[keyof T]} fn fn
219
+ * @param {(obj: T[keyof T], key: keyof T) => T[keyof T]} fn fn
213
220
  * @returns {T} result
214
221
  */
215
222
  const mapObject = (obj, fn) => {
@@ -293,7 +300,7 @@ const ALL_CHUNK_FILTER = (_chunk) => true;
293
300
  */
294
301
  const normalizeSizes = (value, defaultSizeTypes) => {
295
302
  if (typeof value === "number") {
296
- /** @type {Record<string, number>} */
303
+ /** @type {SplitChunksSizes} */
297
304
  const o = {};
298
305
  for (const sizeType of defaultSizeTypes) o[sizeType] = value;
299
306
  return o;
@@ -321,7 +328,7 @@ const mergeSizes = (...sizes) => {
321
328
  * @returns {boolean} true, if there are sizes > 0
322
329
  */
323
330
  const hasNonZeroSizes = (sizes) => {
324
- for (const key of Object.keys(sizes)) {
331
+ for (const key of /** @type {SourceType[]} */ (Object.keys(sizes))) {
325
332
  if (sizes[key] > 0) return true;
326
333
  }
327
334
  return false;
@@ -334,8 +341,8 @@ const hasNonZeroSizes = (sizes) => {
334
341
  * @returns {SplitChunksSizes} the combine sizes
335
342
  */
336
343
  const combineSizes = (a, b, combine) => {
337
- const aKeys = new Set(Object.keys(a));
338
- const bKeys = new Set(Object.keys(b));
344
+ const aKeys = /** @type {Set<SourceType>} */ (new Set(Object.keys(a)));
345
+ const bKeys = /** @type {Set<SourceType>} */ (new Set(Object.keys(b)));
339
346
  /** @type {SplitChunksSizes} */
340
347
  const result = {};
341
348
  for (const key of aKeys) {
@@ -355,7 +362,7 @@ const combineSizes = (a, b, combine) => {
355
362
  * @returns {boolean} true if there are sizes and all existing sizes are at least `minSize`
356
363
  */
357
364
  const checkMinSize = (sizes, minSize) => {
358
- for (const key of Object.keys(minSize)) {
365
+ for (const key of /** @type {SourceType[]} */ (Object.keys(minSize))) {
359
366
  const size = sizes[key];
360
367
  if (size === undefined || size === 0) continue;
361
368
  if (size < minSize[key]) return false;
@@ -366,11 +373,13 @@ const checkMinSize = (sizes, minSize) => {
366
373
  /**
367
374
  * @param {SplitChunksSizes} sizes the sizes
368
375
  * @param {SplitChunksSizes} minSizeReduction the min sizes
369
- * @param {number} chunkCount number of chunks
376
+ * @param {CountOfChunk} chunkCount number of chunks
370
377
  * @returns {boolean} true if there are sizes and all existing sizes are at least `minSizeReduction`
371
378
  */
372
379
  const checkMinSizeReduction = (sizes, minSizeReduction, chunkCount) => {
373
- for (const key of Object.keys(minSizeReduction)) {
380
+ for (const key of /** @type {SourceType[]} */ (
381
+ Object.keys(minSizeReduction)
382
+ )) {
374
383
  const size = sizes[key];
375
384
  if (size === undefined || size === 0) continue;
376
385
  if (size * chunkCount < minSizeReduction[key]) return false;
@@ -384,8 +393,9 @@ const checkMinSizeReduction = (sizes, minSizeReduction, chunkCount) => {
384
393
  * @returns {undefined | SourceTypes} list of size types that are below min size
385
394
  */
386
395
  const getViolatingMinSizes = (sizes, minSize) => {
396
+ /** @type {SourceTypes | undefined} */
387
397
  let list;
388
- for (const key of Object.keys(minSize)) {
398
+ for (const key of /** @type {SourceType[]} */ (Object.keys(minSize))) {
389
399
  const size = sizes[key];
390
400
  if (size === undefined || size === 0) continue;
391
401
  if (size < minSize[key]) {
@@ -398,11 +408,11 @@ const getViolatingMinSizes = (sizes, minSize) => {
398
408
 
399
409
  /**
400
410
  * @param {SplitChunksSizes} sizes the sizes
401
- * @returns {number} the total size
411
+ * @returns {Size} the total size
402
412
  */
403
413
  const totalSize = (sizes) => {
404
414
  let size = 0;
405
- for (const key of Object.keys(sizes)) {
415
+ for (const key of /** @type {SourceType[]} */ (Object.keys(sizes))) {
406
416
  size += sizes[key];
407
417
  }
408
418
  return size;
@@ -887,9 +897,9 @@ module.exports = class SplitChunksPlugin {
887
897
  };
888
898
 
889
899
  const getChunkSetsInGraph = memoize(() => {
890
- /** @type {Map<bigint, Set<Chunk>>} */
900
+ /** @type {Map<bigint, ChunkSet>} */
891
901
  const chunkSetsInGraph = new Map();
892
- /** @type {Set<Chunk>} */
902
+ /** @type {ChunkSet} */
893
903
  const singleChunkSets = new Set();
894
904
  for (const module of compilation.modules) {
895
905
  const chunks = chunkGraph.getModuleChunksIterable(module);
@@ -927,10 +937,12 @@ module.exports = class SplitChunksPlugin {
927
937
  /** @type {Map<Module, Iterable<Chunk[]>>} */
928
938
  const groupedByExportsMap = new Map();
929
939
 
940
+ /** @typedef {Map<bigint | Chunk, ChunkSet>} ChunkSetsInGraph */
941
+
930
942
  const getExportsChunkSetsInGraph = memoize(() => {
931
- /** @type {Map<bigint | Chunk, Set<Chunk>>} */
943
+ /** @type {ChunkSetsInGraph} */
932
944
  const chunkSetsInGraph = new Map();
933
- /** @type {Set<Chunk>} */
945
+ /** @type {ChunkSet} */
934
946
  const singleChunkSets = new Set();
935
947
  for (const module of compilation.modules) {
936
948
  const groupedChunks = [...groupChunksByExports(module)];
@@ -949,13 +961,13 @@ module.exports = class SplitChunksPlugin {
949
961
  return { chunkSetsInGraph, singleChunkSets };
950
962
  });
951
963
 
952
- /** @typedef {Map<number, Set<Chunk>[]>} ChunkSetsByCount */
964
+ /** @typedef {Map<CountOfChunk, ChunkSet[]>} ChunkSetsByCount */
953
965
 
954
966
  // group these set of chunks by count
955
967
  // to allow to check less sets via isSubset
956
968
  // (only smaller sets can be subset)
957
969
  /**
958
- * @param {IterableIterator<Set<Chunk>>} chunkSets set of sets of chunks
970
+ * @param {IterableIterator<ChunkSet>} chunkSets set of sets of chunks
959
971
  * @returns {ChunkSetsByCount} map of sets of chunks by count
960
972
  */
961
973
  const groupChunkSetsByCount = (chunkSets) => {
@@ -983,13 +995,13 @@ module.exports = class SplitChunksPlugin {
983
995
  )
984
996
  );
985
997
 
986
- /** @typedef {(Set<Chunk> | Chunk)[]} Combinations */
998
+ /** @typedef {(ChunkSet | Chunk)[]} Combinations */
987
999
 
988
1000
  // Create a list of possible combinations
989
1001
  /**
990
- * @param {Map<bigint | Chunk, Set<Chunk>>} chunkSets chunk sets
991
- * @param {Set<Chunk>} singleChunkSets single chunks sets
992
- * @param {Map<number, Set<Chunk>[]>} chunkSetsByCount chunk sets by count
1002
+ * @param {ChunkSetsInGraph} chunkSets chunk sets
1003
+ * @param {ChunkSet} singleChunkSets single chunks sets
1004
+ * @param {ChunkSetsByCount} chunkSetsByCount chunk sets by count
993
1005
  * @returns {(key: bigint | Chunk) => Combinations} combinations
994
1006
  */
995
1007
  const createGetCombinations = (
@@ -1009,7 +1021,7 @@ module.exports = class SplitChunksPlugin {
1009
1021
  return result;
1010
1022
  }
1011
1023
  const chunksSet =
1012
- /** @type {Set<Chunk>} */
1024
+ /** @type {ChunkSet} */
1013
1025
  (chunkSets.get(key));
1014
1026
  /** @type {Combinations} */
1015
1027
  const array = [chunksSet];
@@ -1070,13 +1082,13 @@ module.exports = class SplitChunksPlugin {
1070
1082
  * @property {bigint | Chunk} key a key of the list
1071
1083
  */
1072
1084
 
1073
- /** @type {WeakMap<Set<Chunk> | Chunk, WeakMap<ChunkFilterFn, SelectedChunksResult>>} */
1085
+ /** @type {WeakMap<ChunkSet | Chunk, WeakMap<ChunkFilterFn, SelectedChunksResult>>} */
1074
1086
  const selectedChunksCacheByChunksSet = new WeakMap();
1075
1087
 
1076
1088
  /**
1077
1089
  * get list and key by applying the filter function to the list
1078
1090
  * It is cached for performance reasons
1079
- * @param {Set<Chunk> | Chunk} chunks list of chunks
1091
+ * @param {ChunkSet | Chunk} chunks list of chunks
1080
1092
  * @param {ChunkFilterFn} chunkFilter filter function for chunks
1081
1093
  * @returns {SelectedChunksResult} list and key
1082
1094
  */
@@ -1269,7 +1281,7 @@ module.exports = class SplitChunksPlugin {
1269
1281
  const getCombsByUsedExports = memoize(() => {
1270
1282
  // fill the groupedByExportsMap
1271
1283
  getExportsChunkSetsInGraph();
1272
- /** @type {Set<Set<Chunk> | Chunk>} */
1284
+ /** @type {Set<ChunkSet | Chunk>} */
1273
1285
  const set = new Set();
1274
1286
  const groupedByUsedExports =
1275
1287
  /** @type {Iterable<Chunk[]>} */
@@ -1703,7 +1715,9 @@ module.exports = class SplitChunksPlugin {
1703
1715
  if (Object.keys(maxSize).length === 0) {
1704
1716
  continue;
1705
1717
  }
1706
- for (const key of Object.keys(maxSize)) {
1718
+ for (const key of /** @type {SourceType[]} */ (
1719
+ Object.keys(maxSize)
1720
+ )) {
1707
1721
  const maxSizeValue = maxSize[key];
1708
1722
  const minSizeValue = minSize[key];
1709
1723
  if (
@@ -82,7 +82,7 @@ const { SyncHook } = require("tapable");
82
82
  /**
83
83
  * @template T
84
84
  * @template {T[keyof T]} V
85
- * @typedef {({ [P in keyof Required<T>]: Required<T>[P] extends V ? P : never })[keyof T]} KeysOfTypes
85
+ * @typedef {({ [key in keyof Required<T>]: Required<T>[key] extends V ? key : never })[keyof T]} KeysOfTypes
86
86
  */
87
87
 
88
88
  /** @typedef {Set<string>} UnhandledProperties */
@@ -35,10 +35,28 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
35
35
  }hasSymbol ? Symbol("webpack exports") : "${RuntimeGlobals.exports}";`,
36
36
  'var webpackError = hasSymbol ? Symbol("webpack error") : "__webpack_error__";',
37
37
  defer
38
- ? `var webpackDone = ${RuntimeGlobals.asyncModuleDoneSymbol} = hasSymbol ? Symbol("webpack done") : "__webpack_done__";`
39
- : "",
40
- defer
41
- ? `var webpackDefer = ${RuntimeGlobals.makeDeferredNamespaceObjectSymbol} = hasSymbol ? Symbol("webpack defer") : "__webpack_defer__";`
38
+ ? Template.asString([
39
+ `var webpackDone = ${RuntimeGlobals.asyncModuleDoneSymbol} = hasSymbol ? Symbol("webpack done") : "__webpack_done__";`,
40
+ `var webpackDefer = ${RuntimeGlobals.deferredModuleAsyncTransitiveDependenciesSymbol} = hasSymbol ? Symbol("webpack defer") : "__webpack_defer__";`,
41
+ `${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies} = ${runtimeTemplate.basicFunction(
42
+ "asyncDeps",
43
+ [
44
+ Template.indent([
45
+ "var hasUnresolvedAsyncSubgraph = asyncDeps.some((id) => {",
46
+ Template.indent([
47
+ "var cache = __webpack_module_cache__[id];",
48
+ "return !cache || cache[webpackDone] === false;"
49
+ ]),
50
+ "});",
51
+ "if (hasUnresolvedAsyncSubgraph) {",
52
+ Template.indent([
53
+ "return ({ then(onFulfilled, onRejected) { return Promise.all(asyncDeps.map(__webpack_require__)).then(onFulfilled, onRejected) } })"
54
+ ]),
55
+ "}"
56
+ ])
57
+ ]
58
+ )}`
59
+ ])
42
60
  : "",
43
61
  `var resolveQueue = ${runtimeTemplate.basicFunction("queue", [
44
62
  "if(queue && queue.d < 1) {",
@@ -63,25 +81,17 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
63
81
  ? Template.asString([
64
82
  "if(!dep[webpackQueues] && dep[webpackDefer]) {",
65
83
  Template.indent([
66
- "var asyncDeps = dep[webpackDefer];",
67
- `var hasUnresolvedAsyncSubgraph = asyncDeps.some(${runtimeTemplate.basicFunction(
68
- "id",
69
- [
70
- "var cache = __webpack_module_cache__[id];",
71
- "return !cache || cache[webpackDone] === false;"
72
- ]
73
- )});`,
74
- "if (hasUnresolvedAsyncSubgraph) {",
84
+ `var asyncDeps = ${RuntimeGlobals.deferredModuleAsyncTransitiveDependencies}(dep[webpackDefer]);`,
85
+ "if (asyncDeps) {",
75
86
  Template.indent([
76
87
  "var d = dep;",
77
88
  "dep = {",
78
89
  Template.indent([
79
- "then(callback) {",
90
+ "then(onFulfilled, onRejected) {",
80
91
  Template.indent([
81
- "Promise.all(asyncDeps.map(__webpack_require__))",
82
- `.then(${runtimeTemplate.returningFunction(
83
- "callback(d)"
84
- )});`
92
+ `asyncDeps.then(${runtimeTemplate.returningFunction(
93
+ "onFulfilled(d)"
94
+ )}, onRejected);`
85
95
  ]),
86
96
  "}"
87
97
  ]),
@@ -23,7 +23,8 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
23
23
  */
24
24
  generate() {
25
25
  const compilation = /** @type {Compilation} */ (this.compilation);
26
- const { scriptType, importMetaName, path } = compilation.outputOptions;
26
+ const { scriptType, importMetaName, path, environment } =
27
+ compilation.outputOptions;
27
28
  const chunkName = compilation.getPath(
28
29
  JavascriptModulesPlugin.getChunkFilenameTemplate(
29
30
  /** @type {Chunk} */
@@ -41,13 +42,17 @@ class AutoPublicPathRuntimeModule extends RuntimeModule {
41
42
  false
42
43
  );
43
44
 
45
+ const global = environment.globalThis
46
+ ? "globalThis"
47
+ : RuntimeGlobals.global;
48
+
44
49
  return Template.asString([
45
50
  "var scriptUrl;",
46
51
  scriptType === "module"
47
52
  ? `if (typeof ${importMetaName}.url === "string") scriptUrl = ${importMetaName}.url`
48
53
  : Template.asString([
49
- `if (${RuntimeGlobals.global}.importScripts) scriptUrl = ${RuntimeGlobals.global}.location + "";`,
50
- `var document = ${RuntimeGlobals.global}.document;`,
54
+ `if (${global}.importScripts) scriptUrl = ${global}.location + "";`,
55
+ `var document = ${global}.document;`,
51
56
  "if (!scriptUrl && document) {",
52
57
  Template.indent([
53
58
  // Technically we could use `document.currentScript instanceof window.HTMLScriptElement`,
@@ -13,6 +13,7 @@ const { first } = require("../util/SetHelpers");
13
13
  /** @typedef {import("../Chunk").ChunkId} ChunkId */
14
14
  /** @typedef {import("../ChunkGraph")} ChunkGraph */
15
15
  /** @typedef {import("../Compilation")} Compilation */
16
+ /** @typedef {import("../Compilation").HashWithLengthFunction} HashWithLengthFunction */
16
17
  /** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
17
18
 
18
19
  class GetChunkFilenameRuntimeModule extends RuntimeModule {
@@ -138,7 +139,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
138
139
  };
139
140
  /**
140
141
  * @param {string} value string
141
- * @returns {(length: number) => string} string to put in quotes with length
142
+ * @returns {HashWithLengthFunction} string to put in quotes with length
142
143
  */
143
144
  const unquotedStringifyWithLength = (value) => (length) =>
144
145
  unquotedStringify(`${value}`.slice(0, length));
@@ -230,7 +231,7 @@ class GetChunkFilenameRuntimeModule extends RuntimeModule {
230
231
 
231
232
  /**
232
233
  * @param {(chunk: Chunk) => string | number} fn function from chunk to value
233
- * @returns {(length: number) => string} function which generates code with static mapping of results of fn for including in quoted string for specific length
234
+ * @returns {HashWithLengthFunction} function which generates code with static mapping of results of fn for including in quoted string for specific length
234
235
  */
235
236
  const mapExprWithLength = (fn) => (length) =>
236
237
  `" + ${createMap((c) => `${fn(c)}`.slice(0, length))} + "`;