Skip to content

Commit

Permalink
fix: compatibility with nx 12.6+
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Minimum Nx version is 12.6, if using the dep-graph plugin.

Co-authored-by: Leon Chi <leon.chi@serko.com>
Co-authored-by: Craigory Coppola <craigorycoppola@gmail.com>
  • Loading branch information
3 people authored Jul 30, 2021
1 parent 8f925f5 commit d393b3a
Show file tree
Hide file tree
Showing 21 changed files with 496 additions and 630 deletions.
2 changes: 0 additions & 2 deletions apps/nx-ghpages-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"executor": "@nrwl/nx-plugin:e2e",
"options": {
"target": "nx-ghpages:build",
"npmPackageName": "@nx-dotnet/nx-ghpages",
"pluginOutputPath": "dist/packages/nx-ghpages",
"jestConfig": "apps/nx-ghpages-e2e/jest.config.js"
}
}
Expand Down
2 changes: 0 additions & 2 deletions e2e/core-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"executor": "@nrwl/nx-plugin:e2e",
"options": {
"target": "core:build",
"npmPackageName": "@nx-dotnet/core",
"pluginOutputPath": "dist/packages/core",
"jestConfig": "e2e/core-e2e/jest.config.js"
}
}
Expand Down
47 changes: 47 additions & 0 deletions e2e/core-e2e/tests/nx-dotnet.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import { names } from '@nrwl/devkit';
import {
checkFilesExist,
ensureNxProject,
readFile,
runNxCommandAsync,
uniq,
} from '@nrwl/nx-plugin/testing';

import { readFileSync } from 'fs';
import { join } from 'path';
import { XmlDocument } from 'xmldoc';

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

