Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): handle local workspace projects in package.json for affected locator #13728

Merged
merged 2 commits into from Dec 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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(() => {
Expand Down
14 changes: 11 additions & 3 deletions packages/nx/src/project-graph/affected/locators/npm-packages.ts
Expand Up @@ -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
Expand All @@ -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;
Expand Down