Created
June 1, 2016 19:20
-
-
Save vdeturckheim/dbc60c876b3728ac6a6e5671dae0f991 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
const Module = require('module'); | |
const originalCompile = Module.prototype._compile; | |
const nohook = function (content, filename, done) { | |
return done(content); | |
}; | |
let currentHook = nohook; | |
Module.prototype._compile = function (content, filename) { | |
const self = this; | |
currentHook(content, filename, (newContent) => { | |
newContent = newContent || content; | |
originalCompile.call(self, newContent, filename); | |
}); | |
}; | |
const placeHook = function (hook) { | |
currentHook = hook; | |
}; | |
const removeHook = function () { | |
currentHook = nohook; | |
}; | |
module.exports.placeHook = placeHook; | |
module.exports.removeHook = removeHook; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment