Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var pino = require('pino')
require('module').wrap = override
var debug = require('debug')
var debug = reload('debug')

module.exports = pinoDebug

Expand Down Expand Up @@ -102,3 +102,25 @@ function override (script) {

return head + script + tail
}

function reload(module) {
unload(module);
return require(module);
}

function unload(module, stack) {
var path = require.resolve(module);

if (require.cache[path] && require.cache[path].children) {
stack = stack || [];

require.cache[path].children.forEach(function (child) {
if (!stack.includes(child.id)) {
stack.push(path);
unload(child.id, stack);
}
});
}

delete require.cache[path];
}