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

Improve build configuration #169

Merged
merged 5 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/waffle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
'use strict';

const Waffle = require('../dist/cli.js');
const Waffle = require('../dist/cjs/cli.js');
Waffle
.runCli(process.argv.slice(2))
.catch(e => {
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler/findInputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function findInputs(sourcePath: string) {
const stack = [sourcePath];
const inputFiles: string[] = [];
while (stack.length > 0) {
const dir = stack.pop();
const dir = stack.pop()!;
const files = fs.readdirSync(dir);
for (const file of files) {
const filePath = path.join(dir, file);
Expand Down
14 changes: 7 additions & 7 deletions lib/compiler/saveOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const fsOps = {
export async function saveOutput(output: any, config: Config, filesystem = fsOps) {
config.outputType = config.outputType || 'multiple';

filesystem.createDirectory(config.targetPath);
filesystem.createDirectory(config.targetPath!);

if (['multiple', 'all'].includes(config.outputType)) {
saveOutputSingletons(output, config, filesystem);
Expand All @@ -48,17 +48,17 @@ export async function saveOutput(output: any, config: Config, filesystem = fsOps
}

async function saveOutputSingletons(output: any, config: Config, filesystem = fsOps) {
for (const [, file] of Object.entries(output.contracts)) {
for (const [contractName, contractJson] of Object.entries(file)) {
const filePath = join(config.targetPath, `${contractName}.json`);
for (const [, file] of Object.entries<any>(output.contracts)) {
for (const [contractName, contractJson] of Object.entries<any>(file)) {
const filePath = join(config.targetPath!, `${contractName}.json`);
filesystem.writeFile(filePath, getContent(contractJson, config));
}
}
}

async function saveOutputCombined(output: any, config: Config, filesystem = fsOps) {
for (const [key, file] of Object.entries(output.contracts)) {
for (const [contractName, contractJson] of Object.entries(file)) {
for (const [key, file] of Object.entries<any>(output.contracts)) {
for (const [contractName, contractJson] of Object.entries<any>(file)) {
contractJson.bin = contractJson.evm.bytecode.object;
contractJson['bin-runtime'] = contractJson.evm.deployedBytecode.object;
contractJson.srcmap = contractJson.evm.bytecode.sourceMap;
Expand All @@ -80,7 +80,7 @@ async function saveOutputCombined(output: any, config: Config, filesystem = fsOp
output.sourceList = allSources;

filesystem.writeFile(
join(config.targetPath, 'Combined-Json.json'), JSON.stringify(output, null, 2)
join(config.targetPath!, 'Combined-Json.json'), JSON.stringify(output, null, 2)
);
}

Expand Down
18 changes: 9 additions & 9 deletions lib/matchers/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const solidity = (chai: any, utils: any) => {
Assertion.overwriteMethod('least', (_super: any) => overwriteBigNumberFunction('gte', 'at least', _super, utils));
Assertion.overwriteMethod('most', (_super: any) => overwriteBigNumberFunction('lte', 'at most', _super, utils));

Assertion.addProperty('reverted', function () {
Assertion.addProperty('reverted', function (this: any) {
const promise = this._obj;
const derivedPromise = promise.then(
(value: any) => {
Expand Down Expand Up @@ -41,7 +41,7 @@ const solidity = (chai: any, utils: any) => {
return this;
});

Assertion.addMethod('revertedWith', function (revertReason: string) {
Assertion.addMethod('revertedWith', function (this: any, revertReason: string) {
const promise = this._obj;
const derivedPromise = promise.then(
(value: any) => {
Expand Down Expand Up @@ -72,7 +72,7 @@ const solidity = (chai: any, utils: any) => {
const filterLogsWithTopics = (logs: any[], topic: any) =>
logs.filter((log) => log.topics.includes(topic));

Assertion.addMethod('emit', function (contract: Contract, eventName: string) {
Assertion.addMethod('emit', function (this: any, contract: Contract, eventName: string) {
const promise = this._obj;
const derivedPromise = promise.then((tx: any) =>
contract.provider.getTransactionReceipt(tx.hash)
Expand Down Expand Up @@ -132,7 +132,7 @@ const solidity = (chai: any, utils: any) => {
}
};

Assertion.addMethod('withArgs', function (...expectedArgs: any[]) {
Assertion.addMethod('withArgs', function (this: any, ...expectedArgs: any[]) {
const derivedPromise = this.promise.then(() => {
const actualArgs = this.contract.interface.parseLog(this.logs[0]);
assertArgsArraysEqual(this, expectedArgs, actualArgs.values);
Expand All @@ -142,7 +142,7 @@ const solidity = (chai: any, utils: any) => {
return this;
});

Assertion.addProperty('properAddress', function () {
Assertion.addProperty('properAddress', function (this: any) {
const subject = this._obj;
this.assert(/^0x[0-9-a-fA-F]{40}$/.test(subject),
`Expected "${subject}" to be a proper address`,
Expand All @@ -151,7 +151,7 @@ const solidity = (chai: any, utils: any) => {
subject);
});

Assertion.addProperty('properPrivateKey', function () {
Assertion.addProperty('properPrivateKey', function (this: any) {
const subject = this._obj;
this.assert(/^0x[0-9-a-fA-F]{64}$/.test(subject),
`Expected "${subject}" to be a proper private key`,
Expand All @@ -160,7 +160,7 @@ const solidity = (chai: any, utils: any) => {
subject);
});

Assertion.addMethod('properHex', function (length: number) {
Assertion.addMethod('properHex', function (this: any, length: number) {
const subject = this._obj;
const regexp = new RegExp(`^0x[0-9-a-fA-F]{${length}}$`);
this.assert(regexp.test(subject),
Expand All @@ -170,7 +170,7 @@ const solidity = (chai: any, utils: any) => {
subject);
});

Assertion.addMethod('changeBalance', function (wallet: Wallet, balanceChange: any) {
Assertion.addMethod('changeBalance', function (this: any, wallet: Wallet, balanceChange: any) {
const subject = this._obj;
if (typeof subject !== 'function') {
throw new Error(`Expect subject should be a callback returning the Promise
Expand All @@ -191,7 +191,7 @@ const solidity = (chai: any, utils: any) => {
return this;
});

Assertion.addMethod('changeBalances', function (wallets: Wallet[], balanceChanges: any[]) {
Assertion.addMethod('changeBalances', function (this: any, wallets: Wallet[], balanceChanges: any[]) {
const subject = this._obj;
if (typeof subject !== 'function') {
throw new Error(`Expect subject should be a callback returning the Promise
Expand Down
2 changes: 1 addition & 1 deletion lib/matchers/overwriteBigNumberFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const overwriteBigNumberFunction = (
readableName: string,
_super: (...args: any[]) => any,
chaiUtils: {flag: (...args: any[]) => any}
) => function (...args: any[]) {
) => function (this: any, ...args: any[]) {
const [actual] = args;
const expected = chaiUtils.flag(this, 'object');
if (utils.BigNumber.isBigNumber(expected)) {
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@
"repository": "[email protected]:EthWorks/Waffle.git",
"private": false,
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.ts",
"types": "dist/esm/index.d.ts",
"bin": {
"waffle": "./bin/waffle"
},
"scripts": {
"prepublishOnly": "yarn clean && yarn build",
"prepublishOnly": "yarn build",
"test:buildonly": "ts-node script/buildTestContracts",
"test:nobuild": "export NODE_ENV=test && mocha",
"test": "yarn test:buildonly && yarn test:nobuild",
"lint": "eslint '{lib,test}/**/*.ts'",
"lint:fix": "eslint --fix '{lib,test}/**/*.ts'",
"build": "tsc -p tsconfig.build.json",
"build": "rimraf ./dist && yarn build:esm && yarn build:cjs",
"build:esm": "tsc -p tsconfig.build.json --outDir dist/esm --module ES6",
"build:cjs": "tsc -p tsconfig.build.json --outDir dist/cjs --declaration false",
"clean": "rimraf ./dist ./test/compiler/build ./test/example/build ./test/matchers/build"
},
"engines": {
Expand Down
4 changes: 0 additions & 4 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@
"include": [
"lib",
],
"compilerOptions": {
"allowJs": false,
"declaration": true
}
}
21 changes: 12 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"compilerOptions": {
"allowJs": true,
"declaration": true,
"esModuleInterop": true,
"lib": [
"esnext"
],
"typeRoots": [
"node_modules/@types",
"shims",
"ES2018"
],
"module": "CommonJS",
"moduleResolution": "node",
"outDir": "dist",
"resolveJsonModule": true,
"esModuleInterop": true,
"noImplicitAny": true,
"skipLibCheck": true
"skipLibCheck": true,
"strict": true,
"target": "ES2018",
"typeRoots": [
"node_modules/@types",
"shims"
]
}
}