refactoring in playground, use zip file for web

This commit is contained in:
2024-12-08 20:19:55 -08:00
parent 0f5a909cce
commit d6aaaaabf1
47 changed files with 1932 additions and 88 deletions

View File

@@ -6,15 +6,11 @@ const handleMessage = async function (ev: { data: CompileReq }) {
console.log("message", ev.data);
await preload;
shim.archive = archive;
let { src } = ev.data;
let module = "Main";
let m = src.match(/module (\w+)/);
if (m) module = m[1];
let fn = `${module}.newt`;
let { src, fileName } = ev.data;
const outfile = "out.js";
shim.process.argv = ["", "", fn, "-o", outfile, "--top"];
shim.process.argv = ["", "", fileName, "-o", outfile, "--top"];
console.log("Using args", shim.process.argv);
shim.files[fn] = new TextEncoder().encode(src);
shim.files[fileName] = new TextEncoder().encode(src);
shim.files[outfile] = new TextEncoder().encode("No JS output");
shim.stdout = "";
const start = +new Date();
@@ -27,10 +23,10 @@ const handleMessage = async function (ev: { data: CompileReq }) {
shim.stdout += "\n" + String(e);
}
let duration = +new Date() - start;
console.log(`process ${fn} in ${duration} ms`);
console.log(`process ${fileName} in ${duration} ms`);
let javascript = new TextDecoder().decode(shim.files[outfile]);
let output = shim.stdout;
sendResponse({ javascript, output, duration });
sendResponse({ type: 'compileResult', javascript, output, duration });
};
// hooks for worker.html to override