File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed
packages/schematics/angular/app-shell Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -46,17 +46,17 @@ function getSourceFile(host: Tree, path: string): ts.SourceFile {
4646
4747function getServerModulePath (
4848 host : Tree ,
49- projectRoot : string ,
49+ sourceRoot : string ,
5050 mainPath : string ,
5151) : string | null {
52- const mainSource = getSourceFile ( host , mainPath ) ;
52+ const mainSource = getSourceFile ( host , join ( normalize ( sourceRoot ) , mainPath ) ) ;
5353 const allNodes = getSourceNodes ( mainSource ) ;
54- const expNode = allNodes . filter ( node => node . kind === ts . SyntaxKind . ExportDeclaration ) [ 0 ] ;
54+ const expNode = allNodes . find ( node => ts . isExportDeclaration ( node ) ) ;
5555 if ( ! expNode ) {
5656 return null ;
5757 }
5858 const relativePath = ( expNode as ts . ExportDeclaration ) . moduleSpecifier as ts . StringLiteral ;
59- const modulePath = normalize ( `/${ projectRoot } /src /${ relativePath . text } .ts` ) ;
59+ const modulePath = normalize ( `/${ sourceRoot } /${ relativePath . text } .ts` ) ;
6060
6161 return modulePath ;
6262}
@@ -243,7 +243,7 @@ function addServerRoutes(options: AppShellOptions): Rule {
243243 if ( ! clientServerOptions ) {
244244 throw new SchematicsException ( 'Server target does not contain options.' ) ;
245245 }
246- const modulePath = getServerModulePath ( host , clientProject . root , clientServerOptions . main ) ;
246+ const modulePath = getServerModulePath ( host , clientProject . sourceRoot || 'src' , options . main as string ) ;
247247 if ( modulePath === null ) {
248248 throw new SchematicsException ( 'Universal/server module not found.' ) ;
249249 }
Original file line number Diff line number Diff line change @@ -157,6 +157,22 @@ describe('App Shell Schematic', () => {
157157 expect ( content ) . toMatch ( / i m p o r t { R o u t e s , R o u t e r M o d u l e } f r o m \' @ a n g u l a r \/ r o u t e r \' ; / ) ;
158158 } ) ;
159159
160+ it ( 'should work after adding nguniversal' , async ( ) => {
161+ let tree = await schematicRunner . runSchematicAsync ( 'universal' , defaultOptions , appTree )
162+ . toPromise ( ) ;
163+
164+ // change main tsconfig to mimic ng add for nguniveral
165+ const workspace = JSON . parse ( appTree . readContent ( '/angular.json' ) ) ;
166+ workspace . projects . bar . architect . server . options . main = 'server.ts' ;
167+ appTree . overwrite ( 'angular.json' , JSON . stringify ( workspace , undefined , 2 ) ) ;
168+
169+ tree = await schematicRunner . runSchematicAsync ( 'appShell' , defaultOptions , tree )
170+ . toPromise ( ) ;
171+ const filePath = '/projects/bar/src/app/app.server.module.ts' ;
172+ const content = tree . readContent ( filePath ) ;
173+ expect ( content ) . toMatch ( / i m p o r t { R o u t e s , R o u t e r M o d u l e } f r o m \' @ a n g u l a r \/ r o u t e r \' ; / ) ;
174+ } ) ;
175+
160176 it ( 'should define a server route' , async ( ) => {
161177 const tree = await schematicRunner . runSchematicAsync ( 'appShell' , defaultOptions , appTree )
162178 . toPromise ( ) ;
You can’t perform that action at this time.
0 commit comments