Fix bundling

This commit is contained in:
Zef Hemel
2022-10-11 11:38:10 +02:00
parent 61bf715c9f
commit 09ac3ea36a
4 changed files with 30 additions and 16 deletions
+20 -10
View File
@@ -1,10 +1,9 @@
import { safeRun } from "../util.ts";
// @ts-ignore
// import workerCode from "bundle-text:./node_worker.ts";
import { Sandbox } from "../sandbox.ts";
import { WorkerLike } from "./worker.ts";
import { Plug } from "../plug.ts";
import { AssetBundle, assetReadTextFileSync } from "../asset_bundle_reader.ts";
class DenoWorkerWrapper implements WorkerLike {
private worker: Worker;
@@ -31,12 +30,23 @@ class DenoWorkerWrapper implements WorkerLike {
}
}
export function createSandbox(plug: Plug<any>) {
let worker = new Worker(
new URL("./sandbox_worker.ts", import.meta.url).href,
{
type: "module",
}
);
return new Sandbox(plug, new DenoWorkerWrapper(worker));
export function sanboxFactory(
assetBundle: AssetBundle,
): (plug: Plug<any>) => Sandbox {
return (plug: Plug<any>) => {
const workerHref = URL.createObjectURL(
new Blob([
assetReadTextFileSync(assetBundle, "web/worker.js"),
], {
type: "application/javascript",
}),
);
let worker = new Worker(
workerHref,
{
type: "module",
},
);
return new Sandbox(plug, new DenoWorkerWrapper(worker));
};
}
+1 -1
View File
@@ -1,6 +1,6 @@
import { safeRun } from "../util.ts";
import { ConsoleLogger } from "./custom_logger.ts";
import { ControllerMessage, WorkerMessage } from "./worker.ts";
import type { ControllerMessage, WorkerMessage } from "./worker.ts";
if (typeof Deno === "undefined") {
// @ts-ignore: Deno hack