-
-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
we should still run transpilers on source files included via --all #143
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,12 +3,12 @@ var fs = require('fs') | |
var glob = require('glob') | ||
var micromatch = require('micromatch') | ||
var mkdirp = require('mkdirp') | ||
var Module = require('module') | ||
var appendTransform = require('append-transform') | ||
var cachingTransform = require('caching-transform') | ||
var path = require('path') | ||
var rimraf = require('rimraf') | ||
var onExit = require('signal-exit') | ||
var stripBom = require('strip-bom') | ||
var resolveFrom = require('resolve-from') | ||
var arrify = require('arrify') | ||
var SourceMapCache = require('./lib/source-map-cache') | ||
|
@@ -158,15 +158,26 @@ NYC.prototype._prepGlobPatterns = function (patterns) { | |
|
||
NYC.prototype.addFile = function (filename) { | ||
var relFile = path.relative(this.cwd, filename) | ||
var source = stripBom(fs.readFileSync(filename, 'utf8')) | ||
var source = this._readTranspiledSource(path.resolve(this.cwd, filename)) | ||
var instrumentedSource = this._maybeInstrumentSource(source, filename, relFile) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we've already wrapped require? Then the result of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jamestalmage reading through the codebase I think that Mind running this branch against one of your larger codebases and making sure there's no performance hit? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
return { | ||
instrument: !!instrumentedSource, | ||
relFile: relFile, | ||
content: instrumentedSource || source | ||
} | ||
} | ||
|
||
NYC.prototype._readTranspiledSource = function (path) { | ||
var source = null | ||
Module._extensions['.js']({ | ||
_compile: function (content, filename) { | ||
source = content | ||
} | ||
}, path) | ||
return source | ||
} | ||
|
||
NYC.prototype.shouldInstrumentFile = function (filename, relFile) { | ||
relFile = relFile.replace(/^\.\//, '') // remove leading './'. | ||
|
||
|
@@ -177,8 +188,10 @@ NYC.prototype.shouldInstrumentFile = function (filename, relFile) { | |
NYC.prototype.addAllFiles = function () { | ||
var _this = this | ||
|
||
this._loadAdditionalModules() | ||
|
||
glob.sync('**/*.js', {nodir: true, ignore: this.exclude}).forEach(function (filename) { | ||
var obj = _this.addFile(filename, true) | ||
var obj = _this.addFile(filename) | ||
if (obj.instrument) { | ||
module._compile( | ||
_this.instrumenter().getPreamble(obj.content, obj.relFile), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var fs = require('fs') | ||
|
||
require.extensions['.js'] = function (module, filename) { | ||
var content = fs.readFileSync(filename, 'utf8'); | ||
module._compile(content.replace('--> pork chop sandwiches <--', ''), filename); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My only thought would be to do this conditionally if we don't already have coverage data on that particular file. This feels like a performance hit.