From 49c62946c9b84262ed05b15ae65d95cbb9b877fd Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 26 Aug 2021 12:13:28 +0200 Subject: [PATCH] better org of types --- apps/remix-ide/src/app/tabs/compile-tab.js | 3 +- apps/solidity-compiler/src/app/compiler.ts | 3 +- libs/remix-lib/src/index.ts | 55 ++++++++----------- libs/remix-lib/src/types/ICompilerApi.ts | 41 ++++++++++++++ .../src/lib/compiler-container.tsx | 3 +- .../solidity-compiler/src/lib/types/index.ts | 45 +-------------- 6 files changed, 73 insertions(+), 77 deletions(-) create mode 100644 libs/remix-lib/src/types/ICompilerApi.ts diff --git a/apps/remix-ide/src/app/tabs/compile-tab.js b/apps/remix-ide/src/app/tabs/compile-tab.js index 39c66d3ec6..61dc9200b4 100644 --- a/apps/remix-ide/src/app/tabs/compile-tab.js +++ b/apps/remix-ide/src/app/tabs/compile-tab.js @@ -4,6 +4,7 @@ import ReactDOM from 'react-dom' import { SolidityCompiler, CompileTab as CompileTabLogic, parseContracts } from '@remix-ui/solidity-compiler' // eslint-disable-line import { CompilerApiMixin } from '@remixproject/solidity-compiler-plugin' import { ViewPlugin } from '@remixproject/engine-web' +import { ICompilerApi } from '@remix-project/remix-lib-ts' import * as packageJson from '../../../../../package.json' const EventEmitter = require('events') @@ -32,7 +33,7 @@ const profile = { // - events: ['compilationFinished'], // - methods: ['getCompilationResult'] -class CompileTab extends CompilerApiMixin(ViewPlugin) { +class CompileTab extends CompilerApiMixin(ViewPlugin) { // implements ICompilerApi constructor () { super(profile) this.initCompilerApi() diff --git a/apps/solidity-compiler/src/app/compiler.ts b/apps/solidity-compiler/src/app/compiler.ts index 7e6deb8c98..0d1cd1e620 100644 --- a/apps/solidity-compiler/src/app/compiler.ts +++ b/apps/solidity-compiler/src/app/compiler.ts @@ -1,6 +1,7 @@ import { PluginClient } from "@remixproject/plugin"; import { createClient } from "@remixproject/plugin-webview"; import { CompilerApiMixin } from './compiler-api' +import { ICompilerApi } from '@remix-project/remix-lib-ts' const profile = { name: 'solidity', @@ -23,7 +24,7 @@ export interface ConfigurationSettings { runs: string } -export class CompilerClientApi extends CompilerApiMixin(PluginClient) { +export class CompilerClientApi extends CompilerApiMixin(PluginClient) implements ICompilerApi { // interface matches libs/remix-ui/solidity-compiler/types/index.ts : ICompilerApi currentFile: string contractMap: { diff --git a/libs/remix-lib/src/index.ts b/libs/remix-lib/src/index.ts index d3d37231f1..20e192bf9b 100644 --- a/libs/remix-lib/src/index.ts +++ b/libs/remix-lib/src/index.ts @@ -18,36 +18,29 @@ import * as typeConversion from './execution/typeConversion' import { TxRunnerVM } from './execution/txRunnerVM' import { TxRunnerWeb3 } from './execution/txRunnerWeb3' import * as txResultHelper from './helpers/txResultHelper' +export { ICompilerApi, ConfigurationSettings} from './types/ICompilerApi' -export = modules() - -function modules () { - return { - EventManager: EventManager, - helpers: { - ui: uiHelper, - compiler: compilerHelper, - txResultHelper - }, - vm: { - Web3Providers: Web3Providers, - DummyProvider: DummyProvider, - Web3VMProvider: Web3VmProvider - }, - Storage: Storage, - util: util, - execution: { - EventsDecoder: EventsDecoder, - txExecution: txExecution, - txHelper: txHelper, - txFormat: txFormat, - txListener: TxListener, - TxRunner: TxRunner, - TxRunnerWeb3: TxRunnerWeb3, - TxRunnerVM: TxRunnerVM, - typeConversion: typeConversion, - LogsManager, - forkAt - } - } +const helpers = { + ui: uiHelper, + compiler: compilerHelper, + txResultHelper +} +const vm = { + Web3Providers: Web3Providers, + DummyProvider: DummyProvider, + Web3VMProvider: Web3VmProvider +} +const execution = { + EventsDecoder: EventsDecoder, + txExecution: txExecution, + txHelper: txHelper, + txFormat: txFormat, + txListener: TxListener, + TxRunner: TxRunner, + TxRunnerWeb3: TxRunnerWeb3, + TxRunnerVM: TxRunnerVM, + typeConversion: typeConversion, + LogsManager, + forkAt } +export { EventManager, helpers, vm, Storage, util, execution } diff --git a/libs/remix-lib/src/types/ICompilerApi.ts b/libs/remix-lib/src/types/ICompilerApi.ts new file mode 100644 index 0000000000..89dd12c6e6 --- /dev/null +++ b/libs/remix-lib/src/types/ICompilerApi.ts @@ -0,0 +1,41 @@ +export interface ICompilerApi { + currentFile: string + contractMap: { + file: string + } | Record + compileErrors: any + compileTabLogic: any + contractsDetails: Record + configurationSettings: ConfigurationSettings + + setHardHatCompilation: (value: boolean) => void + getParameters: () => any + setParameters: (params) => void + getConfiguration: (value: string) => string + setConfiguration: (name: string, value: string) => void + getFileManagerMode: () => string + setCompilerConfig: (settings: any) => void + + getCompilationResult: () => any + + onCurrentFileChanged: (fileName: string) => void + onResetResults: () => void, + onSetWorkspace: (workspace: any) => void + onNoFileSelected: () => void + onCompilationFinished: (contractsDetails: any, contractMap: any) => void + onSessionSwitched: () => void + onContentChanged: () => void + + fileExists: (file: string) => Promise + writeFile: (file: string, content: string) => Promise + readFile: (file: string) => Promise + open: (file: string) => void + } + +export interface ConfigurationSettings { + version: string, + evmVersion: string, + language: string, + optimize: boolean, + runs: string +} \ No newline at end of file diff --git a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx index 3bd1032c76..b62525dc1f 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx +++ b/libs/remix-ui/solidity-compiler/src/lib/compiler-container.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useState, useRef, useReducer } from 'react' // eslint-disable-line import semver from 'semver' -import { CompilerContainerProps, ConfigurationSettings } from './types' +import { CompilerContainerProps } from './types' +import { ConfigurationSettings } from '@remix-project/remix-lib-ts' import * as helper from '../../../../../apps/remix-ide/src/lib/helper' import { canUseWorker, baseURLBin, baseURLWasm, urlFromVersion, pathToURL, promisedMiniXhr } from '@remix-project/remix-solidity' import { compilerReducer, compilerInitialState } from './reducers/compiler' diff --git a/libs/remix-ui/solidity-compiler/src/lib/types/index.ts b/libs/remix-ui/solidity-compiler/src/lib/types/index.ts index b477a8df85..fdb291b66d 100644 --- a/libs/remix-ui/solidity-compiler/src/lib/types/index.ts +++ b/libs/remix-ui/solidity-compiler/src/lib/types/index.ts @@ -1,43 +1,10 @@ +import { ICompilerApi, ConfigurationSettings } from '@remix-project/remix-lib-ts' export type onCurrentFileChanged = (fileName: string) => void export interface SolidityCompilerProps { plugin: ICompilerApi } -export interface ICompilerApi { - currentFile: string - contractMap: { - file: string - } | Record - compileErrors: any - compileTabLogic: any - contractsDetails: Record - configurationSettings: ConfigurationSettings - - setHardHatCompilation: (value: boolean) => void - getParameters: () => any - setParameters: (params) => void - getConfiguration: (value: string) => string - setConfiguration: (name: string, value: string) => void - getFileManagerMode: () => string - setCompilerConfig: (settings: any) => void - - getCompilationResult: () => any - - onCurrentFileChanged: (fileName: string) => void - onResetResults: () => void, - onSetWorkspace: (isLocalhost: boolean) => void - onNoFileSelected: () => void - onCompilationFinished: (contractsDetails: any, contractMap: any) => void - onSessionSwitched: () => void - onContentChanged: () => void - - fileExists: (file: string) => Promise - writeFile: (file: string, content: string) => Promise - readFile: (file: string) => Promise - open: (file: string) => void -} - export interface CompilerContainerProps { api: any, compileTabLogic: any, @@ -55,12 +22,4 @@ export interface ContractSelectionProps { } | Record, modal: (title: string, message: string | JSX.Element, okLabel: string, okFn: () => void, cancelLabel?: string, cancelFn?: () => void) => void, contractsDetails: Record -} - -export interface ConfigurationSettings { - version: string, - evmVersion: string, - language: string, - optimize: boolean, - runs: string -} +} \ No newline at end of file