From 5e4a80edec7ef1e8fb2dedf7dc618bf3e56c2f55 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Thu, 14 Mar 2019 09:57:48 -0400 Subject: [PATCH] fix(embark/storage): fix hang when storage is disabled --- packages/embark/src/lib/core/engine.js | 6 +-- packages/embark/src/lib/modules/ipfs/index.js | 46 ++++++++++--------- .../embark/src/lib/modules/storage/index.js | 16 ++++++- .../embark/src/lib/modules/swarm/index.js | 4 +- 4 files changed, 43 insertions(+), 29 deletions(-) diff --git a/packages/embark/src/lib/core/engine.js b/packages/embark/src/lib/core/engine.js index 3f532dd40..15fafd5d4 100644 --- a/packages/embark/src/lib/core/engine.js +++ b/packages/embark/src/lib/core/engine.js @@ -192,7 +192,7 @@ class Engine { this.registerModule('code_generator', {plugins: self.plugins, env: self.env}); const generateCode = function (modifiedAssets) { - self.events.request("module:storage:initiated", () => { + self.events.request("module:storage:onReady", () => { self.events.request("code-generator:embarkjs:build", () => { self.events.emit('code-generator-ready', modifiedAssets); }); @@ -278,15 +278,15 @@ class Engine { if (!this.config.storageConfig.available_providers.includes("ipfs")) { return next(); } - this.registerModule('ipfs'); this.events.on("ipfs:process:started", next); + this.registerModule('ipfs'); }, (next) => { if (!this.config.storageConfig.available_providers.includes("swarm")) { return next(); } - this.registerModule('swarm'); this.events.on("swarm:process:started", next); + this.registerModule('swarm'); } ], (err) => { if(err) { diff --git a/packages/embark/src/lib/modules/ipfs/index.js b/packages/embark/src/lib/modules/ipfs/index.js index 5da6d61ef..6476ff597 100644 --- a/packages/embark/src/lib/modules/ipfs/index.js +++ b/packages/embark/src/lib/modules/ipfs/index.js @@ -20,29 +20,31 @@ class IPFS { this.webServerConfig = embark.config.webServerConfig; this.blockchainConfig = embark.config.blockchainConfig; - if (this.isIpfsStorageEnabledInTheConfig()) { - this.setServiceCheck(); - this.registerUploadCommand(); - - this.events.request("processes:register", "ipfs", (cb) => { - this.startProcess(() => { - this.addStorageProviderToEmbarkJS(); - this.addObjectToConsole(); - this.events.emit("ipfs:process:started"); - cb(); - }); - }); - - this._checkService((err) => { - if (!err) { - return; - } - this.logger.info("IPFS node not found, attempting to start own node"); - this.listenToCommands(); - this.registerConsoleCommands(); - this.events.request('processes:launch', 'ipfs'); - }); + if (!this.isIpfsStorageEnabledInTheConfig()) { + return this.events.emit("ipfs:process:started", false); } + + this.setServiceCheck(); + this.registerUploadCommand(); + + this.events.request("processes:register", "ipfs", (cb) => { + this.startProcess(() => { + this.addStorageProviderToEmbarkJS(); + this.addObjectToConsole(); + this.events.emit("ipfs:process:started"); + cb(); + }); + }); + + this._checkService((err) => { + if (!err) { + return; + } + this.logger.info("IPFS node not found, attempting to start own node"); + this.listenToCommands(); + this.registerConsoleCommands(); + this.events.request('processes:launch', 'ipfs'); + }); } downloadIpfsApi(cb) { diff --git a/packages/embark/src/lib/modules/storage/index.js b/packages/embark/src/lib/modules/storage/index.js index 3a20d4b43..b7de558ab 100644 --- a/packages/embark/src/lib/modules/storage/index.js +++ b/packages/embark/src/lib/modules/storage/index.js @@ -3,12 +3,24 @@ class Storage { this.embark = embark; this.storageConfig = embark.config.storageConfig; this.plugins = options.plugins; + this.ready = false; - if (!this.storageConfig.enabled) return; + this.embark.events.setCommandHandler("module:storage:onReady", (cb) => { + if (this.ready) { + return cb(); + } + this.embark.events.once("module:storage:ready", cb); + }); + + if (!this.storageConfig.enabled) { + this.ready = true; + return; + } this.handleUploadCommand(); this.addSetProviders(() => { - this.embark.events.setCommandHandler("module:storage:initiated", (cb) => { cb(); }); + this.ready = true; + this.embark.events.emit("module:storage:ready"); }); } diff --git a/packages/embark/src/lib/modules/swarm/index.js b/packages/embark/src/lib/modules/swarm/index.js index 9d707c16a..23ff6a840 100644 --- a/packages/embark/src/lib/modules/swarm/index.js +++ b/packages/embark/src/lib/modules/swarm/index.js @@ -26,7 +26,7 @@ class Swarm { if (this.isSwarmEnabledInTheConfig() && cantDetermineUrl) { console.warn('\n===== Swarm module will not be loaded ====='); console.warn(`Swarm is enabled in the config, however the config is not setup to provide a URL for swarm and therefore the Swarm module will not be loaded. Please either change the ${'config/storage > upload'.bold} setting to Swarm or add the Swarm config to the ${'config/storage > dappConnection'.bold} array. Please see ${'https://embark.status.im/docs/storage_configuration.html'.underline} for more information.\n`); - return; + return this.events.emit("swarm:process:started", false); } if (!this.isSwarmEnabledInTheConfig()) { this.embark.registerConsoleCommand({ @@ -36,7 +36,7 @@ class Swarm { cb(); } }); - return; + return this.events.emit("swarm:process:started", false); } this.providerUrl = utils.buildUrl(this.storageConfig.upload.protocol, this.storageConfig.upload.host, this.storageConfig.upload.port);