fix(core): Add throw of error if a dependency is not in the graph (#11652)
Co-authored-by: Andreas Richter <708186+richtera@users.noreply.github.com>
This commit is contained in:
parent
7b5b0ba825
commit
2d50f35d83
@ -84,3 +84,34 @@ describe('calculateProjectDependencies', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('missingDependencies', () => {
|
||||||
|
it('should throw an error if dependency is missing', async () => {
|
||||||
|
const graph: ProjectGraph = {
|
||||||
|
nodes: {
|
||||||
|
example: {
|
||||||
|
type: 'lib',
|
||||||
|
name: 'example',
|
||||||
|
data: {
|
||||||
|
files: [],
|
||||||
|
root: '/root/example',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
externalNodes: {},
|
||||||
|
dependencies: {
|
||||||
|
example: [
|
||||||
|
{
|
||||||
|
source: 'example',
|
||||||
|
target: 'npm:formik',
|
||||||
|
type: DependencyType.static,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(() =>
|
||||||
|
calculateProjectDependencies(graph, 'root', 'example', 'build', undefined)
|
||||||
|
).toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@ -44,7 +44,27 @@ export function calculateProjectDependencies(
|
|||||||
// gather the library dependencies
|
// gather the library dependencies
|
||||||
const nonBuildableDependencies = [];
|
const nonBuildableDependencies = [];
|
||||||
const topLevelDependencies: DependentBuildableProjectNode[] = [];
|
const topLevelDependencies: DependentBuildableProjectNode[] = [];
|
||||||
const dependencies = collectDependencies(projectName, projGraph, [], shallow)
|
const collectedDeps = collectDependencies(
|
||||||
|
projectName,
|
||||||
|
projGraph,
|
||||||
|
[],
|
||||||
|
shallow
|
||||||
|
);
|
||||||
|
const missing = collectedDeps.reduce(
|
||||||
|
(missing: string[] | undefined, { name: dep }) => {
|
||||||
|
const depNode = projGraph.nodes[dep] || projGraph.externalNodes[dep];
|
||||||
|
if (!depNode) {
|
||||||
|
missing = missing || [];
|
||||||
|
missing.push(dep);
|
||||||
|
}
|
||||||
|
return missing;
|
||||||
|
},
|
||||||
|
null
|
||||||
|
);
|
||||||
|
if (missing) {
|
||||||
|
throw new Error(`Unable to find ${missing.join(', ')} in project graph.`);
|
||||||
|
}
|
||||||
|
const dependencies = collectedDeps
|
||||||
.map(({ name: dep, isTopLevel }) => {
|
.map(({ name: dep, isTopLevel }) => {
|
||||||
let project: DependentBuildableProjectNode = null;
|
let project: DependentBuildableProjectNode = null;
|
||||||
const depNode = projGraph.nodes[dep] || projGraph.externalNodes[dep];
|
const depNode = projGraph.nodes[dep] || projGraph.externalNodes[dep];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user