From 186b0dfb807a50302bd263264110a2d0fc0ff305 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Tue, 22 Oct 2019 20:09:14 +0800 Subject: [PATCH] remove remote; add ws & types@ws --- js-framework/index.debug.ts | 17 +++++++++++++++++ js-framework/package-lock.json | 21 +++++++++++++++++++++ js-framework/package.json | 6 ++++-- remote/.gitignore | 1 - remote/.vscode/launch.json | 21 --------------------- remote/index.js | 21 --------------------- remote/package-lock.json | 21 --------------------- remote/package.json | 10 ---------- 8 files changed, 42 insertions(+), 76 deletions(-) delete mode 100644 remote/.gitignore delete mode 100644 remote/.vscode/launch.json delete mode 100644 remote/index.js delete mode 100644 remote/package-lock.json delete mode 100644 remote/package.json diff --git a/js-framework/index.debug.ts b/js-framework/index.debug.ts index bbe14f3e..0d428f03 100644 --- a/js-framework/index.debug.ts +++ b/js-framework/index.debug.ts @@ -14,6 +14,8 @@ * limitations under the License. */ import * as doric from './src/runtime/sandbox' +import * as WebSocket from "ws" + let global = new Function('return this')() global.doric = doric const contextId = "DoricDebug" @@ -21,6 +23,21 @@ global.context = doric.jsObtainContext(contextId) global.Entry = doric.jsObtainEntry(contextId) console.log('Start Server') +const wss = new WebSocket.Server({ port: 2080 }) +var sandbox = {} + +wss.on('connection', function connection(ws) { + ws.on('message', function incoming(message: string) { + let messageObject = JSON.parse(message) + switch (messageObject.cmd) { + case "loadJS": + break + case "evaluateJS": + break + } + }) +}) + global.injectGlobal = (objName: string, obj: string) => { Reflect.set(global, objName, JSON.parse(obj)) } diff --git a/js-framework/package-lock.json b/js-framework/package-lock.json index 3a411d17..7dc35b42 100644 --- a/js-framework/package-lock.json +++ b/js-framework/package-lock.json @@ -22,6 +22,14 @@ "@types/node": "*" } }, + "@types/ws": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-6.0.3.tgz", + "integrity": "sha512-yBTM0P05Tx9iXGq00BbJPo37ox68R5vaGTXivs6RGh/BQ6QP5zqZDGWdAO6JbRE/iR1l80xeGAwCQS2nMV9S/w==", + "requires": { + "@types/node": "*" + } + }, "acorn": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", @@ -69,6 +77,11 @@ "resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.3.tgz", "integrity": "sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==" }, + "async-limiter": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", + "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" + }, "atob": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", @@ -2072,6 +2085,14 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "ws": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.0.tgz", + "integrity": "sha512-+SqNqFbwTm/0DC18KYzIsMTnEWpLwJsiasW/O17la4iDRRIO9uaHbvKiAS3AHgTiuuWerK/brj4O6MYZkei9xg==", + "requires": { + "async-limiter": "^1.0.0" + } } } } diff --git a/js-framework/package.json b/js-framework/package.json index 175aae88..0ae78ff9 100644 --- a/js-framework/package.json +++ b/js-framework/package.json @@ -20,11 +20,13 @@ }, "homepage": "https://github.com/doric-pub/doric#readme", "dependencies": { + "@types/ws": "^6.0.3", "reflect-metadata": "^0.1.13", "rollup": "^1.17.0", "rollup-plugin-node-resolve": "^5.2.0", "rollup-watch": "^4.3.1", "tslib": "^1.10.0", - "typescript": "^3.5.3" + "typescript": "^3.5.3", + "ws": "^7.2.0" } -} \ No newline at end of file +} diff --git a/remote/.gitignore b/remote/.gitignore deleted file mode 100644 index 40b878db..00000000 --- a/remote/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ \ No newline at end of file diff --git a/remote/.vscode/launch.json b/remote/.vscode/launch.json deleted file mode 100644 index b5b7c1f1..00000000 --- a/remote/.vscode/launch.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "type": "node", - "request": "launch", - "name": "Launch Program", - "program": "${workspaceFolder}/index.ts", - "preLaunchTask": "tsc: build - tsconfig.json", - }, - { - "type": "node", - "request": "attach", - "name": "Attach", - "port": 9229 - } - ] -} \ No newline at end of file diff --git a/remote/index.js b/remote/index.js deleted file mode 100644 index 1b3a1c20..00000000 --- a/remote/index.js +++ /dev/null @@ -1,21 +0,0 @@ -const WebSocket = require('ws') -const vm = require("vm") - -const wss = new WebSocket.Server({ port: 2080 }) -var sandbox = {} -var context = vm.createContext(sandbox) - -wss.on('connection', function connection(ws) { - ws.on('message', function incoming(message) { - let messageObject = JSON.parse(message) - switch (messageObject.cmd) { - case "loadJS": - let result = vm.runInContext(messageObject.script, sandbox) - ws.send(JSON.stringify({ cmd: 'loadJS', result: String(result) })) - break - case "evaluateJS": - break - } - }) -}) - diff --git a/remote/package-lock.json b/remote/package-lock.json deleted file mode 100644 index a0da7af1..00000000 --- a/remote/package-lock.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "remote", - "version": "0.1.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "async-limiter": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", - "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" - }, - "ws": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.0.tgz", - "integrity": "sha512-+SqNqFbwTm/0DC18KYzIsMTnEWpLwJsiasW/O17la4iDRRIO9uaHbvKiAS3AHgTiuuWerK/brj4O6MYZkei9xg==", - "requires": { - "async-limiter": "^1.0.0" - } - } - } -} diff --git a/remote/package.json b/remote/package.json deleted file mode 100644 index be9c1efa..00000000 --- a/remote/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "remote", - "version": "0.1.0", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "dependencies": { - "ws": "^7.2.0" - } -}