@@ -85,42 +85,24 @@ export default async function build({
85
85
( platform ( ) === 'win32' ? '.cmd' : '' ) ;
86
86
87
87
if ( ! ( await fs . pathExists ( tsc ) ) ) {
88
- tsc = await which ( 'tsc' ) ;
88
+ try {
89
+ tsc = await which ( 'tsc' ) ;
89
90
90
- report . warn (
91
- `Using a global version of ${ chalk . blue (
92
- 'tsc'
93
- ) } . Consider adding ${ chalk . blue ( 'typescript' ) } to your ${ chalk . blue (
94
- 'devDependencies'
95
- ) } or specifying the ${ chalk . blue (
96
- 'tsc'
97
- ) } option for the typescript target.`
98
- ) ;
91
+ report . warn (
92
+ `Using a global version of ${ chalk . blue (
93
+ 'tsc'
94
+ ) } . Consider adding ${ chalk . blue ( 'typescript' ) } to your ${ chalk . blue (
95
+ 'devDependencies'
96
+ ) } or specifying the ${ chalk . blue (
97
+ 'tsc'
98
+ ) } option for the typescript target.`
99
+ ) ;
100
+ } catch ( e ) {
101
+ // Ignore
102
+ }
99
103
}
100
104
101
- if ( await fs . pathExists ( tsc ) ) {
102
- spawn . sync (
103
- tsc ,
104
- [
105
- '--pretty' ,
106
- '--declaration' ,
107
- '--emitDeclarationOnly' ,
108
- '--project' ,
109
- project ,
110
- '--outDir' ,
111
- output ,
112
- ] ,
113
- { stdio : 'inherit' }
114
- ) ;
115
-
116
- await del ( [
117
- path . join ( output , project . replace ( / \. j s o n $ / , '.tsbuildinfo' ) ) ,
118
- ] ) ;
119
-
120
- report . success (
121
- `Wrote definition files to ${ chalk . blue ( path . relative ( root , output ) ) } `
122
- ) ;
123
- } else {
105
+ if ( ! ( await fs . pathExists ( tsc ) ) ) {
124
106
throw new Error (
125
107
`The ${ chalk . blue (
126
108
'tsc'
@@ -133,6 +115,41 @@ export default async function build({
133
115
) } option for typescript.`
134
116
) ;
135
117
}
118
+
119
+ const tsbuildinfo = path . join (
120
+ output ,
121
+ project . replace ( / \. j s o n $ / , '.tsbuildinfo' )
122
+ ) ;
123
+
124
+ try {
125
+ await del ( [ tsbuildinfo ] ) ;
126
+ } catch ( e ) {
127
+ // Ignore
128
+ }
129
+
130
+ const result = spawn . sync (
131
+ tsc ,
132
+ [
133
+ '--pretty' ,
134
+ '--declaration' ,
135
+ '--emitDeclarationOnly' ,
136
+ '--project' ,
137
+ project ,
138
+ '--outDir' ,
139
+ output ,
140
+ ] ,
141
+ { stdio : 'inherit' }
142
+ ) ;
143
+
144
+ if ( result . status === 0 ) {
145
+ await del ( [ tsbuildinfo ] ) ;
146
+
147
+ report . success (
148
+ `Wrote definition files to ${ chalk . blue ( path . relative ( root , output ) ) } `
149
+ ) ;
150
+ } else {
151
+ throw new Error ( 'Failed to build definition files.' ) ;
152
+ }
136
153
} catch ( e ) {
137
154
if ( e . stdout ) {
138
155
report . error (
0 commit comments