-
Notifications
You must be signed in to change notification settings - Fork 0
/
explicit-project-dependencies.ts
32 lines (31 loc) · 1.06 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
import { DependencyType } from '../project-graph-models';
import { TypeScriptImportLocator } from './typescript-import-locator';
import { TargetProjectLocator } from '../../target-project-locator';
import {
ProjectGraphBuilder,
ProjectGraphProcessorContext,
} from '@nrwl/devkit';
export function buildExplicitTypeScriptDependencies(
ctx: ProjectGraphProcessorContext,
builder: ProjectGraphBuilder
) {
const importLocator = new TypeScriptImportLocator();
const targetProjectLocator = new TargetProjectLocator(builder.graph.nodes);
Object.keys(ctx.filesToProcess).forEach((source) => {
Object.values(ctx.filesToProcess[source]).forEach((f) => {
importLocator.fromFile(
f.file,
(importExpr: string, filePath: string, type: DependencyType) => {
const target = targetProjectLocator.findProjectWithImport(
importExpr,
f.file,
ctx.workspace.npmScope
);
if (target) {
builder.addExplicitDependency(source, f.file, target);
}
}
);
});
});
}