webpack 5.59.0 → 5.76.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.

Potentially problematic release.


This version of webpack might be problematic. Click here for more details.

Files changed (236) hide show
  1. package/README.md +22 -24
  2. package/bin/webpack.js +0 -0
  3. package/hot/dev-server.js +17 -4
  4. package/hot/lazy-compilation-node.js +3 -1
  5. package/hot/poll.js +1 -1
  6. package/hot/signal.js +1 -1
  7. package/lib/APIPlugin.js +33 -0
  8. package/lib/BannerPlugin.js +13 -5
  9. package/lib/Cache.js +1 -1
  10. package/lib/CacheFacade.js +4 -11
  11. package/lib/Chunk.js +6 -3
  12. package/lib/ChunkGraph.js +94 -8
  13. package/lib/ChunkGroup.js +1 -1
  14. package/lib/CleanPlugin.js +81 -20
  15. package/lib/Compilation.js +188 -93
  16. package/lib/Compiler.js +87 -18
  17. package/lib/ConstPlugin.js +2 -2
  18. package/lib/ContextModule.js +142 -51
  19. package/lib/ContextModuleFactory.js +65 -25
  20. package/lib/DelegatedModule.js +1 -1
  21. package/lib/DelegatedModuleFactoryPlugin.js +1 -1
  22. package/lib/Dependency.js +17 -0
  23. package/lib/DependencyTemplate.js +9 -0
  24. package/lib/DependencyTemplates.js +1 -1
  25. package/lib/DllModule.js +1 -1
  26. package/lib/DllReferencePlugin.js +1 -1
  27. package/lib/EntryOptionPlugin.js +2 -0
  28. package/lib/ErrorHelpers.js +2 -2
  29. package/lib/EvalDevToolModulePlugin.js +16 -1
  30. package/lib/EvalSourceMapDevToolPlugin.js +25 -4
  31. package/lib/ExportsInfo.js +5 -5
  32. package/lib/ExternalModule.js +94 -54
  33. package/lib/ExternalModuleFactoryPlugin.js +5 -5
  34. package/lib/FileSystemInfo.js +124 -58
  35. package/lib/Generator.js +3 -0
  36. package/lib/HookWebpackError.js +1 -1
  37. package/lib/HotModuleReplacementPlugin.js +3 -1
  38. package/lib/LoaderOptionsPlugin.js +1 -1
  39. package/lib/Module.js +28 -4
  40. package/lib/ModuleFilenameHelpers.js +8 -4
  41. package/lib/ModuleHashingError.js +29 -0
  42. package/lib/MultiCompiler.js +1 -1
  43. package/lib/MultiWatching.js +1 -1
  44. package/lib/NodeStuffPlugin.js +13 -3
  45. package/lib/NormalModule.js +51 -33
  46. package/lib/NormalModuleFactory.js +42 -37
  47. package/lib/ProgressPlugin.js +4 -5
  48. package/lib/RawModule.js +1 -1
  49. package/lib/RuntimeGlobals.js +29 -1
  50. package/lib/RuntimeModule.js +1 -1
  51. package/lib/RuntimePlugin.js +84 -1
  52. package/lib/RuntimeTemplate.js +114 -2
  53. package/lib/Template.js +3 -2
  54. package/lib/TemplatedPathPlugin.js +48 -23
  55. package/lib/WatchIgnorePlugin.js +19 -7
  56. package/lib/Watching.js +33 -19
  57. package/lib/WebpackOptionsApply.js +79 -11
  58. package/lib/asset/AssetGenerator.js +228 -71
  59. package/lib/asset/AssetModulesPlugin.js +3 -0
  60. package/lib/asset/AssetParser.js +1 -0
  61. package/lib/asset/AssetSourceGenerator.js +31 -6
  62. package/lib/asset/AssetSourceParser.js +1 -0
  63. package/lib/asset/RawDataUrlModule.js +148 -0
  64. package/lib/async-modules/AwaitDependenciesInitFragment.js +4 -4
  65. package/lib/buildChunkGraph.js +38 -7
  66. package/lib/cache/PackFileCacheStrategy.js +15 -8
  67. package/lib/cache/ResolverCachePlugin.js +90 -29
  68. package/lib/cli.js +44 -3
  69. package/lib/config/browserslistTargetHandler.js +41 -6
  70. package/lib/config/defaults.js +123 -19
  71. package/lib/config/normalization.js +10 -2
  72. package/lib/config/target.js +10 -0
  73. package/lib/container/ContainerEntryModule.js +8 -5
  74. package/lib/container/FallbackModule.js +4 -4
  75. package/lib/container/ModuleFederationPlugin.js +2 -0
  76. package/lib/container/RemoteModule.js +4 -2
  77. package/lib/container/RemoteRuntimeModule.js +8 -7
  78. package/lib/css/CssExportsGenerator.js +139 -0
  79. package/lib/css/CssGenerator.js +109 -0
  80. package/lib/css/CssLoadingRuntimeModule.js +442 -0
  81. package/lib/css/CssModulesPlugin.js +462 -0
  82. package/lib/css/CssParser.js +618 -0
  83. package/lib/css/walkCssTokens.js +659 -0
  84. package/lib/debug/ProfilingPlugin.js +24 -21
  85. package/lib/dependencies/AMDRequireDependency.js +6 -6
  86. package/lib/dependencies/CommonJsExportsParserPlugin.js +1 -2
  87. package/lib/dependencies/CommonJsFullRequireDependency.js +5 -1
  88. package/lib/dependencies/CommonJsImportsParserPlugin.js +344 -61
  89. package/lib/dependencies/CommonJsRequireContextDependency.js +6 -2
  90. package/lib/dependencies/CommonJsRequireDependency.js +2 -1
  91. package/lib/dependencies/ContextDependency.js +16 -2
  92. package/lib/dependencies/ContextDependencyHelpers.js +21 -8
  93. package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +4 -1
  94. package/lib/dependencies/ContextElementDependency.js +25 -3
  95. package/lib/dependencies/CreateScriptUrlDependency.js +12 -0
  96. package/lib/dependencies/CssExportDependency.js +85 -0
  97. package/lib/dependencies/CssImportDependency.js +75 -0
  98. package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
  99. package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
  100. package/lib/dependencies/CssUrlDependency.js +132 -0
  101. package/lib/dependencies/ExportsInfoDependency.js +6 -0
  102. package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
  103. package/lib/dependencies/HarmonyCompatibilityDependency.js +5 -5
  104. package/lib/dependencies/HarmonyEvaluatedImportSpecifierDependency.js +127 -0
  105. package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +12 -3
  106. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +25 -17
  107. package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
  108. package/lib/dependencies/HarmonyImportDependency.js +23 -0
  109. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +142 -45
  110. package/lib/dependencies/HarmonyImportSpecifierDependency.js +46 -22
  111. package/lib/dependencies/HarmonyModulesPlugin.js +10 -0
  112. package/lib/dependencies/ImportContextDependency.js +0 -2
  113. package/lib/dependencies/ImportMetaContextDependency.js +35 -0
  114. package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
  115. package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
  116. package/lib/dependencies/ImportMetaPlugin.js +22 -3
  117. package/lib/dependencies/ImportParserPlugin.js +35 -29
  118. package/lib/dependencies/JsonExportsDependency.js +17 -21
  119. package/lib/dependencies/LoaderDependency.js +13 -0
  120. package/lib/dependencies/LoaderImportDependency.js +13 -0
  121. package/lib/dependencies/LoaderPlugin.js +4 -2
  122. package/lib/dependencies/ModuleDependency.js +11 -1
  123. package/lib/dependencies/ProvidedDependency.js +31 -8
  124. package/lib/dependencies/RequireContextDependency.js +0 -16
  125. package/lib/dependencies/RequireEnsureDependency.js +2 -2
  126. package/lib/dependencies/RequireResolveContextDependency.js +2 -2
  127. package/lib/dependencies/RequireResolveDependency.js +2 -1
  128. package/lib/dependencies/URLDependency.js +3 -8
  129. package/lib/dependencies/URLPlugin.js +22 -1
  130. package/lib/dependencies/WorkerPlugin.js +2 -0
  131. package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
  132. package/lib/esm/ModuleChunkLoadingPlugin.js +3 -1
  133. package/lib/esm/ModuleChunkLoadingRuntimeModule.js +25 -9
  134. package/lib/hmr/HotModuleReplacement.runtime.js +29 -14
  135. package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +4 -3
  136. package/lib/hmr/LazyCompilationPlugin.js +54 -26
  137. package/lib/hmr/lazyCompilationBackend.js +51 -12
  138. package/lib/ids/DeterministicModuleIdsPlugin.js +55 -35
  139. package/lib/ids/HashedModuleIdsPlugin.js +11 -14
  140. package/lib/ids/IdHelpers.js +26 -12
  141. package/lib/ids/NamedModuleIdsPlugin.js +6 -9
  142. package/lib/ids/NaturalModuleIdsPlugin.js +10 -13
  143. package/lib/ids/OccurrenceModuleIdsPlugin.js +13 -10
  144. package/lib/ids/SyncModuleIdsPlugin.js +140 -0
  145. package/lib/index.js +20 -0
  146. package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
  147. package/lib/javascript/BasicEvaluatedExpression.js +5 -2
  148. package/lib/javascript/ChunkHelpers.js +33 -0
  149. package/lib/javascript/JavascriptGenerator.js +1 -0
  150. package/lib/javascript/JavascriptModulesPlugin.js +27 -2
  151. package/lib/javascript/JavascriptParser.js +143 -73
  152. package/lib/javascript/StartupHelpers.js +7 -30
  153. package/lib/json/JsonData.js +8 -0
  154. package/lib/json/JsonParser.js +4 -6
  155. package/lib/library/AssignLibraryPlugin.js +39 -15
  156. package/lib/library/EnableLibraryPlugin.js +11 -0
  157. package/lib/library/UmdLibraryPlugin.js +5 -3
  158. package/lib/node/NodeTargetPlugin.js +3 -0
  159. package/lib/node/NodeWatchFileSystem.js +85 -31
  160. package/lib/node/ReadFileChunkLoadingRuntimeModule.js +23 -8
  161. package/lib/node/RequireChunkLoadingRuntimeModule.js +24 -9
  162. package/lib/optimize/ConcatenatedModule.js +62 -26
  163. package/lib/optimize/ModuleConcatenationPlugin.js +26 -4
  164. package/lib/optimize/RealContentHashPlugin.js +45 -15
  165. package/lib/optimize/SplitChunksPlugin.js +8 -1
  166. package/lib/runtime/AsyncModuleRuntimeModule.js +50 -66
  167. package/lib/runtime/BaseUriRuntimeModule.js +31 -0
  168. package/lib/runtime/CreateScriptRuntimeModule.js +36 -0
  169. package/lib/runtime/CreateScriptUrlRuntimeModule.js +9 -34
  170. package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +76 -0
  171. package/lib/runtime/LoadScriptRuntimeModule.js +11 -9
  172. package/lib/runtime/NonceRuntimeModule.js +24 -0
  173. package/lib/schemes/HttpUriPlugin.js +77 -14
  174. package/lib/serialization/FileMiddleware.js +44 -9
  175. package/lib/sharing/ConsumeSharedModule.js +8 -2
  176. package/lib/sharing/ConsumeSharedRuntimeModule.js +26 -5
  177. package/lib/sharing/ProvideSharedModule.js +4 -2
  178. package/lib/sharing/ProvideSharedPlugin.js +1 -2
  179. package/lib/sharing/ShareRuntimeModule.js +1 -1
  180. package/lib/sharing/utils.js +1 -1
  181. package/lib/stats/DefaultStatsFactoryPlugin.js +113 -68
  182. package/lib/stats/DefaultStatsPrinterPlugin.js +90 -25
  183. package/lib/util/ArrayHelpers.js +30 -0
  184. package/lib/util/AsyncQueue.js +1 -1
  185. package/lib/util/compileBooleanMatcher.js +1 -1
  186. package/lib/util/create-schema-validation.js +9 -2
  187. package/lib/util/createHash.js +12 -0
  188. package/lib/util/deprecation.js +10 -2
  189. package/lib/util/deterministicGrouping.js +1 -1
  190. package/lib/util/extractUrlAndGlobal.js +3 -0
  191. package/lib/util/fs.js +11 -0
  192. package/lib/util/hash/BatchedHash.js +7 -4
  193. package/lib/util/hash/md4.js +20 -0
  194. package/lib/util/hash/wasm-hash.js +163 -0
  195. package/lib/util/hash/xxhash64.js +5 -139
  196. package/lib/util/identifier.js +65 -44
  197. package/lib/util/internalSerializables.js +15 -0
  198. package/lib/util/nonNumericOnlyHash.js +22 -0
  199. package/lib/util/semver.js +17 -10
  200. package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +9 -3
  201. package/lib/wasm-sync/WebAssemblyParser.js +1 -1
  202. package/lib/web/JsonpChunkLoadingRuntimeModule.js +31 -18
  203. package/lib/webpack.js +10 -3
  204. package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +3 -11
  205. package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +33 -22
  206. package/module.d.ts +215 -0
  207. package/package.json +28 -32
  208. package/schemas/WebpackOptions.check.js +1 -1
  209. package/schemas/WebpackOptions.json +321 -30
  210. package/schemas/plugins/BannerPlugin.check.js +1 -1
  211. package/schemas/plugins/BannerPlugin.json +4 -0
  212. package/schemas/plugins/DllReferencePlugin.check.js +1 -1
  213. package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
  214. package/schemas/plugins/ProgressPlugin.check.js +1 -1
  215. package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
  216. package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
  217. package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
  218. package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
  219. package/schemas/plugins/container/ContainerPlugin.json +2 -1
  220. package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
  221. package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
  222. package/schemas/plugins/container/ExternalsType.check.js +1 -1
  223. package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
  224. package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
  225. package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
  226. package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
  227. package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
  228. package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
  229. package/schemas/plugins/css/CssParserOptions.check.js +6 -0
  230. package/schemas/plugins/css/CssParserOptions.json +3 -0
  231. package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
  232. package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
  233. package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
  234. package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
  235. package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
  236. package/types.d.ts +869 -296
