Skip to content

Commit

Permalink
feat: allow eager instantiation of instrumenter (#490)
Browse files Browse the repository at this point in the history
  • Loading branch information
evantorrie authored and bcoe committed Jan 17, 2017
1 parent d8d2de0 commit 8b58c05
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function NYC (config) {
this._reportDir = config.reportDir || 'coverage'
this._sourceMap = typeof config.sourceMap === 'boolean' ? config.sourceMap : true
this._showProcessTree = config.showProcessTree || false
this._eagerInstantiation = config.eager || false
this.cwd = config.cwd || process.cwd()

this.reporter = arrify(config.reporter || 'text')
Expand Down Expand Up @@ -91,7 +92,7 @@ function NYC (config) {
NYC.prototype._createTransform = function (ext) {
var _this = this

return cachingTransform({
var opts = {
salt: JSON.stringify({
istanbul: require('istanbul-lib-coverage/package.json').version,
nyc: require('./package.json').version
Expand All @@ -101,11 +102,16 @@ NYC.prototype._createTransform = function (ext) {
_this.hashCache[metadata.filename] = hash
return hash
},
factory: this._transformFactory.bind(this),
cacheDir: this.cacheDirectory,
disableCache: !this.enableCache,
ext: ext
})
}
if (this._eagerInstantiation) {
opts.transform = this._transformFactory(this.cacheDirectory)
} else {
opts.factory = this._transformFactory.bind(this)
}
return cachingTransform(opts)
}

NYC.prototype._loadAdditionalModules = function () {
Expand Down
5 changes: 5 additions & 0 deletions lib/config-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ Config.buildYargs = function (cwd) {
default: [],
describe: 'a list of additional modules that nyc should attempt to require in its subprocess, e.g., babel-register, babel-polyfill.'
})
.option('eager', {
default: false,
type: 'boolean',
describe: 'instantiate the instrumenter at startup (see https://git.io/vMKZ9)'
})
.option('cache', {
alias: 'c',
default: true,
Expand Down

0 comments on commit 8b58c05

Please sign in to comment.