lint and build working for remix-solidity

pull/5/head
aniket-engg 4 years ago
parent a1f50eb141
commit fb478a8da7
  1. 15
      libs/remix-solidity/.eslintrc
  2. 2
      libs/remix-solidity/index.ts
  3. 6
      libs/remix-solidity/package.json
  4. 2
      libs/remix-solidity/src/compiler/compiler-input.ts
  5. 48
      libs/remix-solidity/src/compiler/compiler-worker.ts
  6. 22
      libs/remix-solidity/src/compiler/compiler.ts
  7. 6
      libs/remix-solidity/src/compiler/types.ts
  8. 2
      libs/remix-solidity/src/index.ts
  9. 27
      libs/remix-solidity/tsconfig.json
  10. 15
      libs/remix-solidity/tsconfig.lib.json
  11. 33
      workspace.json

@ -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": ["!**/*"]
}

@ -1,2 +0,0 @@
export { Compiler } from './src/compiler/compiler'
export { default as CompilerInput} from './src/compiler/compiler-input'

@ -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": [

@ -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,

@ -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

@ -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 <K extends keyof CompilerState>(key: K, value: CompilerState[K]) {
set <K extends keyof CompilerState>(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))) {

@ -273,7 +273,7 @@ export interface CompilationResult {
/////////
export interface AstNode {
absolutePath?: string
exportedSymbols?: Object
exportedSymbols?: Record<string, unknown>
id: number
nodeType: string
nodes?: Array<AstNode>
@ -302,7 +302,7 @@ export interface CompilationResult {
constant?: boolean
name?: string
public?: boolean
exportedSymbols?: Object
exportedSymbols?: Record<string, unknown>
argumentTypes?: null
absolutePath?: string
[x: string]: any
@ -325,7 +325,7 @@ export interface CompilationResult {
/** EVM-related outputs */
evm: {
assembly: string
legacyAssembly: {}
legacyAssembly: Record<string, unknown>
/** Bytecode and related details. */
bytecode: BytecodeObject
deployedBytecode: BytecodeObject

@ -0,0 +1,2 @@
export { Compiler } from './compiler/compiler'
export { default as CompilerInput} from './compiler/compiler-input'

@ -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. */
}
}
"types": ["node"]
},
"include": ["**/*.ts"]
}

@ -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"]
}

@ -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"]
}
}
}

Loading…
Cancel
Save