diff --git a/index.js b/index.js
index 638b50015..00e6cc81f 100755
--- a/index.js
+++ b/index.js
@@ -179,9 +179,11 @@ NYC.prototype.instrumentAllFiles = function (input, output, cb) {
const outCode = this._transform(inCode, inFile) || inCode
if (output) {
+ const mode = fs.statSync(inFile).mode
const outFile = path.resolve(output, relFile)
mkdirp.sync(path.dirname(outFile))
- fs.writeFileSync(outFile, outCode, 'utf-8')
+ fs.writeFileSync(outFile, outCode)
+ fs.chmodSync(outFile, mode)
} else {
console.log(outCode)
}
diff --git a/lib/commands/instrument.js b/lib/commands/instrument.js
index 1820c5837..3c0fe9d3b 100644
--- a/lib/commands/instrument.js
+++ b/lib/commands/instrument.js
@@ -1,6 +1,7 @@
const NYC = require('../../index.js')
const path = require('path')
const rimraf = require('rimraf')
+const testExclude = require('test-exclude')
exports.command = 'instrument [output]'
@@ -48,6 +49,16 @@ exports.builder = function (yargs) {
type: 'boolean',
description: 'should nyc exit when an instrumentation failure occurs?'
})
+ .option('include', {
+ alias: 'n',
+ default: [],
+ describe: 'a list of specific files and directories that should be instrumented, glob patterns are supported'
+ })
+ .option('exclude', {
+ alias: 'x',
+ default: testExclude.defaultExclude,
+ describe: 'a list of specific files and directories that should not be instrumented, glob patterns are supported'
+ })
.option('es-modules', {
default: true,
type: 'boolean',
@@ -62,6 +73,28 @@ exports.builder = function (yargs) {
}
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