fix(core): empty external deps should work properly (#28727)

This commit is contained in:
Craigory Coppola 2024-11-06 14:55:16 -05:00 committed by GitHub
parent ee7b001ec9
commit a5920e3845
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 55 additions and 1 deletions

View File

@ -163,9 +163,11 @@ impl HashPlanner {
))
} else {
let mut external_deps: Vec<&'a String> = vec![];
let mut has_external_deps = false;
for input in self_inputs {
match input {
Input::ExternalDependency(deps) => {
has_external_deps = true;
for dep in deps.iter() {
let external_node_name =
find_external_dependency_node_name(dep, &self.project_graph);
@ -203,8 +205,10 @@ impl HashPlanner {
.map(|s| HashInstruction::External(s.to_string()))
.collect(),
))
} else {
} else if !has_external_deps {
Ok(Some(vec![HashInstruction::AllExternalDependencies]))
} else {
Ok(None)
}
}
}

View File

@ -492,6 +492,56 @@ describe('task planner', () => {
expect(plans).toMatchSnapshot();
});
it('should build plans where a project specifies no external dependencies', async () => {
let projectFileMap = {
proj: [{ file: '/file.ts', hash: 'file.hash' }],
};
let builder = new ProjectGraphBuilder(undefined, projectFileMap);
builder.addNode({
name: 'proj',
type: 'lib',
data: {
root: 'libs/proj',
targets: {
build: {
executor: 'nx:run-commands',
inputs: [
{
externalDependencies: [],
},
],
},
},
},
});
builder.addNode({
name: 'child',
type: 'lib',
data: {
root: 'libs/child',
targets: { build: { executor: 'nx:run-commands' } },
},
});
let projectGraph = builder.getUpdatedProjectGraph();
let taskGraph = createTaskGraph(
projectGraph,
{},
['proj'],
['build'],
undefined,
{}
);
let nxJson = {} as any;
const planner = new HashPlanner(
nxJson,
transferProjectGraph(transformProjectGraphForRust(projectGraph))
);
const taskIds = Object.keys(taskGraph.tasks);
const plans = planner.getPlans(taskIds, taskGraph);
expect(plans['proj:build']).not.toContain('AllExternalDependencies');
});
it('should include npm projects', async () => {
let projectFileMap = {
app: [{ file: '/filea.ts', hash: 'a.hash' }],