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}/${invalidtaglib}';
|
||||||
import '@${projScope}/${validtaglib}';
|
import '@${projScope}/${validtaglib}';
|
||||||
|
|
||||||
const s = {loadChildren: '@${projScope}/${lazylib}'};
|
const s = {loadChildren: '@secondScope/${lazylib}'};
|
||||||
`
|
`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -234,8 +234,6 @@ function findAllNpmDeps(
|
|||||||
seen,
|
seen,
|
||||||
dependencyPatterns
|
dependencyPatterns
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
throw new Error(`Could not find ${dep} in the project graph.`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -40,20 +40,29 @@ export function buildExplicitTypeScriptDependencies(
|
|||||||
importExpr,
|
importExpr,
|
||||||
f.file
|
f.file
|
||||||
);
|
);
|
||||||
|
let targetProjectName;
|
||||||
if (target) {
|
if (target) {
|
||||||
if (!isRoot(source) && isRoot(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
|
// TODO: These edges technically should be allowed but we need to figure out how to separate config files out from root
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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({
|
res.push({
|
||||||
sourceProjectName: source,
|
sourceProjectName: source,
|
||||||
targetProjectName: target,
|
targetProjectName,
|
||||||
sourceProjectFile: f.file,
|
sourceProjectFile: f.file,
|
||||||
type,
|
type,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -33,6 +33,8 @@ describe('ProjectGraphBuilder', () => {
|
|||||||
expect(() =>
|
expect(() =>
|
||||||
builder.addImplicitDependency('source', 'invalid-target')
|
builder.addImplicitDependency('source', 'invalid-target')
|
||||||
).toThrowError();
|
).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
|
// ignore the self deps
|
||||||
builder.addDynamicDependency('source', 'source', 'source/index.ts');
|
builder.addDynamicDependency('source', 'source', 'source/index.ts');
|
||||||
@ -91,13 +93,6 @@ describe('ProjectGraphBuilder', () => {
|
|||||||
'target'
|
'target'
|
||||||
)
|
)
|
||||||
).toThrowError();
|
).toThrowError();
|
||||||
expect(() =>
|
|
||||||
builder.addExplicitDependency(
|
|
||||||
'source',
|
|
||||||
'source/index.ts',
|
|
||||||
'invalid-target'
|
|
||||||
)
|
|
||||||
).toThrowError();
|
|
||||||
expect(() =>
|
expect(() =>
|
||||||
builder.addExplicitDependency(
|
builder.addExplicitDependency(
|
||||||
'source',
|
'source',
|
||||||
|
|||||||
@ -175,41 +175,11 @@ export class ProjectGraphBuilder {
|
|||||||
sourceProjectFile: string,
|
sourceProjectFile: string,
|
||||||
targetProjectName: string
|
targetProjectName: string
|
||||||
): void {
|
): void {
|
||||||
if (sourceProjectName === targetProjectName) {
|
this.addStaticDependency(
|
||||||
return;
|
sourceProjectName,
|
||||||
}
|
targetProjectName,
|
||||||
const source = this.graph.nodes[sourceProjectName];
|
sourceProjectFile
|
||||||
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
|
|
||||||
);
|
);
|
||||||
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);
|
const fileDeps = this.calculateTargetDepsFromFiles(sourceProject);
|
||||||
for (const [targetProject, types] of fileDeps.entries()) {
|
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()) {
|
for (const type of types.values()) {
|
||||||
if (
|
if (
|
||||||
!alreadySetTargetProjects.has(targetProject) ||
|
!alreadySetTargetProjects.has(targetProject) ||
|
||||||
@ -268,7 +245,8 @@ export class ProjectGraphBuilder {
|
|||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
!this.graph.nodes[targetProjectName] &&
|
!this.graph.nodes[targetProjectName] &&
|
||||||
!this.graph.externalNodes[targetProjectName]
|
!this.graph.externalNodes[targetProjectName] &&
|
||||||
|
!sourceProjectFile
|
||||||
) {
|
) {
|
||||||
throw new Error(`Target project does not exist: ${targetProjectName}`);
|
throw new Error(`Target project does not exist: ${targetProjectName}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user