|
2 | 2 | 'use strict' |
3 | 3 |
|
4 | 4 | const configUtil = require('../lib/config-util') |
| 5 | +const { cliWrapper, suppressEPIPE } = require('../lib/commands/helpers') |
5 | 6 | const foreground = require('foreground-child') |
6 | 7 | const resolveFrom = require('resolve-from') |
7 | 8 | const NYC = require('../index.js') |
@@ -81,29 +82,32 @@ async function main () { |
81 | 82 | // a non-zero exit codes in either one leads to an overall non-zero exit code. |
82 | 83 | process.exitCode = 0 |
83 | 84 | foreground(childArgs, async () => { |
84 | | - var mainChildExitCode = process.exitCode |
85 | | - |
86 | | - await nyc.writeProcessIndex() |
87 | | - |
88 | | - nyc.maybePurgeSourceMapCache() |
89 | | - if (argv.checkCoverage) { |
90 | | - await nyc.checkCoverage({ |
91 | | - lines: argv.lines, |
92 | | - functions: argv.functions, |
93 | | - branches: argv.branches, |
94 | | - statements: argv.statements |
95 | | - }, argv['per-file']) |
96 | | - process.exitCode = process.exitCode || mainChildExitCode |
97 | | - } |
98 | | - |
99 | | - if (!argv.silent) { |
100 | | - await nyc.report() |
| 85 | + const mainChildExitCode = process.exitCode |
| 86 | + |
| 87 | + try { |
| 88 | + await nyc.writeProcessIndex() |
| 89 | + |
| 90 | + nyc.maybePurgeSourceMapCache() |
| 91 | + if (argv.checkCoverage) { |
| 92 | + await nyc.checkCoverage({ |
| 93 | + lines: argv.lines, |
| 94 | + functions: argv.functions, |
| 95 | + branches: argv.branches, |
| 96 | + statements: argv.statements |
| 97 | + }, argv['per-file']).catch(suppressEPIPE) |
| 98 | + process.exitCode = process.exitCode || mainChildExitCode |
| 99 | + } |
| 100 | + |
| 101 | + if (!argv.silent) { |
| 102 | + await nyc.report().catch(suppressEPIPE) |
| 103 | + } |
| 104 | + } catch (error) { |
| 105 | + /* istanbul ignore next */ |
| 106 | + process.exitCode = process.exitCode || mainChildExitCode || 1 |
| 107 | + /* istanbul ignore next */ |
| 108 | + console.error(error.message) |
101 | 109 | } |
102 | 110 | }) |
103 | 111 | } |
104 | 112 |
|
105 | | -/* istanbul ignore next: the error branch should be unreachable */ |
106 | | -main().catch(error => { |
107 | | - console.error(error.message) |
108 | | - process.exit(1) |
109 | | -}) |
| 113 | +cliWrapper(main)() |
0 commit comments