describe('nx-dotnet e2e', () => {
it('should create apps, libs, and project references', async () => {
const testApp = uniq('app');
Expand Down Expand Up @@ -58,6 +66,45 @@ describe('nx-dotnet e2e', () => {

expect(exists).toBeTruthy();
});

it('should update output paths', async () => {
const app = uniq('app');
await runNxCommandAsync(
`generate @nx-dotnet/core:app ${app} --language="C#" --template="webapi"`,
);
const configFilePath = findProjectFileInPathSync(
join('tmp/nx-e2e/proj/apps', app),
);
const config = readFileSync(configFilePath).toString();
const projectXml = new XmlDocument(config);
const outputPath = projectXml
.childNamed('PropertyGroup')
?.childNamed('OutputPath')?.val as string;
expect(outputPath).toBeTruthy();
});
});

describe('nx g test', () => {
xit('should add a reference to the target project', async () => {
const app = uniq('app');
await runNxCommandAsync(
`generate @nx-dotnet/core:app ${app} --language="C#" --template="webapi" --test-template="none"`,
);
const testProject = `${app}.Test`;
await runNxCommandAsync(
`generate @nx-dotnet/core:test ${app} --language="C#" --template="nunit"`,
);

const config = readFile(
join('apps', app, `Proj.${names(testProject).className}.csproj`),
);
const projectXml = new XmlDocument(config);
const projectReference = projectXml
.childrenNamed('ItemGroup')[1]
?.childNamed('ProjectReference');

expect(projectReference).toBeDefined();
});
});

describe('nx g lib', () => {
Expand Down
2 changes: 0 additions & 2 deletions e2e/nxdoc-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"executor": "@nrwl/nx-plugin:e2e",
"options": {
"target": "nxdoc:build",
"npmPackageName": "@nx-dotnet/nxdoc",
"pluginOutputPath": "dist/packages/nxdoc",
"jestConfig": "e2e/nxdoc-e2e/jest.config.js"
}
}
Expand Down
2 changes: 0 additions & 2 deletions e2e/typescript-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
"executor": "@nrwl/nx-plugin:e2e",
"options": {
"target": "typescript:build",
"npmPackageName": "@nx-dotnet/typescript",
"pluginOutputPath": "dist/packages/typescript",
"jestConfig": "e2e/typescript-e2e/jest.config.js"
}
}
Expand Down
3 changes: 2 additions & 1 deletion e2e/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { detectPackageManager } from '@nrwl/tao/src/shared/package-manager';

import { ChildProcess, exec, execSync } from 'child_process';
import {
copySync,
Expand All @@ -12,10 +13,10 @@ import {
statSync,
writeFileSync,
} from 'fs-extra';
import isCI = require('is-ci');
import * as path from 'path';
import { dirSync } from 'tmp';

import isCI = require('is-ci');
interface RunCmdOpts {
silenceError?: boolean;
env?: Record<string, string> | NodeJS.ProcessEnv;
Expand Down
25 changes: 13 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
"publish-local": "cp .npmrc.local .npmrc && run-p \"rimraf tmp\" e2e-registry \"ts-node ./tools/scripts/publish-all 99.99.99 local\"",
"semantic-release": "semantic-release",
"ts-node": "ts-node",
"rimraf": "rimraf"
"rimraf": "rimraf",
"preinstall": "node ./tools/scripts/hooks/preinstall.js"
},
"private": false,
"dependencies": {
Expand All @@ -56,16 +57,16 @@
"@commitlint/cli": "^12.1.1",
"@commitlint/config-conventional": "^12.1.1",
"@commitlint/types": "^12.1.1",
"@nrwl/cli": "12.5.7",
"@nrwl/devkit": "12.5.7",
"@nrwl/eslint-plugin-nx": "12.5.7",
"@nrwl/jest": "12.5.7",
"@nrwl/linter": "12.5.7",
"@nrwl/node": "12.5.7",
"@nrwl/nx-cloud": "12.2.7",
"@nrwl/nx-plugin": "12.5.7",
"@nrwl/tao": "12.5.7",
"@nrwl/workspace": "12.5.7",
"@nrwl/cli": "12.6.2",
"@nrwl/devkit": "12.6.2",
"@nrwl/eslint-plugin-nx": "12.6.2",
"@nrwl/jest": "12.6.2",
"@nrwl/linter": "12.6.2",
"@nrwl/node": "12.6.2",
"@nrwl/nx-cloud": "12.3.5",
"@nrwl/nx-plugin": "12.6.2",
"@nrwl/tao": "12.6.2",
"@nrwl/workspace": "12.6.2",
"@nx-dotnet/nxdoc": "latest",
"@nx-plus/docusaurus": "^12.0.0",
"@semantic-release/changelog": "^5.0.1",
Expand Down Expand Up @@ -108,5 +109,5 @@
"type": "git",
"url": "https://github.com/nx-dotnet/nx-dotnet.git"
},
"version": "0.15.0"
"version": "99.99.99"
}
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"email": "craigorycoppola+nxdotnet@gmail.com"
},
"license": "MIT",
"version": "0.15.0",
"version": "99.99.99",
"keywords": [
"Nx",
".NET",
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/generators/test/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
"description": "Generate a .NET test project for an existing application or library",
"type": "object",
"properties": {
"project": {
"name": {
"type": "string",
"description": "The existing project to generate tests for",
"$default": {
"$source": "argv",
"index": 0
}
},
"alias": ["project"]
},
"testTemplate": {
"type": "string",
Expand Down
45 changes: 6 additions & 39 deletions packages/core/src/generators/utils/generate-project.spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { readProjectConfiguration, Tree, writeJson } from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';

import { readFileSync } from 'fs';
import { resolve } from 'path';
import { XmlDocument } from 'xmldoc';

import {
DotNetClient,
dotnetFactory,
dotnetNewOptions,
mockDotnetFactory,
} from '@nx-dotnet/dotnet';
import { findProjectFileInPath, NXDOTNET_TAG, rimraf } from '@nx-dotnet/utils';
import { DotNetClient, mockDotnetFactory } from '@nx-dotnet/dotnet';
import { NXDOTNET_TAG, rimraf } from '@nx-dotnet/utils';

import { NxDotnetProjectGeneratorSchema } from '../../models';
import { GenerateProject } from './generate-project';

// eslint-disable-next-line @typescript-eslint/no-empty-function
jest.spyOn(console, 'log').mockImplementation(() => {});

describe('nx-dotnet project generator', () => {
let appTree: Tree;
let dotnetClient: DotNetClient;
Expand All @@ -39,7 +35,7 @@ describe('nx-dotnet project generator', () => {
});

afterEach(async () => {
await Promise.all([rimraf('apps'), rimraf('libs'), rimraf('.config')]);
// await Promise.all([rimraf('apps'), rimraf('libs'), rimraf('.config')]);
});

it('should run successfully for libraries', async () => {
Expand Down Expand Up @@ -105,33 +101,4 @@ describe('nx-dotnet project generator', () => {
const nameFlag = dotnetOptions?.find((flag) => flag.flag === 'name');
expect(nameFlag?.value).toBe('Proj.SubDir.Test');
});

/**
* This test requires a live dotnet client.
*/
it('should update output paths in project file', async () => {
await GenerateProject(
appTree,
{
...options,
skipOutputPathManipulation: false,
},
new DotNetClient(dotnetFactory()),
'library',
);
const config = readProjectConfiguration(appTree, 'test');
const projectFilePath = await findProjectFileInPath(config.root);
const projectXml = new XmlDocument(
readFileSync(projectFilePath).toString(),
);
const outputPath = projectXml
.childNamed('PropertyGroup')
?.childNamed('OutputPath')?.val as string;
expect(outputPath).toBeTruthy();

const absoluteDistPath = resolve(config.root, outputPath);
const expectedDistPath = resolve('./dist/libs/test');

expect(absoluteDistPath).toEqual(expectedDistPath);
});
});
66 changes: 3 additions & 63 deletions packages/core/src/generators/utils/generate-test-project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ import {
} from '@nrwl/devkit';
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing';

import { mkdirSync, readFileSync, writeFileSync } from 'fs';
import { mkdirSync, writeFileSync } from 'fs';
import { resolve } from 'path';
import { XmlDocument } from 'xmldoc';

import {
DotNetClient,
dotnetFactory,
mockDotnetFactory,
} from '@nx-dotnet/dotnet';
import { findProjectFileInPath, NXDOTNET_TAG, rimraf } from '@nx-dotnet/utils';
import { DotNetClient, mockDotnetFactory } from '@nx-dotnet/dotnet';
import { NXDOTNET_TAG } from '@nx-dotnet/utils';

import { NxDotnetTestGeneratorSchema } from '../../models';
import { GenerateTestProject } from './generate-test-project';
Expand Down Expand Up @@ -64,10 +59,6 @@ describe('nx-dotnet test project generator', () => {
testProjectName = options.project + '-test';
});

afterEach(async () => {
await Promise.all([rimraf('apps'), rimraf('libs'), rimraf('.config')]);
});

it('should detect library type for libraries', async () => {
options.project = 'domain-existing-lib';
testProjectName = options.project + '-test';
Expand Down Expand Up @@ -128,55 +119,4 @@ describe('nx-dotnet test project generator', () => {
const nameFlag = dotnetOptions?.find((flag) => flag.flag === 'name');
expect(nameFlag?.value).toBe('Proj.Domain.ExistingApp.Test');
});

/**
* This test requires a live dotnet client.
*/
it('should add a reference to the target project', async () => {
await GenerateTestProject(
appTree,
{
...options,
skipOutputPathManipulation: false,
},
new DotNetClient(dotnetFactory()),
);
const config = readProjectConfiguration(appTree, testProjectName);
const projectFilePath = await findProjectFileInPath(config.root);
const projectXml = new XmlDocument(
readFileSync(projectFilePath).toString(),
);
const projectReference = projectXml
.childrenNamed('ItemGroup')[1]
?.childNamed('ProjectReference');
expect(projectReference).toBeDefined();
});

/**
* This test requires a live dotnet client.
*/
it('should update output paths in project file', async () => {
await GenerateTestProject(
appTree,
{
...options,
skipOutputPathManipulation: false,
},
new DotNetClient(dotnetFactory()),
);
const config = readProjectConfiguration(appTree, testProjectName);
const projectFilePath = await findProjectFileInPath(config.root);
const projectXml = new XmlDocument(
readFileSync(projectFilePath).toString(),
);
const outputPath = projectXml
.childNamed('PropertyGroup')
?.childNamed('OutputPath')?.val as string;
expect(outputPath).toBeTruthy();

const absoluteDistPath = resolve(config.root, outputPath);
const expectedDistPath = resolve('./dist/apps/domain/existing-app-test');

expect(absoluteDistPath).toEqual(expectedDistPath);
});
});
7 changes: 3 additions & 4 deletions packages/core/src/graph/process-project-graph.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
DependencyType,
ProjectConfiguration,
ProjectGraph,
ProjectGraphBuilder,
Expand All @@ -26,7 +25,7 @@ export function processProjectGraph(
}
});

return builder.getProjectGraph();
return builder.getUpdatedProjectGraph();
}

function visitProject(
Expand All @@ -38,8 +37,8 @@ function visitProject(
getDependantProjectsForNxProject(
projectName,
context.workspace,
(projectConfig, dependencyName) => {
builder.addDependency(DependencyType.static, projectName, dependencyName);
({ projectFile }, dependencyName) => {
builder.addExplicitDependency(projectName, projectFile, dependencyName);
},
);
}
2 changes: 1 addition & 1 deletion packages/dotnet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "src/index.js",
"dependencies": {},
"license": "MIT",
"version": "0.15.0",
"version": "99.99.99",
"keywords": [
".NET",
"dotnet"
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-ghpages/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nx-dotnet/nx-ghpages",
"version": "0.15.0",
"version": "99.99.99",
"main": "src/index.js",
"generators": "./generators.json",
"executors": "./executors.json"
Expand Down
2 changes: 1 addition & 1 deletion packages/nxdoc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nx-dotnet/nxdoc",
"version": "0.15.0",
"version": "99.99.99",
"main": "src/index.js",
"generators": "./generators.json",
"executors": "./executors.json",
Expand Down
Loading

0 comments on commit d393b3a

Please sign in to comment.