Skip to content

Commit

Permalink
Merge pull request #62 from AlCalzone/ts-global
Browse files Browse the repository at this point in the history
Enable local TypeScripts to use functions defined in global TypeScripts
  • Loading branch information
GermanBluefox committed Jan 6, 2018
2 parents a847ae0 + 79169d8 commit e61fd02
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,9 @@
}

adapter.objects.getObjectView('script', 'javascript', {}, function (err, doc) {
globalScript = '';
// we have to make sure the VM doesn't choke on `exports` when using TypeScript
// even when there's no global script, this line has to exist:
globalScript = "const exports = {};\n";
var count = 0;
if (doc && doc.rows && doc.rows.length) {
// assemble global script
Expand Down Expand Up @@ -463,9 +465,7 @@
} else {
adapter.log.info("TypeScript compilation successful");
}
// polyfill `exports` with an empty object so the vm doesn't choke
var code = "(function(exports){" + tsCompiled.result + "}({}));";
globalScript += code + '\n';
globalScript += tsCompiled.result + '\n';
} else {
adapter.log.error("TypeScript compilation failed: \n" + errors);
}
Expand Down Expand Up @@ -3230,9 +3230,7 @@
} else {
adapter.log.info(name + ': TypeScript compilation successful');
}
// polyfill `exports` with an empty object so the vm doesn't choke
var code = "(function(exports){" + tsCompiled.result + "}({}));";
scripts[name] = compile(globalScript + '\n' + code, name);
scripts[name] = compile(globalScript + '\n' + tsCompiled.result, name);
if (scripts[name]) execute(scripts[name], name, obj.common.verbose, obj.common.debug);
if (typeof callback === 'function') callback(true, name);
} else {
Expand Down

0 comments on commit e61fd02

Please sign in to comment.