From 8b9a212d566451db8d4a99e3675a6f44f823339b Mon Sep 17 00:00:00 2001 From: chriseth Date: Fri, 16 Oct 2015 09:57:17 +0200 Subject: [PATCH] Updated npm package. --- README.md | 15 ++++++++++++++- index.js | 22 +++++++++++++++++----- package.json | 2 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3018b68e8b..d31c6083c8 100644 --- a/README.md +++ b/README.md @@ -15,4 +15,17 @@ And then use it like so: var input = "contract x { function g() {} }"; var output = solc.compile(input, 1); // 1 activates the optimiser for (var contractName in output.contracts) - console.log(contractName + ': ' + output.contracts[contractName].bytecode); \ No newline at end of file + console.log(contractName + ': ' + output.contracts[contractName].bytecode); + +Starting from version 0.1.6, multiple files are supported with automatic import resolution by the compiler as follows: + + var solc = require('solc'); + var input = { + 'lib.sol': 'library L { function f() returns (uint) { return 7; } }', + 'cont.sol': 'import "lib.sol"; contract x { function g() { L.f(); } }' + }; + var output = solc.compile({sources: input}, 1); + for (var contractName in output.contracts) + console.log(contractName + ': ' + output.contracts[contractName].bytecode); + +Note that all input files that are imported have to be supplied, the compiler will not load any additional files on its own. diff --git a/index.js b/index.js index 6589bfd43f..2e3e2552c7 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,23 @@ var soljson = require('./bin/soljson-latest.js'); -compileJSON = soljson.cwrap("compileJSON", "string", ["string", "number"]); +var compileJSON = soljson.cwrap("compileJSON", "string", ["string", "number"]); +var compileJSONMulti = + '_compileJSONMulti' in soljson ? + soljson.cwrap("compileJSONMulti", "string", ["string", "number"]) : + null; + +var compile = function(input, optimise) { + var result = ''; + if (typeof(input) != typeof('') && compileJSONMulti !== null) + result = compileJSONMulti(JSON.stringify(input), optimise); + else + result = compileJSON(input, optimise); + return JSON.parse(result); +} + module.exports = { - compile: function(input, optimise){ - return JSON.parse( compileJSON(input, optimise) ); - }, + compile: compile, version: soljson.cwrap("version", "string", []) -} \ No newline at end of file +} diff --git a/package.json b/package.json index 29bc351e95..b05b6cd2fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "solc", - "version": "0.1.5", + "version": "0.1.5-multi", "description": "Solidity compiler", "main": "index.js", "scripts": {