From c454b56d70d88b3221bdd218607c60f02328f69a Mon Sep 17 00:00:00 2001 From: Andrew Finlay Date: Tue, 19 Mar 2019 12:16:01 +1100 Subject: [PATCH] Address review issues All changed, so all this does now is propagate `cwd` so that it can influence `testExclude` and `require` path settings. --- index.js | 11 +++++------ lib/commands/instrument.js | 5 ----- test/nyc-integration.js | 36 ------------------------------------ 3 files changed, 5 insertions(+), 47 deletions(-) diff --git a/index.js b/index.js index 15f1582e2..43e20884b 100755 --- a/index.js +++ b/index.js @@ -179,7 +179,7 @@ NYC.prototype.addAllFiles = function () { NYC.prototype.instrumentAllFiles = function (input, output, cb) { let inputDir = '.' + path.sep const visitor = filename => { - const inFile = path.resolve(this.cwd, inputDir, filename) + const inFile = path.resolve(inputDir, filename) const inCode = fs.readFileSync(inFile, 'utf-8') const extname = path.extname(filename).toLowerCase() @@ -187,7 +187,7 @@ NYC.prototype.instrumentAllFiles = function (input, output, cb) { const outCode = transform(inCode, { filename: inFile }) if (output) { - const outFile = path.resolve(this.cwd, output, filename) + const outFile = path.resolve(output, filename) mkdirp.sync(path.dirname(outFile)) fs.writeFileSync(outFile, outCode, 'utf-8') } else { @@ -198,11 +198,10 @@ NYC.prototype.instrumentAllFiles = function (input, output, cb) { this._loadAdditionalModules() try { - const inputPath = path.resolve(this.cwd, input) - const stats = fs.lstatSync(inputPath) + const stats = fs.lstatSync(input) if (stats.isDirectory()) { - inputDir = inputPath - this.walkAllFiles(inputPath, visitor) + inputDir = input + this.walkAllFiles(input, visitor) } else { visitor(input) } diff --git a/lib/commands/instrument.js b/lib/commands/instrument.js index 325713cf5..1820c5837 100644 --- a/lib/commands/instrument.js +++ b/lib/commands/instrument.js @@ -7,7 +7,6 @@ exports.command = 'instrument [output]' exports.describe = 'instruments a file or a directory tree and writes the instrumented code to the desired output location' exports.builder = function (yargs) { - const cwd = process.cwd() return yargs .option('require', { alias: 'i', @@ -29,10 +28,6 @@ exports.builder = function (yargs) { type: 'boolean', description: "should nyc's instrumenter produce source maps?" }) - .option('cwd', { - describe: 'working directory used when resolving paths', - default: cwd - }) .option('compact', { default: true, type: 'boolean', diff --git a/test/nyc-integration.js b/test/nyc-integration.js index 1fa30d6ba..8124f671d 100644 --- a/test/nyc-integration.js +++ b/test/nyc-integration.js @@ -606,42 +606,6 @@ describe('the nyc cli', function () { }) }) - it('works with a different working directory', function (done) { - const subdir = path.resolve(fixturesCLI, 'subdir') - const args = [bin, 'instrument', '--cwd', subdir, './input-dir', './output-dir'] - - const proc = spawn(process.execPath, args, { - cwd: fixturesCLI, - env: env - }) - - proc.on('exit', code => { - code.should.equal(0) - const target = path.resolve(subdir, 'output-dir', 'index.js') - fs.readFileSync(target, 'utf8') - .should.match(/console.log\('Hello, World!'\)/) - done() - }) - }) - - it('works with a deep folder structure working directory', function (done) { - const subdir = path.resolve(fixturesCLI, 'subdir') - const args = [bin, 'instrument', '--cwd', subdir, '.', './output-dir'] - - const proc = spawn(process.execPath, args, { - cwd: fixturesCLI, - env: env - }) - - proc.on('exit', code => { - code.should.equal(0) - const target = path.resolve(subdir, 'output-dir', 'input-dir', 'index.js') - fs.readFileSync(target, 'utf8') - .should.match(/console.log\('Hello, World!'\)/) - done() - }) - }) - it('can be configured to exit on error', function (done) { var args = [ bin,