Skip to content

Instantly share code, notes, and snippets.

@vdeturckheim
Created June 1, 2016 19:20
Show Gist options
  • Save vdeturckheim/dbc60c876b3728ac6a6e5671dae0f991 to your computer and use it in GitHub Desktop.
Save vdeturckheim/dbc60c876b3728ac6a6e5671dae0f991 to your computer and use it in GitHub Desktop.
'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