diff --git a/build.ts b/build.ts index f9ae5d09..776d50e5 100644 --- a/build.ts +++ b/build.ts @@ -31,6 +31,9 @@ async function prepareAssets(dist: string) { await copy("web/manifest.json", `${dist}/web/manifest.json`, { overwrite: true, }); + await copy("server/SETTINGS_template.md", `${dist}/SETTINGS_template.md`, { + overwrite: true, + }); const compiler = sass( Deno.readTextFileSync("web/styles/main.scss"), { diff --git a/plugos/environments/deno_sandbox.ts b/plugos/environments/deno_sandbox.ts index 556c3984..1ca49d36 100644 --- a/plugos/environments/deno_sandbox.ts +++ b/plugos/environments/deno_sandbox.ts @@ -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) { - 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) => Sandbox { + return (plug: Plug) => { + 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)); + }; } diff --git a/plugos/environments/sandbox_worker.ts b/plugos/environments/sandbox_worker.ts index 3f8f0d60..73920338 100644 --- a/plugos/environments/sandbox_worker.ts +++ b/plugos/environments/sandbox_worker.ts @@ -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 diff --git a/server/http_server.ts b/server/http_server.ts index e816ad16..8cff7348 100644 --- a/server/http_server.ts +++ b/server/http_server.ts @@ -14,7 +14,7 @@ import { Space } from "../common/spaces/space.ts"; import { SpacePrimitives } from "../common/spaces/space_primitives.ts"; import { markdownSyscalls } from "../common/syscalls/markdown.ts"; import { parseYamlSettings } from "../common/util.ts"; -import { createSandbox } from "../plugos/environments/deno_sandbox.ts"; +import { sanboxFactory } from "../plugos/environments/deno_sandbox.ts"; import { EndpointHook } from "../plugos/hooks/endpoint.ts"; import { EventHook } from "../plugos/hooks/event.ts"; import { DenoCronHook } from "../plugos/hooks/cron.deno.ts"; @@ -175,7 +175,10 @@ export class HttpServer { console.log("Loading plugs", allPlugs); for (const plugName of allPlugs) { const { data } = await this.space.readAttachment(plugName, "string"); - await this.system.load(JSON.parse(data as string), createSandbox); + await this.system.load( + JSON.parse(data as string), + sanboxFactory(this.assetBundle), + ); } this.rebuildMdExtensions(); @@ -347,9 +350,7 @@ export class HttpServer { } catch { await this.space.writePage( "SETTINGS", - await Deno.readTextFile( - new URL("SETTINGS_template.md", import.meta.url).pathname, - ), + assetReadTextFileSync(this.assetBundle, "SETTINGS_template.md"), true, ); }