Skip to content

Commit 7297f82

Browse files
committed
fix(core): update getTouchedProjectsFromLockFile to handle deleted projects correctly
1 parent c5e7f02 commit 7297f82

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.spec.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe('getTouchedProjectsFromLockFile', () => {
6262
],
6363
graph.nodes
6464
);
65-
expect(result).toEqual([]);
65+
expect(result).toStrictEqual([]);
6666
});
6767

6868
it(`should return all nodes when "${lockFile}" is touched`, () => {
@@ -76,7 +76,7 @@ describe('getTouchedProjectsFromLockFile', () => {
7676
],
7777
graph.nodes
7878
);
79-
expect(result).toEqual(allNodes);
79+
expect(result).toStrictEqual(allNodes);
8080
});
8181
});
8282
});
@@ -111,7 +111,7 @@ describe('getTouchedProjectsFromLockFile', () => {
111111
],
112112
graph.nodes
113113
);
114-
expect(result).toEqual([]);
114+
expect(result).toStrictEqual([]);
115115
});
116116

117117
it(`should not return changes when whole lock file "${lockFile}" is changed`, () => {
@@ -125,7 +125,7 @@ describe('getTouchedProjectsFromLockFile', () => {
125125
],
126126
graph.nodes
127127
);
128-
expect(result).toEqual([]);
128+
expect(result).toStrictEqual([]);
129129
});
130130

131131
it(`should return only changed projects when "${lockFile}" is touched`, () => {
@@ -163,12 +163,26 @@ describe('getTouchedProjectsFromLockFile', () => {
163163
rhs: '4.0.1',
164164
},
165165
},
166+
{
167+
type: JsonDiffType.Deleted,
168+
path: [
169+
'importers',
170+
'apps/app-that-was-deleted',
171+
'devDependencies',
172+
'some-other-external-package',
173+
'version',
174+
],
175+
value: {
176+
lhs: '4.0.1',
177+
rhs: undefined,
178+
},
179+
},
166180
],
167181
},
168182
],
169183
graph.nodes
170184
);
171-
expect(result).toEqual(['proj1', 'app1']);
185+
expect(result).toStrictEqual(['proj1', 'app1']);
172186
});
173187
});
174188
});

packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,13 @@ const getProjectsNamesFromPaths = (
7878
projectGraphNodes: Record<string, ProjectGraphProjectNode>,
7979
projectPaths: string[]
8080
): string[] => {
81+
if (!projectPaths.length) {
82+
return [];
83+
}
8184
const lookup = new RootPathLookup(projectGraphNodes);
82-
return projectPaths.map((path) => {
83-
return lookup.findNodeNameByRoot(path);
84-
});
85+
return projectPaths
86+
.map((path) => lookup.findNodeNameByRoot(path))
87+
.filter(Boolean);
8588
};
8689

8790
class RootPathLookup {

0 commit comments

Comments
 (0)