* 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)
| 38 | * @private |
| 39 | */ |
| 40 | function 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 |
no test coverage detected