Use global hook flag rather than module local

This commit is contained in:
kpdecker 2016-10-09 13:37:17 -05:00
parent 08fc0d0ca2
commit 80ee6aadd7

View File

@ -5,7 +5,6 @@ var fs = require('fs');
// Only install once if called multiple times
var errorFormatterInstalled = false;
var uncaughtShimInstalled = false;
var requireHookInstalled = false;
// If true, the caches are reset before a stack trace formatting operation
var emptyCacheBetweenOperations = false;
@ -457,15 +456,19 @@ exports.install = function(options) {
}
// Support runtime transpilers that include inline source maps
if (options.hookRequire && !requireHookInstalled && !isInBrowser()) {
requireHookInstalled = true;
if (options.hookRequire && !isInBrowser()) {
var Module = require('module');
var $compile = Module.prototype._compile;
Module.prototype._compile = function(content, filename) {
fileContentsCache[filename] = content;
sourceMapCache[filename] = undefined;
return $compile.call(this, content, filename);
};
if (!$compile.__sourceMapSupport) {
Module.prototype._compile = function(content, filename) {
fileContentsCache[filename] = content;
sourceMapCache[filename] = undefined;
return $compile.call(this, content, filename);
};
Module.prototype._compile.__sourceMapSupport = true;
}
}
// Configure options