From a78d8b00bfca76cd0719eae0445fd89491f3edcf Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 6 Oct 2017 07:30:34 -0400 Subject: [PATCH] fix support for 1.0 versions of web3 --- lib/contracts/solcW.js | 2 +- lib/core/config.js | 2 +- lib/pipeline/npm.js | 85 ++++++++++++++++++++++++---------- test_app/config/contracts.json | 2 +- 4 files changed, 64 insertions(+), 27 deletions(-) diff --git a/lib/contracts/solcW.js b/lib/contracts/solcW.js index a37d82b2c..2087a903a 100644 --- a/lib/contracts/solcW.js +++ b/lib/contracts/solcW.js @@ -29,7 +29,7 @@ class SolcW { solcProcess.send({action: 'loadCompiler', solcLocation: 'solc'}); } else { let npm = new Npm({logger: this.logger}); - npm.getPackageVersion('solc', this.solcVersion, false, function(location) { + npm.getPackageVersion('solc', this.solcVersion, false, false, function(location) { let requirePath = path.join(process.env.PWD, location); solcProcess.send({action: 'loadCompiler', solcLocation: requirePath}); }); diff --git a/lib/core/config.js b/lib/core/config.js index 2a9703bc8..647ee8e8d 100644 --- a/lib/core/config.js +++ b/lib/core/config.js @@ -257,7 +257,7 @@ Config.prototype.loadFiles = function(files) { //readFiles.push(new File({filename: 'web3-' + web3Version + '.js', type: 'custom', resolver: function(callback) { readFiles.push(new File({filename: 'web3.js', type: 'custom', resolver: function(callback) { let npm = new Npm({logger: self.logger}); - npm.getPackageVersion('web3', web3Version, 'dist/web3.js', function(web3Content) { + npm.getPackageVersion('web3', web3Version, 'dist/web3.min.js', true, function(web3Content) { callback(web3Content); }); }})); diff --git a/lib/pipeline/npm.js b/lib/pipeline/npm.js index 3f4bdfeaa..bf8732d85 100644 --- a/lib/pipeline/npm.js +++ b/lib/pipeline/npm.js @@ -12,7 +12,8 @@ class Npm { this.logger = options.logger; } - getPackageVersion(packageName, version, returnContent, callback) { + // TODO: callback should accept an error + getPackageVersion(packageName, version, returnContent, getFromGit, callback) { let self = this; let npmRegistry = "https://registry.npmjs.org/" + packageName + "/" + version; @@ -25,6 +26,7 @@ class Npm { res.on('end', function () { let registryJSON = JSON.parse(body); + console.log(JSON.stringify(registryJSON)); let tarball = registryJSON.dist.tarball; var download = function(url, dest, cb) { @@ -40,35 +42,70 @@ class Npm { }); }; - let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; + if (getFromGit) { + let repoName = registryJSON.repository.url.replace("git+https://github.com/", "").replace(".git",""); + let gitHead = registryJSON.gitHead; + let fileLocation = "https://raw.githubusercontent.com/" + repoName + "/" + gitHead + "/dist/web3.min.js"; - if (fs.existsSync(packageDirectory + "/downloaded_package.tgz")) { - if (returnContent) { - let distFile = packageDirectory + returnContent; - callback(fs.readFileSync(distFile).toString()); + let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; + if (fs.existsSync(packageDirectory + "/" + packageName + ".js")) { + if (returnContent) { + let distFile = packageDirectory + packageName + ".js"; + callback(fs.readFileSync(distFile).toString()); + } else { + callback(packageDirectory); + } } else { - callback(packageDirectory); + fs.mkdirpSync(packageDirectory); + self.logger.info("downloading " + packageName + " " + version + "...."); + + download(tarball, packageDirectory + "/" + packageName + ".js", function() { + o_fs.createReadStream(packageDirectory + "/" + packageName + ".js").pipe( + tar.x({ + strip: 1, + C: packageDirectory + }).on('end', function() { + if (returnContent) { + let distFile = packageDirectory + packageName + ".js"; + callback(fs.readFileSync(distFile).toString()); + } else { + callback(packageDirectory); + } + }) + ); + }); } + } else { - fs.mkdirpSync(packageDirectory); - self.logger.info("downloading " + packageName + " " + version + "...."); - download(tarball, packageDirectory + "/downloaded_package.tgz", function() { - o_fs.createReadStream(packageDirectory + '/downloaded_package.tgz').pipe( - tar.x({ - strip: 1, - C: packageDirectory - }).on('end', function() { - if (returnContent) { - let distFile = packageDirectory + returnContent; - callback(fs.readFileSync(distFile).toString()); - } else { - callback(packageDirectory); - } - }) - ); - }); + let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/'; + if (fs.existsSync(packageDirectory + "/downloaded_package.tgz")) { + if (returnContent) { + let distFile = packageDirectory + returnContent; + callback(fs.readFileSync(distFile).toString()); + } else { + callback(packageDirectory); + } + } else { + fs.mkdirpSync(packageDirectory); + self.logger.info("downloading " + packageName + " " + version + "...."); + download(tarball, packageDirectory + "/downloaded_package.tgz", function() { + o_fs.createReadStream(packageDirectory + '/downloaded_package.tgz').pipe( + tar.x({ + strip: 1, + C: packageDirectory + }).on('end', function() { + if (returnContent) { + let distFile = packageDirectory + returnContent; + callback(fs.readFileSync(distFile).toString()); + } else { + callback(packageDirectory); + } + }) + ); + }); + } } }); diff --git a/test_app/config/contracts.json b/test_app/config/contracts.json index 4854af1c3..49262ad9e 100644 --- a/test_app/config/contracts.json +++ b/test_app/config/contracts.json @@ -1,7 +1,7 @@ { "default": { "versions": { - "web3.js": "0.20.0", + "web3.js": "1.0.0-beta.18", "solc": "0.4.11" }, "deployment": {