Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typescript support #3652

Merged
merged 17 commits into from
Jul 25, 2020
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
path: |
node_modules
*/*/node_modules
key: 0-${{ runner.os }}-node12-${{ hashFiles('**/package-lock.json') }}
key: 2-${{ runner.os }}-node12-${{ hashFiles('**/package-lock.json') }}
- run: bash ./scripts/install.sh
if: steps.cache-deps.outputs.cache-hit != 'true'
- run: bash ./scripts/ci.sh
Expand All @@ -48,7 +48,7 @@ jobs:
path: |
node_modules
*/*/node_modules
key: 0-${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
key: 2-${{ runner.os }}-node${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
- run: bash ./scripts/install.sh
if: steps.cache-deps.outputs.cache-hit != 'true'
- run: bash ./scripts/ci.sh
Expand Down Expand Up @@ -78,7 +78,7 @@ jobs:
path: |
node_modules
*/*/node_modules
key: 0-${{ runner.os }}-node12-${{ hashFiles('**/package-lock.json') }}
key: 2-${{ runner.os }}-node12-${{ hashFiles('**/package-lock.json') }}
- run: bash ./scripts/install.sh
if: steps.cache-deps.outputs.cache-hit != 'true'
- run: bash ./scripts/ci.sh
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ contracts/
migrations/
truffle-config.js
test/config/ensAddresses.json
*/**/lib
12 changes: 6 additions & 6 deletions dist/web3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/web3.min.js.map

Large diffs are not rendered by default.

