Skip to content

Commit f5336c1

Browse files
committed
Initial code drop for v6-beta-exports.
1 parent 8278dcb commit f5336c1

File tree

184 files changed

+22459
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+22459
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/**
2+
output/**
3+
misc/**

.npmignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
# Ignore TypeScript config and caches
3+
tsconfig.*.json
4+
tsconfig.tsbuildinfo
5+
rollup.config.js
6+
output/**
7+
8+
# Ignore admin scripts and files
9+
src.ts/_admin/**
10+
lib.commonjs/_admin/**
11+
lib.esm/_admin/**
12+
types/_admin/**
13+
reporter.cjs
14+
package-commonjs.json
15+
16+
# Ignore test cases
17+
src.ts/_tests/**
18+
lib.commonjs/_tests/**
19+
lib.esm/_tests/**
20+
types/_tests/**
21+
testcases/**
22+
23+
# Ignore random junk
24+
.DS_Store
25+
node_modules/**
26+
misc/**

package-commonjs.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

package.json

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
{
2+
"author": "Richard Moore <[email protected]>",
3+
"dependencies": {
4+
"@noble/hashes": "1.1.2",
5+
"@noble/secp256k1": "1.6.3",
6+
"aes-js": "4.0.0-beta.2",
7+
"tslib": "2.4.0",
8+
"ws": "8.5.0"
9+
},
10+
"description": "Ethereum library.",
11+
"devDependencies": {
12+
"@rollup/plugin-node-resolve": "13.3.0",
13+
"@types/mocha": "9.1.1",
14+
"c8": "7.12.0",
15+
"mocha": "10.0.0",
16+
"rollup": "2.78.1",
17+
"typescript": "4.7.4",
18+
"uglify-js": "3.17.0"
19+
},
20+
"engines": {
21+
"node": ">=14.0.0"
22+
},
23+
"browser": {
24+
"./lib.esm/crypto/crypto.js": "./lib.esm/crypto/crypto-browser.js",
25+
"./lib.esm/providers/provider-ipcsocket.js": "./lib.esm/providers/provider-ipcsocket-browser.js",
26+
"./lib.esm/providers/ws.js": "./lib.esm/providers/ws-browser.js",
27+
"./lib.esm/utils/base64.js": "./lib.esm/utils/base64-browser.js",
28+
"./lib.esm/utils/geturl.js": "./lib.esm/utils/geturl-browser.js",
29+
"./lib.esm/wordlists/wordlists.js": "./lib.esm/wordlists/wordlists-browser.js"
30+
},
31+
"exports": {
32+
".": {
33+
"import": "./lib.esm/index.js",
34+
"require": "./lib.commonjs/index.js",
35+
"types": "./types/index.d.ts"
36+
},
37+
"./abi": {
38+
"import": "./lib.esm/abi/index.js",
39+
"require": "./lib.commonjs/abi/index.js",
40+
"types": "./types/abi/index.d.ts"
41+
},
42+
"./address": {
43+
"import": "./lib.esm/address/index.js",
44+
"require": "./lib.commonjs/address/index.js",
45+
"types": "./types/address/index.d.ts"
46+
},
47+
"./constants": {
48+
"import": "./lib.esm/constants/index.js",
49+
"require": "./lib.commonjs/constants/index.js",
50+
"types": "./types/constants/index.d.ts"
51+
},
52+
"./contract": {
53+
"import": "./lib.esm/contract/index.js",
54+
"require": "./lib.commonjs/contract/index.js",
55+
"types": "./types/contract/index.d.ts"
56+
},
57+
"./crypto": {
58+
"import": "./lib.esm/crypto/index.js",
59+
"require": "./lib.commonjs/crypto/index.js",
60+
"types": "./types/crypto/index.d.ts"
61+
},
62+
"./hash": {
63+
"import": "./lib.esm/hash/index.js",
64+
"require": "./lib.commonjs/hash/index.js",
65+
"types": "./types/hash/index.d.ts"
66+
},
67+
"./providers": {
68+
"import": "./lib.esm/providers/index.js",
69+
"require": "./lib.commonjs/providers/index.js",
70+
"types": "./types/providers/index.d.ts"
71+
},
72+
"./transaction": {
73+
"import": "./lib.esm/transaction/index.js",
74+
"require": "./lib.commonjs/transaction/index.js",
75+
"types": "./types/transaction/index.d.ts"
76+
},
77+
"./utils": {
78+
"import": "./lib.esm/utils/index.js",
79+
"require": "./lib.commonjs/utils/index.js",
80+
"types": "./types/utils/index.d.ts"
81+
},
82+
"./wallet": {
83+
"import": "./lib.esm/wallet/index.js",
84+
"require": "./lib.commonjs/wallet/index.js",
85+
"types": "./types/wallet/index.d.ts"
86+
},
87+
"./wordlists": {
88+
"import": "./lib.esm/wordlists/index.js",
89+
"require": "./lib.commonjs/wordlists/index.js",
90+
"types": "./types/wordlistsindex.d.ts"
91+
}
92+
},
93+
"keywords": [
94+
"ethereum",
95+
"ethers",
96+
"ethersjs"
97+
],
98+
"license": "MIT",
99+
"main": "./lib.commonjs/index.js",
100+
"module": "./lib.esm/index.js",
101+
"name": "ethers",
102+
"publishConfig": {
103+
"access": "public",
104+
"tag": "beta-exports"
105+
},
106+
"repository": {
107+
"type": "git",
108+
"url": "git://github.com/ethers-io/ethers.js.git"
109+
},
110+
"scripts": {
111+
"clean": "rm -rf dist lib.esm lib.commonjs types",
112+
"build": "tsc --project tsconfig.esm.json",
113+
"build-commonjs": "tsc --project tsconfig.commonjs.json && cp ./package-commonjs.json ./lib.commonjs/package.json",
114+
"build-types": "tsc --project tsconfig.types.json",
115+
"build-docs": "echo 'foo'",
116+
"auto-build": "npm run build -- -w",
117+
"build-all": "npm run build && npm run build-commonjs && npm run build-types",
118+
"build-clean": "npm run clean && npm run build-all",
119+
"_dist-stats": "gzip -k9f -S '.gz' ./dist/ethers.min.js && gzip -k9f -S '.gz' ./dist/wordlists-extra.min.js && du -hs ./dist/*.gz && echo '' && du -hs ./dist/*.js",
120+
"_build-dist": "rollup -c && uglifyjs ./dist/ethers.js -o ./dist/ethers.min.js && uglifyjs ./dist/wordlists-extra.js -o ./dist/wordlists-extra.min.js && npm run _dist-stats",
121+
"build-dist": "npm run build && npm run _build-dist",
122+
"stats": "echo 'Dependencies' && npm ls --all --omit=dev",
123+
"test": "mocha --reporter ./reporter.cjs ./lib.esm/_tests/test-*.js",
124+
"test-commonjs": "mocha --reporter ./reporter.cjs ./lib.commonjs/_tests/test-*.js",
125+
"test-coverage": "c8 -o output -r lcov -r text mocha --no-color --reporter ./reporter.cjs ./lib.esm/_tests/test-*.js | tee output/summary.txt"
126+
},
127+
"sideEffects": false,
128+
"type": "module",
129+
"types": "./types/index.d.ts",
130+
"version": "6.0.0-beta-exports.0"
131+
}

reporter.cjs

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
'use strict';
2+
3+
const Mocha = require('mocha');
4+
const {
5+
EVENT_RUN_BEGIN,
6+
EVENT_RUN_END,
7+
EVENT_TEST_BEGIN,
8+
EVENT_TEST_END,
9+
EVENT_TEST_FAIL,
10+
EVENT_TEST_PASS,
11+
EVENT_SUITE_BEGIN,
12+
EVENT_SUITE_END
13+
} = Mocha.Runner.constants;
14+
15+
16+
// See: https://stackoverflow.com/questions/9781218/how-to-change-node-jss-console-font-color
17+
let disableColor = false; //!(process.stdout.isTTY);
18+
process.argv.forEach((arg) => {
19+
if (arg === "--no-color") { disableColor = true; }
20+
});
21+
22+
const Colors = {
23+
"blue": "\x1b[0;34m",
24+
"blue+": "\x1b[0;1;34m",
25+
"cyan": "\x1b[0;36m",
26+
"cyan+": "\x1b[0;1;36m",
27+
"green": "\x1b[0;32m",
28+
"green+": "\x1b[0;1;32m",
29+
"magenta-": "\x1b[0;2;35m",
30+
"magenta": "\x1b[0;35m",
31+
"magenta+": "\x1b[0;1;35m",
32+
"red": "\x1b[0;31m",
33+
"red+": "\x1b[0;1;31m",
34+
"yellow": "\x1b[0;33m",
35+
"yellow+": "\x1b[0;1;33m",
36+
"dim": "\x1b[0;2;37m",
37+
"bold": "\x1b[0;1;37m",
38+
"normal": "\x1b[0m"
39+
};
40+
41+
function colorify(text) {
42+
return unescapeColor(text.replace(/(<([a-z+]+)>)/g, (all, _, color) => {
43+
if (disableColor) { return ""; }
44+
45+
const seq = Colors[color];
46+
if (seq == null) {
47+
console.log("UNKNOWN COLOR:", color);
48+
return "";
49+
}
50+
return seq;
51+
})) + Colors.normal;
52+
}
53+
54+
function escapeColor(text) {
55+
return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
56+
}
57+
58+
function unescapeColor(text) {
59+
return text.replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&amp;/g, "&");
60+
}
61+
62+
function getString(value) {
63+
if (value instanceof Error) {
64+
return value.stack;
65+
}
66+
return String(value);
67+
}
68+
69+
// To prevent environments from thinking we're dead due to lack of
70+
// output, we force output after 20s
71+
function getTime() { return (new Date()).getTime(); }
72+
const KEEP_ALIVE = 20 * 1000;
73+
74+
// this reporter outputs test results, indenting two spaces per suite
75+
class MyReporter {
76+
constructor(runner) {
77+
this._errors = [ ];
78+
this._indents = 1;
79+
this._lastLog = getTime();
80+
this._lastPass = "";
81+
this._lastPrefix = null;
82+
this._lastPrefixHeader = null;
83+
this._testLogs = [ ];
84+
this._suiteLogs = [ ];
85+
this._prefixCount = 0;
86+
const stats = runner.stats;
87+
88+
runner.once(EVENT_RUN_BEGIN, () => {
89+
90+
}).on(EVENT_SUITE_BEGIN, (suite) => {
91+
this._suiteLogs.push([ ]);
92+
suite._ethersLog = (text) => {
93+
this._suiteLogs[this._suiteLogs.length - 1].push(getString(text))
94+
};
95+
if (suite.title.trim()) {
96+
this.log(`<blue+>Suite: ${ escapeColor(suite.title) }`)
97+
}
98+
this.increaseIndent();
99+
100+
}).on(EVENT_SUITE_END, (suite) => {
101+
this.flush(true);
102+
this.decreaseIndent();
103+
const logs = this._suiteLogs.pop();
104+
if (logs.length) {
105+
logs.join("\n").split("\n").forEach((line) => {
106+
this.log(` <magenta+>&gt;&gt; <dim>${ escapeColor(line) }`);
107+
});
108+
}
109+
if (suite.title.trim()) { this.log(""); }
110+
111+
}).on(EVENT_TEST_BEGIN, (test) => {
112+
this._testLogs.push([ ]);
113+
test._ethersLog = (text) => {
114+
this._testLogs[this._testLogs.length - 1].push(getString(text))
115+
};
116+
117+
}).on(EVENT_TEST_END, (test) => {
118+
const logs = this._testLogs.pop();
119+
if (logs.length) {
120+
this.flush(false);
121+
logs.join("\n").split("\n").forEach((line) => {
122+
this.log(` <cyan+>&gt;&gt; <cyan->${ escapeColor(line) }`);
123+
});
124+
}
125+
126+
}).on(EVENT_TEST_PASS, (test) => {
127+
this.addPass(test.title);
128+
129+
}).on(EVENT_TEST_FAIL, (test, error) => {
130+
this.flush();
131+
this._errors.push({ test, error });
132+
this.log(
133+
` [ <red+>fail(${ this._errors.length }): <red>${ escapeColor(test.title) } - <normal>${ escapeColor(error.message) } ]`
134+
);
135+
136+
}).once(EVENT_RUN_END, () => {
137+
this.flush(true);
138+
this.indent = 0;
139+
140+
if (this._errors.length) {
141+
this._errors.forEach(({ test, error }, index) => {
142+
this.log("<cyan+>---------------------");
143+
this.log(`<red+>ERROR ${ index + 1 }: <red>${ escapeColor(test.title) }`);
144+
this.log(escapeColor(error.toString()));
145+
});
146+
this.log("<cyan+>=====================");
147+
}
148+
149+
const { duration, passes, failures } = stats;
150+
const total = passes + failures;
151+
this.log(`<bold>Done: <green+>${ passes }<green>/${ total } passed <red>(<red+>${ failures } <red>failed)`);
152+
});
153+
}
154+
155+
log(line) {
156+
this._lastLog = getTime();
157+
const indent = Array(this._indents).join(' ');
158+
console.log(`${ indent }${ colorify(line) }`);
159+
}
160+
161+
addPass(line) {
162+
const prefix = line.split(":")[0];
163+
if (prefix === this._lastPrefix) {
164+
this._prefixCount++;
165+
if (getTime() - this._lastLog > KEEP_ALIVE) {
166+
const didLog = this.flush(false);
167+
// Nothing was output, so show *something* so the
168+
// environment knows we're still alive and kicking
169+
if (!didLog) {
170+
this.log(" <yellow>[ keep-alive; forced output ]")
171+
}
172+
}
173+
} else {
174+
this.flush(true);
175+
this._lastPrefixHeader = null;
176+
this._lastPrefix = prefix;
177+
this._prefixCount = 1;
178+
}
179+
this._lastLine = line;
180+
}
181+
182+
flush(reset) {
183+
let didLog = false;
184+
if (this._lastPrefix != null) {
185+
if (this._prefixCount === 1 && this._lastPrefixHeader == null) {
186+
this.log(escapeColor(this._lastLine));
187+
didLog = true;
188+
} else if (this._prefixCount > 0) {
189+
if (this._lastPrefixHeader !== this._lastPrefix) {
190+
this.log(`<cyan>${ escapeColor(this._lastPrefix) }:`);
191+
this._lastPrefixHeader = this._lastPrefix;
192+
}
193+
this.log(` - ${ this._prefixCount } tests passed (prefix coalesced)`);
194+
didLog = true;
195+
}
196+
}
197+
198+
if (reset) {
199+
this._lastPrefixHeader = null;
200+
this._lastPrefix = null;
201+
}
202+
203+
this._prefixCount = 0;
204+
205+
return didLog;
206+
}
207+
208+
increaseIndent() { this._indents++; }
209+
210+
decreaseIndent() { this._indents--; }
211+
}
212+
213+
module.exports = MyReporter;

0 commit comments

Comments
 (0)