webpack 5.99.9 → 5.100.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 (306) hide show
  1. package/bin/webpack.js +8 -2
  2. package/hot/log.js +15 -15
  3. package/hot/poll.js +1 -0
  4. package/lib/APIPlugin.js +3 -3
  5. package/lib/AbstractMethodError.js +1 -0
  6. package/lib/AutomaticPrefetchPlugin.js +1 -0
  7. package/lib/BannerPlugin.js +1 -1
  8. package/lib/CaseSensitiveModulesWarning.js +4 -4
  9. package/lib/Chunk.js +6 -6
  10. package/lib/ChunkGraph.js +37 -31
  11. package/lib/ChunkGroup.js +4 -4
  12. package/lib/ChunkTemplate.js +1 -1
  13. package/lib/CleanPlugin.js +94 -17
  14. package/lib/CodeGenerationResults.js +1 -1
  15. package/lib/CompatibilityPlugin.js +5 -2
  16. package/lib/Compilation.js +67 -45
  17. package/lib/Compiler.js +46 -16
  18. package/lib/ConcatenationScope.js +15 -6
  19. package/lib/ConstPlugin.js +5 -3
  20. package/lib/ContextModule.js +16 -12
  21. package/lib/ContextModuleFactory.js +4 -3
  22. package/lib/ContextReplacementPlugin.js +4 -2
  23. package/lib/CssModule.js +2 -2
  24. package/lib/DefinePlugin.js +111 -3
  25. package/lib/DelegatedModuleFactoryPlugin.js +18 -18
  26. package/lib/Dependency.js +6 -1
  27. package/lib/DependencyTemplate.js +1 -0
  28. package/lib/DllEntryPlugin.js +3 -1
  29. package/lib/DllPlugin.js +4 -3
  30. package/lib/DllReferencePlugin.js +2 -2
  31. package/lib/DynamicEntryPlugin.js +1 -1
  32. package/lib/EntryOptionPlugin.js +5 -0
  33. package/lib/ErrorHelpers.js +4 -4
  34. package/lib/EvalDevToolModulePlugin.js +3 -3
  35. package/lib/EvalSourceMapDevToolPlugin.js +7 -7
  36. package/lib/ExportsInfo.js +48 -39
  37. package/lib/ExternalModule.js +15 -11
  38. package/lib/ExternalModuleFactoryPlugin.js +5 -2
  39. package/lib/FileSystemInfo.js +51 -36
  40. package/lib/FlagDependencyExportsPlugin.js +14 -7
  41. package/lib/FlagDependencyUsagePlugin.js +1 -1
  42. package/lib/Generator.js +14 -1
  43. package/lib/HookWebpackError.js +1 -0
  44. package/lib/HotModuleReplacementPlugin.js +77 -50
  45. package/lib/IgnorePlugin.js +1 -1
  46. package/lib/InvalidDependenciesModuleWarning.js +1 -1
  47. package/lib/JavascriptMetaInfoPlugin.js +0 -1
  48. package/lib/LibManifestPlugin.js +4 -2
  49. package/lib/LoaderOptionsPlugin.js +6 -4
  50. package/lib/MainTemplate.js +2 -2
  51. package/lib/Module.js +21 -6
  52. package/lib/ModuleFactory.js +1 -0
  53. package/lib/ModuleGraph.js +24 -2
  54. package/lib/ModuleGraphConnection.js +5 -5
  55. package/lib/ModuleInfoHeaderPlugin.js +2 -1
  56. package/lib/ModuleParseError.js +1 -0
  57. package/lib/ModuleSourceTypesConstants.js +12 -12
  58. package/lib/ModuleTemplate.js +1 -1
  59. package/lib/ModuleTypeConstants.js +21 -21
  60. package/lib/MultiCompiler.js +6 -6
  61. package/lib/NormalModule.js +31 -44
  62. package/lib/NormalModuleFactory.js +29 -19
  63. package/lib/NormalModuleReplacementPlugin.js +1 -1
  64. package/lib/NullFactory.js +1 -0
  65. package/lib/OptimizationStages.js +1 -1
  66. package/lib/Parser.js +1 -0
  67. package/lib/ProgressPlugin.js +12 -5
  68. package/lib/ProvidePlugin.js +5 -1
  69. package/lib/RecordIdsPlugin.js +3 -3
  70. package/lib/RuntimeGlobals.js +175 -155
  71. package/lib/RuntimeModule.js +1 -0
  72. package/lib/RuntimePlugin.js +33 -7
  73. package/lib/RuntimeTemplate.js +111 -11
  74. package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
  75. package/lib/SourceMapDevToolPlugin.js +19 -17
  76. package/lib/Template.js +2 -2
  77. package/lib/TemplatedPathPlugin.js +1 -1
  78. package/lib/WarnDeprecatedOptionPlugin.js +7 -8
  79. package/lib/WatchIgnorePlugin.js +4 -3
  80. package/lib/WebpackIsIncludedPlugin.js +2 -1
  81. package/lib/WebpackOptionsApply.js +115 -27
  82. package/lib/asset/AssetGenerator.js +15 -11
  83. package/lib/asset/AssetModulesPlugin.js +19 -17
  84. package/lib/asset/AssetSourceGenerator.js +4 -4
  85. package/lib/asset/RawDataUrlModule.js +4 -2
  86. package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
  87. package/lib/buildChunkGraph.js +6 -3
  88. package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
  89. package/lib/cache/IdleFileCachePlugin.js +7 -4
  90. package/lib/cache/MemoryCachePlugin.js +1 -0
  91. package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
  92. package/lib/cache/PackFileCacheStrategy.js +26 -20
  93. package/lib/cache/ResolverCachePlugin.js +16 -8
  94. package/lib/cli.js +15 -10
  95. package/lib/config/browserslistTargetHandler.js +3 -3
  96. package/lib/config/defaults.js +25 -17
  97. package/lib/config/normalization.js +2 -1
  98. package/lib/config/target.js +6 -5
  99. package/lib/container/ContainerPlugin.js +1 -1
  100. package/lib/container/ContainerReferencePlugin.js +1 -1
  101. package/lib/container/FallbackModule.js +2 -1
  102. package/lib/container/HoistContainerReferencesPlugin.js +1 -1
  103. package/lib/container/ModuleFederationPlugin.js +2 -2
  104. package/lib/container/RemoteModule.js +1 -1
  105. package/lib/css/CssGenerator.js +9 -6
  106. package/lib/css/CssModulesPlugin.js +44 -31
  107. package/lib/css/CssParser.js +6 -4
  108. package/lib/css/walkCssTokens.js +33 -37
  109. package/lib/debug/ProfilingPlugin.js +6 -6
  110. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
  111. package/lib/dependencies/AMDPlugin.js +12 -8
  112. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
  113. package/lib/dependencies/CachedConstDependency.js +1 -5
  114. package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
  115. package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
  116. package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
  117. package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
  118. package/lib/dependencies/CommonJsPlugin.js +15 -16
  119. package/lib/dependencies/ContextDependencyHelpers.js +2 -1
  120. package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
  121. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
  122. package/lib/dependencies/CssIcssExportDependency.js +1 -1
  123. package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
  124. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
  125. package/lib/dependencies/DynamicExports.js +9 -9
  126. package/lib/dependencies/ExportsInfoDependency.js +1 -1
  127. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
  128. package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
  129. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
  130. package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
  131. package/lib/dependencies/HarmonyImportDependency.js +11 -5
  132. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
  133. package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
  134. package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
  135. package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
  136. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
  137. package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
  138. package/lib/dependencies/ImportMetaPlugin.js +2 -2
  139. package/lib/dependencies/ImportParserPlugin.js +40 -9
  140. package/lib/dependencies/ImportPlugin.js +3 -1
  141. package/lib/dependencies/LoaderPlugin.js +1 -0
  142. package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
  143. package/lib/dependencies/RequireContextPlugin.js +3 -1
  144. package/lib/dependencies/RequireEnsurePlugin.js +6 -6
  145. package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
  146. package/lib/dependencies/RequireIncludePlugin.js +1 -0
  147. package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
  148. package/lib/dependencies/SystemPlugin.js +1 -1
  149. package/lib/dependencies/URLContextDependency.js +65 -0
  150. package/lib/dependencies/URLPlugin.js +17 -157
  151. package/lib/dependencies/WorkerPlugin.js +23 -10
  152. package/lib/dependencies/processExportInfo.js +2 -1
  153. package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
  154. package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
  155. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
  156. package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
  157. package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
  158. package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
  159. package/lib/hmr/LazyCompilationPlugin.js +4 -2
  160. package/lib/hmr/lazyCompilationBackend.js +4 -2
  161. package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
  162. package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
  163. package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
  164. package/lib/ids/HashedModuleIdsPlugin.js +5 -4
  165. package/lib/ids/IdHelpers.js +21 -17
  166. package/lib/ids/NamedChunkIdsPlugin.js +5 -5
  167. package/lib/ids/NamedModuleIdsPlugin.js +4 -4
  168. package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
  169. package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
  170. package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
  171. package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
  172. package/lib/ids/SyncModuleIdsPlugin.js +1 -1
  173. package/lib/index.js +13 -3
  174. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
  175. package/lib/javascript/BasicEvaluatedExpression.js +2 -1
  176. package/lib/javascript/ChunkHelpers.js +1 -0
  177. package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
  178. package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
  179. package/lib/javascript/JavascriptGenerator.js +14 -2
  180. package/lib/javascript/JavascriptModulesPlugin.js +68 -27
  181. package/lib/javascript/JavascriptParser.js +117 -76
  182. package/lib/javascript/JavascriptParserHelpers.js +41 -41
  183. package/lib/javascript/StartupHelpers.js +17 -17
  184. package/lib/json/JsonGenerator.js +4 -2
  185. package/lib/json/JsonModulesPlugin.js +2 -2
  186. package/lib/json/JsonParser.js +1 -1
  187. package/lib/library/AbstractLibraryPlugin.js +6 -2
  188. package/lib/library/AssignLibraryPlugin.js +21 -6
  189. package/lib/library/EnableLibraryPlugin.js +23 -3
  190. package/lib/library/UmdLibraryPlugin.js +15 -6
  191. package/lib/logging/createConsoleLogger.js +3 -3
  192. package/lib/logging/runtime.js +9 -9
  193. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
  194. package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
  195. package/lib/node/nodeConsole.js +4 -2
  196. package/lib/optimize/AggressiveMergingPlugin.js +45 -46
  197. package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
  198. package/lib/optimize/ConcatenatedModule.js +227 -57
  199. package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
  200. package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
  201. package/lib/optimize/InnerGraph.js +115 -112
  202. package/lib/optimize/InnerGraphPlugin.js +2 -2
  203. package/lib/optimize/LimitChunkCountPlugin.js +4 -2
  204. package/lib/optimize/MangleExportsPlugin.js +4 -3
  205. package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
  206. package/lib/optimize/MinChunkSizePlugin.js +6 -3
  207. package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
  208. package/lib/optimize/RealContentHashPlugin.js +26 -20
  209. package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
  210. package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
  211. package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
  212. package/lib/optimize/SplitChunksPlugin.js +16 -13
  213. package/lib/rules/BasicEffectRulePlugin.js +4 -2
  214. package/lib/rules/BasicMatcherRulePlugin.js +3 -1
  215. package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
  216. package/lib/rules/RuleSetCompiler.js +6 -3
  217. package/lib/rules/UseEffectRulePlugin.js +3 -1
  218. package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
  219. package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
  220. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
  221. package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
  222. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
  223. package/lib/schemes/FileUriPlugin.js +1 -1
  224. package/lib/schemes/HttpUriPlugin.js +27 -19
  225. package/lib/schemes/VirtualUrlPlugin.js +222 -0
  226. package/lib/serialization/AggregateErrorSerializer.js +1 -1
  227. package/lib/serialization/BinaryMiddleware.js +5 -4
  228. package/lib/serialization/FileMiddleware.js +7 -4
  229. package/lib/serialization/ObjectMiddleware.js +14 -8
  230. package/lib/serialization/Serializer.js +5 -3
  231. package/lib/serialization/SerializerMiddleware.js +2 -0
  232. package/lib/sharing/ConsumeSharedModule.js +1 -1
  233. package/lib/sharing/ConsumeSharedPlugin.js +3 -3
  234. package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
  235. package/lib/sharing/ProvideSharedModule.js +1 -1
  236. package/lib/sharing/ProvideSharedPlugin.js +3 -2
  237. package/lib/sharing/SharePlugin.js +2 -1
  238. package/lib/sharing/ShareRuntimeModule.js +3 -5
  239. package/lib/sharing/utils.js +34 -34
  240. package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
  241. package/lib/stats/DefaultStatsPresetPlugin.js +4 -2
  242. package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
  243. package/lib/stats/StatsFactory.js +4 -2
  244. package/lib/stats/StatsPrinter.js +3 -2
  245. package/lib/url/URLParserPlugin.js +266 -0
  246. package/lib/util/ArrayQueue.js +1 -1
  247. package/lib/util/AsyncQueue.js +1 -1
  248. package/lib/util/Hash.js +2 -0
  249. package/lib/util/IterableHelpers.js +1 -1
  250. package/lib/util/LazyBucketSortedSet.js +2 -1
  251. package/lib/util/LazySet.js +11 -6
  252. package/lib/util/ParallelismFactorCalculator.js +1 -1
  253. package/lib/util/SetHelpers.js +3 -3
  254. package/lib/util/SortableSet.js +2 -2
  255. package/lib/util/StackedCacheMap.js +3 -1
  256. package/lib/util/StackedMap.js +2 -2
  257. package/lib/util/StringXor.js +1 -0
  258. package/lib/util/TupleSet.js +1 -0
  259. package/lib/util/URLAbsoluteSpecifier.js +1 -1
  260. package/lib/util/cleverMerge.js +12 -8
  261. package/lib/util/comparators.js +154 -127
  262. package/lib/util/compileBooleanMatcher.js +8 -3
  263. package/lib/util/concatenate.js +8 -7
  264. package/lib/util/conventions.js +72 -73
  265. package/lib/util/create-schema-validation.js +2 -1
  266. package/lib/util/createHash.js +10 -4
  267. package/lib/util/deprecation.js +69 -66
  268. package/lib/util/deterministicGrouping.js +4 -2
  269. package/lib/util/extractUrlAndGlobal.js +1 -1
  270. package/lib/util/findGraphRoots.js +2 -2
  271. package/lib/util/fs.js +30 -23
  272. package/lib/util/hash/md4.js +2 -2
  273. package/lib/util/hash/wasm-hash.js +4 -2
  274. package/lib/util/identifier.js +13 -12
  275. package/lib/util/internalSerializables.js +2 -0
  276. package/lib/util/magicComment.js +5 -5
  277. package/lib/util/processAsyncTree.js +1 -1
  278. package/lib/util/propertyAccess.js +1 -1
  279. package/lib/util/propertyName.js +1 -1
  280. package/lib/util/registerExternalSerializer.js +1 -2
  281. package/lib/util/removeBOM.js +1 -1
  282. package/lib/util/runtime.js +29 -21
  283. package/lib/util/semver.js +1 -1
  284. package/lib/util/serialization.js +3 -0
  285. package/lib/util/source.js +3 -2
  286. package/lib/validateSchema.js +1 -0
  287. package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
  288. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
  289. package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
  290. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
  291. package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
  292. package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
  293. package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
  294. package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
  295. package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
  296. package/lib/webpack.js +4 -5
  297. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
  298. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
  299. package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
  300. package/package.json +119 -113
  301. package/schemas/WebpackOptions.check.js +1 -1
  302. package/schemas/WebpackOptions.json +17 -0
  303. package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
  304. package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
  305. package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
  306. package/types.d.ts +1230 -360
@@ -13,7 +13,7 @@ const createSchemaValidation = require("../util/create-schema-validation");
13
13
  /** @typedef {import("../Compiler")} Compiler */
14
14
 
15
15
  const validate = createSchemaValidation(
16
- require("../../schemas/plugins/optimize/MinChunkSizePlugin.check.js"),
16
+ require("../../schemas/plugins/optimize/MinChunkSizePlugin.check"),
17
17
  () => require("../../schemas/plugins/optimize/MinChunkSizePlugin.json"),
18
18
  {
19
19
  name: "Min Chunk Size Plugin",
@@ -65,13 +65,15 @@ class MinChunkSizePlugin {
65
65
  if (chunkGraph.getChunkSize(a, equalOptions) < minChunkSize) {
66
66
  smallChunks.push(a);
67
67
  for (const b of visitedChunks) {
68
- if (chunkGraph.canChunksBeIntegrated(b, a))
68
+ if (chunkGraph.canChunksBeIntegrated(b, a)) {
69
69
  combinations.push([b, a]);
70
+ }
70
71
  }
71
72
  } else {
72
73
  for (const b of smallChunks) {
73
- if (chunkGraph.canChunksBeIntegrated(b, a))
74
+ if (chunkGraph.canChunksBeIntegrated(b, a)) {
74
75
  combinations.push([b, a]);
76
+ }
75
77
  }
76
78
  }
77
79
  chunkSizesMap.set(a, chunkGraph.getChunkSize(a, options));
@@ -112,4 +114,5 @@ class MinChunkSizePlugin {
112
114
  });
113
115
  }
114
116
  }
