custom-module: add support for standard module export syntax

This commit is contained in:
jean-emmanuel 2019-03-20 19:58:27 +01:00
parent e7ec5208e1
commit cce58c9fc9
3 changed files with 32 additions and 29 deletions

View file

@ -54,11 +54,14 @@ class OscServer {
setTimeout, clearTimeout,
setInterval, clearInterval,
settings,
options: customModule.slice(1, customModule.length)
options: customModule.slice(1, customModule.length),
module: {},
}
try {
mod = vm.runInContext(file, vm.createContext(context))
var context = vm.createContext(context)
mod = vm.runInContext(file, context)
if (context.module.exports) mod = context.module.exports
} catch(err) {
console.error(err)
return false