diff --git a/packages/nx/src/project-graph/affected/locators/npm-packages.spec.ts b/packages/nx/src/project-graph/affected/locators/npm-packages.spec.ts index 58a9d12612226..7cba1534baa00 100644 --- a/packages/nx/src/project-graph/affected/locators/npm-packages.spec.ts +++ b/packages/nx/src/project-graph/affected/locators/npm-packages.spec.ts @@ -266,6 +266,45 @@ describe('getTouchedNpmPackages', () => { 'npm:awesome-nrwl', ]); }); + + it('should handle and workspace packages when defined in dependencies', () => { + const result = getTouchedNpmPackages( + [ + { + file: 'package.json', + hash: 'some-hash', + getChanges: () => [ + { + type: 'JsonPropertyAdded', + path: ['devDependencies', 'changed-test-pkg-name-1'], + value: { rhs: 'workspace:*' }, + }, + ], + }, + ], + workspaceJson, + nxJson, + { + dependencies: { + 'happy-nrwl': '0.0.1', + 'awesome-nrwl': '0.0.1', + }, + }, + { + ...projectGraph, + nodes: { + ...projectGraph.nodes, + 'any-random-name': { + name: 'changed-test-pkg-name-1', + type: 'lib', + data: {}, + }, + }, + } + ); + expect(result).toEqual(['changed-test-pkg-name-1']); + }); + it('should handle and log workspace package.json changes when the changes are not in `npmPackages` (projectGraph.externalNodes)', () => { jest.spyOn(logger, 'warn'); expect(() => { diff --git a/packages/nx/src/project-graph/affected/locators/npm-packages.ts b/packages/nx/src/project-graph/affected/locators/npm-packages.ts index 3f795ee688793..8cf4fadde0d4e 100644 --- a/packages/nx/src/project-graph/affected/locators/npm-packages.ts +++ b/packages/nx/src/project-graph/affected/locators/npm-packages.ts @@ -6,6 +6,10 @@ import { } from '../../../utils/json-diff'; import { logger } from '../../../utils/logger'; import { TouchedProjectLocator } from '../affected-project-graph-models'; +import { + ProjectGraphExternalNode, + ProjectGraphProjectNode, +} from 'nx/src/config/project-graph'; export const getTouchedNpmPackages: TouchedProjectLocator< WholeFileChange | JsonChange @@ -31,9 +35,13 @@ export const getTouchedNpmPackages: TouchedProjectLocator< touched = Object.keys(projectGraph.nodes); break; } else { - const npmPackage = npmPackages.find( - (pkg) => pkg.data.packageName === c.path[1] - ); + let npmPackage: ProjectGraphProjectNode | ProjectGraphExternalNode = + npmPackages.find((pkg) => pkg.data.packageName === c.path[1]); + if (!npmPackage) { + // dependency can also point to a workspace project + const nodes = Object.values(projectGraph.nodes); + npmPackage = nodes.find((n) => n.name === c.path[1]); + } if (!npmPackage) { missingTouchedNpmPackages.push(c.path[1]); continue;