Fixed remixd linting errors

pull/5370/head
ioedeveloper 4 years ago committed by yann300
parent 2b89fbc725
commit 430ae62d28
  1. 3
      .circleci/config.yml
  2. 34
      libs/remixd/src/bin/remixd.ts
  3. 4
      libs/remixd/src/serviceList.ts
  4. 38
      libs/remixd/src/services/remixdClient.ts
  5. 2
      libs/remixd/src/types/index.ts
  6. 6
      libs/remixd/src/utils.ts
  7. 8
      libs/remixd/src/websocket.ts
  8. 5
      package.json
  9. 1
      tsconfig.json

@ -47,6 +47,7 @@ jobs:
- checkout
- run: npm install
- run: npm run lint
- run: npm run lint remix-ide-e2e
- run: npm run build:libs
- run: npm run downloadsolc_root
- run: npm run build
@ -84,6 +85,7 @@ jobs:
- checkout
- run: npm install
- run: npm run lint
- run: npm run lint remix-ide-e2e
- run: npm run build:libs
- run: npm run downloadsolc_root
- run: npm run build
@ -126,6 +128,7 @@ jobs:
- checkout
- run: npm install
- run: npm run lint
- run: npm run lint remix-ide-e2e
- run: npm run build:libs
- run: npm run downloadsolc_root
- run: npm run build

