From 58ea3d9c30162fb60f068a21003728558ed40e2b Mon Sep 17 00:00:00 2001 From: emizzle Date: Thu, 21 Feb 2019 15:23:11 +1100 Subject: [PATCH] fix(@embark/demo): Fix demo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix demo not running, by fixing the following issues: This was due to the removal of `Web3` from the VM initialisation in a recent PR. The reasoning behind the removal was so that the modules that need Web3 could require it as needed, however, it is needed in 3 modules (ENS, Whisper, and web3Connector), all of which would define `const Web = …` in the code generated EmbarkJS, thus causing issues in itself. This needs to be rethought prior to removing it from the VM sandbox. Because Web3 is back to being required in the global sandbox of the VM, it does not need to be registered in the `web3Connector` module, hence the removal of the `runcode:register`. Module not found: Error: Can't resolve 'embarkArtifacts/contracts/SimpleStorage.js' in '/Users/emizzle/temp/embark_demo/app/components’` This was fixed by replacing ``` import SimpleStorage from 'Embark/contracts/SimpleStorage'; ``` with ``` import SimpleStorage from '../../embarkArtifacts/contracts/SimpleStorage'; ``` revert changes changing __Web3 to Web3 --- packages/embark/src/lib/modules/codeRunner/index.js | 4 +++- packages/embark/templates/demo/app/components/blockchain.js | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/embark/src/lib/modules/codeRunner/index.js b/packages/embark/src/lib/modules/codeRunner/index.js index 809d22bfd..31448c5d9 100644 --- a/packages/embark/src/lib/modules/codeRunner/index.js +++ b/packages/embark/src/lib/modules/codeRunner/index.js @@ -1,6 +1,7 @@ const VM = require('./vm'); const fs = require('../../core/fs'); const EmbarkJS = require('embarkjs'); +const Web3 = require('web3'); class CodeRunner { constructor(embark, options) { @@ -13,7 +14,8 @@ class CodeRunner { this.ipc = options.ipc; this.vm = new VM({ sandbox: { - EmbarkJS + EmbarkJS, + Web3 }, require: { mock: { diff --git a/packages/embark/templates/demo/app/components/blockchain.js b/packages/embark/templates/demo/app/components/blockchain.js index d2243554c..66841e4c2 100644 --- a/packages/embark/templates/demo/app/components/blockchain.js +++ b/packages/embark/templates/demo/app/components/blockchain.js @@ -1,5 +1,5 @@ import EmbarkJS from 'Embark/EmbarkJS'; -import SimpleStorage from 'Embark/contracts/SimpleStorage'; +import SimpleStorage from '../../embarkArtifacts/contracts/SimpleStorage'; import React from 'react'; import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap';