Skip to content

Commit 8b58c05

Browse files
evantorriebcoe
authored andcommitted
feat: allow eager instantiation of instrumenter (#490)
1 parent d8d2de0 commit 8b58c05

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

index.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ function NYC (config) {
4848
this._reportDir = config.reportDir || 'coverage'
4949
this._sourceMap = typeof config.sourceMap === 'boolean' ? config.sourceMap : true
5050
this._showProcessTree = config.showProcessTree || false
51+
this._eagerInstantiation = config.eager || false
5152
this.cwd = config.cwd || process.cwd()
5253

5354
this.reporter = arrify(config.reporter || 'text')
@@ -91,7 +92,7 @@ function NYC (config) {
9192
NYC.prototype._createTransform = function (ext) {
9293
var _this = this
9394

94-
return cachingTransform({
95+
var opts = {
9596
salt: JSON.stringify({
9697
istanbul: require('istanbul-lib-coverage/package.json').version,
9798
nyc: require('./package.json').version
@@ -101,11 +102,16 @@ NYC.prototype._createTransform = function (ext) {
101102
_this.hashCache[metadata.filename] = hash
102103
return hash
103104
},
104-
factory: this._transformFactory.bind(this),
105105
cacheDir: this.cacheDirectory,
106106
disableCache: !this.enableCache,
107107
ext: ext
108-
})
108+
}
109+
if (this._eagerInstantiation) {
110+
opts.transform = this._transformFactory(this.cacheDirectory)
111+
} else {
112+
opts.factory = this._transformFactory.bind(this)
113+
}
114+
return cachingTransform(opts)
109115
}
110116

111117
NYC.prototype._loadAdditionalModules = function () {

lib/config-util.js

+5
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ Config.buildYargs = function (cwd) {
131131
default: [],
132132
describe: 'a list of additional modules that nyc should attempt to require in its subprocess, e.g., babel-register, babel-polyfill.'
133133
})
134+
.option('eager', {
135+
default: false,
136+
type: 'boolean',
137+
describe: 'instantiate the instrumenter at startup (see https://git.io/vMKZ9)'
138+
})
134139
.option('cache', {
135140
alias: 'c',
136141
default: true,

0 commit comments

Comments
 (0)