1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
| var NYC
| try {
| NYC = require('../../index.covered.js')
| } catch (e) {
| NYC = require('../../index.js')
| }
|
| exports.command = 'instrument <input> [output]'
|
| exports.describe = 'instruments a file or a directory tree and writes the instrumented code to the desired output location'
|
| exports.builder = function (yargs) {
| return yargs
| .option('require', {
| alias: 'i',
| default: [],
| describe: 'a list of additional modules that nyc should attempt to require in its subprocess, e.g., @babel/register, @babel/polyfill.'
| })
| .option('extension', {
| alias: 'e',
| default: [],
| describe: 'a list of extensions that nyc should handle in addition to .js'
| })
| .option('source-map', {
| default: true,
| type: 'boolean',
| description: 'should nyc detect and handle source maps?'
| })
| .option('produce-source-map', {
| default: false,
| type: 'boolean',
| description: "should nyc's instrumenter produce source maps?"
| })
| .option('compact', {
| default: true,
| type: 'boolean',
| description: 'should the output be compacted?'
| })
| .option('preserve-comments', {
| default: true,
| type: 'boolean',
| description: 'should comments be preserved in the output?'
| })
| .option('instrument', {
| default: true,
| type: 'boolean',
| description: 'should nyc handle instrumentation?'
| })
| .option('exit-on-error', {
| default: false,
| type: 'boolean',
| description: 'should nyc exit when an instrumentation failure occurs?'
| })
| .example('$0 instrument ./lib ./output', 'instrument all .js files in ./lib with coverage and output in ./output')
| }
|
| exports.handler = function (argv) {
| // if instrument is set to false,
| // enable a noop instrumenter.
| if (!argv.instrument) argv.instrumenter = './lib/instrumenters/noop'
| else argv.instrumenter = './lib/instrumenters/istanbul'
|
| var nyc = new NYC({
| instrumenter: argv.instrumenter,
| sourceMap: argv.sourceMap,
| produceSourceMap: argv.produceSourceMap,
| extension: argv.extension,
| require: argv.require,
| compact: argv.compact,
| preserveComments: argv.preserveComments,
| exitOnError: argv.exitOnError
| })
|
| nyc.instrumentAllFiles(argv.input, argv.output, function (err) {
| if (err) {
| console.error(err.message)
| process.exit(1)
| } else {
| process.exit(0)
| }
| })
| }
|
|