webpack 5.110.3 → 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 (208) hide show
  1. package/README.md +5 -0
  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/CircularModulesPlugin.js +157 -55
  7. package/lib/CleanPlugin.js +2 -2
  8. package/lib/Compilation.js +320 -302
  9. package/lib/Compiler.js +209 -46
  10. package/lib/ContextModule.js +17 -81
  11. package/lib/ContextModuleFactory.js +1 -1
  12. package/lib/CopyPlugin.js +1054 -0
  13. package/lib/DefinePlugin.js +24 -8
  14. package/lib/ExternalModule.js +41 -14
  15. package/lib/FileSystemInfo.js +17 -14
  16. package/lib/FlagDependencyExportsPlugin.js +45 -21
  17. package/lib/HotModuleReplacementPlugin.js +53 -7
  18. package/lib/JavascriptMetaInfoPlugin.js +5 -3
  19. package/lib/MainTemplate.js +5 -1
  20. package/lib/Module.js +16 -7
  21. package/lib/MultiCompiler.js +1 -1
  22. package/lib/MultiWatching.js +1 -1
  23. package/lib/NormalModule.js +45 -12
  24. package/lib/NormalModuleFactory.js +1 -1
  25. package/lib/RuntimeGlobals.js +21 -7
  26. package/lib/RuntimeModule.js +28 -12
  27. package/lib/RuntimePlugin.js +30 -3
  28. package/lib/RuntimeTemplate.js +780 -475
  29. package/lib/SourceMapDevToolPlugin.js +1 -1
  30. package/lib/Watching.js +9 -0
  31. package/lib/WebpackOptionsApply.js +84 -91
  32. package/lib/asset/AssetGenerator.js +25 -8
  33. package/lib/asset/AssetModule.js +3 -0
  34. package/lib/asset/WebManifestParser.js +7 -5
  35. package/lib/cache/AddBuildDependenciesPlugin.js +33 -4
  36. package/lib/cache/IdleFileCachePlugin.js +2 -2
  37. package/lib/cache/PackFileCacheStrategy.js +14 -1
  38. package/lib/config/browserslistTargetHandler.js +19 -0
  39. package/lib/config/defaults.js +86 -50
  40. package/lib/config/normalization.js +82 -12
  41. package/lib/config/target.js +10 -0
  42. package/lib/container/ContainerReferencePlugin.js +6 -0
  43. package/lib/container/RemoteRuntimeModule.js +9 -0
  44. package/lib/container/declaredRemotes.js +39 -0
  45. package/lib/css/CssGenerator.js +8 -0
  46. package/lib/css/CssInjectStyleRuntimeModule.js +9 -0
  47. package/lib/css/CssLoadingRuntimeModule.js +94 -36
  48. package/lib/css/CssModule.js +1 -1
  49. package/lib/css/CssModulesPlugin.js +7 -6
  50. package/lib/css/CssParser.js +144 -11
  51. package/lib/css/CssServerStylesRuntimeModule.js +9 -0
  52. package/lib/css/cssMinify.js +11 -3
  53. package/lib/css/data.js +2814 -678
  54. package/lib/css/syntax.js +4082 -248
  55. package/lib/debug/ProfilingPlugin.js +4 -0
  56. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +6 -3
  57. package/lib/dependencies/AMDRuntimeModules.js +18 -0
  58. package/lib/dependencies/CommonJsExportRequireDependency.js +3 -1
  59. package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -13
  60. package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -0
  61. package/lib/dependencies/CommonJsPlugin.js +19 -3
  62. package/lib/dependencies/CommonJsRequireDependency.js +14 -5
  63. package/lib/dependencies/CssIcssExportDependency.js +7 -1
  64. package/lib/dependencies/HarmonyCompatibilityDependency.js +58 -4
  65. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +8 -3
  66. package/lib/dependencies/HarmonyExportExpressionDependency.js +44 -29
  67. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +71 -13
  68. package/lib/dependencies/HarmonyExportInitFragment.js +99 -19
  69. package/lib/dependencies/HarmonyExportSpecifierDependency.js +18 -30
  70. package/lib/dependencies/HarmonyImportBareSideEffectDependency.js +59 -0
  71. package/lib/dependencies/HarmonyImportDependency.js +6 -1
  72. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +8 -1
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +24 -1
  74. package/lib/dependencies/HarmonyModulesPlugin.js +20 -0
  75. package/lib/dependencies/HtmlEntryDependency.js +50 -0
  76. package/lib/dependencies/ImportMetaMainDependency.js +104 -0
  77. package/lib/dependencies/ImportMetaPlugin.js +59 -15
  78. package/lib/dependencies/SystemRuntimeModule.js +9 -0
  79. package/lib/dependencies/WorkerDependency.js +1 -2
  80. package/lib/dependencies/WorkletDependency.js +1 -2
  81. package/lib/dll/DelegatedModule.js +18 -1
  82. package/lib/dll/DllReferencePlugin.js +11 -8
  83. package/lib/dll/LibManifestPlugin.js +1 -1
  84. package/lib/errors/AnalyzableBailoutsWarning.js +41 -0
  85. package/lib/errors/DuplicateModulesWarning.js +12 -7
  86. package/lib/errors/EmptyCopyPatternWarning.js +26 -0
  87. package/lib/errors/ExternalStarReexportError.js +44 -0
  88. package/lib/errors/MissingSourceMapsWarning.js +36 -0
  89. package/lib/errors/ModuleParseError.js +2 -1
  90. package/lib/errors/UnusedAssetsWarning.js +36 -0
  91. package/lib/errors/UnusedFederationWarning.js +35 -0
  92. package/lib/errors/UnusedModulesWarning.js +38 -0
  93. package/lib/esm/ExportWebpackRequireRuntimeModule.js +9 -0
  94. package/lib/esm/ModuleChunkFormatPlugin.js +28 -3
  95. package/lib/esm/ModuleChunkLoadingPlugin.js +30 -11
  96. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +92 -60
  97. package/lib/hmr/HotModuleReplacement.runtime.js +8 -2
  98. package/lib/hmr/HotModuleReplacementRuntimeModule.js +9 -0
  99. package/lib/html/HtmlGenerator.js +11 -5
  100. package/lib/html/HtmlModulesPlugin.js +331 -62
  101. package/lib/html/HtmlParser.js +13 -6
  102. package/lib/html/builtinEmbeddedRenderer.js +107 -0
  103. package/lib/html/data.js +121 -7
  104. package/lib/html/htmlMinify.js +84 -113
  105. package/lib/html/syntax.js +763 -426
  106. package/lib/ids/HashedModuleIdsPlugin.js +2 -1
  107. package/lib/index.js +3 -0
  108. package/lib/javascript/JavascriptModule.js +1 -0
  109. package/lib/javascript/JavascriptModulesPlugin.js +52 -24
  110. package/lib/javascript/JavascriptParser.js +1255 -728
  111. package/lib/javascript/StartupHelpers.js +27 -3
  112. package/lib/javascript/data.js +172 -0
  113. package/lib/javascript/grammar.js +5546 -0
  114. package/lib/javascript/parser.js +1494 -0
  115. package/lib/javascript/regexp.js +1762 -0
  116. package/lib/javascript/regexpData.js +51 -0
  117. package/lib/javascript/syntax.js +8696 -5225
  118. package/lib/library/ModuleLibraryPlugin.js +116 -5
  119. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -0
  120. package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -0
  121. package/lib/optimize/ConcatenatedModule.js +97 -20
  122. package/lib/optimize/ConstExportsPlugin.js +50 -39
  123. package/lib/optimize/InlineExports.js +20 -123
  124. package/lib/optimize/MangleExportsPlugin.js +10 -0
  125. package/lib/optimize/ModuleConcatenationPlugin.js +24 -1
  126. package/lib/optimize/RealContentHashPlugin.js +68 -9
  127. package/lib/optimize/SideEffectsFlagPlugin.js +17 -9
  128. package/lib/performance/AnalyzableBailoutsPlugin.js +115 -0
  129. package/lib/performance/CacheEffectivenessPlugin.js +4 -3
  130. package/lib/performance/DuplicateModulesPlugin.js +57 -13
  131. package/lib/performance/EvalUsagePlugin.js +5 -2
  132. package/lib/performance/MissingSourceMapsPlugin.js +115 -0
  133. package/lib/performance/PureAnnotationsPlugin.js +6 -3
  134. package/lib/performance/TopLevelThisPlugin.js +5 -4
  135. package/lib/performance/UnusedAssetsPlugin.js +109 -0
  136. package/lib/performance/UnusedFederationPlugin.js +147 -0
  137. package/lib/performance/UnusedModulesPlugin.js +141 -0
  138. package/lib/performance/UnusedReexportsPlugin.js +1 -55
  139. package/lib/performance/isOnlyReexported.js +65 -0
  140. package/lib/prefetch/ChunkPrefetchFunctionRuntimeModule.js +25 -5
  141. package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +2 -0
  142. package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +9 -0
  143. package/lib/prefetch/ChunkPrefetchTriggerRuntimeModule.js +9 -0
  144. package/lib/prefetch/ChunkPreloadTriggerRuntimeModule.js +9 -0
  145. package/lib/prefetch/ResourceHintPlugin.js +1 -2
  146. package/lib/prefetch/ResourceHintRuntimeModule.js +9 -0
  147. package/lib/prefetch/StartupAssetHintRuntimeModule.js +9 -0
  148. package/lib/rules/RuleSetCompiler.js +211 -4
  149. package/lib/runtime/AsyncModuleRuntimeModule.js +100 -66
  150. package/lib/runtime/AutoPublicPathRuntimeModule.js +9 -0
  151. package/lib/runtime/BaseUriRuntimeModule.js +9 -0
  152. package/lib/runtime/ChunkNameRuntimeModule.js +9 -0
  153. package/lib/runtime/EnsureChunkRuntimeModule.js +35 -16
  154. package/lib/runtime/GetChunkFilenameRuntimeModule.js +9 -0
  155. package/lib/runtime/GetFullHashRuntimeModule.js +9 -0
  156. package/lib/runtime/GetMainFilenameRuntimeModule.js +9 -0
  157. package/lib/runtime/GetWorkletBootstrapRuntimeModule.js +9 -0
  158. package/lib/runtime/GlobalRuntimeModule.js +9 -0
  159. package/lib/runtime/HasOwnPropertyRuntimeModule.js +9 -0
  160. package/lib/runtime/HelperRuntimeModule.js +10 -0
  161. package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +330 -219
  162. package/lib/runtime/NonceRuntimeModule.js +9 -0
  163. package/lib/runtime/OnChunksLoadedRuntimeModule.js +67 -20
  164. package/lib/runtime/PublicPathRuntimeModule.js +9 -0
  165. package/lib/runtime/RuntimeIdRuntimeModule.js +9 -0
  166. package/lib/runtime/SpecNamespaceObjectRuntimeModule.js +90 -0
  167. package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +9 -0
  168. package/lib/runtime/StartupEntrypointRuntimeModule.js +9 -0
  169. package/lib/runtime/SystemContextRuntimeModule.js +9 -0
  170. package/lib/runtime/ToBinaryRuntimeModule.js +9 -0
  171. package/lib/serialization/ObjectMiddleware.js +138 -106
  172. package/lib/sharing/ConsumeSharedPlugin.js +12 -0
  173. package/lib/sharing/ConsumeSharedRuntimeModule.js +11 -0
  174. package/lib/sharing/ShareRuntimeModule.js +9 -0
  175. package/lib/sharing/declaredShared.js +47 -0
  176. package/lib/stats/DefaultStatsFactoryPlugin.js +3 -1
  177. package/lib/stats/DefaultStatsPrinterPlugin.js +3 -0
  178. package/lib/util/SourceProcessor.js +76 -69
  179. package/lib/util/async.js +292 -0
  180. package/lib/util/buildDiagnostics.js +69 -0
  181. package/lib/util/fs.js +27 -1
  182. package/lib/util/handlerKeys.js +40 -0
  183. package/lib/util/identifier.js +20 -0
  184. package/lib/util/internalSerializables.js +4 -0
  185. package/lib/util/registerExternalSerializer.js +6 -45
  186. package/lib/wasm-async/AsyncWasmCompileRuntimeModule.js +9 -0
  187. package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +9 -0
  188. package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +9 -0
  189. package/lib/web/JsonpChunkLoadingRuntimeModule.js +36 -0
  190. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +19 -0
  191. package/package.json +22 -16
  192. package/schemas/WebpackOptions.check.js +1 -1
  193. package/schemas/WebpackOptions.json +379 -66
  194. package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
  195. package/schemas/plugins/ManifestPlugin.check.js +1 -1
  196. package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
  197. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  198. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  199. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  200. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  201. package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
  202. package/schemas/plugins/dll/DllReferencePlugin.check.js +1 -1
  203. package/schemas/plugins/ids/HashedModuleIdsPlugin.check.js +1 -1
  204. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  205. package/types.d.ts +1414 -314
  206. package/lib/dependencies/ExportBindingInitFragment.js +0 -191
  207. package/lib/errors/EntrypointOverlapWarning.js +0 -45
  208. package/lib/performance/EntrypointOverlapPlugin.js +0 -122
