-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
explicit-project-dependencies.ts
42 lines (41 loc) · 1.22 KB
/
explicit-project-dependencies.ts
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
37
38
39
40
41
42
import { TypeScriptImportLocator } from './typescript-import-locator';
import { TargetProjectLocator } from '../../utils/target-project-locator';
import {
DependencyType,
ProjectFileMap,
ProjectGraph,
} from '../../config/project-graph';
import { Workspace } from '../../config/workspace-json-project-json';
export function buildExplicitTypeScriptDependencies(
workspace: Workspace,
graph: ProjectGraph,
filesToProcess: ProjectFileMap
) {
const importLocator = new TypeScriptImportLocator();
const targetProjectLocator = new TargetProjectLocator(
graph.nodes as any,
graph.externalNodes
);
const res = [] as any;
Object.keys(filesToProcess).forEach((source) => {
Object.values(filesToProcess[source]).forEach((f) => {
importLocator.fromFile(
f.file,
(importExpr: string, filePath: string, type: DependencyType) => {
const target = targetProjectLocator.findProjectWithImport(
importExpr,
f.file
);
if (target) {
res.push({
sourceProjectName: source,
targetProjectName: target,
sourceProjectFile: f.file,
});
}
}
);
});
});
return res;
}