fix: change output from webpack to babel (#64)

* fix: use webpack to transpile js code and removed webpack
* fix: update tests
* fix: node version
* fix: code review
This commit is contained in:
Richard Ramos 2020-02-03 19:51:19 -04:00 committed by GitHub
parent 2c8ca287ac
commit 4232fc3231
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 1481 additions and 2240 deletions

View File

@ -1,4 +0,0 @@
{
"plugins": ["@babel/transform-runtime", "@babel/plugin-proposal-class-properties"],
"presets": ["@babel/preset-env"]
}

2
.gitignore vendored
View File

@ -6,4 +6,6 @@ TODO
test.js
/dist/
/react/
/lib/
/module/
/examples/react-example1/src/contract.json

79
babel.config.js Normal file
View File

@ -0,0 +1,79 @@
module.exports = api => {
api.cache(true);
return {
env: {
development: {
presets: [
[
"@babel/preset-env",
{
corejs: 3,
shippedProposals: true,
targets: { node: "current" },
useBuiltIns: "usage"
}
]
],
plugins: [
[
"@babel/plugin-transform-runtime",
{
corejs: 3
}
],
"@babel/plugin-proposal-class-properties"
]
},
browser: {
presets: [
[
"@babel/preset-env",
{
corejs: 3,
modules: false,
shippedProposals: true,
targets: { browsers: "defaults" },
useBuiltIns: "usage"
}
]
],
plugins: [
[
"@babel/plugin-transform-runtime",
{
corejs: 3,
useESModules: true
}
],
"@babel/plugin-proposal-class-properties"
]
},
module: {
presets: [
[
"@babel/preset-env",
{
corejs: 3,
modules: false,
shippedProposals: true,
targets: { node: "current" },
useBuiltIns: "usage"
}
]
],
plugins: [
[
"@babel/plugin-transform-runtime",
{
corejs: 3,
useESModules: true
}
],
"@babel/plugin-proposal-class-properties"
]
}
},
sourceMaps: true
};
};

View File

@ -24,47 +24,40 @@
"url": "https://github.com/embark-framework/subspace/issues"
},
"license": "MIT",
"main": "./dist/node.js",
"browser": "./dist/browser.js",
"main": "./dist/index.js",
"browser": "./lib/index.js",
"module": "./module/index.js",
"scripts": {
"babel": "babel",
"babel:node": "npm-run-all babel:node:*",
"babel:node:src": "cross-env BABEL_ENV=node babel src --copy-files --extensions \".js\" --out-dir dist",
"webpack:dev": "webpack --config webpack.dev.js",
"webpack:prod": "webpack --config webpack.prod.js",
"build:dev": "npm-run-all clean webpack:dev",
"build:prod": "npm-run-all clean webpack:prod",
"build": "npm-run-all build:dev",
"clean": "rimraf dist; rimraf react"
"clean": "rimraf dist; rimraf lib; rimraf module; rimraf react;",
"build:browser": "cross-env BABEL_ENV=browser babel ./src --out-dir ./lib --source-maps --copy-files --ignore src/react/*",
"build:react": "cross-env BABEL_ENV=browser babel ./src/react --out-dir ./react --source-maps --copy-files",
"build:module": "cross-env BABEL_ENV=module babel ./src --out-dir ./module --source-maps --copy-files",
"build:node": "babel ./src --out-dir ./dist --source-maps --copy-files",
"build": "npm-run-all clean build:*"
},
"devDependencies": {
"@babel/cli": "^7.1.5",
"@babel/core": "^7.1.6",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-transform-runtime": "^7.6.2",
"@babel/preset-env": "^7.1.6",
"@babel/runtime": "^7.7.2",
"add-module-exports-webpack-plugin": "^1.0.0",
"babel-loader": "^8.0.4",
"cross-env": "^5.2.0",
"ganache-core": "^2.7.0",
"@babel/cli": "^7.8.4",
"@babel/core": "^7.8.4",
"@babel/plugin-proposal-class-properties": "^7.8.3",
"@babel/plugin-transform-runtime": "^7.8.3",
"@babel/preset-env": "^7.8.4",
"cross-env": "^7.0.0",
"ganache-core": "^2.10.1",
"npm-run-all": "^4.1.5",
"rimraf": "^2.6.2",
"webpack": "4.39.1",
"webpack-bundle-analyzer": "^3.4.1",
"webpack-cli": "^3.3.6",
"webpack-merge": "^4.2.1",
"webpack-node-externals": "^1.7.2"
"rimraf": "^3.0.1"
},
"dependencies": {
"fast-deep-equal": "^2.0.1",
"@babel/runtime": "^7.8.4",
"@babel/runtime-corejs3": "^7.8.4",
"core-js": "^3.6.4",
"fast-deep-equal": "^3.1.1",
"hex2dec": "^1.1.2",
"lokijs": "^1.5.6",
"object-hash": "^1.3.1",
"object-hash": "^2.0.1",
"rxjs": "^6.5.2",
"web3-eth": "^1.2.1"
"web3-eth": "^1.2.6"
},
"optionalDependencies": {
"peerDependencies": {
"graphql": "^14.4.2",
"graphql-tag": "^2.10.1",
"graphql-tools": "^4.0.5",

View File

@ -14,7 +14,7 @@ import LogSyncer from './logSyncer';
export default class Subspace {
constructor(provider, options = {}) {
if (!!provider.on) {
if (!provider.on) {
// https://github.com/ethereum/web3.js/blob/1.x/packages/web3-core-subscriptions/src/subscription.js#L205
console.warn("subspace: the current provider doesn't support subscriptions. Falling back to http polling");
}

View File

@ -1,7 +1,7 @@
const { makeExecutableSchema } = require("graphql-tools");
const gql = require( "graphql-tag");
const graphql = require( "reactive-graphql").graphql;
const Subspace = require('../dist/node.js');
const Subspace = require('../dist/index.js').default;
const Web3Eth = require('web3-eth');

View File

@ -1,7 +1,7 @@
const { makeExecutableSchema } = require("graphql-tools");
const gql = require( "graphql-tag");
const graphql = require( "reactive-graphql").graphql;
const Subspace = require('../dist/node.js');
const Subspace = require('../dist/index.js').default;
const { map, scan, last, distinctUntilChanged, pluck } = require('rxjs/operators');
const Web3Eth = require('web3-eth');
const {$average} = require('../src/operators');

View File

@ -1,8 +1,7 @@
const { map, scan, last, distinctUntilChanged } = require('rxjs/operators');
const Web3Eth = require('web3-eth');
const {deployRatingContract} = require('./utils-web3');
const Subspace = require('../dist/node.js');
const Subspace = require('../dist/index.js').default;
let eth = new Web3Eth("http://localhost:8545");
let myscan = scan((acc, curr) => {
@ -62,4 +61,4 @@ async function run() {
// await RatingContract.methods.doRating(1, 5).send({from: accounts[0]})
}
run()
run()

View File

@ -1,7 +1,7 @@
const { map, scan, last, distinctUntilChanged } = require('rxjs/operators');
const Web3Eth = require('web3-eth');
const {deployEscrowContract} = require('./utils-web3');
const Subspace = require('../dist/node.js');
const Subspace = require('../dist/index.js').default;
let eth = new Web3Eth("ws://localhost:8545");

View File

@ -1,6 +1,6 @@
const { map, scan, last, distinctUntilChanged } = require('rxjs/operators');
const Web3Eth = require('web3-eth');
const Subspace = require('../dist/node.js');
const Subspace = require('../dist/index.js').default;
let eth = new Web3Eth("ws://localhost:8545");

View File

@ -1,6 +1,6 @@
const ganache = require("ganache-core");
const Web3Eth = require('web3-eth');
const Subspace = require('../dist/node.js');
const Subspace = require('../dist/index.js').default;
console.log("The following error is emitted by ganache - https://github.com/trufflesuite/ganache-core/issues/267")
let eth = new Web3Eth(ganache.provider());

View File

@ -1,5 +1,5 @@
const Web3Eth = require('web3-eth');
const Subspace = require('../dist/node.js');
const Subspace = require('../dist/index.js').default;
let eth = new Web3Eth("ws://localhost:8545");

View File

@ -1,6 +1,6 @@
const Web3Eth = require('web3-eth');
const {deployRatingContract, mine} = require('./utils-web3');
const Subspace = require('../dist/node.js');
const Subspace = require('../dist/index.js').default;
const ganache = require("ganache-core");
console.log("The following error is emitted by ganache - https://github.com/trufflesuite/ganache-core/issues/267")

View File

@ -1,5 +1,5 @@
const Web3Eth = require('web3-eth');
const Subspace = require('../dist/node.js');
const Subspace = require('../dist/index.js').default;
let eth = new Web3Eth("wss://mainnet.infura.io/ws/v3/_____________");

View File

@ -1,107 +0,0 @@
const path = require("path");
const AddModuleExportsPlugin = require('add-module-exports-webpack-plugin');
const externals = {
react: {
commonjs: "react",
commonjs2: "react",
amd: "React",
root: "React"
},
"react-dom": {
commonjs: "react-dom",
commonjs2: "react-dom",
amd: "ReactDOM",
root: "ReactDOM"
},
electron: "electron",
"web3-eth": "web3-eth" // TODO: comment to pack web3-eth
};
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
const web = {
target: "web",
entry: path.join(__dirname, "src/index.js"),
module: {
rules: [
{
test: /\.js/,
exclude: /(node_modules)/,
use: [
{
loader: "babel-loader"
}
]
}
]
},
externals,
output: {
path: path.resolve(__dirname, "dist"),
filename: "browser.js",
library: "subspace",
libraryTarget: "umd"
},
node: {
fs: "empty"
},
optimization: {
usedExports: true,
sideEffects: true
},
plugins: [
// new BundleAnalyzerPlugin()
]
};
const react = {
...web,
entry: path.join(__dirname, "src/react/index.js"),
output: {
path: path.resolve(__dirname, "react"),
filename: "index.js",
library: "subspace-react",
libraryTarget: "umd"
},
plugins: []
};
const node = {
target: "node",
externals,
entry: path.join(__dirname, "src/index.js"),
module: {
rules: [
{
test: /\.js/,
exclude: /(node_modules)/,
use: [
{
loader: "babel-loader"
}
]
}
]
},
output: {
path: path.resolve(__dirname, "dist"),
filename: "node.js",
library: "subspace",
libraryTarget: "commonjs2"
},
optimization: {
usedExports: true,
sideEffects: true
},
plugins: [
new AddModuleExportsPlugin()
]
};
module.exports = {
node,
web,
react
};

View File

@ -1,12 +0,0 @@
const merge = require("webpack-merge");
const common = require("./webpack.common.js");
const mode_config = {};
Object.keys(common).forEach(k => {
mode_config[k] = {
mode: "development"
}
});
module.exports = merge.multiple(common, mode_config);

View File

@ -1,12 +0,0 @@
const merge = require("webpack-merge");
const common = require("./webpack.common.js");
const mode_config = {};
Object.keys(common).forEach(k => {
mode_config[k] = {
mode: "production"
}
});
module.exports = merge.multiple(common, mode_config);

3427
yarn.lock

File diff suppressed because it is too large Load Diff