@@ -303,6 +303,15 @@ const A = (obj, prop, factory) => {
303
303
  }
304
304
  };
305
305
 
306
+ /**
307
+ * Whether the library type emits an ECMAScript module, which only `output.module`
308
+ * output can carry — every other type is written into a script.
309
+ * @param {LibraryType | undefined} type library type
310
+ * @returns {boolean} true, when the type is only emitted as an ECMAScript module
311
+ */
312
+ const isModuleLibraryType = (type) =>
313
+ type === "module" || type === "modern-module";
314
+
306
315
  /**
307
316
  * Apply webpack options base defaults.
308
317
  * @param {WebpackOptionsNormalized} options options to be modified
@@ -364,7 +373,6 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
364
373
  applyExperimentsDefaults(options.experiments, {
365
374
  production,
366
375
  development,
367
- targetProperties,
368
376
  rules: options.module.rules
369
377
  });
370
378
 
@@ -408,9 +416,6 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
408
416
  (typeof target === "string" && target.startsWith("browserslist")) ||
409
417
  (Array.isArray(target) &&
410
418
  target.some((target) => target.startsWith("browserslist"))),
411
- outputModule:
412
- /** @type {NonNullable<ExperimentsNormalized["outputModule"]>} */
413
- (options.experiments.outputModule),
414
419
  development,
