@@ -20,8 +20,10 @@ export interface ModuleOptions {
20
20
standalone ?: boolean ;
21
21
}
22
22
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' ;
25
27
26
28
/**
27
29
* 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
31
33
return undefined ;
32
34
}
33
35
34
- const moduleExt = options . moduleExt || MODULE_EXT ;
35
- const routingModuleExt = options . routingModuleExt || ROUTING_MODULE_EXT ;
36
-
37
36
if ( ! options . module ) {
38
37
const pathToCheck = ( options . path || '' ) + '/' + options . name ;
39
38
40
- return normalize ( findModule ( host , pathToCheck , moduleExt , routingModuleExt ) ) ;
39
+ return normalize ( findModule ( host , pathToCheck , options . moduleExt , options . routingModuleExt ) ) ;
41
40
} else {
42
41
const modulePath = normalize ( `/${ options . path } /${ options . module } ` ) ;
43
42
const componentPath = normalize ( `/${ options . path } /${ options . name } ` ) ;
@@ -53,14 +52,21 @@ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path
53
52
}
54
53
55
54
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 } ` ,
59
62
) ;
63
+ }
60
64
65
+ for ( const c of candidatesDirs ) {
61
66
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 ) ;
64
70
}
65
71
}
66
72
}
@@ -78,15 +84,22 @@ export function findModuleFromOptions(host: Tree, options: ModuleOptions): Path
78
84
export function findModule (
79
85
host : Tree ,
80
86
generateDir : string ,
81
- moduleExt = MODULE_EXT ,
82
- routingModuleExt = ROUTING_MODULE_EXT ,
87
+ moduleExt ?: string ,
88
+ routingModuleExt ?: string ,
83
89
) : Path {
84
90
let dir : DirEntry | null = host . getDir ( '/' + generateDir ) ;
85
91
let foundRoutingModule = false ;
86
92
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
+
87
98
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
+ ) ;
90
103
91
104
foundRoutingModule = foundRoutingModule || allMatches . length !== filteredMatches . length ;
92
105
0 commit comments