From d1ad20574a4b4ab74db2935599f07f88567774b6 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Mon, 16 Jul 2018 17:02:42 -0500 Subject: [PATCH 1/8] bump dev/deps --- package.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 38bb5d5..0ea3ea7 100644 --- a/package.json +++ b/package.json @@ -38,19 +38,19 @@ }, "homepage": "https://github.com/embark-framework/EmbarkJS#readme", "dependencies": { - "@babel/runtime": "^7.0.0-beta.52", + "@babel/runtime": "^7.0.0-beta.54", "async": "^2.0.1" }, "devDependencies": { - "@babel/cli": "7.0.0-beta.52", - "@babel/core": "7.0.0-beta.52", - "@babel/plugin-transform-runtime": "7.0.0-beta.52", - "@babel/preset-env": "7.0.0-beta.52", + "@babel/cli": "7.0.0-beta.54", + "@babel/core": "7.0.0-beta.54", + "@babel/plugin-transform-runtime": "7.0.0-beta.54", + "@babel/preset-env": "7.0.0-beta.54", "ajv": "6.5.2", "babel-loader": "8.0.0-beta.4", "http-server": "0.11.1", "rimraf": "2.6.2", - "webpack": "4.15.1", + "webpack": "4.16.1", "webpack-cli": "3.0.8" } } From 75eeaa5c83f1416020e74139e704dde7a002054e Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Mon, 16 Jul 2018 17:04:25 -0500 Subject: [PATCH 2/8] rev babel, webpack setups and pkg.json fields --- .babelrc | 27 +++++++++++++++++++++++---- package.json | 10 +++++++--- webpack.config.js | 22 +--------------------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/.babelrc b/.babelrc index 1c72f12..bd4c591 100644 --- a/.babelrc +++ b/.babelrc @@ -1,11 +1,30 @@ { "comments": false, "compact": false, - "ignore": ["src/browser.js"], + "env": { + "browser": { + "ignore": [ + "src/embark.js", + "src/node/index.js", + "src/standalone/index.js" + ], + "presets": [ + ["@babel/env", { + "modules": false, + "targets": {"browsers": ["last 1 version", "not dead", "> 0.2%"]} + }] + ] + }, + "node": { + "ignore": ["src/browser.js"], + "presets": [ + ["@babel/env", { + "targets": {"node": "8.11.3"} + }] + ] + } + }, "plugins": [ "@babel/plugin-transform-runtime" - ], - "presets": [ - ["@babel/env", {"targets": {"node": "8.11.3"}}] ] } diff --git a/package.json b/package.json index 0ea3ea7..6d9a151 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,19 @@ "name": "embarkjs", "version": "0.1.0", "description": "JavaScript library for easily interacting with web3 technologies", - "main": "./dist/index.js", - "browser": "./src/browser.js", + "main": "dist/node/index.js", + "browser": { + "./dist/node/index.js": "./dist/browser/browser.js" + }, "files": [ "dist", "embark.min.js", "src" ], "scripts": { - "babel": "babel --out-dir dist src", + "babel": "npm run babel:browser && npm run babel:node", + "babel:browser": "BABEL_ENV=browser babel --out-dir dist/browser src", + "babel:node": "BABEL_ENV=node babel --out-dir dist src", "build": "npm run clean && npm run babel && npm run webpack", "clean": "rimraf dist embark.min.js embarkjs-*.tgz package", "http-server": "http-server", diff --git a/webpack.config.js b/webpack.config.js index 9c970f2..22c5551 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,28 +1,8 @@ const path = require('path'); const standalone = { - entry: path.resolve(__dirname, 'src') + '/browser.js', + entry: path.join(__dirname, 'dist/browser', 'browser.js'), mode: 'production', - module: { - rules: [ - { - test: /\.js$/, - exclude: /(node_modules|bower_components)/, - use: { - loader: 'babel-loader', - options: { - babelrc: false, - plugins: [ - "@babel/plugin-transform-runtime" - ], - presets: [ - ['@babel/env'] - ] - } - } - } - ] - }, // optimization: { // minimize: false // }, From 46489868050b0f0508f0c050a415a098f060a7c3 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Mon, 16 Jul 2018 17:04:48 -0500 Subject: [PATCH 3/8] be more specific,strict about what's supported --- .npmrc | 1 + package.json | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/.npmrc b/.npmrc index 3dbb5b9..ad50df6 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,3 @@ +engine-strict = true package-lock = false save-exact = true diff --git a/package.json b/package.json index 6d9a151..1b39cac 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,11 @@ "browser": { "./dist/node/index.js": "./dist/browser/browser.js" }, + "browserslist": [ + "last 1 version", + "not dead", + "> 0.2%" + ], "files": [ "dist", "embark.min.js", @@ -56,5 +61,8 @@ "rimraf": "2.6.2", "webpack": "4.16.1", "webpack-cli": "3.0.8" + }, + "engines": { + "node" : ">=8.11.3" } } From 3ed02c255338b83f83c5be242a55cbc6b463a4f6 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Mon, 16 Jul 2018 17:05:24 -0500 Subject: [PATCH 4/8] browser and embark entrypoints go through index --- src/browser.js | 6 ++++-- src/embark.js | 22 +--------------------- src/index.js | 25 ++++++++++++++++++++++++- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/src/browser.js b/src/browser.js index a1ed46e..b79195a 100644 --- a/src/browser.js +++ b/src/browser.js @@ -1,9 +1,11 @@ -import _EmbarkJS from './embark'; +import _EmbarkJS from './index'; var EmbarkJS = Object.assign({}, _EmbarkJS); +var _checkWeb3 = EmbarkJS.Contract.checkWeb3; + EmbarkJS.Contract.checkWeb3 = function () { - _EmbarkJS.Contract.checkWeb3.call(this); + _checkWeb3.call(this); if (!this.web3 && typeof (web3) !== 'undefined') { this.web3 = web3; } else if (!this.web3) { diff --git a/src/embark.js b/src/embark.js index c5e31f4..b450ed9 100644 --- a/src/embark.js +++ b/src/embark.js @@ -1,22 +1,2 @@ -import Storage from './storage.js'; -import Names from './names.js'; -import Messages from './messages.js'; -import Contract from './contracts.js'; -import Utils from './utils.js'; - -var EmbarkJS = { - onReady: function (cb) { - if (typeof (__embarkContext) === 'undefined') { - return cb(); - } - return __embarkContext.execWhenReady(cb); - } -}; - -EmbarkJS.Contract = Contract; -EmbarkJS.Storage = Storage; -EmbarkJS.Names = Names; -EmbarkJS.Messages = Messages; -EmbarkJS.Utils = Utils; - +import EmbarkJS from './index'; export default EmbarkJS; diff --git a/src/index.js b/src/index.js index c96c61c..acc07a5 100644 --- a/src/index.js +++ b/src/index.js @@ -1 +1,24 @@ -module.exports = require('./embark').default; +import Storage from './storage.js'; +import Names from './names.js'; +import Messages from './messages.js'; +import Contract from './contracts.js'; +import Utils from './utils.js'; + +var EmbarkJS = { + onReady: function (cb) { + if (typeof (__embarkContext) === 'undefined') { + return cb(); + } + return __embarkContext.execWhenReady(cb); + } +}; + +EmbarkJS.Contract = Contract; +EmbarkJS.Storage = Storage; +EmbarkJS.Names = Names; +EmbarkJS.Messages = Messages; +EmbarkJS.Utils = Utils; + +EmbarkJS.isNewWeb3 = Contract.isNewWeb3; + +export default EmbarkJS; From ca1e5538f7345465942a9317bf03c429fe5e0df7 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Mon, 16 Jul 2018 17:06:06 -0500 Subject: [PATCH 5/8] isNewWeb3 should be a constructor prop since needed on EmbarkJS --- src/contracts.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/contracts.js b/src/contracts.js index ceab073..e86016f 100644 --- a/src/contracts.js +++ b/src/contracts.js @@ -1,12 +1,3 @@ - -let isNewWeb3 = function (web3Obj) { - var _web3 = web3Obj || (new Web3()); - if (typeof(_web3.version) === "string") { - return true; - } - return parseInt(_web3.version.api.split('.')[0], 10) >= 1; -}; - let Contract = function (options) { var self = this; var i, abiElement; @@ -17,12 +8,11 @@ let Contract = function (options) { this.gas = options.gas; this.code = '0x' + options.code; - //this.web3 = options.web3 || web3; this.web3 = options.web3; - this.checkWeb3.call(this); + Contract.checkWeb3.call(this); - if (isNewWeb3(this.web3)) { + if (Contract.isNewWeb3(this.web3)) { ContractClass = new this.web3.eth.Contract(this.abi, this.address); ContractClass.setProvider(this.web3.currentProvider); ContractClass.options.data = this.code; @@ -177,6 +167,14 @@ let Contract = function (options) { Contract.checkWeb3 = function () {}; +Contract.isNewWeb3 = function (web3Obj) { + var _web3 = web3Obj || (new Web3()); + if (typeof(_web3.version) === "string") { + return true; + } + return parseInt(_web3.version.api.split('.')[0], 10) >= 1; +}; + Contract.prototype.deploy = function (args, _options) { var self = this; var contractParams; From 7c6d46c20d11f19e4c30ccb687bd0c659ca2d251 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Mon, 16 Jul 2018 17:07:52 -0500 Subject: [PATCH 6/8] copy missing func/comment from old script --- src/names.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/names.js b/src/names.js index 740efef..baad2ed 100644 --- a/src/names.js +++ b/src/names.js @@ -34,6 +34,13 @@ Names.lookup = function (identifier) { return this.currentNameSystems.lookup(identifier); }; +Names.isAvailable = function () { + return this.currentNameSystems.isAvailable(); +}; + +// To Implement + + // register a name Names.register = function(name, options) { if (!this.currentNameSystems) { From b6c0c429de77943f2793e15ac145ca5e6bc2f379 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Mon, 16 Jul 2018 17:08:22 -0500 Subject: [PATCH 7/8] node entrypoint -- corresponds to "main" in pkg.json --- src/node/index.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/node/index.js diff --git a/src/node/index.js b/src/node/index.js new file mode 100644 index 0000000..18fe3a5 --- /dev/null +++ b/src/node/index.js @@ -0,0 +1 @@ +module.exports = require('../embark').default; From 1f72c2d8303caf6a92b73eb91c3c887de513e338 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Mon, 16 Jul 2018 17:08:42 -0500 Subject: [PATCH 8/8] standalone entrypoint -- simple convenience --- src/standalone/index.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/standalone/index.js diff --git a/src/standalone/index.js b/src/standalone/index.js new file mode 100644 index 0000000..4c504fc --- /dev/null +++ b/src/standalone/index.js @@ -0,0 +1 @@ +module.exports = require('../../embark.min');