webpack 5.100.1 → 5.101.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 (304) hide show
  1. package/README.md +12 -10
  2. package/bin/webpack.js +7 -7
  3. package/lib/APIPlugin.js +12 -14
  4. package/lib/AutomaticPrefetchPlugin.js +2 -2
  5. package/lib/BannerPlugin.js +4 -4
  6. package/lib/Cache.js +1 -1
  7. package/lib/CacheFacade.js +7 -7
  8. package/lib/CaseSensitiveModulesWarning.js +2 -2
  9. package/lib/Chunk.js +3 -3
  10. package/lib/ChunkGraph.js +21 -18
  11. package/lib/ChunkGroup.js +4 -4
  12. package/lib/CleanPlugin.js +19 -53
  13. package/lib/CodeGenerationResults.js +3 -3
  14. package/lib/CompatibilityPlugin.js +6 -6
  15. package/lib/Compilation.js +127 -114
  16. package/lib/Compiler.js +37 -37
  17. package/lib/ConcatenationScope.js +39 -1
  18. package/lib/ConstPlugin.js +11 -11
  19. package/lib/ContextExclusionPlugin.js +3 -3
  20. package/lib/ContextModule.js +12 -11
  21. package/lib/ContextModuleFactory.js +11 -11
  22. package/lib/ContextReplacementPlugin.js +5 -5
  23. package/lib/DefinePlugin.js +24 -22
  24. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  25. package/lib/DllEntryPlugin.js +1 -1
  26. package/lib/DllReferencePlugin.js +1 -1
  27. package/lib/DynamicEntryPlugin.js +3 -3
  28. package/lib/EntryPlugin.js +1 -1
  29. package/lib/EnvironmentPlugin.js +1 -1
  30. package/lib/ErrorHelpers.js +2 -2
  31. package/lib/EvalDevToolModulePlugin.js +2 -2
  32. package/lib/EvalSourceMapDevToolPlugin.js +5 -5
  33. package/lib/ExportsInfo.js +9 -9
  34. package/lib/ExportsInfoApiPlugin.js +2 -2
  35. package/lib/ExternalModule.js +163 -48
  36. package/lib/ExternalModuleFactoryPlugin.js +2 -2
  37. package/lib/ExternalsPlugin.js +45 -0
  38. package/lib/FileSystemInfo.js +64 -61
  39. package/lib/FlagAllModulesAsUsedPlugin.js +2 -2
  40. package/lib/FlagDependencyExportsPlugin.js +7 -7
  41. package/lib/FlagDependencyUsagePlugin.js +4 -4
  42. package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
  43. package/lib/HotModuleReplacementPlugin.js +27 -27
  44. package/lib/IgnorePlugin.js +3 -3
  45. package/lib/IgnoreWarningsPlugin.js +4 -4
  46. package/lib/InitFragment.js +6 -0
  47. package/lib/InvalidDependenciesModuleWarning.js +1 -1
  48. package/lib/JavascriptMetaInfoPlugin.js +1 -1
  49. package/lib/LibManifestPlugin.js +2 -2
  50. package/lib/LoaderOptionsPlugin.js +1 -1
  51. package/lib/LoaderTargetPlugin.js +2 -2
  52. package/lib/MainTemplate.js +1 -1
  53. package/lib/Module.js +1 -1
  54. package/lib/ModuleFilenameHelpers.js +3 -3
  55. package/lib/ModuleGraph.js +86 -5
  56. package/lib/ModuleInfoHeaderPlugin.js +3 -3
  57. package/lib/ModuleParseError.js +5 -3
  58. package/lib/MultiCompiler.js +29 -24
  59. package/lib/MultiStats.js +18 -13
  60. package/lib/MultiWatching.js +1 -1
  61. package/lib/NoEmitOnErrorsPlugin.js +2 -2
  62. package/lib/NodeStuffPlugin.js +27 -15
  63. package/lib/NormalModule.js +28 -24
  64. package/lib/NormalModuleFactory.js +23 -21
  65. package/lib/NormalModuleReplacementPlugin.js +3 -3
  66. package/lib/PrefetchPlugin.js +1 -1
  67. package/lib/ProgressPlugin.js +11 -11
  68. package/lib/ProvidePlugin.js +2 -2
  69. package/lib/RecordIdsPlugin.js +3 -3
  70. package/lib/ResolverFactory.js +3 -3
  71. package/lib/RuntimeGlobals.js +20 -0
  72. package/lib/RuntimePlugin.js +16 -16
  73. package/lib/RuntimeTemplate.js +42 -44
  74. package/lib/SizeFormatHelpers.js +1 -1
  75. package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -4
  76. package/lib/SourceMapDevToolPlugin.js +9 -9
  77. package/lib/Stats.js +2 -2
  78. package/lib/Template.js +1 -1
  79. package/lib/TemplatedPathPlugin.js +2 -2
  80. package/lib/UseStrictPlugin.js +1 -1
  81. package/lib/WarnCaseSensitiveModulesPlugin.js +1 -1
  82. package/lib/WarnDeprecatedOptionPlugin.js +1 -1
  83. package/lib/WarnNoModeSetPlugin.js +1 -1
  84. package/lib/WatchIgnorePlugin.js +2 -2
  85. package/lib/Watching.js +12 -12
  86. package/lib/WebpackIsIncludedPlugin.js +2 -2
  87. package/lib/WebpackOptionsApply.js +10 -3
  88. package/lib/asset/AssetGenerator.js +3 -3
  89. package/lib/asset/AssetModulesPlugin.js +6 -6
  90. package/lib/async-modules/AsyncModuleHelpers.js +50 -0
  91. package/lib/async-modules/AwaitDependenciesInitFragment.js +36 -24
  92. package/lib/async-modules/InferAsyncModulesPlugin.js +3 -3
  93. package/lib/buildChunkGraph.js +5 -5
  94. package/lib/cache/AddBuildDependenciesPlugin.js +1 -1
  95. package/lib/cache/IdleFileCachePlugin.js +5 -5
  96. package/lib/cache/PackFileCacheStrategy.js +20 -20
  97. package/lib/cache/ResolverCachePlugin.js +4 -4
  98. package/lib/cli.js +196 -14
  99. package/lib/config/browserslistTargetHandler.js +6 -6
  100. package/lib/config/defaults.js +23 -14
  101. package/lib/config/normalization.js +41 -38
  102. package/lib/config/target.js +4 -4
  103. package/lib/container/ContainerEntryModule.js +3 -3
  104. package/lib/container/ContainerPlugin.js +3 -3
  105. package/lib/container/ContainerReferencePlugin.js +3 -3
  106. package/lib/container/FallbackModule.js +1 -1
  107. package/lib/container/HoistContainerReferencesPlugin.js +7 -7
  108. package/lib/container/options.js +4 -4
  109. package/lib/css/CssGenerator.js +5 -3
  110. package/lib/css/CssLoadingRuntimeModule.js +1 -1
  111. package/lib/css/CssModulesPlugin.js +25 -22
  112. package/lib/css/CssParser.js +5 -5
  113. package/lib/css/walkCssTokens.js +9 -9
  114. package/lib/debug/ProfilingPlugin.js +5 -5
  115. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +4 -4
  116. package/lib/dependencies/AMDPlugin.js +3 -3
  117. package/lib/dependencies/AMDRequireArrayDependency.js +1 -1
  118. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +3 -3
  119. package/lib/dependencies/CommonJsExportRequireDependency.js +2 -2
  120. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -10
  121. package/lib/dependencies/CommonJsImportsParserPlugin.js +21 -19
  122. package/lib/dependencies/CommonJsPlugin.js +2 -2
  123. package/lib/dependencies/ContextDependency.js +1 -1
  124. package/lib/dependencies/ContextDependencyHelpers.js +3 -3
  125. package/lib/dependencies/CssIcssExportDependency.js +2 -2
  126. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  127. package/lib/dependencies/CssUrlDependency.js +4 -4
  128. package/lib/dependencies/DynamicExports.js +5 -5
  129. package/lib/dependencies/HarmonyAcceptDependency.js +39 -5
  130. package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
  131. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +17 -23
  132. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -8
  133. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  134. package/lib/dependencies/HarmonyExports.js +1 -1
  135. package/lib/dependencies/HarmonyImportDependency.js +28 -9
  136. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +59 -75
  137. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -5
  138. package/lib/dependencies/HarmonyImportSpecifierDependency.js +3 -4
  139. package/lib/dependencies/HarmonyModulesPlugin.js +2 -8
  140. package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
  141. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -4
  142. package/lib/dependencies/ImportMetaPlugin.js +7 -7
  143. package/lib/dependencies/ImportParserPlugin.js +4 -4
  144. package/lib/dependencies/JsonExportsDependency.js +1 -1
  145. package/lib/dependencies/LoaderPlugin.js +4 -4
  146. package/lib/dependencies/ProvidedDependency.js +2 -2
  147. package/lib/dependencies/PureExpressionDependency.js +1 -1
  148. package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
  149. package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -1
  150. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -3
  151. package/lib/dependencies/SystemPlugin.js +3 -3
  152. package/lib/dependencies/WorkerPlugin.js +5 -5
  153. package/lib/dependencies/getFunctionExpression.js +1 -1
  154. package/lib/esm/ModuleChunkFormatPlugin.js +5 -5
  155. package/lib/esm/ModuleChunkLoadingPlugin.js +2 -2
  156. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +15 -11
  157. package/lib/formatLocation.js +2 -2
  158. package/lib/hmr/HotModuleReplacement.runtime.js +39 -27
  159. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +43 -32
  160. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -1
  161. package/lib/hmr/LazyCompilationPlugin.js +6 -6
  162. package/lib/hmr/lazyCompilationBackend.js +6 -6
  163. package/lib/ids/ChunkModuleIdRangePlugin.js +4 -4
  164. package/lib/ids/DeterministicChunkIdsPlugin.js +5 -4
  165. package/lib/ids/DeterministicModuleIdsPlugin.js +2 -2
  166. package/lib/ids/HashedModuleIdsPlugin.js +1 -1
  167. package/lib/ids/IdHelpers.js +9 -9
  168. package/lib/ids/NamedChunkIdsPlugin.js +5 -5
  169. package/lib/ids/NamedModuleIdsPlugin.js +2 -2
  170. package/lib/ids/NaturalChunkIdsPlugin.js +2 -2
  171. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  172. package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
  173. package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -4
  174. package/lib/ids/SyncModuleIdsPlugin.js +4 -4
  175. package/lib/index.js +10 -6
  176. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -1
  177. package/lib/javascript/BasicEvaluatedExpression.js +3 -3
  178. package/lib/javascript/CommonJsChunkFormatPlugin.js +1 -1
  179. package/lib/javascript/EnableChunkLoadingPlugin.js +1 -1
  180. package/lib/javascript/JavascriptGenerator.js +1 -1
  181. package/lib/javascript/JavascriptModulesPlugin.js +16 -16
  182. package/lib/javascript/JavascriptParser.js +90 -83
  183. package/lib/javascript/JavascriptParserHelpers.js +3 -3
  184. package/lib/javascript/StartupHelpers.js +2 -2
  185. package/lib/json/JsonGenerator.js +2 -2
  186. package/lib/json/JsonModulesPlugin.js +2 -2
  187. package/lib/library/AbstractLibraryPlugin.js +3 -3
  188. package/lib/library/AmdLibraryPlugin.js +3 -3
  189. package/lib/library/AssignLibraryPlugin.js +2 -2
  190. package/lib/library/EnableLibraryPlugin.js +2 -2
  191. package/lib/library/ModuleLibraryPlugin.js +7 -2
  192. package/lib/library/SystemLibraryPlugin.js +6 -4
  193. package/lib/library/UmdLibraryPlugin.js +14 -14
  194. package/lib/logging/createConsoleLogger.js +4 -4
  195. package/lib/logging/runtime.js +3 -3
  196. package/lib/logging/truncateArgs.js +4 -4
  197. package/lib/node/CommonJsChunkLoadingPlugin.js +2 -2
  198. package/lib/node/NodeEnvironmentPlugin.js +1 -1
  199. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +16 -14
  200. package/lib/node/ReadFileCompileAsyncWasmPlugin.js +7 -7
  201. package/lib/node/ReadFileCompileWasmPlugin.js +7 -7
  202. package/lib/node/RequireChunkLoadingRuntimeModule.js +6 -4
  203. package/lib/node/nodeConsole.js +2 -2
  204. package/lib/optimize/AggressiveMergingPlugin.js +2 -2
  205. package/lib/optimize/AggressiveSplittingPlugin.js +10 -10
  206. package/lib/optimize/ConcatenatedModule.js +161 -52
  207. package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -2
  208. package/lib/optimize/FlagIncludedChunksPlugin.js +2 -2
  209. package/lib/optimize/InnerGraph.js +5 -5
  210. package/lib/optimize/InnerGraphPlugin.js +14 -12
  211. package/lib/optimize/LimitChunkCountPlugin.js +5 -5
  212. package/lib/optimize/MangleExportsPlugin.js +5 -5
  213. package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
  214. package/lib/optimize/MinChunkSizePlugin.js +3 -3
  215. package/lib/optimize/ModuleConcatenationPlugin.js +45 -38
  216. package/lib/optimize/RealContentHashPlugin.js +23 -23
  217. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
  218. package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
  219. package/lib/optimize/RuntimeChunkPlugin.js +2 -2
  220. package/lib/optimize/SideEffectsFlagPlugin.js +22 -6
  221. package/lib/optimize/SplitChunksPlugin.js +20 -20
  222. package/lib/performance/AssetsOverSizeLimitWarning.js +1 -1
  223. package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
  224. package/lib/performance/SizeLimitsPlugin.js +4 -4
  225. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +1 -1
  226. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -3
  227. package/lib/rules/BasicMatcherRulePlugin.js +1 -1
  228. package/lib/rules/RuleSetCompiler.js +10 -10
  229. package/lib/rules/UseEffectRulePlugin.js +2 -2
  230. package/lib/runtime/GetChunkFilenameRuntimeModule.js +15 -15
  231. package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
  232. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
  233. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
  234. package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -2
  235. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -3
  236. package/lib/schemes/DataUriPlugin.js +3 -3
  237. package/lib/schemes/FileUriPlugin.js +1 -1
  238. package/lib/schemes/HttpUriPlugin.js +40 -36
  239. package/lib/schemes/VirtualUrlPlugin.js +1 -1
  240. package/lib/serialization/BinaryMiddleware.js +11 -11
  241. package/lib/serialization/FileMiddleware.js +17 -17
  242. package/lib/serialization/ObjectMiddleware.js +8 -8
  243. package/lib/serialization/Serializer.js +2 -2
  244. package/lib/serialization/SerializerMiddleware.js +2 -2
  245. package/lib/sharing/ConsumeSharedPlugin.js +4 -4
  246. package/lib/sharing/ProvideSharedPlugin.js +4 -4
  247. package/lib/sharing/SharePlugin.js +1 -1
  248. package/lib/sharing/resolveMatchedConfigs.js +1 -1
  249. package/lib/stats/DefaultStatsFactoryPlugin.js +86 -80
  250. package/lib/stats/DefaultStatsPresetPlugin.js +15 -15
  251. package/lib/stats/DefaultStatsPrinterPlugin.js +87 -87
  252. package/lib/stats/StatsFactory.js +7 -7
  253. package/lib/stats/StatsPrinter.js +9 -9
  254. package/lib/url/URLParserPlugin.js +5 -5
  255. package/lib/util/AsyncQueue.js +4 -4
  256. package/lib/util/IterableHelpers.js +2 -2
  257. package/lib/util/LazyBucketSortedSet.js +3 -3
  258. package/lib/util/SetHelpers.js +2 -2
  259. package/lib/util/StackedCacheMap.js +1 -1
  260. package/lib/util/StackedMap.js +1 -1
  261. package/lib/util/TupleSet.js +1 -1
  262. package/lib/util/WeakTupleMap.js +1 -1
  263. package/lib/util/cleverMerge.js +8 -8
  264. package/lib/util/comparators.js +107 -8
  265. package/lib/util/compileBooleanMatcher.js +20 -20
  266. package/lib/util/concatenate.js +3 -3
  267. package/lib/util/conventions.js +4 -4
  268. package/lib/util/create-schema-validation.js +1 -1
  269. package/lib/util/createHash.js +1 -1
  270. package/lib/util/deprecation.js +4 -4
  271. package/lib/util/deterministicGrouping.js +7 -7
  272. package/lib/util/findGraphRoots.js +1 -1
  273. package/lib/util/fs.js +3 -3
  274. package/lib/util/identifier.js +14 -14
  275. package/lib/util/magicComment.js +5 -1
  276. package/lib/util/memoize.js +1 -1
  277. package/lib/util/processAsyncTree.js +2 -2
  278. package/lib/util/propertyName.js +1 -1
  279. package/lib/util/removeBOM.js +1 -1
  280. package/lib/util/runtime.js +6 -6
  281. package/lib/util/semver.js +16 -16
  282. package/lib/util/serialization.js +5 -5
  283. package/lib/util/smartGrouping.js +1 -1
  284. package/lib/validateSchema.js +2 -2
  285. package/lib/wasm/EnableWasmLoadingPlugin.js +1 -1
  286. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
  287. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
  288. package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -4
  289. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -9
  290. package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -2
  291. package/lib/wasm-sync/WebAssemblyGenerator.js +14 -14
  292. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +4 -2
  293. package/lib/wasm-sync/WebAssemblyParser.js +2 -2
  294. package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -4
  295. package/lib/web/FetchCompileWasmPlugin.js +4 -4
  296. package/lib/web/JsonpChunkLoadingPlugin.js +2 -2
  297. package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
  298. package/lib/webpack.js +17 -12
  299. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -2
  300. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
  301. package/package.json +13 -13
  302. package/schemas/WebpackOptions.check.js +1 -1
  303. package/schemas/WebpackOptions.json +4 -0
  304. package/types.d.ts +186 -54