@@ -1658,84 +1658,121 @@ const collapse = children => {
1658
1658
  return newChildren;
1659
1659
  };
1660
1660
 
1661
- const spaceLimited = (itemsAndGroups, max) => {
1661
+ const spaceLimited = (
1662
+ itemsAndGroups,
1663
+ max,
1664
+ filteredChildrenLineReserved = false
1665
+ ) => {
1666
+ if (max < 1) {
1667
+ return {
1668
+ children: undefined,
1669
+ filteredChildren: getTotalItems(itemsAndGroups)
1670
+ };
1671
+ }
1662
1672
  /** @type {any[] | undefined} */
1663
1673
  let children = undefined;
1664
1674
  /** @type {number | undefined} */
1665
1675
  let filteredChildren = undefined;
1666
1676
  // This are the groups, which take 1+ lines each
1667
- const groups = itemsAndGroups.filter(c => c.children || c.filteredChildren);
1677
+ const groups = [];
1668
1678
  // The sizes of the groups are stored in groupSizes
1669
- const groupSizes = groups.map(g => getItemSize(g));
1679
+ const groupSizes = [];
1670
1680
  // This are the items, which take 1 line each
1671
- const items = itemsAndGroups.filter(c => !c.children && !c.filteredChildren);
1681
+ const items = [];
1672
1682
  // The total of group sizes
1673
- let groupsSize = groupSizes.reduce((a, b) => a + b, 0);
1683
+ let groupsSize = 0;
1684
+
1685
+ for (const itemOrGroup of itemsAndGroups) {
1686
+ // is item
1687
+ if (!itemOrGroup.children && !itemOrGroup.filteredChildren) {
1688
+ items.push(itemOrGroup);
1689
+ } else {
1690
+ groups.push(itemOrGroup);
1691
+ const size = getItemSize(itemOrGroup);
1692
+ groupSizes.push(size);
1693
+ groupsSize += size;
1694
+ }
1695
+ }
1696
+
1674
1697
  if (groupsSize + items.length <= max) {
1675
1698
  // The total size in the current state fits into the max
1676
1699
  // keep all
1677
- children = groups.concat(items);
1678
- } else if (
1679
- groups.length > 0 &&
1680
- groups.length + Math.min(1, items.length) < max
1681
- ) {
1682
- // If each group would take 1 line the total would be below the maximum
1683
- // collapse some groups, keep items
1684
- while (groupsSize + items.length + (filteredChildren ? 1 : 0) > max) {
1700
+ children = groups.length > 0 ? groups.concat(items) : items;
1701
+ } else if (groups.length === 0) {
1702
+ // slice items to max
1703
+ // inner space marks that lines for filteredChildren already reserved
1704
+ const limit = max - (filteredChildrenLineReserved ? 0 : 1);
1705
+ filteredChildren = items.length - limit;
1706
+ items.length = limit;
1707
+ children = items;
1708
+ } else {
1709
+ // limit is the size when all groups are collapsed
1710
+ const limit =
1711
+ groups.length +
1712
+ (filteredChildrenLineReserved || items.length === 0 ? 0 : 1);
1713
+ if (limit < max) {
1685
1714
  // calculate how much we are over the size limit
1686
1715
  // this allows to approach the limit faster
1687
- // it's always > 1
1688
- const oversize =
1689
- items.length + groupsSize + (filteredChildren ? 1 : 0) - max;
1690
- // Find the maximum group and process only this one
1691
- const maxGroupSize = Math.max(...groupSizes);
1692
- if (maxGroupSize < items.length) {
1693
- filteredChildren = items.length;
1694
- items.length = 0;
1695
- continue;
1696
- }
1697
- for (let i = 0; i < groups.length; i++) {
1698
- if (groupSizes[i] === maxGroupSize) {
1699
- const group = groups[i];
1700
- // run this algorithm recursively and limit the size of the children to
1701
- // current size - oversize / number of groups
1702
- // So it should always end up being smaller
1703
- const headerSize = !group.children
1704
- ? 0
1705
- : group.filteredChildren
1706
- ? 2
1707
- : 1;
1708
- const limited = spaceLimited(
1709
- group.children,
1710
- groupSizes[i] - headerSize - oversize / groups.length
1711
- );
1712
- groups[i] = {
1713
- ...group,
1714
- children: limited.children,
1715
- filteredChildren:
1716
- (group.filteredChildren || 0) + limited.filteredChildren
1717
- };
1718
- const newSize = getItemSize(groups[i]);
1719
- groupsSize -= groupSizes[i] - newSize;
1720
- groupSizes[i] = newSize;
1721
- break;
1716
+ let oversize;
1717
+ // If each group would take 1 line the total would be below the maximum
1718
+ // collapse some groups, keep items
1719
+ while (
1720
+ (oversize =
1721
+ groupsSize +
1722
+ items.length +
1723
+ (filteredChildren && !filteredChildrenLineReserved ? 1 : 0) -
1724
+ max) > 0
1725
+ ) {
1726
+ // Find the maximum group and process only this one
1727
+ const maxGroupSize = Math.max(...groupSizes);
1728
+ if (maxGroupSize < items.length) {
1729
+ filteredChildren = items.length;
1730
+ items.length = 0;
1731
+ continue;
1732
+ }
1733
+ for (let i = 0; i < groups.length; i++) {
1734
+ if (groupSizes[i] === maxGroupSize) {
1735
+ const group = groups[i];
1736
+ // run this algorithm recursively and limit the size of the children to
1737
+ // current size - oversize / number of groups
1738
+ // So it should always end up being smaller
1739
+ const headerSize = group.filteredChildren ? 2 : 1;
1740
+ const limited = spaceLimited(
1741
+ group.children,
1742
+ maxGroupSize -
1743
+ // we should use ceil to always feet in max
1744
+ Math.ceil(oversize / groups.length) -
1745
+ // we substitute size of group head
1746
+ headerSize,
1747
+ headerSize === 2
1748
+ );
1749
+ groups[i] = {
1750
+ ...group,
1751
+ children: limited.children,
1752
+ filteredChildren: limited.filteredChildren
1753
+ ? (group.filteredChildren || 0) + limited.filteredChildren
1754
+ : group.filteredChildren
1755
+ };
1756
+ const newSize = getItemSize(groups[i]);
1757
+ groupsSize -= maxGroupSize - newSize;
1758
+ groupSizes[i] = newSize;
1759
+ break;
1760
+ }
1722
1761
  }
1723
1762
  }
1763
+ children = groups.concat(items);
1764
+ } else if (limit === max) {
1765
+ // If we have only enough space to show one line per group and one line for the filtered items
1766
+ // collapse all groups and items
1767
+ children = collapse(groups);
1768
+ filteredChildren = items.length;
1769
+ } else {
1770
+ // If we have no space
1771
+ // collapse complete group
1772
+ filteredChildren = getTotalItems(itemsAndGroups);
1724
1773
  }
1725
- children = groups.concat(items);
1726
- } else if (
1727
- groups.length > 0 &&
1728
- groups.length + Math.min(1, items.length) <= max
1729
- ) {
1730
- // If we have only enough space to show one line per group and one line for the filtered items
1731
- // collapse all groups and items
1732
- children = groups.length ? collapse(groups) : undefined;
1733
- filteredChildren = items.length;
1734
- } else {
1735
- // If we have no space
1736
- // collapse complete group
1737
- filteredChildren = getTotalItems(itemsAndGroups);
1738
1774
  }
1775
+
1739
1776
  return {
1740
1777
  children,
1741
1778
  filteredChildren
@@ -1777,6 +1814,9 @@ const reasonGroup = (children, reasons) => {
1777
1814
  };
1778
1815
  };
1779
1816
 
1817
+ const GROUP_EXTENSION_REGEXP = /(\.[^.]+?)(?:\?|(?: \+ \d+ modules?)?$)/;
1818
+ const GROUP_PATH_REGEXP = /(.+)[/\\][^/\\]+?(?:\?|(?: \+ \d+ modules?)?$)/;
1819
+
1780
1820
  /** @type {Record<string, (groupConfigs: GroupConfig[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
1781
1821
  const ASSETS_GROUPERS = {
1782
1822
  _: (groupConfigs, context, options) => {
@@ -1825,10 +1865,10 @@ const ASSETS_GROUPERS = {
1825
1865
  groupConfigs.push({
1826
1866
  getKeys: asset => {
1827
1867
  const extensionMatch =
1828
- groupAssetsByExtension && /(\.[^.]+)(?:\?.*|$)/.exec(asset.name);
1868
+ groupAssetsByExtension && GROUP_EXTENSION_REGEXP.exec(asset.name);
1829
1869
  const extension = extensionMatch ? extensionMatch[1] : "";
1830
1870
  const pathMatch =
1831
- groupAssetsByPath && /(.+)[/\\][^/\\]+(?:\?.*|$)/.exec(asset.name);
1871
+ groupAssetsByPath && GROUP_PATH_REGEXP.exec(asset.name);
1832
1872
  const path = pathMatch ? pathMatch[1].split(/[/\\]/) : [];
1833
1873
  const keys = [];
1834
1874
  if (groupAssetsByPath) {
@@ -2022,11 +2062,13 @@ const MODULES_GROUPERS = type => ({
2022
2062
  getKeys: module => {
2023
2063
  if (!module.name) return;
2024
2064
  const resource = parseResource(module.name.split("!").pop()).path;
2065
+ const dataUrl = /^data:[^,;]+/.exec(resource);
2066
+ if (dataUrl) return [dataUrl[0]];
2025
2067
  const extensionMatch =
2026
- groupModulesByExtension && /(\.[^.]+)(?:\?.*|$)/.exec(resource);
2068
+ groupModulesByExtension && GROUP_EXTENSION_REGEXP.exec(resource);
2027
2069
  const extension = extensionMatch ? extensionMatch[1] : "";
2028
2070
  const pathMatch =
2029
- groupModulesByPath && /(.+)[/\\][^/\\]+(?:\?.*|$)/.exec(resource);
2071
+ groupModulesByPath && GROUP_PATH_REGEXP.exec(resource);
2030
2072
  const path = pathMatch ? pathMatch[1].split(/[/\\]/) : [];
2031
2073
  const keys = [];
2032
2074
  if (groupModulesByPath) {
@@ -2046,11 +2088,14 @@ const MODULES_GROUPERS = type => ({
2046
2088
  return keys;
2047
2089
  },
2048
2090
  createGroup: (key, children, modules) => {
2091
+ const isDataUrl = key.startsWith("data:");
2049
2092
  return {
2050
- type: groupModulesByPath
2093
+ type: isDataUrl
2094
+ ? "modules by mime type"
2095
+ : groupModulesByPath
2051
2096
  ? "modules by path"
2052
2097
  : "modules by extension",
2053
- name: key,
2098
+ name: isDataUrl ? key.slice(/* 'data:'.length */ 5) : key,
2054
2099
  children,
2055
2100
  ...moduleGroup(children, modules)
2056
2101
  };
@@ -2110,7 +2155,7 @@ const RESULT_GROUPERS = {
2110
2155
  // remove a prefixed "!" that can be specified to reverse sort order
2111
2156
  const normalizeFieldKey = field => {
2112
2157
  if (field[0] === "!") {
2113
- return field.substr(1);
2158
+ return field.slice(1);
2114
2159
  }
2115
2160
  return field;
2116
2161
  };
@@ -9,6 +9,8 @@
9
9
  /** @typedef {import("./StatsPrinter")} StatsPrinter */
10
10
  /** @typedef {import("./StatsPrinter").StatsPrinterContext} StatsPrinterContext */
11
11
 
12
+ const DATA_URI_CONTENT_LENGTH = 16;
13
+
12
14
  const plural = (n, singular, plural) => (n === 1 ? singular : plural);
13
15
 
14
16
  /**
@@ -26,6 +28,23 @@ const printSizes = (sizes, { formatSize = n => `${n}` }) => {
26
28
  }
27
29
  };
28
30
 
31
+ const getResourceName = resource => {
32
+ const dataUrl = /^data:[^,]+,/.exec(resource);
33
+ if (!dataUrl) return resource;
34
+
35
+ const len = dataUrl[0].length + DATA_URI_CONTENT_LENGTH;
36
+ if (resource.length < len) return resource;
37
+ return `${resource.slice(
38
+ 0,
39
+ Math.min(resource.length - /* '..'.length */ 2, len)
40
+ )}..`;
41
+ };
42
+
43
+ const getModuleName = name => {
44
+ const [, prefix, resource] = /^(.*!)?([^!]*)$/.exec(name);
45
+ return [prefix, getResourceName(resource)];
46
+ };
47
+
29
48
  const mapLines = (str, fn) => str.split("\n").map(fn).join("\n");
30
49
 
31
50
  /**
@@ -38,6 +57,10 @@ const isValidId = id => {
38
57
  return typeof id === "number" || id;
39
58
  };
40
59
 
60
+ const moreCount = (list, count) => {
61
+ return list && list.length > 0 ? `+ ${count}` : `${count}`;
62
+ };
63
+
41
64
  /** @type {Record<string, (thing: any, context: StatsPrinterContext, printer: StatsPrinter) => string | void>} */
42
65
  const SIMPLE_PRINTERS = {
43
66
  "compilation.summary!": (
@@ -163,13 +186,24 @@ const SIMPLE_PRINTERS = {
163
186
  },
164
187
  "compilation.assetsByChunkName": () => "",
165
188
 
166
- "compilation.filteredModules": filteredModules =>
189
+ "compilation.filteredModules": (
190
+ filteredModules,
191
+ { compilation: { modules } }
192
+ ) =>
167
193
  filteredModules > 0
168
- ? `${filteredModules} ${plural(filteredModules, "module", "modules")}`
194
+ ? `${moreCount(modules, filteredModules)} ${plural(
195
+ filteredModules,
196
+ "module",
197
+ "modules"
198
+ )}`
169
199
  : undefined,
170
200
  "compilation.filteredAssets": (filteredAssets, { compilation: { assets } }) =>
171
201
  filteredAssets > 0
172
- ? `${filteredAssets} ${plural(filteredAssets, "asset", "assets")}`
202
+ ? `${moreCount(assets, filteredAssets)} ${plural(
203
+ filteredAssets,
204
+ "asset",
205
+ "assets"
206
+ )}`
173
207
  : undefined,
174
208
  "compilation.logging": (logging, context, printer) =>
175
209
  Array.isArray(logging)
@@ -262,15 +296,19 @@ const SIMPLE_PRINTERS = {
262
296
  "asset.separator!": () => "\n",
263
297
  "asset.filteredRelated": (filteredRelated, { asset: { related } }) =>
264
298
  filteredRelated > 0
265
- ? `${filteredRelated} related ${plural(
299
+ ? `${moreCount(related, filteredRelated)} related ${plural(
266
300
  filteredRelated,
267
301
  "asset",
268
302
  "assets"
269
303
  )}`
270
304
  : undefined,
271
- "asset.filteredChildren": filteredChildren =>
305
+ "asset.filteredChildren": (filteredChildren, { asset: { children } }) =>
272
306
  filteredChildren > 0
273
- ? `${filteredChildren} ${plural(filteredChildren, "asset", "assets")}`
307
+ ? `${moreCount(children, filteredChildren)} ${plural(
308
+ filteredChildren,
309
+ "asset",
310
+ "assets"
311
+ )}`
274
312
  : undefined,
275
313
 
276
314
  assetChunk: (id, { formatChunkId }) => formatChunkId(id),
@@ -282,8 +320,8 @@ const SIMPLE_PRINTERS = {
282
320
  "module.id": (id, { formatModuleId }) =>
283
321
  isValidId(id) ? formatModuleId(id) : undefined,
284
322
  "module.name": (name, { bold }) => {
285
- const [, prefix, resource] = /^(.*!)?([^!]*)$/.exec(name);
286
- return (prefix || "") + bold(resource);
323
+ const [prefix, resource] = getModuleName(name);
324
+ return `${prefix || ""}${bold(resource || "")}`;
287
325
  },
288
326
  "module.identifier": identifier => undefined,
289
327
  "module.layer": (layer, { formatLayer }) =>
@@ -366,21 +404,29 @@ const SIMPLE_PRINTERS = {
366
404
  "module.issuerPath": (issuerPath, { module }) =>
367
405
  module.profile ? undefined : "",
368
406
  "module.profile": profile => undefined,
369
- "module.filteredModules": filteredModules =>
407
+ "module.filteredModules": (filteredModules, { module: { modules } }) =>
370
408
  filteredModules > 0
371
- ? `${filteredModules} nested ${plural(
409
+ ? `${moreCount(modules, filteredModules)} nested ${plural(
372
410
  filteredModules,
373
411
  "module",
374
412
  "modules"
375
413
  )}`
376
414
  : undefined,
377
- "module.filteredReasons": filteredReasons =>
415
+ "module.filteredReasons": (filteredReasons, { module: { reasons } }) =>
378
416
  filteredReasons > 0
379
- ? `${filteredReasons} ${plural(filteredReasons, "reason", "reasons")}`
417
+ ? `${moreCount(reasons, filteredReasons)} ${plural(
418
+ filteredReasons,
419
+ "reason",
420
+ "reasons"
421
+ )}`
380
422
  : undefined,
381
- "module.filteredChildren": filteredChildren =>
423
+ "module.filteredChildren": (filteredChildren, { module: { children } }) =>
382
424
  filteredChildren > 0
383
- ? `${filteredChildren} ${plural(filteredChildren, "module", "modules")}`
425
+ ? `${moreCount(children, filteredChildren)} ${plural(
426
+ filteredChildren,
427
+ "module",
428
+ "modules"
429
+ )}`
384
430
  : undefined,
385
431
  "module.separator!": () => "\n",
386
432
 
@@ -388,7 +434,8 @@ const SIMPLE_PRINTERS = {
388
434
  "moduleIssuer.profile.total": (value, { formatTime }) => formatTime(value),
389
435
 
390
436
  "moduleReason.type": type => type,
391
- "moduleReason.userRequest": (userRequest, { cyan }) => cyan(userRequest),
437
+ "moduleReason.userRequest": (userRequest, { cyan }) =>
438
+ cyan(getResourceName(userRequest)),
392
439
  "moduleReason.moduleId": (moduleId, { formatModuleId }) =>
393
440
  isValidId(moduleId) ? formatModuleId(moduleId) : undefined,
394
441
  "moduleReason.module": (module, { magenta }) => magenta(module),
@@ -397,9 +444,16 @@ const SIMPLE_PRINTERS = {
397
444
  "moduleReason.active": (active, { formatFlag }) =>
398
445
  active ? undefined : formatFlag("inactive"),
399
446
  "moduleReason.resolvedModule": (module, { magenta }) => magenta(module),
400
- "moduleReason.filteredChildren": filteredChildren =>
447
+ "moduleReason.filteredChildren": (
448
+ filteredChildren,
449
+ { moduleReason: { children } }
450
+ ) =>
401
451
  filteredChildren > 0
402
- ? `${filteredChildren} ${plural(filteredChildren, "reason", "reasons")}`
452
+ ? `${moreCount(children, filteredChildren)} ${plural(
453
+ filteredChildren,
454
+ "reason",
455
+ "reasons"
456
+ )}`
403
457
  : undefined,
404
458
 
405
459
  "module.profile.total": (value, { formatTime }) => formatTime(value),
@@ -427,10 +481,21 @@ const SIMPLE_PRINTERS = {
427
481
  size ? formatSize(size) : undefined,
428
482
  "chunkGroup.auxiliaryAssetsSize": (size, { formatSize }) =>
429
483
  size ? `(${formatSize(size)})` : undefined,
430
- "chunkGroup.filteredAssets": n =>
431
- n > 0 ? `${n} ${plural(n, "asset", "assets")}` : undefined,
432
- "chunkGroup.filteredAuxiliaryAssets": n =>
433
- n > 0 ? `${n} auxiliary ${plural(n, "asset", "assets")}` : undefined,
484
+ "chunkGroup.filteredAssets": (n, { chunkGroup: { assets } }) =>
485
+ n > 0
486
+ ? `${moreCount(assets, n)} ${plural(n, "asset", "assets")}`
487
+ : undefined,
488
+ "chunkGroup.filteredAuxiliaryAssets": (
489
+ n,
490
+ { chunkGroup: { auxiliaryAssets } }
491
+ ) =>
492
+ n > 0
493
+ ? `${moreCount(auxiliaryAssets, n)} auxiliary ${plural(
494
+ n,
495
+ "asset",
496
+ "assets"
497
+ )}`
498
+ : undefined,
434
499
  "chunkGroup.is!": () => "=",
435
500
  "chunkGroupAsset.name": (asset, { green }) => green(asset),
436
501
  "chunkGroupAsset.size": (size, { formatSize, chunkGroup }) =>
@@ -490,9 +555,9 @@ const SIMPLE_PRINTERS = {
490
555
  "chunk.recorded": (recorded, { formatFlag, green }) =>
491
556
  recorded ? green(formatFlag("recorded")) : undefined,
492
557
  "chunk.reason": (reason, { yellow }) => (reason ? yellow(reason) : undefined),
493
- "chunk.filteredModules": filteredModules =>
558
+ "chunk.filteredModules": (filteredModules, { chunk: { modules } }) =>
494
559
  filteredModules > 0
495
- ? `${filteredModules} chunk ${plural(
560
+ ? `${moreCount(modules, filteredModules)} chunk ${plural(
496
561
  filteredModules,
497
562
  "module",
498
563
  "modules"
@@ -1088,7 +1153,7 @@ const SIMPLE_ELEMENT_JOINERS = {
1088
1153
  chunkOrigin: items => "> " + joinOneLine(items),
1089
1154
  "errors[].error": joinError(true),
1090
1155
  "warnings[].error": joinError(false),
1091
- loggingGroup: items => joinExplicitNewLine(items, "").trimRight(),
1156
+ loggingGroup: items => joinExplicitNewLine(items, "").trimEnd(),
1092
1157
  moduleTraceItem: items => " @ " + joinOneLine(items),
1093
1158
  moduleTraceDependency: joinOneLine
1094
1159
  };
@@ -1160,7 +1225,7 @@ const AVAILABLE_FORMATS = {
1160
1225
  },
1161
1226
  { regExp: /(\(module has no exports\))/g, format: red },
1162
1227
  { regExp: /\(possible exports: (.+)\)/g, format: green },
1163
- { regExp: /\s*(.+ doesn't exist)/g, format: red },
1228
+ { regExp: /(?:^|\n)(.* doesn't exist)/g, format: red },
1164
1229
  { regExp: /('\w+' option has not been set)/g, format: red },
1165
1230
  {
1166
1231
  regExp: /(Emitted value instead of an instance of Error)/g,
@@ -5,6 +5,14 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ /**
9
+ * Compare two arrays or strings by performing strict equality check for each value.
10
+ * @template T [T=any]
11
+ * @param {ArrayLike<T>} a Array of values to be compared
12
+ * @param {ArrayLike<T>} b Array of values to be compared
13
+ * @returns {boolean} returns true if all the elements of passed arrays are strictly equal.
14
+ */
15
+
8
16
  exports.equals = (a, b) => {
9
17
  if (a.length !== b.length) return false;
10
18
  for (let i = 0; i < a.length; i++) {
@@ -12,3 +20,25 @@ exports.equals = (a, b) => {
12
20
  }
13
21
  return true;
14
22
  };
23
+
24
+ /**
25
+ * Partition an array by calling a predicate function on each value.
26
+ * @template T [T=any]
27
+ * @param {Array<T>} arr Array of values to be partitioned
28
+ * @param {(value: T) => boolean} fn Partition function which partitions based on truthiness of result.
29
+ * @returns {[Array<T>, Array<T>]} returns the values of `arr` partitioned into two new arrays based on fn predicate.
30
+ */
31
+ exports.groupBy = (arr = [], fn) => {
32
+ return arr.reduce(
33
+ /**
34
+ * @param {[Array<T>, Array<T>]} groups An accumulator storing already partitioned values returned from previous call.
35
+ * @param {T} value The value of the current element
36
+ * @returns {[Array<T>, Array<T>]} returns an array of partitioned groups accumulator resulting from calling a predicate on the current value.
37
+ */
38
+ (groups, value) => {
39
+ groups[fn(value) ? 0 : 1].push(value);
40
+ return groups;
41
+ },
42
+ [[], []]
43
+ );
44
+ };
@@ -19,7 +19,7 @@ let inHandleResult = 0;
19
19
  /**
20
20
  * @template T
21
21
  * @callback Callback
22
- * @param {WebpackError=} err
22
+ * @param {(WebpackError | null)=} err
23
23
  * @param {T=} result
24
24
  */
25
25
 
@@ -18,7 +18,7 @@ const toSimpleString = str => {
18
18
 
19
19
  /**
20
20
  * @param {Record<string|number, boolean>} map value map
21
- * @returns {true|false|function(string): string} true/false, when unconditionally true/false, or a template function to determine the value at runtime
21
+ * @returns {boolean|(function(string): string)} true/false, when unconditionally true/false, or a template function to determine the value at runtime
22
22
  */
23
23
  const compileBooleanMatcher = map => {
24
24
  const positiveItems = Object.keys(map).filter(i => map[i]);
@@ -9,11 +9,18 @@ const memoize = require("./memoize");
9
9
 
10
10
  const getValidate = memoize(() => require("schema-utils").validate);
11
11
 
12
- const createSchemaValidation = (check = v => false, getSchema, options) => {
12
+ const createSchemaValidation = (check, getSchema, options) => {
13
13
  getSchema = memoize(getSchema);
14
14
  return value => {
15
- if (!check(value)) {
15
+ if (check && !check(value)) {
16
16
  getValidate()(getSchema(), value, options);
17
+ if (check) {
18
+ require("util").deprecate(
19
+ () => {},
20
+ "webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.",
21
+ "DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID"
22
+ )();
23
+ }
17
24
  }
18
25
  };
19
26
  };
@@ -126,6 +126,7 @@ class DebugHash extends Hash {
126
126
 
127
127
  let crypto = undefined;
128
128
  let createXXHash64 = undefined;
129
+ let createMd4 = undefined;
129
130
  let BatchedHash = undefined;
130
131
 
131
132
  /**
@@ -149,6 +150,17 @@ module.exports = algorithm => {
149
150
  }
150
151
  }
151
152
  return new BatchedHash(createXXHash64());
153
+ case "md4":
154
+ if (createMd4 === undefined) {
155
+ createMd4 = require("./hash/md4");
156
+ if (BatchedHash === undefined) {
157
+ BatchedHash = require("./hash/BatchedHash");
158
+ }
159
+ }
160
+ return new BatchedHash(createMd4());
161
+ case "native-md4":
162
+ if (crypto === undefined) crypto = require("crypto");
163
+ return new BulkUpdateDecorator(() => crypto.createHash("md4"), "md4");
152
164
  default:
153
165
  if (crypto === undefined) crypto = require("crypto");
154
166
  return new BulkUpdateDecorator(
@@ -165,8 +165,16 @@ exports.arrayToSetDeprecation = (set, name) => {
165
165
  };
166
166
 
167
167
  exports.createArrayToSetDeprecationSet = name => {
168
- class SetDeprecatedArray extends Set {}
169
- exports.arrayToSetDeprecation(SetDeprecatedArray.prototype, name);
168
+ let initialized = false;
169
+ class SetDeprecatedArray extends Set {
170
+ constructor(items) {
171
+ super(items);
172
+ if (!initialized) {
173
+ initialized = true;
174
+ exports.arrayToSetDeprecation(SetDeprecatedArray.prototype, name);
175
+ }
176
+ }
177
+ }
170
178
  return SetDeprecatedArray;
171
179
  };
172
180
 
@@ -498,7 +498,7 @@ module.exports = ({ maxSize, minSize, items, getSize, getKey }) => {
498
498
 
499
499
  // return the results
500
500
  return result.map(group => {
501
- /** @type {GroupedItems} */
501
+ /** @type {GroupedItems<T>} */
502
502
  return {
503
503
  key: group.key,
504
504
  items: group.nodes.map(node => node.item),
@@ -11,5 +11,8 @@
11
11
  */
12
12
  module.exports = function extractUrlAndGlobal(urlAndGlobal) {
13
13
  const index = urlAndGlobal.indexOf("@");
14
+ if (index <= 0 || index === urlAndGlobal.length - 1) {
15
+ throw new Error(`Invalid request "${urlAndGlobal}"`);
16
+ }
14
17
  return [urlAndGlobal.substring(index + 1), urlAndGlobal.substring(0, index)];
15
18
  };
package/lib/util/fs.js CHANGED
@@ -61,6 +61,15 @@ const path = require("path");
61
61
  /** @typedef {function((NodeJS.ErrnoException | Error | null)=, any=): void} ReadJsonCallback */
62
62
  /** @typedef {function((NodeJS.ErrnoException | Error | null)=, IStats|string=): void} LstatReadlinkAbsoluteCallback */
63
63
 
64
+ /**
65
+ * @typedef {Object} WatcherInfo
66
+ * @property {Set<string>} changes get current aggregated changes that have not yet send to callback
67
+ * @property {Set<string>} removals get current aggregated removals that have not yet send to callback
68
+ * @property {Map<string, FileSystemInfoEntry | "ignore">} fileTimeInfoEntries get info about files
69
+ * @property {Map<string, FileSystemInfoEntry | "ignore">} contextTimeInfoEntries get info about directories
70
+ */
71
+
72
+ // TODO webpack 6 deprecate missing getInfo
64
73
  /**
65
74
  * @typedef {Object} Watcher
66
75
  * @property {function(): void} close closes the watcher and all underlying file watchers
@@ -69,6 +78,7 @@ const path = require("path");
69
78
  * @property {function(): Set<string>=} getAggregatedRemovals get current aggregated removals that have not yet send to callback
70
79
  * @property {function(): Map<string, FileSystemInfoEntry | "ignore">} getFileTimeInfoEntries get info about files
71
80
  * @property {function(): Map<string, FileSystemInfoEntry | "ignore">} getContextTimeInfoEntries get info about directories
81
+ * @property {function(): WatcherInfo=} getInfo get info about timestamps and changes
72
82
  */
73
83
 
74
84
  /**
@@ -93,6 +103,7 @@ const path = require("path");
93
103
  * @property {function(string, Callback): void=} rmdir
94
104
  * @property {function(string, Callback): void=} unlink
95
105
  * @property {function(string, StatsCallback): void} stat
106
+ * @property {function(string, StatsCallback): void=} lstat
96
107
  * @property {function(string, BufferOrStringCallback): void} readFile
97
108
  * @property {(function(string, string): string)=} join
98
109
  * @property {(function(string, string): string)=} relative