@@ -44,7 +44,8 @@ import {
4444
4545import {
4646 NodeDependencyType ,
47- addPackageJsonDependency
47+ addPackageJsonDependency ,
48+ getPackageJsonDependency ,
4849} from '@schematics/angular/utility/dependencies' ;
4950
5051import { getSourceFile } from '../utility/source' ;
@@ -173,6 +174,28 @@ async function updateBudgets(host: Tree, options: any) {
173174 return host ;
174175}
175176
177+ async function addPolyfills ( host : Tree , project : string , polyfills : string [ ] ) {
178+ const projectName = await getProjectName ( host , project ) ;
179+
180+ modifyJSONFile ( host , './angular.json' , config => {
181+ const buildOptions : Record < string , any > = config . projects [ projectName ] [ 'architect' ] [ 'build' ] [ 'options' ] ;
182+
183+ if ( ! buildOptions . polyfills ) {
184+ buildOptions . polyfills = [ ] ;
185+ }
186+
187+ polyfills . forEach ( ( polyfill ) => {
188+ if ( ! buildOptions . polyfills . includes ( polyfill ) ) {
189+ buildOptions . polyfills . push ( polyfill ) ;
190+ }
191+ } )
192+
193+ return config ;
194+ } ) ;
195+
196+ return host ;
197+ }
198+
176199function addViewportToBody ( sourcePath : string = '' ) {
177200 return ( host : Tree ) => {
178201 const indexPath = join ( sourcePath , 'index.html' ) ;
@@ -200,7 +223,7 @@ function modifyFileRule(path: string, callback: (source: SourceFile) => Change[]
200223}
201224
202225function updateAppComponent ( host : Tree , sourcePath : string , templateOptions : any = { } ) {
203- const appMComponentPath = sourcePath + ( isAngularVersionHigherThan ( host , 20 ) ? 'app.ts' : 'app.component. ts') ;
226+ const appMComponentPath = sourcePath + templateOptions . name + '. ts';
204227
205228 const importSetter = ( importName : string , path : string , alias : string ) => {
206229 return ( source : SourceFile ) => {
@@ -250,13 +273,25 @@ function hasRouting(host: Tree, sourcePath: string) {
250273
251274function addPackagesToDependency ( globalNgCliVersion : string ) {
252275 const version = new SemVer ( globalNgCliVersion . replace ( / \^ | \~ / g, '' ) ) ;
276+
253277 return ( host : Tree ) => {
278+ const zonejs = getPackageJsonDependency ( host , 'zone.js' ) ;
279+
254280 addPackageJsonDependency ( host , {
255281 type : NodeDependencyType . Default ,
256282 name : '@angular/cdk' ,
257- version : `~${ version . major } .${ version . minor } .0`
283+ version : version . raw . includes ( 'next' ) || version . raw . includes ( '-rc' )
284+ ? 'next' : `^${ version . major } .${ version . minor > 1 ? version . minor - 1 : 0 } .0`
258285 } ) ;
259286
287+ if ( ! zonejs ) {
288+ addPackageJsonDependency ( host , {
289+ type : NodeDependencyType . Default ,
290+ name : 'zone.js' ,
291+ version : version . major > 18 ? '~0.15.0' : '~0.14.0'
292+ } ) ;
293+ }
294+
260295 return host ;
261296 } ;
262297}
@@ -393,7 +428,8 @@ export default function(options: any): Rule {
393428 addBuildThemeScript ( ) ,
394429 ( ) => addCustomThemeStyles ( host , options , sourcePath ) as any ,
395430 addViewportToBody ( sourcePath ) ,
396- addPackagesToDependency ( options . globalNgCliVersion )
431+ addPackagesToDependency ( options . globalNgCliVersion ) ,
432+ ( ) => addPolyfills ( host , options . project , [ 'zone.js' ] )
397433 ] ;
398434
399435 if ( options . updateBudgets ) {
0 commit comments