Comparing version 0.1.1 to 0.2.0
35
index.js
@@ -7,3 +7,3 @@ var Module = require('module'); | ||
filename = filename.replace(/\\/g, '\\\\'); | ||
if (!~filename.indexOf(addCoverage.subdir)) { | ||
if (!eligibleForCoverage(filename)) { | ||
return code; | ||
@@ -17,3 +17,7 @@ } | ||
if (lines.length > 0) { | ||
lines[0] = 'if (!__cov["' + filename + '"]) {__cov["' + filename + '"] = { 0: 1}; }' + lines[0]; | ||
if (lines[0].match(/use strict/)) { | ||
lines[0] = lines[0] + ' if (!__cov["' + filename + '"]) {__cov["' + filename + '"] = { 0: 1}; }'; | ||
} else { | ||
lines[0] = 'if (!__cov["' + filename + '"]) {__cov["' + filename + '"] = { 0: 1}; }' + lines[0]; | ||
} | ||
} | ||
@@ -33,2 +37,15 @@ | ||
var eligibleForCoverage = exports.eligibleForCoverage = function (filename) { | ||
var p = exports.addCoverage.paths; | ||
if (typeof p === 'string') { | ||
return ~filename.indexOf(p); | ||
} else if (p instanceof RegExp) { | ||
return filename.match(p); | ||
} else if (p instanceof Array) { | ||
return p.some(function(x) { | ||
return !!~filename.indexOf(x); | ||
}); | ||
} | ||
}; | ||
var projectName; | ||
@@ -41,7 +58,13 @@ | ||
subdir = process.cwd(); | ||
} else if (!subdir.match(/^\//)) { | ||
subdir = path.join(process.cwd(), subdir); | ||
} else if (typeof subdir === 'string') { | ||
if (!subdir.match(/^\//)) { | ||
subdir = path.join(process.cwd(), subdir); | ||
} | ||
} else if (subdir instanceof Array) { | ||
subdir = subdir.map(function(x) { | ||
return x.match(/^\//) ? x : path.join(process.cwd(), x); | ||
}); | ||
} | ||
global.__cov = {}; | ||
exports.addCoverage.subdir = subdir; | ||
exports.addCoverage.paths = subdir; | ||
var compile = Module.prototype._compile; | ||
@@ -53,3 +76,3 @@ Object.keys(Module._cache).forEach(function (path) { | ||
Module.prototype._compile = function (code, filename) { | ||
if (~filename.indexOf(subdir)) { | ||
if (eligibleForCoverage(filename)) { | ||
code = exports.addCoverage(code, filename); | ||
@@ -56,0 +79,0 @@ } |
{ | ||
"author": "Anatoliy Chakkaev <rpm1602@gmail.com>", | ||
"name": "semicov", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"main": "index.js", | ||
@@ -9,2 +9,6 @@ "dependencies": {}, | ||
"optionalDependencies": {}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/1602/semicov" | ||
}, | ||
"engines": { | ||
@@ -11,0 +15,0 @@ "node": "*" |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
261423
2492
6