11import { normalize } from 'path' ;
22import { getGlobalVariable } from '../../utils/env' ;
3- import { expectFileToMatch , writeFile } from '../../utils/fs' ;
3+ import { appendToFile , expectFileToMatch , writeFile } from '../../utils/fs' ;
44import { exec , ng , silentNpm } from '../../utils/process' ;
55import { updateJsonFile } from '../../utils/project' ;
66import { readNgVersion } from '../../utils/version' ;
@@ -9,9 +9,7 @@ export default async function () {
99 const argv = getGlobalVariable ( 'argv' ) ;
1010 const veEnabled = argv [ 've' ] ;
1111
12- await ng ( 'add' , '@nguniversal/express-engine' , '--client-project' , 'test-project' ) ;
13- // todo remove once https://github.com/angular/universal/pull/1229 is landed
14- await silentNpm ( 'install' , '@types/express' , '--save-dev' ) ;
12+ await ng ( 'add' , '@nguniversal/express-engine@9.0.0-next.5' ) ;
1513
1614 await updateJsonFile ( 'package.json' , packageJson => {
1715 const dependencies = packageJson [ 'dependencies' ] ;
@@ -22,32 +20,40 @@ export default async function () {
2220
2321 await silentNpm ( 'install' ) ;
2422 if ( veEnabled ) {
23+ // todo: https://github.com/angular/angular-cli/issues/15851
24+ // We need to fix the 'export_ngfactory' transformer as with the
25+ // new universal approach the factory is not exported.
26+ await appendToFile (
27+ './src/main.server.ts' ,
28+ `export { AppServerModuleNgFactory } from './app/app.server.module.ngfactory'` ,
29+ ) ;
30+
2531 await writeFile (
26- './index.js ' ,
27- ` require( 'zone.js/dist/zone-node') ;
28- const fs = require( 'fs') ;
29- const { AppServerModuleNgFactory, renderModuleFactory } = require( './dist/server/ main') ;
32+ './server.ts ' ,
33+ ` import 'zone.js/dist/zone-node';
34+ import * as fs from 'fs';
35+ import { AppServerModuleNgFactory, renderModuleFactory } from './src/ main.server' ;
3036
3137 renderModuleFactory(AppServerModuleNgFactory, {
3238 url: '/',
3339 document: '<app-root></app-root>'
3440 }).then(html => {
35- fs.writeFileSync('dist/server/index.html', html);
41+ fs.writeFileSync('dist/test-project/ server/index.html', html);
3642 });
3743 ` ,
3844 ) ;
3945 } else {
4046 await writeFile (
41- './index.js ' ,
42- ` require( 'zone.js/dist/zone-node') ;
43- const fs = require( 'fs') ;
44- const { AppServerModule, renderModule } = require( './dist/server/ main') ;
47+ './server.ts ' ,
48+ ` import 'zone.js/dist/zone-node';
49+ import * as fs from 'fs';
50+ import { AppServerModule, renderModule } from './src/ main.server' ;
4551
4652 renderModule(AppServerModule, {
4753 url: '/',
4854 document: '<app-root></app-root>'
4955 }).then(html => {
50- fs.writeFileSync('dist/server/index.html', html);
56+ fs.writeFileSync('dist/test-project/ server/index.html', html);
5157 });
5258 ` ,
5359 ) ;
@@ -56,18 +62,18 @@ export default async function () {
5662
5763 await ng ( 'run' , 'test-project:server:production' , '--optimization' , 'false' ) ;
5864
59- await expectFileToMatch ( 'dist/server/main.js' , veEnabled ? / e x p o r t s .* A p p S e r v e r M o d u l e N g F a c t o r y / : / e x p o r t s .* A p p S e r v e r M o d u l e / ) ;
60- await exec ( normalize ( 'node' ) , 'index .js' ) ;
65+ await expectFileToMatch ( 'dist/test-project/ server/main.js' , veEnabled ? / e x p o r t s .* A p p S e r v e r M o d u l e N g F a c t o r y / : / e x p o r t s .* A p p S e r v e r M o d u l e / ) ;
66+ await exec ( normalize ( 'node' ) , 'dist/test-project/server/main .js' ) ;
6167 await expectFileToMatch (
62- 'dist/server/index.html' ,
68+ 'dist/test-project/ server/index.html' ,
6369 / < p .* > H e r e a r e s o m e l i n k s t o h e l p y o u g e t s t a r t e d : < \/ p > / ,
6470 ) ;
6571
6672 // works with optimization and bundleDependencies enabled
6773 await ng ( 'run' , 'test-project:server:production' , '--optimization' , '--bundleDependencies' , 'all' ) ;
68- await exec ( normalize ( 'node' ) , 'index .js' ) ;
74+ await exec ( normalize ( 'node' ) , 'dist/test-project/server/main .js' ) ;
6975 await expectFileToMatch (
70- 'dist/server/index.html' ,
76+ 'dist/test-project/ server/index.html' ,
7177 / < p .* > H e r e a r e s o m e l i n k s t o h e l p y o u g e t s t a r t e d : < \/ p > / ,
7278 ) ;
7379}
0 commit comments