mirror of
https://github.com/embarklabs/embark-solc.git
synced 2025-02-28 14:30:36 +00:00
fix: fix race condition by using the new compiler api
This commit is contained in:
parent
1be928a525
commit
0fdea9d20c
48
index.js
48
index.js
@ -1,30 +1,38 @@
|
||||
/*global require, module*/
|
||||
const Compiler = require("./lib/Compiler");
|
||||
const semver = require('semver');
|
||||
|
||||
module.exports = (embark) => {
|
||||
if (embark.config.embarkConfig.versions.solc) {
|
||||
// Check solc version
|
||||
Compiler.getSolcVersion(embark.logger, (err, version) => {
|
||||
if (err) {
|
||||
embark.logger.error(err);
|
||||
embark.logger.error("Error getting solc's version. Will default back to Embark's commpiler");
|
||||
return;
|
||||
}
|
||||
const wantedVer = embark.config.embarkConfig.versions.solc.split('.').map(ver => parseInt(ver, 10));
|
||||
const currentVer = version.split('.').map(ver => parseInt(ver, 10));
|
||||
if (wantedVer[0] > currentVer[0] || wantedVer[1] > currentVer[1] || wantedVer[2] > currentVer[2]) {
|
||||
embark.logger.warn(`Current version of solc lower than version in embark.json`);
|
||||
embark.logger.warn(`Current: ${version} | Wanted: ${embark.config.embarkConfig.versions.solc}`);
|
||||
embark.logger.warn('Will default back to Embark\'s compiler');
|
||||
return;
|
||||
}
|
||||
|
||||
embark.registerCompiler('.sol', (contractFiles, options, cb) => {
|
||||
if (!contractFiles || !contractFiles.length) {
|
||||
return cb();
|
||||
const versionPromise = new Promise(function(resolve, reject) {
|
||||
// Check solc version
|
||||
Compiler.getSolcVersion(embark.logger, (err, version) => {
|
||||
if (err) {
|
||||
embark.logger.error(err);
|
||||
embark.logger.error("Error getting solc's version. Will default back to Embark's compiler");
|
||||
return reject(err);
|
||||
}
|
||||
Compiler.compileSolc(embark, contractFiles, embark.config.contractDirectories, cb);
|
||||
if (semver.lt(version, embark.config.embarkConfig.versions.solc)) {
|
||||
embark.logger.warn(`Current version of solc lower than version in embark.json`);
|
||||
embark.logger.warn(`Current: ${version} | Wanted: ${embark.config.embarkConfig.versions.solc}`);
|
||||
embark.logger.warn('Will default back to Embark\'s compiler');
|
||||
return reject(new Error('Bad version'));
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
||||
embark.registerCompiler('.sol', (contractFiles, options, cb) => {
|
||||
if (!contractFiles || !contractFiles.length) {
|
||||
return cb();
|
||||
}
|
||||
versionPromise.then(() => {
|
||||
Compiler.compileSolc(embark, contractFiles, embark.config.contractDirectories, cb);
|
||||
}).catch(_e => {
|
||||
// Need to default to Embark's compiler
|
||||
cb(null, false);
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
};
|
||||
|
7
package-lock.json
generated
7
package-lock.json
generated
@ -997,10 +997,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"semver": {
|
||||
"version": "5.5.1",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.5.1.tgz",
|
||||
"integrity": "sha512-PqpAxfrEhlSUWge8dwIp4tZnQ25DIOthpiaHNIthsjEFQD6EvqUKUDM7L8O2rShkFccYo1VjJR0coWfNkCubRw==",
|
||||
"dev": true
|
||||
"version": "5.6.0",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-5.6.0.tgz",
|
||||
"integrity": "sha512-RS9R6R35NYgQn++fkDWaOmqGoj4Ek9gGs+DPxNUZKuwE183xjJroKvyo1IzVFeXvUrvmALy6FWD5xrdJT25gMg=="
|
||||
},
|
||||
"shebang-command": {
|
||||
"version": "1.2.0",
|
||||
|
@ -25,6 +25,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"async": "^2.6.0",
|
||||
"semver": "^5.6.0",
|
||||
"shelljs": "^0.8.1"
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user