superc8 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016-now coderaiser
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,206 @@
1
+ # superc8 - native V8 code-coverage
2
+
3
+ [![ci](https://github.com/bcoe/c8/actions/workflows/ci.yaml/badge.svg)](https://github.com/bcoe/c8/actions/workflows/ci.yaml)
4
+ ![nycrc config on GitHub](https://img.shields.io/nycrc/bcoe/c8)
5
+ [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://www.conventionalcommits.org/)
6
+
7
+ ## Fork of `c8` contains
8
+
9
+ - ✅ Fixed TODO ([`parase-args#L176`](https://github.com/bcoe/c8/blob/main/lib/parse-args.js#L176), [`check-coverage#L14`](https://github.com/bcoe/c8/blob/ee2f1cfc5584d41bb2d51b788d0953dab0c798f8/lib/commands/check-coverage.js#L14));
10
+ - ✅ ESM-only code;
11
+ - ✅ Updated dependencies, including `yargs` that makes `node v25` crash (https://github.com/bcoe/c8/issues/582);
12
+ - ✅ Applied 🐊[**Putout**](https://github.com/coderaiser/putout) default suggestions;
13
+
14
+ Code-coverage using [Node.js' built in functionality](https://nodejs.org/dist/latest-v10.x/docs/api/cli.html#cli_node_v8_coverage_dir)
15
+ that's compatible with [Istanbul's reporters](https://istanbul.js.org/docs/advanced/alternative-reporters/).
16
+
17
+ Like [nyc](https://github.com/istanbuljs/nyc), c8 just magically works:
18
+
19
+ ```sh
20
+ npm i superc8 -g
21
+ c8 node foo.js
22
+ ```
23
+
24
+ The above example will output coverage metrics for `foo.js`.
25
+
26
+ ## CLI Options / Configuration
27
+
28
+ c8 can be configured via command-line flags, a `c8` section in `package.json`, or a JSON configuration file on disk.
29
+
30
+ A configuration file can be specified by passing its path on the command line with `--config` or `-c`. If no config option is provided, c8 searches for files named `.c8rc`, `.c8rc.json`, `.nycrc`, or `.nycrc.json`, starting from
31
+ `cwd` and walking up the filesystem tree.
32
+
33
+ When using `package.json` configuration or a dedicated configuration file, omit the `--` prefix from the long-form of the desired command-line option.
34
+
35
+ Here is a list of common options. Run `c8 --help` for the full list and documentation.
36
+
37
+ | Option | Description | Type | Default |
38
+ | ------ | ----------- | ---- | ------- |
39
+ | `-c`, `--config` | path to JSON configuration file | `string` | See above |
40
+ | `-r`, `--reporter` | coverage reporter(s) to use | `Array<string>` | `['text']` |
41
+ | `-o`, `--reports-dir`, `--report-dir` | directory where coverage reports will be output to | `string` | `./coverage` |
42
+ | `--all` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `boolean` | `false` |
43
+ | `--src` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `Array<string>` | `[process.cwd()]`|
44
+ | `-n`, `--include` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `Array<string>` | `[]` (include all files) |
45
+ | `-x`, `--exclude` | see [section below](#checking-for-full-source-coverage-using---all) for more info | `Array<string>` | [list](https://github.com/istanbuljs/schema/blob/master/default-exclude.js) |
46
+ | `--exclude-after-remap` | see [section below](#exclude-after-remap) for more info | `boolean` | `false` |
47
+ | `-e`, `--extension` | only files matching these extensions will show coverage | `string \| Array<string>` | [list](https://github.com/istanbuljs/schema/blob/master/default-extension.js) |
48
+ | `--skip-full` | do not show files with 100% statement, branch, and function coverage | `boolean` | `false` |
49
+ | `--check-coverage` | check whether coverage is within thresholds provided | `boolean` | `false` |
50
+ | `--per-file` | check thresholds per file | `boolean` | `false` |
51
+ | `--temp-directory` | directory V8 coverage data is written to and read from | `string` | `process.env.NODE_V8_COVERAGE` |
52
+ | `--clean` | should temp files be deleted before script execution | `boolean` | `true` |
53
+ | `--experimental-monocart` | see [section below](#using-monocart-coverage-reports-experimental) for more info | `boolean` | `false` |
54
+
55
+ ## Checking for "full" source coverage using `--all`
56
+
57
+ By default v8 will only give us coverage for files that were loaded by the engine. If there are source files in your
58
+ project that are flexed in production but not in your tests, your coverage numbers will not reflect this. For example,
59
+ if your project's `main.js` loads `a.js` and `b.js` but your unit tests only load `a.js` your total coverage
60
+ could show as `100%` for `a.js` when in fact both `main.js` and `b.js` are uncovered.
61
+
62
+ By supplying `--all` to c8, all files in directories specified with `--src` (defaults to `cwd`) that pass the `--include`
63
+ and `--exclude` flag checks, will be loaded into the report. If any of those files remain uncovered they will be factored
64
+ into the report with a default of 0% coverage.
65
+
66
+ ## SourceMap Support
67
+
68
+ `c8` can handle source-maps, for remapping coverage from generated code to original source files (*useful for TypeScript, JSX, etc*).
69
+
70
+ ### Source map files versus inline source maps
71
+
72
+ Just-in-time instrumented codebases will often insert source maps inline with the `.js` code they generate at runtime (e.g, `@babel/register` can be configured to insert a source map footer).
73
+
74
+ Pre-instrumented codebases, e.g., running `tsc` to generate `.js` in a build folder, may generate either inline source maps, or a separate `.map` file stored on disk.
75
+
76
+ `c8` can handle loading both types of source maps.
77
+
78
+ ### Exclude after remap
79
+
80
+ Depending on the size and configuration of your project, it may be preferable to apply exclusion logic either before or after source-maps are used to remap compiled to original source files.
81
+
82
+ `--exclude-after-remap` is used to control this behaviour.
83
+
84
+ ## c8 report
85
+
86
+ run `c8 report` to regenerate reports after `c8` has already been run.
87
+
88
+ ## Checking coverage
89
+
90
+ c8 can fail tests if coverage falls below a threshold.
91
+ After running your tests with c8, simply run:
92
+
93
+ ```sh
94
+ c8 check-coverage --lines 95 --functions 95 --branches 95
95
+ ```
96
+
97
+ c8 also accepts a `--check-coverage` shorthand, which can be used to
98
+ both run tests and check that coverage falls within the threshold provided:
99
+
100
+ ```sh
101
+ c8 --check-coverage --lines 100 npm test
102
+ ```
103
+
104
+ The above check fails if coverage falls below 100%.
105
+
106
+ To check thresholds on a per-file basis run:
107
+
108
+ ```sh
109
+ c8 check-coverage --lines 95 --per-file
110
+ ```
111
+
112
+ If you want to check for 100% coverage across all dimensions, use `--100`:
113
+
114
+ ```sh
115
+ c8 --100 npm test
116
+ ```
117
+
118
+ Is equivalent to
119
+
120
+ ```sh
121
+ c8 --check-coverage --lines 100 --functions 100 --branches 100 --statements 100 npm test
122
+ ```
123
+
124
+ The `--100` flag can be set for the `check-coverage` as well:
125
+
126
+ ```sh
127
+ c8 check-coverage --100
128
+ ```
129
+
130
+ ## Using Monocart coverage reports (experimental)
131
+
132
+ Monocart is an alternate library for outputting [v8 code coverage](https://v8.dev/blog/javascript-code-coverage) data as Istanbul reports.
133
+
134
+ Monocart also provides reporters based directly on v8's byte-offset-based output. Such as, `console-details` and `v8`. This removes a complex transformation step and may be less bug prone for some environments.
135
+
136
+ **Example usage:**
137
+
138
+ ```sh
139
+ c8 --experimental-monocart --reporter=v8 --reporter=console-details node foo.js
140
+ ```
141
+
142
+ NOTE: Monocart requires additional `monocart-coverage-reports` to be installed:
143
+
144
+ ```sh
145
+ npm i monocart-coverage-reports@2 --save-dev
146
+ ```
147
+
148
+ ## Ignoring Uncovered Lines, Functions, and Blocks
149
+
150
+ Sometimes you might find yourself wanting to ignore uncovered portions of your
151
+ codebase. For example, perhaps you run your tests on Linux, but
152
+ there's some logic that only executes on Windows.
153
+
154
+ To ignore lines, blocks, and functions, use the special comment:
155
+
156
+ `/* c8 ignore next */`.
157
+
158
+ ### Ignoring the next line
159
+
160
+ ```js
161
+ const myVariable = 99;
162
+
163
+ /* c8 ignore next */
164
+ if (process.platform === 'win32')
165
+ console.info('hello world');
166
+ ```
167
+
168
+ ### Ignoring the next N lines
169
+
170
+ ```js
171
+ const myVariable = 99;
172
+
173
+ /* c8 ignore next 3 */
174
+ if (process.platform === 'win32') {
175
+ console.info('hello world');
176
+ }
177
+ ```
178
+
179
+ ### Ignoring all lines until told
180
+
181
+ ```js
182
+ /* c8 ignore start */
183
+ function dontMindMe() {
184
+ // ...
185
+ } /* c8 ignore stop */
186
+ ```
187
+
188
+ ### Ignoring a block on the current line
189
+
190
+ ```js
191
+ const myVariable = 99;
192
+ const os = process.platform === 'darwin' ? 'OSXy' /* c8 ignore next */ : 'Windowsy';
193
+ ```
194
+
195
+ ## Supported Node.js Versions
196
+
197
+ c8 uses [native V8 coverage](https://github.com/nodejs/node/pull/22527),
198
+ make sure you're running Node.js `>= 22`.
199
+
200
+ ## Contributing to `c8`
201
+
202
+ See the [contributing guide here](./CONTRIBUTING.md).
203
+
204
+ ## License
205
+
206
+ MIT
package/bin/c8.js ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+
3
+ import {rm, mkdir} from 'node:fs/promises';
4
+ import process from 'node:process';
5
+ import {foregroundChild} from 'foreground-child';
6
+ import {tryToCatch} from 'try-to-catch';
7
+ import {outputReport} from '../lib/commands/report.js';
8
+ import {
9
+ buildYargs,
10
+ hideInstrumenteeArgs,
11
+ hideInstrumenterArgs,
12
+ } from '../lib/parse-args.js';
13
+
14
+ const instrumenterArgs = hideInstrumenteeArgs();
15
+ let argv = buildYargs().parse(instrumenterArgs);
16
+
17
+ const [error] = await tryToCatch(run);
18
+
19
+ if (error) {
20
+ console.error(error.stack);
21
+ process.exitCode = 1;
22
+ }
23
+
24
+ async function run() {
25
+ if ([
26
+ 'check-coverage',
27
+ 'report',
28
+ ].includes(argv._[0])) {
29
+ argv = buildYargs(true).parse(process.argv.slice(2));
30
+ } else {
31
+ if (argv.clean)
32
+ await rm(argv.tempDirectory, {
33
+ recursive: true,
34
+ force: true,
35
+ });
36
+
37
+ await mkdir(argv.tempDirectory, {
38
+ recursive: true,
39
+ });
40
+ process.env.NODE_V8_COVERAGE = argv.tempDirectory;
41
+ foregroundChild(hideInstrumenterArgs(argv), async () => {
42
+ try {
43
+ await outputReport(argv);
44
+ return process.exitCode;
45
+ } catch(err) {
46
+ console.error(err.stack);
47
+ return 1;
48
+ }
49
+ });
50
+ }
51
+ }
package/index.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ export type Watermark = [
2
+ number,
3
+ number,
4
+ ];
5
+
6
+ export declare class Report {
7
+ constructor(opts: {
8
+ exclude?: string | string[];
9
+ extension?: string | string[];
10
+ excludeAfterRemap?: boolean;
11
+ include?: string | string[];
12
+ reporter: string[];
13
+ reportsDirectory?: string;
14
+ reporterOptions?: Record<string, Record<string, unknown>>;
15
+ tempDirectory?: string;
16
+ watermarks?: Partial<{
17
+ statements: Watermark;
18
+ functions: Watermark;
19
+ branches: Watermark;
20
+ lines: Watermark;
21
+ }>;
22
+ omitRelative?: boolean;
23
+ wrapperLength?: number;
24
+ resolve?: string;
25
+ all?: boolean;
26
+ src?: string[];
27
+ allowExternal?: boolean;
28
+ skipFull?: boolean;
29
+ excludeNodeModules?: boolean;
30
+ });
31
+ run(): Promise<void>;
32
+ }
package/index.js ADDED
@@ -0,0 +1 @@
1
+ export * as Report from './lib/report.js';
@@ -0,0 +1,83 @@
1
+ import {relative} from 'node:path';
2
+ import process from 'node:process';
3
+ import {Report} from '../report.js';
4
+
5
+ const {isArray} = Array;
6
+ const maybeArray = (a) => isArray(a) ? a : [a];
7
+ const consoleError = console.error;
8
+
9
+ export const command = 'check-coverage';
10
+
11
+ export const describe = 'check whether coverage is within thresholds provided';
12
+
13
+ export const builder = function(yargs) {
14
+ yargs.example('$0 check-coverage --lines 95', `check whether the JSON in c8's output folder meets the thresholds provided`);
15
+ };
16
+
17
+ export const handler = function(argv) {
18
+ // TODO: this is a workaround until yargs gets upgraded to v17, see https://github.com/bcoe/c8/pull/332#discussion_r721636191
19
+ if (argv['100']) {
20
+ argv.lines = 100;
21
+ argv.functions = 100;
22
+ argv.branches = 100;
23
+ argv.statements = 100;
24
+ }
25
+
26
+ const report = Report({
27
+ include: argv.include,
28
+ exclude: argv.exclude,
29
+ extension: argv.extension,
30
+ reporter: maybeArray(argv.reporter),
31
+ reportsDirectory: argv['reports-dir'],
32
+ tempDirectory: argv.tempDirectory,
33
+ watermarks: argv.watermarks,
34
+ resolve: argv.resolve,
35
+ omitRelative: argv.omitRelative,
36
+ wrapperLength: argv.wrapperLength,
37
+ all: argv.all,
38
+ });
39
+
40
+ checkCoverages(argv, report);
41
+ };
42
+
43
+ export const checkCoverages = async function(argv, report) {
44
+ const thresholds = {
45
+ lines: argv.lines,
46
+ functions: argv.functions,
47
+ branches: argv.branches,
48
+ statements: argv.statements,
49
+ };
50
+
51
+ const map = await report.getCoverageMapFromAllCoverageFiles();
52
+
53
+ if (argv.perFile)
54
+ for (const file of map.files()) {
55
+ checkCoverage(
56
+ map
57
+ .fileCoverageFor(file)
58
+ .toSummary(),
59
+ thresholds,
60
+ file,
61
+ );
62
+ }
63
+
64
+ else
65
+ checkCoverage(map.getCoverageSummary(), thresholds);
66
+ };
67
+
68
+ function checkCoverage(summary, thresholds, file) {
69
+ for (const key of Object.keys(thresholds)) {
70
+ const coverage = summary[key].pct;
71
+
72
+ if (coverage < thresholds[key]) {
73
+ process.exitCode = 1;
74
+
75
+ if (file) {
76
+ // standardize path for Windows.
77
+ consoleError('ERROR: Coverage for ' + key + ' (' + coverage + '%) does not meet threshold (' + thresholds[key] + '%) for ' + relative('./', file).replace(/\\/g, '/'));
78
+ } else {
79
+ consoleError('ERROR: Coverage for ' + key + ' (' + coverage + '%) does not meet global threshold (' + thresholds[key] + '%)');
80
+ }
81
+ }
82
+ }
83
+ }
@@ -0,0 +1,43 @@
1
+ import process from 'node:process';
2
+ import {checkCoverages} from './check-coverage.js';
3
+ import {Report} from '../report.js';
4
+
5
+ const {isArray} = Array;
6
+ const maybeArray = (a) => isArray(a) ? a : [a];
7
+
8
+ export const command = 'report';
9
+
10
+ export const describe = 'read V8 coverage data from temp and output report';
11
+
12
+ export const handler = async function(argv) {
13
+ await outputReport(argv);
14
+ };
15
+
16
+ export const outputReport = async function(argv) {
17
+ const report = Report({
18
+ include: argv.include,
19
+ exclude: argv.exclude,
20
+ extension: argv.extension,
21
+ excludeAfterRemap: argv.excludeAfterRemap,
22
+ reporter: maybeArray(argv.reporter),
23
+ reportsDirectory: argv['reports-dir'],
24
+ reporterOptions: argv.reporterOptions || {},
25
+ tempDirectory: argv.tempDirectory,
26
+ watermarks: argv.watermarks,
27
+ resolve: argv.resolve,
28
+ omitRelative: argv.omitRelative,
29
+ wrapperLength: argv.wrapperLength,
30
+ all: argv.all,
31
+ allowExternal: argv.allowExternal,
32
+ src: argv.src,
33
+ skipFull: argv.skipFull,
34
+ excludeNodeModules: argv.excludeNodeModules,
35
+ mergeAsync: argv.mergeAsync,
36
+ monocartArgv: argv.experimentalMonocart || process.env.EXPERIMENTAL_MONOCART ? argv : null,
37
+ });
38
+
39
+ await report.run();
40
+
41
+ if (argv.checkCoverage)
42
+ await checkCoverages(argv, report);
43
+ };
@@ -0,0 +1,229 @@
1
+ import {readFileSync} from 'node:fs';
2
+ import {resolve} from 'node:path';
3
+ import process from 'node:process';
4
+ import defaultExclude from '@istanbuljs/schema/default-exclude.js';
5
+ import defaultExtension from '@istanbuljs/schema/default-extension.js';
6
+ import {findUpSync} from 'find-up';
7
+ import Yargs from 'yargs/yargs';
8
+ import {applyExtends} from 'yargs/helpers';
9
+ import parser from 'yargs-parser';
10
+ import * as checkCoverage from './commands/check-coverage.js';
11
+ import * as report from './commands/report.js';
12
+
13
+ export function buildYargs(withCommands = false) {
14
+ const yargs = Yargs([])
15
+ .usage('$0 [opts] [script] [opts]')
16
+ .options('config', {
17
+ alias: 'c',
18
+ config: true,
19
+ describe: 'path to JSON configuration file',
20
+ configParser: (path) => {
21
+ const config = JSON.parse(readFileSync(path));
22
+ return applyExtends(config, process.cwd(), true);
23
+ },
24
+ default: () => findUpSync([
25
+ '.c8rc',
26
+ '.c8rc.json',
27
+ '.nycrc',
28
+ '.nycrc.json',
29
+ ]),
30
+ })
31
+ .option('reporter', {
32
+ alias: 'r',
33
+ group: 'Reporting options',
34
+ describe: 'coverage reporter(s) to use',
35
+ default: 'text',
36
+ })
37
+ .option('reports-dir', {
38
+ alias: ['o', 'report-dir'],
39
+ group: 'Reporting options',
40
+ describe: 'directory where coverage reports will be output to',
41
+ default: './coverage',
42
+ })
43
+ .options('all', {
44
+ default: false,
45
+ type: 'boolean',
46
+ group: 'Reporting options',
47
+ describe: 'supplying --all will cause c8 to consider all src files in the current working directory ' + 'when the determining coverage. Respects include/exclude.',
48
+ })
49
+ .options('src', {
50
+ default: undefined,
51
+ type: 'string',
52
+ group: 'Reporting options',
53
+ describe: 'supplying --src will override cwd as the default location where --all looks for src files. --src can be ' + 'supplied multiple times and each directory will be included. This allows for workspaces spanning multiple projects',
54
+ })
55
+ .option('exclude-node-modules', {
56
+ default: true,
57
+ type: 'boolean',
58
+ describe: 'whether or not to exclude all node_module folders (i.e. **/node_modules/**) by default',
59
+ })
60
+ .option('include', {
61
+ alias: 'n',
62
+ default: [],
63
+ group: 'Reporting options',
64
+ describe: 'a list of specific files that should be covered (glob patterns are supported)',
65
+ })
66
+ .option('exclude', {
67
+ alias: 'x',
68
+ default: defaultExclude,
69
+ group: 'Reporting options',
70
+ describe: 'a list of specific files and directories that should be excluded from coverage (glob patterns are supported)',
71
+ })
72
+ .option('extension', {
73
+ alias: 'e',
74
+ default: defaultExtension,
75
+ group: 'Reporting options',
76
+ describe: 'a list of specific file extensions that should be covered',
77
+ })
78
+ .option('exclude-after-remap', {
79
+ alias: 'a',
80
+ type: 'boolean',
81
+ default: false,
82
+ group: 'Reporting options',
83
+ describe: 'apply exclude logic to files after they are remapped by a source-map',
84
+ })
85
+ .options('skip-full', {
86
+ default: false,
87
+ type: 'boolean',
88
+ group: 'Reporting options',
89
+ describe: 'do not show files with 100% statement, branch, and function coverage',
90
+ })
91
+ .option('check-coverage', {
92
+ default: false,
93
+ type: 'boolean',
94
+ group: 'Coverage thresholds',
95
+ description: 'check whether coverage is within thresholds provided',
96
+ })
97
+ .option('branches', {
98
+ default: 0,
99
+ group: 'Coverage thresholds',
100
+ description: 'what % of branches must be covered?',
101
+ type: 'number',
102
+ })
103
+ .option('functions', {
104
+ default: 0,
105
+ group: 'Coverage thresholds',
106
+ description: 'what % of functions must be covered?',
107
+ type: 'number',
108
+ })
109
+ .option('lines', {
110
+ default: 90,
111
+ group: 'Coverage thresholds',
112
+ description: 'what % of lines must be covered?',
113
+ type: 'number',
114
+ })
115
+ .option('statements', {
116
+ default: 0,
117
+ group: 'Coverage thresholds',
118
+ description: 'what % of statements must be covered?',
119
+ type: 'number',
120
+ })
121
+ .option('per-file', {
122
+ default: false,
123
+ group: 'Coverage thresholds',
124
+ description: 'check thresholds per file',
125
+ type: 'boolean',
126
+ })
127
+ .option('100', {
128
+ default: false,
129
+ group: 'Coverage thresholds',
130
+ description: 'shortcut for --check-coverage --lines 100 --functions 100 --branches 100 --statements 100',
131
+ type: 'boolean',
132
+ })
133
+ .option('temp-directory', {
134
+ describe: 'directory V8 coverage data is written to and read from',
135
+ default: process.env.NODE_V8_COVERAGE,
136
+ })
137
+ .option('clean', {
138
+ default: true,
139
+ type: 'boolean',
140
+ describe: 'should temp files be deleted before script execution',
141
+ })
142
+ .option('resolve', {
143
+ default: '',
144
+ describe: 'resolve paths to alternate base directory',
145
+ })
146
+ .option('wrapper-length', {
147
+ describe: 'how many bytes is the wrapper prefix on executed JavaScript',
148
+ type: 'number',
149
+ })
150
+ .option('omit-relative', {
151
+ default: true,
152
+ type: 'boolean',
153
+ describe: 'omit any paths that are not absolute, e.g., internal/net.js',
154
+ })
155
+ .options('allowExternal', {
156
+ default: false,
157
+ type: 'boolean',
158
+ describe: 'supplying --allowExternal will cause c8 to allow files from outside of your cwd. This applies both to ' + 'files discovered in coverage temp files and also src files discovered if using the --all flag.',
159
+ })
160
+ .options('merge-async', {
161
+ default: false,
162
+ type: 'boolean',
163
+ describe: 'supplying --merge-async will merge all v8 coverage reports asynchronously and incrementally. ' + 'This is to avoid OOM issues with Node.js runtime.',
164
+ })
165
+ .option('experimental-monocart', {
166
+ default: false,
167
+ type: 'boolean',
168
+ describe: 'Use Monocart coverage reports',
169
+ })
170
+ .pkgConf('c8')
171
+ .demandCommand(1)
172
+ .check((argv) => {
173
+ if (!argv.tempDirectory)
174
+ argv.tempDirectory = resolve(argv.reportsDir, 'tmp');
175
+
176
+ return true;
177
+ })
178
+ .epilog('visit https://git.io/vHysA for list of available reporters');
179
+
180
+ yargs.middleware((argv) => {
181
+ if (!argv['100'])
182
+ return argv;
183
+
184
+ return {
185
+ ...argv,
186
+ branches: 100,
187
+ functions: 100,
188
+ lines: 100,
189
+ statements: 100,
190
+ checkCoverage: 100,
191
+ };
192
+ });
193
+
194
+ if (withCommands) {
195
+ yargs.command(checkCoverage);
196
+ yargs.command(report);
197
+ } else {
198
+ yargs.command(checkCoverage.command, checkCoverage.describe);
199
+ yargs.command(report.command, report.describe);
200
+ }
201
+
202
+ return yargs;
203
+ }
204
+
205
+ export function hideInstrumenterArgs(yargv) {
206
+ let argv = process.argv.slice(1);
207
+
208
+ argv = argv.slice(argv.indexOf(yargv._[0]));
209
+
210
+ if (argv[0][0] === '-')
211
+ argv.unshift(process.execPath);
212
+
213
+ return argv;
214
+ }
215
+
216
+ export function hideInstrumenteeArgs() {
217
+ let argv = process.argv.slice(2);
218
+ const yargv = parser(argv);
219
+
220
+ if (!yargv._.length)
221
+ return argv;
222
+
223
+ // drop all the arguments after the bin being
224
+ // instrumented by c8.
225
+ argv = argv.slice(0, argv.indexOf(yargv._[0]));
226
+ argv.push(yargv._[0]);
227
+
228
+ return argv;
229
+ }