Skip to content

Commit ff9f822

Browse files
alan-agius4Keen Yee Liau
authored and
Keen Yee Liau
committed
fix(@schematics/angular): findModuleFromOptions not handling properly different casing in name
At the moment users can have various casing and seperatirs in paths, we should not always dasherize the name when resolving modules. As for example when providing something like: ``` /module/SubModule/feature ``` It won't be able to resolve the modules properly as `sub-module` does't exist. This PR also updates the test for underscore as previously it was not properly testing this usercase, since the formatter was used on name and not th path. Fixes #13714
1 parent 7b31c86 commit ff9f822

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
join,
1313
normalize,
1414
relative,
15-
strings,
1615
} from '@angular-devkit/core';
1716
import { DirEntry, Tree } from '@angular-devkit/schematics';
1817

@@ -25,7 +24,6 @@ export interface ModuleOptions {
2524
skipImport?: boolean;
2625
moduleExt?: string;
2726
routingModuleExt?: string;
28-
nameFormatter?: (str: string) => string;
2927
}
3028

3129
const MODULE_EXT = '.module.ts';
@@ -43,8 +41,7 @@ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path
4341
const routingModuleExt = options.routingModuleExt || ROUTING_MODULE_EXT;
4442

4543
if (!options.module) {
46-
options.nameFormatter = options.nameFormatter || strings.dasherize;
47-
const pathToCheck = (options.path || '') + '/' + options.nameFormatter(options.name);
44+
const pathToCheck = (options.path || '') + '/' + options.name;
4845

4946
return normalize(findModule(host, pathToCheck, moduleExt, routingModuleExt));
5047
} else {

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

+13-5
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, strings } from '@angular-devkit/core';
8+
import { Path } from '@angular-devkit/core';
99
import { EmptyTree, Tree } from '@angular-devkit/schematics';
1010
import { ModuleOptions, findModule, findModuleFromOptions } from './find-module';
1111

@@ -111,12 +111,20 @@ 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 nameFormatter is provided', () => {
115-
tree.create('/projects/my-proj/src/app_test.module.ts', '');
114+
it('should find a module when name has underscore', () => {
115+
tree.create('/projects/my-proj/src/feature_module/app_test.module.ts', '');
116116
options.path = '/projects/my-proj/src';
117-
options.nameFormatter = strings.underscore;
117+
options.name = 'feature_module/new_component';
118118
const modPath = findModuleFromOptions(tree, options);
119-
expect(modPath).toEqual('/projects/my-proj/src/app_test.module.ts' as Path);
119+
expect(modPath).toEqual('/projects/my-proj/src/feature_module/app_test.module.ts' as Path);
120+
});
121+
122+
it('should find a module when name has uppercase', () => {
123+
tree.create('/projects/my-proj/src/featureModule/appTest.module.ts', '');
124+
options.path = '/projects/my-proj/src';
125+
options.name = 'featureModule/newComponent';
126+
const modPath = findModuleFromOptions(tree, options);
127+
expect(modPath).toEqual('/projects/my-proj/src/featureModule/appTest.module.ts' as Path);
120128
});
121129

122130
it('should find a module if flat is true', () => {

0 commit comments

Comments
 (0)