Skip to content

Commit 7748f9c

Browse files
bcallaghan-etbenjcallaghan
authored andcommitted
fix(core): use full project path in output directory
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>
1 parent ed1c53a commit 7748f9c

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

packages/core/src/generators/utils/generate-project.spec.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,22 @@ describe('nx-dotnet project generator', () => {
5454
expect(config).toBeDefined();
5555
});
5656

57+
it('should set output paths in build target', async () => {
58+
await GenerateProject(appTree, options, dotnetClient, 'application');
59+
const config = readProjectConfiguration(appTree, 'test');
60+
const outputPath = config.targets.build.options.output;
61+
expect(outputPath).toBeTruthy();
62+
63+
const absoluteDistPath = resolve(appTree.root, outputPath);
64+
const expectedDistPath = resolve(appTree.root, './dist/apps/test');
65+
66+
expect(absoluteDistPath).toEqual(expectedDistPath);
67+
});
68+
5769
/**
5870
* This test requires a live dotnet client.
5971
*/
60-
it('should update output paths', async () => {
72+
it('should update output paths in project file', async () => {
6173
await GenerateProject(
6274
appTree,
6375
{
@@ -79,7 +91,7 @@ describe('nx-dotnet project generator', () => {
7991

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

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

packages/core/src/generators/utils/generate-project.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ async function GenerateTestProject(
9292
projectType: projectType,
9393
sourceRoot: `${testRoot}`,
9494
targets: {
95-
build: GetBuildExecutorConfiguration(testName),
95+
build: GetBuildExecutorConfiguration(testRoot),
9696
test: GetTestExecutorConfig(),
9797
},
9898
tags: schema.parsedTags,
@@ -123,16 +123,16 @@ async function GenerateTestProject(
123123

124124
if (!isDryRun() && !schema.skipOutputPathManipulation) {
125125
const testCsProj = await findProjectFileInPath(testRoot);
126-
SetOutputPath(host, testProjectName, testCsProj);
126+
SetOutputPath(host, testRoot, testCsProj);
127127
const baseCsProj = await findProjectFileInPath(schema.projectRoot);
128-
SetOutputPath(host, schema.projectName, baseCsProj);
128+
SetOutputPath(host, schema.projectRoot, baseCsProj);
129129
dotnetClient.addProjectReference(testCsProj, baseCsProj);
130130
}
131131
}
132132

133133
function SetOutputPath(
134134
host: Tree,
135-
projectName: string,
135+
projectRootPath: string,
136136
projectFilePath: string
137137
): void {
138138
const xml: XmlDocument = new XmlDocument(
@@ -142,7 +142,7 @@ function SetOutputPath(
142142
let outputPath = `${relative(
143143
dirname(projectFilePath),
144144
process.cwd()
145-
)}/dist/${projectName}`;
145+
)}/dist/${projectRootPath}`;
146146
outputPath = outputPath.replace('\\', '/'); // Forward slash works on windows, backslash does not work on mac/linux
147147

148148
const textNode: Partial<XmlTextNode> = {
@@ -187,7 +187,7 @@ export async function GenerateProject(
187187
projectType: projectType,
188188
sourceRoot: `${normalizedOptions.projectRoot}`,
189189
targets: {
190-
build: GetBuildExecutorConfiguration(normalizedOptions.name),
190+
build: GetBuildExecutorConfiguration(normalizedOptions.projectRoot),
191191
serve: GetServeExecutorConfig(),
192192
},
193193
tags: normalizedOptions.parsedTags,
@@ -238,7 +238,7 @@ export async function GenerateProject(
238238
} else if (!options.skipOutputPathManipulation) {
239239
SetOutputPath(
240240
host,
241-
normalizedOptions.projectName,
241+
normalizedOptions.projectRoot,
242242
await findProjectFileInPath(normalizedOptions.projectRoot)
243243
);
244244
}

packages/core/src/models/build-executor-configuration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { TargetConfiguration } from '@nrwl/devkit';
44
* Returns a TargetConfiguration for the nx-dotnet/core:build executor
55
*/
66
export function GetBuildExecutorConfiguration(
7-
projectName: string
7+
projectRoot: string
88
): BuildExecutorConfiguration {
9-
const outputDirectory = `dist/${projectName}`;
9+
const outputDirectory = `dist/${projectRoot}`;
1010

1111
return {
1212
executor: '@nx-dotnet/core:build',
13-
outputs: [outputDirectory],
13+
outputs: ['{options.output}'],
1414
options: {
1515
output: outputDirectory,
1616
configuration: 'Debug',

0 commit comments

Comments
 (0)