55 * Use of this source code is governed by an MIT-style license that can be
66 * found in the LICENSE file at https://angular.io/license
77 */
8- import { JsonAstNode , JsonAstString , JsonParseMode , dirname , join , normalize , parseJsonAst , resolve } from '@angular-devkit/core' ;
8+ import { JsonAstNode , JsonAstString , JsonParseMode , dirname , join , logging , normalize , parseJsonAst , resolve } from '@angular-devkit/core' ;
99import { DirEntry , Rule , chain } from '@angular-devkit/schematics' ;
1010import { findPropertyInAstObject } from '../../utility/json-utils' ;
1111import { getWorkspace } from '../../utility/workspace' ;
@@ -18,7 +18,7 @@ const SOLUTIONS_TS_CONFIG_HEADER = `/*
1818*/
1919` ;
2020
21- function * visitExtendedJsonFiles ( directory : DirEntry ) : IterableIterator < [ string , JsonAstString ] > {
21+ function * visitExtendedJsonFiles ( directory : DirEntry , logger : logging . LoggerApi ) : IterableIterator < [ string , JsonAstString ] > {
2222 for ( const path of directory . subfiles ) {
2323 if ( ! path . endsWith ( '.json' ) ) {
2424 continue ;
@@ -33,8 +33,16 @@ function* visitExtendedJsonFiles(directory: DirEntry): IterableIterator<[string,
3333 let jsonAst : JsonAstNode ;
3434 try {
3535 jsonAst = parseJsonAst ( content , JsonParseMode . Loose ) ;
36- } catch {
37- throw new Error ( `Invalid JSON AST Object (${ path } )` ) ;
36+ } catch ( error ) {
37+ let jsonFilePath = `${ join ( directory . path , path ) } ` ;
38+ jsonFilePath = jsonFilePath . startsWith ( '/' ) ? jsonFilePath . substr ( 1 ) : jsonFilePath ;
39+
40+ const msg = error instanceof Error ? error . message : error ;
41+ logger . warn (
42+ `Failed to parse "${ jsonFilePath } " as JSON AST Object. ${ msg } \n` +
43+ 'If this is a TypeScript configuration file you will need to update the "extends" value manually.' ,
44+ ) ;
45+ continue ;
3846 }
3947
4048 if ( jsonAst . kind !== 'object' ) {
@@ -54,12 +62,12 @@ function* visitExtendedJsonFiles(directory: DirEntry): IterableIterator<[string,
5462 continue ;
5563 }
5664
57- yield * visitExtendedJsonFiles ( directory . dir ( path ) ) ;
65+ yield * visitExtendedJsonFiles ( directory . dir ( path ) , logger ) ;
5866 }
5967}
6068
6169function updateTsconfigExtendsRule ( ) : Rule {
62- return host => {
70+ return ( host , context ) => {
6371 if ( ! host . exists ( 'tsconfig.json' ) ) {
6472 return ;
6573 }
@@ -68,7 +76,7 @@ function updateTsconfigExtendsRule(): Rule {
6876 host . rename ( 'tsconfig.json' , 'tsconfig.base.json' ) ;
6977
7078 // Iterate over all tsconfig files and change the extends from 'tsconfig.json' 'tsconfig.base.json'
71- for ( const [ tsconfigPath , extendsAst ] of visitExtendedJsonFiles ( host . root ) ) {
79+ for ( const [ tsconfigPath , extendsAst ] of visitExtendedJsonFiles ( host . root , context . logger ) ) {
7280 const tsConfigDir = dirname ( normalize ( tsconfigPath ) ) ;
7381 if ( '/tsconfig.json' !== resolve ( tsConfigDir , normalize ( extendsAst . value ) ) ) {
7482 // tsconfig extends doesn't refer to the workspace tsconfig path.
0 commit comments