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:
Craigory Coppola 2022-08-19 17:58:40 -04:00 committed by GitHub
parent 7b5b0ba825
commit 2d50f35d83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 1 deletions

View File

@ -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();
});
});

View File

@ -44,7 +44,27 @@ export function calculateProjectDependencies(
// gather the library dependencies
const nonBuildableDependencies = [];
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 }) => {
let project: DependentBuildableProjectNode = null;
const depNode = projGraph.nodes[dep] || projGraph.externalNodes[dep];