emizzle a100dd4260 Requested PR fixes
Added catch to live-plugin-manager install promise running in child process

Removed some `else`'s ;)

Only showing solc downloading spinner when `--nodashboard` option is used.

When installing package in main process and simultaneous downloads fail, all callbacks called with error.

Updated logging in npmTimer.
2018-06-15 17:06:59 -04:00

60 lines
1.9 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] = [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 => {
this._installing[packageName + version].forEach((cb) => {
cb(err);
});
});
}
}
}
module.exports = Npm;