Skip to content

Commit 2e56afc

Browse files
authored
fix(core): dep-graph affected should work (#76)
1 parent 07404c6 commit 2e56afc

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

e2e/core-e2e/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ module.exports = {
1111
},
1212
moduleFileExtensions: ['ts', 'js', 'html'],
1313
coverageDirectory: '../../coverage/e2ecore-e2e',
14-
testTimeout: 90000,
14+
testTimeout: 120000,
1515
};

e2e/core-e2e/tests/nx-dotnet.spec.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
checkFilesExist,
44
ensureNxProject,
55
readFile,
6+
readJson,
67
runNxCommandAsync,
78
uniq,
89
} from '@nrwl/nx-plugin/testing';
@@ -13,6 +14,8 @@ import { XmlDocument } from 'xmldoc';
1314

1415
import { findProjectFileInPathSync } from '@nx-dotnet/utils';
1516

17+
const e2eDir = 'tmp/nx-e2e/proj';
18+
1619
describe('nx-dotnet e2e', () => {
1720
it('should create apps, libs, and project references', async () => {
1821
const testApp = uniq('app');
@@ -34,6 +37,42 @@ describe('nx-dotnet e2e', () => {
3437
expect(output.stdout).toMatch(/Reference .* added to the project/);
3538
});
3639

40+
it('should work with affected', async () => {
41+
const testApp = uniq('app');
42+
const testLib = uniq('lib');
43+
ensureNxProject('@nx-dotnet/core', 'dist/packages/core');
44+
45+
await runNxCommandAsync(
46+
`generate @nx-dotnet/core:app ${testApp} --language="C#" --template="webapi"`,
47+
);
48+
49+
await runNxCommandAsync(
50+
`generate @nx-dotnet/core:lib ${testLib} --language="C#" --template="classlib"`,
51+
);
52+
53+
await runNxCommandAsync(
54+
`generate @nx-dotnet/core:project-reference ${testApp} ${testLib}`,
55+
);
56+
57+
const output = await runNxCommandAsync(
58+
'print-affected --target build --base HEAD~1',
59+
);
60+
61+
const depGraphCachePath = join(
62+
__dirname,
63+
'../../../',
64+
e2eDir,
65+
'node_modules/.cache/nx/nxdeps.json',
66+
);
67+
68+
const deps = readJson(depGraphCachePath).nodes[testApp].data.files.find(
69+
(x: { ext: string; deps: string[] }) => x.ext === '.csproj',
70+
).deps;
71+
72+
expect(output.stderr).toBeFalsy();
73+
expect(deps).toContain(testLib);
74+
}, 150000);
75+
3776
describe('nx g app', () => {
3877
it('should obey dry-run', async () => {
3978
const app = uniq('app');
@@ -73,7 +112,7 @@ describe('nx-dotnet e2e', () => {
73112
`generate @nx-dotnet/core:app ${app} --language="C#" --template="webapi"`,
74113
);
75114
const configFilePath = findProjectFileInPathSync(
76-
join('tmp/nx-e2e/proj/apps', app),
115+
join(e2eDir, 'apps', app),
77116
);
78117
const config = readFileSync(configFilePath).toString();
79118
const projectXml = new XmlDocument(config);

packages/core/src/graph/process-project-graph.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import {
55
ProjectGraphProcessorContext,
66
} from '@nrwl/devkit';
77

8-
import { getDependantProjectsForNxProject } from '@nx-dotnet/utils';
8+
import {
9+
getDependantProjectsForNxProject,
10+
getProjectFileForNxProjectSync,
11+
} from '@nx-dotnet/utils';
912

1013
export function processProjectGraph(
1114
graph: ProjectGraph,
@@ -34,10 +37,11 @@ function visitProject(
3437
project: ProjectConfiguration,
3538
projectName: string,
3639
) {
40+
const projectFile = getProjectFileForNxProjectSync(project);
3741
getDependantProjectsForNxProject(
3842
projectName,
3943
context.workspace,
40-
({ projectFile }, dependencyName) => {
44+
(config, dependencyName) => {
4145
builder.addExplicitDependency(projectName, projectFile, dependencyName);
4246
},
4347
);

0 commit comments

Comments
 (0)