Skip to content

Commit bcaf37e

Browse files
committed
refactor: Add an extra option to not use dasherize in findModuleFromOptions
In Google we prefer underscore instead of dashes. So this options is useful there.
1 parent 248d531 commit bcaf37e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

Diff for: packages/schematics/angular/utility/find-module.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface ModuleOptions {
2525
skipImport?: boolean;
2626
moduleExt?: string;
2727
routingModuleExt?: string;
28+
normalizeName?: (str: string) => string;
2829
}
2930

3031
const MODULE_EXT = '.module.ts';
@@ -42,8 +43,9 @@ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path
4243
const routingModuleExt = options.routingModuleExt || ROUTING_MODULE_EXT;
4344

4445
if (!options.module) {
46+
options.normalizeName = options.normalizeName || strings.dasherize;
4547
const pathToCheck = (options.path || '')
46-
+ (options.flat ? '' : '/' + strings.dasherize(options.name));
48+
+ (options.flat ? '' : '/' + options.normalizeName(options.name));
4749

4850
return normalize(findModule(host, pathToCheck, moduleExt, routingModuleExt));
4951
} else {

Diff for: packages/schematics/angular/utility/find-module_spec.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { Path } from '@angular-devkit/core';
8+
import { Path, strings } from '@angular-devkit/core';
99
import { EmptyTree, Tree } from '@angular-devkit/schematics';
1010
import { ModuleOptions, findModule, findModuleFromOptions } from './find-module';
1111

@@ -111,6 +111,14 @@ describe('find-module', () => {
111111
expect(modPath).toEqual('/projects/my-proj/src/app.module.ts' as Path);
112112
});
113113

114+
it('should find a module if normalizeName is provided', () => {
115+
tree.create('/projects/my-proj/src/app_test.module.ts', '');
116+
options.path = '/projects/my-proj/src';
117+
options.normalizeName = strings.underscore;
118+
const modPath = findModuleFromOptions(tree, options);
119+
expect(modPath).toEqual('/projects/my-proj/src/app_test.module.ts' as Path);
120+
});
121+
114122
it('should find a module in a sub dir', () => {
115123
tree.create('/projects/my-proj/src/admin/foo.module.ts', '');
116124
options.name = 'other/test';

0 commit comments

Comments
 (0)