mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-01-11 06:25:57 +00:00
eedcdc77a7
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.
59 lines
1.8 KiB
JavaScript
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;
|