mirror of https://github.com/embarklabs/embark.git
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.
This commit is contained in:
parent
a046acb732
commit
eedcdc77a7
|
@ -0,0 +1,147 @@
|
||||||
|
{
|
||||||
|
// Use IntelliSense to learn about possible attributes.
|
||||||
|
// Hover to view descriptions of existing attributes.
|
||||||
|
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Embark: Mocha All",
|
||||||
|
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
|
||||||
|
"args": [
|
||||||
|
"--colors",
|
||||||
|
"--no-timeouts",
|
||||||
|
"${workspaceFolder}/test/"
|
||||||
|
],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Embark: Mocha Current File",
|
||||||
|
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
|
||||||
|
"args": [
|
||||||
|
"--colors",
|
||||||
|
"--no-timeouts",
|
||||||
|
"${file}"
|
||||||
|
],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Embark: embark test",
|
||||||
|
"autoAttachChildProcesses": true,
|
||||||
|
//"preLaunchTask": "npm_install",
|
||||||
|
"program": "${workspaceFolder}/lib/tests/test_embark",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Test app: Embark test",
|
||||||
|
"cwd": "${workspaceFolder}/test_apps/test_app/",
|
||||||
|
"autoAttachChildProcesses": true,
|
||||||
|
//"preLaunchTask": "npm_install",
|
||||||
|
"program": "${workspaceFolder}/bin/embark",
|
||||||
|
"args": [
|
||||||
|
"test"
|
||||||
|
],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Test app: Embark new testapp123",
|
||||||
|
"cwd": "${workspaceFolder}/test_apps/test_app/",
|
||||||
|
"autoAttachChildProcesses": true,
|
||||||
|
//"preLaunchTask": "npm_install",
|
||||||
|
"program": "${workspaceFolder}/bin/embark",
|
||||||
|
"args": [
|
||||||
|
"new",
|
||||||
|
"testapp123"
|
||||||
|
],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Test app: Embark upload",
|
||||||
|
"cwd": "${workspaceFolder}/test_apps/test_app/",
|
||||||
|
"autoAttachChildProcesses": true,
|
||||||
|
//"preLaunchTask": "npm_install",
|
||||||
|
"program": "${workspaceFolder}/bin/embark",
|
||||||
|
"args": [
|
||||||
|
"upload"
|
||||||
|
],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Test app: Embark run",
|
||||||
|
"cwd": "${workspaceFolder}/test_apps/test_app/",
|
||||||
|
"autoAttachChildProcesses": true,
|
||||||
|
//"preLaunchTask": "npm_install",
|
||||||
|
"program": "${workspaceFolder}/bin/embark",
|
||||||
|
"args": [
|
||||||
|
"run",
|
||||||
|
"--nodashboard"
|
||||||
|
],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Embark demo from main repo: Embark run",
|
||||||
|
"cwd": "${workspaceFolder}/../../embk-fw/embark/embark_demo/",
|
||||||
|
"autoAttachChildProcesses": true,
|
||||||
|
//"preLaunchTask": "npm_install",
|
||||||
|
"program": "${workspaceFolder}/bin/embark",
|
||||||
|
"args": [
|
||||||
|
"run"
|
||||||
|
],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Embark demo from dapp-bin: Embark run",
|
||||||
|
"cwd": "${workspaceFolder}/../../embk-fw/dapp-bin/embark_demo/",
|
||||||
|
"autoAttachChildProcesses": false,
|
||||||
|
//"preLaunchTask": "npm_install",
|
||||||
|
"program": "${workspaceFolder}/bin/embark",
|
||||||
|
"args": [
|
||||||
|
"run",
|
||||||
|
"--nodashboard"
|
||||||
|
],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "Embark react routes demo: Embark run",
|
||||||
|
"cwd": "${workspaceFolder}/../../emizzle/embark-demo-react-routes/",
|
||||||
|
"autoAttachChildProcesses": true,
|
||||||
|
//"preLaunchTask": "npm_install",
|
||||||
|
"program": "${workspaceFolder}/bin/embark",
|
||||||
|
"args": [
|
||||||
|
"run"
|
||||||
|
],
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"internalConsoleOptions": "neverOpen"
|
||||||
|
}
|
||||||
|
|
||||||
|
]
|
||||||
|
}
|
|
@ -61,10 +61,10 @@ class IPFS {
|
||||||
return cb({name: "IPFS ", status: 'off'});
|
return cb({name: "IPFS ", status: 'off'});
|
||||||
}
|
}
|
||||||
if (body.Version) {
|
if (body.Version) {
|
||||||
self.logger.trace("Swarm available");
|
self.logger.trace("IPFS available");
|
||||||
return cb({name: ("IPFS " + body.Version), status: 'on'});
|
return cb({name: ("IPFS " + body.Version), status: 'on'});
|
||||||
}
|
}
|
||||||
self.logger.trace("Swarm available");
|
self.logger.trace("IPFS available");
|
||||||
return cb({name: "IPFS ", status: 'on'});
|
return cb({name: "IPFS ", status: 'on'});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -75,7 +75,10 @@ class Solidity {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.solcW.compile(jsonObj, function (output) {
|
self.solcW.compile(jsonObj, function (err, output) {
|
||||||
|
if(err){
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
if (output.errors) {
|
if (output.errors) {
|
||||||
for (let i=0; i<output.errors.length; i++) {
|
for (let i=0; i<output.errors.length; i++) {
|
||||||
if (output.errors[i].type === 'Warning') {
|
if (output.errors[i].type === 'Warning') {
|
||||||
|
|
|
@ -3,10 +3,18 @@ const path = require('path');
|
||||||
const constants = require('../../constants');
|
const constants = require('../../constants');
|
||||||
const Utils = require('../../utils/utils');
|
const Utils = require('../../utils/utils');
|
||||||
const ProcessWrapper = require('../../process/processWrapper');
|
const ProcessWrapper = require('../../process/processWrapper');
|
||||||
const PluginManager = require('live-plugin-manager').PluginManager;
|
const PluginManager = require('live-plugin-manager-git-fix').PluginManager;
|
||||||
|
const NpmTimer = require('../../versions/npmTimer');
|
||||||
|
|
||||||
|
|
||||||
class SolcProcess extends ProcessWrapper {
|
class SolcProcess extends ProcessWrapper {
|
||||||
|
|
||||||
|
constructor(options){
|
||||||
|
super();
|
||||||
|
this._logger = options.logger;
|
||||||
|
this._npm = options.npm;
|
||||||
|
}
|
||||||
|
|
||||||
findImports(filename) {
|
findImports(filename) {
|
||||||
if (filename.startsWith('http') || filename.startsWith('git')) {
|
if (filename.startsWith('http') || filename.startsWith('git')) {
|
||||||
const fileObj = Utils.getExternalContractUrl(filename);
|
const fileObj = Utils.getExternalContractUrl(filename);
|
||||||
|
@ -26,46 +34,57 @@ class SolcProcess extends ProcessWrapper {
|
||||||
|
|
||||||
installAndLoadCompiler(solcVersion, packagePath){
|
installAndLoadCompiler(solcVersion, packagePath){
|
||||||
let self = this;
|
let self = this;
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
let manager = new PluginManager({pluginsPath: packagePath});
|
let manager = new PluginManager({pluginsPath: packagePath});
|
||||||
|
let timer;
|
||||||
|
if (!fs.existsSync(packagePath)) {
|
||||||
|
timer = new NpmTimer({logger: self._logger, packageName: 'solc', version: solcVersion, showSpinner: true});
|
||||||
|
}
|
||||||
|
|
||||||
|
if(timer) timer.start();
|
||||||
manager.install('solc', solcVersion).then(() => {
|
manager.install('solc', solcVersion).then(() => {
|
||||||
self.solc = manager.require('solc');
|
self.solc = manager.require('solc');
|
||||||
|
if(timer) timer.end();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
compile(jsonObj, cb) {
|
compile(jsonObj, cb) {
|
||||||
// TODO: only available in 0.4.11; need to make versions warn about this
|
// TODO: only available in 0.4.11; need to make versions warn about this
|
||||||
let output = this.solc.compileStandardWrapper(JSON.stringify(jsonObj), this.findImports);
|
try {
|
||||||
cb(output);
|
let output = this.solc.compileStandardWrapper(JSON.stringify(jsonObj), this.findImports);
|
||||||
|
cb(null, output);
|
||||||
|
} catch (err) {
|
||||||
|
cb(err.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let solcProcess;
|
let solcProcess;
|
||||||
|
process.on('message', (msg) => {
|
||||||
process.on('message', function (msg) {
|
|
||||||
if (msg.action === "init") {
|
if (msg.action === "init") {
|
||||||
solcProcess = new SolcProcess(msg.options);
|
solcProcess = new SolcProcess(msg.options);
|
||||||
return this.send({result: "initiated"});
|
return process.send({result: "initiated"});
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (msg.action === 'loadCompiler') {
|
else if (msg.action === 'loadCompiler') {
|
||||||
require('solc');
|
solcProcess.solc = require('solc');
|
||||||
return this.send({result: "loadedCompiler"});
|
return process.send({result: "loadedCompiler"});
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (msg.action == 'installAndLoadCompiler') {
|
else if (msg.action == 'installAndLoadCompiler') {
|
||||||
solcProcess.installAndLoadCompiler(msg.solcVersion, msg.packagePath).then(() => {
|
solcProcess.installAndLoadCompiler(msg.solcVersion, msg.packagePath).then(() => {
|
||||||
return this.send({result: "loadedCompiler"});
|
return process.send({result: "loadedCompiler"});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (msg.action === 'compile') {
|
else if (msg.action === 'compile') {
|
||||||
solcProcess.compile(msg.jsonObj, (output) => {
|
solcProcess.compile(msg.jsonObj, (err, output) => {
|
||||||
this.send({result: "compilation-" + msg.id, output: output});
|
process.send({result: "compilation-" + msg.id, err: err, output: output});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -60,8 +60,7 @@ class SolcW {
|
||||||
self.compilerLoaded = true;
|
self.compilerLoaded = true;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
this.solcProcess.send({action: "init", options: {logger: self.logger}});
|
||||||
this.solcProcess.send({action: "init", options: {}});
|
|
||||||
|
|
||||||
if (this.ipc.isServer()) {
|
if (this.ipc.isServer()) {
|
||||||
this.ipc.on('compile', self.compile.bind(this));
|
this.ipc.on('compile', self.compile.bind(this));
|
||||||
|
@ -80,7 +79,10 @@ class SolcW {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.solcProcess.once('result', 'compilation-' + id, (msg) => {
|
this.solcProcess.once('result', 'compilation-' + id, (msg) => {
|
||||||
done(JSON.parse(msg.output));
|
if(msg.err) {
|
||||||
|
return done(msg.err);
|
||||||
|
}
|
||||||
|
done(null, JSON.parse(msg.output));
|
||||||
});
|
});
|
||||||
|
|
||||||
this.solcProcess.send({action: 'compile', jsonObj: jsonObj, id});
|
this.solcProcess.send({action: 'compile', jsonObj: jsonObj, id});
|
||||||
|
|
|
@ -80,7 +80,12 @@ class Swarm {
|
||||||
let currentPIterationVersion = require('../../../package.json').dependencies["p-iteration"];
|
let currentPIterationVersion = require('../../../package.json').dependencies["p-iteration"];
|
||||||
if (pIterationVersion !== currentPIterationVersion) {
|
if (pIterationVersion !== currentPIterationVersion) {
|
||||||
self.events.request("version:getPackageLocation", "p-iteration", pIterationVersion, function(err, location) {
|
self.events.request("version:getPackageLocation", "p-iteration", pIterationVersion, function(err, location) {
|
||||||
self.embark.registerImportFile("p-iteration", fs.dappPath(location));
|
if(!err){
|
||||||
|
self.embark.registerImportFile("p-iteration", fs.dappPath(location));
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
self.logger.error("Error getting package location for p-iteration: " + err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -64,13 +64,12 @@ class LibraryManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
listenToCommandsToGetLibrary() {
|
listenToCommandsToGetLibrary() {
|
||||||
|
let npm = new Npm({logger: this.embark.logger});
|
||||||
this.embark.events.setCommandHandler('version:getPackageLocation', (libName, version, cb) => {
|
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);
|
npm.getPackageVersion(libName, version, cb);
|
||||||
});
|
});
|
||||||
this.embark.events.setCommandHandler('version:getPackagePath', (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.getPackagePath(libName, version));
|
||||||
cb(null, npm.packagePath);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,128 +1,57 @@
|
||||||
const fs = require('../core/fs.js');
|
const fs = require('../core/fs.js');
|
||||||
const {PerformanceObserver, performance} = require('perf_hooks');
|
|
||||||
const PluginManager = require('live-plugin-manager-git-fix').PluginManager;
|
const PluginManager = require('live-plugin-manager-git-fix').PluginManager;
|
||||||
require('colors');
|
require('colors');
|
||||||
const _ = require('underscore');
|
const NpmTimer = require('./npmTimer');
|
||||||
|
|
||||||
class Npm {
|
class Npm {
|
||||||
|
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.logger = options.logger;
|
this._logger = options.logger;
|
||||||
this.packageName = options.packageName;
|
this._packageName = options.packageName;
|
||||||
this.version = options.version;
|
this._version = options.version;
|
||||||
|
this._installing = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
get packagePath(){
|
static getPackagePath(packageName, version){
|
||||||
if(typeof this._packagePath == 'undefined'){
|
return './.embark/versions/' + packageName + '/' + version + '/' + packageName;
|
||||||
this._packagePath = './.embark/versions/' + this.packageName + '/' + this.version + '/';
|
|
||||||
}
|
|
||||||
return this._packagePath;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get pluginManager(){
|
_isInstalling(packageName, version){
|
||||||
if(typeof this._pluginManager == 'undefined'){
|
return typeof this._installing[packageName + version] != 'undefined';
|
||||||
this._pluginManager = new PluginManager({pluginsPath: this.packagePath});
|
|
||||||
}
|
|
||||||
return this._pluginManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getPackageVersion(packageName, version, callback) {
|
getPackageVersion(packageName, version, callback) {
|
||||||
|
const packagePath = Npm.getPackagePath(packageName, version);
|
||||||
|
|
||||||
if (fs.existsSync(this.packagePath + packageName)) {
|
// check if this package already exists in the filesystem
|
||||||
return callback(null, this.packagePath + packageName);
|
if (fs.existsSync(packagePath)) {
|
||||||
|
return callback(null, packagePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.info(__("Downloading and installing {{packageName}} {{version}}...", {packageName: packageName, version: version}));
|
const pluginManager = new PluginManager({pluginsPath: './.embark/versions/' + packageName + '/' + version + '/'});
|
||||||
|
|
||||||
const obsMeasure = new PerformanceObserver((items) => {
|
|
||||||
let entry;
|
|
||||||
let strDuration;
|
|
||||||
|
|
||||||
// find any download ongoing measurements we've made
|
|
||||||
entry = _.last(_.where(items.getEntries(), {name: downloadOngoing}));
|
|
||||||
if(entry){
|
|
||||||
// ongoing performance mark
|
|
||||||
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 and installing {{packageName}} {{version}} in {{duration}}ms', {packageName: packageName, version: version, duration: entry.duration});
|
|
||||||
performance.clearMarks();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// log our measurement and make it red if it has taken too long
|
|
||||||
if(entry && strDuration){
|
|
||||||
if(entry.duration > 4000){
|
|
||||||
strDuration = strDuration.red;
|
|
||||||
}
|
|
||||||
this.logger.info(strDuration);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
obsMeasure.observe({entryTypes: ['measure']});
|
|
||||||
|
|
||||||
// define mark and measurement names
|
|
||||||
let startMark = 'downloadStart' + packageName + version;
|
|
||||||
let ongoingMark = 'downloadOngoingMark' + packageName + version;
|
|
||||||
let downloadOngoing = 'downloadOngoing' + packageName + version;
|
|
||||||
let endMark = 'downloadEnd' + packageName + version;
|
|
||||||
let downloadComplete = 'downloadComplete' + packageName + version;
|
|
||||||
|
|
||||||
// mark our start time
|
|
||||||
performance.mark(startMark);
|
|
||||||
|
|
||||||
// function that continually updates the console to show user that we're downloading a library
|
// check if we're already installing this package
|
||||||
let intOngoingDownload = setInterval(
|
if(this._isInstalling(packageName, version)){
|
||||||
function(){
|
this._installing[packageName + version].push(callback);
|
||||||
performance.mark(ongoingMark);
|
}else{
|
||||||
performance.measure(downloadOngoing, startMark, ongoingMark);
|
this._installing[packageName + version] = new Array(callback);
|
||||||
}, 750);
|
|
||||||
|
|
||||||
// do the package download/install
|
|
||||||
this.pluginManager.install(packageName, version).then((result) => {
|
const timer = new NpmTimer({logger: this._logger, packageName: packageName, version: version});
|
||||||
|
timer.start();
|
||||||
|
|
||||||
// if(packageName === 'solc'){
|
// do the package download/install
|
||||||
|
pluginManager.install(packageName, version).then((result) => {
|
||||||
// async.each(Object.keys(result.dependencies), function(dependency, cb){
|
timer.end();
|
||||||
|
this._installing[packageName + version].forEach((cb) => {
|
||||||
// console.log('getting dependency: ' + dependency + ' ' + result.dependencies[dependency]);
|
cb(null, result.location);
|
||||||
|
});
|
||||||
// self.pluginManager.install(dependency, result.dependencies[dependency]).then(() => {
|
delete this._installing[packageName + version];
|
||||||
// console.log('installed ' + dependency + ' ' + result.dependencies[dependency]);
|
//callback(null, result.location);
|
||||||
// cb();
|
}).catch(err => {
|
||||||
// })
|
callback(err);
|
||||||
// .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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,109 @@
|
||||||
|
const {PerformanceObserver, performance} = require('perf_hooks');
|
||||||
|
const _ = require('underscore');
|
||||||
|
require('colors');
|
||||||
|
const i18n = require('../i18n/i18n.js');
|
||||||
|
i18n.setOrDetectLocale('en');
|
||||||
|
|
||||||
|
|
||||||
|
class NpmTimer{
|
||||||
|
constructor(options){
|
||||||
|
this._logger = options.logger;
|
||||||
|
this._packageName = options.packageName;
|
||||||
|
this._version = options.version;
|
||||||
|
this._showSpinner = options.showSpinner || false;
|
||||||
|
this._spinnerStyle = options.spinnerStyle || 'dots';
|
||||||
|
this._interval = options.interval || 750;
|
||||||
|
|
||||||
|
// define mark and measurement names
|
||||||
|
this._startMark = 'downloadStart' + this._packageName + this._version;
|
||||||
|
this._ongoingMark = 'downloadOngoingMark' + this._packageName + this._version;
|
||||||
|
this._downloadOngoing = 'downloadOngoing' + this._packageName + this._version;
|
||||||
|
this._endMark = 'downloadEnd' + this._packageName + this._version;
|
||||||
|
this._downloadComplete = 'downloadComplete' + this._packageName + this._version;
|
||||||
|
|
||||||
|
this.observer.observe({entryTypes: ['measure']});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
get observer(){
|
||||||
|
if(typeof this._observer == 'undefined'){
|
||||||
|
this._observer = new PerformanceObserver((items) => {
|
||||||
|
let entry;
|
||||||
|
let strDuration;
|
||||||
|
|
||||||
|
// find any download ongoing measurements we've made
|
||||||
|
entry = _.last(_.where(items.getEntries(), {name: this._downloadOngoing}));
|
||||||
|
if(entry){
|
||||||
|
// ongoing performance mark
|
||||||
|
strDuration = __('Downloading and installing {{packageName}} {{version}}... ({{duration}}ms elapsed)', {packageName: this._packageName, version: this._version, duration: entry.duration});
|
||||||
|
if(this._spinner) this._spinner.text = strDuration;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
// otherwise, find our download complete measurement
|
||||||
|
entry = _.last(_.where(items.getEntries(), {name: this._downloadComplete}));
|
||||||
|
|
||||||
|
if(entry){
|
||||||
|
strDuration = __('Finished downloading and installing {{packageName}} {{version}} in {{duration}}ms', {packageName: this._packageName, version: this._version, duration: entry.duration});
|
||||||
|
performance.clearMarks();
|
||||||
|
if(this._spinner) this._spinner.succeed(strDuration);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// log our measurement and make it red if it has taken too long
|
||||||
|
if(!this._showSpinner && entry && strDuration){
|
||||||
|
if(entry.duration > 4000){
|
||||||
|
strDuration = strDuration.red;
|
||||||
|
}
|
||||||
|
this._log(strDuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return this._observer;
|
||||||
|
}
|
||||||
|
|
||||||
|
_log(msg){
|
||||||
|
if(typeof this._logger.info == 'function'){
|
||||||
|
this._logger.info(msg);
|
||||||
|
}
|
||||||
|
else{ // occurs in subprocess as functions are not serialised/deserialised properly
|
||||||
|
console.log(msg.green);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
start(){
|
||||||
|
let self = this;
|
||||||
|
|
||||||
|
const strDownloadStart = __("Downloading and installing {{packageName}} {{version}}...", {packageName: this._packageName, version: this._version});
|
||||||
|
if(this._showSpinner){
|
||||||
|
const ora = require('ora');
|
||||||
|
this._spinner = ora({
|
||||||
|
spinner: this._spinnerStyle,
|
||||||
|
text: strDownloadStart
|
||||||
|
}).start();
|
||||||
|
}else{
|
||||||
|
this._log(strDownloadStart);
|
||||||
|
}
|
||||||
|
|
||||||
|
// mark our start time
|
||||||
|
performance.mark(this._startMark);
|
||||||
|
|
||||||
|
// function that continually updates the console to show user that we're downloading a library
|
||||||
|
this._intOngoingDownload = setInterval(
|
||||||
|
function(){
|
||||||
|
self._log('npmTimer: hit an interval');
|
||||||
|
performance.mark(self._ongoingMark);
|
||||||
|
performance.measure(self._downloadOngoing, self._startMark, self._ongoingMark);
|
||||||
|
}, this._interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
end(){
|
||||||
|
// stop updating console for ongoing download
|
||||||
|
clearInterval(this._intOngoingDownload);
|
||||||
|
performance.mark(this._endMark);
|
||||||
|
performance.measure(this._downloadComplete, this._startMark, this._endMark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = NpmTimer;
|
|
@ -2344,9 +2344,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"cli-spinners": {
|
"cli-spinners": {
|
||||||
"version": "0.1.2",
|
"version": "1.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-0.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-1.3.1.tgz",
|
||||||
"integrity": "sha1-u3ZNiOGF+54eaiofGXcjGPYF4xw="
|
"integrity": "sha512-1QL4544moEsDVH9T/l6Cemov/37iv1RtoKf7NJ04A60+4MREXNfx/QvavbH6QoGdsD4N4Mwy49cmaINR/o2mdg=="
|
||||||
},
|
},
|
||||||
"cli-table": {
|
"cli-table": {
|
||||||
"version": "0.3.1",
|
"version": "0.3.1",
|
||||||
|
@ -3037,6 +3037,14 @@
|
||||||
"integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=",
|
"integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"defaults": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz",
|
||||||
|
"integrity": "sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=",
|
||||||
|
"requires": {
|
||||||
|
"clone": "1.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"deferred-leveldown": {
|
"deferred-leveldown": {
|
||||||
"version": "1.2.2",
|
"version": "1.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/deferred-leveldown/-/deferred-leveldown-1.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/deferred-leveldown/-/deferred-leveldown-1.2.2.tgz",
|
||||||
|
@ -6986,6 +6994,19 @@
|
||||||
"strip-ansi": "3.0.1"
|
"strip-ansi": "3.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"cli-cursor": {
|
||||||
|
"version": "1.0.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-1.0.2.tgz",
|
||||||
|
"integrity": "sha1-ZNo/fValRBLll5S9Ytw1KV6PKYc=",
|
||||||
|
"requires": {
|
||||||
|
"restore-cursor": "1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"cli-spinners": {
|
||||||
|
"version": "0.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-0.1.2.tgz",
|
||||||
|
"integrity": "sha1-u3ZNiOGF+54eaiofGXcjGPYF4xw="
|
||||||
|
},
|
||||||
"figures": {
|
"figures": {
|
||||||
"version": "1.7.0",
|
"version": "1.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/figures/-/figures-1.7.0.tgz",
|
||||||
|
@ -7008,6 +7029,31 @@
|
||||||
"chalk": "1.1.3"
|
"chalk": "1.1.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"onetime": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
|
||||||
|
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k="
|
||||||
|
},
|
||||||
|
"ora": {
|
||||||
|
"version": "0.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/ora/-/ora-0.2.3.tgz",
|
||||||
|
"integrity": "sha1-N1J9Igrc1Tw5tzVx11QVbV22V6Q=",
|
||||||
|
"requires": {
|
||||||
|
"chalk": "1.1.3",
|
||||||
|
"cli-cursor": "1.0.2",
|
||||||
|
"cli-spinners": "0.1.2",
|
||||||
|
"object-assign": "4.1.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"restore-cursor": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-NGYfRohjJ/7SmRR5FSJS35LapUE=",
|
||||||
|
"requires": {
|
||||||
|
"exit-hook": "1.1.1",
|
||||||
|
"onetime": "1.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"rxjs": {
|
"rxjs": {
|
||||||
"version": "6.2.0",
|
"version": "6.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.2.0.tgz",
|
||||||
|
@ -9037,36 +9083,60 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ora": {
|
"ora": {
|
||||||
"version": "0.2.3",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/ora/-/ora-0.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/ora/-/ora-2.1.0.tgz",
|
||||||
"integrity": "sha1-N1J9Igrc1Tw5tzVx11QVbV22V6Q=",
|
"integrity": "sha512-hNNlAd3gfv/iPmsNxYoAPLvxg7HuPozww7fFonMZvL84tP6Ox5igfk5j/+a9rtJJwqMgKK+JgWsAQik5o0HTLA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"chalk": "1.1.3",
|
"chalk": "2.4.1",
|
||||||
"cli-cursor": "1.0.2",
|
"cli-cursor": "2.1.0",
|
||||||
"cli-spinners": "0.1.2",
|
"cli-spinners": "1.3.1",
|
||||||
"object-assign": "4.1.1"
|
"log-symbols": "2.2.0",
|
||||||
|
"strip-ansi": "4.0.0",
|
||||||
|
"wcwidth": "1.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cli-cursor": {
|
"ansi-regex": {
|
||||||
"version": "1.0.2",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
|
||||||
"integrity": "sha1-ZNo/fValRBLll5S9Ytw1KV6PKYc=",
|
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg="
|
||||||
|
},
|
||||||
|
"ansi-styles": {
|
||||||
|
"version": "3.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
|
||||||
|
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"restore-cursor": "1.0.1"
|
"color-convert": "1.9.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"onetime": {
|
"chalk": {
|
||||||
"version": "1.1.0",
|
"version": "2.4.1",
|
||||||
"resolved": "http://registry.npmjs.org/onetime/-/onetime-1.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.1.tgz",
|
||||||
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k="
|
"integrity": "sha512-ObN6h1v2fTJSmUXoS3nMQ92LbDK9be4TV+6G+omQlGJFdcUX5heKi1LZ1YnRMIgwTLEj3E24bT6tYni50rlCfQ==",
|
||||||
},
|
|
||||||
"restore-cursor": {
|
|
||||||
"version": "1.0.1",
|
|
||||||
"resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-1.0.1.tgz",
|
|
||||||
"integrity": "sha1-NGYfRohjJ/7SmRR5FSJS35LapUE=",
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"exit-hook": "1.1.1",
|
"ansi-styles": "3.2.1",
|
||||||
"onetime": "1.1.0"
|
"escape-string-regexp": "1.0.5",
|
||||||
|
"supports-color": "5.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"has-flag": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
||||||
|
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
|
||||||
|
},
|
||||||
|
"strip-ansi": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
|
||||||
|
"integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
|
||||||
|
"requires": {
|
||||||
|
"ansi-regex": "3.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"supports-color": {
|
||||||
|
"version": "5.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz",
|
||||||
|
"integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==",
|
||||||
|
"requires": {
|
||||||
|
"has-flag": "3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12673,6 +12743,14 @@
|
||||||
"typechecker": "2.1.0"
|
"typechecker": "2.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"wcwidth": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g=",
|
||||||
|
"requires": {
|
||||||
|
"defaults": "1.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"web3": {
|
"web3": {
|
||||||
"version": "1.0.0-beta.34",
|
"version": "1.0.0-beta.34",
|
||||||
"resolved": "https://registry.npmjs.org/web3/-/web3-1.0.0-beta.34.tgz",
|
"resolved": "https://registry.npmjs.org/web3/-/web3-1.0.0-beta.34.tgz",
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
"babel-preset-es2017": "6.24.1",
|
"babel-preset-es2017": "6.24.1",
|
||||||
"babel-preset-react": "^6.24.1",
|
"babel-preset-react": "^6.24.1",
|
||||||
"bip39": "^2.5.0",
|
"bip39": "^2.5.0",
|
||||||
"neo-blessed": "^0.2.0",
|
|
||||||
"chokidar": "^2.0.3",
|
"chokidar": "^2.0.3",
|
||||||
"clone-deep": "^4.0.0",
|
"clone-deep": "^4.0.0",
|
||||||
"colors": "^1.1.2",
|
"colors": "^1.1.2",
|
||||||
|
@ -55,8 +54,10 @@
|
||||||
"ipfs-api": "17.2.4",
|
"ipfs-api": "17.2.4",
|
||||||
"live-plugin-manager-git-fix": "^0.12.1",
|
"live-plugin-manager-git-fix": "^0.12.1",
|
||||||
"merge": "^1.2.0",
|
"merge": "^1.2.0",
|
||||||
|
"neo-blessed": "^0.2.0",
|
||||||
"node-http-proxy": "^0.2.3",
|
"node-http-proxy": "^0.2.3",
|
||||||
"node-ipc": "^9.1.1",
|
"node-ipc": "^9.1.1",
|
||||||
|
"ora": "^2.1.0",
|
||||||
"os-locale": "^2.1.0",
|
"os-locale": "^2.1.0",
|
||||||
"p-iteration": "^1.1.7",
|
"p-iteration": "^1.1.7",
|
||||||
"parse-json": "^4.0.0",
|
"parse-json": "^4.0.0",
|
||||||
|
|
Loading…
Reference in New Issue