forked from OKEAMAH/bolt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetDependencyGraph.js
More file actions
36 lines (28 loc) · 920 Bytes
/
getDependencyGraph.js
File metadata and controls
36 lines (28 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// @flow
import Project from '../Project';
import * as yarn from '../utils/yarn';
import type { configDependencyType } from '../types';
type Options = {
cwd?: string,
excludedTypes?: Array<configDependencyType>
};
type DependencyGraph = Map<string, Array<string>>;
export default async function getDependencyGraph(
opts: Options = {}
): Promise<DependencyGraph> {
let cwd = opts.cwd || process.cwd();
let project = await Project.init(cwd);
let packages = await project.getPackages();
let {
graph: dependencyGraph,
valid: graphIsValid
} = await project.getDependencyGraph(packages, opts.excludedTypes);
if (!graphIsValid) {
throw new Error('Dependency graph is not valid');
}
let simplifiedDependencyGraph = new Map();
dependencyGraph.forEach((pkgInfo, pkgName) => {
simplifiedDependencyGraph.set(pkgName, pkgInfo.dependencies);
});
return simplifiedDependencyGraph;
}