Skip to content

Commit 65ecd9c

Browse files
authored
fix(core): handle local workspace projects in package.json for affected locator (#13728)
1 parent 6b8d3d6 commit 65ecd9c

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

packages/nx/src/project-graph/affected/locators/npm-packages.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,45 @@ describe('getTouchedNpmPackages', () => {
266266
'npm:awesome-nrwl',
267267
]);
268268
});
269+
270+
it('should handle and workspace packages when defined in dependencies', () => {
271+
const result = getTouchedNpmPackages(
272+
[
273+
{
274+
file: 'package.json',
275+
hash: 'some-hash',
276+
getChanges: () => [
277+
{
278+
type: 'JsonPropertyAdded',
279+
path: ['devDependencies', 'changed-test-pkg-name-1'],
280+
value: { rhs: 'workspace:*' },
281+
},
282+
],
283+
},
284+
],
285+
workspaceJson,
286+
nxJson,
287+
{
288+
dependencies: {
289+
'happy-nrwl': '0.0.1',
290+
'awesome-nrwl': '0.0.1',
291+
},
292+
},
293+
{
294+
...projectGraph,
295+
nodes: {
296+
...projectGraph.nodes,
297+
'any-random-name': {
298+
name: 'changed-test-pkg-name-1',
299+
type: 'lib',
300+
data: {},
301+
},
302+
},
303+
}
304+
);
305+
expect(result).toEqual(['changed-test-pkg-name-1']);
306+
});
307+
269308
it('should handle and log workspace package.json changes when the changes are not in `npmPackages` (projectGraph.externalNodes)', () => {
270309
jest.spyOn(logger, 'warn');
271310
expect(() => {

packages/nx/src/project-graph/affected/locators/npm-packages.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import {
66
} from '../../../utils/json-diff';
77
import { logger } from '../../../utils/logger';
88
import { TouchedProjectLocator } from '../affected-project-graph-models';
9+
import {
10+
ProjectGraphExternalNode,
11+
ProjectGraphProjectNode,
12+
} from 'nx/src/config/project-graph';
913

1014
export const getTouchedNpmPackages: TouchedProjectLocator<
1115
WholeFileChange | JsonChange
@@ -31,9 +35,13 @@ export const getTouchedNpmPackages: TouchedProjectLocator<
3135
touched = Object.keys(projectGraph.nodes);
3236
break;
3337
} else {
34-
const npmPackage = npmPackages.find(
35-
(pkg) => pkg.data.packageName === c.path[1]
36-
);
38+
let npmPackage: ProjectGraphProjectNode | ProjectGraphExternalNode =
39+
npmPackages.find((pkg) => pkg.data.packageName === c.path[1]);
40+
if (!npmPackage) {
41+
// dependency can also point to a workspace project
42+
const nodes = Object.values(projectGraph.nodes);
43+
npmPackage = nodes.find((n) => n.name === c.path[1]);
44+
}
3745
if (!npmPackage) {
3846
missingTouchedNpmPackages.push(c.path[1]);
3947
continue;

0 commit comments

Comments
 (0)