@@ -3,6 +3,7 @@ import path from 'path';
33import child_process from 'child_process' ;
44import fs from 'fs-extra' ;
55import del from 'del' ;
6+ import JSON5 from 'json5' ;
67import { platform } from 'os' ;
78import { Input } from '../types' ;
89
@@ -19,37 +20,47 @@ export default async function build({ root, output, report }: Input) {
1920
2021 try {
2122 if ( await fs . pathExists ( tsconfig ) ) {
22- const config = JSON . parse ( await fs . readFile ( tsconfig , 'utf-8' ) ) ;
23-
24- if ( config . compilerOptions ) {
25- const conflicts : string [ ] = [ ] ;
26-
27- if ( config . compilerOptions . noEmit !== undefined ) {
28- conflicts . push ( 'compilerOptions.noEmit' ) ;
29- }
30-
31- if ( config . compilerOptions . emitDeclarationOnly !== undefined ) {
32- conflicts . push ( 'compilerOptions.emitDeclarationOnly' ) ;
33- }
34-
35- if ( config . compilerOptions . outDir ) {
36- conflicts . push ( 'compilerOptions.outDir' ) ;
37- }
38-
39- if ( config . compilerOptions . declarationDir ) {
40- conflicts . push ( 'compilerOptions.declarationDir' ) ;
41- }
42-
43- if ( conflicts . length ) {
44- report . warn (
45- `Found following options in the config file which can conflict with the CLI options. Please remove them from ${ chalk . blue (
46- 'tsconfig.json'
47- ) } :${ conflicts . reduce (
48- ( acc , curr ) => acc + `\n${ chalk . gray ( '-' ) } ${ chalk . yellow ( curr ) } ` ,
49- ''
50- ) } `
51- ) ;
23+ try {
24+ const config = JSON5 . parse ( await fs . readFile ( tsconfig , 'utf-8' ) ) ;
25+
26+ if ( config . compilerOptions ) {
27+ const conflicts : string [ ] = [ ] ;
28+
29+ if ( config . compilerOptions . noEmit !== undefined ) {
30+ conflicts . push ( 'compilerOptions.noEmit' ) ;
31+ }
32+
33+ if ( config . compilerOptions . emitDeclarationOnly !== undefined ) {
34+ conflicts . push ( 'compilerOptions.emitDeclarationOnly' ) ;
35+ }
36+
37+ if ( config . compilerOptions . declarationDir ) {
38+ conflicts . push ( 'compilerOptions.declarationDir' ) ;
39+ }
40+
41+ if (
42+ config . compilerOptions . outDir &&
43+ path . join ( root , config . compilerOptions . outDir ) !== output
44+ ) {
45+ conflicts . push ( 'compilerOptions.outDir' ) ;
46+ }
47+
48+ if ( conflicts . length ) {
49+ report . warn (
50+ `Found following options in the config file which can conflict with the CLI options. Please remove them from ${ chalk . blue (
51+ 'tsconfig.json'
52+ ) } :${ conflicts . reduce (
53+ ( acc , curr ) =>
54+ acc + `\n${ chalk . gray ( '-' ) } ${ chalk . yellow ( curr ) } ` ,
55+ ''
56+ ) } `
57+ ) ;
58+ }
5259 }
60+ } catch ( e ) {
61+ report . warn (
62+ `Couldn't parse 'tsconfig.json'. There might be validation errors.`
63+ ) ;
5364 }
5465 }
5566
@@ -73,6 +84,8 @@ export default async function build({ root, output, report }: Input) {
7384 output ,
7485 ] ) ;
7586
87+ await del ( [ path . join ( output , 'tsconfig.tsbuildinfo' ) ] ) ;
88+
7689 report . success (
7790 `Wrote definition files to ${ chalk . blue ( path . relative ( root , output ) ) } `
7891 ) ;
0 commit comments