Extract global and web3js

This commit is contained in:
Anthony Laibe 2018-08-28 15:09:07 +01:00
parent 83c01cffdc
commit a8c5205b67
3 changed files with 4 additions and 3 deletions

View File

@ -36,6 +36,9 @@ class CodeRunner {
this.runCode.registerVar('Web3', Web3); this.runCode.registerVar('Web3', Web3);
this.runCode.registerVar('EmbarkJS', EmbarkJS); this.runCode.registerVar('EmbarkJS', EmbarkJS);
this.events.on('code-generator-ready', () => { this.events.on('code-generator-ready', () => {
this.events.request('code-generator:web3js', ((_err, code) => {
this.runCode.doEval(code);
}));
this.events.request('code-generator:embarkjs:provider-code', (code) => { this.events.request('code-generator:embarkjs:provider-code', (code) => {
this.runCode.doEval(code); this.runCode.doEval(code);
const codeTypes = { const codeTypes = {

View File

@ -2,7 +2,7 @@ const vm = require('vm');
class RunCode { class RunCode {
constructor() { constructor() {
this.context = Object.assign({}, {console, exports, require, module, __filename, __dirname}, global.this); this.context = Object.assign({}, {global, console, exports, require, module, __filename, __dirname});
} }
doEval(code) { doEval(code) {

View File

@ -379,7 +379,6 @@ class CodeGenerator {
}, },
function getImports(web3Location, next) { function getImports(web3Location, next) {
web3Location = web3Location.replace(/\\/g, '/'); // Import paths must always have forward slashes web3Location = web3Location.replace(/\\/g, '/'); // Import paths must always have forward slashes
code += "\nimport Web3 from '" + web3Location + "';\n";
code += "\nglobal.Web3 = Web3;\n"; code += "\nglobal.Web3 = Web3;\n";
code += "\n if (typeof web3 === 'undefined') {"; code += "\n if (typeof web3 === 'undefined') {";
@ -390,7 +389,6 @@ class CodeGenerator {
let providerCode = self.generateProvider(false); let providerCode = self.generateProvider(false);
code += providerCode; code += providerCode;
code += "\nglobal.__embarkContext = __mainContext.__loadManagerInstance;\n"; code += "\nglobal.__embarkContext = __mainContext.__loadManagerInstance;\n";
code += "\nexport default web3;\n";
next(null, code); next(null, code);
} }
], cb); ], cb);