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 {
46
46
47
47
function getServerModulePath (
48
48
host : Tree ,
49
- projectRoot : string ,
49
+ sourceRoot : string ,
50
50
mainPath : string ,
51
51
) : string | null {
52
- const mainSource = getSourceFile ( host , mainPath ) ;
52
+ const mainSource = getSourceFile ( host , join ( normalize ( sourceRoot ) , mainPath ) ) ;
53
53
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 ) ) ;
55
55
if ( ! expNode ) {
56
56
return null ;
57
57
}
58
58
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` ) ;
60
60
61
61
return modulePath ;
62
62
}
@@ -243,7 +243,7 @@ function addServerRoutes(options: AppShellOptions): Rule {
243
243
if ( ! clientServerOptions ) {
244
244
throw new SchematicsException ( 'Server target does not contain options.' ) ;
245
245
}
246
- const modulePath = getServerModulePath ( host , clientProject . root , clientServerOptions . main ) ;
246
+ const modulePath = getServerModulePath ( host , clientProject . sourceRoot || 'src' , options . main as string ) ;
247
247
if ( modulePath === null ) {
248
248
throw new SchematicsException ( 'Universal/server module not found.' ) ;
249
249
}
Original file line number Diff line number Diff line change @@ -157,6 +157,22 @@ describe('App Shell Schematic', () => {
157
157
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 \' ; / ) ;
158
158
} ) ;
159
159
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
+
160
176
it ( 'should define a server route' , async ( ) => {
161
177
const tree = await schematicRunner . runSchematicAsync ( 'appShell' , defaultOptions , appTree )
162
178
. toPromise ( ) ;
You can’t perform that action at this time.
0 commit comments