Skip to content

Commit

Permalink
fix(core): traverse project deps properly in hash planner (#20621)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli authored Dec 7, 2023
1 parent 3781b59 commit a5a4211
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/nx/src/native/tasks/hash_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl HashPlanner {
external_deps_mapped: &hashbrown::HashMap<&str, Vec<&str>>,
visited: &mut Box<hashbrown::HashSet<String>>,
) -> anyhow::Result<Vec<HashInstruction>> {
let project_deps = &self.project_graph.dependencies[&task.target.project]
let project_deps = &self.project_graph.dependencies[project_name]
.iter()
.map(|d| d.as_str())
.collect::<Vec<_>>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ exports[`task planner should plan the task where the project has dependencies 1`
"child:ProjectConfiguration",
"child:TsConfig",
"child:{projectRoot}/**/*",
"grandchild:ProjectConfiguration",
"grandchild:TsConfig",
"grandchild:{projectRoot}/**/*",
"parent:ProjectConfiguration",
"parent:TsConfig",
"parent:{projectRoot}/**/*",
Expand Down
15 changes: 14 additions & 1 deletion packages/nx/src/native/tests/planner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ProjectGraphBuilder } from '../../project-graph/project-graph-builder';
import { createTaskGraph } from '../../tasks-runner/create-task-graph';
import { transformProjectGraphForRust } from '../transform-objects';


describe('task planner', () => {
// disable NX_NATIVE_TASK_HASHER for this test because we need to compare the results of the new planner with the old task hasher
process.env.NX_NATIVE_TASK_HASHER = 'false';
Expand All @@ -23,6 +22,7 @@ describe('task planner', () => {
paths: {
'@nx/parent': ['libs/parent/src/index.ts'],
'@nx/child': ['libs/child/src/index.ts'],
'@nx/grandchild': ['libs/grandchild/src/index.ts'],
},
},
});
Expand Down Expand Up @@ -188,6 +188,10 @@ describe('task planner', () => {
{ file: '/fileb.ts', hash: 'b.hash' },
{ file: '/fileb.spec.ts', hash: 'b.spec.hash' },
],
grandchild: [
{ file: '/filec.ts', hash: 'c.hash' },
{ file: '/filec.spec.ts', hash: 'c.spec.hash' },
],
};

const builder = new ProjectGraphBuilder(undefined, projectFileMap);
Expand All @@ -209,7 +213,16 @@ describe('task planner', () => {
targets: { build: { executor: 'none' } },
},
});
builder.addNode({
name: 'grandchild',
type: 'lib',
data: {
root: 'libs/grandchild',
targets: { build: { executor: 'none' } },
},
});
builder.addStaticDependency('parent', 'child', '/filea.ts');
builder.addStaticDependency('child', 'grandchild', '/fileb.ts');

const projectGraph = builder.getUpdatedProjectGraph();

Expand Down

0 comments on commit a5a4211

Please sign in to comment.