Finally fixed the solc loading issue.

Moved the instantiation of the live-plugin-manager in to the child solc process. This allowed us to use the live-plugin-manager to require the installed solc file.

If the module is the same version as used by embark, the module is still loading using the normal require (from node_modules), as before.
This commit is contained in:
emizzle 2018-06-13 23:16:54 +10:00 committed by Iuri Matias
parent 5ee9843973
commit 62f3b85bc4
5 changed files with 117 additions and 67 deletions

View File

@ -2,8 +2,8 @@ const fs = require('fs-extra');
const path = require('path');
const constants = require('../../constants');
const Utils = require('../../utils/utils');
const ProcessWrapper = require('../../process/processWrapper');
const PluginManager = require('live-plugin-manager').PluginManager;
class SolcProcess extends ProcessWrapper {
@ -24,8 +24,15 @@ class SolcProcess extends ProcessWrapper {
return {error: 'File not found'};
}
loadCompiler(solcLocation) {
this.solc = require(solcLocation);
installAndLoadCompiler(solcVersion, packagePath){
let self = this;
return new Promise((resolve) => {
let manager = new PluginManager({pluginsPath: packagePath});
manager.install('solc', solcVersion).then(() => {
self.solc = manager.require('solc');
resolve();
});
});
}
compile(jsonObj, cb) {
@ -34,6 +41,7 @@ class SolcProcess extends ProcessWrapper {
cb(output);
}
}
let solcProcess;
@ -41,17 +49,23 @@ let solcProcess;
process.on('message', function (msg) {
if (msg.action === "init") {
solcProcess = new SolcProcess(msg.options);
return process.send({result: "initiated"});
return this.send({result: "initiated"});
}
if (msg.action === 'loadCompiler') {
solcProcess.loadCompiler(msg.requirePath);
process.send({result: "loadedCompiler"});
else if (msg.action === 'loadCompiler') {
require('solc');
return this.send({result: "loadedCompiler"});
}
if (msg.action === 'compile') {
else if (msg.action == 'installAndLoadCompiler') {
solcProcess.installAndLoadCompiler(msg.solcVersion, msg.packagePath).then(() => {
return this.send({result: "loadedCompiler"});
});
}
else if (msg.action === 'compile') {
solcProcess.compile(msg.jsonObj, (output) => {
process.send({result: "compilation-" + msg.id, output: output});
this.send({result: "compilation-" + msg.id, output: output});
});
}
});

View File

@ -39,30 +39,33 @@ class SolcW {
logger: self.logger,
events: self.events
});
this.solcProcess.send({action: "init", options: {}});
this.solcProcess.once('result', 'loadedCompiler', () => {
this.solcProcess.once("result", "initiated", () => {
this.events.request("version:get:solc", function(solcVersion) {
if (solcVersion === currentSolcVersion) {
self.solcProcess.send({action: 'loadCompiler', requirePath: 'solc'});
} else {
self.events.request("version:getPackagePath", "solc", solcVersion, function(err, path) {
if (err) {
return done(err);
}
let requirePath = fs.dappPath(path);
self.solcProcess.send({action: 'installAndLoadCompiler', solcVersion: solcVersion, packagePath: requirePath});
});
}
});
});
this.solcProcess.once("result", "loadedCompiler", () => {
self.compilerLoaded = true;
done();
});
this.solcProcess.send({action: "init", options: {}});
if (this.ipc.isServer()) {
this.ipc.on('compile', self.compile.bind(this));
}
this.events.request("version:get:solc", function(solcVersion) {
if (solcVersion === currentSolcVersion) {
self.solcProcess.send({action: 'loadCompiler', requirePath: 'solc'});
} else {
self.events.request("version:getPackageLocation", "solc", solcVersion, function(err, location) {
if (err) {
return done(err);
}
let requirePath = fs.dappPath(location);
self.solcProcess.send({action: 'loadCompiler', requirePath: requirePath});
});
}
});
}
isCompilerLoaded() {

View File

@ -64,10 +64,14 @@ class LibraryManager {
}
listenToCommandsToGetLibrary() {
let npm = new Npm({logger: this.embark.logger});
this.embark.events.setCommandHandler('version:getPackageLocation', (libName, version, cb) => {
let npm = new Npm({logger: this.embark.logger, packageName: libName, version:version});
npm.getPackageVersion(libName, version, cb);
});
this.embark.events.setCommandHandler('version:getPackagePath', (libName, version, cb) => {
let npm = new Npm({logger: this.embark.logger, packageName: libName, version:version});
cb(null, npm.packagePath);
});
}
}

View File

@ -8,18 +8,31 @@ class Npm {
constructor(options) {
this.logger = options.logger;
this.packageName = options.packageName;
this.version = options.version;
}
get packagePath(){
if(typeof this._packagePath == 'undefined'){
this._packagePath = './.embark/versions/' + this.packageName + '/' + this.version + '/';
}
return this._packagePath;
}
get pluginManager(){
if(typeof this._pluginManager == 'undefined'){
this._pluginManager = new PluginManager({pluginsPath: this.packagePath});
}
return this._pluginManager;
}
getPackageVersion(packageName, version, callback) {
let packageDirectory = './.embark/versions/' + packageName + '/' + version + '/';
let manager = new PluginManager({pluginsPath: packageDirectory});
if (fs.existsSync(packageDirectory + packageName)) {
return callback(null, packageDirectory + packageName);
if (fs.existsSync(this.packagePath + packageName)) {
return callback(null, this.packagePath + packageName);
}
this.logger.info(__("Downloading {{packageName}} {{version}}...", {packageName: packageName, version: version}));
this.logger.info(__("Downloading and installing {{packageName}} {{version}}...", {packageName: packageName, version: version}));
const obsMeasure = new PerformanceObserver((items) => {
let entry;
@ -29,14 +42,14 @@ class Npm {
entry = _.last(_.where(items.getEntries(), {name: downloadOngoing}));
if(entry){
// ongoing performance mark
strDuration = __('Still downloading {{packageName}} {{version}}... ({{duration}}ms elapsed)', {packageName: packageName, version: version, duration: entry.duration});
strDuration = __('Downloading and installing {{packageName}} {{version}}... ({{duration}}ms elapsed)', {packageName: packageName, version: version, duration: entry.duration});
}
else{
// otherwise, find our download complete measurement
entry = _.last(_.where(items.getEntries(), {name: downloadComplete}));
if(entry){
strDuration = __('Finished downloading {{packageName}} {{version}} in {{duration}}ms', {packageName: packageName, version: version, duration: entry.duration});
strDuration = __('Finished downloading and installing {{packageName}} {{version}} in {{duration}}ms', {packageName: packageName, version: version, duration: entry.duration});
performance.clearMarks();
}
}
@ -70,12 +83,45 @@ class Npm {
}, 750);
// do the package download/install
manager.install(packageName, version).then((result) => {
// stop updating console for ongoing download
clearInterval(intOngoingDownload);
performance.mark(endMark);
performance.measure(downloadComplete, startMark, endMark);
callback(null , result.location);
this.pluginManager.install(packageName, version).then((result) => {
// if(packageName === 'solc'){
// async.each(Object.keys(result.dependencies), function(dependency, cb){
// console.log('getting dependency: ' + dependency + ' ' + result.dependencies[dependency]);
// self.pluginManager.install(dependency, result.dependencies[dependency]).then(() => {
// console.log('installed ' + dependency + ' ' + result.dependencies[dependency]);
// cb();
// })
// .catch(cb);
// }, function(err){
// // stop updating console for ongoing download
// clearInterval(intOngoingDownload);
// performance.mark(endMark);
// performance.measure(downloadComplete, startMark, endMark);
// if(err){
// self.logger.error(err);
// return callback(err);
// }else{
// return callback(null, result.location, self.pluginManager);
// }
// });
// }
// else{
// stop updating console for ongoing download
clearInterval(intOngoingDownload);
performance.mark(endMark);
performance.measure(downloadComplete, startMark, endMark);
callback(null, result.location);
//}
}).catch(callback);
}
}

37
package-lock.json generated
View File

@ -1656,7 +1656,7 @@
"browserify-zlib": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/browserify-zlib/-/browserify-zlib-0.2.0.tgz",
"integrity": "sha512-Z942RysHXmJrhqk88FmKBVq/v5tqmSkDz7p54G/MGyjMnCFFnC79XWNbg+Vta8W6Wb2qtSZTSxIGkJrRpCFEiA==",
"integrity": "sha1-KGlFnZqjviRf6P4sofRuLn9U1z8=",
"requires": {
"pako": "1.0.6"
}
@ -2894,7 +2894,7 @@
"domain-browser": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/domain-browser/-/domain-browser-1.2.0.tgz",
"integrity": "sha512-jnjyiM6eRyZl2H+W8Q/zLMA481hzi0eszAaBUzIVnmYVDBbnLxVNnfu1HgEBvCbL+71FrxMl3E6lpKH7Ge3OXA=="
"integrity": "sha1-PTH1AZGmdJ3RN1p/Ui6CPULlTto="
},
"drbg.js": {
"version": "1.0.1",
@ -3016,7 +3016,7 @@
"errno": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz",
"integrity": "sha512-MfrRBDWzIWifgq6tJj60gkAwtLNb6sQPlcFrSOflcP1aFmmruKQ2wRnze/8V6kgyz7H3FF8Npzv78mZ7XLLflg==",
"integrity": "sha1-RoTXF3mtOa8Xfj8AeZb3xnyFJhg=",
"requires": {
"prr": "1.0.1"
}
@ -4583,6 +4583,7 @@
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.5.tgz",
"integrity": "sha512-JhBl0skXjUPCFH7x6x61gQxrKyXsxB5gcgePLZCwfyCGGsTISMoIeObbrvVeP6Xmyaudw4TT43qV2Gz+iyd2oQ==",
"optional": true,
"requires": {
"minipass": "2.3.3"
}
@ -6927,7 +6928,7 @@
"json-loader": {
"version": "0.5.7",
"resolved": "https://registry.npmjs.org/json-loader/-/json-loader-0.5.7.tgz",
"integrity": "sha512-QLPs8Dj7lnf3e3QYS1zkCo+4ZwqOiF9d/nZnYozTISxXWCfNs9yuky5rJw4/W34s7POaNlbZmQGaB5NiXCbP4w=="
"integrity": "sha1-3KFKcCNf+C8KyaOr62DTN6NlGF0="
},
"json-parse-better-errors": {
"version": "1.0.2",
@ -7529,14 +7530,6 @@
"path-exists": "3.0.0"
}
},
"lockfile": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/lockfile/-/lockfile-1.0.4.tgz",
"integrity": "sha512-cvbTwETRfsFh4nHsL1eGWapU1XFi5Ot9E85sWAwia7Y7EgB7vfqcZhTKZ+l7hCGxSPoushMv5GKhT5PdLv03WA==",
"requires": {
"signal-exit": "3.0.2"
}
},
"lodash": {
"version": "4.17.10",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.10.tgz",
@ -8857,7 +8850,7 @@
"node-libs-browser": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/node-libs-browser/-/node-libs-browser-2.1.0.tgz",
"integrity": "sha512-5AzFzdoIMb89hBGMZglEegffzgRg+ZFoUmisQ8HI4j1KDdpx13J0taNp2y9xPbur6W61gepGDDotGBVQ7mfUCg==",
"integrity": "sha1-X5QmPUBPbkR2fXJpAf/wVHjWAN8=",
"requires": {
"assert": "1.4.1",
"browserify-zlib": "0.2.0",
@ -9223,7 +9216,7 @@
"os-locale": {
"version": "2.1.0",
"resolved": "https://registry.npmjs.org/os-locale/-/os-locale-2.1.0.tgz",
"integrity": "sha512-3sslG3zJbEYcaC4YVAvDorjGxc7tv6KVATnLPZONiljsUncvihe9BQoVCEs0RZ1kmf4Hk9OBqlZfJZWI4GanKA==",
"integrity": "sha1-QrwpAKa1uL0XN2yOiCtlr8zyS/I=",
"requires": {
"execa": "0.7.0",
"lcid": "1.0.0",
@ -9310,7 +9303,7 @@
"pako": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.6.tgz",
"integrity": "sha512-lQe48YPsMJAig+yngZ87Lus+NF+3mtu7DVOBu6b/gHO1YpKwIj5AWjZ/TOS7i46HD/UixzWb1zeWDZfGZ3iYcg=="
"integrity": "sha1-AQEhG6pwxLykoPY/Igbpe3368lg="
},
"parse-asn1": {
"version": "5.1.1",
@ -12540,11 +12533,6 @@
"resolved": "https://registry.npmjs.org/uniqs/-/uniqs-2.0.0.tgz",
"integrity": "sha1-/+3ks2slKQaW5uFl1KWe25mOawI="
},
"universalify": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz",
"integrity": "sha1-+nG63UQ3r0wUiEHjs7Fl+enlkLc="
},
"unorm": {
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/unorm/-/unorm-1.4.1.tgz",
@ -12636,11 +12624,6 @@
}
}
},
"url-join": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.0.tgz",
"integrity": "sha1-TTNA6AfTdzvamZH4MFrNzCpmXSo="
},
"url-loader": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/url-loader/-/url-loader-0.6.2.tgz",
@ -13752,7 +13735,7 @@
"webpack-sources": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/webpack-sources/-/webpack-sources-1.1.0.tgz",
"integrity": "sha512-aqYp18kPphgoO5c/+NaUvEeACtZjMESmDChuD3NBciVpah3XpMEU9VAAtIaB1BsfJWWTSdv8Vv1m3T0aRk2dUw==",
"integrity": "sha1-oQHrrlnWUHNU1x2AE5UKOot6WlQ=",
"requires": {
"source-list-map": "2.0.0",
"source-map": "0.6.1"
@ -13761,7 +13744,7 @@
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
"integrity": "sha1-dHIq8y6WFOnCh6jQu95IteLxomM="
}
}
},