From 0e4791755d9bb0c96d7673abeef08cd727044ec7 Mon Sep 17 00:00:00 2001 From: Alexandre Tolstenko Date: Fri, 22 Dec 2023 16:10:02 -0500 Subject: [PATCH] fix syntax training webworker importer. but still have issues related to pack loader --- .gitignore | 1 + .../src/components/SyntaxTraining.tsx | 7 ++++--- .../components/{emception.ts => emception.js} | 18 +++++++++--------- .../src/components/emception.worker.js | 6 ++++++ 4 files changed, 20 insertions(+), 12 deletions(-) rename demo-syntax-training/src/components/{emception.ts => emception.js} (91%) create mode 100755 demo-syntax-training/src/components/emception.worker.js diff --git a/.gitignore b/.gitignore index f6f7db4b..6bc64446 100755 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ build**/ upstream**/ **/dist/ +**/cmake-build**/ # build cache files **/*.idx diff --git a/demo-syntax-training/src/components/SyntaxTraining.tsx b/demo-syntax-training/src/components/SyntaxTraining.tsx index d09c7462..c3d7c2c3 100644 --- a/demo-syntax-training/src/components/SyntaxTraining.tsx +++ b/demo-syntax-training/src/components/SyntaxTraining.tsx @@ -4,8 +4,9 @@ import {CopyOutlined, PlayCircleFilled, UndoOutlined} from "@ant-design/icons"; import { Editor, Monaco } from "@monaco-editor/react"; import {editor} from "monaco-editor"; const { Header, Content, Footer } = Layout; +import * as Comlink from "comlink"; -import Emception from "./emception"; +import EmceptionWorker from "./emception.worker"; const containerStyle: React.CSSProperties = { width: '100%', @@ -35,10 +36,10 @@ const SyntaxTrainingPage: React.FC = ({ const [api, contextHolder] = notification.useNotification(); - let emception: Emception; + let emception: any; async function loadEmception(): Promise { showNotification("Loading emception..."); - emception = new Emception(); + emception = Comlink.wrap(new EmceptionWorker()); await emception.init(); showNotification("Emception loaded"); } diff --git a/demo-syntax-training/src/components/emception.ts b/demo-syntax-training/src/components/emception.js similarity index 91% rename from demo-syntax-training/src/components/emception.ts rename to demo-syntax-training/src/components/emception.js index bfd568cf..292431c0 100755 --- a/demo-syntax-training/src/components/emception.ts +++ b/demo-syntax-training/src/components/emception.js @@ -51,7 +51,7 @@ const preloads = [ ]; class Emception { - fileSystem: FileSystem = null; + fileSystem = null; tools = {}; async init() { @@ -83,7 +83,7 @@ class Emception { const processConfig = { FS: fileSystem.FS, - onrunprocess: (...args) => this._run_process(args), + onrunprocess: (...args) => this._run_process(...args), }; const tools = { @@ -103,10 +103,10 @@ class Emception { } } - onprocessstart = (str) => {console.log("onprocessstart", str)}; - onprocessend = (str) => {console.log("onprocessend", str)}; - onstdout = (str) => {console.log(str)}; - onstderr = (str) => {console.error(str)}; + onprocessstart = () => {}; + onprocessend = () => {}; + onstdout = () => {}; + onstderr = () => {}; run(...args) { if (this.fileSystem.exists("/emscripten/cache/cache.lock")) { @@ -117,8 +117,8 @@ class Emception { `/emscripten/${args[0]}.py`, ...args.slice(1) ], { - print: (...args) => this.onstdout(args), - printErr: (...args) => this.onstderr(args), + print: (...args) => this.onstdout(...args), + printErr: (...args) => this.onstderr(...args), cwd: "/working", path: ["/emscripten"], }); @@ -131,7 +131,7 @@ class Emception { return result; } - _run_process_impl(argv, opts:any = {}) { + _run_process_impl(argv, opts = {}) { const emscripten_script = argv[0].match(/^((\/lazy)?\/emscripten\/.+?)(?:\.py)?$/)?.[1] if (emscripten_script && this.fileSystem.exists(`${emscripten_script}.py`)) { argv = [ diff --git a/demo-syntax-training/src/components/emception.worker.js b/demo-syntax-training/src/components/emception.worker.js new file mode 100755 index 00000000..cd1a0287 --- /dev/null +++ b/demo-syntax-training/src/components/emception.worker.js @@ -0,0 +1,6 @@ +import * as Comlink from "comlink"; +import Emception from "./emception.js"; + +const emception = new Emception(); +globalThis.emception = emception; +Comlink.expose(emception);