diff --git a/dapps/templates/boilerplate/embark.json b/dapps/templates/boilerplate/embark.json index 19d902845..ec7345cfc 100644 --- a/dapps/templates/boilerplate/embark.json +++ b/dapps/templates/boilerplate/embark.json @@ -12,6 +12,13 @@ "solc": "0.6.1" }, "plugins": { + "embark-ipfs": {}, + "embark-swarm": {}, + "embark-whisper-geth": {}, + "embark-geth": {}, + "embark-parity": {}, + "embark-profiler": {}, + "embark-graph": {} }, "options": { "solc": { diff --git a/dapps/templates/boilerplate/package.json b/dapps/templates/boilerplate/package.json index 5ee56459c..d25b61516 100644 --- a/dapps/templates/boilerplate/package.json +++ b/dapps/templates/boilerplate/package.json @@ -40,6 +40,13 @@ "embarkjs-swarm": "^5.1.1", "embarkjs-web3": "^5.2.0-nightly.2", "embarkjs-whisper": "^5.1.1", + "embark-ipfs": "^5.2.0-nightly.1", + "embark-swarm": "^5.2.0-nightly.1", + "embark-whisper-geth": "^5.2.0-nightly.1", + "embark-geth": "^5.2.0-nightly.1", + "embark-parity": "^5.2.0-nightly.1", + "embark-profiler": "^5.1.1", + "embark-graph": "^5.1.1", "rimraf": "3.0.0" } } diff --git a/dapps/templates/demo/embark.json b/dapps/templates/demo/embark.json index 082d43b54..09d8a1307 100644 --- a/dapps/templates/demo/embark.json +++ b/dapps/templates/demo/embark.json @@ -12,6 +12,13 @@ "solc": "0.6.1" }, "plugins": { + "embark-ipfs": {}, + "embark-swarm": {}, + "embark-whisper-geth": {}, + "embark-geth": {}, + "embark-parity": {}, + "embark-profiler": {}, + "embark-graph": {} }, "options": { "solc": { diff --git a/dapps/templates/demo/package.json b/dapps/templates/demo/package.json index 58d0479c7..770bf6ddf 100644 --- a/dapps/templates/demo/package.json +++ b/dapps/templates/demo/package.json @@ -42,6 +42,13 @@ "embarkjs-swarm": "^5.1.1", "embarkjs-web3": "^5.2.0-nightly.2", "embarkjs-whisper": "^5.1.1", + "embark-ipfs": "^5.2.0-nightly.1", + "embark-swarm": "^5.2.0-nightly.1", + "embark-whisper-geth": "^5.2.0-nightly.1", + "embark-geth": "^5.2.0-nightly.1", + "embark-parity": "^5.2.0-nightly.1", + "embark-profiler": "^5.1.1", + "embark-graph": "^5.1.1", "jquery": "3.4.1", "popper.js": "1.15.0", "react": "16.12.0", diff --git a/dapps/templates/simple/embark.json b/dapps/templates/simple/embark.json index 27b1b6716..9c3ff7a28 100644 --- a/dapps/templates/simple/embark.json +++ b/dapps/templates/simple/embark.json @@ -13,6 +13,10 @@ "solc": "0.6.1" }, "plugins": { + "embark-geth": {}, + "embark-parity": {}, + "embark-profiler": {}, + "embark-graph": {} }, "options": { "solc": { diff --git a/dapps/templates/simple/package.json b/dapps/templates/simple/package.json index 4f8d786e6..24d7c9f8a 100644 --- a/dapps/templates/simple/package.json +++ b/dapps/templates/simple/package.json @@ -32,10 +32,11 @@ "embark-reset": "^5.1.1", "embarkjs": "^5.2.0-nightly.2", "embarkjs-ens": "^5.2.0-nightly.2", - "embarkjs-ipfs": "^5.1.1", - "embarkjs-swarm": "^5.1.1", "embarkjs-web3": "^5.2.0-nightly.2", - "embarkjs-whisper": "^5.1.1", + "embark-geth": "^5.2.0-nightly.2", + "embark-parity": "^5.2.0-nightly.2", + "embark-profiler": "^5.1.1", + "embark-graph": "^5.1.1", "rimraf": "3.0.0" } } diff --git a/dapps/tests/app/embark.json b/dapps/tests/app/embark.json index cef864cbc..976da4024 100644 --- a/dapps/tests/app/embark.json +++ b/dapps/tests/app/embark.json @@ -18,6 +18,13 @@ "solc": "0.4.26" }, "plugins": { + "embark-ipfs": {}, + "embark-swarm": {}, + "embark-whisper-geth": {}, + "embark-geth": {}, + "embark-parity": {}, + "embark-profiler": {}, + "embark-graph": {}, "embark-dapp-test-service": {} }, "options": { diff --git a/dapps/tests/app/package.json b/dapps/tests/app/package.json index e5e513935..6f219ce44 100644 --- a/dapps/tests/app/package.json +++ b/dapps/tests/app/package.json @@ -13,6 +13,13 @@ "embarkjs-swarm": "^5.1.1", "embarkjs-web3": "^5.2.0-nightly.2", "embarkjs-whisper": "^5.1.1", + "embark-ipfs": "^5.2.0-nightly.1", + "embark-swarm": "^5.2.0-nightly.1", + "embark-whisper-geth": "^5.2.0-nightly.1", + "embark-geth": "^5.2.0-nightly.1", + "embark-parity": "^5.2.0-nightly.1", + "embark-profiler": "^5.1.1", + "embark-graph": "^5.1.1", "fs-extra": "8.1.0", "haml": "0.4.3", "jquery": "3.4.0", diff --git a/dapps/tests/contracts/embark.json b/dapps/tests/contracts/embark.json index 2c762516c..89dc71622 100644 --- a/dapps/tests/contracts/embark.json +++ b/dapps/tests/contracts/embark.json @@ -15,5 +15,9 @@ "solc": "0.4.26" }, "plugins": { + "embark-geth": {}, + "embark-parity": {}, + "embark-profiler": {}, + "embark-graph": {} } } diff --git a/dapps/tests/contracts/package.json b/dapps/tests/contracts/package.json index 0d21b2d9b..e50a2e2b0 100644 --- a/dapps/tests/contracts/package.json +++ b/dapps/tests/contracts/package.json @@ -9,6 +9,13 @@ "embarkjs-swarm": "^5.1.1", "embarkjs-web3": "^5.2.0-nightly.2", "embarkjs-whisper": "^5.1.1", + "embark-ipfs": "^5.2.0-nightly.1", + "embark-swarm": "^5.2.0-nightly.1", + "embark-whisper-geth": "^5.2.0-nightly.1", + "embark-geth": "^5.2.0-nightly.1", + "embark-parity": "^5.2.0-nightly.1", + "embark-profiler": "^5.1.1", + "embark-graph": "^5.1.1", "rimraf": "3.0.0" }, "license": "MIT", diff --git a/packages/core/core/src/config.ts b/packages/core/core/src/config.ts index 6fecfa22d..b0e140868 100644 --- a/packages/core/core/src/config.ts +++ b/packages/core/core/src/config.ts @@ -100,6 +100,8 @@ export class Config { buildDir: any; + client: string; + dappPath = dappPath; constructor(options) { @@ -114,6 +116,7 @@ export class Config { this.events = options.events; this.context = options.context || [constants.contexts.any]; this.version = options.version; + this.client = options.client; this.registerEvents(); } @@ -194,7 +197,8 @@ export class Config { config: this, context: this.context, env: this.env, - version: this.version + version: this.version, + client: this.client }); this.loadEmbarkConfigFile(); diff --git a/packages/core/core/src/plugins.ts b/packages/core/core/src/plugins.ts index f10244aba..a6fb6c156 100644 --- a/packages/core/core/src/plugins.ts +++ b/packages/core/core/src/plugins.ts @@ -2,6 +2,7 @@ import * as fs from './fs'; import { Plugin } from './plugin'; import { EmbarkEmitter as Events } from './events'; import { Config } from './config'; +import { IPC } from './ipc'; import * as async from 'async'; import { dappPath, embarkPath } from 'embark-utils'; @@ -31,6 +32,8 @@ export class Plugins { version: string; + client: string; + static deprecated = { 'embarkjs-connector-web3': '4.1.0' }; @@ -46,6 +49,7 @@ export class Plugins { this.fs = fs; this.env = options.env; this.version = options.version; + this.client = options.client; } loadPlugins() { @@ -85,7 +89,8 @@ export class Plugins { plugins: this.plugins, fs: this.fs, isInternal: true, - context: this.context + context: this.context, + client: this.client }); this.plugins.push(pluginWrapper); return pluginWrapper; @@ -119,7 +124,8 @@ export class Plugins { fs: this.fs, isInternal: true, context: this.context, - env: this.env + env: this.env, + client: this.client }); const pluginInstance = pluginWrapper.loadInternalPlugin(); this.plugins.push(pluginWrapper); @@ -149,7 +155,8 @@ export class Plugins { fs: this.fs, isInternal: false, context: this.context, - version: this.version + version: this.version, + client: this.client }); pluginWrapper.loadPlugin(); this.plugins.push(pluginWrapper); diff --git a/packages/core/engine/src/index.ts b/packages/core/engine/src/index.ts index d60ec364f..c91e54b8f 100644 --- a/packages/core/engine/src/index.ts +++ b/packages/core/engine/src/index.ts @@ -57,8 +57,6 @@ export class Engine { package: any; - isDev: boolean | undefined; - constructor(options) { this.env = options.env; this.client = options.client; @@ -85,6 +83,9 @@ export class Engine { const options = _options || {}; this.events = options.events || this.events || new Events(); this.logger = this.logger || new Logger({context: this.context, logLevel: options.logLevel || this.logLevel || 'info', events: this.events, logFile: this.logFile}); + + this.ipc = new IPC({ logger: this.logger, ipcRole: this.ipcRole }); + this.config = new Config({ env: this.env, logger: this.logger, @@ -93,17 +94,17 @@ export class Engine { webServerConfig: this.webServerConfig, version: this.version, package: this.package, - locale: this.locale + locale: this.locale, + client: this.client, + ipc: this.ipc }); this.config.loadConfigFiles({embarkConfig: this.embarkConfig, interceptLogs: this.interceptLogs}); this.plugins = this.config.plugins; - this.isDev = this.config && this.config.blockchainConfig && (this.config.blockchainConfig.isDev || this.config.blockchainConfig.default); if (this.interceptLogs || this.interceptLogs === undefined) { interceptLogs(console, this.logger); } - this.ipc = new IPC({ logger: this.logger, ipcRole: this.ipcRole }); if (this.ipc.isClient()) { return this.ipc.connect((_err) => { callback(); @@ -268,20 +269,8 @@ export class Engine { blockchainComponents() { // plugins - this.registerModulePackage('embark-geth', { - client: this.client, - locale: this.locale, - isDev: this.isDev, - plugins: this.plugins, - ipc: this.ipc - }); - this.registerModulePackage('embark-parity', { - client: this.client, - locale: this.locale, - isDev: this.isDev, - plugins: this.plugins, - ipc: this.ipc - }); + this.registerModulePackage('embark-geth'); + this.registerModulePackage('embark-parity'); } testComponents(options) { diff --git a/packages/core/utils/src/index.ts b/packages/core/utils/src/index.ts index 8575f4c9b..a2dec93b3 100644 --- a/packages/core/utils/src/index.ts +++ b/packages/core/utils/src/index.ts @@ -5,7 +5,11 @@ const clipboardy = require('clipboardy'); import * as Serialize from './serialize'; export { Serialize }; +import { __ } from 'embark-i18n'; + import { canonicalHost } from './host'; +import * as findUp from 'find-up'; +import * as fs from 'fs-extra'; export { canonicalHost, defaultCorsHost, defaultHost, dockerHostSwap, isDocker } from './host'; export { downloadFile, findNextPort, getJson, httpGet, httpsGet, httpGetJson, httpsGetJson, pingEndpoint } from './network'; export { testRpcWithEndpoint, testWsEndpoint } from './check'; @@ -55,6 +59,10 @@ export { } from './pathUtils'; export { setUpEnv } from './env'; +import { + dappPath +} from './pathUtils'; + const { extendZeroAddressShorthand, replaceZeroAddressShorthand } = AddressUtils; export { compact, last, recursiveMerge, groupBy } from './collections'; @@ -300,3 +308,25 @@ export function isConstructor(obj) { export function isEs6Module(module) { return (typeof module === 'function' && isConstructor(module)) || (typeof module === 'object' && typeof module.default === 'function' && module.__esModule); } + +export function warnIfPackageNotDefinedLocally(packageName, warnFunc) { + const packageIsResolvable = findUp.sync("node_modules/" + packageName, {cwd: dappPath()}); + if (!packageIsResolvable) { + return warnFunc("== WARNING: " + packageName + " could not be resolved; ensure it is defined in your dapp's package.json dependencies and then run npm or yarn install; in future versions of embark this package should be a local dependency and configured as a plugin"); + } + + const dappPackage = fs.readJSONSync(dappPath("package.json")); + const { dependencies, devDependencies } = dappPackage; + if (!((dependencies && dependencies[packageName]) || (devDependencies && devDependencies[packageName]))) { + return warnFunc("== WARNING: it seems " + packageName + " is not defined in your dapp's package.json dependencies; In future versions of embark this package should be a local dependency and configured as a plugin"); + } + + const embarkConfig = fs.readJSONSync(dappPath("embark.json")); + if (!embarkConfig.plugins[packageName]) { + return warnFunc( + __("== WARNING: it seems %s is not defined in your Dapp's embark.json plugins;\nIn future versions of Embark, this package should be a local dependency and configured as a plugin", packageName) + ); + } + + return true; +} diff --git a/packages/plugins/geth/src/index.js b/packages/plugins/geth/src/index.js index 2539ac08a..4f7968dc4 100644 --- a/packages/plugins/geth/src/index.js +++ b/packages/plugins/geth/src/index.js @@ -7,19 +7,19 @@ import DevTxs from "./devtxs"; const constants = require('embark-core/constants'); class Geth { - constructor(embark, options) { + constructor(embark) { this.embark = embark; this.embarkConfig = embark.config.embarkConfig; this.blockchainConfig = embark.config.blockchainConfig; this.communicationConfig = embark.config.communicationConfig; // TODO get options from config instead of options - this.locale = options.locale; + this.locale = embark.config.locale; this.logger = embark.logger; - this.client = options.client; - this.isDev = options.isDev; + this.client = embark.client; this.events = embark.events; - this.plugins = options.plugins; + this.plugins = embark.plugins; this.shownNoAccountConfigMsg = false; // flag to ensure "no account config" message is only displayed once to the user + this.isDev = (this.blockchainConfig.isDev || this.blockchainConfig.default); if (!this.shouldInit()) { return; diff --git a/packages/plugins/graph/package.json b/packages/plugins/graph/package.json index 6ba44b84c..0607ab230 100644 --- a/packages/plugins/graph/package.json +++ b/packages/plugins/graph/package.json @@ -46,6 +46,7 @@ "dependencies": { "@babel/runtime-corejs3": "7.7.4", "async": "2.6.1", + "embark-utils": "^5.2.0-nightly.1", "core-js": "3.4.3", "viz.js": "1.8.2" }, diff --git a/packages/plugins/graph/src/index.js b/packages/plugins/graph/src/index.js index eea48389f..64280ae6c 100644 --- a/packages/plugins/graph/src/index.js +++ b/packages/plugins/graph/src/index.js @@ -1,3 +1,5 @@ +import { warnIfPackageNotDefinedLocally } from 'embark-utils'; + const async = require('async'); const Viz = require('viz.js'); @@ -7,6 +9,7 @@ class GraphGenerator { this.events = embark.events; this.events.setCommandHandler("graph:create", this.generate.bind(this)); + warnIfPackageNotDefinedLocally("embark-graph", this.embark.logger.warn.bind(this.embark.logger)); } /*eslint complexity: ["error", 21]*/ diff --git a/packages/plugins/graph/tsconfig.json b/packages/plugins/graph/tsconfig.json index 2121fd4b1..0dcc4cc43 100644 --- a/packages/plugins/graph/tsconfig.json +++ b/packages/plugins/graph/tsconfig.json @@ -8,5 +8,10 @@ "extends": "../../../tsconfig.base.json", "include": [ "src/**/*" + ], + "references": [ + { + "path": "../../core/utils" + } ] } diff --git a/packages/plugins/parity/src/index.js b/packages/plugins/parity/src/index.js index 57913c0b9..b5c84beec 100644 --- a/packages/plugins/parity/src/index.js +++ b/packages/plugins/parity/src/index.js @@ -7,18 +7,16 @@ const constants = require('embark-core/constants'); class Parity { - constructor(embark, options) { + constructor(embark) { this.embark = embark; this.embarkConfig = embark.config.embarkConfig; this.blockchainConfig = embark.config.blockchainConfig; // TODO get options from config instead of options - this.locale = options.locale; + this.locale = embark.config.locale; this.logger = embark.logger; - this.client = options.client; - this.isDev = options.isDev; + this.client = embark.client; this.events = embark.events; - this.plugins = options.plugins; - // let plugin = this.plugins.createPlugin('gethplugin', {}); + this.isDev = (this.blockchainConfig.isDev || this.blockchainConfig.default); if (!this.shouldInit()) { return; diff --git a/packages/plugins/profiler/package.json b/packages/plugins/profiler/package.json index 88c5a77e2..aa6a92bbb 100644 --- a/packages/plugins/profiler/package.json +++ b/packages/plugins/profiler/package.json @@ -48,6 +48,7 @@ "ascii-table": "0.0.9", "async": "2.6.1", "core-js": "3.4.3", + "embark-utils": "^5.2.0-nightly.1", "web3": "1.2.6", "web3-utils": "1.2.6" }, diff --git a/packages/plugins/profiler/src/index.js b/packages/plugins/profiler/src/index.js index f8d5f6007..691c4c47e 100644 --- a/packages/plugins/profiler/src/index.js +++ b/packages/plugins/profiler/src/index.js @@ -1,3 +1,5 @@ +import { warnIfPackageNotDefinedLocally } from 'embark-utils'; + const asciiTable = require('ascii-table'); const GasEstimator = require('./gasEstimator.js'); @@ -10,6 +12,7 @@ class Profiler { this.registerConsoleCommand(); this.registerApi(); + warnIfPackageNotDefinedLocally("embark-profiler", this.embark.logger.warn.bind(this.embark.logger)); } profileJSON(contractName, returnCb) { diff --git a/packages/plugins/profiler/tsconfig.json b/packages/plugins/profiler/tsconfig.json index 2f6e7e52b..e0c6f4a52 100644 --- a/packages/plugins/profiler/tsconfig.json +++ b/packages/plugins/profiler/tsconfig.json @@ -8,5 +8,10 @@ "extends": "../../../tsconfig.base.json", "include": [ "src/**/*" + ], + "references": [ + { + "path": "../../core/utils" + } ] } diff --git a/packages/stack/blockchain/src/index.js b/packages/stack/blockchain/src/index.js index 6fc6209c7..0c9ccbd68 100644 --- a/packages/stack/blockchain/src/index.js +++ b/packages/stack/blockchain/src/index.js @@ -1,4 +1,5 @@ import async from 'async'; +import { warnIfPackageNotDefinedLocally } from 'embark-utils'; const { __ } = require('embark-i18n'); const constants = require('embark-core/constants'); @@ -109,6 +110,13 @@ export default class Blockchain { }); this.blockchainApi.registerAPIs("ethereum"); this.blockchainApi.registerRequests("ethereum"); + + if (this.blockchainConfig.enabled && this.blockchainConfig.client === "geth") { + warnIfPackageNotDefinedLocally("embark-geth", this.embark.logger.warn.bind(this.embark.logger)); + } + if (this.blockchainConfig.enabled && this.blockchainConfig.client === "parity") { + warnIfPackageNotDefinedLocally("embark-parity", this.embark.logger.warn.bind(this.embark.logger)); + } } addArtifactFile(_params, cb) { diff --git a/packages/stack/communication/src/index.js b/packages/stack/communication/src/index.js index b66047119..c157c2dc8 100644 --- a/packages/stack/communication/src/index.js +++ b/packages/stack/communication/src/index.js @@ -1,5 +1,5 @@ import { __ } from 'embark-i18n'; -import {canonicalHost, defaultHost} from 'embark-utils'; +import {canonicalHost, defaultHost, warnIfPackageNotDefinedLocally} from 'embark-utils'; class Communication { constructor(embark, _options){ @@ -30,6 +30,10 @@ class Communication { client.apply(client, [onStart]); }); + + if (this.communicationConfig.enabled && this.communicationConfig.available_providers.includes("whisper")) { + warnIfPackageNotDefinedLocally("embark-whisper-geth", this.embark.logger.warn.bind(this.embark.logger)); + } } addArtifactFile(_params, cb) { diff --git a/packages/stack/storage/src/index.js b/packages/stack/storage/src/index.js index 33aaf1374..0f2282141 100644 --- a/packages/stack/storage/src/index.js +++ b/packages/stack/storage/src/index.js @@ -1,4 +1,5 @@ import {__} from 'embark-i18n'; +import { warnIfPackageNotDefinedLocally } from 'embark-utils'; class Storage { constructor(embark, options) { @@ -41,6 +42,13 @@ class Storage { if (!client) return cb("upload client for " + clientName + " not found"); client.apply(client, [cb]); }); + + if (this.storageConfig.enabled && this.storageConfig.available_providers.includes("ipfs")) { + warnIfPackageNotDefinedLocally("embark-ipfs", this.embark.logger.warn.bind(this.embark.logger)); + } + if (this.storageConfig.enabled && this.storageConfig.available_providers.includes("swarm")) { + warnIfPackageNotDefinedLocally("embark-swarm", this.embark.logger.warn.bind(this.embark.logger)); + } } addArtifactFile(_params, cb) {