117
+
115
118
  module.exports = MinChunkSizePlugin;
@@ -13,11 +13,11 @@ const { STAGE_DEFAULT } = require("../OptimizationStages");
13
13
  const HarmonyImportDependency = require("../dependencies/HarmonyImportDependency");
14
14
  const { compareModulesByIdentifier } = require("../util/comparators");
15
15
  const {
16
+ filterRuntime,
16
17
  intersectRuntime,
18
+ mergeRuntime,
17
19
  mergeRuntimeOwned,
18
- filterRuntime,
19
- runtimeToString,
20
- mergeRuntime
20
+ runtimeToString
21
21
  } = require("../util/runtime");
22
22
  const ConcatenatedModule = require("./ConcatenatedModule");
23
23
 
@@ -223,6 +223,11 @@ class ModuleConcatenationPlugin {
223
223
  canBeInner = false;
224
224
  }
225
225
 
226
+ if (moduleGraph.isDeferred(module)) {
227
+ setInnerBailoutReason(module, "Module is deferred");
228
+ canBeInner = false;
229
+ }
230
+
226
231
  if (canBeRoot) relevantModules.push(module);
227
232
  if (canBeInner) possibleInners.add(module);
228
233
  }
@@ -585,25 +590,27 @@ class ModuleConcatenationPlugin {
585
590
  }
