diff --git a/docs/instrument.md b/docs/instrument.md
index af19b6daa..bce1a3b4c 100644
--- a/docs/instrument.md
+++ b/docs/instrument.md
@@ -20,6 +20,8 @@ For example, `nyc instrument . ./output` will produce instrumented versions of a
The `--delete` option will remove the existing output directory before instrumenting.
+The `--in-place` option will allow you to run the instrument command.
+
The `--complete-copy` option will copy all remaining files from the `input` directory to the `output` directory.
When using `--complete-copy` nyc will not copy the contents of a `.git` folder to the output directory.
@@ -27,8 +29,8 @@ When using `--complete-copy` nyc will not copy the contents of a `.git` folder t
## Streaming instrumentation
-`nyc instrument` will stream instrumented source directly to `stdout`, that can then be piped to another process.
-You can use this behaviour to create a server that can instrument files on request.
+`nyc instrument ` will stream instrumented source directly to `stdout` and that output can then be piped to another process.
+You can use this behaviour to create a server that dynamically instruments files on request.
The following example shows streaming instrumentation middleware capable of instrumenting files on request.
```javascript
diff --git a/lib/commands/instrument.js b/lib/commands/instrument.js
index 553a1af7b..541878b2c 100644
--- a/lib/commands/instrument.js
+++ b/lib/commands/instrument.js
@@ -31,32 +31,37 @@ exports.builder = function (yargs) {
.option('source-map', {
default: true,
type: 'boolean',
- description: 'should nyc detect and handle source maps?'
+ describe: 'should nyc detect and handle source maps?'
})
.option('produce-source-map', {
default: false,
type: 'boolean',
- description: "should nyc's instrumenter produce source maps?"
+ describe: "should nyc's instrumenter produce source maps?"
})
.option('compact', {
default: true,
type: 'boolean',
- description: 'should the output be compacted?'
+ describe: 'should the output be compacted?'
})
.option('preserve-comments', {
default: true,
type: 'boolean',
- description: 'should comments be preserved in the output?'
+ describe: 'should comments be preserved in the output?'
})
.option('instrument', {
default: true,
type: 'boolean',
- description: 'should nyc handle instrumentation?'
+ describe: 'should nyc handle instrumentation?'
+ })
+ .option('in-place', {
+ default: false,
+ type: 'boolean',
+ describe: 'should nyc run the instrumentation in place?'
})
.option('exit-on-error', {
default: false,
type: 'boolean',
- description: 'should nyc exit when an instrumentation failure occurs?'
+ describe: 'should nyc exit when an instrumentation failure occurs?'
})
.option('include', {
alias: 'n',
@@ -92,17 +97,22 @@ exports.builder = function (yargs) {
.example('$0 instrument ./lib ./output', 'instrument all .js files in ./lib with coverage and output in ./output')
}
+const errorExit = msg => {
+ console.error(`nyc instrument failed: ${msg}`)
+ process.exitCode = 1
+}
+
exports.handler = function (argv) {
- if (argv.output && (path.resolve(argv.cwd, argv.input) === path.resolve(argv.cwd, argv.output))) {
- console.error(`nyc instrument failed: cannot instrument files in place, must differ from