diff --git a/libs/remix-solidity/.eslintrc b/libs/remix-solidity/.eslintrc new file mode 100644 index 0000000000..e060220185 --- /dev/null +++ b/libs/remix-solidity/.eslintrc @@ -0,0 +1,15 @@ +{ + "extends": "../../.eslintrc", + "rules": { + "@typescript-eslint/no-explicit-any": "off", + "@typescript-eslint/no-var-requires": "off", + "@typescript-eslint/no-unused-vars": "off" + }, + "env": { + "browser": true, + "amd": true, + "node": true, + "es6": true + }, + "ignorePatterns": ["!**/*"] +} \ No newline at end of file diff --git a/libs/remix-solidity/index.ts b/libs/remix-solidity/index.ts deleted file mode 100644 index f62854b786..0000000000 --- a/libs/remix-solidity/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { Compiler } from './src/compiler/compiler' -export { default as CompilerInput} from './src/compiler/compiler-input' diff --git a/libs/remix-solidity/package.json b/libs/remix-solidity/package.json index 49e639566b..ea4419b768 100644 --- a/libs/remix-solidity/package.json +++ b/libs/remix-solidity/package.json @@ -1,5 +1,5 @@ { - "name": "remix-solidity", + "name": "@remix-project/remix-solidity", "version": "0.3.30", "description": "Tool to load and run Solidity compiler", "main": "./dist/index.js", @@ -16,7 +16,7 @@ ], "dependencies": { "eslint-scope": "^5.0.0", - "remix-lib": "0.4.29", + "@remix-project/remix-lib": "0.4.29", "solc": "^0.6.0", "webworkify": "^1.2.1" }, @@ -37,7 +37,7 @@ "scripts": { "build": "tsc", "lint": "standard", - "test": "tsc && tape ./test/tests.js" + "test": "./../../node_modules/.bin/tape ./test/tests.js" }, "standard": { "ignore": [ diff --git a/libs/remix-solidity/src/compiler/compiler-input.ts b/libs/remix-solidity/src/compiler/compiler-input.ts index f474fd8019..0d87a2ecd8 100644 --- a/libs/remix-solidity/src/compiler/compiler-input.ts +++ b/libs/remix-solidity/src/compiler/compiler-input.ts @@ -2,7 +2,7 @@ import { CompilerInput, Source, CompilerInputOptions } from './types' -export default (sources: Source, opts: CompilerInputOptions) => { +export default (sources: Source, opts: CompilerInputOptions): string => { const o: CompilerInput = { language: 'Solidity', sources: sources, diff --git a/libs/remix-solidity/src/compiler/compiler-worker.ts b/libs/remix-solidity/src/compiler/compiler-worker.ts index 480fbb8524..06ec145f0b 100644 --- a/libs/remix-solidity/src/compiler/compiler-worker.ts +++ b/libs/remix-solidity/src/compiler/compiler-worker.ts @@ -2,39 +2,41 @@ import solc from 'solc/wrapper' import { CompilerInput, MessageToWorker } from './types' -var compileJSON: ((input: CompilerInput) => string) | null = (input) => { return '' } -var missingInputs: string[] = [] +let compileJSON: ((input: CompilerInput) => string) | null = (input) => { return '' } +const missingInputs: string[] = [] // 'DedicatedWorkerGlobalScope' object (the Worker global scope) is accessible through the self keyword // 'dom' and 'webworker' library files can't be included together https://github.com/microsoft/TypeScript/issues/20595 -export default (self) => { +export default (self): void => { // eslint-disable-line @typescript-eslint/explicit-module-boundary-types self.addEventListener('message', (e) => { const data: MessageToWorker = e.data switch (data.cmd) { case 'loadVersion': - delete self.Module - // NOTE: workaround some browsers? - self.Module = undefined - compileJSON = null - //importScripts() method of synchronously imports one or more scripts into the worker's scope - self.importScripts(data.data) - let compiler: solc = solc(self.Module) - compileJSON = (input) => { - try { - let missingInputsCallback = (path) => { - missingInputs.push(path) - return { 'error': 'Deferred import' } + { + delete self.Module + // NOTE: workaround some browsers? + self.Module = undefined + compileJSON = null + //importScripts() method of synchronously imports one or more scripts into the worker's scope + self.importScripts(data.data) + const compiler: solc = solc(self.Module) + compileJSON = (input) => { + try { + const missingInputsCallback = (path) => { + missingInputs.push(path) + return { 'error': 'Deferred import' } + } + return compiler.compile(input, { import: missingInputsCallback }) + } catch (exception) { + return JSON.stringify({ error: 'Uncaught JavaScript exception:\n' + exception }) } - return compiler.compile(input, { import: missingInputsCallback }) - } catch (exception) { - return JSON.stringify({ error: 'Uncaught JavaScript exception:\n' + exception }) } + self.postMessage({ + cmd: 'versionLoaded', + data: compiler.version() + }) + break } - self.postMessage({ - cmd: 'versionLoaded', - data: compiler.version() - }) - break case 'compile': missingInputs.length = 0 diff --git a/libs/remix-solidity/src/compiler/compiler.ts b/libs/remix-solidity/src/compiler/compiler.ts index d9975011bf..6ec30d6bea 100644 --- a/libs/remix-solidity/src/compiler/compiler.ts +++ b/libs/remix-solidity/src/compiler/compiler.ts @@ -3,7 +3,7 @@ import { update } from 'solc/abi' import webworkify from 'webworkify' import compilerInput from './compiler-input' -import { EventManager } from 'remix-lib' +import { EventManager } from '@remix-project/remix-lib' import { default as txHelper } from './txHelper'; import { Source, SourceWithTarget, MessageFromWorker, CompilerState, CompilationResult, visitContractsCallbackParam, visitContractsCallbackInterface, CompilationError, @@ -13,10 +13,10 @@ import { Source, SourceWithTarget, MessageFromWorker, CompilerState, Compilation trigger compilationFinished, compilerLoaded, compilationStarted, compilationDuration */ export class Compiler { - event: EventManager + event state: CompilerState - constructor (public handleImportCall: (fileurl: string, cb: Function) => void) { + constructor (public handleImportCall: (fileurl: string, cb) => void) { this.event = new EventManager() this.state = { compileJSON: null, @@ -51,7 +51,7 @@ export class Compiler { * @param value value of key in CompilerState */ - set (key: K, value: CompilerState[K]) { + set (key: K, value: CompilerState[K]): void { this.state[key] = value } @@ -101,7 +101,7 @@ export class Compiler { if (this.state.worker === null) { const compiler: any = typeof (window) === 'undefined' ? require('solc') : require('solc/wrapper')(window['Module']) this.state.compileJSON = (source: SourceWithTarget) => { - let missingInputs: string[] = [] + const missingInputs: string[] = [] const missingInputsCallback = (path: string) => { missingInputs.push(path) return { error: 'Deferred import' } @@ -129,7 +129,7 @@ export class Compiler { */ onCompilationFinished (data: CompilationResult, missingInputs?: string[], source?: SourceWithTarget): void { - let noFatalErrors: boolean = true // ie warnings are ok + let noFatalErrors = true // ie warnings are ok const checkIfFatalError = (error: CompilationError) => { // Ignore warnings and the 'Deferred import' error as those are generated by us as a workaround @@ -192,7 +192,7 @@ export class Compiler { this.state.compileJSON = (source: SourceWithTarget) => { this.onCompilationFinished({ error: { formattedMessage: 'Compiler not yet loaded.' } }) } - let newScript: HTMLScriptElement = document.createElement('script') + const newScript: HTMLScriptElement = document.createElement('script') newScript.type = 'text/javascript' newScript.src = url document.getElementsByTagName('head')[0].appendChild(newScript) @@ -212,7 +212,7 @@ export class Compiler { loadWorker (url: string): void { this.state.worker = webworkify(require('./compiler-worker.js').default) - let jobs: Record<'sources', SourceWithTarget> [] = [] + const jobs: Record<'sources', SourceWithTarget> [] = [] this.state.worker.addEventListener('message', (msg: Record <'data', MessageFromWorker>) => { const data: MessageFromWorker = msg.data @@ -220,7 +220,8 @@ export class Compiler { case 'versionLoaded': if(data.data) this.onCompilerLoaded(data.data) break - case 'compiled': + case 'compiled': + { let result: CompilationResult if(data.data && data.job !== undefined && data.job >= 0) { try { @@ -236,6 +237,7 @@ export class Compiler { this.onCompilationFinished(result, data.missingInputs, sources) } break + } } }) @@ -275,7 +277,7 @@ export class Compiler { importHints = importHints || [] // FIXME: This will only match imports if the file begins with one '.' // It should tokenize by lines and check each. - const importRegex: RegExp = /^\s*import\s*[\'\"]([^\'\"]+)[\'\"];/g + const importRegex = /^\s*import\s*['"]([^'"]+)['"];/g for (const fileName in files) { let match: RegExpExecArray | null while ((match = importRegex.exec(files[fileName].content))) { diff --git a/libs/remix-solidity/src/compiler/types.ts b/libs/remix-solidity/src/compiler/types.ts index 56a0d3ff79..df5ce4aaca 100644 --- a/libs/remix-solidity/src/compiler/types.ts +++ b/libs/remix-solidity/src/compiler/types.ts @@ -273,7 +273,7 @@ export interface CompilationResult { ///////// export interface AstNode { absolutePath?: string - exportedSymbols?: Object + exportedSymbols?: Record id: number nodeType: string nodes?: Array @@ -302,7 +302,7 @@ export interface CompilationResult { constant?: boolean name?: string public?: boolean - exportedSymbols?: Object + exportedSymbols?: Record argumentTypes?: null absolutePath?: string [x: string]: any @@ -325,7 +325,7 @@ export interface CompilationResult { /** EVM-related outputs */ evm: { assembly: string - legacyAssembly: {} + legacyAssembly: Record /** Bytecode and related details. */ bytecode: BytecodeObject deployedBytecode: BytecodeObject diff --git a/libs/remix-solidity/src/index.ts b/libs/remix-solidity/src/index.ts new file mode 100644 index 0000000000..c6972c95c4 --- /dev/null +++ b/libs/remix-solidity/src/index.ts @@ -0,0 +1,2 @@ +export { Compiler } from './compiler/compiler' +export { default as CompilerInput} from './compiler/compiler-input' diff --git a/libs/remix-solidity/tsconfig.json b/libs/remix-solidity/tsconfig.json index 9cb9baf18e..a73c9a881d 100644 --- a/libs/remix-solidity/tsconfig.json +++ b/libs/remix-solidity/tsconfig.json @@ -1,24 +1,7 @@ { - "include": ["src", "index.ts"], + "extends": "../../tsconfig.json", "compilerOptions": { - "target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - "lib": ["dom", "es2018"], /* Specify library files to be included in the compilation. */ - "declaration": true, /* Generates corresponding '.d.ts' file. */ - "sourceMap": true, /* Generates corresponding '.map' file. */ - "outDir": "./dist", /* Redirect output structure to the directory. */ - /* Strict Type-Checking Options */ - "strict": true, /* Enable all strict type-checking options. */ - "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */ - /* Module Resolution Options */ - "baseUrl": "./src", /* Base directory to resolve non-absolute module names. */ - "paths": { "remix-solidity": ["./"] }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - "typeRoots": [ - "./@types", - "./node_modules/@types" - ], - "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - /* Experimental Options */ - "experimentalDecorators": false, /* Enables experimental support for ES7 decorators. */ - } -} \ No newline at end of file + "types": ["node"] + }, + "include": ["**/*.ts"] +} diff --git a/libs/remix-solidity/tsconfig.lib.json b/libs/remix-solidity/tsconfig.lib.json new file mode 100644 index 0000000000..736089467e --- /dev/null +++ b/libs/remix-solidity/tsconfig.lib.json @@ -0,0 +1,15 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "../../dist/out-tsc", + "declaration": true, + "rootDir": "./src", + "types": ["node"] + }, + "exclude": [ + "**/*.spec.ts" + ], + "include": ["**/*.ts"] + } + \ No newline at end of file diff --git a/workspace.json b/workspace.json index 0524b502a5..28a8e34aeb 100644 --- a/workspace.json +++ b/workspace.json @@ -269,28 +269,25 @@ }, "remix-solidity": { "root": "libs/remix-solidity", - "sourceRoot": "libs/remix-solidity/", + "sourceRoot": "libs/remix-solidity/src", "projectType": "library", "schematics": {}, "architect": { "lint": { - "builder": "@nrwl/workspace:run-commands", + "builder": "@nrwl/linter:lint", "options": { - "commands": [ - { - "command": "./../../node_modules/.bin/npm-run-all lint" - } + "linter": "eslint", + "config": "libs/remix-solidity/.eslintrc", + "tsConfig": [ + "libs/remix-solidity/tsconfig.lib.json" ], - "cwd": "libs/remix-solidity" + "exclude": ["**/node_modules/**"] } }, "test": { "builder": "@nrwl/workspace:run-commands", "options": { "commands": [ - { - "command": "rm -rf ../../dist" - }, { "command": "./../../node_modules/.bin/npm-run-all test" } @@ -299,17 +296,13 @@ } }, "build": { - "builder": "@nrwl/workspace:run-commands", + "builder": "@nrwl/node:package", "options": { - "commands": [ - { - "command": "rm -rf ../../dist" - }, - { - "command": "./../../node_modules/.bin/npm-run-all build" - } - ], - "cwd": "libs/remix-solidity" + "outputPath": "dist/libs/remix-solidity", + "tsConfig": "libs/remix-solidity/tsconfig.lib.json", + "packageJson": "libs/remix-solidity/package.json", + "main": "libs/remix-solidity/src/index.ts", + "assets": ["libs/remix-solidity/*.md"] } } }