-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
33 lines (25 loc) · 766 Bytes
/
index.js
File metadata and controls
33 lines (25 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
module.exports = reloadable
var inspect = require('util').inspect
function reloadable (module_path, opts) {
var facade = {
toJSON: function() { return this.__proto__ },
inspect: function() { return inspect(this.__proto__) },
}
opts || (opts = {})
opts.error || (opts.error = defaultErrorHandler)
var _reload = opts.reload || function refreshrequire () {
delete require.cache[require.resolve(module_path)]
return require(module_path)
}
function reload () {
try { facade.__proto__ = _reload() }
catch (err) { opts.error(err, module_path) }
}
if (opts.signal) process.on(opts.signal, reload)
if (opts.exposeReload) facade.reload = reload
reload()
return facade
}
function defaultErrorHandler (err, path) {
console.error(path, err)
}