webpack 5.110.2 → 5.111.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 (226) hide show
  1. package/README.md +5 -2
  2. package/lib/APIPlugin.js +23 -7
  3. package/lib/AutomaticPrefetchPlugin.js +1 -1
  4. package/lib/Cache.js +8 -3
  5. package/lib/CacheFacade.js +1 -1
  6. package/lib/ChunkGraph.js +20 -18
  7. package/lib/CircularModulesPlugin.js +157 -55
  8. package/lib/CleanPlugin.js +2 -2
  9. package/lib/Compilation.js +321 -303
  10. package/lib/Compiler.js +209 -46
  11. package/lib/ConcatenationScope.js +25 -35
  12. package/lib/ContextModule.js +17 -81
  13. package/lib/ContextModuleFactory.js +1 -1
  14. package/lib/CopyPlugin.js +1054 -0
  15. package/lib/DefinePlugin.js +24 -8
  16. package/lib/DotenvPlugin.js +41 -13
  17. package/lib/ExternalModule.js +41 -14
  18. package/lib/FileSystemInfo.js +17 -14
  19. package/lib/FlagDependencyExportsPlugin.js +45 -21
  20. package/lib/FlagDependencyUsagePlugin.js +8 -2
  21. package/lib/HotModuleReplacementPlugin.js +53 -7
  22. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  23. package/lib/MainTemplate.js +5 -1
  24. package/lib/Module.js +16 -7
  25. package/lib/MultiCompiler.js +1 -1
  26. package/lib/MultiWatching.js +1 -1
  27. package/lib/NormalModule.js +58 -32
  28. package/lib/NormalModuleFactory.js +1 -1
  29. package/lib/RuntimeGlobals.js +21 -7
  30. package/lib/RuntimeModule.js +28 -12
  31. package/lib/RuntimePlugin.js +33 -3
  32. package/lib/RuntimeTemplate.js +794 -477
  33. package/lib/SourceMapDevToolPlugin.js +1 -1
  34. package/lib/Watching.js +9 -0
  35. package/lib/WebpackOptionsApply.js +84 -91
  36. package/lib/asset/AssetGenerator.js +25 -8
  37. package/lib/asset/AssetModule.js +3 -0
  38. package/lib/asset/WebManifestParser.js +7 -5
  39. package/lib/async-modules/AsyncModuleHelpers.js +10 -4
  40. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  41. package/lib/cache/IdleFileCachePlugin.js +2 -2
  42. package/lib/cache/PackFileCacheStrategy.js +14 -1
  43. package/lib/config/browserslistTargetHandler.js +19 -0
  44. package/lib/config/defaults.js +110 -64
  45. package/lib/config/normalization.js +100 -20
  46. package/lib/config/target.js +10 -0
  47. package/lib/container/ContainerReferencePlugin.js +6 -0
  48. package/lib/container/RemoteRuntimeModule.js +9 -0
  49. package/lib/container/declaredRemotes.js +39 -0
  50. package/lib/css/CssGenerator.js +8 -0
  51. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  52. package/lib/css/CssLoadingRuntimeModule.js +94 -36
  53. package/lib/css/CssModule.js +1 -1
  54. package/lib/css/CssModulesPlugin.js +7 -6
  55. package/lib/css/CssParser.js +144 -11
  56. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  57. package/lib/css/cssMinify.js +11 -3
  58. package/lib/css/data.js +2814 -678
  59. package/lib/css/syntax.js +4082 -248
  60. package/lib/debug/ProfilingPlugin.js +4 -0
  61. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  62. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  63. package/lib/dependencies/CommonJsExportRequireDependency.js +3 -1
  64. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  65. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -0
  66. package/lib/dependencies/CommonJsPlugin.js +19 -3
  67. package/lib/dependencies/CommonJsRequireDependency.js +32 -9
  68. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +20 -7
  69. package/lib/dependencies/CssIcssExportDependency.js +7 -1
  70. package/lib/dependencies/HarmonyCompatibilityDependency.js +58 -4
  71. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -3
  72. package/lib/dependencies/HarmonyExportExpressionDependency.js +44 -29
  73. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +171 -32
  74. package/lib/dependencies/HarmonyExportInitFragment.js +99 -19
  75. package/lib/dependencies/HarmonyExportSpecifierDependency.js +18 -30
  76. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  77. package/lib/dependencies/HarmonyImportDependency.js +99 -41
  78. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +20 -3
  79. package/lib/dependencies/HarmonyImportSpecifierDependency.js +24 -1
  80. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  81. package/lib/dependencies/HtmlEntryDependency.js +62 -2
  82. package/lib/dependencies/ImportContextDependency.js +43 -3
  83. package/lib/dependencies/ImportDependency.js +8 -29
  84. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  85. package/lib/dependencies/ImportMetaPlugin.js +59 -15
  86. package/lib/dependencies/ImportParserPlugin.js +24 -14
  87. package/lib/dependencies/RequireHeaderDependency.js +20 -21
  88. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  89. package/lib/dependencies/WorkerDependency.js +1 -2
  90. package/lib/dependencies/WorkletDependency.js +1 -2
  91. package/lib/dependencies/importOptionsCheck.js +47 -0
  92. package/lib/dll/DelegatedModule.js +18 -1
  93. package/lib/dll/DllReferencePlugin.js +11 -8
  94. package/lib/dll/LibManifestPlugin.js +1 -1
  95. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  96. package/lib/errors/DotenvFileError.js +29 -0
  97. package/lib/errors/DuplicateModulesWarning.js +12 -7
  98. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  99. package/lib/errors/ExternalStarReexportError.js +44 -0
  100. package/lib/errors/ImportedBindingAssignmentError.js +30 -0
  101. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  102. package/lib/errors/ModuleParseError.js +2 -1
  103. package/lib/errors/UnusedAssetsWarning.js +36 -0
  104. package/lib/errors/UnusedFederationWarning.js +35 -0
  105. package/lib/errors/UnusedModulesWarning.js +38 -0
  106. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  107. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  108. package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
  109. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
  110. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  111. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  112. package/lib/html/HtmlGenerator.js +11 -5
  113. package/lib/html/HtmlModulesPlugin.js +360 -84
  114. package/lib/html/HtmlParser.js +13 -6
  115. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  116. package/lib/html/data.js +121 -7
  117. package/lib/html/htmlMinify.js +84 -113
  118. package/lib/html/syntax.js +1067 -569
  119. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  120. package/lib/index.js +3 -0
  121. package/lib/javascript/JavascriptModule.js +1 -0
  122. package/lib/javascript/JavascriptModulesPlugin.js +52 -22
  123. package/lib/javascript/JavascriptParser.js +1255 -728
  124. package/lib/javascript/StartupHelpers.js +27 -3
  125. package/lib/javascript/data.js +172 -0
  126. package/lib/javascript/grammar.js +5546 -0
  127. package/lib/javascript/parser.js +1494 -0
  128. package/lib/javascript/regexp.js +1762 -0
  129. package/lib/javascript/regexpData.js +51 -0
  130. package/lib/javascript/syntax.js +8696 -5225
  131. package/lib/library/ModuleLibraryPlugin.js +116 -5
  132. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  133. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  134. package/lib/optimize/ConcatenatedModule.js +133 -25
  135. package/lib/optimize/ConstExportsPlugin.js +50 -39
  136. package/lib/optimize/InlineExports.js +20 -123
  137. package/lib/optimize/MangleExportsPlugin.js +10 -0
  138. package/lib/optimize/ModuleConcatenationPlugin.js +24 -1
  139. package/lib/optimize/RealContentHashPlugin.js +68 -9
  140. package/lib/optimize/SideEffectsFlagPlugin.js +17 -9
  141. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  142. package/lib/performance/CacheEffectivenessPlugin.js +4 -3
  143. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  144. package/lib/performance/EvalUsagePlugin.js +5 -2
  145. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  146. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  147. package/lib/performance/TopLevelThisPlugin.js +5 -4
  148. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  149. package/lib/performance/UnusedFederationPlugin.js +147 -0
  150. package/lib/performance/UnusedModulesPlugin.js +141 -0
  151. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  152. package/lib/performance/isOnlyReexported.js +65 -0
  153. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  154. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +2 -0
  155. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  156. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  157. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  158. package/lib/prefetch/ResourceHintPlugin.js +7 -3
  159. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  160. package/lib/prefetch/StartupAssetHintRuntimeModule.js +9 -0
  161. package/lib/rules/RuleSetCompiler.js +211 -4
  162. package/lib/runtime/AsyncModuleRuntimeModule.js +105 -67
  163. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  164. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  165. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  166. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  167. package/lib/runtime/GetChunkFilenameRuntimeModule.js +9 -0
  168. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  169. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  170. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  171. package/lib/runtime/GlobalRuntimeModule.js +9 -0
  172. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  173. package/lib/runtime/HelperRuntimeModule.js +10 -0
  174. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +338 -217
  175. package/lib/runtime/NonceRuntimeModule.js +9 -0
  176. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  177. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  178. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  179. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  180. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  181. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  182. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  183. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  184. package/lib/schemes/HttpUriPlugin.js +22 -5
  185. package/lib/serialization/FileMiddleware.js +15 -2
  186. package/lib/serialization/ObjectMiddleware.js +138 -106
  187. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  188. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  189. package/lib/sharing/ShareRuntimeModule.js +9 -0
  190. package/lib/sharing/declaredShared.js +47 -0
  191. package/lib/stats/DefaultStatsFactoryPlugin.js +3 -1
  192. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  193. package/lib/util/ArrayQueue.js +3 -3
  194. package/lib/util/SourceProcessor.js +76 -69
  195. package/lib/util/URLAbsoluteSpecifier.js +3 -1
  196. package/lib/util/async.js +292 -0
  197. package/lib/util/buildDiagnostics.js +69 -0
  198. package/lib/util/conventions.js +5 -1
  199. package/lib/util/fs.js +27 -1
  200. package/lib/util/handlerKeys.js +40 -0
  201. package/lib/util/identifier.js +20 -0
  202. package/lib/util/internalSerializables.js +6 -0
  203. package/lib/util/registerExternalSerializer.js +6 -45
  204. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
  205. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  206. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +9 -0
  207. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  208. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  209. package/package.json +22 -16
  210. package/schemas/WebpackOptions.check.js +1 -1
  211. package/schemas/WebpackOptions.json +388 -76
  212. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  213. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  214. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  215. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  216. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  217. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  218. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  219. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  220. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  221. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  222. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  223. package/types.d.ts +1440 -331
  224. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  225. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  226. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -6,7 +6,6 @@
6
6
  "use strict";
7
7
 
8
8
  const util = require("util");
9
- const asyncLib = require("neo-async");
10
9
  const {
11
10
  AsyncParallelHook,
12
11
  AsyncSeriesBailHook,
@@ -53,6 +52,8 @@ const AsyncQueue = require("./util/AsyncQueue");
53
52
  const LazySet = require("./util/LazySet");
54
53
  const { getOrInsert } = require("./util/MapHelpers");
55
54
  const WeakTupleMap = require("./util/WeakTupleMap");
55
+ const asyncLib = require("./util/async");
56
+ const { replayOptimizationBailouts } = require("./util/buildDiagnostics");
56
57
  const { cachedCleverMerge } = require("./util/cleverMerge");
57
58
  const {
58
59
  compareErrors,
@@ -367,6 +368,20 @@ const getBuildCycleError = memoize(() => require("./errors/BuildCycleError"));
367
368
  * @property {string[]=} trace
368
369
  */
369
370
 
371
+ /**
372
+ * Where an asset which is a symbolic link points, as the link itself spells it.
373
+ * @typedef {object} AssetSymlink
374
+ * @property {string} target what the link points at, left as it is written
375
+ * @property {boolean} isDirectory whether it points at a directory, which is what Windows needs in order to create one
376
+ */
377
+
378
+ /**
379
+ * Access and modification times an asset carries onto the file it is written to.
380
+ * @typedef {object} AssetTimestamps
381
+ * @property {number} atime last access time, in milliseconds
382
+ * @property {number} mtime last modification time, in milliseconds
383
+ */
384
+
370
385
  /**
371
386
  * Defines the known asset info type used by this module.
372
387
  * @typedef {object} KnownAssetInfo
@@ -378,6 +393,10 @@ const getBuildCycleError = memoize(() => require("./errors/BuildCycleError"));
378
393
  * @property {string | string[]=} contenthash the value(s) of the content hash used for this asset
379
394
  * @property {Record<string, string>=} contenthashDigest maps a `[contenthash:<digest>]` value to its digest, so `RealContentHashPlugin` re-encodes the recomputed hash in it
380
395
  * @property {string=} sourceFilename when asset was created from a source file (potentially transformed), the original filename relative to compilation context
396
+ * @property {boolean=} copied true, when the asset was copied from a file by `output.copy`
397
+ * @property {AssetSymlink=} symlink when set, the asset is emitted as a symbolic link rather than as its content
398
+ * @property {number=} mode when set, the file the asset is written to is given these permissions
399
+ * @property {AssetTimestamps=} timestamps when set, the file the asset is written to is stamped with these times
381
400
  * @property {number=} size size in bytes, only set after asset has been emitted
382
401
  * @property {boolean=} development true, when asset is only used for development and doesn't count towards user-facing assets
383
402
  * @property {boolean=} hotModuleReplacement true, when asset ships data for updating an existing application (HMR)
@@ -1458,6 +1477,8 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1458
1477
  this.missingDependencies = new LazySet();
1459
1478
  /** @type {FileSystemDependencies} */
1460
1479
  this.buildDependencies = new LazySet();
1480
+ /** @type {FileSystemDependencies} */
1481
+ this.optionalBuildDependencies = new LazySet();
1461
1482
  // TODO webpack 6 remove
1462
1483
  /**
1463
1484
  * @deprecated
@@ -1806,6 +1827,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1806
1827
  if (currentProfile !== undefined) {
1807
1828
  currentProfile.markBuildingEnd();
1808
1829
  }
1830
+ replayOptimizationBailouts(this.moduleGraph, module);
1809
1831
  this.hooks.stillValidModule.call(module);
1810
1832
  return callback();
1811
1833
  }
@@ -1826,6 +1848,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1826
1848
  this.hooks.failedModule.call(module, err);
1827
1849
  return callback(err);
1828
1850
  }
1851
+ replayOptimizationBailouts(this.moduleGraph, module);
1829
1852
  if (currentProfile !== undefined) {
1830
1853
  currentProfile.markStoringStart();
1831
1854
  }
@@ -4083,7 +4106,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4083
4106
  const text = /** @type {string} */ (source.source());
4084
4107
  // Everything the hook is handed is in the key: a tap answers per language
4085
4108
  // pair, so identical text offered as two of them is two questions.
4086
- const key = `${info.type}${info.hostType}${text}`;
4109
+ const key = `${info.type}\0${info.hostType}\0${text}`;
4087
4110
  const resolved = this._embeddedSources.get(info.module);
4088
4111
  if (resolved !== undefined) {
4089
4112
  const hit = resolved.get(key);
@@ -4221,15 +4244,17 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4221
4244
  const { codeGenerationDependencies } = module;
4222
4245
  if (
4223
4246
  codeGenerationDependencies !== undefined &&
4224
- (notCodeGeneratedModules === undefined ||
4225
- codeGenerationDependencies.some((dep) => {
4226
- const referencedModule = /** @type {Module} */ (
4227
- moduleGraph.getModule(dep)
4228
- );
4229
- return /** @type {NotCodeGeneratedModules} */ (
4230
- notCodeGeneratedModules
4231
- ).has(referencedModule);
4232
- }))
4247
+ codeGenerationDependencies.some((dep) => {
4248
+ const referencedModule = moduleGraph.getModule(dep);
4249
+ // Nothing resolved it, so it is never code-generated and
4250
+ // waiting on it would stall instead of ordering anything.
4251
+ if (!referencedModule) return false;
4252
+ return (
4253
+ notCodeGeneratedModules === undefined ||
4254
+ /** @type {NotCodeGeneratedModules} */
4255
+ (notCodeGeneratedModules).has(referencedModule)
4256
+ );
4257
+ })
4233
4258
  ) {
4234
4259
  delayedJobs.push(job);
4235
4260
  delayedModules.add(module);
@@ -4338,6 +4363,9 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4338
4363
  codeGenerated = true;
4339
4364
  this.codeGeneratedModules.add(module);
4340
4365
  this._generatingModule = module;
4366
+ // Not stored, since nothing is restored here: named so a reason lands on
4367
+ // the same module as it does in a cached build.
4368
+ runtimeTemplate.beginAnalyzableBailouts(module);
4341
4369
  result = module.codeGeneration({
4342
4370
  chunkGraph,
4343
4371
  moduleGraph,
@@ -4359,6 +4387,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4359
4387
  };
4360
4388
  } finally {
4361
4389
  this._generatingModule = undefined;
4390
+ runtimeTemplate.finishAnalyzableBailouts();
4362
4391
  }
4363
4392
  for (const runtime of runtimes) {
4364
4393
  results.add(module, runtime, result);
@@ -4382,6 +4411,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4382
4411
  codeGenerated = true;
4383
4412
  this.codeGeneratedModules.add(module);
4384
4413
  this._generatingModule = module;
4414
+ runtimeTemplate.beginAnalyzableBailouts(module);
4385
4415
  result = module.codeGeneration({
4386
4416
  chunkGraph,
4387
4417
  moduleGraph,
@@ -4392,6 +4422,13 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4392
4422
  codeGenerationResults: results,
4393
4423
  compilation: this
4394
4424
  });
4425
+ // The bailouts travel with the result: a restored module never runs
4426
+ // the code generation that would record them again.
4427
+ const bailouts = runtimeTemplate.finishAnalyzableBailouts();
4428
+ if (bailouts !== undefined) {
4429
+ if (result.data === undefined) result.data = new Map();
4430
+ result.data.set("analyzableBailouts", bailouts);
4431
+ }
4395
4432
  } catch (err) {
4396
4433
  errors.push(
4397
4434
  new (getCodeGenerationError())(module, /** @type {Error} */ (err))
@@ -4403,9 +4440,14 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
4403
4440
  };
4404
4441
  } finally {
4405
4442
  this._generatingModule = undefined;
4443
+ runtimeTemplate.finishAnalyzableBailouts();
4406
4444
  }
4407
4445
  } else {
4408
4446
  result = cachedResult;
4447
+ const bailouts = result.data && result.data.get("analyzableBailouts");
4448
+ if (bailouts) {
4449
+ runtimeTemplate.restoreAnalyzableBailouts(module, bailouts);
4450
+ }
4409
4451
  }
4410
4452
  for (const runtime of runtimes) {
4411
4453
  results.add(module, runtime, result);
@@ -5008,6 +5050,7 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
5008
5050
  this.contextDependencies.addAll(child.contextDependencies);
5009
5051
  this.missingDependencies.addAll(child.missingDependencies);
5010
5052
  this.buildDependencies.addAll(child.buildDependencies);
5053
+ this.optionalBuildDependencies.addAll(child.optionalBuildDependencies);
5011
5054
  }
5012
5055
 
5013
5056
  for (const module of this.modules) {
@@ -5377,14 +5420,6 @@ This prevents using hashes of each other and should be avoided.`);
5377
5420
  for (const chunk of initialChunks) processChunk(chunk);
5378
5421
  for (const chunk of runtimeChunks) processChunk(chunk);
5379
5422
  for (const chunk of entryChunks) processChunk(chunk);
5380
- if (errors.length > 0) {
5381
- errors.sort(
5382
- compareSelect((err) => err.module, compareModulesByIdentifier)
5383
- );
5384
- for (const error of errors) {
5385
- this.errors.push(error);
5386
- }
5387
- }
5388
5423
 
5389
5424
  this.logger.timeAggregateEnd("hashing: hash runtime modules");
5390
5425
  this.logger.timeAggregateEnd("hashing: hash chunks");
@@ -5399,19 +5434,16 @@ This prevents using hashes of each other and should be avoided.`);
5399
5434
  for (const module of /** @type {Iterable<RuntimeModule>} */ (
5400
5435
  chunkGraph.getChunkFullHashModulesIterable(chunk)
5401
5436
  )) {
5402
- const moduleHash = createHash(hashFunction);
5403
- module.updateHash(moduleHash, {
5404
- chunkGraph,
5405
- runtime: chunk.runtime,
5406
- runtimeTemplate
5407
- });
5408
- const moduleHashDigest = moduleHash.digest(hashDigest);
5409
5437
  const oldHash = chunkGraph.getModuleHash(module, chunk.runtime);
5410
- chunkGraph.setModuleHashes(
5438
+ const moduleHashDigest = this._createModuleHash(
5411
5439
  module,
5440
+ chunkGraph,
5412
5441
  chunk.runtime,
5413
- moduleHashDigest,
5414
- moduleHashDigest.slice(0, hashDigestLength)
5442
+ hashFunction,
5443
+ runtimeTemplate,
5444
+ hashDigest,
5445
+ hashDigestLength,
5446
+ errors
5415
5447
  );
5416
5448
  /** @type {CodeGenerationJob} */
5417
5449
  (
@@ -5428,6 +5460,16 @@ This prevents using hashes of each other and should be avoided.`);
5428
5460
  this.hooks.contentHash.call(chunk);
5429
5461
  }
5430
5462
  this.logger.timeEnd("hashing: process full hash modules");
5463
+
5464
+ if (errors.length > 0) {
5465
+ errors.sort(
5466
+ compareSelect((err) => err.module, compareModulesByIdentifier)
5467
+ );
5468
+ for (const error of errors) {
5469
+ this.errors.push(error);
5470
+ }
5471
+ }
5472
+
5431
5473
  return codeGenerationJobs;
5432
5474
  }
5433
5475
 
@@ -5861,7 +5903,7 @@ This prevents using hashes of each other and should be avoided.`);
5861
5903
  /** @type {Map<string, { hash: string, source: Source, chunk: Chunk }>} */
5862
5904
  const alreadyWrittenFiles = new Map();
5863
5905
 
5864
- asyncLib.forEachLimit(
5906
+ asyncLib.eachLimit(
5865
5907
  this.chunks,
5866
5908
  15,
5867
5909
  (chunk, callback) => {
@@ -6239,299 +6281,275 @@ This prevents using hashes of each other and should be avoided.`);
6239
6281
  };
6240
6282
 
6241
6283
  // Generate code for all aggregated modules
6242
- asyncLib.eachLimit(
6243
- /** @type {import("neo-async").IterableCollection<Module>} */ (
6244
- /** @type {unknown} */ (modules)
6245
- ),
6246
- 10,
6247
- codeGen,
6248
- (err) => {
6284
+ asyncLib.eachLimit(modules, 10, codeGen, (err) => {
6285
+ if (err) return callback(err);
6286
+ reportErrors();
6287
+
6288
+ // for backward-compat temporary set the chunk graph
6289
+ // TODO webpack 6
6290
+ const old = this.chunkGraph;
6291
+ this.chunkGraph = chunkGraph;
6292
+ this.processRuntimeRequirements({
6293
+ chunkGraph,
6294
+ modules,
6295
+ chunks,
6296
+ codeGenerationResults,
6297
+ chunkGraphEntries: chunks
6298
+ });
6299
+ // restored before the deferred attach so no concurrent `make`
6300
+ // task observes the build-time graph
6301
+ this.chunkGraph = old;
6302
+ this._attachPendingRuntimeModules((err) => {
6249
6303
  if (err) return callback(err);
6250
- reportErrors();
6251
-
6252
- // for backward-compat temporary set the chunk graph
6253
- // TODO webpack 6
6254
- const old = this.chunkGraph;
6255
- this.chunkGraph = chunkGraph;
6256
- this.processRuntimeRequirements({
6257
- chunkGraph,
6258
- modules,
6259
- chunks,
6260
- codeGenerationResults,
6261
- chunkGraphEntries: chunks
6262
- });
6263
- // restored before the deferred attach so no concurrent `make`
6264
- // task observes the build-time graph
6265
- this.chunkGraph = old;
6266
- this._attachPendingRuntimeModules((err) => {
6267
- if (err) return callback(err);
6268
6304
 
6269
- const runtimeModules =
6270
- chunkGraph.getChunkRuntimeModulesIterable(chunk);
6305
+ const runtimeModules =
6306
+ chunkGraph.getChunkRuntimeModulesIterable(chunk);
6271
6307
 
6272
- // Hash runtime modules
6273
- for (const module of runtimeModules) {
6274
- modules.add(module);
6275
- this._createModuleHash(
6276
- module,
6277
- chunkGraph,
6278
- runtime,
6279
- hashFunction,
6280
- runtimeTemplate,
6281
- hashDigest,
6282
- hashDigestLength,
6283
- errors
6284
- );
6285
- }
6308
+ // Hash runtime modules
6309
+ for (const module of runtimeModules) {
6310
+ modules.add(module);
6311
+ this._createModuleHash(
6312
+ module,
6313
+ chunkGraph,
6314
+ runtime,
6315
+ hashFunction,
6316
+ runtimeTemplate,
6317
+ hashDigest,
6318
+ hashDigestLength,
6319
+ errors
6320
+ );
6321
+ }
6322
+
6323
+ // Generate code for all runtime modules
6324
+ asyncLib.eachLimit(runtimeModules, 10, codeGen, (err) => {
6325
+ if (err) return callback(err);
6326
+ reportErrors();
6327
+
6328
+ /** @type {Map<Module, ExecuteModuleArgument>} */
6329
+ const moduleArgumentsMap = new Map();
6330
+ /** @type {Map<string, ExecuteModuleArgument>} */
6331
+ const moduleArgumentsById = new Map();
6332
+
6333
+ /** @type {ExecuteModuleResult["fileDependencies"]} */
6334
+ const fileDependencies = new LazySet();
6335
+ /** @type {ExecuteModuleResult["contextDependencies"]} */
6336
+ const contextDependencies = new LazySet();
6337
+ /** @type {ExecuteModuleResult["missingDependencies"]} */
6338
+ const missingDependencies = new LazySet();
6339
+ /** @type {ExecuteModuleResult["buildDependencies"]} */
6340
+ const buildDependencies = new LazySet();
6341
+
6342
+ /** @type {ExecuteModuleResult["assets"]} */
6343
+ const assets = new Map();
6344
+
6345
+ let cacheable = true;
6346
+ /** @type {ExecuteModuleResult["notCacheableReasons"]} */
6347
+ const notCacheableReasons = [];
6348
+
6349
+ /** @type {ExecuteModuleContext} */
6350
+ const context = {
6351
+ assets,
6352
+ __webpack_require__: undefined,
6353
+ chunk,
6354
+ chunkGraph
6355
+ };
6286
6356
 
6287
- // Generate code for all runtime modules
6357
+ // Prepare execution
6288
6358
  asyncLib.eachLimit(
6289
- /** @type {import("neo-async").IterableCollection<RuntimeModule>} */ (
6290
- runtimeModules
6291
- ),
6359
+ modules,
6292
6360
  10,
6293
- codeGen,
6294
- (err) => {
6295
- if (err) return callback(err);
6296
- reportErrors();
6297
-
6298
- /** @type {Map<Module, ExecuteModuleArgument>} */
6299
- const moduleArgumentsMap = new Map();
6300
- /** @type {Map<string, ExecuteModuleArgument>} */
6301
- const moduleArgumentsById = new Map();
6302
-
6303
- /** @type {ExecuteModuleResult["fileDependencies"]} */
6304
- const fileDependencies = new LazySet();
6305
- /** @type {ExecuteModuleResult["contextDependencies"]} */
6306
- const contextDependencies = new LazySet();
6307
- /** @type {ExecuteModuleResult["missingDependencies"]} */
6308
- const missingDependencies = new LazySet();
6309
- /** @type {ExecuteModuleResult["buildDependencies"]} */
6310
- const buildDependencies = new LazySet();
6311
-
6312
- /** @type {ExecuteModuleResult["assets"]} */
6313
- const assets = new Map();
6314
-
6315
- let cacheable = true;
6316
- /** @type {ExecuteModuleResult["notCacheableReasons"]} */
6317
- const notCacheableReasons = [];
6318
-
6319
- /** @type {ExecuteModuleContext} */
6320
- const context = {
6321
- assets,
6322
- __webpack_require__: undefined,
6323
- chunk,
6324
- chunkGraph
6361
+ (module, callback) => {
6362
+ const codeGenerationResult = codeGenerationResults.get(
6363
+ module,
6364
+ runtime
6365
+ );
6366
+ /** @type {ExecuteModuleArgument} */
6367
+ const moduleArgument = {
6368
+ module,
6369
+ codeGenerationResult,
6370
+ moduleObject: undefined
6325
6371
  };
6326
-
6327
- // Prepare execution
6328
- asyncLib.eachLimit(
6329
- modules,
6330
- 10,
6331
- (module, callback) => {
6332
- const codeGenerationResult = codeGenerationResults.get(
6333
- module,
6334
- runtime
6335
- );
6336
- /** @type {ExecuteModuleArgument} */
6337
- const moduleArgument = {
6338
- module,
6339
- codeGenerationResult,
6340
- moduleObject: undefined
6341
- };
6342
- moduleArgumentsMap.set(module, moduleArgument);
6343
- moduleArgumentsById.set(
6344
- module.identifier(),
6345
- moduleArgument
6346
- );
6347
- module.addCacheDependencies(
6348
- fileDependencies,
6349
- contextDependencies,
6350
- missingDependencies,
6351
- buildDependencies
6352
- );
6353
- const buildInfo = /** @type {BuildInfo} */ (
6354
- module.buildInfo
6355
- );
6356
- if (buildInfo.cacheable === false) {
6357
- cacheable = false;
6358
- if (buildInfo.notCacheableReasons) {
6359
- for (const reason of buildInfo.notCacheableReasons) {
6360
- if (!notCacheableReasons.includes(reason)) {
6361
- notCacheableReasons.push(reason);
6362
- }
6363
- }
6372
+ moduleArgumentsMap.set(module, moduleArgument);
6373
+ moduleArgumentsById.set(module.identifier(), moduleArgument);
6374
+ module.addCacheDependencies(
6375
+ fileDependencies,
6376
+ contextDependencies,
6377
+ missingDependencies,
6378
+ buildDependencies
6379
+ );
6380
+ const buildInfo = /** @type {BuildInfo} */ (module.buildInfo);
6381
+ if (buildInfo.cacheable === false) {
6382
+ cacheable = false;
6383
+ const moduleDiagnostics = buildInfo.diagnostics;
6384
+ if (
6385
+ moduleDiagnostics !== undefined &&
6386
+ moduleDiagnostics.notCacheableReasons
6387
+ ) {
6388
+ for (const reason of moduleDiagnostics.notCacheableReasons) {
6389
+ if (!notCacheableReasons.includes(reason)) {
6390
+ notCacheableReasons.push(reason);
6364
6391
  }
6365
6392
  }
6366
- if (module.buildInfo && module.buildInfo.assets) {
6367
- const { assets: moduleAssets, assetsInfo } =
6368
- module.buildInfo;
6369
- for (const assetName of Object.keys(moduleAssets)) {
6370
- assets.set(assetName, {
6371
- source: moduleAssets[assetName],
6372
- info: assetsInfo
6373
- ? assetsInfo.get(assetName)
6374
- : undefined
6375
- });
6376
- }
6393
+ }
6394
+ }
6395
+ if (module.buildInfo && module.buildInfo.assets) {
6396
+ const { assets: moduleAssets, assetsInfo } =
6397
+ module.buildInfo;
6398
+ for (const assetName of Object.keys(moduleAssets)) {
6399
+ assets.set(assetName, {
6400
+ source: moduleAssets[assetName],
6401
+ info: assetsInfo ? assetsInfo.get(assetName) : undefined
6402
+ });
6403
+ }
6404
+ }
6405
+ this.hooks.prepareModuleExecution.callAsync(
6406
+ moduleArgument,
6407
+ context,
6408
+ callback
6409
+ );
6410
+ },
6411
+ (err) => {
6412
+ if (err) {
6413
+ return callback(/** @type {WebpackError} */ (err));
6414
+ }
6415
+
6416
+ /** @type {ExecuteModuleExports | undefined} */
6417
+ let exports;
6418
+ try {
6419
+ const {
6420
+ strictModuleErrorHandling,
6421
+ strictModuleExceptionHandling
6422
+ } = this.outputOptions;
6423
+
6424
+ /** @type {WebpackRequire} */
6425
+ const __webpack_require__ = (id) => {
6426
+ const cached = moduleCache[id];
6427
+ if (cached !== undefined) {
6428
+ if (cached.error) throw cached.error;
6429
+ return cached.exports;
6377
6430
  }
6378
- this.hooks.prepareModuleExecution.callAsync(
6379
- moduleArgument,
6380
- context,
6381
- callback
6431
+ const moduleArgument = moduleArgumentsById.get(id);
6432
+ return __webpack_require_module__(
6433
+ /** @type {ExecuteModuleArgument} */
6434
+ (moduleArgument),
6435
+ id
6382
6436
  );
6383
- },
6384
- (err) => {
6385
- if (err) {
6386
- return callback(/** @type {WebpackError} */ (err));
6437
+ };
6438
+ const interceptModuleExecution = (__webpack_require__[
6439
+ /** @type {"i"} */
6440
+ (
6441
+ RuntimeGlobals.interceptModuleExecution.replace(
6442
+ `${RuntimeGlobals.require}.`,
6443
+ ""
6444
+ )
6445
+ )
6446
+ ] = /** @type {NonNullable<WebpackRequire["i"]>} */ ([]));
6447
+ const moduleCache = (__webpack_require__[
6448
+ /** @type {"c"} */ (
6449
+ RuntimeGlobals.moduleCache.replace(
6450
+ `${RuntimeGlobals.require}.`,
6451
+ ""
6452
+ )
6453
+ )
6454
+ ] = /** @type {NonNullable<WebpackRequire["c"]>} */ ({}));
6455
+
6456
+ context.__webpack_require__ = __webpack_require__;
6457
+
6458
+ /**
6459
+ * Webpack require module.
6460
+ * @param {ExecuteModuleArgument} moduleArgument the module argument
6461
+ * @param {string=} id id
6462
+ * @returns {ExecuteModuleExports} exports
6463
+ */
6464
+ const __webpack_require_module__ = (moduleArgument, id) => {
6465
+ /** @type {ExecuteOptions} */
6466
+ const execOptions = {
6467
+ id,
6468
+ module: {
6469
+ id,
6470
+ exports: {},
6471
+ loaded: false,
6472
+ error: undefined
6473
+ },
6474
+ require: __webpack_require__
6475
+ };
6476
+ for (const handler of interceptModuleExecution) {
6477
+ handler(execOptions);
6387
6478
  }
6388
-
6389
- /** @type {ExecuteModuleExports | undefined} */
6390
- let exports;
6479
+ const module = moduleArgument.module;
6480
+ this.buildTimeExecutedModules.add(module);
6481
+ const moduleObject = execOptions.module;
6482
+ moduleArgument.moduleObject = moduleObject;
6391
6483
  try {
6392
- const {
6393
- strictModuleErrorHandling,
6394
- strictModuleExceptionHandling
6395
- } = this.outputOptions;
6396
-
6397
- /** @type {WebpackRequire} */
6398
- const __webpack_require__ = (id) => {
6399
- const cached = moduleCache[id];
6400
- if (cached !== undefined) {
6401
- if (cached.error) throw cached.error;
6402
- return cached.exports;
6403
- }
6404
- const moduleArgument = moduleArgumentsById.get(id);
6405
- return __webpack_require_module__(
6406
- /** @type {ExecuteModuleArgument} */
6407
- (moduleArgument),
6408
- id
6409
- );
6410
- };
6411
- const interceptModuleExecution = (__webpack_require__[
6412
- /** @type {"i"} */
6413
- (
6414
- RuntimeGlobals.interceptModuleExecution.replace(
6415
- `${RuntimeGlobals.require}.`,
6416
- ""
6417
- )
6418
- )
6419
- ] =
6420
- /** @type {NonNullable<WebpackRequire["i"]>} */ ([]));
6421
- const moduleCache = (__webpack_require__[
6422
- /** @type {"c"} */ (
6423
- RuntimeGlobals.moduleCache.replace(
6424
- `${RuntimeGlobals.require}.`,
6425
- ""
6426
- )
6427
- )
6428
- ] =
6429
- /** @type {NonNullable<WebpackRequire["c"]>} */ ({}));
6430
-
6431
- context.__webpack_require__ = __webpack_require__;
6432
-
6433
- /**
6434
- * Webpack require module.
6435
- * @param {ExecuteModuleArgument} moduleArgument the module argument
6436
- * @param {string=} id id
6437
- * @returns {ExecuteModuleExports} exports
6438
- */
6439
- const __webpack_require_module__ = (
6440
- moduleArgument,
6441
- id
6442
- ) => {
6443
- /** @type {ExecuteOptions} */
6444
- const execOptions = {
6445
- id,
6446
- module: {
6447
- id,
6448
- exports: {},
6449
- loaded: false,
6450
- error: undefined
6451
- },
6452
- require: __webpack_require__
6453
- };
6454
- for (const handler of interceptModuleExecution) {
6455
- handler(execOptions);
6456
- }
6457
- const module = moduleArgument.module;
6458
- this.buildTimeExecutedModules.add(module);
6459
- const moduleObject = execOptions.module;
6460
- moduleArgument.moduleObject = moduleObject;
6461
- try {
6462
- if (id) moduleCache[id] = moduleObject;
6463
-
6464
- tryRunOrWebpackError(
6465
- () =>
6466
- this.hooks.executeModule.call(
6467
- moduleArgument,
6468
- context
6469
- ),
6470
- "Compilation.hooks.executeModule"
6471
- );
6472
- moduleObject.loaded = true;
6473
- return moduleObject.exports;
6474
- } catch (execErr) {
6475
- if (strictModuleExceptionHandling) {
6476
- if (id) delete moduleCache[id];
6477
- } else if (strictModuleErrorHandling) {
6478
- moduleObject.error =
6479
- /** @type {WebpackError} */
6480
- (execErr);
6481
- }
6482
- if (
6483
- !(/** @type {WebpackError} */ (execErr).module)
6484
- ) {
6485
- /** @type {WebpackError} */
6486
- (execErr).module = module;
6487
- }
6488
- throw execErr;
6489
- }
6490
- };
6491
-
6492
- for (const runtimeModule of chunkGraph.getChunkRuntimeModulesInOrder(
6493
- chunk
6494
- )) {
6495
- __webpack_require_module__(
6496
- /** @type {ExecuteModuleArgument} */
6497
- (moduleArgumentsMap.get(runtimeModule))
6498
- );
6499
- }
6500
-
6501
- exports = __webpack_require__(module.identifier());
6484
+ if (id) moduleCache[id] = moduleObject;
6485
+
6486
+ tryRunOrWebpackError(
6487
+ () =>
6488
+ this.hooks.executeModule.call(
6489
+ moduleArgument,
6490
+ context
6491
+ ),
6492
+ "Compilation.hooks.executeModule"
6493
+ );
6494
+ moduleObject.loaded = true;
6495
+ return moduleObject.exports;
6502
6496
  } catch (execErr) {
6503
- const { message, stack, module } =
6497
+ if (strictModuleExceptionHandling) {
6498
+ if (id) delete moduleCache[id];
6499
+ } else if (strictModuleErrorHandling) {
6500
+ moduleObject.error =
6501
+ /** @type {WebpackError} */
6502
+ (execErr);
6503
+ }
6504
+ if (!(/** @type {WebpackError} */ (execErr).module)) {
6504
6505
  /** @type {WebpackError} */
6505
- (execErr);
6506
- const err = new WebpackError(
6507
- `Execution of module code from module graph (${
6508
- /** @type {Module} */
6509
- (module).readableIdentifier(this.requestShortener)
6510
- }) failed: ${message}`,
6511
- { cause: execErr }
6512
- );
6513
- err.stack = stack;
6514
- err.module = module;
6515
- return callback(err);
6506
+ (execErr).module = module;
6507
+ }
6508
+ throw execErr;
6516
6509
  }
6517
-
6518
- callback(null, {
6519
- exports,
6520
- assets,
6521
- cacheable,
6522
- notCacheableReasons,
6523
- fileDependencies,
6524
- contextDependencies,
6525
- missingDependencies,
6526
- buildDependencies
6527
- });
6510
+ };
6511
+
6512
+ for (const runtimeModule of chunkGraph.getChunkRuntimeModulesInOrder(
6513
+ chunk
6514
+ )) {
6515
+ __webpack_require_module__(
6516
+ /** @type {ExecuteModuleArgument} */
6517
+ (moduleArgumentsMap.get(runtimeModule))
6518
+ );
6528
6519
  }
6529
- );
6520
+
6521
+ exports = __webpack_require__(module.identifier());
6522
+ } catch (execErr) {
6523
+ const { message, stack, module } =
6524
+ /** @type {WebpackError} */
6525
+ (execErr);
6526
+ const err = new WebpackError(
6527
+ `Execution of module code from module graph (${
6528
+ /** @type {Module} */
6529
+ (module).readableIdentifier(this.requestShortener)
6530
+ }) failed: ${message}`,
6531
+ { cause: execErr }
6532
+ );
6533
+ err.stack = stack;
6534
+ err.module = module;
6535
+ return callback(err);
6536
+ }
6537
+
6538
+ callback(null, {
6539
+ exports,
6540
+ assets,
6541
+ cacheable,
6542
+ notCacheableReasons,
6543
+ fileDependencies,
6544
+ contextDependencies,
6545
+ missingDependencies,
6546
+ buildDependencies
6547
+ });
6530
6548
  }
6531
6549
  );
6532
6550
  });
6533
- }
6534
- );
6551
+ });
6552
+ });
6535
6553
  }
6536
6554
  );
6537
6555
  }