Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Bump TypeScript to 3.7 (#1347)
Browse files Browse the repository at this point in the history
* bump typescript to 3.7

* update ts-node and typescript-eslint dependencies

* update prettier for typescript 3.7 support

* fix all linter errors
  • Loading branch information
frangio authored and spalladino committed Dec 17, 2019
1 parent 961443e commit 28226a5
Show file tree
Hide file tree
Showing 35 changed files with 321 additions and 177 deletions.
10 changes: 5 additions & 5 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@
"@types/lodash": "^4.14.119",
"@types/mocha": "^5.2.5",
"@types/node": "^10.12.12",
"@typescript-eslint/eslint-plugin": "^1.9.0",
"@typescript-eslint/parser": "^1.9.0",
"@typescript-eslint/eslint-plugin": "^2.12.0",
"@typescript-eslint/parser": "^2.12.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"chai-bignumber": "^2.0.2",
Expand All @@ -163,11 +163,11 @@
"mock-stdlib-undeployed-2": "file:./test/mocks/mock-stdlib-undeployed-2",
"mock-stdlib-unpublished": "file:./test/mocks/mock-stdlib-unpublished",
"mock-stdlib-unsupported": "file:./test/mocks/mock-stdlib-unsupported",
"prettier": "^1.17.1",
"prettier": "^1.19.1",
"sinon": "^6.1.4",
"sinon-chai": "^3.2.0",
"ts-node": "^7.0.1",
"typescript": "^3.2.2",
"ts-node": "^8.5.4",
"typescript": "^3.7.3",
"yargs": "^7.1.0"
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function action(options: any): Promise<void> {
if (!options.dontExitProcess && process.env.NODE_ENV !== 'test') process.exit(0);
}

function getCommandProps(accounts: string[] = [], unit: string = 'ether'): InquirerQuestions {
function getCommandProps(accounts: string[] = [], unit = 'ether'): InquirerQuestions {
return {
...networksList('network', 'list'),
from: {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/models/compiler/Compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const execFile = promisify(callbackExecFile);
export async function compile(
compilerOptions?: ProjectCompilerOptions,
projectFile = new ProjectFile(),
force: boolean = false,
force = false,
): Promise<void> {
if (!force && state.alreadyCompiled) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ export async function compileProject(options: ProjectCompilerOptions = {}): Prom
};
}

export interface CompiledContract {
filePath: string;
contractName: string;
}

export interface ProjectCompileResult {
compilerVersion: SolcBuild;
contracts: RawContract[];
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/models/config/TruffleConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TruffleConfig = {
return this.exists(path);
},

async loadNetworkConfig(network: string, force: boolean = false, path: string = process.cwd()): Promise<any> {
async loadNetworkConfig(network: string, force = false, path: string = process.cwd()): Promise<any> {
const config = this.getConfig(force);
const { networks: networkList } = config;
if (!networkList[network])
Expand All @@ -38,7 +38,7 @@ const TruffleConfig = {
return config.contracts_build_directory;
},

getConfig(force: boolean = false): any | never {
getConfig(force = false): any | never {
if (!force && this.config) return this.config;
try {
this.config = TruffleConfigModule.detect({ logger: console });
Expand Down
17 changes: 7 additions & 10 deletions packages/cli/src/models/local/KitController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import child from '../../utils/child';
const simpleGit = patch('simple-git/promise');

export default class KitController {
public async unpack(
url: string,
branchName: string = 'stable',
workingDirPath: string = '',
config: KitFile,
): Promise<void | never> {
public async unpack(url: string, branchName = 'stable', workingDirPath = '', config: KitFile): Promise<void | never> {
if (!url) throw Error('A url must be provided.');
if (!config) throw Error('A config must be provided.');

Expand Down Expand Up @@ -61,13 +56,15 @@ export default class KitController {
}
}

public async verifyRepo(url: string, branchName: string = 'stable'): Promise<KitFile | never> {
public async verifyRepo(url: string, branchName = 'stable'): Promise<KitFile | never> {
if (!url) throw Error('A url must be provided.');

try {
const config = (await axios.get(
url.replace('.git', `/${branchName}/kit.json`).replace('github.com', 'raw.githubusercontent.com'),
)).data as KitFile;
const config = (
await axios.get(
url.replace('.git', `/${branchName}/kit.json`).replace('github.com', 'raw.githubusercontent.com'),
)
).data as KitFile;

// validate our json config
// TODO: derive the schema directly from the KitConfig type
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/models/local/LocalController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const DEFAULT_VERSION = '0.1.0';
export default class LocalController {
public projectFile: ProjectFile;

public constructor(projectFile: ProjectFile = new ProjectFile(), init: boolean = false) {
public constructor(projectFile: ProjectFile = new ProjectFile(), init = false) {
if (!init && !projectFile.exists()) {
throw Error(
`OpenZeppelin file ${projectFile.filePath} not found. Run 'openzeppelin init' first to initialize the project.`,
Expand All @@ -36,14 +36,14 @@ export default class LocalController {
this.projectFile = projectFile;
}

public init(name: string, version: string, force: boolean = false, publish: boolean = false): void | never {
public init(name: string, version: string, force = false, publish = false): void | never {
if (!name) throw Error('A project name must be provided to initialize the project.');
this.initProjectFile(name, version, force, publish);
Session.ignoreFile();
ConfigManager.initialize();
}

public initProjectFile(name: string, version: string, force: boolean = false, publish: boolean): void | never {
public initProjectFile(name: string, version: string, force = false, publish: boolean): void | never {
if (this.projectFile.exists() && !force) {
throw Error(`Cannot overwrite existing file ${this.projectFile.filePath}`);
}
Expand Down Expand Up @@ -146,7 +146,7 @@ export default class LocalController {
}

// DependencyController
public async linkDependencies(dependencies: string[], installDependencies: boolean = false): Promise<void> {
public async linkDependencies(dependencies: string[], installDependencies = false): Promise<void> {
const linkedDependencies = await Promise.all(
dependencies.map(
async (depNameVersion: string): Promise<string> => {
Expand Down
23 changes: 14 additions & 9 deletions packages/cli/src/models/network/NetworkController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export default class NetworkController {
}

// DeployerController
public async push(reupload: boolean = false, force: boolean = false): Promise<void | never> {
public async push(reupload = false, force = false): Promise<void | never> {
const changedLibraries = this._solidityLibsForPush(!reupload);
const contracts = this._contractsListForPush(!reupload, changedLibraries);
const buildArtifacts = getBuildArtifacts();
Expand Down Expand Up @@ -183,7 +183,7 @@ export default class NetworkController {
}

// Contract model
private _contractsListForPush(onlyChanged: boolean = false, changedLibraries: Contract[] = []): [string, Contract][] {
private _contractsListForPush(onlyChanged = false, changedLibraries: Contract[] = []): [string, Contract][] {
const newVersion = this._newVersionRequired();
const pipeline = [
contracts => toPairs(contracts),
Expand All @@ -207,10 +207,10 @@ export default class NetworkController {
}

// Contract model || SolidityLib model
private _solidityLibsForPush(onlyChanged: boolean = false): Contract[] | never {
private _solidityLibsForPush(onlyChanged = false): Contract[] | never {
const { contractNames, contractAliases } = this.projectFile;

let libNames = this._getAllSolidityLibNames(contractNames);
const libNames = this._getAllSolidityLibNames(contractNames);

const clashes = intersection(libNames, contractAliases);
if (!isEmpty(clashes)) {
Expand Down Expand Up @@ -314,7 +314,12 @@ export default class NetworkController {
// Contract model || SolidityLib model
private _hasChangedLibraries(contract: Contract, changedLibraries: Contract[]): boolean {
const libNames = getSolidityLibNames(contract.schema.bytecode);
return !isEmpty(intersection(changedLibraries.map(c => c.schema.contractName), libNames));
return !isEmpty(
intersection(
changedLibraries.map(c => c.schema.contractName),
libNames,
),
);
}

// Contract model || SolidityLib model
Expand Down Expand Up @@ -398,14 +403,14 @@ export default class NetworkController {
}

// Contract model
public checkContractDeployed(packageName: string, contractAlias: string, throwIfFail: boolean = false): void {
public checkContractDeployed(packageName: string, contractAlias: string, throwIfFail = false): void {
if (!packageName) packageName = this.projectFile.name;
const err = this._errorForContractDeployed(packageName, contractAlias);
if (err) this._handleErrorMessage(err, throwIfFail);
}

// Contract model
public checkLocalContractsDeployed(throwIfFail: boolean = false): void {
public checkLocalContractsDeployed(throwIfFail = false): void {
const err = this._errorForLocalContractsDeployed();
if (err) this._handleErrorMessage(err, throwIfFail);
}
Expand All @@ -425,7 +430,7 @@ export default class NetworkController {
}

// Contract model
public checkLocalContractDeployed(contractAlias: string, throwIfFail: boolean = false): void {
public checkLocalContractDeployed(contractAlias: string, throwIfFail = false): void {
// if (!packageName) packageName = this.projectFile.name
const err = this._errorForLocalContractDeployed(contractAlias);
if (err) this._handleErrorMessage(err, throwIfFail);
Expand All @@ -443,7 +448,7 @@ export default class NetworkController {
}

// TODO: move to utils folder or somewhere else
private _handleErrorMessage(msg: string, throwIfFail: boolean = false): void | never {
private _handleErrorMessage(msg: string, throwIfFail = false): void | never {
if (throwIfFail) {
throw Error(msg);
} else {
Expand Down
6 changes: 1 addition & 5 deletions packages/cli/src/models/network/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ const Session = {
return { network, expired: this._hasExpired(session) };
},

open(
{ network, from, timeout }: SessionOptions,
expires: number = DEFAULT_EXPIRATION_TIMEOUT,
logInfo: boolean = true,
): void {
open({ network, from, timeout }: SessionOptions, expires: number = DEFAULT_EXPIRATION_TIMEOUT, logInfo = true): void {
const expirationTimestamp = new Date(new Date().getTime() + expires * 1000);
fs.writeJson(SESSION_PATH, {
network,
Expand Down
9 changes: 6 additions & 3 deletions packages/cli/src/prompts/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { fromContractFullName, toContractFullName } from '../utils/naming';
import { ProxyType } from '../scripts/interfaces';
import NetworkFile, { ProxyInterface } from '../models/files/NetworkFile';

type ChoicesT = string[] | ({ [key: string]: any });
type ChoicesT = string[] | { [key: string]: any };

export interface InquirerQuestions {
[key: string]: InquirerQuestion;
Expand Down Expand Up @@ -52,7 +52,7 @@ interface MethodOptions {
constant?: boolean;
}

export let DISABLE_INTERACTIVITY: boolean =
export const DISABLE_INTERACTIVITY: boolean =
!process.stdin.isTTY ||
!!process.env.OPENZEPPELIN_NON_INTERACTIVE ||
!!process.env.ZOS_NON_INTERACTIVE ||
Expand Down Expand Up @@ -142,7 +142,10 @@ export function contractsList(name: string, message: string, type: string, sourc
return inquirerQuestion(name, message, type, contractsFromBuild);
// get contracts from project.json file
} else if (source === 'notAdded') {
const contracts = difference(contractsFromBuild, contractsFromLocal.map(({ value }) => value));
const contracts = difference(
contractsFromBuild,
contractsFromLocal.map(({ value }) => value),
);
return inquirerQuestion(name, message, type, contracts);
} else if (source === 'added') {
return inquirerQuestion(name, message, type, contractsFromLocal);
Expand Down
5 changes: 2 additions & 3 deletions packages/cli/test/commands/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ import ConfigManager from '../../src/models/config/ConfigManager';
import Telemetry from '../../src/telemetry';

program.Command.prototype.parseReset = function() {
var self = this;
this.args = [];
this.rawArgs = [];
this.options.forEach(function(option) {
self[option.name()] = undefined;
this.options.forEach(option => {
this[option.name()] = undefined;
});
this.commands.forEach(function(command) {
if (command.options) {
Expand Down
53 changes: 34 additions & 19 deletions packages/cli/test/scripts/update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ describe('update script', function() {
const createProxies = async function() {
this.networkFile = new NetworkFile(this.projectFile, network);

const contractsData = [{ name: 'ImplV1', alias: 'Impl' }, { name: 'WithLibraryImplV1', alias: 'WithLibraryImpl' }];
const contractsData = [
{ name: 'ImplV1', alias: 'Impl' },
{ name: 'WithLibraryImplV1', alias: 'WithLibraryImpl' },
];
await add({ contractsData, projectFile: this.projectFile });
await push({ network, txParams, networkFile: this.networkFile });

Expand Down Expand Up @@ -563,15 +566,19 @@ describe('update script', function() {
});

const { address: proxyAddress } = await assertProxyInfo(this.networkFile, 'Greeter', 0, { version: '1.2.0' });
(await GreeterV2.at(proxyAddress)
.methods.version()
.call()).should.eq('1.2.0');
(
await GreeterV2.at(proxyAddress)
.methods.version()
.call()
).should.eq('1.2.0');
const { address: anotherProxyAddress } = await assertProxyInfo(this.networkFile, 'Greeter', 0, {
version: '1.2.0',
});
(await GreeterV2.at(anotherProxyAddress)
.methods.version()
.call()).should.eq('1.2.0');
(
await GreeterV2.at(anotherProxyAddress)
.methods.version()
.call()
).should.eq('1.2.0');
});

it('should upgrade the version of all proxies given their package', async function() {
Expand All @@ -583,15 +590,19 @@ describe('update script', function() {
});

const { address: proxyAddress } = await assertProxyInfo(this.networkFile, 'Greeter', 0, { version: '1.2.0' });
(await GreeterV2.at(proxyAddress)
.methods.version()
.call()).should.eq('1.2.0');
(
await GreeterV2.at(proxyAddress)
.methods.version()
.call()
).should.eq('1.2.0');
const { address: anotherProxyAddress } = await assertProxyInfo(this.networkFile, 'Greeter', 0, {
version: '1.2.0',
});
(await GreeterV2.at(anotherProxyAddress)
.methods.version()
.call()).should.eq('1.2.0');
(
await GreeterV2.at(anotherProxyAddress)
.methods.version()
.call()
).should.eq('1.2.0');
});

it('should upgrade the version of all proxies', async function() {
Expand All @@ -603,15 +614,19 @@ describe('update script', function() {
});

const { address: proxyAddress } = await assertProxyInfo(this.networkFile, 'Greeter', 0, { version: '1.2.0' });
(await GreeterV2.at(proxyAddress)
.methods.version()
.call()).should.eq('1.2.0');
(
await GreeterV2.at(proxyAddress)
.methods.version()
.call()
).should.eq('1.2.0');
const { address: anotherProxyAddress } = await assertProxyInfo(this.networkFile, 'Greeter', 0, {
version: '1.2.0',
});
(await GreeterV2.at(anotherProxyAddress)
.methods.version()
.call()).should.eq('1.2.0');
(
await GreeterV2.at(anotherProxyAddress)
.methods.version()
.call()
).should.eq('1.2.0');
});
}).timeout(5000);
};
Expand Down
Loading

0 comments on commit 28226a5

Please sign in to comment.