@ -1,7 +1,7 @@
#!/usr/bin/env node
import WebSocket from '../websocket'
import * as servicesList from '../serviceList'
import * as WS from 'ws'
import * as WS from 'ws' // eslint-disable-line
import { getDomain } from '../utils'
import Axios from 'axios'
import * as fs from 'fs-extra'
@ -10,14 +10,14 @@ import * as program from 'commander'
(async () => {
program
.usage('-s <shared folder>')
.description('Provide a two-way connection between the local computer and Remix IDE')
.option('--remix-ide <url>', 'URL of remix instance allowed to connect to this web sockect connection')
.option('-s, --shared-folder <path>', 'Folder to share with Remix IDE')
.option('--read-only', 'Treat shared folder as read-only (experimental)')
.on('--help', function(){
console.log('\nExample:\n\n remixd -s ./ --remix-ide http://localhost:8080')
}).parse(process.argv)
.usage('-s <shared folder>')
.description('Provide a two-way connection between the local computer and Remix IDE')
.option('--remix-ide <url>', 'URL of remix instance allowed to connect to this web sockect connection')
.option('-s, --shared-folder <path>', 'Folder to share with Remix IDE')
.option('--read-only', 'Treat shared folder as read-only (experimental)')
.on('--help', function () {
console.log('\nExample:\n\n remixd -s ./ --remix-ide http://localhost:8080')
}).parse(process.argv)
// eslint-disable-next-line
const killCallBack: Array<Function> = []
@ -38,7 +38,7 @@ import * as program from 'commander'
console.log('\x1b[33m%s\x1b[0m', '[WARN] Any application that runs on your computer can potentially read from and write to all files in the directory.')
console.log('\x1b[33m%s\x1b[0m', '[WARN] Symbolic links are not forwarded to Remix IDE\n')
try {
const sharedFolderClient = new servicesList['sharedfolder']()
const sharedFolderClient = new servicesList.Sharedfolder()
const websocketHandler = new WebSocket(65520, { remixIdeUrl: program.remixIde }, sharedFolderClient)
websocketHandler.start((ws: WS) => {
@ -47,7 +47,7 @@ import * as program from 'commander'
sharedFolderClient.sharedFolder(program.sharedFolder, program.readOnly || false)
})
killCallBack.push(websocketHandler.close.bind(websocketHandler))
} catch(error) {
} catch (error) {
throw new Error(error)
}
} else {
@ -64,7 +64,7 @@ import * as program from 'commander'
}
}
}
process.on('SIGINT', kill) // catch ctrl-c
process.on('SIGTERM', kill) // catch kill
process.on('exit', kill)
@ -73,23 +73,23 @@ import * as program from 'commander'
if (!origin) return false
const domain = getDomain(origin)
const gistUrl = 'https://gist.githubusercontent.com/EthereumRemix/091ccc57986452bbb33f57abfb13d173/raw/3367e019335746b73288e3710af2922d4c8ef5a3/origins.json'
try {
const { data } = await Axios.get(gistUrl)
try {
await fs.writeJSON(path.resolve(__dirname + '/../origins.json'), { data })
await fs.writeJSON(path.resolve(path.join(__dirname, '..', 'origins.json')), { data })
} catch (e) {
console.error(e)
}
return data.includes(origin) ? data.includes(origin) : data.includes(domain)
} catch (e) {
try {
// eslint-disable-next-line
const origins = require('../origins.json')
const { data } = origins
return data.includes(origin) ? data.includes(origin) : data.includes(domain)
} catch (e) {
return false

@ -1,3 +1 @@
import { RemixdClient as sharedfolder } from './services/remixdClient'
export { sharedfolder }
export { RemixdClient as Sharedfolder } from './services/remixdClient'

@ -1,6 +1,6 @@
import { PluginClient } from '@remixproject/plugin'
import { SharedFolderArgs, TrackDownStreamUpdate, Filelist, ResolveDirectory, FileContent } from '../types'
import * as WS from 'ws'
import { SharedFolderArgs, TrackDownStreamUpdate, Filelist, ResolveDirectory, FileContent } from '../types' // eslint-disable-line
import * as WS from 'ws' // eslint-disable-line
import * as utils from '../utils'
import * as chokidar from 'chokidar'
import * as fs from 'fs-extra'
@ -49,9 +49,9 @@ export class RemixdClient extends PluginClient {
try {
return new Promise((resolve, reject) => {
const path = utils.absolutePath(args.path, this.currentSharedFolder)
if (!fs.existsSync(path)) {
return reject('File not found ' + path)
return reject(new Error('File not found ' + path))
}
if (!isRealPath(path)) return
isbinaryfile(path, (error: Error, isBinary: boolean) => {
@ -76,7 +76,7 @@ export class RemixdClient extends PluginClient {
const path = utils.absolutePath(args.path, this.currentSharedFolder)
return fs.existsSync(path)
} catch(error) {
} catch (error) {
throw new Error(error)
}
}
@ -84,21 +84,21 @@ export class RemixdClient extends PluginClient {
set (args: SharedFolderArgs): Promise<void> {
try {
return new Promise((resolve, reject) => {
if (this.readOnly) reject('Cannot write file: read-only mode selected')
if (this.readOnly) reject(new Error('Cannot write file: read-only mode selected'))
const isFolder = args.path.endsWith('/')
const path = utils.absolutePath(args.path, this.currentSharedFolder)
const exists = fs.existsSync(path)
if (exists && !isRealPath(path)) reject()
if (exists && !isRealPath(path)) reject(new Error(''))
if (args.content === 'undefined') { // no !!!!!
console.log('trying to write "undefined" ! stopping.')
reject('trying to write "undefined" ! stopping.')
reject(new Error('trying to write "undefined" ! stopping.'))
}
this.trackDownStreamUpdate[path] = path
if (isFolder) {
fs.mkdirp(path).then(() => {
let splitPath = args.path.split('/')
splitPath = splitPath.filter(dir => dir)
const dir = '/' + splitPath.join('/')
@ -130,14 +130,14 @@ export class RemixdClient extends PluginClient {
rename (args: SharedFolderArgs): Promise<boolean> {
try {
return new Promise((resolve, reject) => {
if (this.readOnly) reject('Cannot rename file: read-only mode selected')
if (this.readOnly) reject(new Error('Cannot rename file: read-only mode selected'))
const oldpath = utils.absolutePath(args.oldPath, this.currentSharedFolder)
if (!fs.existsSync(oldpath)) {
reject('File not found ' + oldpath)
reject(new Error('File not found ' + oldpath))
}
const newpath = utils.absolutePath(args.newPath, this.currentSharedFolder)
if (!isRealPath(oldpath)) return
fs.move(oldpath, newpath, (error: Error) => {
if (error) {
@ -156,15 +156,15 @@ export class RemixdClient extends PluginClient {
remove (args: SharedFolderArgs): Promise<boolean> {
try {
return new Promise((resolve, reject) => {
if (this.readOnly) reject('Cannot remove file: read-only mode selected')
if (this.readOnly) reject(new Error('Cannot remove file: read-only mode selected'))
const path = utils.absolutePath(args.path, this.currentSharedFolder)
if (!fs.existsSync(path)) reject('File not found ' + path)
if (!fs.existsSync(path)) reject(new Error('File not found ' + path))
if (!isRealPath(path)) return
return fs.remove(path, (error: Error) => {
if (error) {
console.log(error)
reject('Failed to remove file/directory: ' + error)
reject(new Error('Failed to remove file/directory: ' + error))
}
this.emit('fileRemoved', args.path)
resolve(true)
@ -239,4 +239,4 @@ function isRealPath (path: string): boolean {
// throw new Error(mes)
}
return isRealPath
}
}

@ -36,4 +36,4 @@ export type SharedFolderArgs = FolderArgs & KeyPairString
export type WS = typeof Websocket
export type Filelist = KeyPairString
export type Filelist = KeyPairString

@ -1,4 +1,4 @@
import { ResolveDirectory, Filelist } from './types'
import { ResolveDirectory, Filelist } from './types' // eslint-disable-line
import * as fs from 'fs-extra'
import * as isbinaryfile from 'isbinaryfile'
import * as pathModule from 'path'
@ -49,7 +49,7 @@ function walkSync (dir: string, filelist: Filelist, sharedFolder: string): Filel
filelist = walkSync(subElement, filelist, sharedFolder)
} else {
const relative = relativePath(subElement, sharedFolder)
filelist[relative] = isbinaryfile.sync(subElement)
}
}
@ -79,7 +79,7 @@ function resolveDirectory (dir: string, sharedFolder: string): ResolveDirectory
* @param {String} url - Remix-IDE URL instance
* @return {String} extracted domain name from url
*/
function getDomain(url: string) {
function getDomain (url: string) {
// eslint-disable-next-line
const domainMatch = url.match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)/img)

@ -1,13 +1,13 @@
import * as WS from 'ws'
import * as http from 'http'
import { WebsocketOpt, SharedFolderClient } from './types'
import { WebsocketOpt, SharedFolderClient } from './types' // eslint-disable-line
import { getDomain } from './utils'
import { createClient } from '@remixproject/plugin-ws'
export default class WebSocket {
server: http.Server
wsServer: WS.Server
constructor (public port: number, public opt: WebsocketOpt, public sharedFolder: SharedFolderClient) {}
constructor (public port: number, public opt: WebsocketOpt, public sharedFolder: SharedFolderClient) {} //eslint-disable-line
start (callback?: (ws: WS) => void): void {
this.server = http.createServer((request, response) => {
@ -35,7 +35,7 @@ export default class WebSocket {
const { sharedFolder } = this
createClient(ws, sharedFolder as any)
if(callback) callback(ws)
if (callback) callback(ws)
})
}
@ -58,7 +58,7 @@ function originIsAllowed (origin: string, self: WebSocket): boolean {
const origins = require('./origins.json')
const domain = getDomain(origin)
const { data } = origins
if (data.includes(origin) || data.includes(domain)) {
self.opt.remixIdeUrl = origin
console.log('\x1b[33m%s\x1b[0m', '[WARN] You may now only use IDE at ' + self.opt.remixIdeUrl + ' to connect to that instance')

@ -43,7 +43,7 @@
"workspace-schematic": "nx workspace-schematic",
"dep-graph": "nx dep-graph",
"help": "nx help",
"lint:libs": "nx run-many --target=lint --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd",
"lint:libs": "nx run-many --target=lint --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd,remix-ui-tree-view,remix-ui-debugger-ui,remix-ui-utils,remix-ui-clipboard",
"build:libs": "nx run-many --target=build --parallel=false --with-deps=true --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd",
"test:libs": "nx run-many --target=test --projects=remix-analyzer,remix-astwalker,remix-debug,remix-lib,remix-simulator,remix-solidity,remix-tests,remix-url-resolver,remixd",
"publish:libs": "npm run build:libs; lerna publish --skip-git; npm run bumpVersion:libs",
@ -182,7 +182,6 @@
"@types/axios": "^0.14.0",
"@types/chai": "^4.2.11",
"@types/fs-extra": "^9.0.1",
"@types/jest": "25.1.4",
"@types/mocha": "^7.0.2",
"@types/nightwatch": "^1.1.6",
"@types/node": "~8.9.4",
@ -279,4 +278,4 @@
"yo-yo": "github:ioedeveloper/yo-yo",
"yo-yoify": "^3.7.3"
}
}
}

@ -25,7 +25,6 @@
"@remix-project/remix-tests": ["dist/libs/remix-tests/src/index.js"],
"@remix-project/remix-url-resolver": ["dist/libs/remix-url-resolver/index.js"],
"@remix-project/remixd": ["dist/libs/remixd/index.js"],
"@remix-project/debugger-ui": ["libs/debugger-ui/src/index.ts"],
"@remix-ui/tree-view": ["libs/remix-ui/tree-view/src/index.ts"],
"@remix-ui/debugger-ui": ["libs/remix-ui/debugger-ui/src/index.ts"],
"@remix-ui/utils": ["libs/remix-ui/utils/src/index.ts"],

Loading…
Cancel
Save