fix(core): keep all explicit dependencies in the graph (#16576)
This commit is contained in:
parent
50ad516278
commit
ae5cdcb86e
@ -232,7 +232,7 @@ describe('Linter', () => {
|
||||
import '@${projScope}/${invalidtaglib}';
|
||||
import '@${projScope}/${validtaglib}';
|
||||
|
||||
const s = {loadChildren: '@${projScope}/${lazylib}'};
|
||||
const s = {loadChildren: '@secondScope/${lazylib}'};
|
||||
`
|
||||
);
|
||||
|
||||
|
||||
@ -234,8 +234,6 @@ function findAllNpmDeps(
|
||||
seen,
|
||||
dependencyPatterns
|
||||
);
|
||||
} else {
|
||||
throw new Error(`Could not find ${dep} in the project graph.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,19 +40,28 @@ export function buildExplicitTypeScriptDependencies(
|
||||
importExpr,
|
||||
f.file
|
||||
);
|
||||
let targetProjectName;
|
||||
if (target) {
|
||||
if (!isRoot(source) && isRoot(target)) {
|
||||
// TODO: These edges technically should be allowed but we need to figure out how to separate config files out from root
|
||||
return;
|
||||
}
|
||||
|
||||
res.push({
|
||||
sourceProjectName: source,
|
||||
targetProjectName: target,
|
||||
sourceProjectFile: f.file,
|
||||
type,
|
||||
});
|
||||
targetProjectName = target;
|
||||
} else {
|
||||
// treat all unknowns as npm packages, they can be eiher
|
||||
// - mistyped local import, which has to be fixed manually
|
||||
// - node internals, which should still be tracked as a dependency
|
||||
// - npm packages, which are not yet installed but should be tracked
|
||||
targetProjectName = `npm:${importExpr}`;
|
||||
}
|
||||
|
||||
res.push({
|
||||
sourceProjectName: source,
|
||||
targetProjectName,
|
||||
sourceProjectFile: f.file,
|
||||
type,
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@ -33,6 +33,8 @@ describe('ProjectGraphBuilder', () => {
|
||||
expect(() =>
|
||||
builder.addImplicitDependency('source', 'invalid-target')
|
||||
).toThrowError();
|
||||
// this should not break, but should not exist in resulting dependencies either
|
||||
builder.addStaticDependency('source', 'invalid-target', 'source/index.ts');
|
||||
|
||||
// ignore the self deps
|
||||
builder.addDynamicDependency('source', 'source', 'source/index.ts');
|
||||
@ -91,13 +93,6 @@ describe('ProjectGraphBuilder', () => {
|
||||
'target'
|
||||
)
|
||||
).toThrowError();
|
||||
expect(() =>
|
||||
builder.addExplicitDependency(
|
||||
'source',
|
||||
'source/index.ts',
|
||||
'invalid-target'
|
||||
)
|
||||
).toThrowError();
|
||||
expect(() =>
|
||||
builder.addExplicitDependency(
|
||||
'source',
|
||||
|
||||
@ -175,41 +175,11 @@ export class ProjectGraphBuilder {
|
||||
sourceProjectFile: string,
|
||||
targetProjectName: string
|
||||
): void {
|
||||
if (sourceProjectName === targetProjectName) {
|
||||
return;
|
||||
}
|
||||
const source = this.graph.nodes[sourceProjectName];
|
||||
if (!source) {
|
||||
throw new Error(`Source project does not exist: ${sourceProjectName}`);
|
||||
}
|
||||
|
||||
if (
|
||||
!this.graph.nodes[targetProjectName] &&
|
||||
!this.graph.externalNodes[targetProjectName]
|
||||
) {
|
||||
throw new Error(`Target project does not exist: ${targetProjectName}`);
|
||||
}
|
||||
|
||||
const fileData = source.data.files.find(
|
||||
(f) => f.file === sourceProjectFile
|
||||
this.addStaticDependency(
|
||||
sourceProjectName,
|
||||
targetProjectName,
|
||||
sourceProjectFile
|
||||
);
|
||||
if (!fileData) {
|
||||
throw new Error(
|
||||
`Source project ${sourceProjectName} does not have a file: ${sourceProjectFile}`
|
||||
);
|
||||
}
|
||||
|
||||
if (!fileData.dependencies) {
|
||||
fileData.dependencies = [];
|
||||
}
|
||||
|
||||
if (!fileData.dependencies.find((t) => t.target === targetProjectName)) {
|
||||
fileData.dependencies.push({
|
||||
target: targetProjectName,
|
||||
source: sourceProjectName,
|
||||
type: DependencyType.static,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -229,6 +199,13 @@ export class ProjectGraphBuilder {
|
||||
|
||||
const fileDeps = this.calculateTargetDepsFromFiles(sourceProject);
|
||||
for (const [targetProject, types] of fileDeps.entries()) {
|
||||
// only add known nodes
|
||||
if (
|
||||
!this.graph.nodes[targetProject] &&
|
||||
!this.graph.externalNodes[targetProject]
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
for (const type of types.values()) {
|
||||
if (
|
||||
!alreadySetTargetProjects.has(targetProject) ||
|
||||
@ -268,7 +245,8 @@ export class ProjectGraphBuilder {
|
||||
}
|
||||
if (
|
||||
!this.graph.nodes[targetProjectName] &&
|
||||
!this.graph.externalNodes[targetProjectName]
|
||||
!this.graph.externalNodes[targetProjectName] &&
|
||||
!sourceProjectFile
|
||||
) {
|
||||
throw new Error(`Target project does not exist: ${targetProjectName}`);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user