mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
buildWorkerBase bundles with esbuild code splitting into one private directory: the entry and its static chunks load at each fork, a lazily imported module and the packages it imports only when imported. @earendil-works/chord/workers/child exports the worker's side (workerMain, processLock) without esbuild.
22 lines
947 B
TypeScript
22 lines
947 B
TypeScript
// The worker process: a host at the session's address, connected to the server, loading the plugins it was shipped.
|
|
|
|
import { BACKGROUND_CONTEXT } from "../../../src/context/index.ts";
|
|
import { createHost } from "../../../src/host/index.ts";
|
|
import * as chord from "../../../src/index.ts";
|
|
import { workerMain } from "../../../src/node/workers/child.ts";
|
|
|
|
workerMain(
|
|
async ({ address, parent, plugins, onClose }, context) => {
|
|
const host = createHost({ address, principal: { kind: "worker" }, onError: console.error });
|
|
onClose(() => host.close(BACKGROUND_CONTEXT));
|
|
// Connect first: the server sees the worker started; then load.
|
|
host.connect(parent, { principal: { kind: "server" }, trusted: true }, context);
|
|
await plugins.load(host, { kind: "worker", core: [] }, context);
|
|
return {};
|
|
},
|
|
{
|
|
hostPackages: { "@earendil-works/chord": chord },
|
|
redact: (error) => ({ message: String(error) }),
|
|
onError: console.error,
|
|
},
|
|
);
|