@@ -32,6 +32,7 @@ import {
32
32
addPackageJsonDependency ,
33
33
} from '../../utility/dependencies' ;
34
34
import {
35
+ appendPropertyInAstObject ,
35
36
appendValueInAstArray ,
36
37
findPropertyInAstObject ,
37
38
} from '../../utility/json-utils' ;
@@ -724,6 +725,44 @@ function updateTsLintConfig(): Rule {
724
725
} ;
725
726
}
726
727
728
+ function updateRootTsConfig ( ) : Rule {
729
+ return ( host : Tree , context : SchematicContext ) => {
730
+ const tsConfigPath = '/tsconfig.json' ;
731
+ const buffer = host . read ( tsConfigPath ) ;
732
+ if ( ! buffer ) {
733
+ return ;
734
+ }
735
+
736
+ const tsCfgAst = parseJsonAst ( buffer . toString ( ) , JsonParseMode . Loose ) ;
737
+ if ( tsCfgAst . kind != 'object' ) {
738
+ throw new SchematicsException (
739
+ 'Invalid tsconfig. Was expecting an object'
740
+ ) ;
741
+ }
742
+
743
+ const compilerOptionsAstNode = findPropertyInAstObject ( tsCfgAst , 'compilerOptions' ) ;
744
+ if ( ! compilerOptionsAstNode || compilerOptionsAstNode . kind != 'object' ) {
745
+ throw new SchematicsException ( 'Invalid tsconfig "compilerOptions" property; expected an object.' ) ;
746
+ }
747
+
748
+ if ( findPropertyInAstObject ( compilerOptionsAstNode , 'baseUrl' ) ) {
749
+ return host ;
750
+ }
751
+
752
+ const recorder = host . beginUpdate ( tsConfigPath ) ;
753
+ appendPropertyInAstObject (
754
+ recorder ,
755
+ compilerOptionsAstNode ,
756
+ 'baseUrl' ,
757
+ './' ,
758
+ 4 ,
759
+ ) ;
760
+
761
+ host . commitUpdate ( recorder ) ;
762
+ return host ;
763
+ } ;
764
+ }
765
+
727
766
export default function ( ) : Rule {
728
767
return ( host : Tree , context : SchematicContext ) => {
729
768
if ( host . exists ( '/.angular.json' ) || host . exists ( '/angular.json' ) ) {
@@ -748,6 +787,7 @@ export default function (): Rule {
748
787
migrateConfiguration ( config , context . logger ) ,
749
788
updateSpecTsConfig ( config ) ,
750
789
updatePackageJson ( config ) ,
790
+ updateRootTsConfig ( ) ,
751
791
updateTsLintConfig ( ) ,
752
792
( host : Tree , context : SchematicContext ) => {
753
793
context . logger . warn ( tags . oneLine `Some configuration options have been changed,
0 commit comments