This repository was archived by the owner on Apr 4, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
packages/schematics/angular/module Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -53,7 +53,7 @@ function addDeclarationToNgModule(options: ModuleOptions): Rule {
53
53
) ;
54
54
const relativeDir = relative ( dirname ( modulePath ) , dirname ( importModulePath ) ) ;
55
55
const relativePath = ( relativeDir . startsWith ( '.' ) ? relativeDir : './' + relativeDir )
56
- + '/' + basename ( importModulePath ) ;
56
+ + ( relativeDir . length === 0 ? '' : '/' ) + basename ( importModulePath ) ;
57
57
const changes = addImportToModule ( source , modulePath ,
58
58
strings . classify ( `${ options . name } Module` ) ,
59
59
relativePath ) ;
Original file line number Diff line number Diff line change @@ -55,6 +55,22 @@ describe('Module Schematic', () => {
55
55
expect ( files . indexOf ( '/projects/bar/src/app/foo/foo.module.ts' ) ) . toBeGreaterThanOrEqual ( 0 ) ;
56
56
} ) ;
57
57
58
+ it ( 'should import a generated flat module with a correct relative path' , ( ) => {
59
+ const options = {
60
+ ...defaultOptions ,
61
+ appRoot : 'app' ,
62
+ module : 'app' ,
63
+ flat : true ,
64
+ } ;
65
+
66
+ const tree = schematicRunner . runSchematic ( 'module' , options , appTree ) ;
67
+ const files = tree . files ;
68
+ expect ( files . indexOf ( '/projects/bar/src/app/app.module.ts' ) ) . toBeGreaterThanOrEqual ( 0 ) ;
69
+ expect ( files . indexOf ( '/projects/bar/src/app/foo.module.ts' ) ) . toBeGreaterThanOrEqual ( 0 ) ;
70
+ const moduleContent = tree . readContent ( '/projects/bar/src/app/app.module.ts' ) ;
71
+ expect ( moduleContent ) . toMatch ( / i m p o r t { F o o M o d u l e } f r o m ' \. \/ f o o .m o d u l e ' / ) ;
72
+ } ) ;
73
+
58
74
it ( 'should import into another module' , ( ) => {
59
75
const options = { ...defaultOptions , module : 'app.module.ts' } ;
60
76
You can’t perform that action at this time.
0 commit comments