Skip to content

Commit

Permalink
fix(@schematics/angular): module is not being located correctly when …
Browse files Browse the repository at this point in the history
…using `flat`

Fixes #12614
  • Loading branch information
alan-agius4 authored and Keen Yee Liau committed Oct 23, 2018
1 parent 0b4f3c1 commit 515553f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/schematics/angular/utility/find-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path

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

return normalize(findModule(host, pathToCheck, moduleExt, routingModuleExt));
} else {
Expand Down
9 changes: 9 additions & 0 deletions packages/schematics/angular/utility/find-module_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,15 @@ describe('find-module', () => {
expect(modPath).toEqual('/projects/my-proj/src/app_test.module.ts' as Path);
});

it('should find a module if flat is true', () => {
tree.create('/projects/my-proj/src/module/app_test.module.ts', '');
options.path = '/projects/my-proj/src';
options.flat = true;
options.name = '/module/directive';
const modPath = findModuleFromOptions(tree, options);
expect(modPath).toEqual('/projects/my-proj/src/module/app_test.module.ts' as Path);
});

it('should find a module in a sub dir', () => {
tree.create('/projects/my-proj/src/admin/foo.module.ts', '');
options.name = 'other/test';
Expand Down

0 comments on commit 515553f

Please sign in to comment.