From cae80756829cd5d4877741259b6cf1674b5a53bd Mon Sep 17 00:00:00 2001 From: Pascal Precht Date: Fri, 10 May 2019 12:52:34 +0200 Subject: [PATCH] refactor(@embark/solidity): move solidity module into own package --- packages/embark-solidity/.npmrc | 4 + packages/embark-solidity/README.md | 6 ++ packages/embark-solidity/package.json | 75 +++++++++++++++++++ .../solidity => embark-solidity/src}/index.js | 2 +- .../solidity => embark-solidity/src}/solcP.js | 0 .../solidity => embark-solidity/src}/solcW.js | 3 +- packages/embark-solidity/tsconfig.json | 4 + packages/embark-solidity/tslint.json | 3 + packages/embark/package.json | 1 + packages/embark/src/lib/core/engine.js | 4 +- packages/embark/src/test/contracts.js | 11 ++- .../src/test/modules/solidity/solidity.js | 7 +- 12 files changed, 111 insertions(+), 9 deletions(-) create mode 100644 packages/embark-solidity/.npmrc create mode 100644 packages/embark-solidity/README.md create mode 100644 packages/embark-solidity/package.json rename packages/{embark/src/lib/modules/solidity => embark-solidity/src}/index.js (99%) rename packages/{embark/src/lib/modules/solidity => embark-solidity/src}/solcP.js (100%) rename packages/{embark/src/lib/modules/solidity => embark-solidity/src}/solcW.js (95%) create mode 100644 packages/embark-solidity/tsconfig.json create mode 100644 packages/embark-solidity/tslint.json diff --git a/packages/embark-solidity/.npmrc b/packages/embark-solidity/.npmrc new file mode 100644 index 000000000..e031d3432 --- /dev/null +++ b/packages/embark-solidity/.npmrc @@ -0,0 +1,4 @@ +engine-strict = true +package-lock = false +save-exact = true +scripts-prepend-node-path = true diff --git a/packages/embark-solidity/README.md b/packages/embark-solidity/README.md new file mode 100644 index 000000000..3e43fd7d6 --- /dev/null +++ b/packages/embark-solidity/README.md @@ -0,0 +1,6 @@ +# `embark-solidity` + +> Solidity Compiler APIs for Embark + +Visit [embark.status.im](https://embark.status.im/) to get started with +[Embark](https://github.com/embark-framework/embark). diff --git a/packages/embark-solidity/package.json b/packages/embark-solidity/package.json new file mode 100644 index 000000000..01ef89ecd --- /dev/null +++ b/packages/embark-solidity/package.json @@ -0,0 +1,75 @@ +{ + "name": "embark-solidity", + "version": "4.1.0-beta.0", + "author": "Iuri Matias ", + "contributors": [], + "description": "Solidity Compiler APIs for Embark", + "homepage": "https://github.com/embark-framework/embark/tree/master/packages/embark-solidity#readme", + "bugs": "https://github.com/embark-framework/embark/issues", + "keywords": [ + "blockchain", + "dapps", + "ethereum", + "ipfs", + "serverless", + "solc", + "solidity" + ], + "files": [ + "dist" + ], + "license": "MIT", + "repository": { + "directory": "packages/embark-solidity", + "type": "git", + "url": "https://github.com/embark-framework/embark.git" + }, + "main": "./dist/index.js", + "scripts": { + "build": "cross-env BABEL_ENV=node babel src --extensions \".js\" --out-dir dist --root-mode upward --source-maps", + "ci": "npm run qa", + "clean": "npm run reset", + "lint": "npm-run-all lint:*", + "lint:js": "eslint src/", + "// lint:ts": "tslint -c tslint.json \"src/**/*.ts\"", + "package": "npm pack", + "// qa": "npm-run-all lint typecheck build package", + "qa": "npm-run-all lint build package", + "reset": "npx rimraf dist embark-*.tgz package", + "start": "npm run watch", + "// typecheck": "tsc", + "watch": "run-p watch:*", + "watch:build": "npm run build -- --verbose --watch", + "// watch:typecheck": "npm run typecheck -- --preserveWatchOutput --watch" + }, + "eslintConfig": { + "extends": "../../.eslintrc.json" + }, + "dependencies": { + "@babel/runtime-corejs2": "7.3.1", + "async": "2.6.1", + "embark-core": "^4.1.0-beta.0", + "embark-i18n": "^4.1.0-beta.0", + "embark-utils": "^4.1.0-beta.0", + "fs-extra": "7.0.1", + "live-plugin-manager-git-fix": "0.12.1", + "semver": "5.6.0", + "solc": "0.5.0", + "uuid": "3.3.2" + }, + "devDependencies": { + "@babel/cli": "7.2.3", + "@babel/core": "7.2.2", + "cross-env": "5.2.0", + "eslint": "5.7.0", + "npm-run-all": "4.1.5", + "rimraf": "2.6.3", + "tslint": "5.16.0", + "typescript": "3.4.5" + }, + "engines": { + "node": ">=8.12.0", + "npm": ">=6.4.1", + "yarn": ">=1.12.3" + } +} diff --git a/packages/embark/src/lib/modules/solidity/index.js b/packages/embark-solidity/src/index.js similarity index 99% rename from packages/embark/src/lib/modules/solidity/index.js rename to packages/embark-solidity/src/index.js index 77e9f4880..194a1a68c 100644 --- a/packages/embark/src/lib/modules/solidity/index.js +++ b/packages/embark-solidity/src/index.js @@ -1,4 +1,4 @@ -let async = require('../../utils/async_extend.js'); +let async = require('async'); let SolcW = require('./solcW.js'); const path = require('path'); import { __ } from 'embark-i18n'; diff --git a/packages/embark/src/lib/modules/solidity/solcP.js b/packages/embark-solidity/src/solcP.js similarity index 100% rename from packages/embark/src/lib/modules/solidity/solcP.js rename to packages/embark-solidity/src/solcP.js diff --git a/packages/embark/src/lib/modules/solidity/solcW.js b/packages/embark-solidity/src/solcW.js similarity index 95% rename from packages/embark/src/lib/modules/solidity/solcW.js rename to packages/embark-solidity/src/solcW.js index 921294577..24a1db16e 100644 --- a/packages/embark/src/lib/modules/solidity/solcW.js +++ b/packages/embark-solidity/src/solcW.js @@ -1,7 +1,6 @@ import { __ } from 'embark-i18n'; import { ProcessLauncher } from 'embark-core'; import {joinPath} from 'embark-utils'; -let currentSolcVersion = require('../../../../package.json').dependencies.solc; const uuid = require('uuid/v1'); class SolcW { @@ -52,7 +51,7 @@ class SolcW { this.solcProcess.once("result", "initiated", () => { this.events.request("version:get:solc", function(solcVersion) { - if (solcVersion === currentSolcVersion) { + if (solcVersion === self.embark.config.package.dependencies.solc) { return self.solcProcess.send({action: 'loadCompiler', requirePath: 'solc'}); } self.events.request("version:getPackagePath", "solc", solcVersion, function(err, path) { diff --git a/packages/embark-solidity/tsconfig.json b/packages/embark-solidity/tsconfig.json new file mode 100644 index 000000000..52d43eaaa --- /dev/null +++ b/packages/embark-solidity/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"] +} diff --git a/packages/embark-solidity/tslint.json b/packages/embark-solidity/tslint.json new file mode 100644 index 000000000..0946f2096 --- /dev/null +++ b/packages/embark-solidity/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "../../tslint.json" +} diff --git a/packages/embark/package.json b/packages/embark/package.json index ad846b069..88b5a7899 100644 --- a/packages/embark/package.json +++ b/packages/embark/package.json @@ -112,6 +112,7 @@ "embark-reset": "^4.1.0-beta.0", "embark-specialconfigs": "^4.1.0-beta.0", "embark-scaffolding": "^4.1.0-beta.0", + "embark-solidity": "^4.1.0-beta.0", "embark-ui": "^4.1.0-beta.0", "embark-test-runner": "^4.1.0-beta.0", "embark-transaction-tracker": "^4.1.0-beta.0", diff --git a/packages/embark/src/lib/core/engine.js b/packages/embark/src/lib/core/engine.js index 86d78e975..112932fb3 100644 --- a/packages/embark/src/lib/core/engine.js +++ b/packages/embark/src/lib/core/engine.js @@ -215,7 +215,7 @@ class Engine { setupCompilerAndContractsManagerService(options) { this.registerModulePackage('embark-compiler', {plugins: this.plugins, isCoverage: options.isCoverage}); - this.registerModule('solidity', {ipc: this.ipc, useDashboard: this.useDashboard}); + this.registerModulePackage('embark-solidity', {ipc: this.ipc, useDashboard: this.useDashboard}); this.registerModulePackage('embark-vyper'); this.registerModulePackage('embark-contracts-manager', {plugins: this.plugins, compileOnceOnly: options.compileOnceOnly}); } @@ -224,7 +224,7 @@ class Engine { let self = this; this.setupCompilerAndContractsManagerService(options); - this.registerModule('solidity', {ipc: self.ipc, useDashboard: this.useDashboard}); + this.registerModulePackage('embark-solidity', {ipc: self.ipc, useDashboard: this.useDashboard}); this.registerModulePackage('embark-vyper'); this.registerModulePackage('embark-profiler'); this.registerModule('deploytracker', {trackContracts: options.trackContracts}); diff --git a/packages/embark/src/test/contracts.js b/packages/embark/src/test/contracts.js index 5dc837886..a7bce76f7 100644 --- a/packages/embark/src/test/contracts.js +++ b/packages/embark/src/test/contracts.js @@ -10,7 +10,6 @@ let Events = require('../lib/core/events'); const fs = require('../lib/core/fs'); let assert = require('assert'); -//let SolidityCompiler = require('../lib/modules/solidity'); let Plugins = require('../lib/core/plugins.js'); let readFile = function(file) { @@ -40,6 +39,9 @@ describe('embark.Contracts', function() { "optimize-runs": 200 } } + }, + package: { + dependencies: { solc: currentSolcVersion } } } }); @@ -47,7 +49,7 @@ describe('embark.Contracts', function() { ipcRole: 'none', fs }); - plugins.loadInternalPlugin('solidity', {ipc: ipcObject}); + plugins.loadInternalPlugin('embark-solidity', {ipc: ipcObject}, true); let events = new Events(); let embarkObject = { @@ -180,6 +182,9 @@ describe('embark.Contracts', function() { "optimize-runs": 200 } } + }, + package: { + dependencies: { solc: currentSolcVersion } } } }); @@ -187,7 +192,7 @@ describe('embark.Contracts', function() { ipcRole: 'none', fs }); - plugins.loadInternalPlugin('solidity', {ipc: ipcObject}); + plugins.loadInternalPlugin('embark-solidity', {ipc: ipcObject}, true); let events = new Events(); let compiler = new Compiler({events: events, logger: plugins.logger}, {plugins: plugins}); diff --git a/packages/embark/src/test/modules/solidity/solidity.js b/packages/embark/src/test/modules/solidity/solidity.js index f4d3047f6..6b901ae72 100644 --- a/packages/embark/src/test/modules/solidity/solidity.js +++ b/packages/embark/src/test/modules/solidity/solidity.js @@ -2,7 +2,7 @@ import { File, Types } from "../../../lib/core/file.js"; const fs = require('../../../lib/core/fs'); import { IPC } from 'embark-core'; -let SolidityCompiler = require('../../../lib/modules/solidity'); +let SolidityCompiler = require('embark-solidity'); let TestLogger = require('../../../lib/utils/test_logger'); let readFile = function(file) { @@ -30,6 +30,11 @@ let generateApiObject = function() { logger: new TestLogger({}), events: TestEvents, config: { + package: { + dependencies: { + solc: solcVersion + } + }, contractDirectories: ['app/contracts/'], embarkConfig: { options: {