3
3
4
4
const configUtil = require ( '../lib/config-util' )
5
5
const { cliWrapper, suppressEPIPE } = require ( '../lib/commands/helpers' )
6
- const foreground = require ( 'foreground-child' )
6
+ const { foregroundChild } = require ( 'foreground-child' )
7
7
const resolveFrom = require ( 'resolve-from' )
8
8
const NYC = require ( '../index.js' )
9
+ const path = require ( 'path' )
10
+ const fs = require ( 'fs' )
9
11
10
12
// parse configuration and command-line arguments;
11
13
// we keep these values in a few different forms,
@@ -86,10 +88,22 @@ async function main () {
86
88
// set process.exitCode. Keep track so that both children are run, but
87
89
// a non-zero exit codes in either one leads to an overall non-zero exit code.
88
90
process . exitCode = 0
89
- foreground ( childArgs , async ( ) => {
90
- const mainChildExitCode = process . exitCode
91
+ foregroundChild ( childArgs , async ( code , signal , processInfo ) => {
92
+ let exitCode = process . exitCode || code
91
93
92
94
try {
95
+ // clean up foreground-child watchdog process info
96
+ const parentDir = path . resolve ( nyc . tempDirectory ( ) )
97
+ const dir = path . resolve ( nyc . tempDirectory ( ) , 'processinfo' )
98
+ const files = await nyc . coverageFiles ( dir )
99
+ for ( let i = 0 ; i < files . length ; i ++ ) {
100
+ const data = await nyc . coverageFileLoad ( files [ i ] , dir )
101
+ if ( data . pid === processInfo . watchdogPid ) {
102
+ fs . unlinkSync ( path . resolve ( parentDir , files [ i ] ) )
103
+ fs . unlinkSync ( path . resolve ( dir , files [ i ] ) )
104
+ }
105
+ }
106
+
93
107
await nyc . writeProcessIndex ( )
94
108
95
109
nyc . maybePurgeSourceMapCache ( )
@@ -100,18 +114,20 @@ async function main () {
100
114
branches : argv . branches ,
101
115
statements : argv . statements
102
116
} , argv [ 'per-file' ] ) . catch ( suppressEPIPE )
103
- process . exitCode = process . exitCode || mainChildExitCode
117
+ exitCode = process . exitCode || exitCode
104
118
}
105
119
106
120
if ( ! argv . silent ) {
107
121
await nyc . report ( ) . catch ( suppressEPIPE )
108
122
}
109
123
} catch ( error ) {
110
124
/* istanbul ignore next */
111
- process . exitCode = process . exitCode || mainChildExitCode || 1
125
+ exitCode = process . exitCode || exitCode || 1
112
126
/* istanbul ignore next */
113
127
console . error ( error . message )
114
128
}
129
+
130
+ return exitCode
115
131
} )
116
132
}
117
133
0 commit comments