@@ -32,6 +32,7 @@ import {
3232 addPackageJsonDependency ,
3333} from '../../utility/dependencies' ;
3434import {
35+ appendPropertyInAstObject ,
3536 appendValueInAstArray ,
3637 findPropertyInAstObject ,
3738} from '../../utility/json-utils' ;
@@ -724,6 +725,44 @@ function updateTsLintConfig(): Rule {
724725 } ;
725726}
726727
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+
727766export default function ( ) : Rule {
728767 return ( host : Tree , context : SchematicContext ) => {
729768 if ( host . exists ( '/.angular.json' ) || host . exists ( '/angular.json' ) ) {
@@ -748,6 +787,7 @@ export default function (): Rule {
748787 migrateConfiguration ( config , context . logger ) ,
749788 updateSpecTsConfig ( config ) ,
750789 updatePackageJson ( config ) ,
790+ updateRootTsConfig ( ) ,
751791 updateTsLintConfig ( ) ,
752792 ( host : Tree , context : SchematicContext ) => {
753793 context . logger . warn ( tags . oneLine `Some configuration options have been changed,
0 commit comments