MCPcopy Create free account
hub / github.com/SAP/ui5-builder / createDependencyGraph

Function createDependencyGraph

lib/lbt/graph/topologicalSort.js:40–81  ·  view source on GitHub ↗

* Creates a dependency graph from the given moduleNames. * Ignores modules not in the pool * * @param {ResourcePool} pool * @param {string[]} moduleNames * @param {boolean} indegreeOnly * @returns {Promise } * @private

(pool, moduleNames, indegreeOnly)

Source from the content-addressed store, hash-verified

38 * @private
39 */
40function createDependencyGraph(pool, moduleNames, indegreeOnly) {
41 const graph = Object.create(null);
42
43 const promises = moduleNames.map( (moduleName) => {
44 return pool.getModuleInfo(moduleName).
45 then( (module) => {
46 let node = graph[moduleName];
47 if ( node == null ) {
48 node = new GraphNode(moduleName, indegreeOnly);
49 graph[moduleName] = node;
50 }
51 const p = module.dependencies.map( function(dep) {
52 if ( module.isConditionalDependency(dep) ) {
53 return;
54 }
55 return pool.getModuleInfo(dep).then( (depModule) => {
56 if ( moduleNames.indexOf(dep) >= 0 ) {
57 let depNode = graph[dep];
58 if ( depNode == null ) {
59 depNode = new GraphNode(dep, indegreeOnly);
60 graph[dep] = depNode;
61 }
62 node.outgoing.push(depNode);
63 if ( indegreeOnly ) {
64 depNode.indegree++;
65 } else {
66 depNode.incoming.push(node);
67 }
68 }
69 }, (erro) => null);
70 });
71 return Promise.all(p);
72 }, (err) => {
73 log.error(`Module ${moduleName} not found in pool`);
74 });
75 });
76
77 return Promise.all(promises).then(function() {
78 // if ( trace.isTrace() ) trace.trace("initial module dependency graph: %s", dumpGraph(graph, moduleNames));
79 return graph;
80 });
81}
82
83/**
84 * @param {ResourcePool} pool Modulepool to retrieve module information from

Callers 1

topologicalSortFunction · 0.70

Calls 2

getModuleInfoMethod · 0.80

Tested by

no test coverage detected