1
0

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

View File

@ -31,6 +31,9 @@ async function prepareAssets(dist: string) {
await copy("web/manifest.json", `${dist}/web/manifest.json`, { await copy("web/manifest.json", `${dist}/web/manifest.json`, {
overwrite: true, overwrite: true,
}); });
await copy("server/SETTINGS_template.md", `${dist}/SETTINGS_template.md`, {
overwrite: true,
});
const compiler = sass( const compiler = sass(
Deno.readTextFileSync("web/styles/main.scss"), Deno.readTextFileSync("web/styles/main.scss"),
{ {

View File

@ -1,10 +1,9 @@
import { safeRun } from "../util.ts"; import { safeRun } from "../util.ts";
// @ts-ignore
// import workerCode from "bundle-text:./node_worker.ts";
import { Sandbox } from "../sandbox.ts"; import { Sandbox } from "../sandbox.ts";
import { WorkerLike } from "./worker.ts"; import { WorkerLike } from "./worker.ts";
import { Plug } from "../plug.ts"; import { Plug } from "../plug.ts";
import { AssetBundle, assetReadTextFileSync } from "../asset_bundle_reader.ts";
class DenoWorkerWrapper implements WorkerLike { class DenoWorkerWrapper implements WorkerLike {
private worker: Worker; private worker: Worker;
@ -31,12 +30,23 @@ class DenoWorkerWrapper implements WorkerLike {
} }
} }
export function createSandbox(plug: Plug<any>) { export function sanboxFactory(
let worker = new Worker( assetBundle: AssetBundle,
new URL("./sandbox_worker.ts", import.meta.url).href, ): (plug: Plug<any>) => Sandbox {
{ return (plug: Plug<any>) => {
type: "module", const workerHref = URL.createObjectURL(
} new Blob([
); assetReadTextFileSync(assetBundle, "web/worker.js"),
return new Sandbox(plug, new DenoWorkerWrapper(worker)); ], {
type: "application/javascript",
}),
);
let worker = new Worker(
workerHref,
{
type: "module",
},
);
return new Sandbox(plug, new DenoWorkerWrapper(worker));
};
} }

View File

@ -1,6 +1,6 @@
import { safeRun } from "../util.ts"; import { safeRun } from "../util.ts";
import { ConsoleLogger } from "./custom_logger.ts"; import { ConsoleLogger } from "./custom_logger.ts";
import { ControllerMessage, WorkerMessage } from "./worker.ts"; import type { ControllerMessage, WorkerMessage } from "./worker.ts";
if (typeof Deno === "undefined") { if (typeof Deno === "undefined") {
// @ts-ignore: Deno hack // @ts-ignore: Deno hack

View File

@ -14,7 +14,7 @@ import { Space } from "../common/spaces/space.ts";
import { SpacePrimitives } from "../common/spaces/space_primitives.ts"; import { SpacePrimitives } from "../common/spaces/space_primitives.ts";
import { markdownSyscalls } from "../common/syscalls/markdown.ts"; import { markdownSyscalls } from "../common/syscalls/markdown.ts";
import { parseYamlSettings } from "../common/util.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 { EndpointHook } from "../plugos/hooks/endpoint.ts";
import { EventHook } from "../plugos/hooks/event.ts"; import { EventHook } from "../plugos/hooks/event.ts";
import { DenoCronHook } from "../plugos/hooks/cron.deno.ts"; import { DenoCronHook } from "../plugos/hooks/cron.deno.ts";
@ -175,7 +175,10 @@ export class HttpServer {
console.log("Loading plugs", allPlugs); console.log("Loading plugs", allPlugs);
for (const plugName of allPlugs) { for (const plugName of allPlugs) {
const { data } = await this.space.readAttachment(plugName, "string"); 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(); this.rebuildMdExtensions();
@ -347,9 +350,7 @@ export class HttpServer {
} catch { } catch {
await this.space.writePage( await this.space.writePage(
"SETTINGS", "SETTINGS",
await Deno.readTextFile( assetReadTextFileSync(this.assetBundle, "SETTINGS_template.md"),
new URL("SETTINGS_template.md", import.meta.url).pathname,
),
true, true,
); );
} }