/
check-dependencies.ts
71 lines (67 loc) · 1.92 KB
/
check-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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { ExecutorContext, ProjectGraphProjectNode } from '@nrwl/devkit';
import { readCachedProjectGraph } from '@nrwl/workspace/src/core/project-graph';
import {
calculateProjectDependencies,
checkDependentProjectsHaveBeenBuilt,
createTmpTsConfig,
DependentBuildableProjectNode,
} from '@nrwl/workspace/src/utilities/buildable-libs-utils';
export function checkDependencies(
context: ExecutorContext,
tsConfigPath: string
): {
tmpTsConfig: string | null;
projectRoot: string;
target: ProjectGraphProjectNode<any>;
dependencies: DependentBuildableProjectNode[];
} {
const projectGraph = readCachedProjectGraph();
const { target, dependencies, nonBuildableDependencies } =
calculateProjectDependencies(
projectGraph,
context.root,
context.projectName,
context.targetName,
context.configurationName
);
const projectRoot = target.data.root;
if (nonBuildableDependencies.length > 0) {
throw new Error(
`Buildable libraries can only depend on other buildable libraries. You must define the ${
context.targetName
} target for the following libraries: ${nonBuildableDependencies
.map((t) => `"${t}"`)
.join(', ')}`
);
}
if (dependencies.length > 0) {
const areDependentProjectsBuilt = checkDependentProjectsHaveBeenBuilt(
context.root,
context.projectName,
context.targetName,
dependencies
);
if (!areDependentProjectsBuilt) {
throw new Error(
`Some dependencies of '${context.projectName}' have not been built. This probably due to the ${context.targetName} target being misconfigured.`
);
}
return {
tmpTsConfig: createTmpTsConfig(
tsConfigPath,
context.root,
projectRoot,
dependencies
),
projectRoot,
target,
dependencies,
};
}
return {
tmpTsConfig: null,
projectRoot,
target,
dependencies,
};
}