diff --git a/index.js b/index.js
index 3ebf3555c..d0c0de4f4 100755
--- a/index.js
+++ b/index.js
@@ -212,7 +212,7 @@ class NYC {
}
async instrumentAllFiles (input, output) {
- let inputDir = '.' + path.sep
+ const inputDir = path.resolve(this.cwd, input)
const visitor = async relFile => {
const inFile = path.resolve(inputDir, relFile)
const inCode = await fs.readFile(inFile, 'utf-8')
@@ -232,21 +232,19 @@ class NYC {
this._loadAdditionalModules()
- const stats = await fs.lstat(input)
+ const stats = await fs.lstat(inputDir)
if (stats.isDirectory()) {
- inputDir = input
-
- const filesToInstrument = await this.exclude.glob(input)
+ const filesToInstrument = await this.exclude.glob(inputDir)
const concurrency = output ? os.cpus().length : 1
if (this.config.completeCopy && output) {
- const files = await glob(path.resolve(input, '**'), {
+ const files = await glob(path.resolve(inputDir, '**'), {
dot: true,
nodir: true,
ignore: ['**/.git', '**/.git/**', path.join(output, '**')]
})
const destDirs = new Set(
- files.map(src => path.dirname(path.join(output, path.relative(input, src))))
+ files.map(src => path.dirname(path.join(output, path.relative(inputDir, src))))
)
await pMap(
@@ -256,14 +254,14 @@ class NYC {
)
await pMap(
files,
- src => fs.copyFile(src, path.join(output, path.relative(input, src))),
+ src => fs.copyFile(src, path.join(output, path.relative(inputDir, src))),
{ concurrency }
)
}
await pMap(filesToInstrument, visitor, { concurrency })
} else {
- await visitor(input)
+ await visitor(inputDir)
}
}
@@ -294,7 +292,7 @@ class NYC {
return (code, metadata, hash) => {
const filename = metadata.filename
- const sourceMap = this._getSourceMap(code, filename, hash)
+ const sourceMap = this._getSourceMap(code, path.resolve(this.cwd, filename), hash)
try {
instrumented = instrumenter.instrumentSync(code, filename, sourceMap)
diff --git a/lib/commands/instrument.js b/lib/commands/instrument.js
index cabb43775..cb350e115 100644
--- a/lib/commands/instrument.js
+++ b/lib/commands/instrument.js
@@ -24,6 +24,7 @@ exports.handler = cliWrapper(async argv => {
throw new Error('cannot instrument files in place, must differ from