Fixes #193: Allowing plug overrides
This commit is contained in:
+12
-1
@@ -1,7 +1,8 @@
|
||||
import { Hook } from "./types.ts";
|
||||
import { Hook, Manifest } from "./types.ts";
|
||||
import { EventEmitter } from "./event.ts";
|
||||
import type { SandboxFactory } from "./sandbox.ts";
|
||||
import { Plug } from "./plug.ts";
|
||||
import { deepObjectMerge } from "$sb/lib/json.ts";
|
||||
|
||||
export interface SysCallMapping {
|
||||
[key: string]: (ctx: SyscallContext, ...args: any) => Promise<any> | any;
|
||||
@@ -95,11 +96,21 @@ export class System<HookT> extends EventEmitter<SystemEvents<HookT>> {
|
||||
async load(
|
||||
workerUrl: URL,
|
||||
sandboxFactory: SandboxFactory<HookT>,
|
||||
// Mapping plug name -> manifest overrides
|
||||
manifestOverrides?: Record<string, Partial<Manifest<HookT>>>,
|
||||
): Promise<Plug<HookT>> {
|
||||
const plug = new Plug(this, workerUrl, sandboxFactory);
|
||||
|
||||
// Wait for worker to boot, and pass back its manifest
|
||||
await plug.ready;
|
||||
|
||||
if (manifestOverrides && manifestOverrides[plug.manifest!.name]) {
|
||||
plug.manifest = deepObjectMerge(
|
||||
plug.manifest,
|
||||
manifestOverrides[plug.manifest!.name],
|
||||
);
|
||||
console.log("New manifest", plug.manifest);
|
||||
}
|
||||
// and there it is!
|
||||
const manifest = plug.manifest!;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user