@@ -46,30 +46,41 @@ const handleOutput = (command, result, ctx, isError = false) => {
46
46
}
47
47
}
48
48
49
+ /**
50
+ * Kill an execa process along with all its child processes.
51
+ * @param {execa.ExecaChildProcess<string> } execaProcess
52
+ */
53
+ const killExecaProcess = async ( execaProcess ) => {
54
+ try {
55
+ const childPids = await pidTree ( execaProcess . pid )
56
+ for ( const childPid of childPids ) {
57
+ process . kill ( childPid )
58
+ }
59
+ } catch {
60
+ // Suppress "No matching pid found" error. This probably means
61
+ // the process already died before executing.
62
+ }
63
+
64
+ // The execa process is killed separately in order to get the `KILLED` status.
65
+ execaProcess . kill ( )
66
+ }
67
+
49
68
/**
50
69
* Interrupts the execution of the execa process that we spawned if
51
70
* another task adds an error to the context.
52
71
*
53
72
* @param {Object } ctx
54
73
* @param {execa.ExecaChildProcess<string> } execaChildProcess
55
- * @returns {function(): void } Function that clears the interval that
74
+ * @returns {() => void } Function that clears the interval that
56
75
* checks the context.
57
76
*/
58
77
const interruptExecutionOnError = ( ctx , execaChildProcess ) => {
59
78
let loopIntervalId
60
79
61
- async function loop ( ) {
80
+ const loop = async ( ) => {
62
81
if ( ctx . errors . size > 0 ) {
63
82
clearInterval ( loopIntervalId )
64
-
65
- const childPids = await pidTree ( execaChildProcess . pid )
66
- for ( const pid of childPids ) {
67
- process . kill ( pid )
68
- }
69
-
70
- // The execa process is killed separately in order
71
- // to get the `KILLED` status.
72
- execaChildProcess . kill ( )
83
+ await killExecaProcess ( execaChildProcess )
73
84
}
74
85
}
75
86
@@ -111,7 +122,7 @@ const makeErr = (command, result, ctx) => {
111
122
* @param {Array<string> } options.files — Filepaths to run the linter task against
112
123
* @param {Boolean } [options.shell] — Whether to skip parsing linter task for better shell support
113
124
* @param {Boolean } [options.verbose] — Always show task verbose
114
- * @returns {function(): Promise<Array<string>> }
125
+ * @returns {() => Promise<Array<string>> }
115
126
*/
116
127
export const resolveTaskFn = ( {
117
128
command,
0 commit comments