ChunkGraph.js 53 KB

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