@@ -32,7 +32,6 @@ import {
3232 addPackageJsonDependency ,
3333} from '../../utility/dependencies' ;
3434import {
35- appendPropertyInAstObject ,
3635 appendValueInAstArray ,
3736 findPropertyInAstObject ,
3837} from '../../utility/json-utils' ;
@@ -734,31 +733,47 @@ function updateRootTsConfig(): Rule {
734733 }
735734
736735 const tsCfgAst = parseJsonAst ( buffer . toString ( ) , JsonParseMode . Loose ) ;
737- if ( tsCfgAst . kind != 'object' ) {
738- throw new SchematicsException (
739- 'Invalid tsconfig. Was expecting an object'
740- ) ;
736+ if ( tsCfgAst . kind !== 'object' ) {
737+ throw new SchematicsException ( 'Invalid root tsconfig. Was expecting an object' ) ;
741738 }
742739
743740 const compilerOptionsAstNode = findPropertyInAstObject ( tsCfgAst , 'compilerOptions' ) ;
744741 if ( ! compilerOptionsAstNode || compilerOptionsAstNode . kind != 'object' ) {
745- throw new SchematicsException ( 'Invalid tsconfig "compilerOptions" property; expected an object.' ) ;
742+ throw new SchematicsException (
743+ 'Invalid root tsconfig "compilerOptions" property; expected an object.' ,
744+ ) ;
746745 }
747746
748- if ( findPropertyInAstObject ( compilerOptionsAstNode , 'baseUrl' ) ) {
747+ if (
748+ findPropertyInAstObject ( compilerOptionsAstNode , 'baseUrl' ) &&
749+ findPropertyInAstObject ( compilerOptionsAstNode , 'module' )
750+ ) {
749751 return host ;
750752 }
751753
752- const recorder = host . beginUpdate ( tsConfigPath ) ;
753- appendPropertyInAstObject (
754- recorder ,
755- compilerOptionsAstNode ,
756- 'baseUrl' ,
757- './' ,
758- 4 ,
759- ) ;
754+ const compilerOptions = compilerOptionsAstNode . value ;
755+ const { baseUrl = './' , module = 'es2015' } = compilerOptions ;
756+
757+ const validBaseUrl = [ './' , '' , '.' ] ;
758+ if ( ! validBaseUrl . includes ( baseUrl as string ) ) {
759+ const formattedBaseUrl = validBaseUrl . map ( x => `'${ x } '` ) . join ( ', ' ) ;
760+ context . logger . warn ( tags . oneLine
761+ `Root tsconfig option 'baseUrl' is not one of: ${ formattedBaseUrl } .
762+ This might cause unexpected behaviour when generating libraries.` ,
763+ ) ;
764+ }
765+
766+ if ( module !== 'es2015' ) {
767+ context . logger . warn (
768+ `Root tsconfig option 'module' is not 'es2015'. This might cause unexpected behaviour.` ,
769+ ) ;
770+ }
771+
772+ compilerOptions . module = module ;
773+ compilerOptions . baseUrl = baseUrl ;
774+
775+ host . overwrite ( tsConfigPath , JSON . stringify ( tsCfgAst . value , null , 2 ) ) ;
760776
761- host . commitUpdate ( recorder ) ;
762777 return host ;
763778 } ;
764779}
0 commit comments