From 3de655b70c500ca0e666f40fbe0650090ce5e679 Mon Sep 17 00:00:00 2001 From: Filip Gurbal Date: Fri, 19 Aug 2022 15:18:14 +0200 Subject: [PATCH] make input relative to --cwd path --- index.js | 18 ++++++++---------- lib/commands/instrument.js | 3 ++- 2 files changed, 10 insertions(+), 11 deletions(-) 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 . Set \'--in-place\' to force') } + argv.cwd = path.resolve(argv.cwd) if (path.relative(argv.cwd, path.resolve(argv.cwd, argv.input)).startsWith('..')) { throw new Error('cannot instrument files outside project root directory') } @@ -47,7 +48,7 @@ exports.handler = cliWrapper(async argv => { : './lib/instrumenters/noop' if (argv.inPlace) { - argv.output = argv.input + argv.output = path.join(argv.cwd, argv.input) argv.completeCopy = false }