Skip to content

Commit d0f654c

Browse files
authored
fix: source was being instrumented twice, due to upstream fix in ista… (#853)
BREAKING CHANGE: --hook-run-in-context, and --hook-run-in-this-context are no longer true by default (they should be enabled if you're using a library like requirejs).
1 parent adb310c commit d0f654c

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

appveyor.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ environment:
55
- nodejs_version: '6'
66
install:
77
- ps: Install-Product node $env:nodejs_version
8+
- npm i npm@5 -g
89
- set PATH=%APPDATA%\npm;%PATH%
910
- set CI=true
1011
- npm config set progress=false

index.js

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const findCacheDir = require('find-cache-dir')
99
const fs = require('fs')
1010
const glob = require('glob')
1111
const Hash = require('./lib/hash')
12-
const js = require('default-require-extensions/js')
1312
const libCoverage = require('istanbul-lib-coverage')
1413
const libHook = require('istanbul-lib-hook')
1514
const libReport = require('istanbul-lib-report')
@@ -80,6 +79,7 @@ function NYC (config) {
8079
return transforms
8180
}.bind(this), {})
8281

82+
this.hookRequire = config.hookRequire
8383
this.hookRunInContext = config.hookRunInContext
8484
this.hookRunInThisContext = config.hookRunInThisContext
8585
this.fakeRequire = null
@@ -311,14 +311,10 @@ NYC.prototype._addHook = function (type) {
311311
libHook['hook' + type](dummyMatcher, handleJs, { extensions: this.extensions })
312312
}
313313

314-
NYC.prototype._wrapRequire = function () {
315-
this.extensions.forEach(function (ext) {
316-
require.extensions[ext] = js
317-
})
318-
this._addHook('Require')
319-
}
320-
321-
NYC.prototype._addOtherHooks = function () {
314+
NYC.prototype._addRequireHooks = function () {
315+
if (this.hookRequire) {
316+
this._addHook('Require')
317+
}
322318
if (this.hookRunInContext) {
323319
this._addHook('RunInContext')
324320
}
@@ -362,8 +358,7 @@ NYC.prototype._wrapExit = function () {
362358
}
363359

364360
NYC.prototype.wrap = function (bin) {
365-
this._wrapRequire()
366-
this._addOtherHooks()
361+
this._addRequireHooks()
367362
this._wrapExit()
368363
this._loadAdditionalModules()
369364
return this

lib/config-util.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,20 @@ Config.buildYargs = function (cwd) {
181181
description: 'should nyc handle instrumentation?',
182182
global: false
183183
})
184-
.option('hook-run-in-context', {
184+
.option('hook-require', {
185185
default: true,
186186
type: 'boolean',
187+
description: 'should nyc wrap require?',
188+
global: false
189+
})
190+
.option('hook-run-in-context', {
191+
default: false,
192+
type: 'boolean',
187193
description: 'should nyc wrap vm.runInContext?',
188194
global: false
189195
})
190196
.option('hook-run-in-this-context', {
191-
default: true,
197+
default: false,
192198
type: 'boolean',
193199
description: 'should nyc wrap vm.runInThisContext?',
194200
global: false

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@
7878
"caching-transform": "^1.0.0",
7979
"convert-source-map": "^1.5.1",
8080
"debug-log": "^1.0.1",
81-
"default-require-extensions": "^1.0.0",
8281
"find-cache-dir": "^0.1.1",
8382
"find-up": "^2.1.0",
8483
"foreground-child": "^1.5.3",
@@ -133,7 +132,6 @@
133132
"caching-transform",
134133
"convert-source-map",
135134
"debug-log",
136-
"default-require-extensions",
137135
"find-cache-dir",
138136
"find-up",
139137
"foreground-child",

test/nyc-bin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ describe('the nyc cli', function () {
570570

571571
describe('hooks', function () {
572572
it('provides coverage for requireJS and AMD modules', function (done) {
573-
var args = [bin, process.execPath, './index.js']
573+
var args = [bin, '--hook-run-in-this-context', '--hook-require=false', process.execPath, './index.js']
574574

575575
var proc = spawn(process.execPath, args, {
576576
cwd: fixturesHooks,

0 commit comments

Comments
 (0)