@@ -20,8 +20,10 @@ export interface ModuleOptions {
2020 standalone ?: boolean ;
2121}
2222
23- export const MODULE_EXT = '.module.ts' ;
24- export const ROUTING_MODULE_EXT = '-routing.module.ts' ;
23+ export const MODULE_EXT = '-module.ts' ;
24+ export const ROUTING_MODULE_EXT = '-routing-module.ts' ;
25+ export const MODULE_EXT_LEGACY = '.module.ts' ;
26+ export const ROUTING_MODULE_EXT_LEGACY = '-routing.module.ts' ;
2527
2628/**
2729 * Find the module referred by a set of options passed to the schematics.
@@ -31,13 +33,10 @@ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path
3133 return undefined ;
3234 }
3335
34- const moduleExt = options . moduleExt || MODULE_EXT ;
35- const routingModuleExt = options . routingModuleExt || ROUTING_MODULE_EXT ;
36-
3736 if ( ! options . module ) {
3837 const pathToCheck = ( options . path || '' ) + '/' + options . name ;
3938
40- return normalize ( findModule ( host , pathToCheck , moduleExt , routingModuleExt ) ) ;
39+ return normalize ( findModule ( host , pathToCheck , options . moduleExt , options . routingModuleExt ) ) ;
4140 } else {
4241 const modulePath = normalize ( `/${ options . path } /${ options . module } ` ) ;
4342 const componentPath = normalize ( `/${ options . path } /${ options . name } ` ) ;
@@ -53,14 +52,21 @@ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path
5352 }
5453
5554 const candidatesDirs = [ ...candidateSet ] . sort ( ( a , b ) => b . length - a . length ) ;
56- for ( const c of candidatesDirs ) {
57- const candidateFiles = [ '' , `${ moduleBaseName } .ts` , `${ moduleBaseName } ${ moduleExt } ` ] . map (
58- ( x ) => join ( c , x ) ,
55+ const candidateFiles : string [ ] = [ '' , `${ moduleBaseName } .ts` ] ;
56+ if ( options . moduleExt ) {
57+ candidateFiles . push ( `${ moduleBaseName } ${ options . moduleExt } ` ) ;
58+ } else {
59+ candidateFiles . push (
60+ `${ moduleBaseName } ${ MODULE_EXT } ` ,
61+ `${ moduleBaseName } ${ MODULE_EXT_LEGACY } ` ,
5962 ) ;
63+ }
6064
65+ for ( const c of candidatesDirs ) {
6166 for ( const sc of candidateFiles ) {
62- if ( host . exists ( sc ) && host . readText ( sc ) . includes ( '@NgModule' ) ) {
63- return normalize ( sc ) ;
67+ const scPath = join ( c , sc ) ;
68+ if ( host . exists ( scPath ) && host . readText ( scPath ) . includes ( '@NgModule' ) ) {
69+ return normalize ( scPath ) ;
6470 }
6571 }
6672 }
@@ -78,15 +84,22 @@ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path
7884export function findModule (
7985 host : Tree ,
8086 generateDir : string ,
81- moduleExt = MODULE_EXT ,
82- routingModuleExt = ROUTING_MODULE_EXT ,
87+ moduleExt ?: string ,
88+ routingModuleExt ?: string ,
8389) : Path {
8490 let dir : DirEntry | null = host . getDir ( '/' + generateDir ) ;
8591 let foundRoutingModule = false ;
8692
93+ const moduleExtensions : string [ ] = moduleExt ? [ moduleExt ] : [ MODULE_EXT , MODULE_EXT_LEGACY ] ;
94+ const routingModuleExtensions : string [ ] = routingModuleExt
95+ ? [ routingModuleExt ]
96+ : [ ROUTING_MODULE_EXT , ROUTING_MODULE_EXT_LEGACY ] ;
97+
8798 while ( dir ) {
88- const allMatches = dir . subfiles . filter ( ( p ) => p . endsWith ( moduleExt ) ) ;
89- const filteredMatches = allMatches . filter ( ( p ) => ! p . endsWith ( routingModuleExt ) ) ;
99+ const allMatches = dir . subfiles . filter ( ( p ) => moduleExtensions . some ( ( m ) => p . endsWith ( m ) ) ) ;
100+ const filteredMatches = allMatches . filter (
101+ ( p ) => ! routingModuleExtensions . some ( ( m ) => p . endsWith ( m ) ) ,
102+ ) ;
90103
91104 foundRoutingModule = foundRoutingModule || allMatches . length !== filteredMatches . length ;
92105
0 commit comments