emizzle eedcdc77a7 Solc loading issue now fully resolved
Added better error checking for solidity compilation errors

Extracted timer functionality for downloading packages so it works across the main process and child processes.

Npm class is instantiated only once and reused for event commands.

Npm class can handle concurrent requests for the same package and callback the installation result for each request.
2018-06-15 17:02:53 -04:00

59 lines
1.8 KiB
JavaScript

const fs = require('../core/fs.js');
const PluginManager = require('live-plugin-manager-git-fix').PluginManager;
require('colors');
const NpmTimer = require('./npmTimer');
class Npm {
constructor(options) {
this._logger = options.logger;
this._packageName = options.packageName;
this._version = options.version;
this._installing = {};
}
static getPackagePath(packageName, version){
return './.embark/versions/' + packageName + '/' + version + '/' + packageName;
}
_isInstalling(packageName, version){
return typeof this._installing[packageName + version] != 'undefined';
}
getPackageVersion(packageName, version, callback) {
const packagePath = Npm.getPackagePath(packageName, version);
// check if this package already exists in the filesystem
if (fs.existsSync(packagePath)) {
return callback(null, packagePath);
}
const pluginManager = new PluginManager({pluginsPath: './.embark/versions/' + packageName + '/' + version + '/'});
// check if we're already installing this package
if(this._isInstalling(packageName, version)){
this._installing[packageName + version].push(callback);
}else{
this._installing[packageName + version] = new Array(callback);
const timer = new NpmTimer({logger: this._logger, packageName: packageName, version: version});
timer.start();
// do the package download/install
pluginManager.install(packageName, version).then((result) => {
timer.end();
this._installing[packageName + version].forEach((cb) => {
cb(null, result.location);
});
delete this._installing[packageName + version];
//callback(null, result.location);
}).catch(err => {
callback(err);
});
}
}
}
module.exports = Npm;