@@ -179,29 +179,24 @@ export async function build(_options: Options) {
179
179
}
180
180
}
181
181
182
- const otherTasks = async ( ) => {
182
+ const mainTasks = async ( ) => {
183
183
if ( ! options . dts ?. only ) {
184
- let existingOnSuccess : ChildProcess | undefined
185
- let existingOnSuccessFnPromise : Promise < any > | undefined
184
+ let onSuccessProcess : ChildProcess | undefined
185
+ let onSuccessCleanup : ( ( ) => any ) | undefined | void
186
186
/** Files imported by the entry */
187
187
const buildDependencies : Set < string > = new Set ( )
188
188
189
- const killPreviousProcessOrPromise = async ( ) => {
190
- if ( existingOnSuccess ) {
189
+ const doOnSuccessCleanup = async ( ) => {
190
+ if ( onSuccessProcess ) {
191
191
await killProcess ( {
192
- pid : existingOnSuccess . pid ,
192
+ pid : onSuccessProcess . pid ,
193
193
} )
194
- } else if ( existingOnSuccessFnPromise ) {
195
- await Promise . race ( [
196
- existingOnSuccessFnPromise ,
197
- // cancel existingOnSuccessFnPromise if it is still running,
198
- // using a promise that's been already resolved
199
- Promise . resolve ( ) ,
200
- ] )
194
+ } else if ( onSuccessCleanup ) {
195
+ await onSuccessCleanup ( )
201
196
}
202
197
// reset them in all occassions anyway
203
- existingOnSuccess = undefined
204
- existingOnSuccessFnPromise = undefined
198
+ onSuccessProcess = undefined
199
+ onSuccessCleanup = undefined
205
200
}
206
201
207
202
const debouncedBuildAll = debouncePromise (
@@ -213,7 +208,7 @@ export async function build(_options: Options) {
213
208
)
214
209
215
210
const buildAll = async ( ) => {
216
- const killPromise = killPreviousProcessOrPromise ( )
211
+ await doOnSuccessCleanup ( )
217
212
// Store previous build dependencies in case the build failed
218
213
// So we can restore it
219
214
const previousBuildDependencies = new Set ( buildDependencies )
@@ -258,12 +253,12 @@ export async function build(_options: Options) {
258
253
} )
259
254
} ) ,
260
255
] )
261
- await killPromise
256
+
262
257
if ( options . onSuccess ) {
263
258
if ( typeof options . onSuccess === 'function' ) {
264
- existingOnSuccessFnPromise = options . onSuccess ( )
259
+ onSuccessCleanup = await options . onSuccess ( )
265
260
} else {
266
- existingOnSuccess = execa ( options . onSuccess , {
261
+ onSuccessProcess = execa ( options . onSuccess , {
267
262
shell : true ,
268
263
stdio : 'inherit' ,
269
264
} )
@@ -338,7 +333,7 @@ export async function build(_options: Options) {
338
333
}
339
334
}
340
335
341
- await Promise . all ( [ dtsTask ( ) , otherTasks ( ) ] )
336
+ await Promise . all ( [ dtsTask ( ) , mainTasks ( ) ] )
342
337
}
343
338
)
344
339
)
0 commit comments