fix(core): update getTouchedProjectsFromLockFile to handle deleted/moved projects correctly (#31361)

This commit is contained in:
laney 2025-06-02 14:41:13 -07:00 committed by GitHub
parent fc99ded082
commit 88c51965e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 8 deletions

View File

@ -62,7 +62,7 @@ describe('getTouchedProjectsFromLockFile', () => {
], ],
graph.nodes graph.nodes
); );
expect(result).toEqual([]); expect(result).toStrictEqual([]);
}); });
it(`should return all nodes when "${lockFile}" is touched`, () => { it(`should return all nodes when "${lockFile}" is touched`, () => {
@ -76,7 +76,7 @@ describe('getTouchedProjectsFromLockFile', () => {
], ],
graph.nodes graph.nodes
); );
expect(result).toEqual(allNodes); expect(result).toStrictEqual(allNodes);
}); });
}); });
}); });
@ -111,7 +111,7 @@ describe('getTouchedProjectsFromLockFile', () => {
], ],
graph.nodes graph.nodes
); );
expect(result).toEqual([]); expect(result).toStrictEqual([]);
}); });
it(`should not return changes when whole lock file "${lockFile}" is changed`, () => { it(`should not return changes when whole lock file "${lockFile}" is changed`, () => {
@ -125,7 +125,7 @@ describe('getTouchedProjectsFromLockFile', () => {
], ],
graph.nodes graph.nodes
); );
expect(result).toEqual([]); expect(result).toStrictEqual([]);
}); });
it(`should return only changed projects when "${lockFile}" is touched`, () => { it(`should return only changed projects when "${lockFile}" is touched`, () => {
@ -163,12 +163,26 @@ describe('getTouchedProjectsFromLockFile', () => {
rhs: '4.0.1', rhs: '4.0.1',
}, },
}, },
{
type: JsonDiffType.Deleted,
path: [
'importers',
'apps/app-that-was-deleted',
'devDependencies',
'some-other-external-package',
'version',
],
value: {
lhs: '4.0.1',
rhs: undefined,
},
},
], ],
}, },
], ],
graph.nodes graph.nodes
); );
expect(result).toEqual(['proj1', 'app1']); expect(result).toStrictEqual(['proj1', 'app1']);
}); });
}); });
}); });

View File

@ -78,10 +78,13 @@ const getProjectsNamesFromPaths = (
projectGraphNodes: Record<string, ProjectGraphProjectNode>, projectGraphNodes: Record<string, ProjectGraphProjectNode>,
projectPaths: string[] projectPaths: string[]
): string[] => { ): string[] => {
if (!projectPaths.length) {
return [];
}
const lookup = new RootPathLookup(projectGraphNodes); const lookup = new RootPathLookup(projectGraphNodes);
return projectPaths.map((path) => { return projectPaths
return lookup.findNodeNameByRoot(path); .map((path) => lookup.findNodeNameByRoot(path))
}); .filter(Boolean);
}; };
class RootPathLookup { class RootPathLookup {