271 changes: 153 additions & 118 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
"scripts": {
"version": "npm run build",
"postinstall": "npm run bootstrap",
"build": "npm run bootstrap && webpack && cp -r ./dist ./packages/web3",
"build": "npm run bootstrap && lerna run tsc && webpack && cp -r ./dist ./packages/web3",
"publish": "lerna publish",
"bootstrap": "lerna bootstrap --hoist",
"lint": "jshint *.js packages",
"test": "mocha --grep E2E --invert; jshint *.js packages",
"test:unit": "nyc --no-clean --silent _mocha -- -R spec --grep E2E --invert --exit",
"test": "mocha -R spec --require ts-node/register --grep E2E --invert",
"test:unit": "nyc --no-clean --silent _mocha -- -R spec --require ts-node/register --grep E2E --invert --exit",
"test:cov": "npm run cov:clean; npm run test:unit; npm run test:e2e:clients; npm run cov:merge_reports",
"dtslint": "lerna run dtslint",
"depcheck": "lerna exec dependency-check -- --missing --verbose .",
Expand Down Expand Up @@ -128,6 +128,7 @@
"nyc": "^14.1.1",
"pify": "^4.0.1",
"sandboxed-module": "^2.0.3",
"ts-node": "^8.10.2",
"typescript": "^3.9.5",
"underscore": "1.9.1",
"wait-port": "^0.2.6",
Expand Down
3 changes: 2 additions & 1 deletion packages/web3-bzz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
},
"types": "types/index.d.ts",
"scripts": {
"tsc": "tsc -b tsconfig.json",
"dtslint": "dtslint --localTs ../../node_modules/typescript/lib types"
},
"main": "src/index.js",
"main": "lib/index.js",
"dependencies": {
"@types/node": "^12.12.6",
"got": "9.6.0",
Expand Down
9 changes: 9 additions & 0 deletions packages/web3-bzz/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
},
"include": [
"./src"
]
}
3 changes: 2 additions & 1 deletion packages/web3-core-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
},
"types": "types/index.d.ts",
"scripts": {
"tsc": "tsc -b tsconfig.json",
"dtslint": "dtslint --localTs ../../node_modules/typescript/lib types"
},
"main": "src/index.js",
"main": "lib/index.js",
"dependencies": {
"underscore": "1.9.1",
"web3-eth-iban": "1.2.11",
Expand Down
9 changes: 9 additions & 0 deletions packages/web3-core-helpers/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
},
"include": [
"./src"
]
}
3 changes: 2 additions & 1 deletion packages/web3-core-method/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
},
"types": "types/index.d.ts",
"scripts": {
"tsc": "tsc -b tsconfig.json",
"dtslint": "dtslint --localTs ../../node_modules/typescript/lib types"
},
"main": "src/index.js",
"main": "lib/index.js",
"dependencies": {
"@ethersproject/transactions": "^5.0.0-beta.135",
"underscore": "1.9.1",
Expand Down
9 changes: 9 additions & 0 deletions packages/web3-core-method/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
},
"include": [
"./src"
]
}
5 changes: 4 additions & 1 deletion packages/web3-core-promievent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"engines": {
"node": ">=8.0.0"
},
"main": "src/index.js",
"main": "lib/index.js",
"scripts": {
"tsc": "tsc -b tsconfig.json"
},
"dependencies": {
"eventemitter3": "4.0.4"
}
Expand Down
9 changes: 9 additions & 0 deletions packages/web3-core-promievent/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
},
"include": [
"./src"
]
}
5 changes: 4 additions & 1 deletion packages/web3-core-requestmanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"engines": {
"node": ">=8.0.0"
},
"main": "src/index.js",
"main": "lib/index.js",
"scripts": {
"tsc": "tsc -b tsconfig.json"
},
"dependencies": {
"underscore": "1.9.1",
"web3-core-helpers": "1.2.11",
Expand Down
9 changes: 9 additions & 0 deletions packages/web3-core-requestmanager/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
},
"include": [
"./src"
]
}
3 changes: 2 additions & 1 deletion packages/web3-core-subscriptions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
},
"types": "types/index.d.ts",
"scripts": {
"tsc": "tsc -b tsconfig.json",
"dtslint": "dtslint --localTs ../../node_modules/typescript/lib types"
},
"main": "src/index.js",
"main": "lib/index.js",
"dependencies": {
"eventemitter3": "4.0.4",
"underscore": "1.9.1",
Expand Down
9 changes: 9 additions & 0 deletions packages/web3-core-subscriptions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
},
"include": [
"./src"
]
}
3 changes: 2 additions & 1 deletion packages/web3-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
},
"types": "types/index.d.ts",
"scripts": {
"tsc": "tsc -b tsconfig.json",
"dtslint": "dtslint --localTs ../../node_modules/typescript/lib types"
},
"main": "src/index.js",
"main": "lib/index.js",
"dependencies": {
"@types/bn.js": "^4.11.5",
"@types/node": "^12.12.6",
Expand Down
117 changes: 59 additions & 58 deletions packages/web3-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,67 +20,68 @@
* @date 2017
*/

"use strict";
const requestManager = require("web3-core-requestmanager");
const extend = require("./extend");

const packageInit = (pkg, args) => {
args = Array.prototype.slice.call(args);

var requestManager = require('web3-core-requestmanager');
var extend = require('./extend.js');
if (!pkg) {
throw new Error('You need to instantiate using the "new" keyword.');
}

module.exports = {
packageInit: function (pkg, args) {
args = Array.prototype.slice.call(args);

if (!pkg) {
throw new Error('You need to instantiate using the "new" keyword.');
}

// make property of pkg._provider, which can properly set providers
Object.defineProperty(pkg, 'currentProvider', {
get: function () {
return pkg._provider;
},
set: function (value) {
return pkg.setProvider(value);
},
enumerable: true,
configurable: true
});

// inherit from parent package or create a new RequestManager
if (args[0] && args[0]._requestManager) {
pkg._requestManager = args[0]._requestManager;
} else {
pkg._requestManager = new requestManager.Manager(args[0], args[1]);
}

// add givenProvider
pkg.givenProvider = requestManager.Manager.givenProvider;
pkg.providers = requestManager.Manager.providers;

pkg._provider = pkg._requestManager.provider;

// add SETPROVIDER function (don't overwrite if already existing)
if (!pkg.setProvider) {
pkg.setProvider = function (provider, net) {
pkg._requestManager.setProvider(provider, net);
pkg._provider = pkg._requestManager.provider;
return true;
};
}

pkg.setRequestManager = function(manager) {
pkg._requestManager = manager;
pkg._provider = manager.provider;
};
// make property of pkg._provider, which can properly set providers
Object.defineProperty(pkg, 'currentProvider', {
get: () => {
return pkg._provider;
},
set: (value) => {
return pkg.setProvider(value);
},
enumerable: true,
configurable: true
});

// inherit from parent package or create a new RequestManager
if (args[0] && args[0]._requestManager) {
pkg._requestManager = args[0]._requestManager;
} else {
pkg._requestManager = new requestManager.Manager(args[0], args[1]);
}

// add givenProvider
pkg.givenProvider = requestManager.Manager.givenProvider;
pkg.providers = requestManager.Manager.providers;

// attach batch request creation
pkg.BatchRequest = requestManager.BatchManager.bind(null, pkg._requestManager);
pkg._provider = pkg._requestManager.provider;

// attach extend function
pkg.extend = extend(pkg);
},
addProviders: function (pkg) {
pkg.givenProvider = requestManager.Manager.givenProvider;
pkg.providers = requestManager.Manager.providers;
// add SETPROVIDER function (don't overwrite if already existing)
if (!pkg.setProvider) {
pkg.setProvider = (provider, net) => {
pkg._requestManager.setProvider(provider, net);
pkg._provider = pkg._requestManager.provider;
return true;
};
}
};

pkg.setRequestManager = (manager) => {
pkg._requestManager = manager;
pkg._provider = manager.provider;
};

// attach batch request creation
pkg.BatchRequest = requestManager.BatchManager.bind(null, pkg._requestManager);

// attach extend function
pkg.extend = extend(pkg);
}

const addProviders = (pkg) => {
pkg.givenProvider = requestManager.Manager.givenProvider;
pkg.providers = requestManager.Manager.providers;
}

module.exports = {
packageInit,
addProviders
}
9 changes: 9 additions & 0 deletions packages/web3-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
},
"include": [
"./src"
]
}
3 changes: 2 additions & 1 deletion packages/web3-eth-abi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
},
"types": "types/index.d.ts",
"scripts": {
"tsc": "tsc -b tsconfig.json",
"dtslint": "dtslint --localTs ../../node_modules/typescript/lib types"
},
"main": "src/index.js",
"main": "lib/index.js",
"dependencies": {
"@ethersproject/abi": "5.0.0-beta.153",
"underscore": "1.9.1",
Expand Down
9 changes: 9 additions & 0 deletions packages/web3-eth-abi/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
},
"include": [
"./src"
]
}
3 changes: 2 additions & 1 deletion packages/web3-eth-accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
},
"types": "types/index.d.ts",
"scripts": {
"tsc": "tsc -b tsconfig.json",
"dtslint": "dtslint --localTs ../../node_modules/typescript/lib types"
},
"main": "src/index.js",
"main": "lib/index.js",
"dependencies": {
"crypto-browserify": "3.12.0",
"eth-lib": "0.2.8",
Expand Down
9 changes: 9 additions & 0 deletions packages/web3-eth-accounts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./lib"
},
"include": [
"./src"
]
}
Loading