istanbul-lib-hook
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -6,2 +6,10 @@ # Change Log | ||
## [2.0.4](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-hook@2.0.3...istanbul-lib-hook@2.0.4) (2019-03-12) | ||
**Note:** Version bump only for package istanbul-lib-hook | ||
## [2.0.3](https://github.com/istanbuljs/istanbuljs/compare/istanbul-lib-hook@2.0.2...istanbul-lib-hook@2.0.3) (2019-01-26) | ||
@@ -8,0 +16,0 @@ |
@@ -5,8 +5,8 @@ /* | ||
*/ | ||
var path = require('path'), | ||
vm = require('vm'), | ||
appendTransform = require('append-transform'), | ||
originalCreateScript = vm.createScript, | ||
originalRunInThisContext = vm.runInThisContext, | ||
originalRunInContext = vm.runInContext; | ||
const path = require('path'); | ||
const vm = require('vm'); | ||
const appendTransform = require('append-transform'); | ||
const originalCreateScript = vm.createScript; | ||
const originalRunInThisContext = vm.runInThisContext; | ||
const originalRunInContext = vm.runInContext; | ||
@@ -23,7 +23,7 @@ function transformFn(matcher, transformer, verbose) { | ||
var shouldHook = | ||
typeof options.filename === 'string' && | ||
matcher(path.resolve(options.filename)), | ||
transformed, | ||
changed = false; | ||
const shouldHook = | ||
typeof options.filename === 'string' && | ||
matcher(path.resolve(options.filename)); | ||
let transformed; | ||
let changed = false; | ||
@@ -54,3 +54,3 @@ if (shouldHook) { | ||
} | ||
return { code: transformed, changed: changed }; | ||
return { code: transformed, changed }; | ||
}; | ||
@@ -67,3 +67,3 @@ } | ||
if (matcher && typeof require !== 'undefined' && require && require.cache) { | ||
Object.keys(require.cache).forEach(function(filename) { | ||
Object.keys(require.cache).forEach(filename => { | ||
if (matcher(filename)) { | ||
@@ -92,18 +92,17 @@ delete require.cache[filename]; | ||
options = options || {}; | ||
var extensions, | ||
disable = false, | ||
fn = transformFn(matcher, transformer, options.verbose), | ||
postLoadHook = | ||
options.postLoadHook && typeof options.postLoadHook === 'function' | ||
? options.postLoadHook | ||
: null; | ||
let disable = false; | ||
const fn = transformFn(matcher, transformer, options.verbose); | ||
const postLoadHook = | ||
options.postLoadHook && typeof options.postLoadHook === 'function' | ||
? options.postLoadHook | ||
: null; | ||
extensions = options.extensions || ['.js']; | ||
const extensions = options.extensions || ['.js']; | ||
extensions.forEach(function(ext) { | ||
appendTransform(function(code, filename) { | ||
extensions.forEach(ext => { | ||
appendTransform((code, filename) => { | ||
if (disable) { | ||
return code; | ||
} | ||
var ret = fn(code, filename); | ||
const ret = fn(code, filename); | ||
if (postLoadHook) { | ||
@@ -134,5 +133,5 @@ postLoadHook(filename); | ||
opts = opts || {}; | ||
var fn = transformFn(matcher, transformer, opts.verbose); | ||
const fn = transformFn(matcher, transformer, opts.verbose); | ||
vm.createScript = function(code, file) { | ||
var ret = fn(code, file); | ||
const ret = fn(code, file); | ||
return originalCreateScript(ret.code, file); | ||
@@ -162,5 +161,5 @@ }; | ||
opts = opts || {}; | ||
var fn = transformFn(matcher, transformer, opts.verbose); | ||
const fn = transformFn(matcher, transformer, opts.verbose); | ||
vm.runInThisContext = function(code, options) { | ||
var ret = fn(code, options); | ||
const ret = fn(code, options); | ||
return originalRunInThisContext(ret.code, options); | ||
@@ -190,6 +189,6 @@ }; | ||
opts = opts || {}; | ||
var fn = transformFn(matcher, transformer, opts.verbose); | ||
const fn = transformFn(matcher, transformer, opts.verbose); | ||
vm.runInContext = function(code, context, file) { | ||
var ret = fn(code, file); | ||
var coverageVariable = opts.coverageVariable || '__coverage__'; | ||
const ret = fn(code, file); | ||
const coverageVariable = opts.coverageVariable || '__coverage__'; | ||
// Refer coverage variable in context to global coverage variable. | ||
@@ -237,10 +236,10 @@ // So that coverage data will be written in global coverage variable for unit tests run in vm.runInContext. | ||
module.exports = { | ||
hookRequire: hookRequire, | ||
hookCreateScript: hookCreateScript, | ||
unhookCreateScript: unhookCreateScript, | ||
hookRunInThisContext: hookRunInThisContext, | ||
unhookRunInThisContext: unhookRunInThisContext, | ||
hookRunInContext: hookRunInContext, | ||
unhookRunInContext: unhookRunInContext, | ||
unloadRequireCache: unloadRequireCache | ||
hookRequire, | ||
hookCreateScript, | ||
unhookCreateScript, | ||
hookRunInThisContext, | ||
unhookRunInThisContext, | ||
hookRunInContext, | ||
unhookRunInContext, | ||
unloadRequireCache | ||
}; |
{ | ||
"name": "istanbul-lib-hook", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "Hooks for require, vm and script used in istanbul", | ||
@@ -29,7 +29,7 @@ "author": "Krishnan Anantheswaran <kananthmail-github@yahoo.com>", | ||
}, | ||
"homepage": "https://github.com/istanbuljs/istanbuljs#readme", | ||
"homepage": "https://istanbul.js.org/", | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"gitHead": "7875defdc3c3640787ac5d83700246de119e8b83" | ||
"gitHead": "c81b051d83217947dfd97d8d06532bd5013e98c3" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15931
234