Skip to content

Commit

Permalink
Major overhaul in compilation to enable ES6 module generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Aug 25, 2019
1 parent 81fd942 commit 73a0077
Show file tree
Hide file tree
Showing 686 changed files with 58,756 additions and 447 deletions.
40 changes: 36 additions & 4 deletions admin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const fs = require("fs");
const resolve = require("path").resolve;
const spawn = require("child_process").spawn;

const local = require("./local");
const { dirnames } = require("./local");
const { loadPackage } = require("./depgraph");
const { loadJson, saveJson } = require("./utils");

function run(progname, args, ignoreErrorStream) {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -46,8 +48,37 @@ function run(progname, args, ignoreErrorStream) {
});
}

function runBuild() {
return run("npx", [ "tsc", "--build", resolve(__dirname, "../tsconfig.project.json") ]);
function setupConfig(outDir, moduleType, targetType) {
// Configure the tsconfit.package.json...
const path = resolve(__dirname, "../tsconfig.package.json");
const content = loadJson(path);
content.compilerOptions.module = moduleType;
content.compilerOptions.target = targetType;
saveJson(path, content);

dirnames.forEach((dirname) => {
if (loadPackage(dirname)._ethers_nobuild) { return; }

let path = resolve(__dirname, "../packages", dirname, "tsconfig.json");
let content = loadJson(path);
content.compilerOptions.outDir = outDir;
saveJson(path, content);
});
}

function setupBuild(buildModule) {
if (buildModule) {
setupConfig("./lib.esm/", "es2015", "es2015");
} else {
setupConfig("./lib/", "commonjs", "es5");
}
}

function runBuild(buildModule) {
setupBuild(buildModule);

// Compile
return run("npx", [ "tsc", "--build", resolve(__dirname, "../tsconfig.project.json"), "--force" ]);
}

function runDist() {
Expand All @@ -57,5 +88,6 @@ function runDist() {
module.exports = {
run: run,
runDist: runDist,
runBuild: runBuild
runBuild: runBuild,
setupBuild: setupBuild
};
5 changes: 5 additions & 0 deletions admin/cmds/reset-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"use strict";

const { setupBuild } = require("../build");

setupBuild(false);
5 changes: 3 additions & 2 deletions admin/cmds/update-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ if (process.argv.length > 2) {
}

(async function() {

let progress = getProgressBar(colorify("Updating versions", "bold"));

for (let i = 0; i < dirnames.length; i++) {
Expand Down Expand Up @@ -85,7 +84,9 @@ if (process.argv.length > 2) {
progress(1);

try {
log("<bold:Building TypeScript source...>");
log("<bold:Building TypeScript source (es6)...>");
await runBuild(true);
log("<bold:Building TypeScript source (commonjs)...>");
await runBuild();
log("<bold:Building distribution files...>");
let content = await runDist();
Expand Down
11 changes: 10 additions & 1 deletion admin/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

const packlist = require("npm-packlist");
const tar = require("tar");
const keccak256 = require("../packages/keccak256").keccak256;

const keccak256 = (function() {
try {
return require("../packages/keccak256").keccak256;
} catch (error) {
console.log("Cannot load Keccak256 (maybe not built yet? Not really a problem for most things)");
return null;
}
})();

const { dirnames, loadPackage, ROOT } = require("./depgraph");
const { resolve, saveJson } = require("./utils");

Expand Down
44 changes: 31 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@
"name": "root",
"private": true,
"scripts": {
"auto-build": "npm run build -- -w",
"bootstrap": "node ./admin/cmds/update-depgraph && lerna bootstrap --hoist",
"auto-build": "node ./admin/cmds/reset-build.js && npm run build -- -w",
"bootstrap": "node ./admin/cmds/reset-build.js && node ./admin/cmds/update-depgraph && lerna bootstrap --hoist",
"build": "tsc --build ./tsconfig.project.json",
"clean": "tsc --build --clean ./tsconfig.project.json",
"_dist": "npm run clean && npm run bootstrap && npm run build && lerna run dist",
"test": "npm run _dist && npm run test-check",
"test-check": "if [ \"$RUN_PHANTOMJS\" = \"1\" ]; then npm run-script test-phantomjs; else npm run-script test-node; fi",
"test-node": "cd packages/tests && mocha --no-colors --reporter ./tests/reporter ./tests/test-*.js",
"test-phantomjs": "cd packages/tests && npm run dist-phantomjs && phantomjs --web-security=false ../../node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js ./test.html ./tests/reporter.js",
"test-aion": "npm run dist && npm run test-aion-node",
"test-aion-node": "cd packages/aion-tests && mocha --no-colors --reporter ../tests/tests/reporter ./tests/test-*.js",
"update-versions": "npm run clean && npm run bootstrap && npm run build && node ./admin/cmds/update-versions",
"publish-all": "node ./admin/cmds/publish"
"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_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",
"_test_node": "cd packages/tests && mocha --no-colors --reporter ./tests/reporter ./tests/test-*.js",
"test_node": "npm run _test_prepare && npm run _test_node",

"_dist_old": "npm run clean && npm run bootstrap && npm run build && lerna run dist",
"old-test": "npm run _dist_old && npm run test-check",
"old-test-check": "if [ \"$RUN_PHANTOMJS\" = \"1\" ]; then npm run-script test-phantomjs; else npm run-script test-node; fi",
"old-test-node": "cd packages/tests && mocha --no-colors --reporter ./tests/reporter ./tests/test-*.js",
"old-test-phantomjs": "cd packages/tests && npm run dist-phantomjs && phantomjs --web-security=false ../../node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js ./test.html ./tests/reporter.js",
"old-test-aion": "npm run dist && npm run test-aion-node",
"old-test-aion-node": "cd packages/aion-tests && mocha --no-colors --reporter ../tests/tests/reporter ./tests/test-*.js",

"update-versions": "npm run _dist_prepare && node ./admin/cmds/update-versions",
"publish-all": "node ./admin/cmds/publish",
"build-docs": "flatworm docs.wrm docs"
},
"devDependencies": {
"@types/assert": "^1.4.1",
Expand All @@ -30,6 +41,13 @@
"scrypt-js": "2.0.4",
"semver": "^5.6.0",
"tar": "4.4.8",
"typescript": "3.3.3"
"typescript": "3.3.3",
"rollup": "1.20.1",
"rollup-plugin-commonjs": "10.0.2",
"rollup-plugin-json": "4.0.0",
"rollup-plugin-node-resolve": "5.2.0",
"rollup-plugin-terser": "5.1.1",
"rollup-plugin-uglify": "6.0.2",
"rollup-pluginutils": "2.8.1"
}
}
File renamed without changes.
1 change: 1 addition & 0 deletions packages/abi/lib.esm/_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const version = "abi/5.0.0-beta.136";
File renamed without changes.
91 changes: 91 additions & 0 deletions packages/abi/lib.esm/abi-coder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
"use strict";
// See: https://github.com/ethereum/wiki/wiki/Ethereum-Contract-ABI
import { arrayify } from "@ethersproject/bytes";
import { defineReadOnly } from "@ethersproject/properties";
import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);
import { Reader, Writer } from "./coders/abstract-coder";
import { AddressCoder } from "./coders/address";
import { ArrayCoder } from "./coders/array";
import { BooleanCoder } from "./coders/boolean";
import { BytesCoder } from "./coders/bytes";
import { FixedBytesCoder } from "./coders/fixed-bytes";
import { NullCoder } from "./coders/null";
import { NumberCoder } from "./coders/number";
import { StringCoder } from "./coders/string";
import { TupleCoder } from "./coders/tuple";
import { ParamType } from "./fragments";
const paramTypeBytes = new RegExp(/^bytes([0-9]*)$/);
const paramTypeNumber = new RegExp(/^(u?int)([0-9]*)$/);
export class AbiCoder {
constructor(coerceFunc) {
logger.checkNew(new.target, AbiCoder);
defineReadOnly(this, "coerceFunc", coerceFunc || null);
}
_getCoder(param) {
switch (param.baseType) {
case "address":
return new AddressCoder(param.name);
case "bool":
return new BooleanCoder(param.name);
case "string":
return new StringCoder(param.name);
case "bytes":
return new BytesCoder(param.name);
case "array":
return new ArrayCoder(this._getCoder(param.arrayChildren), param.arrayLength, param.name);
case "tuple":
return new TupleCoder((param.components || []).map((component) => {
return this._getCoder(component);
}), param.name);
case "":
return new NullCoder(param.name);
}
// u?int[0-9]*
let match = param.type.match(paramTypeNumber);
if (match) {
let size = parseInt(match[2] || "256");
if (size === 0 || size > 256 || (size % 8) !== 0) {
logger.throwArgumentError("invalid " + match[1] + " bit length", "param", param);
}
return new NumberCoder(size / 8, (match[1] === "int"), param.name);
}
// bytes[0-9]+
match = param.type.match(paramTypeBytes);
if (match) {
let size = parseInt(match[1]);
if (size === 0 || size > 32) {
logger.throwArgumentError("invalid bytes length", "param", param);
}
return new FixedBytesCoder(size, param.name);
}
return logger.throwError("invalid type", "type", param.type);
}
_getWordSize() { return 32; }
_getReader(data) {
return new Reader(data, this._getWordSize(), this.coerceFunc);
}
_getWriter() {
return new Writer(this._getWordSize());
}
encode(types, values) {
if (types.length !== values.length) {
logger.throwError("types/values length mismatch", Logger.errors.INVALID_ARGUMENT, {
count: { types: types.length, values: values.length },
value: { types: types, values: values }
});
}
let coders = types.map((type) => this._getCoder(ParamType.from(type)));
let coder = (new TupleCoder(coders, "_"));
let writer = this._getWriter();
coder.encode(writer, values);
return writer.data;
}
decode(types, data) {
let coders = types.map((type) => this._getCoder(ParamType.from(type)));
let coder = new TupleCoder(coders, "_");
return coder.decode(this._getReader(arrayify(data)));
}
}
export const defaultAbiCoder = new AbiCoder();
41 changes: 41 additions & 0 deletions packages/abi/lib.esm/coders/abstract-coder.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { BytesLike } from "@ethersproject/bytes";
import { BigNumber, BigNumberish } from "@ethersproject/bignumber";
export declare type CoerceFunc = (type: string, value: any) => any;
export declare abstract class Coder {
readonly name: string;
readonly type: string;
readonly localName: string;
readonly dynamic: boolean;
constructor(name: string, type: string, localName: string, dynamic: boolean);
_throwError(message: string, value: any): void;
abstract encode(writer: Writer, value: any): number;
abstract decode(reader: Reader): any;
}
export declare class Writer {
readonly wordSize: number;
_data: Uint8Array;
_padding: Uint8Array;
constructor(wordSize?: number);
readonly data: string;
readonly length: number;
_writeData(data: Uint8Array): number;
writeBytes(value: BytesLike): number;
_getValue(value: BigNumberish): Uint8Array;
writeValue(value: BigNumberish): number;
writeUpdatableValue(): (value: BigNumberish) => void;
}
export declare class Reader {
readonly wordSize: number;
readonly _data: Uint8Array;
readonly _coerceFunc: CoerceFunc;
_offset: number;
constructor(data: BytesLike, wordSize?: number, coerceFunc?: CoerceFunc);
readonly data: string;
readonly consumed: number;
static coerce(name: string, value: any): any;
coerce(name: string, value: any): any;
_peekBytes(offset: number, length: number): Uint8Array;
subReader(offset: number): Reader;
readBytes(length: number): Uint8Array;
readValue(): BigNumber;
}
Loading

0 comments on commit 73a0077

Please sign in to comment.