Skip to content

Commit

Permalink
fix(core): use full project path in output directory
Browse files Browse the repository at this point in the history
Include the full project path to match the pattern established by official Nx generators. This enhances consistency + prevents errors from apps having the same name in separate directories building to the same output.

Fixes #27

Co-authored-by: Ben Callaghan <bcallaghan@selectbankcard.com>
  • Loading branch information
2 people authored and AgentEnder committed Apr 27, 2021
1 parent ed1c53a commit 7748f9c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
16 changes: 14 additions & 2 deletions packages/core/src/generators/utils/generate-project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,22 @@ describe('nx-dotnet project generator', () => {
expect(config).toBeDefined();
});

it('should set output paths in build target', async () => {
await GenerateProject(appTree, options, dotnetClient, 'application');
const config = readProjectConfiguration(appTree, 'test');
const outputPath = config.targets.build.options.output;
expect(outputPath).toBeTruthy();

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

expect(absoluteDistPath).toEqual(expectedDistPath);
});

/**
* This test requires a live dotnet client.
*/
it('should update output paths', async () => {
it('should update output paths in project file', async () => {
await GenerateProject(
appTree,
{
Expand All @@ -79,7 +91,7 @@ describe('nx-dotnet project generator', () => {

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const absoluteDistPath = resolve(config.root, outputPath);
const expectedDistPath = resolve('./dist/test');
const expectedDistPath = resolve('./dist/libs/test');

expect(absoluteDistPath).toEqual(expectedDistPath);
});
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/generators/utils/generate-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async function GenerateTestProject(
projectType: projectType,
sourceRoot: `${testRoot}`,
targets: {
build: GetBuildExecutorConfiguration(testName),
build: GetBuildExecutorConfiguration(testRoot),
test: GetTestExecutorConfig(),
},
tags: schema.parsedTags,
Expand Down Expand Up @@ -123,16 +123,16 @@ async function GenerateTestProject(

if (!isDryRun() && !schema.skipOutputPathManipulation) {
const testCsProj = await findProjectFileInPath(testRoot);
SetOutputPath(host, testProjectName, testCsProj);
SetOutputPath(host, testRoot, testCsProj);
const baseCsProj = await findProjectFileInPath(schema.projectRoot);
SetOutputPath(host, schema.projectName, baseCsProj);
SetOutputPath(host, schema.projectRoot, baseCsProj);
dotnetClient.addProjectReference(testCsProj, baseCsProj);
}
}

function SetOutputPath(
host: Tree,
projectName: string,
projectRootPath: string,
projectFilePath: string
): void {
const xml: XmlDocument = new XmlDocument(
Expand All @@ -142,7 +142,7 @@ function SetOutputPath(
let outputPath = `${relative(
dirname(projectFilePath),
process.cwd()
)}/dist/${projectName}`;
)}/dist/${projectRootPath}`;
outputPath = outputPath.replace('\\', '/'); // Forward slash works on windows, backslash does not work on mac/linux

const textNode: Partial<XmlTextNode> = {
Expand Down Expand Up @@ -187,7 +187,7 @@ export async function GenerateProject(
projectType: projectType,
sourceRoot: `${normalizedOptions.projectRoot}`,
targets: {
build: GetBuildExecutorConfiguration(normalizedOptions.name),
build: GetBuildExecutorConfiguration(normalizedOptions.projectRoot),
serve: GetServeExecutorConfig(),
},
tags: normalizedOptions.parsedTags,
Expand Down Expand Up @@ -238,7 +238,7 @@ export async function GenerateProject(
} else if (!options.skipOutputPathManipulation) {
SetOutputPath(
host,
normalizedOptions.projectName,
normalizedOptions.projectRoot,
await findProjectFileInPath(normalizedOptions.projectRoot)
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/models/build-executor-configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { TargetConfiguration } from '@nrwl/devkit';
* Returns a TargetConfiguration for the nx-dotnet/core:build executor
*/
export function GetBuildExecutorConfiguration(
projectName: string
projectRoot: string
): BuildExecutorConfiguration {
const outputDirectory = `dist/${projectName}`;
const outputDirectory = `dist/${projectRoot}`;

return {
executor: '@nx-dotnet/core:build',
outputs: [outputDirectory],
outputs: ['{options.output}'],
options: {
output: outputDirectory,
configuration: 'Debug',
Expand Down

0 comments on commit 7748f9c

Please sign in to comment.