look for contract import in dapp dir and node_modules

This commit is contained in:
Iuri Matias 2018-04-12 17:55:57 -04:00
parent e3fde1ad22
commit db61e355c1
5 changed files with 63 additions and 3 deletions

View File

@ -1,5 +1,20 @@
let solc; 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) { process.on('message', function (msg) {
if (msg.action === 'loadCompiler') { if (msg.action === 'loadCompiler') {
solc = require(msg.solcLocation); solc = require(msg.solcLocation);
@ -8,7 +23,7 @@ process.on('message', function (msg) {
if (msg.action === 'compile') { if (msg.action === 'compile') {
// TODO: only available in 0.4.11; need to make versions warn about this // 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}); process.send({result: "compilation", output: output});
} }
}); });

View File

@ -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;
}
}

View File

@ -16,7 +16,7 @@
"config": "config/", "config": "config/",
"versions": { "versions": {
"web3.js": "1.0.0-beta.27", "web3.js": "1.0.0-beta.27",
"solc": "0.4.17", "solc": "0.4.21",
"ipfs-api": "17.2.6" "ipfs-api": "17.2.6"
}, },
"plugins": { "plugins": {

View File

@ -18,6 +18,7 @@
"jquery": "^1.11.3", "jquery": "^1.11.3",
"react": "^16.0.0", "react": "^16.0.0",
"react-bootstrap": "^0.32.0", "react-bootstrap": "^0.32.0",
"react-dom": "^16.2.0" "react-dom": "^16.2.0",
"zeppelin-solidity": "^1.8.0"
} }
} }

View File

@ -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;
}
}