Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.

Commit 049367c

Browse files
fix(core): Remove extra separator from project names (#61)
* fix(core): remove extra separator from project names Remove capturing parentheses to keep separator out of the project's name Fixes #60 * test(core): reset options object before each test Reset the options object to improve test isolation and repeatability Co-authored-by: Ben Callaghan <bcallaghan@selectbankcard.com>
1 parent 6d09f31 commit 049367c

2 files changed

Lines changed: 20 additions & 9 deletions

File tree

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { XmlDocument } from 'xmldoc';
88
import {
99
DotNetClient,
1010
dotnetFactory,
11+
dotnetNewOptions,
1112
mockDotnetFactory,
1213
} from '@nx-dotnet/dotnet';
1314
import { findProjectFileInPath, NXDOTNET_TAG, rimraf } from '@nx-dotnet/utils';
@@ -18,21 +19,22 @@ import { GenerateProject } from './generate-project';
1819
describe('nx-dotnet project generator', () => {
1920
let appTree: Tree;
2021
let dotnetClient: DotNetClient;
21-
22-
const options: NxDotnetProjectGeneratorSchema = {
23-
name: 'test',
24-
language: 'C#',
25-
template: 'classlib',
26-
testTemplate: 'none',
27-
skipOutputPathManipulation: true,
28-
};
22+
let options: NxDotnetProjectGeneratorSchema;
2923

3024
beforeEach(() => {
3125
appTree = createTreeWithEmptyWorkspace();
3226
dotnetClient = new DotNetClient(mockDotnetFactory());
3327

3428
const packageJson = { scripts: {} };
3529
writeJson(appTree, 'package.json', packageJson);
30+
31+
options = {
32+
name: 'test',
33+
language: 'C#',
34+
template: 'classlib',
35+
testTemplate: 'none',
36+
skipOutputPathManipulation: true,
37+
};
3638
});
3739

3840
afterEach(async () => {
@@ -107,6 +109,15 @@ describe('nx-dotnet project generator', () => {
107109
expect(config.targets.lint).toBeDefined();
108110
});
109111

112+
it('should prepend directory name to project name', async () => {
113+
options.directory = 'sub-dir';
114+
const spy = spyOn(dotnetClient, 'new');
115+
await GenerateProject(appTree, options, dotnetClient, 'library');
116+
const dotnetOptions: dotnetNewOptions = spy.calls.mostRecent().args[1];
117+
const nameFlag = dotnetOptions.find((flag) => flag.flag === 'name');
118+
expect(nameFlag?.value).toBe('Proj.SubDir.Test');
119+
});
120+
110121
/**
111122
* This test requires a live dotnet client.
112123
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function normalizeOptions(
6464

6565
const npmScope = names(readWorkspaceConfiguration(host).npmScope).className;
6666
const featureScope = projectDirectory
67-
.split(/(\/|\\)/gm)
67+
.split(/\/|\\/gm) // Without the unnecessary parentheses, the separator is excluded from the result array.
6868
.map((part) => names(part).className);
6969
const namespaceName = [npmScope, ...featureScope].join('.');
7070

0 commit comments

Comments
 (0)