@@ -3,6 +3,7 @@ import path from 'path';
3
3
import child_process from 'child_process' ;
4
4
import fs from 'fs-extra' ;
5
5
import del from 'del' ;
6
+ import JSON5 from 'json5' ;
6
7
import { platform } from 'os' ;
7
8
import { Input } from '../types' ;
8
9
@@ -19,37 +20,47 @@ export default async function build({ root, output, report }: Input) {
19
20
20
21
try {
21
22
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
+ }
52
59
}
60
+ } catch ( e ) {
61
+ report . warn (
62
+ `Couldn't parse 'tsconfig.json'. There might be validation errors.`
63
+ ) ;
53
64
}
54
65
}
55
66
@@ -73,6 +84,8 @@ export default async function build({ root, output, report }: Input) {
73
84
output ,
74
85
] ) ;
75
86
87
+ await del ( [ path . join ( output , 'tsconfig.tsbuildinfo' ) ] ) ;
88
+
76
89
report . success (
77
90
`Wrote definition files to ${ chalk . blue ( path . relative ( root , output ) ) } `
78
91
) ;
0 commit comments