From 27be6aaae82292c13548a1820c0f0732583e77f0 Mon Sep 17 00:00:00 2001 From: nimrod-becker Date: Wed, 20 Apr 2016 08:21:17 +0300 Subject: [PATCH] Provide an option to skip path resolution --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index c2cf412..ecc04a3 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ var through = require('through2').obj; var path = require('path'); var checker = require('istanbul-threshold-checker'); -// Make sure istanbul is `require`d after the istanbul-threshold-checker to use the istanbul version +// Make sure istanbul is `require`d after the istanbul-threshold-checker to use the istanbul version // defined in this package.json instead of the one defined in istanbul-threshold-checker. var istanbul = require('istanbul'); var gutil = require('gulp-util'); @@ -22,6 +22,7 @@ var plugin = module.exports = function (opts) { instrumenter: istanbul.Instrumenter }); opts.includeUntested = opts.includeUntested === true; + opts.resolveAbsolutePaths = opts.resolveAbsolutePaths === true; var instrumenter = new opts.instrumenter(opts); @@ -31,6 +32,10 @@ var plugin = module.exports = function (opts) { return cb(new PluginError(PLUGIN_NAME, 'streams not supported')); } + if (opts.resolveAbsolutePaths) { + file.path = path.resolve(file.path); + } + instrumenter.instrument(file.contents.toString(), file.path, function (err, code) { if (err) { return cb(new PluginError( @@ -52,7 +57,7 @@ var plugin = module.exports = function (opts) { if (covStubMatch !== null) { var covStub = JSON.parse(covStubMatch[0]); global[opts.coverageVariable] = global[opts.coverageVariable] || {}; - global[opts.coverageVariable][path.resolve(file.path)] = covStub; + global[opts.coverageVariable][file.path] = covStub; } }