586
591
 
587
592
  // Module must be in the correct chunks
588
- const missingChunks = Array.from(
589
- chunkGraph.getModuleChunksIterable(config.rootModule)
590
- ).filter(chunk => !chunkGraph.isModuleInChunk(module, chunk));
593
+ const missingChunks = [
594
+ ...chunkGraph.getModuleChunksIterable(config.rootModule)
595
+ ].filter(chunk => !chunkGraph.isModuleInChunk(module, chunk));
591
596
  if (missingChunks.length > 0) {
592
597
  /**
593
598
  * @param {RequestShortener} requestShortener request shortener
594
599
  * @returns {string} problem description
595
600
  */
596
601
  const problem = requestShortener => {
597
- const missingChunksList = Array.from(
598
- new Set(missingChunks.map(chunk => chunk.name || "unnamed chunk(s)"))
599
- ).sort();
600
- const chunks = Array.from(
601
- new Set(
602
- Array.from(chunkGraph.getModuleChunksIterable(module)).map(
602
+ const missingChunksList = [
603
+ ...new Set(
604
+ missingChunks.map(chunk => chunk.name || "unnamed chunk(s)")
605
+ )
606
+ ].sort();
607
+ const chunks = [
608
+ ...new Set(
609
+ [...chunkGraph.getModuleChunksIterable(module)].map(
603
610
  chunk => chunk.name || "unnamed chunk(s)"
604
611
  )
605
612
  )
606
- ).sort();
613
+ ].sort();
607
614
  return `Module ${module.readableIdentifier(
608
615
  requestShortener
609
616
  )} is not in the same chunk(s) (expected in chunk(s) ${missingChunksList.join(
@@ -638,7 +645,7 @@ class ModuleConcatenationPlugin {
638
645
  const importingExplanations = new Set(
639
646
  activeNonModulesConnections.map(c => c.explanation).filter(Boolean)
640
647
  );
641
- const explanations = Array.from(importingExplanations).sort();
648
+ const explanations = [...importingExplanations].sort();
642
649
  return `Module ${module.readableIdentifier(
643
650
  requestShortener
644
651
  )} is referenced ${
@@ -672,12 +679,13 @@ class ModuleConcatenationPlugin {
672
679
  const activeConnections = connections.filter(connection =>
673
680
  connection.isActive(runtime)
674
681
  );
675
- if (activeConnections.length > 0)
682
+ if (activeConnections.length > 0) {
676
683
  incomingConnectionsFromModules.set(originModule, activeConnections);
684
+ }
677
685
  }
678
686
  }
679
687
 
680
- const incomingModules = Array.from(incomingConnectionsFromModules.keys());
688
+ const incomingModules = [...incomingConnectionsFromModules.keys()];
681
689
 
682
690
  // Module must be in the same chunks like the referencing module
683
691
  const otherChunkModules = incomingModules.filter(originModule => {
@@ -718,8 +726,9 @@ class ModuleConcatenationPlugin {
718
726
  !connection.dependency ||
719
727
  !(connection.dependency instanceof HarmonyImportDependency)
720
728
  );
721
- if (selected.length > 0)
729
+ if (selected.length > 0) {
722
730
  nonHarmonyConnections.set(originModule, connections);
731
+ }
723
732
  }
724
733
  if (nonHarmonyConnections.size > 0) {
725
734
  /**
@@ -727,18 +736,18 @@ class ModuleConcatenationPlugin {
727
736
  * @returns {string} problem description
728
737
  */
729
738
  const problem = requestShortener => {
730
- const names = Array.from(nonHarmonyConnections)
739
+ const names = [...nonHarmonyConnections]
731
740
  .map(
732
741
  ([originModule, connections]) =>
733
742
  `${originModule.readableIdentifier(
734
743
  requestShortener
735
- )} (referenced with ${Array.from(
736
- new Set(
744
+ )} (referenced with ${[
745
+ ...new Set(
737
746
  connections
738
747
  .map(c => c.dependency && c.dependency.type)
739
748
  .filter(Boolean)
740
749
  )
741
- )
750
+ ]
742
751
  .sort()
743
752
  .join(", ")})`
744
753
  )
@@ -898,7 +907,7 @@ class ConcatConfiguration {
898
907
  */
899
908
  getWarningsSorted() {
900
909
  return new Map(
901
- Array.from(this.warnings).sort((a, b) => {
910
+ [...this.warnings].sort((a, b) => {
902
911
  const ai = a[0].identifier();
903
912
  const bi = b[0].identifier();
904
913
  if (ai < bi) return -1;
@@ -6,7 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const { SyncBailHook } = require("tapable");
9
- const { RawSource, CachedSource, CompatSource } = require("webpack-sources");
9
+ const { CachedSource, CompatSource, RawSource } = require("webpack-sources");
10
10
  const Compilation = require("../Compilation");
11
11
  const WebpackError = require("../WebpackError");
12
12
  const { compareSelect, compareStrings } = require("../util/comparators");
@@ -214,7 +214,7 @@ class RealContentHashPlugin {
214
214
  }
215
215
  const etag = cacheAnalyse.mergeEtags(
216
216
  cacheAnalyse.getLazyHashedEtag(source),
217
- Array.from(hashes).join("|")
217
+ [...hashes].join("|")
218
218
  );
219
219
  [asset.referencedHashes, asset.ownHashes] =
220
220
  await cacheAnalyse.providePromise(name, etag, () => {
@@ -288,6 +288,7 @@ ${referencingAssets
288
288
  a => a.name
289
289
  )})`;
290
290
  };
291
+ /** @type {Set<string>} */
291
292
  const hashesInOrder = new Set();
292
293
  for (const hash of hashToAssets.keys()) {
293
294
  /**
@@ -316,6 +317,7 @@ ${referencingAssets
316
317
  if (hashesInOrder.has(hash)) continue;
317
318
  add(hash, new Set());
318
319
  }
320
+ /** @type {Map<string, string>} */
319
321
  const hashToNewHash = new Map();
320
322
  /**
321
323
  * @param {AssetInfoForRealContentHash} asset asset info
@@ -338,10 +340,9 @@ ${referencingAssets
338
340
  return (asset.contentComputePromise = (async () => {
339
341
  if (
340
342
  /** @type {OwnHashes} */ (asset.ownHashes).size > 0 ||
341
- Array.from(
342
- /** @type {ReferencedHashes} */
343
- (asset.referencedHashes)
344
- ).some(hash => hashToNewHash.get(hash) !== hash)
343
+ [
344
+ .../** @type {ReferencedHashes} */ (asset.referencedHashes)
345
+ ].some(hash => hashToNewHash.get(hash) !== hash)
345
346
  ) {
346
347
  const identifier = asset.name;
347
348
  const etag = getEtag(asset);
@@ -349,8 +350,9 @@ ${referencingAssets
349
350
  identifier,
350
351
  etag,
351
352
  () => {
352
- const newContent = asset.content.replace(hashRegExp, hash =>
353
- hashToNewHash.get(hash)
353
+ const newContent = asset.content.replace(
354
+ hashRegExp,
355
+ hash => /** @type {string} */ (hashToNewHash.get(hash))
354
356
  );
355
357
  return new RawSource(newContent);
356
358
  }
@@ -363,15 +365,15 @@ ${referencingAssets
363
365
  * @returns {Promise<void>}
364
366
  */
365
367
  const computeNewContentWithoutOwn = asset => {
366
- if (asset.contentComputeWithoutOwnPromise)
368
+ if (asset.contentComputeWithoutOwnPromise) {
367
369
  return asset.contentComputeWithoutOwnPromise;
370
+ }
368
371
  return (asset.contentComputeWithoutOwnPromise = (async () => {
369
372
  if (
370
373
  /** @type {OwnHashes} */ (asset.ownHashes).size > 0 ||
371
- Array.from(
372
- /** @type {ReferencedHashes} */
373
- (asset.referencedHashes)
374
- ).some(hash => hashToNewHash.get(hash) !== hash)
374
+ [
375
+ .../** @type {ReferencedHashes} */ (asset.referencedHashes)
376
+ ].some(hash => hashToNewHash.get(hash) !== hash)
375
377
  ) {
376
378
  const identifier = `${asset.name}|without-own`;
377
379
  const etag = getEtag(asset);
@@ -383,11 +385,12 @@ ${referencingAssets
383
385
  hashRegExp,
384
386
  hash => {
385
387
  if (
386
- /** @type {OwnHashes} */ (asset.ownHashes).has(hash)
388
+ /** @type {OwnHashes} */
389
+ (asset.ownHashes).has(hash)
387
390
  ) {
388
391
  return "";
389
392
  }
390
- return hashToNewHash.get(hash);
393
+ return /** @type {string} */ (hashToNewHash.get(hash));
391
394
  }
392
395
  );
393
396
  return new RawSource(newContent);
@@ -436,15 +439,18 @@ ${referencingAssets
436
439
  await Promise.all(
437
440
  assetsWithInfo.map(async asset => {
438
441
  await computeNewContent(asset);
439
- const newName = asset.name.replace(hashRegExp, hash =>
440
- hashToNewHash.get(hash)
442
+ const newName = asset.name.replace(
443
+ hashRegExp,
444
+ hash => /** @type {string} */ (hashToNewHash.get(hash))
441
445
  );
442
446
 
443
447
  const infoUpdate = {};
444
- const hash = asset.info.contenthash;
448
+ const hash = /** @type {string} */ (asset.info.contenthash);
445
449
  infoUpdate.contenthash = Array.isArray(hash)
446
- ? hash.map(hash => hashToNewHash.get(hash))
447
- : hashToNewHash.get(hash);
450
+ ? hash.map(
451
+ hash => /** @type {string} */ (hashToNewHash.get(hash))
452
+ )
453
+ : /** @type {string} */ (hashToNewHash.get(hash));
448
454
 
449
455
  if (asset.newSource !== undefined) {
450
456
  compilation.updateAsset(
@@ -5,7 +5,7 @@
5
5
 
6
6
  "use strict";
7
7
 
8
- const { STAGE_BASIC, STAGE_ADVANCED } = require("../OptimizationStages");
8
+ const { STAGE_ADVANCED, STAGE_BASIC } = require("../OptimizationStages");
9
9
 
10
10
  /** @typedef {import("../Chunk")} Chunk */
11
11
  /** @typedef {import("../Compiler")} Compiler */
@@ -56,4 +56,5 @@ class RemoveEmptyChunksPlugin {
56
56
  });
57
57
  }
58
58
  }
59
+
59
60
  module.exports = RemoveEmptyChunksPlugin;
@@ -203,4 +203,5 @@ class RemoveParentModulesPlugin {
203
203
  });
204
204
  }
205
205
  }
206
+
206
207
  module.exports = RemoveParentModulesPlugin;
@@ -8,8 +8,8 @@
8
8
  const glob2regexp = require("glob-to-regexp");
9
9
  const {
10
10
  JAVASCRIPT_MODULE_TYPE_AUTO,
11
- JAVASCRIPT_MODULE_TYPE_ESM,
12
- JAVASCRIPT_MODULE_TYPE_DYNAMIC
11
+ JAVASCRIPT_MODULE_TYPE_DYNAMIC,
12
+ JAVASCRIPT_MODULE_TYPE_ESM
13
13
  } = require("../ModuleTypeConstants");
14
14
  const { STAGE_DEFAULT } = require("../OptimizationStages");
15
15
  const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
@@ -400,4 +400,5 @@ class SideEffectsFlagPlugin {
400
400
  }
401
401
  }
402
402
  }
403
+
403
404
  module.exports = SideEffectsFlagPlugin;
@@ -12,8 +12,8 @@ const { requestToId } = require("../ids/IdHelpers");
12
12
  const { isSubset } = require("../util/SetHelpers");
13
13
  const SortableSet = require("../util/SortableSet");
14
14
  const {
15
- compareModulesByIdentifier,
16
- compareIterables
15
+ compareIterables,
16
+ compareModulesByIdentifier
17
17
  } = require("../util/comparators");
18
18
  const createHash = require("../util/createHash");
19
19
  const deterministicGrouping = require("../util/deterministicGrouping");
@@ -279,10 +279,10 @@ const INITIAL_CHUNK_FILTER = chunk => chunk.canBeInitial();
279
279
  */
280
280
  const ASYNC_CHUNK_FILTER = chunk => !chunk.canBeInitial();
281
281
  /**
282
- * @param {Chunk} chunk the chunk
282
+ * @param {Chunk} _chunk the chunk
283
283
  * @returns {boolean} always true
284
284
  */
285
- const ALL_CHUNK_FILTER = chunk => true;
285
+ const ALL_CHUNK_FILTER = _chunk => true;
286
286
 
287
287
  /**
288
288
  * @param {OptimizationSplitChunksSizes | undefined} value the sizes
@@ -853,7 +853,7 @@ module.exports = class SplitChunksPlugin {
853
853
  chunk,
854
854
  index | BigInt((Math.random() * 0x7fffffff) | 0)
855
855
  );
856
- index = index << ONE;
856
+ index <<= ONE;
857
857
  }
858
858
  /**
859
859
  * @param {Iterable<Chunk>} chunks list of chunks
@@ -871,7 +871,7 @@ module.exports = class SplitChunksPlugin {
871
871
  /** @type {bigint} */ (chunkIndexMap.get(result.value));
872
872
  while (!(result = iterator.next()).done) {
873
873
  const raw = chunkIndexMap.get(result.value);
874
- key = key ^ /** @type {bigint} */ (raw);
874
+ key ^= /** @type {bigint} */ (raw);
875
875
  }
876
876
  return key;
877
877
  };
@@ -931,7 +931,7 @@ module.exports = class SplitChunksPlugin {
931
931
  /** @type {Set<Chunk>} */
932
932
  const singleChunkSets = new Set();
933
933
  for (const module of compilation.modules) {
934
- const groupedChunks = Array.from(groupChunksByExports(module));
934
+ const groupedChunks = [...groupChunksByExports(module)];
935
935
  groupedByExportsMap.set(module, groupedChunks);
936
936
  for (const chunks of groupedChunks) {
937
937
  if (chunks.length === 1) {
@@ -1270,8 +1270,9 @@ module.exports = class SplitChunksPlugin {
1270
1270
  (groupedByExportsMap.get(module));
1271
1271
  for (const chunks of groupedByUsedExports) {
1272
1272
  const chunksKey = getKey(chunks);
1273
- for (const comb of getExportsCombinations(chunksKey))
1273
+ for (const comb of getExportsCombinations(chunksKey)) {
1274
1274
  set.add(comb);
1275
+ }
1275
1276
  }
1276
1277
  return set;
1277
1278
  });
@@ -1489,10 +1490,11 @@ module.exports = class SplitChunksPlugin {
1489
1490
  // Were some (invalid) chunks removed from usedChunks?
1490
1491
  // => readd all modules to the queue, as things could have been changed
1491
1492
  if (usedChunks.size < item.chunks.size) {
1492
- if (isExistingChunk)
1493
+ if (isExistingChunk) {
1493
1494
  usedChunks.add(/** @type {Chunk} */ (newChunk));
1495
+ }
1494
1496
  if (usedChunks.size >= item.cacheGroup.minChunks) {
1495
- const chunksArr = Array.from(usedChunks);
1497
+ const chunksArr = [...usedChunks];
1496
1498
  for (const module of item.modules) {
1497
1499
  addModuleToChunksInfoMap(
1498
1500
  item.cacheGroup,
@@ -1618,7 +1620,7 @@ module.exports = class SplitChunksPlugin {
1618
1620
  : item.cacheGroup.maxInitialSize,
1619
1621
  automaticNameDelimiter: item.cacheGroup.automaticNameDelimiter,
1620
1622
  keys: oldMaxSizeSettings
1621
- ? oldMaxSizeSettings.keys.concat(item.cacheGroup.key)
1623
+ ? [...oldMaxSizeSettings.keys, item.cacheGroup.key]
1622
1624
  : [item.cacheGroup.key]
1623
1625
  });
1624
1626
  }
@@ -1672,7 +1674,7 @@ module.exports = class SplitChunksPlugin {
1672
1674
 
1673
1675
  // Make sure that maxSize is fulfilled
1674
1676
  const { fallbackCacheGroup } = this.options;
1675
- for (const chunk of Array.from(compilation.chunks)) {
1677
+ for (const chunk of compilation.chunks) {
1676
1678
  const chunkConfig = maxSizeQueueMap.get(chunk);
1677
1679
  const {
1678
1680
  minSize,
@@ -1680,8 +1682,9 @@ module.exports = class SplitChunksPlugin {
1680
1682
  maxInitialSize,
1681
1683
  automaticNameDelimiter
1682
1684
  } = chunkConfig || fallbackCacheGroup;
1683
- if (!chunkConfig && !fallbackCacheGroup.chunksFilter(chunk))
1685
+ if (!chunkConfig && !fallbackCacheGroup.chunksFilter(chunk)) {
1684
1686
  continue;
1687
+ }
1685
1688
  /** @type {SplitChunksSizes} */
1686
1689
  let maxSize;
1687
1690
  if (chunk.isOnlyInitial()) {
@@ -16,6 +16,8 @@
16
16
 
17
17
  /** @typedef {KeysOfTypes<RuleSetRule, string | boolean | { [k: string]: EXPECTED_ANY }>} BasicEffectRuleKeys */
18
18
 
19
+ const PLUGIN_NAME = "BasicEffectRulePlugin";
20
+
19
21
  class BasicEffectRulePlugin {
20
22
  /**
21
23
  * @param {BasicEffectRuleKeys} ruleProperty the rule property
@@ -32,8 +34,8 @@ class BasicEffectRulePlugin {
32
34
  */
33
35
  apply(ruleSetCompiler) {
34
36
  ruleSetCompiler.hooks.rule.tap(
35
- "BasicEffectRulePlugin",
36
- (path, rule, unhandledProperties, result, references) => {
37
+ PLUGIN_NAME,
38
+ (path, rule, unhandledProperties, result) => {
37
39
  if (unhandledProperties.has(this.ruleProperty)) {
38
40
  unhandledProperties.delete(this.ruleProperty);
39
41
 
@@ -20,6 +20,8 @@
20
20
 
21
21
  /** @typedef {KeysOfTypes<RuleSetRule, RuleSetConditionOrConditions | RuleSetConditionOrConditionsAbsolute>} BasicMatcherRuleKeys */
22
22
 
23
+ const PLUGIN_NAME = "BasicMatcherRulePlugin";
24
+
23
25
  class BasicMatcherRulePlugin {
24
26
  /**
25
27
  * @param {BasicMatcherRuleKeys} ruleProperty the rule property
@@ -38,7 +40,7 @@ class BasicMatcherRulePlugin {
38
40
  */
39
41
  apply(ruleSetCompiler) {
40
42
  ruleSetCompiler.hooks.rule.tap(
41
- "BasicMatcherRulePlugin",
43
+ PLUGIN_NAME,
42
44
  (path, rule, unhandledProperties, result) => {
43
45
  if (unhandledProperties.has(this.ruleProperty)) {
44
46
  unhandledProperties.delete(this.ruleProperty);
@@ -20,6 +20,8 @@
20
20
 
21
21
  /** @typedef {KeysOfTypes<RuleSetRule, { [k: string]: RuleSetConditionOrConditions }>} ObjectMatcherRuleKeys */
22
22
 
23
+ const PLUGIN_NAME = "ObjectMatcherRulePlugin";
24
+
23
25
  class ObjectMatcherRulePlugin {
24
26
  /**
25
27
  * @param {ObjectMatcherRuleKeys} ruleProperty the rule property
@@ -39,7 +41,7 @@ class ObjectMatcherRulePlugin {
39
41
  apply(ruleSetCompiler) {
40
42
  const { ruleProperty, dataProperty } = this;
41
43
  ruleSetCompiler.hooks.rule.tap(
42
- "ObjectMatcherRulePlugin",
44
+ PLUGIN_NAME,
43
45
  (path, rule, unhandledProperties, result) => {
44
46
  if (unhandledProperties.has(ruleProperty)) {
45
47
  unhandledProperties.delete(ruleProperty);
@@ -208,6 +208,7 @@ class RuleSetCompiler {
208
208
  * @returns {CompiledRule} normalized and compiled rule for processing
209
209
  */
210
210
  compileRule(path, rule, refs) {
211
+ /** @type {Set<string>} */
211
212
  const unhandledProperties = new Set(
212
213
  Object.keys(rule).filter(
213
214
  key => rule[/** @type {keyof RuleSetRule} */ (key)] !== undefined
@@ -227,16 +228,18 @@ class RuleSetCompiler {
227
228
  if (unhandledProperties.has("rules")) {
228
229
  unhandledProperties.delete("rules");
229
230
  const rules = rule.rules;
230
- if (!Array.isArray(rules))
231
+ if (!Array.isArray(rules)) {
231
232
  throw this.error(path, rules, "Rule.rules must be an array of rules");
233
+ }
232
234
  compiledRule.rules = this.compileRules(`${path}.rules`, rules, refs);
233
235
  }
234
236
 
235
237
  if (unhandledProperties.has("oneOf")) {
236
238
  unhandledProperties.delete("oneOf");
237
239
  const oneOf = rule.oneOf;
238
- if (!Array.isArray(oneOf))
240
+ if (!Array.isArray(oneOf)) {
239
241
  throw this.error(path, oneOf, "Rule.oneOf must be an array of rules");
242
+ }
240
243
  compiledRule.oneOf = this.compileRules(`${path}.oneOf`, oneOf, refs);
241
244
  }
242
245
 
@@ -244,7 +247,7 @@ class RuleSetCompiler {
244
247
  throw this.error(
245
248
  path,
246
249
  rule,
247
- `Properties ${Array.from(unhandledProperties).join(", ")} are unknown`
250
+ `Properties ${[...unhandledProperties].join(", ")} are unknown`
248
251
  );
249
252
  }
250
253
 
@@ -17,6 +17,8 @@ const util = require("util");
17
17
  /** @typedef {import("./RuleSetCompiler").Effect} Effect */
18
18
  /** @typedef {import("./RuleSetCompiler").EffectData} EffectData */
19
19
 
20
+ const PLUGIN_NAME = "UseEffectRulePlugin";
21
+
20
22
  class UseEffectRulePlugin {
21
23
  /**
22
24
  * @param {RuleSetCompiler} ruleSetCompiler the rule set compiler
@@ -24,7 +26,7 @@ class UseEffectRulePlugin {
24
26
  */
25
27
  apply(ruleSetCompiler) {
26
28
  ruleSetCompiler.hooks.rule.tap(
27
- "UseEffectRulePlugin",
29
+ PLUGIN_NAME,
28
30
  (path, rule, unhandledProperties, result, references) => {
29
31
  /**
30
32
  * @param {keyof RuleSetRule} property property
@@ -11,8 +11,12 @@ const HelperRuntimeModule = require("./HelperRuntimeModule");
11
11
  /** @typedef {import("../Compilation")} Compilation */
12
12
 
13
13
  class AsyncModuleRuntimeModule extends HelperRuntimeModule {
14
- constructor() {
14
+ /**
15
+ * @param {boolean=} deferInterop if defer import is used.
16
+ */
17
+ constructor(deferInterop = false) {
15
18
  super("async module");
19
+ this._deferInterop = deferInterop;
16
20
  }
17
21
 
18
22
  /**
@@ -22,10 +26,20 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
22
26
  const compilation = /** @type {Compilation} */ (this.compilation);
23
27
  const { runtimeTemplate } = compilation;
24
28
  const fn = RuntimeGlobals.asyncModule;
29
+ const defer = this._deferInterop;
25
30
  return Template.asString([
26
- 'var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__";',
27
- `var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "${RuntimeGlobals.exports}";`,
28
- 'var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";',
31
+ 'var hasSymbol = typeof Symbol === "function";',
32
+ 'var webpackQueues = hasSymbol ? Symbol("webpack queues") : "__webpack_queues__";',
33
+ `var webpackExports = ${
34
+ defer ? `${RuntimeGlobals.asyncModuleExportSymbol}= ` : ""
35
+ }hasSymbol ? Symbol("webpack exports") : "${RuntimeGlobals.exports}";`,
36
+ 'var webpackError = hasSymbol ? Symbol("webpack error") : "__webpack_error__";',
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__";`
42
+ : "",
29
43
  `var resolveQueue = ${runtimeTemplate.basicFunction("queue", [
30
44
  "if(queue && queue.d < 1) {",
31
45
  Template.indent([
@@ -45,6 +59,39 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
45
59
  `deps.map(${runtimeTemplate.basicFunction("dep", [
46
60
  'if(dep !== null && typeof dep === "object") {',
47
61
  Template.indent([
62
+ defer
63
+ ? Template.asString([
64
+ "if(!dep[webpackQueues] && dep[webpackDefer]) {",
65
+ 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) {",
75
+ Template.indent([
76
+ "var d = dep;",
77
+ "dep = {",
78
+ Template.indent([
79
+ "then(callback) {",
80
+ Template.indent([
81
+ "Promise.all(asyncDeps.map(__webpack_require__))",
82
+ `.then(${runtimeTemplate.returningFunction(
83
+ "callback(d)"
84
+ )});`
85
+ ]),
86
+ "}"
87
+ ]),
88
+ "};"
89
+ ]),
90
+ "} else return dep;"
91
+ ]),
92
+ "}"
93
+ ])
94
+ : "",
48
95
  "if(dep[webpackQueues]) return dep;",
49
96
  "if(dep.then) {",
50
97
  Template.indent([
@@ -58,6 +105,7 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
58
105
  "resolveQueue(queue);"
59
106
  ])});`,
60
107
  "var obj = {};",
108
+ defer ? "obj[webpackDefer] = false;" : "",
61
109
  `obj[webpackQueues] = ${runtimeTemplate.expressionFunction(
62
110
  "fn(queue)",
63
111
  "fn"
@@ -92,11 +140,12 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
92
140
  "fn"
93
141
  )};`,
94
142
  "module.exports = promise;",
95
- `body(${runtimeTemplate.basicFunction("deps", [
143
+ `var handle = ${runtimeTemplate.basicFunction("deps", [
96
144
  "currentDeps = wrapDeps(deps);",
97
145
  "var fn;",
98
146
  `var getResult = ${runtimeTemplate.returningFunction(
99
147
  `currentDeps.map(${runtimeTemplate.basicFunction("d", [
148
+ defer ? "if(d[webpackDefer]) return d;" : "",
100
149
  "if(d[webpackError]) throw d[webpackError];",
101
150
  "return d[webpackExports];"
102
151
  ])})`
@@ -114,16 +163,22 @@ class AsyncModuleRuntimeModule extends HelperRuntimeModule {
114
163
  "q"
115
164
  )};`,
116
165
  `currentDeps.map(${runtimeTemplate.expressionFunction(
117
- "dep[webpackQueues](fnQueue)",
166
+ `${
167
+ defer ? "dep[webpackDefer]||" : ""
168
+ }dep[webpackQueues](fnQueue)`,
118
169
  "dep"
119
170
  )});`
120
171
  ]
121
172
  )});`,
122
173
  "return fn.r ? promise : getResult();"
123
- ])}, ${runtimeTemplate.expressionFunction(
124
- "(err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)",
174
+ ])}`,
175
+ `var done = ${runtimeTemplate.expressionFunction(
176
+ `(err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)${
177
+ defer ? ", promise[webpackDone] = true" : ""
178
+ }`,
125
179
  "err"
126
- )});`,
180
+ )}`,
181
+ "body(handle, done);",
127
182
  "queue && queue.d < 0 && (queue.d = 0);"
128
183
  ])};`
129
184
  ]);
@@ -49,7 +49,7 @@ class CreateFakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
49
49
  `${RuntimeGlobals.makeNamespaceObject}(ns);`,
50
50
  "var def = {};",
51
51
  "leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];",
52
- "for(var current = mode & 2 && value; typeof current == 'object' && !~leafPrototypes.indexOf(current); current = getProto(current)) {",
52
+ "for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) {",
53
53
  Template.indent([
54
54
  `Object.getOwnPropertyNames(current).forEach(${runtimeTemplate.expressionFunction(
55
55
  `def[key] = ${runtimeTemplate.returningFunction("value[key]", "")}`,