Skip to content

Commit

Permalink
chore: typing
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Oct 27, 2024
1 parent a9f508a commit c29faae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 2 additions & 4 deletions packages/workerd/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import {
type ResolvedConfig,
} from "vite";
import type { SourcelessWorkerOptions } from "wrangler";
import { type FetchMetadata } from "./shared";
import type { RunnerObject } from "./worker";
import { type FetchMetadata, type RunnerRpc } from "./shared";

interface WorkerdPluginOptions extends WorkerdEnvironmentOptions {
entry?: string;
Expand Down Expand Up @@ -149,8 +148,7 @@ export async function createWorkerdDevEnvironment(

// get durable object singleton
const ns = await miniflare.getDurableObjectNamespace("__viteRunner");
const runnerObject = ns.get(ns.idFromName("")) as any as Fetcher &
Pick<RunnerObject, "__viteInit" | "__viteServerSend">;
const runnerObject = ns.get(ns.idFromName("")) as any as Fetcher & RunnerRpc;

// init via rpc
await runnerObject.__viteInit();
Expand Down
5 changes: 5 additions & 0 deletions packages/workerd/src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ export type RunnerEnv = {
__viteRunner: DurableObject;
};

export type RunnerRpc = {
__viteInit: () => Promise<void>;
__viteServerSend: (payload: unknown) => Promise<void>;
};

export type FetchMetadata = {
entry: string;
};
10 changes: 7 additions & 3 deletions packages/workerd/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import {
ssrImportMetaKey,
ssrModuleExportsKey,
} from "vite/module-runner";
import { ANY_URL, type FetchMetadata, type RunnerEnv } from "./shared";
import {
ANY_URL,
type FetchMetadata,
type RunnerEnv,
type RunnerRpc,
} from "./shared";

export class RunnerObject extends DurableObject {
export class RunnerObject extends DurableObject implements RunnerRpc {
#env: RunnerEnv;
#runner?: ModuleRunner;
#viteServerSend!: (payload: HotPayload) => void;
Expand Down Expand Up @@ -85,7 +90,6 @@ export class RunnerObject extends DurableObject {
},
},
);
return { ok: true };
}

async __viteServerSend(payload: any) {
Expand Down

0 comments on commit c29faae

Please sign in to comment.