Skip to content

Commit e89440e

Browse files
alan-agius4kyliau
authored andcommitted
fix(@schematics/angular): module is not being located correctly when using flat
Fixes #12614
1 parent 4d4d118 commit e89440e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

packages/schematics/angular/utility/find-module.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path
4444

4545
if (!options.module) {
4646
options.nameFormatter = options.nameFormatter || strings.dasherize;
47-
const pathToCheck = (options.path || '')
48-
+ (options.flat ? '' : '/' + options.nameFormatter(options.name));
47+
const pathToCheck = (options.path || '') + '/' + options.nameFormatter(options.name);
4948

5049
return normalize(findModule(host, pathToCheck, moduleExt, routingModuleExt));
5150
} else {

packages/schematics/angular/utility/find-module_spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,15 @@ describe('find-module', () => {
119119
expect(modPath).toEqual('/projects/my-proj/src/app_test.module.ts' as Path);
120120
});
121121

122+
it('should find a module if flat is true', () => {
123+
tree.create('/projects/my-proj/src/module/app_test.module.ts', '');
124+
options.path = '/projects/my-proj/src';
125+
options.flat = true;
126+
options.name = '/module/directive';
127+
const modPath = findModuleFromOptions(tree, options);
128+
expect(modPath).toEqual('/projects/my-proj/src/module/app_test.module.ts' as Path);
129+
});
130+
122131
it('should find a module in a sub dir', () => {
123132
tree.create('/projects/my-proj/src/admin/foo.module.ts', '');
124133
options.name = 'other/test';

0 commit comments

Comments
 (0)