Skip to content

Commit

Permalink
Updated TypeScript version.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Sep 6, 2019
1 parent 1e0ed4e commit e8028d0
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 23 deletions.
20 changes: 20 additions & 0 deletions admin/cmds/update-exports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";

const fs = require("fs");
const { resolve } = require("path");

const sourceEthers = fs.readFileSync(resolve(__dirname, "../../packages/ethers/src.ts/ethers.ts")).toString();
const targets = sourceEthers.match(/export\s*{\s*((.|\s)*)}/)[1].trim();

const output = `"use strict";
import * as ethers from "./ethers";
export { ethers };
export {
${ targets }
} from "./ethers";
`;

fs.writeFileSync(resolve(__dirname, "../../packages/ethers/src.ts/index.ts"), output);
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"bootstrap": "node ./admin/cmds/reset-build.js && node ./admin/cmds/update-depgraph && lerna bootstrap --hoist",
"build": "tsc --build ./tsconfig.project.json",
"clean": "node ./admin/cmds/reset-build.js && tsc --build --clean ./tsconfig.project.json",
"_dist_prepare": "npm run clean && npm run bootstrap && npm run build",
"_dist_prepare": "npm run clean && npm run bootstrap && npm run build && node ./admin/cmds/update-exports.js",
"_dist_ethers": "rollup -c && rollup -c --configMinify && rollup -c --configModule && rollup -c --configModule --configMinify",
"_dist_tests": "rollup -c --configTest && rollup -c --configTest --configMinify && rollup -c --configTest --configModule && rollup -c --configTest --configModule --configMinify",
"_test_prepare": "npm run _dist_prepare && npm run _dist_tests",
Expand All @@ -27,6 +27,7 @@
"devDependencies": {
"@types/assert": "^1.4.1",
"@types/mocha": "^5.2.0",
"@types/node": "^12.7.4",
"aes-js": "3.0.0",
"browserify": "16.2.3",
"diff": "4.0.1",
Expand All @@ -38,7 +39,7 @@
"scrypt-js": "2.0.4",
"semver": "^5.6.0",
"tar": "4.4.8",
"typescript": "3.3.3",
"typescript": "3.6.2",
"rollup": "1.20.1",
"rollup-plugin-commonjs": "10.0.2",
"rollup-plugin-json": "4.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/address/src.ts/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";

// We use this for base 36 maths
import * as BN from "bn.js";
import { BN } from "bn.js";

import { arrayify, hexDataSlice, isHexString, stripZeros } from "@ethersproject/bytes";
import { BigNumberish } from "@ethersproject/bignumber";
Expand Down Expand Up @@ -106,7 +106,7 @@ export function getAddress(address: string): string {
logger.throwArgumentError("bad icap checksum", "address", address);
}

result = (new BN.BN(address.substring(4), 36)).toString(16);
result = (new BN(address.substring(4), 36)).toString(16);
while (result.length < 40) { result = "0" + result; }
result = getChecksumAddress("0x" + result);

Expand All @@ -126,7 +126,7 @@ export function isAddress(address: string): boolean {
}

export function getIcapAddress(address: string): string {
let base36 = (new BN.BN(getAddress(address).substring(2), 16)).toString(36).toUpperCase();
let base36 = (new BN(getAddress(address).substring(2), 16)).toString(36).toUpperCase();
while (base36.length < 30) { base36 = "0" + base36; }
return "XE" + ibanChecksum("XE00" + base36) + base36;
}
Expand Down
14 changes: 7 additions & 7 deletions packages/bignumber/src.ts/bignumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*
*/

import * as BN from "bn.js";
import { BN } from "bn.js";

import { Bytes, Hexable, hexlify, isBytes, isHexString } from "@ethersproject/bytes";

Expand Down Expand Up @@ -154,7 +154,7 @@ export class BigNumber implements Hexable {
}

if (value.match(/^-?[0-9]+$/)) {
return new BigNumber(_constructorGuard, toHex(new BN.BN(value)));
return new BigNumber(_constructorGuard, toHex(new BN(value)));
}

return logger.throwArgumentError("invalid BigNumber string", "value", value);
Expand Down Expand Up @@ -200,7 +200,7 @@ export class BigNumber implements Hexable {
}

// Normalize the hex string
function toHex(value: string | BN.BN): string {
function toHex(value: string | BN): string {

// For BN, call on the hex string
if (typeof(value) !== "string") {
Expand Down Expand Up @@ -242,16 +242,16 @@ function toHex(value: string | BN.BN): string {
return value;
}

function toBigNumber(value: BN.BN): BigNumber {
function toBigNumber(value: BN): BigNumber {
return BigNumber.from(toHex(value));
}

function toBN(value: BigNumberish): BN.BN {
function toBN(value: BigNumberish): BN {
let hex = BigNumber.from(value).toHexString();
if (hex[0] === "-") {
return (new BN.BN("-" + hex.substring(3), 16));
return (new BN("-" + hex.substring(3), 16));
}
return new BN.BN(hex.substring(2), 16);
return new BN(hex.substring(2), 16);
}

function throwFault(fault: string, operation: string, value?: any): never {
Expand Down
6 changes: 4 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
"ethers-ts": "./lib/bin/ethers-ts.js"
},
"dependencies": {
"@types/node": "10.3.2",
"@ethersproject/basex": ">=5.0.0-beta.127",
"ethers": ">=5.0.0-beta.156",
"mime-types": "2.1.11",
"scrypt-js": "2.0.4",
"solc": "0.5.10",
"solidity-parser-antlr": "^0.3.2"
},
"devDependencies": {
"@types/node": "^12.7.4"
},
"keywords": [
"Ethereum",
"ethers",
Expand All @@ -36,5 +38,5 @@
},
"module": "./lib.esm/index.js",
"types": "./lib/index.d.ts",
"tarballHash": "0x045c7d61113b060ecb79426c442a9bcc28c3ed5baebd6c324b8c5ccdd83aa39c"
"tarballHash": "0x7224b7a62cd2554bab3585709e8016fc4a7672c33c568dcbdfbf63d838c18283"
}
59 changes: 58 additions & 1 deletion packages/ethers/src.ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,61 @@ import * as ethers from "./ethers";

export { ethers };

export * from "./ethers";
export {
Signer,

Wallet,
VoidSigner,

getDefaultProvider,
providers,

Contract,
ContractFactory,

BigNumber,
FixedNumber,

constants,
errors,

logger,

utils,

wordlists,


////////////////////////
// Compile-Time Constants

version,


////////////////////////
// Types

ContractFunction,
ContractReceipt,
ContractTransaction,
Event,
EventFilter,

Overrides,
PayableOverrides,
CallOverrides,

ContractInterface,

BigNumberish,

Bytes,
BytesLike,

Signature,

Transaction,
UnsignedTransaction,

Wordlist
} from "./ethers";
4 changes: 2 additions & 2 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@ethersproject/web": ">=5.0.0-beta.129"
},
"devDependencies": {
"@types/node": "10.3.2"
"@types/node": "^12.7.4"
},
"keywords": [
"Ethereum",
Expand All @@ -45,5 +45,5 @@
},
"module": "./lib.esm/index.js",
"types": "./lib/index.d.ts",
"tarballHash": "0x655b117ac21836fcd5bed6025dbd53583596f141bc2b67b833342f60e37038d4"
"tarballHash": "0xc0b5e1a60b427d64d93f366727dc57777d24bfd92b8ddeb6408b367a7780f045"
}
4 changes: 2 additions & 2 deletions packages/random/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@ethersproject/logger": ">=5.0.0-beta.129"
},
"devDependencies": {
"@types/node": "10.3.2"
"@types/node": "^12.7.4"
},
"keywords": [
"Ethereum",
Expand All @@ -30,5 +30,5 @@
},
"module": "./lib.esm/index.js",
"types": "./lib/index.d.ts",
"tarballHash": "0x45c2e53529bd3cf7b1ba4bbbe448813aa2540b792fab4db7bdfbac9c204f1d7e"
"tarballHash": "0x884bc62b2feb8949cbbf59bb1fea3ca8c671ab16149e1688d74b9f1bd360e89c"
}
16 changes: 12 additions & 4 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,24 @@ function Replacer(options = {}) {
return {
name: "file-replacer",
transform(code, id) {
//console.log(id, code.length);
/*
console.log("------");
console.log("NAME", id, id.match("node-resolve:empty.js$"));
console.log(code);
console.log("------");
*/

if (!filter(id)) { return null; }

for (let i = 0; i < suffixes.length; i++) {
const suffix = suffixes[i];
if (id.match(new RegExp(suffix))) {
//if (id.substring(id.length - suffix.length) === suffix) {
let newCode = options.replace[suffix];
console.log(`Replace: ${ id } (${ code.length } => ${ newCode.length })`);
return {
code: newCode
code: newCode,
map: { mappings: '' }
};
}
}
Expand Down Expand Up @@ -89,8 +97,8 @@ export default commandLineArgs => {
namedExports: {
"bn.js": [ "BN" ],
"elliptic": [ "ec" ]
}
})
},
}),
];

if (minify) {
Expand Down

0 comments on commit e8028d0

Please sign in to comment.