diff --git a/lib/modules/solidity/solcP.js b/lib/modules/solidity/solcP.js index 5550c9b1..e4d04cab 100644 --- a/lib/modules/solidity/solcP.js +++ b/lib/modules/solidity/solcP.js @@ -1,5 +1,20 @@ let solc; +let fs = require('fs-extra'); +let path = require('path'); + +function findImports(filename) { + console.dir(filename); + if (!fs.existsSync(filename)) { + if (fs.existsSync(path.join('./node_modules/', filename))) { + return {contents: fs.readFileSync(path.join('./node_modules/', filename)).toString()}; + } else { + return {error: 'File not found'}; + } + } + return {contents: fs.readFileSync(filename).toString()}; +} + process.on('message', function (msg) { if (msg.action === 'loadCompiler') { solc = require(msg.solcLocation); @@ -8,7 +23,7 @@ process.on('message', function (msg) { if (msg.action === 'compile') { // TODO: only available in 0.4.11; need to make versions warn about this - let output = solc.compileStandardWrapper(JSON.stringify(msg.jsonObj)); + let output = solc.compileStandardWrapper(JSON.stringify(msg.jsonObj), findImports); process.send({result: "compilation", output: output}); } }); diff --git a/test_apps/test_app/another_folder/another_test.sol b/test_apps/test_app/another_folder/another_test.sol new file mode 100644 index 00000000..ddd06f3e --- /dev/null +++ b/test_apps/test_app/another_folder/another_test.sol @@ -0,0 +1,21 @@ +pragma solidity ^0.4.17; + +contract SimpleStorageTest2 { + uint public storedData; + + function() public payable { } + + function SimpleStorage(uint initialValue) public { + storedData = initialValue; + } + + function set(uint x) public { + storedData = x; + } + + function get() public view returns (uint retVal) { + return storedData; + } + +} + diff --git a/test_apps/test_app/embark.json b/test_apps/test_app/embark.json index e4974bb6..0b6e48a0 100644 --- a/test_apps/test_app/embark.json +++ b/test_apps/test_app/embark.json @@ -16,7 +16,7 @@ "config": "config/", "versions": { "web3.js": "1.0.0-beta.27", - "solc": "0.4.17", + "solc": "0.4.21", "ipfs-api": "17.2.6" }, "plugins": { diff --git a/test_apps/test_app/package.json b/test_apps/test_app/package.json index 234db24d..8711dde1 100644 --- a/test_apps/test_app/package.json +++ b/test_apps/test_app/package.json @@ -18,6 +18,7 @@ "jquery": "^1.11.3", "react": "^16.0.0", "react-bootstrap": "^0.32.0", - "react-dom": "^16.2.0" + "react-dom": "^16.2.0", + "zeppelin-solidity": "^1.8.0" } } diff --git a/test_apps/test_app/some_folder/test_contract.sol b/test_apps/test_app/some_folder/test_contract.sol new file mode 100644 index 00000000..233605e4 --- /dev/null +++ b/test_apps/test_app/some_folder/test_contract.sol @@ -0,0 +1,23 @@ +pragma solidity ^0.4.17; + +import "another_folder/another_test.sol"; +import "zeppelin-solidity/contracts/ownership/Ownable.sol"; + +contract SimpleStorageTest is Ownable { + uint public storedData; + + function() public payable { } + + function SimpleStorage(uint initialValue) public { + storedData = initialValue; + } + + function set(uint x) public { + storedData = x; + } + + function get() public view returns (uint retVal) { + return storedData; + } + +}