415
420
  entry: options.entry,
416
421
  futureDefaults,
@@ -423,9 +428,7 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
423
428
  // is read by another bundler, where an eval wrapper hides `import.meta` from it.
424
429
  const noDevSourceMap = /** @type {LibraryType[]} */ (
425
430
  options.output.enabledLibraryTypes
426
- ).some(
427
- (type) => futureDefaults || type === "module" || type === "modern-module"
428
- );
431
+ ).some((type) => futureDefaults || isModuleLibraryType(type));
429
432
 
430
433
  F(
431
434
  options,
@@ -630,13 +633,12 @@ const applyWebpackOptionsDefaults = (options, compilerIndex) => {
630
633
  * @param {object} options options
631
634
  * @param {boolean} options.production is production
632
635
  * @param {boolean} options.development is development mode
633
- * @param {TargetProperties | false} options.targetProperties target properties
634
636
  * @param {RuleSetRules} options.rules user `module.rules`, used to resolve the css/html/asyncWebAssembly/typescript "auto" defaults
635
637
  * @returns {void}
636
638
  */
637
639
  const applyExperimentsDefaults = (
638
640
  experiments,
639
- { production, development, targetProperties, rules }
641
+ { production, development, rules }
640
642
  ) => {
641
643
  D(experiments, "futureDefaults", false);
642
644
  D(experiments, "backCompat", !experiments.futureDefaults);
@@ -647,23 +649,6 @@ const applyExperimentsDefaults = (
647
649
  "asyncWebAssembly",
648
650
  experiments.futureDefaults ? true : "auto"
649
651
  );
650
- // the universal target (web + node, neither specific) only works as ESM —
651
- // unless the target cannot read one, which no output format can repair, so
652
- // leave `output.chunkFormat` to say so rather than emitting a module the
653
- // target has already reported it will not load
654
- const universal =
655
- Boolean(targetProperties) &&
656
- /** @type {TargetProperties} */ (targetProperties).node === null &&
657
- /** @type {TargetProperties} */ (targetProperties).web === null &&
658
- /** @type {TargetProperties} */ (targetProperties).module !== false;
659
- // the deno and bun targets only emit ECMAScript modules
660
- const deno =
661
- Boolean(targetProperties) &&
662
- /** @type {TargetProperties} */ (targetProperties).deno === true;
663
- const bun =
664
- Boolean(targetProperties) &&
665
- /** @type {TargetProperties} */ (targetProperties).bun === true;
666
- D(experiments, "outputModule", universal || deno || bun);
667
652
  D(experiments, "lazyCompilation", undefined);
668
653
  D(experiments, "buildHttp", undefined);
669
654
  D(experiments, "cacheUnaffected", experiments.futureDefaults);
@@ -919,6 +904,7 @@ const applyJavascriptParserOptionsDefaults = (
919
904
  D(parserOptions, "wrappedContextRecursive", true);
920
905
  D(parserOptions, "wrappedContextCritical", false);
921
906
  D(parserOptions, "strictThisContextOnImports", false);
907
+ D(parserOptions, "specNamespaceObject", false);
922
908
  D(parserOptions, "importMeta", outputModule ? "preserve-unknown" : true);
923
909
  D(parserOptions, "dynamicImportMode", "lazy");
924
910
  D(parserOptions, "dynamicImportPrefetch", false);
@@ -1433,8 +1419,10 @@ const applyModuleDefaults = (
1433
1419
  type: HTML_MODULE_TYPE,
1434
1420
  resolve
1435
1421
  });
1422
+ // Exactly `text/html` — a string condition matches by prefix, which
1423
+ // would make a `data:text/htmlx,` module (JavaScript) a page.
1436
1424
  rules.push({
1437
- mimetype: "text/html",
1425
+ mimetype: /^text\/html$/i,
1438
1426
  type: HTML_MODULE_TYPE,
1439
1427
  resolve
1440
1428
  });
@@ -1593,7 +1581,6 @@ const applyModuleDefaults = (
1593
1581
  * @param {string} options.context context
1594
1582
  * @param {TargetProperties | false} options.targetProperties target properties
1595
1583
  * @param {boolean} options.isAffectedByBrowserslist is affected by browserslist
1596
- * @param {boolean} options.outputModule is outputModule experiment enabled
1597
1584
  * @param {boolean} options.development is development mode
1598
1585
  * @param {Entry} options.entry entry option
1599
1586
  * @param {boolean} options.futureDefaults is future defaults enabled
@@ -1606,7 +1593,6 @@ const applyOutputDefaults = (
1606
1593
  context,
1607
1594
  targetProperties: tp,
1608
1595
  isAffectedByBrowserslist,
1609
- outputModule,
1610
1596
  development,
1611
1597
  entry,
1612
1598
  futureDefaults,
@@ -1662,7 +1648,65 @@ const applyOutputDefaults = (
1662
1648
  }
1663
1649
  });
1664
1650
 
1665
- F(output, "module", () => Boolean(outputModule));
1651
+ /**
1652
+ * Processes the provided fn.
1653
+ * @param {(entryDescription: EntryDescription) => void} fn iterator
1654
+ * @returns {void}
1655
+ */
1656
+ const forEachEntry = (fn) => {
1657
+ for (const name of Object.keys(entry)) {
1658
+ fn(/** @type {{ [k: string]: EntryDescription }} */ (entry)[name]);
1659
+ }
1660
+ };
1661
+
1662
+ /**
1663
+ * Every library type the configuration states, wherever it was declared.
1664
+ * @returns {LibraryType[]} the declared library types
1665
+ */
1666
+ const declaredLibraryTypes = () => {
1667
+ /** @type {LibraryType[]} */
1668
+ const types = [];
1669
+ if (output.library && output.library.type) types.push(output.library.type);
1670
+ // A plugin (`ModuleFederationPlugin`) pushed its type here before the defaults;
1671
+ // `"..."` is the extend placeholder `A` resolves, never a type of its own.
1672
+ if (output.enabledLibraryTypes) {
1673
+ for (const type of output.enabledLibraryTypes) {
1674
+ if (type !== "...") types.push(type);
1675
+ }
1676
+ }
1677
+ forEachEntry((desc) => {
1678
+ if (desc.library && desc.library.type) types.push(desc.library.type);
1679
+ });
1680
+ return types;
1681
+ };
1682
+
1683
+ const libraryTypes = declaredLibraryTypes();
1684
+
1685
+ // A library type that is an ECMAScript module is another spelling of
1686
+ // `output.module`, so it turns it on rather than disagreeing with it.
1687
+ if (libraryTypes.some(isModuleLibraryType)) {
1688
+ output.module = true;
1689
+ }
1690
+
1691
+ // Every other library type is read out of a script, which is a statement that
1692
+ // the output is not an ECMAScript module — so it holds the default below back.
1693
+ const hasScriptLibrary = libraryTypes.some(
1694
+ (type) => !isModuleLibraryType(type)
1695
+ );
1696
+
1697
+ // the universal target (web + node, neither specific), deno and bun only work
1698
+ // as ESM, unless `module: false` says the target cannot read one
1699
+ F(output, "module", () =>
1700
+ Boolean(
1701
+ tp &&
1702
+ ((tp.node === null && tp.web === null && tp.module !== false) ||
1703
+ tp.deno === true ||
1704
+ tp.bun === true ||
1705
+ // webpack@6 emits ESM wherever the target reads one — a browserslist
1706
+ // query (or `esX`/`nodeX`) without ESM support keeps script output
1707
+ (futureDefaults && tp.module !== false && !hasScriptLibrary))
1708
+ )
1709
+ );
1666
1710
 
1667
1711
  const environment = /** @type {Environment} */ (output.environment);
1668
1712
  /**
@@ -1748,8 +1792,12 @@ const applyOutputDefaults = (
1748
1792
  "generator",
1749
1793
  () => tp && optimistic(/** @type {boolean | undefined} */ (tp.generator))
1750
1794
  );
1751
- // No `topLevelAwait` here: the option is held back from the patch release,
1752
- // so nothing derives it from `tp` yet. Reapply by reverting #21881.
1795
+ F(
1796
+ environment,
1797
+ "topLevelAwait",
1798
+ () =>
1799
+ tp && optimistic(/** @type {boolean | undefined} */ (tp.topLevelAwait))
1800
+ );
1753
1801
  F(
1754
1802
  environment,
1755
1803
  "forOf",
@@ -1984,7 +2032,7 @@ const applyOutputDefaults = (
1984
2032
  "For the selected environment is no default script chunk format available:\n" +
1985
2033
  `${
1986
2034
  tp.module
1987
- ? "Module ('module') can be chosen when ES modules are available (please set 'experiments.outputModule' and 'output.module' to `true`)"
2035
+ ? "Module ('module') can be chosen when ES modules are available (please set 'output.module' to `true`)"
1988
2036
  : ""
1989
2037
  }\n` +
1990
2038
  "JSONP Array push ('array-push') can be chosen when 'document' or 'importScripts' is available.\n" +
@@ -2131,16 +2179,6 @@ const applyOutputDefaults = (
2131
2179
  D(trustedTypes, "onPolicyCreationFailure", "stop");
2132
2180
  }
2133
2181
 
2134
- /**
2135
- * Processes the provided fn.
2136
- * @param {(entryDescription: EntryDescription) => void} fn iterator
2137
- * @returns {void}
2138
- */
2139
- const forEachEntry = (fn) => {
2140
- for (const name of Object.keys(entry)) {
2141
- fn(/** @type {{ [k: string]: EntryDescription }} */ (entry)[name]);
2142
- }
2143
- };
2144
2182
  A(output, "enabledLibraryTypes", () => {
2145
2183
  /** @type {LibraryType[]} */
2146
2184
  const enabledLibraryTypes = [];
@@ -2391,6 +2429,7 @@ const applyPerformanceDefaults = (performance, { production }) => {
2391
2429
  // Stands in for every check left unset, so an explicit one still wins.
2392
2430
  const all = performance.all !== undefined ? performance.all : false;
2393
2431
 
2432
+ D(performance, "analyzableBailouts", all);
2394
2433
  D(performance, "asyncChunkWaterfalls", all);
2395
2434
  D(performance, "broadContexts", all);
2396
2435
  D(performance, "cacheEffectiveness", all);
@@ -2399,8 +2438,6 @@ const applyPerformanceDefaults = (performance, { production }) => {
2399
2438
  D(performance, "duplicateModules", all);
2400
2439
  D(performance, "duplicatePackages", all);
2401
2440
  D(performance, "dynamicExports", all);
2402
- D(performance, "entrypointOverlap", all);
2403
- D(performance, "embeddedSourceMaps", all);
2404
2441
  D(performance, "evalUsage", all);
2405
2442
  D(performance, "hotspots", all);
2406
2443
  D(performance, "legacyJavascript", all);
@@ -2413,14 +2450,13 @@ const applyPerformanceDefaults = (performance, { production }) => {
2413
2450
  D(performance, "redundantDynamicImports", all);
2414
2451
  D(performance, "scopeHoistingBailouts", all);
2415
2452
  D(performance, "splitChunksCapped", all);
2453
+ D(performance, "sourceMaps", all);
2416
2454
  D(performance, "tinyChunks", all);
2417
2455
  D(performance, "topLevelThis", all);
2418
2456
  D(performance, "unsplitVendors", all);
2419
- D(performance, "unusedAliases", all);
2420
- D(performance, "unusedDefines", all);
2421
- D(performance, "unusedExternals", all);
2422
- D(performance, "unusedReexports", all);
2423
- D(performance, "unusedRules", all);
2457
+ D(performance, "unusedAssets", all);
2458
+ D(performance, "unusedConfig", all);
2459
+ D(performance, "unusedModules", all);
2424
2460
  F(performance, "hints", () => (production ? "warning" : false));
2425
2461
  };
2426
2462
 
@@ -6,6 +6,7 @@
6
6
  "use strict";
7
7
 
8
8
  const util = require("util");
9
+ const { fileUrlToPath } = require("../util/identifier");
9
10
 
10
11
  /**
11
12
  * @import {
@@ -138,6 +139,28 @@ const keyedNestedConfig = (value, fn, customKeys) => {
138
139
  return result;
139
140
  };
140
141
 
142
+ /**
143
+ * Converts a file URL to the path it names. Anything that is not a string is
144
+ * returned unchanged, so `false` and `undefined` pass through.
145
+ * @template {string | false | undefined} T
146
+ * @param {T} pathOrUrl an absolute path, a file URL, `false` or `undefined`
147
+ * @returns {T} an absolute path, `false` or `undefined`
148
+ */
149
+ const optionalFileUrlToPath = (pathOrUrl) =>
150
+ typeof pathOrUrl === "string"
151
+ ? /** @type {T} */ (fileUrlToPath(pathOrUrl))
152
+ : pathOrUrl;
153
+
154
+ /**
155
+ * Converts every file URL of a list to the path it names.
156
+ * @param {(string | RegExp)[]} pathsOrUrls absolute paths, file URLs or regular expressions
157
+ * @returns {(string | RegExp)[]} absolute paths and regular expressions
158
+ */
159
+ const fileUrlsToPaths = (pathsOrUrls) =>
160
+ pathsOrUrls.map((pathOrUrl) =>
161
+ typeof pathOrUrl === "string" ? fileUrlToPath(pathOrUrl) : pathOrUrl
162
+ );
163
+
141
164
  /**
142
165
  * Normalize `output.resourceHints` into its object form: the scalar / array /
143
166
  * function shorthand becomes `{ initial: <value> }` (with `"preload"` aliased to
@@ -162,6 +185,40 @@ const normalizeResourceHints = (resourceHints) => {
162
185
  return { initial: alias(resourceHints) };
163
186
  };
164
187
 
188
+ /**
189
+ * @typedef {object} NormalizedBuildDependencyItem
190
+ * @property {string} dependency request to resolve
191
+ * @property {boolean} optional when true the dependency may be missing
192
+ */
193
+
194
+ /**
195
+ * @param {import("../../declarations/WebpackOptions").BuildDependencyItem} item build dependency
196
+ * @returns {NormalizedBuildDependencyItem} normalized build dependency
197
+ */
198
+ const normalizeBuildDependencyItem = (item) => {
199
+ if (typeof item === "string") {
200
+ return { dependency: item, optional: false };
201
+ }
202
+ return {
203
+ dependency: item.dependency,
204
+ optional: item.optional === true
205
+ };
206
+ };
207
+
208
+ /**
209
+ * @param {import("../../declarations/WebpackOptions").FileCacheOptions["buildDependencies"]=} buildDependencies build dependencies
210
+ * @returns {Record<string, NormalizedBuildDependencyItem[]>} normalized build dependencies
211
+ */
212
+ const normalizeBuildDependencies = (buildDependencies) => {
213
+ /** @type {Record<string, NormalizedBuildDependencyItem[]>} */
214
+ const result = Object.create(null);
215
+ if (buildDependencies === undefined) return result;
216
+ for (const key of Object.keys(buildDependencies)) {
217
+ result[key] = buildDependencies[key].map(normalizeBuildDependencyItem);
218
+ }
219
+ return result;
220
+ };
221
+
165
222
  /**
166
223
  * Gets normalized webpack options.
167
224
  * @param {WebpackOptions} config input config
@@ -189,9 +246,11 @@ const getNormalizedWebpackOptions = (config) => ({
189
246
  maxMemoryGenerations: cache.maxMemoryGenerations,
190
247
  maxAge: cache.maxAge,
191
248
  profile: cache.profile,
192
- buildDependencies: cloneObject(cache.buildDependencies),
193
- cacheDirectory: cache.cacheDirectory,
194
- cacheLocation: cache.cacheLocation,
249
+ buildDependencies: normalizeBuildDependencies(
250
+ cache.buildDependencies
251
+ ),
252
+ cacheDirectory: optionalFileUrlToPath(cache.cacheDirectory),
253
+ cacheLocation: optionalFileUrlToPath(cache.cacheLocation),
195
254
  hashAlgorithm: cache.hashAlgorithm,
196
255
  compression: cache.compression,
197
256
  idleTimeout: cache.idleTimeout,
@@ -214,7 +273,7 @@ const getNormalizedWebpackOptions = (config) => ({
214
273
  }
215
274
  })
216
275
  ),
217
- context: config.context,
276
+ context: optionalFileUrlToPath(config.context),
218
277
  dependencies: config.dependencies,
219
278
  devServer: optionalNestedConfig(config.devServer, (devServer) => {
220
279
  if (devServer === false) return false;
@@ -381,6 +440,9 @@ const getNormalizedWebpackOptions = (config) => ({
381
440
  cssChunkFilename: output.cssChunkFilename,
382
441
  clean: output.clean,
383
442
  compareBeforeEmit: output.compareBeforeEmit,
443
+ copy: optionalNestedConfig(output.copy, (copy) => ({
444
+ patterns: typeof copy === "string" ? [copy] : [...copy]
445
+ })),
384
446
  crossOriginLoading: output.crossOriginLoading,
385
447
  devtoolFallbackModuleFilenameTemplate:
386
448
  output.devtoolFallbackModuleFilenameTemplate,
@@ -439,7 +501,7 @@ const getNormalizedWebpackOptions = (config) => ({
439
501
  : libraryBase.umdNamedDefine
440
502
  },
441
503
  module: output.module,
442
- path: output.path,
504
+ path: optionalFileUrlToPath(output.path),
443
505
  pathinfo: output.pathinfo,
444
506
  publicPath: output.publicPath,
445
507
  resourceHints: normalizeResourceHints(output.resourceHints),
@@ -481,14 +543,16 @@ const getNormalizedWebpackOptions = (config) => ({
481
543
  nestedArray(config.plugins, (p) => p.filter(Boolean))
482
544
  ),
483
545
  profile: config.profile,
484
- recordsInputPath:
546
+ recordsInputPath: optionalFileUrlToPath(
485
547
  config.recordsInputPath !== undefined
486
548
  ? config.recordsInputPath
487
- : config.recordsPath,
488
- recordsOutputPath:
549
+ : config.recordsPath
550
+ ),
551
+ recordsOutputPath: optionalFileUrlToPath(
489
552
  config.recordsOutputPath !== undefined
490
553
  ? config.recordsOutputPath
491
- : config.recordsPath,
554
+ : config.recordsPath
555
+ ),
492
556
  resolve: nestedConfig(config.resolve, (resolve) => ({
493
557
  ...resolve,
494
558
  byDependency: keyedNestedConfig(resolve.byDependency, cloneObject)
@@ -524,9 +588,15 @@ const getNormalizedWebpackOptions = (config) => ({
524
588
  hash: contextModule.hash
525
589
  })
526
590
  ),
527
- immutablePaths: optionalNestedArray(snapshot.immutablePaths, (p) => [...p]),
528
- managedPaths: optionalNestedArray(snapshot.managedPaths, (p) => [...p]),
529
- unmanagedPaths: optionalNestedArray(snapshot.unmanagedPaths, (p) => [...p])
591
+ immutablePaths: optionalNestedArray(
592
+ snapshot.immutablePaths,
593
+ fileUrlsToPaths
594
+ ),
595
+ managedPaths: optionalNestedArray(snapshot.managedPaths, fileUrlsToPaths),
596
+ unmanagedPaths: optionalNestedArray(
597
+ snapshot.unmanagedPaths,
598
+ fileUrlsToPaths
599
+ )
530
600
  })),
531
601
  stats: nestedConfig(config.stats, (stats) => {
532
602
  if (stats === false) {
@@ -82,6 +82,7 @@ const getDefaultTarget = (context) => {
82
82
  * @property {boolean | null} templateLiteral template literal is available
83
83
  * @property {boolean | null} asyncFunction async functions and await are available
84
84
  * @property {boolean | null} generator generator functions and yield are available
85
+ * @property {boolean | null} topLevelAwait top-level await is available
85
86
  * @property {(boolean | null)=} deferImport deferred evaluation (`import defer`, `import.defer()`) is available (optional; absent means "assume unavailable")
86
87
  * @property {(boolean | null)=} sourceImport source phase imports (`import source`, `import.source()`) are available (optional; absent means "assume unavailable")
87
88
  */
@@ -269,6 +270,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
269
270
  arrowFunction: v(6),
270
271
  asyncFunction: v(7, 6),
271
272
  generator: v(4),
273
+ // v14.8.0
274
+ topLevelAwait: v(14, 8),
272
275
  forOf: v(5),
273
276
  destructuring: v(6),
274
277
  bigIntLiteral: v(10, 4),
@@ -329,6 +332,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
329
332
  templateLiteral: true,
330
333
  asyncFunction: true,
331
334
  generator: true,
335
+ topLevelAwait: true,
332
336
  // import defer - v2.8.0
333
337
  deferImport: v(2, 8),
334
338
  // import source - v2.6.0
@@ -380,6 +384,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
380
384
  arrowFunction: true,
381
385
  asyncFunction: true,
382
386
  generator: true,
387
+ topLevelAwait: true,
383
388
  forOf: true,
384
389
  destructuring: true,
385
390
  bigIntLiteral: true,
@@ -437,6 +442,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
437
442
  arrowFunction: v(1, 1),
438
443
  asyncFunction: v(1, 7),
439
444
  generator: v(1, 1),
445
+ // 12.0.0 - Chromium 89
446
+ topLevelAwait: v(12),
440
447
  forOf: v(0, 36),
441
448
  destructuring: v(1, 1),
442
449
  bigIntLiteral: v(4),
@@ -486,6 +493,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
486
493
  arrowFunction: v(0, 15),
487
494
  asyncFunction: v(0, 21),
488
495
  generator: v(0, 15),
496
+ // 0.52.0 - Chromium 89
497
+ topLevelAwait: v(0, 52),
489
498
  forOf: v(0, 13),
490
499
  destructuring: v(0, 15),
491
500
  bigIntLiteral: v(0, 32),
@@ -515,6 +524,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
515
524
  destructuring: v >= 2015,
516
525
  module: v >= 2015,
517
526
  asyncFunction: v >= 2017,
527
+ topLevelAwait: v >= 2022,
518
528
  generator: v >= 2015,
519
529
  globalThis: v >= 2020,
520
530
  symbol: v >= 2015,
@@ -14,6 +14,7 @@ const FallbackModuleFactory = require("./FallbackModuleFactory");
14
14
  const RemoteModule = require("./RemoteModule");
15
15
  const RemoteRuntimeModule = require("./RemoteRuntimeModule");
16
16
  const RemoteToExternalDependency = require("./RemoteToExternalDependency");
17
+ const { addDeclaredRemotes } = require("./declaredRemotes");
17
18
  const { parseOptions } = require("./options");
18
19
 
19
20
  /**
@@ -91,6 +92,11 @@ class ContainerReferencePlugin {
91
92
  compiler.hooks.compilation.tap(
92
93
  PLUGIN_NAME,
93
94
  (compilation, { normalModuleFactory }) => {
95
+ addDeclaredRemotes(
96
+ compilation,
97
+ remotes.map(([key]) => key)
98
+ );
99
+
94
100
  compilation.dependencyFactories.set(
95
101
  RemoteToExternalDependency,
96
102
  normalModuleFactory
@@ -20,6 +20,15 @@ class RemoteRuntimeModule extends RuntimeModule {
20
20
  super("remotes loading");
21
21
  }
22
22
 
23
+ /**
24
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
25
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
26
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
27
+ */
28
+ getInstalledChunkHandlers() {
29
+ return [[RuntimeGlobals.ensureChunkHandlers, "remotes"]];
30
+ }
31
+
23
32
  /**
24
33
  * Generates runtime code for this runtime module.
25
34
  * @returns {string | null} runtime code
@@ -0,0 +1,39 @@
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Alexander Akait @alexander-akait
4
+ */
5
+
6
+ "use strict";
7
+
8
+ /** @import Compilation from "../Compilation" */
9
+
10
+ /** @type {WeakMap<Compilation, Set<string>>} */
11
+ const DECLARED_REMOTES = new WeakMap();
12
+
13
+ /**
14
+ * The remote names this build declared, in declaration order, which is the
15
+ * order `factorize` resolves a request against them in.
16
+ * @param {Compilation} compilation the compilation
17
+ * @returns {Set<string> | undefined} the declared names, when any were declared
18
+ */
19
+ const getDeclaredRemotes = (compilation) => DECLARED_REMOTES.get(compilation);
20
+
21
+ /**
22
+ * Records declared names, adding to any a previous application made.
23
+ * @param {Compilation} compilation the compilation
24
+ * @param {Iterable<string>} names what this application declared
25
+ * @returns {void}
26
+ */
27
+ const addDeclaredRemotes = (compilation, names) => {
28
+ let declared = DECLARED_REMOTES.get(compilation);
29
+
30
+ if (declared === undefined) {
31
+ declared = new Set();
32
+ DECLARED_REMOTES.set(compilation, declared);
33
+ }
34
+
35
+ for (const name of names) declared.add(name);
36
+ };
37
+
38
+ module.exports.addDeclaredRemotes = addDeclaredRemotes;
39
+ module.exports.getDeclaredRemotes = getDeclaredRemotes;
@@ -32,6 +32,7 @@ const Template = require("../Template");
32
32
  const { getPresentKinds } = require("../TemplatedPathPlugin");
33
33
  const CssImportDependency = require("../dependencies/CssImportDependency");
34
34
  const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
35
+ const LoaderImportDependency = require("../dependencies/LoaderImportDependency");
35
36
 
36
37
  const { encodeMappings } = require("../util/createMappings");
37
38
  const {
@@ -668,6 +669,13 @@ class CssGenerator extends Generator {
668
669
  continue;
669
670
  }
670
671
 
672
+ // `importModule()` executes the module as JavaScript, and its dependency
673
+ // carries no origin module (`connectOrigin: false` in `LoaderPlugin`).
674
+ if (connection.dependency instanceof LoaderImportDependency) {
675
+ hasJs = true;
676
+ continue;
677
+ }
678
+
671
679
  if (!connection.originModule) {
672
680
  continue;
673
681
  }
@@ -30,6 +30,15 @@ class CssInjectStyleRuntimeModule extends RuntimeModule {
30
30
  this._runtimeRequirements = runtimeRequirements;
31
31
  }
32
32
 
33
+ /**
34
+ * The `[handlerMap, key]` pairs this module installs onto a chunk handler map
35
+ * such as `__webpack_require__.f`, or `null` where it cannot name them.
36
+ * @returns {[string, string][] | null} installed chunk handlers (do not mutate)
37
+ */
38
+ getInstalledChunkHandlers() {
39
+ return RuntimeModule.NO_CHUNK_HANDLERS;
40
+ }
41
+
33
42
  /**
34
43
  * Generates runtime code for this runtime module.
35
44
  * @returns {string | null} runtime code