@@ -0,0 +1,50 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Haijie Xie @hai-x
4
+ */
5
+
6
+ "use strict";
7
+
8
+ const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
9
+
10
+ /** @typedef {import("../ModuleGraph")} ModuleGraph */
11
+ /** @typedef {import("../Module")} Module */
12
+
13
+ /**
14
+ * @param {ModuleGraph} moduleGraph module graph
15
+ * @param {Module} module module
16
+ * @returns {Set<Module>} set of modules
17
+ */
18
+ const getOutgoingAsyncModules = (moduleGraph, module) => {
19
+ /** @type {Set<Module>} */
20
+ const set = new Set();
21
+ /** @type {Set<Module>} */
22
+ const seen = new Set();
23
+ (function g(/** @type {Module} */ module) {
24
+ if (!moduleGraph.isAsync(module) || seen.has(module)) return;
25
+ seen.add(module);
26
+ if (module.buildMeta && module.buildMeta.async) {
27
+ set.add(module);
28
+ } else {
29
+ const outgoingConnectionMap =
30
+ moduleGraph.getOutgoingConnectionsByModule(module);
31
+ if (outgoingConnectionMap) {
32
+ for (const [module, connections] of outgoingConnectionMap) {
33
+ if (
34
+ connections.some(
35
+ (c) =>
36
+ c.dependency instanceof HarmonyImportDependency &&
37
+ c.isTargetActive(undefined)
38
+ ) &&
39
+ module
40
+ ) {
41
+ g(module);
42
+ }
43
+ }
44
+ }
45
+ }
46
+ })(module);
47
+ return set;
48
+ };
49
+
50
+ module.exports.getOutgoingAsyncModules = getOutgoingAsyncModules;
@@ -17,16 +17,16 @@ const Template = require("../Template");
17
17
  */
18
18
  class AwaitDependenciesInitFragment extends InitFragment {
19
19
  /**
20
- * @param {Set<string>} promises the promises that should be awaited
20
+ * @param {Map<string, string>} dependencies maps an import var to an async module that needs to be awaited
21
21
  */
22
- constructor(promises) {
22
+ constructor(dependencies) {
23
23
  super(
24
24
  undefined,
25
25
  InitFragment.STAGE_ASYNC_DEPENDENCIES,
26
26
  0,
27
27
  "await-dependencies"
28
28
  );
29
- this.promises = promises;
29
+ this.dependencies = dependencies;
30
30
  }
31
31
 
32
32
  /**
@@ -34,38 +34,50 @@ class AwaitDependenciesInitFragment extends InitFragment {
34
34
  * @returns {AwaitDependenciesInitFragment} AwaitDependenciesInitFragment
35
35
  */
36
36
  merge(other) {
37
- const promises = new Set(other.promises);
38
- for (const p of this.promises) {
39
- promises.add(p);
37
+ const dependencies = new Map(other.dependencies);
38
+ for (const [key, value] of this.dependencies) {
39
+ dependencies.set(key, value);
40
40
  }
41
- return new AwaitDependenciesInitFragment(promises);
41
+ return new AwaitDependenciesInitFragment(dependencies);
42
42
  }
43
43
 
44
44
  /**
45
45
  * @param {GenerateContext} context context
46
46
  * @returns {string | Source | undefined} the source code that will be included as initialization code
47
47
  */
48
- getContent({ runtimeRequirements }) {
48
+ getContent({ runtimeRequirements, runtimeTemplate }) {
49
49
  runtimeRequirements.add(RuntimeGlobals.module);
50
- const promises = this.promises;
51
- if (promises.size === 0) {
50
+ if (this.dependencies.size === 0) {
52
51
  return "";
53
52
  }
54
- if (promises.size === 1) {
55
- const [p] = promises;
56
- return Template.asString([
57
- `var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${p}]);`,
58
- `${p} = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[0];`,
59
- ""
60
- ]);
53
+
54
+ const importVars = [...this.dependencies.keys()];
55
+ const asyncModuleValues = [...this.dependencies.values()].join(", ");
56
+
57
+ const templateInput = [
58
+ `var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${asyncModuleValues}]);`
59
+ ];
60
+
61
+ if (
62
+ this.dependencies.size === 1 ||
63
+ !runtimeTemplate.supportsDestructuring()
64
+ ) {
65
+ for (const [index, importVar] of importVars.entries()) {
66
+ templateInput.push(
67
+ `${importVar} = (__webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__)[${index}];`
68
+ );
69
+ }
70
+ } else {
71
+ const importVarsStr = importVars.join(", ");
72
+
73
+ templateInput.push(
74
+ `([${importVarsStr}] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);`
75
+ );
61
76
  }
62
- const sepPromises = [...promises].join(", ");
63
- // TODO check if destructuring is supported
64
- return Template.asString([
65
- `var __webpack_async_dependencies__ = __webpack_handle_async_dependencies__([${sepPromises}]);`,
66
- `([${sepPromises}] = __webpack_async_dependencies__.then ? (await __webpack_async_dependencies__)() : __webpack_async_dependencies__);`,
67
- ""
68
- ]);
77
+
78
+ templateInput.push("");
79
+
80
+ return Template.asString(templateInput);
69
81
  }
70
82
  }
71
83
 
@@ -19,9 +19,9 @@ class InferAsyncModulesPlugin {
19
19
  * @returns {void}
20
20
  */
21
21
  apply(compiler) {
22
- compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
22
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
23
23
  const { moduleGraph } = compilation;
24
- compilation.hooks.finishModules.tap(PLUGIN_NAME, modules => {
24
+ compilation.hooks.finishModules.tap(PLUGIN_NAME, (modules) => {
25
25
  /** @type {Set<Module>} */
26
26
  const queue = new Set();
27
27
  for (const module of modules) {
@@ -37,7 +37,7 @@ class InferAsyncModulesPlugin {
37
37
  ] of moduleGraph.getIncomingConnectionsByOriginModule(module)) {
38
38
  if (
39
39
  connections.some(
40
- c =>
40
+ (c) =>
41
41
  c.dependency instanceof HarmonyImportDependency &&
42
42
  c.isTargetActive(undefined)
43
43
  )
@@ -269,7 +269,7 @@ const visitModules = (
269
269
  * @param {Module} module The module to look up
270
270
  * @returns {number} The ordinal of the module in masks
271
271
  */
272
- const getModuleOrdinal = module => {
272
+ const getModuleOrdinal = (module) => {
273
273
  let ordinal = ordinalByModule.get(module);
274
274
  if (ordinal === undefined) {
275
275
  ordinal = ordinalByModule.size;
@@ -486,7 +486,7 @@ const visitModules = (
486
486
  * @param {AsyncDependenciesBlock} b iterating over each Async DepBlock
487
487
  * @returns {void}
488
488
  */
489
- const iteratorBlock = b => {
489
+ const iteratorBlock = (b) => {
490
490
  // 1. We create a chunk group with single chunk in it for this Block
491
491
  // but only once (blockChunkGroups map)
492
492
  /** @type {ChunkGroupInfo | undefined} */
@@ -673,7 +673,7 @@ const visitModules = (
673
673
  * @param {DependenciesBlock} block the block
674
674
  * @returns {void}
675
675
  */
676
- const processBlock = block => {
676
+ const processBlock = (block) => {
677
677
  statProcessedBlocks++;
678
678
  // get prepared block info
679
679
  const blockModules = getBlockModules(block, chunkGroupInfo.runtime);
@@ -765,7 +765,7 @@ const visitModules = (
765
765
  * @param {DependenciesBlock} block the block
766
766
  * @returns {void}
767
767
  */
768
- const processEntryBlock = block => {
768
+ const processEntryBlock = (block) => {
769
769
  statProcessedBlocks++;
770
770
  // get prepared block info
771
771
  const blockModules = getBlockModules(block, chunkGroupInfo.runtime);
@@ -892,7 +892,7 @@ const visitModules = (
892
892
  * @param {ChunkGroupInfo} chunkGroupInfo The info object for the chunk group
893
893
  * @returns {bigint} The mask of available modules after the chunk group
894
894
  */
895
- const calculateResultingAvailableModules = chunkGroupInfo => {
895
+ const calculateResultingAvailableModules = (chunkGroupInfo) => {
896
896
  if (chunkGroupInfo.resultingAvailableModules !== undefined) {
897
897
  return chunkGroupInfo.resultingAvailableModules;
898
898
  }
@@ -23,7 +23,7 @@ class AddBuildDependenciesPlugin {
23
23
  * @returns {void}
24
24
  */
25
25
  apply(compiler) {
26
- compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
26
+ compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
27
27
  compilation.buildDependencies.addAll(this.buildDependencies);
28
28
  });
29
29
  }
@@ -68,7 +68,7 @@ class IdleFileCachePlugin {
68
68
  { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
69
69
  (identifier, etag, gotHandlers) => {
70
70
  const restore = () =>
71
- strategy.restore(identifier, etag).then(cacheEntry => {
71
+ strategy.restore(identifier, etag).then((cacheEntry) => {
72
72
  if (cacheEntry === undefined) {
73
73
  gotHandlers.push((result, callback) => {
74
74
  if (result !== undefined) {
@@ -93,7 +93,7 @@ class IdleFileCachePlugin {
93
93
 
94
94
  compiler.cache.hooks.storeBuildDependencies.tap(
95
95
  { name: PLUGIN_NAME, stage: Cache.STAGE_DISK },
96
- dependencies => {
96
+ (dependencies) => {
97
97
  pendingIdleTasks.set(BUILD_DEPENDENCIES_KEY, () =>
98
98
  Promise.resolve().then(() =>
99
99
  strategy.storeBuildDependencies(dependencies)
@@ -113,7 +113,7 @@ class IdleFileCachePlugin {
113
113
  const reportProgress = ProgressPlugin.getReporter(compiler);
114
114
  const jobs = [...pendingIdleTasks.values()];
115
115
  if (reportProgress) reportProgress(0, "process pending cache items");
116
- const promises = jobs.map(fn => fn());
116
+ const promises = jobs.map((fn) => fn());
117
117
  pendingIdleTasks.clear();
118
118
  promises.push(currentIdlePromise);
119
119
  const promise = Promise.all(promises);
@@ -168,7 +168,7 @@ class IdleFileCachePlugin {
168
168
  timeSpendInStore = 0;
169
169
  timeSpendInBuild = 0;
170
170
  })
171
- .catch(err => {
171
+ .catch((err) => {
172
172
  const logger = compiler.getInfrastructureLogger(PLUGIN_NAME);
173
173
  logger.warn(`Background tasks during idle failed: ${err.message}`);
174
174
  logger.debug(err.stack);
@@ -229,7 +229,7 @@ class IdleFileCachePlugin {
229
229
  isIdle = false;
230
230
  }
231
231
  );
232
- compiler.hooks.done.tap(PLUGIN_NAME, stats => {
232
+ compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
233
233
  // 10% build overhead is ignored, as it's not cacheable
234
234
  timeSpendInBuild *= 0.9;
235
235
  timeSpendInBuild +=
@@ -330,7 +330,7 @@ class Pack {
330
330
  `${itemsCount} fresh items in cache put into pack ${
331
331
  packs.length > 1
332
332
  ? packs
333
- .map(pack => `${pack.loc} (${pack.items.size} items)`)
333
+ .map((pack) => `${pack.loc} (${pack.items.size} items)`)
334
334
  .join(", ")
335
335
  : packs[0].loc
336
336
  }`
@@ -407,7 +407,7 @@ class Pack {
407
407
  for (const identifier of content.used) {
408
408
  mergedUsedItems.add(identifier);
409
409
  }
410
- addToMergedMap.push(async map => {
410
+ addToMergedMap.push(async (map) => {
411
411
  // unpack existing content
412
412
  // after that values are accessible in .content
413
413
  await content.unpack(
@@ -433,7 +433,7 @@ class Pack {
433
433
  memoize(async () => {
434
434
  /** @type {Content} */
435
435
  const map = new Map();
436
- await Promise.all(addToMergedMap.map(fn => fn(map)));
436
+ await Promise.all(addToMergedMap.map((fn) => fn(map)));
437
437
  return new PackContentItems(map);
438
438
  })
439
439
  );
@@ -603,7 +603,7 @@ class Pack {
603
603
  const content = this.content[i];
604
604
  if (content !== undefined) {
605
605
  write(content.items);
606
- content.writeLazy(lazy =>
606
+ content.writeLazy((lazy) =>
607
607
  /** @type {NonNullable<ObjectSerializerContext["writeSeparate"]>} */
608
608
  (writeSeparate)(lazy, { name: `${i}` })
609
609
  );
@@ -627,7 +627,7 @@ class Pack {
627
627
  item = read();
628
628
  }
629
629
  this.itemInfo.clear();
630
- const infoItems = items.map(identifier => {
630
+ const infoItems = items.map((identifier) => {
631
631
  const info = new PackItemInfo(identifier, undefined, undefined);
632
632
  this.itemInfo.set(identifier, info);
633
633
  return info;
@@ -875,7 +875,7 @@ class PackContent {
875
875
  }
876
876
  const value = /** @type {LazyFunction} */ (this.lazy)();
877
877
  if ("then" in value) {
878
- return value.then(data => {
878
+ return value.then((data) => {
879
879
  const map = data.map;
880
880
  if (timeMessage) {
881
881
  logger.timeEnd(timeMessage);
@@ -927,7 +927,7 @@ class PackContent {
927
927
  /** @type {PackContentItems | Promise<PackContentItems>} */
928
928
  (this.lazy());
929
929
  if ("then" in value) {
930
- return value.then(data => {
930
+ return value.then((data) => {
931
931
  if (timeMessage) {
932
932
  logger.timeEnd(timeMessage);
933
933
  }
@@ -1022,7 +1022,7 @@ class PackContent {
1022
1022
  if ("then" in value) {
1023
1023
  // Move to state B1
1024
1024
  this.lazy = write(() =>
1025
- value.then(data => {
1025
+ value.then((data) => {
1026
1026
  if (timeMessage) {
1027
1027
  logger.timeEnd(timeMessage);
1028
1028
  }
@@ -1060,7 +1060,7 @@ class PackContent {
1060
1060
  * @param {Buffer} buf buffer
1061
1061
  * @returns {Buffer} buffer that can be collected
1062
1062
  */
1063
- const allowCollectingMemory = buf => {
1063
+ const allowCollectingMemory = (buf) => {
1064
1064
  const wasted = buf.buffer.byteLength - buf.byteLength;
1065
1065
  if (wasted > 8192 && (wasted > 1048576 || wasted > buf.byteLength)) {
1066
1066
  return Buffer.from(buf);
@@ -1178,7 +1178,7 @@ class PackFileCacheStrategy {
1178
1178
  ? allowCollectingMemory
1179
1179
  : undefined
1180
1180
  })
1181
- .catch(err => {
1181
+ .catch((err) => {
1182
1182
  if (err.code !== "ENOENT") {
1183
1183
  logger.warn(
1184
1184
  `Restoring pack failed from ${cacheLocation}${this._extension}: ${err}`
@@ -1191,7 +1191,7 @@ class PackFileCacheStrategy {
1191
1191
  }
1192
1192
  return undefined;
1193
1193
  })
1194
- .then(packContainer => {
1194
+ .then((packContainer) => {
1195
1195
  logger.timeEnd("restore cache container");
1196
1196
  if (!packContainer) return;
1197
1197
  if (!(packContainer instanceof PackContainer)) {
@@ -1277,7 +1277,7 @@ class PackFileCacheStrategy {
1277
1277
  );
1278
1278
  })
1279
1279
  ])
1280
- .catch(err => {
1280
+ .catch((err) => {
1281
1281
  logger.timeEnd("check build dependencies");
1282
1282
  throw err;
1283
1283
  })
@@ -1292,7 +1292,7 @@ class PackFileCacheStrategy {
1292
1292
  return undefined;
1293
1293
  });
1294
1294
  })
1295
- .then(pack => {
1295
+ .then((pack) => {
1296
1296
  if (pack) {
1297
1297
  pack.maxAge = this.maxAge;
1298
1298
  this.buildSnapshot = buildSnapshot;
@@ -1307,7 +1307,7 @@ class PackFileCacheStrategy {
1307
1307
  }
1308
1308
  return new Pack(logger, this.maxAge);
1309
1309
  })
1310
- .catch(err => {
1310
+ .catch((err) => {
1311
1311
  this.logger.warn(
1312
1312
  `Restoring pack from ${cacheLocation}${this._extension} failed: ${err}`
1313
1313
  );
@@ -1325,7 +1325,7 @@ class PackFileCacheStrategy {
1325
1325
  store(identifier, etag, data) {
1326
1326
  if (this.readonly) return Promise.resolve();
1327
1327
 
1328
- return this._getPack().then(pack => {
1328
+ return this._getPack().then((pack) => {
1329
1329
  pack.set(identifier, etag === null ? null : etag.toString(), data);
1330
1330
  });
1331
1331
  }
@@ -1337,10 +1337,10 @@ class PackFileCacheStrategy {
1337
1337
  */
1338
1338
  restore(identifier, etag) {
1339
1339
  return this._getPack()
1340
- .then(pack =>
1340
+ .then((pack) =>
1341
1341
  pack.get(identifier, etag === null ? null : etag.toString())
1342
1342
  )
1343
- .catch(err => {
1343
+ .catch((err) => {
1344
1344
  if (err && err.code !== "ENOENT") {
1345
1345
  this.logger.warn(
1346
1346
  `Restoring failed for ${identifier} from pack: ${err}`
@@ -1363,7 +1363,7 @@ class PackFileCacheStrategy {
1363
1363
  if (packPromise === undefined) return Promise.resolve();
1364
1364
  const reportProgress = ProgressPlugin.getReporter(this.compiler);
1365
1365
  return (this.storePromise = packPromise
1366
- .then(pack => {
1366
+ .then((pack) => {
1367
1367
  pack.stopCapturingRequests();
1368
1368
  if (!pack.invalid) return;
1369
1369
  this.packPromise = undefined;
@@ -1526,14 +1526,14 @@ class PackFileCacheStrategy {
1526
1526
  Math.round(stats.size / 1024 / 1024)
1527
1527
  );
1528
1528
  })
1529
- .catch(err => {
1529
+ .catch((err) => {
1530
1530
  this.logger.timeEnd("store pack");
1531
1531
  this.logger.warn(`Caching failed for pack: ${err}`);
1532
1532
  this.logger.debug(err.stack);
1533
1533
  });
1534
1534
  });
1535
1535
  })
1536
- .catch(err => {
1536
+ .catch((err) => {
1537
1537
  this.logger.warn(`Caching failed for pack: ${err}`);
1538
1538
  this.logger.debug(err.stack);
1539
1539
  }));
@@ -115,7 +115,7 @@ class ResolverCachePlugin {
115
115
  let cachedResolves = 0;
116
116
  let cacheInvalidResolves = 0;
117
117
  let concurrentResolves = 0;
118
- compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
118
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
119
119
  snapshotOptions = compilation.options.snapshot.resolve;
120
120
  fileSystemInfo = compilation.fileSystemInfo;
121
121
  compilation.hooks.finishModules.tap(PLUGIN_NAME, () => {
@@ -176,14 +176,14 @@ class ResolverCachePlugin {
176
176
  if (typeof newResolveContext.yield === "function") {
177
177
  yieldResult = [];
178
178
  withYield = true;
179
- newResolveContext.yield = obj =>
179
+ newResolveContext.yield = (obj) =>
180
180
  /** @type {ResolveRequest[]} */
181
181
  (yieldResult).push(obj);
182
182
  }
183
183
  /**
184
184
  * @param {"fileDependencies" | "contextDependencies" | "missingDependencies"} key key
185
185
  */
186
- const propagate = key => {
186
+ const propagate = (key) => {
187
187
  if (resolveContext[key]) {
188
188
  addAllToSet(
189
189
  /** @type {Set<string>} */ (resolveContext[key]),
@@ -239,7 +239,7 @@ class ResolverCachePlugin {
239
239
  (resolveResult),
240
240
  snapshot
241
241
  ),
242
- storeErr => {
242
+ (storeErr) => {
243
243
  if (storeErr) return callback(storeErr);
244
244
  if (resolveResult) {
245
245
  return callback(