ChunkGraph.js 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. const util = require("util");
  7. const Entrypoint = require("./Entrypoint");
  8. const ModuleGraphConnection = require("./ModuleGraphConnection");
  9. const { first } = require("./util/SetHelpers");
  10. const SortableSet = require("./util/SortableSet");
  11. const {
  12. compareModulesById,
  13. compareIterables,
  14. compareModulesByIdentifier,
  15. concatComparators,
  16. compareSelect,
  17. compareIds
  18. } = require("./util/comparators");
  19. const createHash = require("./util/createHash");
  20. const findGraphRoots = require("./util/findGraphRoots");
  21. const {
  22. RuntimeSpecMap,
  23. RuntimeSpecSet,
  24. runtimeToString,
  25. mergeRuntime,
  26. forEachRuntime
  27. } = require("./util/runtime");
  28. /** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
  29. /** @typedef {import("./Chunk")} Chunk */
  30. /** @typedef {import("./ChunkGroup")} ChunkGroup */
  31. /** @typedef {import("./Module")} Module */
  32. /** @typedef {import("./ModuleGraph")} ModuleGraph */
  33. /** @typedef {import("./ModuleGraphConnection").ConnectionState} ConnectionState */
  34. /** @typedef {import("./RuntimeModule")} RuntimeModule */
  35. /** @typedef {typeof import("./util/Hash")} Hash */
  36. /** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
  37. /** @type {ReadonlySet<string>} */
  38. const EMPTY_SET = new Set();
  39. const ZERO_BIG_INT = BigInt(0);
  40. const compareModuleIterables = compareIterables(compareModulesByIdentifier);
  41. /** @typedef {(c: Chunk, chunkGraph: ChunkGraph) => boolean} ChunkFilterPredicate */
  42. /** @typedef {(m: Module) => boolean} ModuleFilterPredicate */
  43. /** @typedef {[Module, Entrypoint | undefined]} EntryModuleWithChunkGroup */
  44. /**
  45. * @typedef {Object} ChunkSizeOptions
  46. * @property {number=} chunkOverhead constant overhead for a chunk
  47. * @property {number=} entryChunkMultiplicator multiplicator for initial chunks
  48. */
  49. class ModuleHashInfo {
  50. /**
  51. * @param {string} hash hash
  52. * @param {string} renderedHash rendered hash
  53. */
  54. constructor(hash, renderedHash) {
  55. this.hash = hash;
  56. this.renderedHash = renderedHash;
  57. }
  58. }
  59. /** @template T @typedef {(set: SortableSet<T>) => T[]} SetToArrayFunction<T> */
  60. /**
  61. * @template T
  62. * @param {SortableSet<T>} set the set
  63. * @returns {T[]} set as array
  64. */
  65. const getArray = set => {
  66. return Array.from(set);
  67. };
  68. /**
  69. * @param {SortableSet<Chunk>} chunks the chunks
  70. * @returns {RuntimeSpecSet} runtimes
  71. */
  72. const getModuleRuntimes = chunks => {
  73. const runtimes = new RuntimeSpecSet();
  74. for (const chunk of chunks) {
  75. runtimes.add(chunk.runtime);
  76. }
  77. return runtimes;
  78. };
  79. /**
  80. * @param {WeakMap<Module, Set<string>> | undefined} sourceTypesByModule sourceTypesByModule
  81. * @returns {function (SortableSet<Module>): Map<string, SortableSet<Module>>} modules by source type
  82. */
  83. const modulesBySourceType = sourceTypesByModule => set => {
  84. /** @type {Map<string, SortableSet<Module>>} */
  85. const map = new Map();
  86. for (const module of set) {
  87. const sourceTypes =
  88. (sourceTypesByModule && sourceTypesByModule.get(module)) ||
  89. module.getSourceTypes();
  90. for (const sourceType of sourceTypes) {
  91. let innerSet = map.get(sourceType);
  92. if (innerSet === undefined) {
  93. innerSet = new SortableSet();
  94. map.set(sourceType, innerSet);
  95. }
  96. innerSet.add(module);
  97. }
  98. }
  99. for (const [key, innerSet] of map) {
  100. // When all modules have the source type, we reuse the original SortableSet
  101. // to benefit from the shared cache (especially for sorting)
  102. if (innerSet.size === set.size) {
  103. map.set(key, set);
  104. }
  105. }
  106. return map;
  107. };
  108. const defaultModulesBySourceType = modulesBySourceType(undefined);
  109. /** @type {WeakMap<Function, any>} */
  110. const createOrderedArrayFunctionMap = new WeakMap();
  111. /**
  112. * @template T
  113. * @param {function(T, T): -1|0|1} comparator comparator function
  114. * @returns {SetToArrayFunction<T>} set as ordered array
  115. */
  116. const createOrderedArrayFunction = comparator => {
  117. /** @type {SetToArrayFunction<T>} */
  118. let fn = createOrderedArrayFunctionMap.get(comparator);
  119. if (fn !== undefined) return fn;
  120. fn = set => {
  121. set.sortWith(comparator);
  122. return Array.from(set);
  123. };
  124. createOrderedArrayFunctionMap.set(comparator, fn);
  125. return fn;
  126. };
  127. /**
  128. * @param {Iterable<Module>} modules the modules to get the count/size of
  129. * @returns {number} the size of the modules
  130. */
  131. const getModulesSize = modules => {
  132. let size = 0;
  133. for (const module of modules) {
  134. for (const type of module.getSourceTypes()) {
  135. size += module.size(type);
  136. }
  137. }
  138. return size;
  139. };
  140. /**
  141. * @param {Iterable<Module>} modules the sortable Set to get the size of
  142. * @returns {Record<string, number>} the sizes of the modules
  143. */
  144. const getModulesSizes = modules => {
  145. let sizes = Object.create(null);
  146. for (const module of modules) {
  147. for (const type of module.getSourceTypes()) {
  148. sizes[type] = (sizes[type] || 0) + module.size(type);
  149. }
  150. }
  151. return sizes;
  152. };
  153. /**
  154. * @param {Chunk} a chunk
  155. * @param {Chunk} b chunk
  156. * @returns {boolean} true, if a is always a parent of b
  157. */
  158. const isAvailableChunk = (a, b) => {
  159. const queue = new Set(b.groupsIterable);
  160. for (const chunkGroup of queue) {
  161. if (a.isInGroup(chunkGroup)) continue;
  162. if (chunkGroup.isInitial()) return false;
  163. for (const parent of chunkGroup.parentsIterable) {
  164. queue.add(parent);
  165. }
  166. }
  167. return true;
  168. };
  169. /** @typedef {Set<Chunk>} EntryInChunks */
  170. /** @typedef {Set<Chunk>} RuntimeInChunks */
  171. class ChunkGraphModule {
  172. constructor() {
  173. /** @type {SortableSet<Chunk>} */
  174. this.chunks = new SortableSet();
  175. /** @type {EntryInChunks | undefined} */
  176. this.entryInChunks = undefined;
  177. /** @type {RuntimeInChunks | undefined} */
  178. this.runtimeInChunks = undefined;
  179. /** @type {RuntimeSpecMap<ModuleHashInfo> | undefined} */
  180. this.hashes = undefined;
  181. /** @type {string | number} */
  182. this.id = null;
  183. /** @type {RuntimeSpecMap<Set<string>> | undefined} */
  184. this.runtimeRequirements = undefined;
  185. /** @type {RuntimeSpecMap<string> | undefined} */
  186. this.graphHashes = undefined;
  187. /** @type {RuntimeSpecMap<string> | undefined} */
  188. this.graphHashesWithConnections = undefined;
  189. }
  190. }
  191. class ChunkGraphChunk {
  192. constructor() {
  193. /** @type {SortableSet<Module>} */
  194. this.modules = new SortableSet();
  195. /** @type {WeakMap<Module, Set<string>> | undefined} */
  196. this.sourceTypesByModule = undefined;
  197. /** @type {Map<Module, Entrypoint>} */
  198. this.entryModules = new Map();
  199. /** @type {SortableSet<RuntimeModule>} */
  200. this.runtimeModules = new SortableSet();
  201. /** @type {Set<RuntimeModule> | undefined} */
  202. this.fullHashModules = undefined;
  203. /** @type {Set<RuntimeModule> | undefined} */
  204. this.dependentHashModules = undefined;
  205. /** @type {Set<string> | undefined} */
  206. this.runtimeRequirements = undefined;
  207. /** @type {Set<string>} */
  208. this.runtimeRequirementsInTree = new Set();
  209. this._modulesBySourceType = defaultModulesBySourceType;
  210. }
  211. }
  212. class ChunkGraph {
  213. /**
  214. * @param {ModuleGraph} moduleGraph the module graph
  215. * @param {string | Hash} hashFunction the hash function to use
  216. */
  217. constructor(moduleGraph, hashFunction = "md4") {
  218. /** @private @type {WeakMap<Module, ChunkGraphModule>} */
  219. this._modules = new WeakMap();
  220. /** @private @type {WeakMap<Chunk, ChunkGraphChunk>} */
  221. this._chunks = new WeakMap();
  222. /** @private @type {WeakMap<AsyncDependenciesBlock, ChunkGroup>} */
  223. this._blockChunkGroups = new WeakMap();
  224. /** @private @type {Map<string, string | number>} */
  225. this._runtimeIds = new Map();
  226. /** @type {ModuleGraph} */
  227. this.moduleGraph = moduleGraph;
  228. this._hashFunction = hashFunction;
  229. this._getGraphRoots = this._getGraphRoots.bind(this);
  230. }
  231. /**
  232. * @private
  233. * @param {Module} module the module
  234. * @returns {ChunkGraphModule} internal module
  235. */
  236. _getChunkGraphModule(module) {
  237. let cgm = this._modules.get(module);
  238. if (cgm === undefined) {
  239. cgm = new ChunkGraphModule();
  240. this._modules.set(module, cgm);
  241. }
  242. return cgm;
  243. }
  244. /**
  245. * @private
  246. * @param {Chunk} chunk the chunk
  247. * @returns {ChunkGraphChunk} internal chunk
  248. */
  249. _getChunkGraphChunk(chunk) {
  250. let cgc = this._chunks.get(chunk);
  251. if (cgc === undefined) {
  252. cgc = new ChunkGraphChunk();
  253. this._chunks.set(chunk, cgc);
  254. }
  255. return cgc;
  256. }
  257. /**
  258. * @param {SortableSet<Module>} set the sortable Set to get the roots of
  259. * @returns {Module[]} the graph roots
  260. */
  261. _getGraphRoots(set) {
  262. const { moduleGraph } = this;
  263. return Array.from(
  264. findGraphRoots(set, module => {
  265. /** @type {Set<Module>} */
  266. const set = new Set();
  267. /**
  268. * @param {Module} module module
  269. */
  270. const addDependencies = module => {
  271. for (const connection of moduleGraph.getOutgoingConnections(module)) {
  272. if (!connection.module) continue;
  273. const activeState = connection.getActiveState(undefined);
  274. if (activeState === false) continue;
  275. if (activeState === ModuleGraphConnection.TRANSITIVE_ONLY) {
  276. addDependencies(connection.module);
  277. continue;
  278. }
  279. set.add(connection.module);
  280. }
  281. };
  282. addDependencies(module);
  283. return set;
  284. })
  285. ).sort(compareModulesByIdentifier);
  286. }
  287. /**
  288. * @param {Chunk} chunk the new chunk
  289. * @param {Module} module the module
  290. * @returns {void}
  291. */
  292. connectChunkAndModule(chunk, module) {
  293. const cgm = this._getChunkGraphModule(module);
  294. const cgc = this._getChunkGraphChunk(chunk);
  295. cgm.chunks.add(chunk);
  296. cgc.modules.add(module);
  297. }
  298. /**
  299. * @param {Chunk} chunk the chunk
  300. * @param {Module} module the module
  301. * @returns {void}
  302. */
  303. disconnectChunkAndModule(chunk, module) {
  304. const cgm = this._getChunkGraphModule(module);
  305. const cgc = this._getChunkGraphChunk(chunk);
  306. cgc.modules.delete(module);
  307. // No need to invalidate cgc._modulesBySourceType because we modified cgc.modules anyway
  308. if (cgc.sourceTypesByModule) cgc.sourceTypesByModule.delete(module);
  309. cgm.chunks.delete(chunk);
  310. }
  311. /**
  312. * @param {Chunk} chunk the chunk which will be disconnected
  313. * @returns {void}
  314. */
  315. disconnectChunk(chunk) {
  316. const cgc = this._getChunkGraphChunk(chunk);
  317. for (const module of cgc.modules) {
  318. const cgm = this._getChunkGraphModule(module);
  319. cgm.chunks.delete(chunk);
  320. }
  321. cgc.modules.clear();
  322. chunk.disconnectFromGroups();
  323. ChunkGraph.clearChunkGraphForChunk(chunk);
  324. }
  325. /**
  326. * @param {Chunk} chunk the chunk
  327. * @param {Iterable<Module>} modules the modules
  328. * @returns {void}
  329. */
  330. attachModules(chunk, modules) {
  331. const cgc = this._getChunkGraphChunk(chunk);
  332. for (const module of modules) {
  333. cgc.modules.add(module);
  334. }
  335. }
  336. /**
  337. * @param {Chunk} chunk the chunk
  338. * @param {Iterable<RuntimeModule>} modules the runtime modules
  339. * @returns {void}
  340. */
  341. attachRuntimeModules(chunk, modules) {
  342. const cgc = this._getChunkGraphChunk(chunk);
  343. for (const module of modules) {
  344. cgc.runtimeModules.add(module);
  345. }
  346. }
  347. /**
  348. * @param {Chunk} chunk the chunk
  349. * @param {Iterable<RuntimeModule>} modules the modules that require a full hash
  350. * @returns {void}
  351. */
  352. attachFullHashModules(chunk, modules) {
  353. const cgc = this._getChunkGraphChunk(chunk);
  354. if (cgc.fullHashModules === undefined) cgc.fullHashModules = new Set();
  355. for (const module of modules) {
  356. cgc.fullHashModules.add(module);
  357. }
  358. }
  359. /**
  360. * @param {Chunk} chunk the chunk
  361. * @param {Iterable<RuntimeModule>} modules the modules that require a full hash
  362. * @returns {void}
  363. */
  364. attachDependentHashModules(chunk, modules) {
  365. const cgc = this._getChunkGraphChunk(chunk);
  366. if (cgc.dependentHashModules === undefined)
  367. cgc.dependentHashModules = new Set();
  368. for (const module of modules) {
  369. cgc.dependentHashModules.add(module);
  370. }
  371. }
  372. /**
  373. * @param {Module} oldModule the replaced module
  374. * @param {Module} newModule the replacing module
  375. * @returns {void}
  376. */
  377. replaceModule(oldModule, newModule) {
  378. const oldCgm = this._getChunkGraphModule(oldModule);
  379. const newCgm = this._getChunkGraphModule(newModule);
  380. for (const chunk of oldCgm.chunks) {
  381. const cgc = this._getChunkGraphChunk(chunk);
  382. cgc.modules.delete(oldModule);
  383. cgc.modules.add(newModule);
  384. newCgm.chunks.add(chunk);
  385. }
  386. oldCgm.chunks.clear();
  387. if (oldCgm.entryInChunks !== undefined) {
  388. if (newCgm.entryInChunks === undefined) {
  389. newCgm.entryInChunks = new Set();
  390. }
  391. for (const chunk of oldCgm.entryInChunks) {
  392. const cgc = this._getChunkGraphChunk(chunk);
  393. const old = /** @type {Entrypoint} */ (cgc.entryModules.get(oldModule));
  394. /** @type {Map<Module, Entrypoint>} */
  395. const newEntryModules = new Map();
  396. for (const [m, cg] of cgc.entryModules) {
  397. if (m === oldModule) {
  398. newEntryModules.set(newModule, old);
  399. } else {
  400. newEntryModules.set(m, cg);
  401. }
  402. }
  403. cgc.entryModules = newEntryModules;
  404. newCgm.entryInChunks.add(chunk);
  405. }
  406. oldCgm.entryInChunks = undefined;
  407. }
  408. if (oldCgm.runtimeInChunks !== undefined) {
  409. if (newCgm.runtimeInChunks === undefined) {
  410. newCgm.runtimeInChunks = new Set();
  411. }
  412. for (const chunk of oldCgm.runtimeInChunks) {
  413. const cgc = this._getChunkGraphChunk(chunk);
  414. cgc.runtimeModules.delete(/** @type {RuntimeModule} */ (oldModule));
  415. cgc.runtimeModules.add(/** @type {RuntimeModule} */ (newModule));
  416. newCgm.runtimeInChunks.add(chunk);
  417. if (
  418. cgc.fullHashModules !== undefined &&
  419. cgc.fullHashModules.has(/** @type {RuntimeModule} */ (oldModule))
  420. ) {
  421. cgc.fullHashModules.delete(/** @type {RuntimeModule} */ (oldModule));
  422. cgc.fullHashModules.add(/** @type {RuntimeModule} */ (newModule));
  423. }
  424. if (
  425. cgc.dependentHashModules !== undefined &&
  426. cgc.dependentHashModules.has(/** @type {RuntimeModule} */ (oldModule))
  427. ) {
  428. cgc.dependentHashModules.delete(
  429. /** @type {RuntimeModule} */ (oldModule)
  430. );
  431. cgc.dependentHashModules.add(
  432. /** @type {RuntimeModule} */ (newModule)
  433. );
  434. }
  435. }
  436. oldCgm.runtimeInChunks = undefined;
  437. }
  438. }
  439. /**
  440. * @param {Module} module the checked module
  441. * @param {Chunk} chunk the checked chunk
  442. * @returns {boolean} true, if the chunk contains the module
  443. */
  444. isModuleInChunk(module, chunk) {
  445. const cgc = this._getChunkGraphChunk(chunk);
  446. return cgc.modules.has(module);
  447. }
  448. /**
  449. * @param {Module} module the checked module
  450. * @param {ChunkGroup} chunkGroup the checked chunk group
  451. * @returns {boolean} true, if the chunk contains the module
  452. */
  453. isModuleInChunkGroup(module, chunkGroup) {
  454. for (const chunk of chunkGroup.chunks) {
  455. if (this.isModuleInChunk(module, chunk)) return true;
  456. }
  457. return false;
  458. }
  459. /**
  460. * @param {Module} module the checked module
  461. * @returns {boolean} true, if the module is entry of any chunk
  462. */
  463. isEntryModule(module) {
  464. const cgm = this._getChunkGraphModule(module);
  465. return cgm.entryInChunks !== undefined;
  466. }
  467. /**
  468. * @param {Module} module the module
  469. * @returns {Iterable<Chunk>} iterable of chunks (do not modify)
  470. */
  471. getModuleChunksIterable(module) {
  472. const cgm = this._getChunkGraphModule(module);
  473. return cgm.chunks;
  474. }
  475. /**
  476. * @param {Module} module the module
  477. * @param {function(Chunk, Chunk): -1|0|1} sortFn sort function
  478. * @returns {Iterable<Chunk>} iterable of chunks (do not modify)
  479. */
  480. getOrderedModuleChunksIterable(module, sortFn) {
  481. const cgm = this._getChunkGraphModule(module);
  482. cgm.chunks.sortWith(sortFn);
  483. return cgm.chunks;
  484. }
  485. /**
  486. * @param {Module} module the module
  487. * @returns {Chunk[]} array of chunks (cached, do not modify)
  488. */
  489. getModuleChunks(module) {
  490. const cgm = this._getChunkGraphModule(module);
  491. return cgm.chunks.getFromCache(getArray);
  492. }
  493. /**
  494. * @param {Module} module the module
  495. * @returns {number} the number of chunk which contain the module
  496. */
  497. getNumberOfModuleChunks(module) {
  498. const cgm = this._getChunkGraphModule(module);
  499. return cgm.chunks.size;
  500. }
  501. /**
  502. * @param {Module} module the module
  503. * @returns {RuntimeSpecSet} runtimes
  504. */
  505. getModuleRuntimes(module) {
  506. const cgm = this._getChunkGraphModule(module);
  507. return cgm.chunks.getFromUnorderedCache(getModuleRuntimes);
  508. }
  509. /**
  510. * @param {Chunk} chunk the chunk
  511. * @returns {number} the number of modules which are contained in this chunk
  512. */
  513. getNumberOfChunkModules(chunk) {
  514. const cgc = this._getChunkGraphChunk(chunk);
  515. return cgc.modules.size;
  516. }
  517. /**
  518. * @param {Chunk} chunk the chunk
  519. * @returns {number} the number of full hash modules which are contained in this chunk
  520. */
  521. getNumberOfChunkFullHashModules(chunk) {
  522. const cgc = this._getChunkGraphChunk(chunk);
  523. return cgc.fullHashModules === undefined ? 0 : cgc.fullHashModules.size;
  524. }
  525. /**
  526. * @param {Chunk} chunk the chunk
  527. * @returns {Iterable<Module>} return the modules for this chunk
  528. */
  529. getChunkModulesIterable(chunk) {
  530. const cgc = this._getChunkGraphChunk(chunk);
  531. return cgc.modules;
  532. }
  533. /**
  534. * @param {Chunk} chunk the chunk
  535. * @param {string} sourceType source type
  536. * @returns {Iterable<Module> | undefined} return the modules for this chunk
  537. */
  538. getChunkModulesIterableBySourceType(chunk, sourceType) {
  539. const cgc = this._getChunkGraphChunk(chunk);
  540. const modulesWithSourceType = cgc.modules
  541. .getFromUnorderedCache(cgc._modulesBySourceType)
  542. .get(sourceType);
  543. return modulesWithSourceType;
  544. }
  545. /**
  546. * @param {Chunk} chunk chunk
  547. * @param {Module} module chunk module
  548. * @param {Set<string>} sourceTypes source types
  549. */
  550. setChunkModuleSourceTypes(chunk, module, sourceTypes) {
  551. const cgc = this._getChunkGraphChunk(chunk);
  552. if (cgc.sourceTypesByModule === undefined) {
  553. cgc.sourceTypesByModule = new WeakMap();
  554. }
  555. cgc.sourceTypesByModule.set(module, sourceTypes);
  556. // Update cgc._modulesBySourceType to invalidate the cache
  557. cgc._modulesBySourceType = modulesBySourceType(cgc.sourceTypesByModule);
  558. }
  559. /**
  560. * @param {Chunk} chunk chunk
  561. * @param {Module} module chunk module
  562. * @returns {Set<string>} source types
  563. */
  564. getChunkModuleSourceTypes(chunk, module) {
  565. const cgc = this._getChunkGraphChunk(chunk);
  566. if (cgc.sourceTypesByModule === undefined) {
  567. return module.getSourceTypes();
  568. }
  569. return cgc.sourceTypesByModule.get(module) || module.getSourceTypes();
  570. }
  571. /**
  572. * @param {Module} module module
  573. * @returns {Set<string>} source types
  574. */
  575. getModuleSourceTypes(module) {
  576. return (
  577. this._getOverwrittenModuleSourceTypes(module) || module.getSourceTypes()
  578. );
  579. }
  580. /**
  581. * @param {Module} module module
  582. * @returns {Set<string> | undefined} source types
  583. */
  584. _getOverwrittenModuleSourceTypes(module) {
  585. let newSet = false;
  586. let sourceTypes;
  587. for (const chunk of this.getModuleChunksIterable(module)) {
  588. const cgc = this._getChunkGraphChunk(chunk);
  589. if (cgc.sourceTypesByModule === undefined) return;
  590. const st = cgc.sourceTypesByModule.get(module);
  591. if (st === undefined) return;
  592. if (!sourceTypes) {
  593. sourceTypes = st;
  594. continue;
  595. } else if (!newSet) {
  596. for (const type of st) {
  597. if (!newSet) {
  598. if (!sourceTypes.has(type)) {
  599. newSet = true;
  600. sourceTypes = new Set(sourceTypes);
  601. sourceTypes.add(type);
  602. }
  603. } else {
  604. sourceTypes.add(type);
  605. }
  606. }
  607. } else {
  608. for (const type of st) sourceTypes.add(type);
  609. }
  610. }
  611. return sourceTypes;
  612. }
  613. /**
  614. * @param {Chunk} chunk the chunk
  615. * @param {function(Module, Module): -1|0|1} comparator comparator function
  616. * @returns {Iterable<Module>} return the modules for this chunk
  617. */
  618. getOrderedChunkModulesIterable(chunk, comparator) {
  619. const cgc = this._getChunkGraphChunk(chunk);
  620. cgc.modules.sortWith(comparator);
  621. return cgc.modules;
  622. }
  623. /**
  624. * @param {Chunk} chunk the chunk
  625. * @param {string} sourceType source type
  626. * @param {function(Module, Module): -1|0|1} comparator comparator function
  627. * @returns {Iterable<Module> | undefined} return the modules for this chunk
  628. */
  629. getOrderedChunkModulesIterableBySourceType(chunk, sourceType, comparator) {
  630. const cgc = this._getChunkGraphChunk(chunk);
  631. const modulesWithSourceType = cgc.modules
  632. .getFromUnorderedCache(cgc._modulesBySourceType)
  633. .get(sourceType);
  634. if (modulesWithSourceType === undefined) return undefined;
  635. modulesWithSourceType.sortWith(comparator);
  636. return modulesWithSourceType;
  637. }
  638. /**
  639. * @param {Chunk} chunk the chunk
  640. * @returns {Module[]} return the modules for this chunk (cached, do not modify)
  641. */
  642. getChunkModules(chunk) {
  643. const cgc = this._getChunkGraphChunk(chunk);
  644. return cgc.modules.getFromUnorderedCache(getArray);
  645. }
  646. /**
  647. * @param {Chunk} chunk the chunk
  648. * @param {function(Module, Module): -1|0|1} comparator comparator function
  649. * @returns {Module[]} return the modules for this chunk (cached, do not modify)
  650. */
  651. getOrderedChunkModules(chunk, comparator) {
  652. const cgc = this._getChunkGraphChunk(chunk);
  653. const arrayFunction = createOrderedArrayFunction(comparator);
  654. return cgc.modules.getFromUnorderedCache(arrayFunction);
  655. }
  656. /**
  657. * @param {Chunk} chunk the chunk
  658. * @param {ModuleFilterPredicate} filterFn function used to filter modules
  659. * @param {boolean} includeAllChunks all chunks or only async chunks
  660. * @returns {Record<string|number, (string|number)[]>} chunk to module ids object
  661. */
  662. getChunkModuleIdMap(chunk, filterFn, includeAllChunks = false) {
  663. /** @type {Record<string|number, (string|number)[]>} */
  664. const chunkModuleIdMap = Object.create(null);
  665. for (const asyncChunk of includeAllChunks
  666. ? chunk.getAllReferencedChunks()
  667. : chunk.getAllAsyncChunks()) {
  668. /** @type {(string | number)[] | undefined} */
  669. let array;
  670. for (const module of this.getOrderedChunkModulesIterable(
  671. asyncChunk,
  672. compareModulesById(this)
  673. )) {
  674. if (filterFn(module)) {
  675. if (array === undefined) {
  676. array = [];
  677. chunkModuleIdMap[asyncChunk.id] = array;
  678. }
  679. const moduleId = this.getModuleId(module);
  680. array.push(moduleId);
  681. }
  682. }
  683. }
  684. return chunkModuleIdMap;
  685. }
  686. /**
  687. * @param {Chunk} chunk the chunk
  688. * @param {ModuleFilterPredicate} filterFn function used to filter modules
  689. * @param {number} hashLength length of the hash
  690. * @param {boolean} includeAllChunks all chunks or only async chunks
  691. * @returns {Record<string|number, Record<string|number, string>>} chunk to module id to module hash object
  692. */
  693. getChunkModuleRenderedHashMap(
  694. chunk,
  695. filterFn,
  696. hashLength = 0,
  697. includeAllChunks = false
  698. ) {
  699. /** @type {Record<string|number, Record<string|number, string>>} */
  700. const chunkModuleHashMap = Object.create(null);
  701. for (const asyncChunk of includeAllChunks
  702. ? chunk.getAllReferencedChunks()
  703. : chunk.getAllAsyncChunks()) {
  704. /** @type {Record<string|number, string> | undefined} */
  705. let idToHashMap;
  706. for (const module of this.getOrderedChunkModulesIterable(
  707. asyncChunk,
  708. compareModulesById(this)
  709. )) {
  710. if (filterFn(module)) {
  711. if (idToHashMap === undefined) {
  712. idToHashMap = Object.create(null);
  713. chunkModuleHashMap[asyncChunk.id] = idToHashMap;
  714. }
  715. const moduleId = this.getModuleId(module);
  716. const hash = this.getRenderedModuleHash(module, asyncChunk.runtime);
  717. idToHashMap[moduleId] = hashLength ? hash.slice(0, hashLength) : hash;
  718. }
  719. }
  720. }
  721. return chunkModuleHashMap;
  722. }
  723. /**
  724. * @param {Chunk} chunk the chunk
  725. * @param {ChunkFilterPredicate} filterFn function used to filter chunks
  726. * @returns {Record<string|number, boolean>} chunk map
  727. */
  728. getChunkConditionMap(chunk, filterFn) {
  729. const map = Object.create(null);
  730. for (const c of chunk.getAllReferencedChunks()) {
  731. map[c.id] = filterFn(c, this);
  732. }
  733. return map;
  734. }
  735. /**
  736. * @param {Chunk} chunk the chunk
  737. * @param {ModuleFilterPredicate} filterFn predicate function used to filter modules
  738. * @param {ChunkFilterPredicate=} filterChunkFn predicate function used to filter chunks
  739. * @returns {boolean} return true if module exists in graph
  740. */
  741. hasModuleInGraph(chunk, filterFn, filterChunkFn) {
  742. const queue = new Set(chunk.groupsIterable);
  743. const chunksProcessed = new Set();
  744. for (const chunkGroup of queue) {
  745. for (const innerChunk of chunkGroup.chunks) {
  746. if (!chunksProcessed.has(innerChunk)) {
  747. chunksProcessed.add(innerChunk);
  748. if (!filterChunkFn || filterChunkFn(innerChunk, this)) {
  749. for (const module of this.getChunkModulesIterable(innerChunk)) {
  750. if (filterFn(module)) {
  751. return true;
  752. }
  753. }
  754. }
  755. }
  756. }
  757. for (const child of chunkGroup.childrenIterable) {
  758. queue.add(child);
  759. }
  760. }
  761. return false;
  762. }
  763. /**
  764. * @param {Chunk} chunkA first chunk
  765. * @param {Chunk} chunkB second chunk
  766. * @returns {-1|0|1} this is a comparator function like sort and returns -1, 0, or 1 based on sort order
  767. */
  768. compareChunks(chunkA, chunkB) {
  769. const cgcA = this._getChunkGraphChunk(chunkA);
  770. const cgcB = this._getChunkGraphChunk(chunkB);
  771. if (cgcA.modules.size > cgcB.modules.size) return -1;
  772. if (cgcA.modules.size < cgcB.modules.size) return 1;
  773. cgcA.modules.sortWith(compareModulesByIdentifier);
  774. cgcB.modules.sortWith(compareModulesByIdentifier);
  775. return compareModuleIterables(cgcA.modules, cgcB.modules);
  776. }
  777. /**
  778. * @param {Chunk} chunk the chunk
  779. * @returns {number} total size of all modules in the chunk
  780. */
  781. getChunkModulesSize(chunk) {
  782. const cgc = this._getChunkGraphChunk(chunk);
  783. return cgc.modules.getFromUnorderedCache(getModulesSize);
  784. }
  785. /**
  786. * @param {Chunk} chunk the chunk
  787. * @returns {Record<string, number>} total sizes of all modules in the chunk by source type
  788. */
  789. getChunkModulesSizes(chunk) {
  790. const cgc = this._getChunkGraphChunk(chunk);
  791. return cgc.modules.getFromUnorderedCache(getModulesSizes);
  792. }
  793. /**
  794. * @param {Chunk} chunk the chunk
  795. * @returns {Module[]} root modules of the chunks (ordered by identifier)
  796. */
  797. getChunkRootModules(chunk) {
  798. const cgc = this._getChunkGraphChunk(chunk);
  799. return cgc.modules.getFromUnorderedCache(this._getGraphRoots);
  800. }
  801. /**
  802. * @param {Chunk} chunk the chunk
  803. * @param {ChunkSizeOptions} options options object
  804. * @returns {number} total size of the chunk
  805. */
  806. getChunkSize(chunk, options = {}) {
  807. const cgc = this._getChunkGraphChunk(chunk);
  808. const modulesSize = cgc.modules.getFromUnorderedCache(getModulesSize);
  809. const chunkOverhead =
  810. typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000;
  811. const entryChunkMultiplicator =
  812. typeof options.entryChunkMultiplicator === "number"
  813. ? options.entryChunkMultiplicator
  814. : 10;
  815. return (
  816. chunkOverhead +
  817. modulesSize * (chunk.canBeInitial() ? entryChunkMultiplicator : 1)
  818. );
  819. }
  820. /**
  821. * @param {Chunk} chunkA chunk
  822. * @param {Chunk} chunkB chunk
  823. * @param {ChunkSizeOptions} options options object
  824. * @returns {number} total size of the chunk or false if chunks can't be integrated
  825. */
  826. getIntegratedChunksSize(chunkA, chunkB, options = {}) {
  827. const cgcA = this._getChunkGraphChunk(chunkA);
  828. const cgcB = this._getChunkGraphChunk(chunkB);
  829. const allModules = new Set(cgcA.modules);
  830. for (const m of cgcB.modules) allModules.add(m);
  831. let modulesSize = getModulesSize(allModules);
  832. const chunkOverhead =
  833. typeof options.chunkOverhead === "number" ? options.chunkOverhead : 10000;
  834. const entryChunkMultiplicator =
  835. typeof options.entryChunkMultiplicator === "number"
  836. ? options.entryChunkMultiplicator
  837. : 10;
  838. return (
  839. chunkOverhead +
  840. modulesSize *
  841. (chunkA.canBeInitial() || chunkB.canBeInitial()
  842. ? entryChunkMultiplicator
  843. : 1)
  844. );
  845. }
  846. /**
  847. * @param {Chunk} chunkA chunk
  848. * @param {Chunk} chunkB chunk
  849. * @returns {boolean} true, if chunks could be integrated
  850. */
  851. canChunksBeIntegrated(chunkA, chunkB) {
  852. if (chunkA.preventIntegration || chunkB.preventIntegration) {
  853. return false;
  854. }
  855. const hasRuntimeA = chunkA.hasRuntime();
  856. const hasRuntimeB = chunkB.hasRuntime();
  857. if (hasRuntimeA !== hasRuntimeB) {
  858. if (hasRuntimeA) {
  859. return isAvailableChunk(chunkA, chunkB);
  860. } else if (hasRuntimeB) {
  861. return isAvailableChunk(chunkB, chunkA);
  862. } else {
  863. return false;
  864. }
  865. }
  866. if (
  867. this.getNumberOfEntryModules(chunkA) > 0 ||
  868. this.getNumberOfEntryModules(chunkB) > 0
  869. ) {
  870. return false;
  871. }
  872. return true;
  873. }
  874. /**
  875. * @param {Chunk} chunkA the target chunk
  876. * @param {Chunk} chunkB the chunk to integrate
  877. * @returns {void}
  878. */
  879. integrateChunks(chunkA, chunkB) {
  880. // Decide for one name (deterministic)
  881. if (chunkA.name && chunkB.name) {
  882. if (
  883. this.getNumberOfEntryModules(chunkA) > 0 ===
  884. this.getNumberOfEntryModules(chunkB) > 0
  885. ) {
  886. // When both chunks have entry modules or none have one, use
  887. // shortest name
  888. if (chunkA.name.length !== chunkB.name.length) {
  889. chunkA.name =
  890. chunkA.name.length < chunkB.name.length ? chunkA.name : chunkB.name;
  891. } else {
  892. chunkA.name = chunkA.name < chunkB.name ? chunkA.name : chunkB.name;
  893. }
  894. } else if (this.getNumberOfEntryModules(chunkB) > 0) {
  895. // Pick the name of the chunk with the entry module
  896. chunkA.name = chunkB.name;
  897. }
  898. } else if (chunkB.name) {
  899. chunkA.name = chunkB.name;
  900. }
  901. // Merge id name hints
  902. for (const hint of chunkB.idNameHints) {
  903. chunkA.idNameHints.add(hint);
  904. }
  905. // Merge runtime
  906. chunkA.runtime = mergeRuntime(chunkA.runtime, chunkB.runtime);
  907. // getChunkModules is used here to create a clone, because disconnectChunkAndModule modifies
  908. for (const module of this.getChunkModules(chunkB)) {
  909. this.disconnectChunkAndModule(chunkB, module);
  910. this.connectChunkAndModule(chunkA, module);
  911. }
  912. for (const [module, chunkGroup] of Array.from(
  913. this.getChunkEntryModulesWithChunkGroupIterable(chunkB)
  914. )) {
  915. this.disconnectChunkAndEntryModule(chunkB, module);
  916. this.connectChunkAndEntryModule(chunkA, module, chunkGroup);
  917. }
  918. for (const chunkGroup of chunkB.groupsIterable) {
  919. chunkGroup.replaceChunk(chunkB, chunkA);
  920. chunkA.addGroup(chunkGroup);
  921. chunkB.removeGroup(chunkGroup);
  922. }
  923. ChunkGraph.clearChunkGraphForChunk(chunkB);
  924. }
  925. /**
  926. * @param {Chunk} chunk the chunk to upgrade
  927. * @returns {void}
  928. */
  929. upgradeDependentToFullHashModules(chunk) {
  930. const cgc = this._getChunkGraphChunk(chunk);
  931. if (cgc.dependentHashModules === undefined) return;
  932. if (cgc.fullHashModules === undefined) {
  933. cgc.fullHashModules = cgc.dependentHashModules;
  934. } else {
  935. for (const m of cgc.dependentHashModules) {
  936. cgc.fullHashModules.add(m);
  937. }
  938. cgc.dependentHashModules = undefined;
  939. }
  940. }
  941. /**
  942. * @param {Module} module the checked module
  943. * @param {Chunk} chunk the checked chunk
  944. * @returns {boolean} true, if the chunk contains the module as entry
  945. */
  946. isEntryModuleInChunk(module, chunk) {
  947. const cgc = this._getChunkGraphChunk(chunk);
  948. return cgc.entryModules.has(module);
  949. }
  950. /**
  951. * @param {Chunk} chunk the new chunk
  952. * @param {Module} module the entry module
  953. * @param {Entrypoint=} entrypoint the chunk group which must be loaded before the module is executed
  954. * @returns {void}
  955. */
  956. connectChunkAndEntryModule(chunk, module, entrypoint) {
  957. const cgm = this._getChunkGraphModule(module);
  958. const cgc = this._getChunkGraphChunk(chunk);
  959. if (cgm.entryInChunks === undefined) {
  960. cgm.entryInChunks = new Set();
  961. }
  962. cgm.entryInChunks.add(chunk);
  963. cgc.entryModules.set(module, entrypoint);
  964. }
  965. /**
  966. * @param {Chunk} chunk the new chunk
  967. * @param {RuntimeModule} module the runtime module
  968. * @returns {void}
  969. */
  970. connectChunkAndRuntimeModule(chunk, module) {
  971. const cgm = this._getChunkGraphModule(module);
  972. const cgc = this._getChunkGraphChunk(chunk);
  973. if (cgm.runtimeInChunks === undefined) {
  974. cgm.runtimeInChunks = new Set();
  975. }
  976. cgm.runtimeInChunks.add(chunk);
  977. cgc.runtimeModules.add(module);
  978. }
  979. /**
  980. * @param {Chunk} chunk the new chunk
  981. * @param {RuntimeModule} module the module that require a full hash
  982. * @returns {void}
  983. */
  984. addFullHashModuleToChunk(chunk, module) {
  985. const cgc = this._getChunkGraphChunk(chunk);
  986. if (cgc.fullHashModules === undefined) cgc.fullHashModules = new Set();
  987. cgc.fullHashModules.add(module);
  988. }
  989. /**
  990. * @param {Chunk} chunk the new chunk
  991. * @param {RuntimeModule} module the module that require a full hash
  992. * @returns {void}
  993. */
  994. addDependentHashModuleToChunk(chunk, module) {
  995. const cgc = this._getChunkGraphChunk(chunk);
  996. if (cgc.dependentHashModules === undefined)
  997. cgc.dependentHashModules = new Set();
  998. cgc.dependentHashModules.add(module);
  999. }
  1000. /**
  1001. * @param {Chunk} chunk the new chunk
  1002. * @param {Module} module the entry module
  1003. * @returns {void}
  1004. */
  1005. disconnectChunkAndEntryModule(chunk, module) {
  1006. const cgm = this._getChunkGraphModule(module);
  1007. const cgc = this._getChunkGraphChunk(chunk);
  1008. cgm.entryInChunks.delete(chunk);
  1009. if (cgm.entryInChunks.size === 0) {
  1010. cgm.entryInChunks = undefined;
  1011. }
  1012. cgc.entryModules.delete(module);
  1013. }
  1014. /**
  1015. * @param {Chunk} chunk the new chunk
  1016. * @param {RuntimeModule} module the runtime module
  1017. * @returns {void}
  1018. */
  1019. disconnectChunkAndRuntimeModule(chunk, module) {
  1020. const cgm = this._getChunkGraphModule(module);
  1021. const cgc = this._getChunkGraphChunk(chunk);
  1022. cgm.runtimeInChunks.delete(chunk);
  1023. if (cgm.runtimeInChunks.size === 0) {
  1024. cgm.runtimeInChunks = undefined;
  1025. }
  1026. cgc.runtimeModules.delete(module);
  1027. }
  1028. /**
  1029. * @param {Module} module the entry module, it will no longer be entry
  1030. * @returns {void}
  1031. */
  1032. disconnectEntryModule(module) {
  1033. const cgm = this._getChunkGraphModule(module);
  1034. for (const chunk of /** @type {EntryInChunks} */ (cgm.entryInChunks)) {
  1035. const cgc = this._getChunkGraphChunk(chunk);
  1036. cgc.entryModules.delete(module);
  1037. }
  1038. cgm.entryInChunks = undefined;
  1039. }
  1040. /**
  1041. * @param {Chunk} chunk the chunk, for which all entries will be removed
  1042. * @returns {void}
  1043. */
  1044. disconnectEntries(chunk) {
  1045. const cgc = this._getChunkGraphChunk(chunk);
  1046. for (const module of cgc.entryModules.keys()) {
  1047. const cgm = this._getChunkGraphModule(module);
  1048. cgm.entryInChunks.delete(chunk);
  1049. if (cgm.entryInChunks.size === 0) {
  1050. cgm.entryInChunks = undefined;
  1051. }
  1052. }
  1053. cgc.entryModules.clear();
  1054. }
  1055. /**
  1056. * @param {Chunk} chunk the chunk
  1057. * @returns {number} the amount of entry modules in chunk
  1058. */
  1059. getNumberOfEntryModules(chunk) {
  1060. const cgc = this._getChunkGraphChunk(chunk);
  1061. return cgc.entryModules.size;
  1062. }
  1063. /**
  1064. * @param {Chunk} chunk the chunk
  1065. * @returns {number} the amount of entry modules in chunk
  1066. */
  1067. getNumberOfRuntimeModules(chunk) {
  1068. const cgc = this._getChunkGraphChunk(chunk);
  1069. return cgc.runtimeModules.size;
  1070. }
  1071. /**
  1072. * @param {Chunk} chunk the chunk
  1073. * @returns {Iterable<Module>} iterable of modules (do not modify)
  1074. */
  1075. getChunkEntryModulesIterable(chunk) {
  1076. const cgc = this._getChunkGraphChunk(chunk);
  1077. return cgc.entryModules.keys();
  1078. }
  1079. /**
  1080. * @param {Chunk} chunk the chunk
  1081. * @returns {Iterable<Chunk>} iterable of chunks
  1082. */
  1083. getChunkEntryDependentChunksIterable(chunk) {
  1084. /** @type {Set<Chunk>} */
  1085. const set = new Set();
  1086. for (const chunkGroup of chunk.groupsIterable) {
  1087. if (chunkGroup instanceof Entrypoint) {
  1088. const entrypointChunk = chunkGroup.getEntrypointChunk();
  1089. const cgc = this._getChunkGraphChunk(entrypointChunk);
  1090. for (const chunkGroup of cgc.entryModules.values()) {
  1091. for (const c of chunkGroup.chunks) {
  1092. if (c !== chunk && c !== entrypointChunk && !c.hasRuntime()) {
  1093. set.add(c);
  1094. }
  1095. }
  1096. }
  1097. }
  1098. }
  1099. return set;
  1100. }
  1101. /**
  1102. * @param {Chunk} chunk the chunk
  1103. * @returns {boolean} true, when it has dependent chunks
  1104. */
  1105. hasChunkEntryDependentChunks(chunk) {
  1106. const cgc = this._getChunkGraphChunk(chunk);
  1107. for (const chunkGroup of cgc.entryModules.values()) {
  1108. for (const c of chunkGroup.chunks) {
  1109. if (c !== chunk) {
  1110. return true;
  1111. }
  1112. }
  1113. }
  1114. return false;
  1115. }
  1116. /**
  1117. * @param {Chunk} chunk the chunk
  1118. * @returns {Iterable<RuntimeModule>} iterable of modules (do not modify)
  1119. */
  1120. getChunkRuntimeModulesIterable(chunk) {
  1121. const cgc = this._getChunkGraphChunk(chunk);
  1122. return cgc.runtimeModules;
  1123. }
  1124. /**
  1125. * @param {Chunk} chunk the chunk
  1126. * @returns {RuntimeModule[]} array of modules in order of execution
  1127. */
  1128. getChunkRuntimeModulesInOrder(chunk) {
  1129. const cgc = this._getChunkGraphChunk(chunk);
  1130. const array = Array.from(cgc.runtimeModules);
  1131. array.sort(
  1132. concatComparators(
  1133. compareSelect(r => /** @type {RuntimeModule} */ (r).stage, compareIds),
  1134. compareModulesByIdentifier
  1135. )
  1136. );
  1137. return array;
  1138. }
  1139. /**
  1140. * @param {Chunk} chunk the chunk
  1141. * @returns {Iterable<RuntimeModule> | undefined} iterable of modules (do not modify)
  1142. */
  1143. getChunkFullHashModulesIterable(chunk) {
  1144. const cgc = this._getChunkGraphChunk(chunk);
  1145. return cgc.fullHashModules;
  1146. }
  1147. /**
  1148. * @param {Chunk} chunk the chunk
  1149. * @returns {ReadonlySet<RuntimeModule> | undefined} set of modules (do not modify)
  1150. */
  1151. getChunkFullHashModulesSet(chunk) {
  1152. const cgc = this._getChunkGraphChunk(chunk);
  1153. return cgc.fullHashModules;
  1154. }
  1155. /**
  1156. * @param {Chunk} chunk the chunk
  1157. * @returns {Iterable<RuntimeModule> | undefined} iterable of modules (do not modify)
  1158. */
  1159. getChunkDependentHashModulesIterable(chunk) {
  1160. const cgc = this._getChunkGraphChunk(chunk);
  1161. return cgc.dependentHashModules;
  1162. }
  1163. /**
  1164. * @param {Chunk} chunk the chunk
  1165. * @returns {Iterable<EntryModuleWithChunkGroup>} iterable of modules (do not modify)
  1166. */
  1167. getChunkEntryModulesWithChunkGroupIterable(chunk) {
  1168. const cgc = this._getChunkGraphChunk(chunk);
  1169. return cgc.entryModules;
  1170. }
  1171. /**
  1172. * @param {AsyncDependenciesBlock} depBlock the async block
  1173. * @returns {ChunkGroup | undefined} the chunk group
  1174. */
  1175. getBlockChunkGroup(depBlock) {
  1176. return this._blockChunkGroups.get(depBlock);
  1177. }
  1178. /**
  1179. * @param {AsyncDependenciesBlock} depBlock the async block
  1180. * @param {ChunkGroup} chunkGroup the chunk group
  1181. * @returns {void}
  1182. */
  1183. connectBlockAndChunkGroup(depBlock, chunkGroup) {
  1184. this._blockChunkGroups.set(depBlock, chunkGroup);
  1185. chunkGroup.addBlock(depBlock);
  1186. }
  1187. /**
  1188. * @param {ChunkGroup} chunkGroup the chunk group
  1189. * @returns {void}
  1190. */
  1191. disconnectChunkGroup(chunkGroup) {
  1192. for (const block of chunkGroup.blocksIterable) {
  1193. this._blockChunkGroups.delete(block);
  1194. }
  1195. // TODO refactor by moving blocks list into ChunkGraph
  1196. chunkGroup._blocks.clear();
  1197. }
  1198. /**
  1199. * @param {Module} module the module
  1200. * @returns {string | number} the id of the module
  1201. */
  1202. getModuleId(module) {
  1203. const cgm = this._getChunkGraphModule(module);
  1204. return cgm.id;
  1205. }
  1206. /**
  1207. * @param {Module} module the module
  1208. * @param {string | number} id the id of the module
  1209. * @returns {void}
  1210. */
  1211. setModuleId(module, id) {
  1212. const cgm = this._getChunkGraphModule(module);
  1213. cgm.id = id;
  1214. }
  1215. /**
  1216. * @param {string} runtime runtime
  1217. * @returns {string | number} the id of the runtime
  1218. */
  1219. getRuntimeId(runtime) {
  1220. return this._runtimeIds.get(runtime);
  1221. }
  1222. /**
  1223. * @param {string} runtime runtime
  1224. * @param {string | number} id the id of the runtime
  1225. * @returns {void}
  1226. */
  1227. setRuntimeId(runtime, id) {
  1228. this._runtimeIds.set(runtime, id);
  1229. }
  1230. /**
  1231. * @template T
  1232. * @param {Module} module the module
  1233. * @param {RuntimeSpecMap<T>} hashes hashes data
  1234. * @param {RuntimeSpec} runtime the runtime
  1235. * @returns {T} hash
  1236. */
  1237. _getModuleHashInfo(module, hashes, runtime) {
  1238. if (!hashes) {
  1239. throw new Error(
  1240. `Module ${module.identifier()} has no hash info for runtime ${runtimeToString(
  1241. runtime
  1242. )} (hashes not set at all)`
  1243. );
  1244. } else if (runtime === undefined) {
  1245. const hashInfoItems = new Set(hashes.values());
  1246. if (hashInfoItems.size !== 1) {
  1247. throw new Error(
  1248. `No unique hash info entry for unspecified runtime for ${module.identifier()} (existing runtimes: ${Array.from(
  1249. hashes.keys(),
  1250. r => runtimeToString(r)
  1251. ).join(", ")}).
  1252. Caller might not support runtime-dependent code generation (opt-out via optimization.usedExports: "global").`
  1253. );
  1254. }
  1255. return /** @type {T} */ (first(hashInfoItems));
  1256. } else {
  1257. const hashInfo = hashes.get(runtime);
  1258. if (!hashInfo) {
  1259. throw new Error(
  1260. `Module ${module.identifier()} has no hash info for runtime ${runtimeToString(
  1261. runtime
  1262. )} (available runtimes ${Array.from(
  1263. hashes.keys(),
  1264. runtimeToString
  1265. ).join(", ")})`
  1266. );
  1267. }
  1268. return hashInfo;
  1269. }
  1270. }
  1271. /**
  1272. * @param {Module} module the module
  1273. * @param {RuntimeSpec} runtime the runtime
  1274. * @returns {boolean} true, if the module has hashes for this runtime
  1275. */
  1276. hasModuleHashes(module, runtime) {
  1277. const cgm = this._getChunkGraphModule(module);
  1278. const hashes = /** @type {RuntimeSpecMap<ModuleHashInfo>} */ (cgm.hashes);
  1279. return hashes && hashes.has(runtime);
  1280. }
  1281. /**
  1282. * @param {Module} module the module
  1283. * @param {RuntimeSpec} runtime the runtime
  1284. * @returns {string} hash
  1285. */
  1286. getModuleHash(module, runtime) {
  1287. const cgm = this._getChunkGraphModule(module);
  1288. const hashes = /** @type {RuntimeSpecMap<ModuleHashInfo>} */ (cgm.hashes);
  1289. return this._getModuleHashInfo(module, hashes, runtime).hash;
  1290. }
  1291. /**
  1292. * @param {Module} module the module
  1293. * @param {RuntimeSpec} runtime the runtime
  1294. * @returns {string} hash
  1295. */
  1296. getRenderedModuleHash(module, runtime) {
  1297. const cgm = this._getChunkGraphModule(module);
  1298. const hashes = /** @type {RuntimeSpecMap<ModuleHashInfo>} */ (cgm.hashes);
  1299. return this._getModuleHashInfo(module, hashes, runtime).renderedHash;
  1300. }
  1301. /**
  1302. * @param {Module} module the module
  1303. * @param {RuntimeSpec} runtime the runtime
  1304. * @param {string} hash the full hash
  1305. * @param {string} renderedHash the shortened hash for rendering
  1306. * @returns {void}
  1307. */
  1308. setModuleHashes(module, runtime, hash, renderedHash) {
  1309. const cgm = this._getChunkGraphModule(module);
  1310. if (cgm.hashes === undefined) {
  1311. cgm.hashes = new RuntimeSpecMap();
  1312. }
  1313. cgm.hashes.set(runtime, new ModuleHashInfo(hash, renderedHash));
  1314. }
  1315. /**
  1316. * @param {Module} module the module
  1317. * @param {RuntimeSpec} runtime the runtime
  1318. * @param {Set<string>} items runtime requirements to be added (ownership of this Set is given to ChunkGraph when transferOwnership not false)
  1319. * @param {boolean} transferOwnership true: transfer ownership of the items object, false: items is immutable and shared and won't be modified
  1320. * @returns {void}
  1321. */
  1322. addModuleRuntimeRequirements(
  1323. module,
  1324. runtime,
  1325. items,
  1326. transferOwnership = true
  1327. ) {
  1328. const cgm = this._getChunkGraphModule(module);
  1329. const runtimeRequirementsMap = cgm.runtimeRequirements;
  1330. if (runtimeRequirementsMap === undefined) {
  1331. const map = new RuntimeSpecMap();
  1332. // TODO avoid cloning item and track ownership instead
  1333. map.set(runtime, transferOwnership ? items : new Set(items));
  1334. cgm.runtimeRequirements = map;
  1335. return;
  1336. }
  1337. runtimeRequirementsMap.update(runtime, runtimeRequirements => {
  1338. if (runtimeRequirements === undefined) {
  1339. return transferOwnership ? items : new Set(items);
  1340. } else if (!transferOwnership || runtimeRequirements.size >= items.size) {
  1341. for (const item of items) runtimeRequirements.add(item);
  1342. return runtimeRequirements;
  1343. } else {
  1344. for (const item of runtimeRequirements) items.add(item);
  1345. return items;
  1346. }
  1347. });
  1348. }
  1349. /**
  1350. * @param {Chunk} chunk the chunk
  1351. * @param {Set<string>} items runtime requirements to be added (ownership of this Set is given to ChunkGraph)
  1352. * @returns {void}
  1353. */
  1354. addChunkRuntimeRequirements(chunk, items) {
  1355. const cgc = this._getChunkGraphChunk(chunk);
  1356. const runtimeRequirements = cgc.runtimeRequirements;
  1357. if (runtimeRequirements === undefined) {
  1358. cgc.runtimeRequirements = items;
  1359. } else if (runtimeRequirements.size >= items.size) {
  1360. for (const item of items) runtimeRequirements.add(item);
  1361. } else {
  1362. for (const item of runtimeRequirements) items.add(item);
  1363. cgc.runtimeRequirements = items;
  1364. }
  1365. }
  1366. /**
  1367. * @param {Chunk} chunk the chunk
  1368. * @param {Iterable<string>} items runtime requirements to be added
  1369. * @returns {void}
  1370. */
  1371. addTreeRuntimeRequirements(chunk, items) {
  1372. const cgc = this._getChunkGraphChunk(chunk);
  1373. const runtimeRequirements = cgc.runtimeRequirementsInTree;
  1374. for (const item of items) runtimeRequirements.add(item);
  1375. }
  1376. /**
  1377. * @param {Module} module the module
  1378. * @param {RuntimeSpec} runtime the runtime
  1379. * @returns {ReadonlySet<string>} runtime requirements
  1380. */
  1381. getModuleRuntimeRequirements(module, runtime) {
  1382. const cgm = this._getChunkGraphModule(module);
  1383. const runtimeRequirements =
  1384. cgm.runtimeRequirements && cgm.runtimeRequirements.get(runtime);
  1385. return runtimeRequirements === undefined ? EMPTY_SET : runtimeRequirements;
  1386. }
  1387. /**
  1388. * @param {Chunk} chunk the chunk
  1389. * @returns {ReadonlySet<string>} runtime requirements
  1390. */
  1391. getChunkRuntimeRequirements(chunk) {
  1392. const cgc = this._getChunkGraphChunk(chunk);
  1393. const runtimeRequirements = cgc.runtimeRequirements;
  1394. return runtimeRequirements === undefined ? EMPTY_SET : runtimeRequirements;
  1395. }
  1396. /**
  1397. * @param {Module} module the module
  1398. * @param {RuntimeSpec} runtime the runtime
  1399. * @param {boolean} withConnections include connections
  1400. * @returns {string} hash
  1401. */
  1402. getModuleGraphHash(module, runtime, withConnections = true) {
  1403. const cgm = this._getChunkGraphModule(module);
  1404. return withConnections
  1405. ? this._getModuleGraphHashWithConnections(cgm, module, runtime)
  1406. : this._getModuleGraphHashBigInt(cgm, module, runtime).toString(16);
  1407. }
  1408. /**
  1409. * @param {Module} module the module
  1410. * @param {RuntimeSpec} runtime the runtime
  1411. * @param {boolean} withConnections include connections
  1412. * @returns {bigint} hash
  1413. */
  1414. getModuleGraphHashBigInt(module, runtime, withConnections = true) {
  1415. const cgm = this._getChunkGraphModule(module);
  1416. return withConnections
  1417. ? BigInt(
  1418. `0x${this._getModuleGraphHashWithConnections(cgm, module, runtime)}`
  1419. )
  1420. : this._getModuleGraphHashBigInt(cgm, module, runtime);
  1421. }
  1422. /**
  1423. * @param {ChunkGraphModule} cgm the ChunkGraphModule
  1424. * @param {Module} module the module
  1425. * @param {RuntimeSpec} runtime the runtime
  1426. * @returns {bigint} hash as big int
  1427. */
  1428. _getModuleGraphHashBigInt(cgm, module, runtime) {
  1429. if (cgm.graphHashes === undefined) {
  1430. cgm.graphHashes = new RuntimeSpecMap();
  1431. }
  1432. const graphHash = cgm.graphHashes.provide(runtime, () => {
  1433. const hash = createHash(this._hashFunction);
  1434. hash.update(`${cgm.id}${this.moduleGraph.isAsync(module)}`);
  1435. const sourceTypes = this._getOverwrittenModuleSourceTypes(module);
  1436. if (sourceTypes !== undefined) {
  1437. for (const type of sourceTypes) hash.update(type);
  1438. }
  1439. this.moduleGraph.getExportsInfo(module).updateHash(hash, runtime);
  1440. return BigInt(`0x${/** @type {string} */ (hash.digest("hex"))}`);
  1441. });
  1442. return graphHash;
  1443. }
  1444. /**
  1445. * @param {ChunkGraphModule} cgm the ChunkGraphModule
  1446. * @param {Module} module the module
  1447. * @param {RuntimeSpec} runtime the runtime
  1448. * @returns {string} hash
  1449. */
  1450. _getModuleGraphHashWithConnections(cgm, module, runtime) {
  1451. if (cgm.graphHashesWithConnections === undefined) {
  1452. cgm.graphHashesWithConnections = new RuntimeSpecMap();
  1453. }
  1454. /**
  1455. * @param {ConnectionState} state state
  1456. * @returns {"F" | "T" | "O"} result
  1457. */
  1458. const activeStateToString = state => {
  1459. if (state === false) return "F";
  1460. if (state === true) return "T";
  1461. if (state === ModuleGraphConnection.TRANSITIVE_ONLY) return "O";
  1462. throw new Error("Not implemented active state");
  1463. };
  1464. const strict = module.buildMeta && module.buildMeta.strictHarmonyModule;
  1465. return cgm.graphHashesWithConnections.provide(runtime, () => {
  1466. const graphHash = this._getModuleGraphHashBigInt(
  1467. cgm,
  1468. module,
  1469. runtime
  1470. ).toString(16);
  1471. const connections = this.moduleGraph.getOutgoingConnections(module);
  1472. /** @type {Set<Module>} */
  1473. const activeNamespaceModules = new Set();
  1474. /** @type {Map<string, Module | Set<Module>>} */
  1475. const connectedModules = new Map();
  1476. const processConnection = (connection, stateInfo) => {
  1477. const module = connection.module;
  1478. stateInfo += module.getExportsType(this.moduleGraph, strict);
  1479. // cspell:word Tnamespace
  1480. if (stateInfo === "Tnamespace") activeNamespaceModules.add(module);
  1481. else {
  1482. const oldModule = connectedModules.get(stateInfo);
  1483. if (oldModule === undefined) {
  1484. connectedModules.set(stateInfo, module);
  1485. } else if (oldModule instanceof Set) {
  1486. oldModule.add(module);
  1487. } else if (oldModule !== module) {
  1488. connectedModules.set(stateInfo, new Set([oldModule, module]));
  1489. }
  1490. }
  1491. };
  1492. if (runtime === undefined || typeof runtime === "string") {
  1493. for (const connection of connections) {
  1494. const state = connection.getActiveState(runtime);
  1495. if (state === false) continue;
  1496. processConnection(connection, state === true ? "T" : "O");
  1497. }
  1498. } else {
  1499. // cspell:word Tnamespace
  1500. for (const connection of connections) {
  1501. const states = new Set();
  1502. let stateInfo = "";
  1503. forEachRuntime(
  1504. runtime,
  1505. runtime => {
  1506. const state = connection.getActiveState(runtime);
  1507. states.add(state);
  1508. stateInfo += activeStateToString(state) + runtime;
  1509. },
  1510. true
  1511. );
  1512. if (states.size === 1) {
  1513. const state = first(states);
  1514. if (state === false) continue;
  1515. stateInfo = activeStateToString(state);
  1516. }
  1517. processConnection(connection, stateInfo);
  1518. }
  1519. }
  1520. // cspell:word Tnamespace
  1521. if (activeNamespaceModules.size === 0 && connectedModules.size === 0)
  1522. return graphHash;
  1523. const connectedModulesInOrder =
  1524. connectedModules.size > 1
  1525. ? Array.from(connectedModules).sort(([a], [b]) => (a < b ? -1 : 1))
  1526. : connectedModules;
  1527. const hash = createHash(this._hashFunction);
  1528. /**
  1529. * @param {Module} module module
  1530. */
  1531. const addModuleToHash = module => {
  1532. hash.update(
  1533. this._getModuleGraphHashBigInt(
  1534. this._getChunkGraphModule(module),
  1535. module,
  1536. runtime
  1537. ).toString(16)
  1538. );
  1539. };
  1540. /**
  1541. * @param {Set<Module>} modules modules
  1542. */
  1543. const addModulesToHash = modules => {
  1544. let xor = ZERO_BIG_INT;
  1545. for (const m of modules) {
  1546. xor =
  1547. xor ^
  1548. this._getModuleGraphHashBigInt(
  1549. this._getChunkGraphModule(m),
  1550. m,
  1551. runtime
  1552. );
  1553. }
  1554. hash.update(xor.toString(16));
  1555. };
  1556. if (activeNamespaceModules.size === 1)
  1557. addModuleToHash(activeNamespaceModules.values().next().value);
  1558. else if (activeNamespaceModules.size > 1)
  1559. addModulesToHash(activeNamespaceModules);
  1560. for (const [stateInfo, modules] of connectedModulesInOrder) {
  1561. hash.update(stateInfo);
  1562. if (modules instanceof Set) {
  1563. addModulesToHash(modules);
  1564. } else {
  1565. addModuleToHash(modules);
  1566. }
  1567. }
  1568. hash.update(graphHash);
  1569. return /** @type {string} */ (hash.digest("hex"));
  1570. });
  1571. }
  1572. /**
  1573. * @param {Chunk} chunk the chunk
  1574. * @returns {ReadonlySet<string>} runtime requirements
  1575. */
  1576. getTreeRuntimeRequirements(chunk) {
  1577. const cgc = this._getChunkGraphChunk(chunk);
  1578. return cgc.runtimeRequirementsInTree;
  1579. }
  1580. // TODO remove in webpack 6
  1581. /**
  1582. * @param {Module} module the module
  1583. * @param {string} deprecateMessage message for the deprecation message
  1584. * @param {string} deprecationCode code for the deprecation
  1585. * @returns {ChunkGraph} the chunk graph
  1586. */
  1587. static getChunkGraphForModule(module, deprecateMessage, deprecationCode) {
  1588. const fn = deprecateGetChunkGraphForModuleMap.get(deprecateMessage);
  1589. if (fn) return fn(module);
  1590. const newFn = util.deprecate(
  1591. /**
  1592. * @param {Module} module the module
  1593. * @returns {ChunkGraph} the chunk graph
  1594. */
  1595. module => {
  1596. const chunkGraph = chunkGraphForModuleMap.get(module);
  1597. if (!chunkGraph)
  1598. throw new Error(
  1599. deprecateMessage +
  1600. ": There was no ChunkGraph assigned to the Module for backward-compat (Use the new API)"
  1601. );
  1602. return chunkGraph;
  1603. },
  1604. deprecateMessage + ": Use new ChunkGraph API",
  1605. deprecationCode
  1606. );
  1607. deprecateGetChunkGraphForModuleMap.set(deprecateMessage, newFn);
  1608. return newFn(module);
  1609. }
  1610. // TODO remove in webpack 6
  1611. /**
  1612. * @param {Module} module the module
  1613. * @param {ChunkGraph} chunkGraph the chunk graph
  1614. * @returns {void}
  1615. */
  1616. static setChunkGraphForModule(module, chunkGraph) {
  1617. chunkGraphForModuleMap.set(module, chunkGraph);
  1618. }
  1619. // TODO remove in webpack 6
  1620. /**
  1621. * @param {Module} module the module
  1622. * @returns {void}
  1623. */
  1624. static clearChunkGraphForModule(module) {
  1625. chunkGraphForModuleMap.delete(module);
  1626. }
  1627. // TODO remove in webpack 6
  1628. /**
  1629. * @param {Chunk} chunk the chunk
  1630. * @param {string} deprecateMessage message for the deprecation message
  1631. * @param {string} deprecationCode code for the deprecation
  1632. * @returns {ChunkGraph} the chunk graph
  1633. */
  1634. static getChunkGraphForChunk(chunk, deprecateMessage, deprecationCode) {
  1635. const fn = deprecateGetChunkGraphForChunkMap.get(deprecateMessage);
  1636. if (fn) return fn(chunk);
  1637. const newFn = util.deprecate(
  1638. /**
  1639. * @param {Chunk} chunk the chunk
  1640. * @returns {ChunkGraph} the chunk graph
  1641. */
  1642. chunk => {
  1643. const chunkGraph = chunkGraphForChunkMap.get(chunk);
  1644. if (!chunkGraph)
  1645. throw new Error(
  1646. deprecateMessage +
  1647. "There was no ChunkGraph assigned to the Chunk for backward-compat (Use the new API)"
  1648. );
  1649. return chunkGraph;
  1650. },
  1651. deprecateMessage + ": Use new ChunkGraph API",
  1652. deprecationCode
  1653. );
  1654. deprecateGetChunkGraphForChunkMap.set(deprecateMessage, newFn);
  1655. return newFn(chunk);
  1656. }
  1657. // TODO remove in webpack 6
  1658. /**
  1659. * @param {Chunk} chunk the chunk
  1660. * @param {ChunkGraph} chunkGraph the chunk graph
  1661. * @returns {void}
  1662. */
  1663. static setChunkGraphForChunk(chunk, chunkGraph) {
  1664. chunkGraphForChunkMap.set(chunk, chunkGraph);
  1665. }
  1666. // TODO remove in webpack 6
  1667. /**
  1668. * @param {Chunk} chunk the chunk
  1669. * @returns {void}
  1670. */
  1671. static clearChunkGraphForChunk(chunk) {
  1672. chunkGraphForChunkMap.delete(chunk);
  1673. }
  1674. }
  1675. // TODO remove in webpack 6
  1676. /** @type {WeakMap<Module, ChunkGraph>} */
  1677. const chunkGraphForModuleMap = new WeakMap();
  1678. // TODO remove in webpack 6
  1679. /** @type {WeakMap<Chunk, ChunkGraph>} */
  1680. const chunkGraphForChunkMap = new WeakMap();
  1681. // TODO remove in webpack 6
  1682. /** @type {Map<string, (module: Module) => ChunkGraph>} */
  1683. const deprecateGetChunkGraphForModuleMap = new Map();
  1684. // TODO remove in webpack 6
  1685. /** @type {Map<string, (chunk: Chunk) => ChunkGraph>} */
  1686. const deprecateGetChunkGraphForChunkMap = new Map();
  1687. module.exports = ChunkGraph;