Fix bundling
parent
61bf715c9f
commit
09ac3ea36a
3
build.ts
3
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"),
|
||||
{
|
||||
|
|
|
@ -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,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
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue